(This article by Philip Parker was originally published at Adventures in R.)
Have been attending a seminar on propensity score matching this week, when I was asked if I could write a function to reduce the complexity of the matchit package output. I produced two functions.
First I wrote a function to produce a histogram of the matched mean differences which gives a nice summary of how well the matching procedure has achieved balance (note you need to install the package ggplot2 to use this function):
meandiffplot <- function (x) { mdiff<-data.frame(x$sum.matched) names(mdiff)[4]<-c("m_mean_diff") diffplot<-ggplot(mdiff, aes(m_mean_diff) ) diffplot<- diffplot+ geom_histogram (fill="grey") diffplot<- diffplot+ geom_density (colour="red") diffplot }
Next I produced a function the reports only those matched mean differences with a standardized difference of over .1 (sorted by absolute size).
meandifftable<- function (x){ post<-data.frame(x$sum.matched[4]) matchID <- as.vector (row.names (post) ) names(post)[1]<-c("m_mean_diff") post$absolute<- abs(post[1]) total2<-post[order (-post$absolute, na.last=NA) ,] meandiffover1<- subset(total2[1], total2[1]> .1 | total2[1]< -.1) meandiffover1 }
If you use the matchit package I think these functions are really useful.
Please comment on the article here: http://adventuresinr.wordpress.com/2010/11/02/simplified-output-for-matchit-package/
