Description Usage Arguments Details Value Author(s) References See Also Examples

`CBMSM`

estimates propensity scores such that both covariate balance
and prediction of treatment assignment are maximized. With longitudinal
data, the method returns marginal structural model weights that can be
entered directly into a linear model. The method also handles multiple
binary treatments administered concurrently.

1 2 3 4 5 6 7 8 9 10 11 12 |

`formula` |
A formula of the form treat ~ X. The same covariates are used
in each time period. At default values, a single set of coefficients is estimated
across all time periods. To allow a different set of coefficients for each
time period, set |

`id` |
A vector which identifies the unit associated with each row of treat and X. |

`time` |
A vector which identifies the time period associated with each row of treat and X. All data should be sorted by time. |

`data` |
An optional data frame, list or environment (or object coercible
by as.data.frame to a data frame) containing the variables in the model. If
not found in data, the variables are taken from |

`type` |
"MSM" for a marginal structural model, with multiple time periods or "MultiBin" for multiple binary treatments at the same time period. |

`twostep` |
Set to |

`msm.variance` |
Default is |

`time.vary` |
Default is |

`init` |
Default is |

`...` |
Other parameters to be passed through to |

Fits covariate balancing propensity scores for marginal structural models.

### @aliases CBMSM CBMSM.fit

`weights` |
The optimal weights. |

`fitted.values` |
The fitted propensity score for each observation. |

`y` |
The treatment vector used. |

`x` |
The covariate matrix. |

`id` |
The vector id used in CBMSM.fit. |

`time` |
The vector time used in CBMSM.fit. |

`model` |
The model frame. |

`call` |
The matched call. |

`formula` |
The formula supplied. |

`data` |
The data argument. |

`treat.hist` |
A matrix of the treatment history, with each observation in rows and time in columns. |

`treat.cum` |
A vector of the cumulative treatment history, by individual. |

Marc Ratkovic, Christian Fong, and Kosuke Imai; The CBMSM function is based on the code for version 2.15.0 of the glm function implemented in the stats package, originally written by Simon Davies. This documenation is likewise modeled on the documentation for glm and borrows its language where the arguments and values are the same.

Imai, Kosuke and Marc Ratkovic. 2014. “Covariate Balancing Propensity Score.” Journal of the Royal Statistical Society, Series B (Statistical Methodology). http://imai.princeton.edu/research/CBPS.html

Imai, Kosuke and Marc Ratkovic. 2015. “Robust Estimation of Inverse Probability Weights for Marginal Structural Models.” Journal of the American Statistical Association. http://imai.princeton.edu/research/MSM.html

plot.CBMSM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ```
##Load Blackwell data
data(Blackwell)
## Quickly fit a short model to test
form0 <- "d.gone.neg ~ d.gone.neg.l1 + camp.length"
fit0<-CBMSM(formula = form0, time=Blackwell$time,id=Blackwell$demName,
data=Blackwell, type="MSM", iterations = NULL, twostep = TRUE,
msm.variance = "approx", time.vary = FALSE)
## Not run:
##Fitting the models in Imai and Ratkovic (2014)
##Warning: may take a few mintues; setting time.vary to FALSE
##Results in a quicker fit but with poorer balance
##Usually, it is best to use time.vary TRUE
form1<-"d.gone.neg ~ d.gone.neg.l1 + d.gone.neg.l2 + d.neg.frac.l3 +
camp.length + camp.length + deminc + base.poll + year.2002 +
year.2004 + year.2006 + base.und + office"
##Note that init="glm" gives the published results but the default is now init="opt"
fit1<-CBMSM(formula = form1, time=Blackwell$time,id=Blackwell$demName,
data=Blackwell, type="MSM", iterations = NULL, twostep = TRUE,
msm.variance = "full", time.vary = TRUE, init="glm")
fit2<-CBMSM(formula = form1, time=Blackwell$time,id=Blackwell$demName,
data=Blackwell, type="MSM", iterations = NULL, twostep = TRUE,
msm.variance = "approx", time.vary = TRUE, init="glm")
##Assessing balance
bal1<-balance.CBMSM(fit1)
bal2<-balance.CBMSM(fit2)
##Effect estimation: Replicating Effect Estimates in
##Table 3 of Imai and Ratkovic (2014)
lm1<-lm(demprcnt[time==1]~fit1$treat.hist,data=Blackwell,
weights=fit1$glm.weights)
lm2<-lm(demprcnt[time==1]~fit1$treat.hist,data=Blackwell,
weights=fit1$weights)
lm3<-lm(demprcnt[time==1]~fit1$treat.hist,data=Blackwell,
weights=fit2$weights)
lm4<-lm(demprcnt[time==1]~fit1$treat.cum,data=Blackwell,
weights=fit1$glm.weights)
lm5<-lm(demprcnt[time==1]~fit1$treat.cum,data=Blackwell,
weights=fit1$weights)
lm6<-lm(demprcnt[time==1]~fit1$treat.cum,data=Blackwell,
weights=fit2$weights)
### Example: Multiple Binary Treatments Administered at the Same Time
n<-200
k<-4
set.seed(1040)
X1<-cbind(1,matrix(rnorm(n*k),ncol=k))
betas.1<-betas.2<-betas.3<-c(2,4,4,-4,3)/5
probs.1<-probs.2<-probs.3<-(1+exp(-X1 %*% betas.1))^-1
treat.1<-rbinom(n=length(probs.1),size=1,probs.1)
treat.2<-rbinom(n=length(probs.2),size=1,probs.2)
treat.3<-rbinom(n=length(probs.3),size=1,probs.3)
treat<-c(treat.1,treat.2,treat.3)
X<-rbind(X1,X1,X1)
time<-c(rep(1,nrow(X1)),rep(2,nrow(X1)),rep(3,nrow(X1)))
id<-c(rep(1:nrow(X1),3))
y<-cbind(treat.1,treat.2,treat.3) %*% c(2,2,2) +
X1 %*% c(-2,8,7,6,2) + rnorm(n,sd=5)
multibin1<-CBMSM(treat~X,id=id,time=time,type="MultiBin",twostep=TRUE)
summary(lm(y~-1+treat.1+treat.2+treat.3+X1, weights=multibin1$w))
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.