Add a cumulative membership effect to a
This function adds a cumulative membership effect to a data
frame. This is useful for specifying models such as random walks (using
rw()) where these features can be used in the design matrix with the
appropriate formula. Supports grouping via the optional
Note that cumulative membership is indexed to start with zero (i.e. the
first observation is assigned a cumulative membership of zero).
data.framewith a column named
featurethat contains a numeric vector of values.
The name of the column in
metaobsthat contains the numeric vector of values.
metaobsbe copied (default) or modified in place?
data.frame with a new columns
cfeature$ that contain the
cumulative membership effect for each value of
feature. For example if the
week (with numeric entries
1, 2, 3) then the new
columns will be
metaobs <- data.frame(week = 1:3) enw_add_cumulative_membership(metaobs, "week") #> week .group cweek2 cweek3 #> 1: 1 1 0 0 #> 2: 2 1 1 0 #> 3: 3 1 1 1 metaobs <- data.frame(week = 1:3, .group = c(1,1,2)) enw_add_cumulative_membership(metaobs, "week") #> week .group cweek2 cweek3 #> 1: 1 1 0 0 #> 2: 2 1 1 0 #> 3: 3 2 0 1