msm_multinomial_fit: Fitting marginal structural model (MSM) within quantile...

msm_multinomial_fitR Documentation

Fitting marginal structural model (MSM) within quantile g-computation


This is an internal function called by qgcomp.multinomial.boot, but is documented here for clarity. Generally, users will not need to call this function directly.


  main = TRUE,
  degree = 1,
  id = NULL,
  bayes = FALSE,
  MCsize = nrow(qdata),
  hasintercept = TRUE,



an r formula representing the conditional model for the outcome, given all exposures and covariates. Interaction terms that include exposure variables should be represented via the AsIs function


a data frame with quantized exposures


sequence, the sequence of integer values that the joint exposure is 'set' to for estimating the msm. For quantile g-computation, this is just 0:(q-1), where q is the number of quantiles of exposure.


a character vector with the names of the columns in qdata that represent the exposures of interest (main terms only!)


logical, internal use: produce estimates of exposure effect (psi) and expected outcomes under g-computation and the MSM


polynomial bases for marginal model (e.g. degree = 2 allows that the relationship between the whole exposure mixture and the outcome is quadratic. Default=1)


(optional) NULL, or variable name indexing individual units of observation (only needed if analyzing data with multiple observations per id/cluster)


"case weights" - passed to the "weight" argument of glm or bayesglm


use underlying Bayesian model (arm package defaults). Results in penalized parameter estimation that can help with very highly correlated exposures. Note: this does not lead to fully Bayesian inference in general, so results should be interpreted as frequentist.


integer: sample size for simulation to approximate marginal zero inflated model parameters. This can be left small for testing, but should be as large as needed to reduce simulation error to an acceptable magnitude (can compare psi coefficients for linear fits with qgcomp.zi.noboot to gain some intuition for the level of expected simulation error at a given value of MCsize)


(logical) does the model have an intercept?


arguments to glm (e.g. family)


This function first computes expected outcomes under hypothetical interventions to simultaneously set all exposures to a specific quantile. These predictions are based on g-computation, where the exposures are ‘quantized’, meaning that they take on ordered integer values according to their ranks, and the integer values are determined by the number of quantile cutpoints used. The function then takes these expected outcomes and fits an additional model (a marginal structural model) with the expected outcomes as the outcome and the intervention value of the exposures (the quantile integer) as the exposure. Under causal identification assumptions and correct model specification, the MSM yields a causal exposure-response representing the incremental change in the expected outcome given a joint intervention on all exposures.

See Also

qgcomp.glm.boot, and qgcomp


data("metals") # from qgcomp package
# create categorical outcome from the existing continuous outcome (usually, one will already exist)
metals$ycat = factor(quantize(metals, "y",q=4)$data$y, levels=c("0", "1", "2", "3"), 
                     labels=c("cct", "ccg", "aat", "aag")) 
# restrict to smaller dataset for simplicity
smallmetals = metals[,c("ycat", "arsenic", "lead", "cadmium", "mage35")]

### 1: Define mixture and underlying model ####
mixture = c("arsenic", "lead", "cadmium")
f0 = ycat ~ arsenic + lead + cadmium # the multinomial model 
# (be sure that factor variables are properly coded ahead of time in the dataset)
qdat <- quantize(smallmetals, mixture, q=4)$data
mod <- msm_multinomial_fit(f0,
        expnms = mixture, qdata=qdat, intvals=1:4, bayes=FALSE)
summary(mod$fit) # outcome regression model
summary(mod$msmfit) # msm fit (variance not valid - must be obtained via bootstrap)

qgcomp documentation built on Aug. 10, 2023, 5:07 p.m.