msm: Marginal structural model

View source: R/msm.r

msmR Documentation

Marginal structural model

Description

Estimation of a marginal structural model using results from the parametric g-formula.

Usage

msm(X, formula, family = gaussian, se = NULL, cilevel = 0.95, abar=NULL)

Arguments

X

An object of class gformula produced by gformula, with option ret = TRUE.

formula

Form of the marginal structural model. Can be specified as a formula object, e.g., formula = VL.4 ~ efv.4, as a quoted expression, e.g., formula = quote(VL.4 ~ efv.4), or as a character string, e.g., formula = "VL.4 ~ efv.4".

family

A description of the error distribution and link function to be used in the model. See family for details of family functions.

se

A character string specifying the standard errors used to compute confidence intervals. One of c('bootstrap', 'glm'). See Details.

cilevel

Numeric value between 0 and 1 specifying the confidence level of the bootstrap confidence intervals. Defaults to 95%.

abar

Vector or matrix that is a subset of the intervention used in X. Can be used to fit an MSM on a subset of the stacked counterfactual data.

Details

The marginal structural model (MSM) is estimated as a GLM. Confidence intervals are calculated using GLM standard errors (if se = 'glm') or nonparametric boostrap standard errors (if se = 'bootstrap' and gformula was run with B > 0.) By default: se = 'bootstrap' if gformula was run with B > 0, and se = 'glm' otherwise.

Value

Returns a list of class msmResult:

MSM

The fitted MSM of class glm.

coefs

The estimated coefficients of the MSM.

CIlow

Lower confidence interval bounds for each coefficient.

CIup

Upper confidence interval bounds for each coefficient.

formula

The 'formula' input argument.

se

The 'se' input argument.

vcov

Covariance matrix.

See Also

gformula for estimating expected counterfactual outcomes under multiple intervention values.

Examples


data(EFV)
gf <- gformula(
  X = EFV, Anodes = c("efv.0", "efv.1", "efv.2", "efv.3", "efv.4"),
  Ynodes = c("VL.0", "VL.1", "VL.2", "VL.3", "VL.4"),
  Lnodes = c("adherence.1", "weight.1", "adherence.2", "weight.2",
             "adherence.3", "weight.3", "adherence.4", "weight.4"),
  abar = seq(0, 5), B = 10, ret = TRUE
)

msm(gf, VL.4 ~ efv.4, se = "bootstrap") # default if B>0
msm(gf, VL.4 ~ efv.4, se = "glm")       # fast, but not valid (undercoverage)


CICI documentation built on April 7, 2026, 5:08 p.m.