calculate_group_weights: Calculate proportion of subgroups across time

View source: R/post_stratified_ITS.R

calculate_group_weightsR Documentation

Calculate proportion of subgroups across time

Description

Calculate overall proportion of cases in each group that lie within a given interval of time defined by t_min and t_max.

Usage

calculate_group_weights(groupname, dat, t_min, t_max = Inf, Nname = "N")

Arguments

groupname

Name of the column that has the grouping categorical variable

dat

Dataframe with one row for each time point and group that we are going to post stratify on. This dataframe should also have an column with passed name "Nname" indicating the number of cases that make up each given row. It should have a column "timename" for the time.

t_min

The start time point to aggregate cases over.

t_max

The final time point (default is last time point).

Nname

Name of variable holding the counts (weight) in each group.

Value

Dataframe of each group along with overall average group weight in the specified timespan.

Examples

data( "meck_subgroup" )
head( meck_subgroup )
pis = calculate_group_weights( "category", Nname="n.cases", 
                               meck_subgroup, t_min=0, t_max= max( meck_subgroup$month ) )
pis

agg = aggregate_data( meck_subgroup, 
                      outcomename="pbail", groupname="category", Nname="n.cases", 
                      is_count=FALSE,
                      rich = TRUE, covariates = NULL )
head( agg )  


adjdat = adjust_data( meck_subgroup, "pbail", "category", "n.cases", pis, include_aggregate=TRUE )
head( adjdat )

lmiratrix/simITS documentation built on Sept. 1, 2023, 9:02 p.m.