enw_add_cumulative_membership: Add a cumulative membership effect to a 'data.frame'

View source: R/model-design-tools.R

enw_add_cumulative_membershipR Documentation

Add a cumulative membership effect to a data.frame

Description

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 .group column. Note that cumulative membership is indexed to start with zero (i.e. the first observation is assigned a cumulative membership of zero).

Usage

enw_add_cumulative_membership(metaobs, feature, copy = TRUE)

Arguments

metaobs

A data.frame with a column named feature that contains a numeric vector of values.

feature

The name of the column in metaobs that contains the numeric vector of values.

copy

Should metaobs be copied (default) or modified in place?

Value

A data.frame with a new columns ⁠cfeature$⁠ that contain the cumulative membership effect for each value of feature. For example if the original feature was week (with numeric entries ⁠1, 2, 3⁠) then the new columns will be cweek1, cweek2, and cweek3.

See Also

Functions used to formulate models enw_add_pooling_effect(), enw_design(), enw_effects_metadata(), enw_one_hot_encode_feature()

Examples

metaobs <- data.frame(week = 1:2)
enw_add_cumulative_membership(metaobs, "week")

metaobs <- data.frame(week = 1:3, .group = c(1,1,2))
enw_add_cumulative_membership(metaobs, "week")

seabbs/epinowcast documentation built on Sept. 20, 2024, 2:39 a.m.