detrend_factor: Calculate aggregated variance to provide denominator for...

View source: R/detrend_factor.R

detrend_factorR Documentation

Calculate aggregated variance to provide denominator for trend-adjusting outcomes

Description

Calculate aggregated variance to provide denominator for trend-adjusting outcomes

Usage

detrend_factor(sdid, df)

Arguments

sdid

sdid object containing the model to summarize.

df

A data frame containing the variables in the model.

Value

numeric

Examples

# First fit a model using the original outcome, with or without covariate adjustments.
sdid_hosp <- sdid(hospitalized ~ cohort + yr + age + sex + comorb,
                  df = hosp,
                  intervention_var  = "intervention_yr")

# Retrieve an estimate for the pre-intervention period
raw_pre_intervention_trend <-
  ave_coeff(sdid = sdid_hosp,
            coefs = select_period(sdid = sdid_hosp, period = "pre"))[["est"]]

# Normalize the pre-intervention estimate by de-trending factor
beta_detrend <-
  raw_pre_intervention_trend /
  detrend_factor(sdid = sdid_hosp,
                 df = hosp)

staggR documentation built on April 2, 2026, 5:08 p.m.