recursive_ice_long | R Documentation |
Recursively apply the ICE algorithm for a long dataset
recursive_ice_long( Tt, n_nested, df_obs, df_interv, inside_formula_t, inside_formula_tmin1, outside_formula, inside_family, t_col, binomial_n = NULL, models = TRUE, tmle = FALSE, weights = NULL )
Tt |
int. Max time period (total of TT+1) periods |
n_nested |
int. Index of the current nested expectation being estimated. 0=innermost (non-nested) expectation, Tt=outermost. Generally always Tt when called by the user. |
df_obs |
long data frame of the observed data with columns uid, t (0,1,...,Tt), Y, Y_lag, exposure and covariates. |
df_interv |
long data frame with all columns in df_obs, but exposure variables set to their intervened values. |
inside_formula_t |
chr. full formula for innermost expectation model for Y_t. Will be |
inside_formula_tmin1 |
chr. full formula for innermost expectation model for Y_t-1. Will be |
outside_formula |
chr. RHS-only formula for outer (nested) expectation models for n_nested=0,1,...,Tt. Will be |
inside_family |
stats::families object or character naming one, for inside model fit using |
binomial_n |
int length nrow(df_obs). Group sizes for aggregate binomial data. |
models |
lgl. Return all models as an attribute? |
Formulas in recursive_ice_long()
are glue-style and admit 2 special references.
{n} is shorthand for `n_nested`. For example, we typically want exposure and covariate values lagged exactly `n_nested` periods in each outside model, so we might pass `'~A_lag{n}*L_lag{n}'` as `outside_formula`. This is simply a more concise version of `'~A_lag{n_nested}*L_lag{n_nested}`. {tvars} is an internally generated string variable that looks like `"(t{n} + t{n+1} + ... + t{Tt})"`, where again {n} is shorthand for `{n_nested}`. Specifically, `recursive_ice_long()` retrieves the `timevars` attribute of `df_obs`, takes the indices `n_nested:length(tvars)`, and pastes these together with `collapse='+'`. This is useful for including time indicators in saturated models, since the `n`th outside model will only have observations with `t>=n` in it.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.