This function computes the balance statistics before and after matching.
balance(rawdata, matched, pscore.fit, factor=TRUE)# S3 method for balance
print(x, …, digits = 2)
# S3 method for balance
plot(x, longcovnames = NULL,
main = "Standardized Difference in Means",
v.axis=TRUE, cex.main = 1,
cex.vars = 0.8, cex.pts = 0.8,
mar=c(0,3,5.1,2), plot=TRUE, …)
data before using matching
function, see the example below.
matched data using matching
function, see the example below.
glm.fit object to get propensity scores.
default is TRUE
which will display the factorized categorical variables. In
a situation where no equal levels of factorized categorical variables is observed,
use factor=FALSE to proceed.
an object return by the balance function.
minimal number of significant digits, default is 2.
long covariate names. If not provided, plot will use covariate variable name by default
The main title (on top) using font and size (character
expansion) par("font.main")
and color par("col.main")
;
default title is Standardized Difference in Means
.
default is TRUE
, which shows the top axis--axis(3).
font size of main title
font size of variabel names
point size of the estimates
A numerical vector of the form c(bottom, left, top, right)
which gives the number of lines of margin to be specified on
the four sides of the plot. The default is c(0,3,5.1,2)
.
default is TRUE
, which will plot the plot.
other plot options may be passed to this function
This function plots the balance statistics before and after matching. The open circle dots represent the unmatched balance statistics. The solid dots represent the matched balance statistics. The closer the value of the estimates to the zero, the better the treated and control groups are balanced after matching.
Andrew Gelman and Jennifer Hill. (2006). Data Analysis Using Regression and Multilevel/Hierarchical Models. Cambridge University Press. (Chapter 10)
# NOT RUN {
# matching first
old.par <- par(no.readonly = TRUE)
data(lalonde)
attach(lalonde)
fit <- glm(treat ~ re74 + re75 + age + factor(educ) +
black + hisp + married + nodegr + u74 + u75,
family=binomial(link="logit"))
pscores <- predict(fit, type="link")
matches <- matching(z=lalonde$treat, score=pscores)
matched <- lalonde[matches$matched,]
# balance check
b.stats <- balance(lalonde, matched, fit)
print(b.stats)
plot(b.stats)
par(old.par)
# }
Run the code above in your browser using DataLab