R package to generate data suitable for Marginal Structural Cox Model fit
This package simulates survival data suitable for fitting Marginal Structural Model.
Installation
library(devtools)
install_github("ehsanx/simMSM")
Loading the package
require(simMSM)
Pulling the help file
?simmsm
Setting working directory to save the generated datafiles
setwd("C:/data") # change working dir
Using this package to generate data in the working directory
simmsm(subjects=2500, tpoints=10, psi=0.3, n=1000)
# This code generates 1000 datasets (takes time!)# 2500 subjects in each datasets# Each subject followed upto 10 time-points (say, months)# Causal effect (log-odds) is 0.3
Parameter
Description
subjects
Number of Subjects in each simulated dataset
tpoints
Maximum number of time-points each subjects are followed
psi
Causal effect parameter for Marginal Structural Model
n
Number of simulated datasets an user wants to generate
Author
Ehsan Karim (only R porting from the SAS code). I wrote them in R basically to understand the mechanism, but the SAS / SAS IML / Stata codes (I have them as well, available upon request) are faster than this. Feel free to report any errors / update suggestions.
Young, Jessica G., et al. Simulation from structural survival models under complex time-varying data structures. JSM proceedings, section on statistics in epidemiology. American Statistical Association, Denver, CO (2008)