adjust_data {simITS} | R Documentation |
Adjust an outcome time series based on the group weights.
Description
Reweight the components of a series to match target weights for several categories. This is a good preprocessing step to adjust for time-varying covariates such as changing mix of case types.
Usage
adjust_data(
dat,
outcomename,
groupname,
Nname,
pi_star,
is_count = FALSE,
include_aggregate = FALSE,
covariates = NULL
)
Arguments
dat |
Dataframe of data. Requires an N column of total cases represented in each row. |
outcomename |
Name of column that has the outcome to calculated adjusted values for. |
groupname |
Name of categorical covariate that determines the groups. |
Nname |
Name of column in dat that contains total cases (this is the name of the variable used to generate the weights in pi_star). |
pi_star |
The target weights. Each month will have its groups re-weighted to match these target weights. |
is_count |
Indicator of whether outcome is count data or a continuous measure (this impacts how aggregation is done). |
include_aggregate |
Include aggregated (unadjusted) totals in the output as well. |
covariates |
Covariates to be passed to aggregation (list of string variable names). |
Value
Dataframe of adjusted data.
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 )