recursive_ice_long: Recursively apply the ICE algorithm for a long dataset

View source: R/ice_long.R

recursive_ice_longR Documentation

Recursively apply the ICE algorithm for a long dataset

Description

Recursively apply the ICE algorithm for a long dataset

Usage

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
)

Arguments

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 glue()ed internally, so can include tvars. (See details)

inside_formula_tmin1

chr. full formula for innermost expectation model for Y_t-1. Will be glue()ed internally, so can include tvars. (See details)

outside_formula

chr. RHS-only formula for outer (nested) expectation models for n_nested=0,1,...,Tt. Will be glue()ed internally, so can include tvars and n. (See details)

inside_family

stats::families object or character naming one, for inside model fit using glm

binomial_n

int length nrow(df_obs). Group sizes for aggregate binomial data.

models

lgl. Return all models as an attribute?

Details

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.

audreyrenson/didgformula documentation built on Oct. 9, 2022, 11:45 a.m.