My first post in blogger is about Propensity Score Matching (PSM) in R. In this post I will introduce the R packages MatchIt and Zelig. The first one is devoted to perform different PSM algorithms and the other one is used in order to estimate the average treatment effect (ATE) and the effect of the treatment on the treated (ATT). First of all, I will simulate a population where some individuals receive the treatment, and the remaining ones do not.
N <- 1000
f <- 1 + 1*x1 - 0.28*x2
y <- rep(0, times=N)
# Different values for y over z# The mean difference for y is 5000
y[z == 1] <- 9000 + 2*x1[z == 1] + 0.5*x2[z == 1]
y[z == 0] <- 4000 + 2*x1[z == 0] + 0.5*x2[z == 0]
Data <- data.frame(y=y, x1=x1, x2=x2, z)
# The treatment population
Treats <- subset(Data, z == 1)
# The control population
# Computing the real effect of the treatment
Effect <- model$coeff Effect
Then I will run a logistic regression in order to estimate the propensity scores. That is the probability of receiving the treatment.
Nearest neighbour matching (NNM) is an algorithm that matches individuals with controls (it could be more two or more controls per treated unit) one by one based on a distance.
#Nearest neighbor matching
summary(m3.ps, covariates = T)
m3.data <- match.data(m3.ps)
Optimal matching solves the problem inherent to the NNM, that matches units one at a time, without taking into account any global (over the entire population) distance measure. This way, with NNM the last treated unit could could match an inappropriate unit.
Full matching forms subgroups in an optimal way.
summary(m4.ps, covariates = T)
m4.data <- match.data(m4.ps)
Caliper matching is a refinement of the NNM. It defines a constraint over the individual distant measure. So, it minimises the probability of bad matching.
# Caliper matching
summary(m8.ps, covariates = T)
m8.data <- match.data(m8.ps)
m8.data.control <- match.data(m8.ps,"control")
m8.data.treat <- match.data(m8.ps,"treat")
Finally, with the matched data, we estimate the average treatment effects, via automatic simulation, with the Zelig package.
Zelig package also allows to estimate the effect on the treated, and the effect on the controls.
# Average Treatment Effect on the Controls
s.out1 <- sim(z1c.ps, x = x.out1)summary(s.out1)
# Average Treatment Effect on the Treated
s.out2 <- sim(z1t.ps, x = x.out2)