Fast binning of cumulative vector sum with new groups when the sum passes a threshold or the group size becomes too large

cumsumbinning(x, cutoff, maxgroupsize = NULL)

Arguments

x

A matrix of regressor variables. Must have the same number of rows as the length of y.

cutoff

The value of the threshold that the cumulative group sum must not cross.

maxgroupsize

An integer that defines the maximum number of elements in each group. NULL (the default) corresponds to no group size.

Value

An integer vector giving the group indices

Details

Missing values (NA, Inf, NaN) are completely disregarded and pairwise complete cases are used f

Examples

set.seed(1) x <- sample(10, 20, replace = TRUE) cumsumbinning(x, 15)
#> [1] 1 1 1 2 2 3 4 5 5 5 6 6 6 7 7 8 8 9 9 10
cumsumbinning(x, 15, 3)
#> [1] 1 1 1 2 2 3 4 5 5 5 6 6 6 7 7 8 8 9 9 10