aggregate_data: Aggregate grouped data

Description Usage Arguments Value Examples

View source: R/post_stratified_ITS.R

Description

This will take a dataframe with each row being the outcomes, etc., for a given group for a given month and aggregate those groups for each month.

Usage

1
2
3
4
5
6
7
8
9
aggregate_data(
  dat,
  outcomename,
  groupname,
  Nname,
  is_count = FALSE,
  rich = TRUE,
  covariates = NULL
)

Arguments

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 'month' column for the time.

outcomename

String name of the outcome variable in dat.

groupname

Name of the column that has the grouping categorical variable

Nname

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

is_count

If TRUE the data are counts, and should be aggregated by sum rather than by mean.

rich

If TRUE, add a bunch of extra columns with proportions of the month that are each group and so forth.

covariates

group-invariant covariates to preserve in the augmented rich dataframe. These are not used in this method for any calculations. Pass as list of column names of dat

Value

Dataframe of aggregated data, one row per month. If rich=TRUE many extra columns with further information.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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 )

simITS documentation built on July 2, 2020, 4:10 a.m.