Skip to content
/ causl Public

Methods for Specifying, Simulating from and Fitting Causal Models

Notifications You must be signed in to change notification settings

rje42/causl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

causl

Methods for Specifying, Simulating from, and Fitting Marginal Causal Models

Basic Idea

This package enables one to simulate from a frugal parameterization, that is one where we have a specific marginal causal quantity of interest and use something like a copula to model its dependence structure. More details can be found in Evans and Didelez (2024).

Example: Marginal structural model

graph TD
    A(Z) --> B(X)
    B --> C(Y)
    A --> C
Loading

Suppose we have the causal model above, and are interested in a marginal structural model (MSM): $P(y \mid do(x)) = \sum_z P(z) \cdot P(y \mid z, x).$ A frugal parameterization for this quantity would be a parametric model for $P(y \mid do(x))$, another for $P(z,x)$, and a third for the dependence between $Y$ and $Z$ conditional on $X$. We could use a (conditional) copula for this last model, or a conditional odds ratio if $Y$ and $Z$ are both discrete.

One example would consist of setting $Z \sim \text{Exp}(1)$, with $X \mid Z=z \sim N(z/2, 1)$ and $Y \mid do(X=x) \sim N((x-1)/2, 1)$, with a Gaussian copula between $Z$ and $Y$ with correlation $\rho = 2\text{expit}(1) - 1$. (Note that, by default, we use the log link for the Gamma distribution.)

Sample Code

We can specify such a marginal causal model with the following syntax.

# formulae corresponding to covariates, treatments, outcomes and the dependence
forms <- list(Z ~ 1, X ~ Z, Y ~ X, ~ 1)
# vector of model families (3=gamma/exponential, 1=normal/Gaussian)
fam <- c(3, 1, 1, 1)
# list of parameters, including 'beta' (regression params) and 'phi' dispersion
pars <- list(Z = list(beta=log(1), phi=1),   # note log-link
             X = list(beta=c(0,0.5), phi=1),
             Y = list(beta=c(-0.5,0.5), phi=1),
             cop = list(beta=1))

## now create a `causl_model` object
cm <- causl_model(formulas=forms, family=fam, pars=pars)

# now simulate 100 observations
rfrugal(n=100, causl_model=cm)

Note that, by default, we use the log link for the Gamma distribution.

Reference

Evans, R.J. and Didelez, V. Parameterizing and simulating from causal models (with discussion). Journal of the Royal Statistical Society, Series B (to appear), 2024.

About

Methods for Specifying, Simulating from and Fitting Causal Models

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •