# C Methods for Estimating Propensity Scores

This appendix provide R code for multiple statistical models for estimating propensity scores. The examples use the `lalonde`

dataset with the following formula:

```
lalonde.formu <- treat ~ age + I(age^2) + educ + I(educ^2) + black +
hisp + married + nodegr + re74 + I(re74^2) + re75 + I(re75^2) +
u74 + u75
```

## C.6 Random Forests

```
library(randomForest)
rf_out <- randomForest(update.formula(lalonde.formu, factor(treat) ~ .),
data = lalonde)
# For classification
rf_strata <- predict(rf_out, type = 'response')
# For matching or weighting
rf_ps <- predict(rf_out, type = 'prob')[,1,drop=TRUE]
```