Additional Functions for the MatchIt Package – Part 2

I have reworked the graphing and summarizing functions I wrote for the matchit package to be cleaner and to provide more information.

Currently I have functions for a sorted by size summary table of the post matching mean differences:

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
}

A graph function (histogram and density plot) for both pre-matched mean differences:

all_meandiffplot <- function (x) {
	adiff<-data.frame(x$sum.all)
	names(adiff)[4]<-c("all_mean_diff")
	diffplot<-ggplot(adiff, aes(all_mean_diff) )
	diffplot<- diffplot+ geom_histogram (fill="grey")
	diffplot<- diffplot+ geom_density (colour="red")
	diffplot<-diffplot+xlim(-.5, .5)
	diffplot
	}

and after matching mean differences:

matched_meandiffplot <- function (x) {
	mdiff<-data.frame(x$sum.matched)
	names(mdiff)[4]<-c("matched_mean_diff")
	diffplot<-ggplot(mdiff, aes(matched_mean_diff) )
	diffplot<- diffplot+ geom_histogram (fill="grey")
	diffplot<- diffplot+ geom_density (colour="red")
	diffplot<-diffplot+xlim(-.5, .5)
	diffplot
	}

Not that both plots are on a scale from -.5 to .5 so that they can easily be compared.

Finally I have a set of simple tables which indicate how many “large” (>.25), “medium” (>.20) and “small” (<.20) standardized mean differences there were before matching:

all_meandiffcount<-function (x){
	all<-data.frame(x$sum.all[4])
	all$all_group[all[1] > .25]<- "Large"
 	all$all_group[all[1] < -.25] <- "Large"
	all$all_group[all[1] > .20 & all[1] < .25 ] <- "Medium"
	all$all_group[all[1] < -.20 & all[1] > -.25] <- "Medium"
	all$all_group[all[1] < .20 & all[1] > .00]<- "Small"
	all$all_group[all[1] > -.20 & all[1] < .00] <- "Small"
	table(all$all_group)
}

and after matching:

matched_meandiffcount<-function (x){
	matched<-data.frame(x$sum.matched[4])
	matched$matched_group[matched[1] > .25]<- "Large"
 	matched$matched_group[matched[1] < -.25] <- "Large"
	matched$matched_group[matched[1] > .20 & matched[1] < .25 ] <- "Medium"
	matched$matched_group[matched[1] < -.20 & matched[1] > -.25] <- "Medium"
	matched$matched_group[matched[1] < .20 & matched[1] > .00]<- "Small"
	matched$matched_group[matched[1] > -.20 & matched[1] < .00] <- "Small"
	table(matched$matched_group)
}
Advertisements

About Philip Parker

I am a post doc in developmental and educational psychology at a Germany university. I did my PhD at the university of Sydney in stress and well-being. Most days I am hunched over a computer yelling at statistical software or responding to journal editors who seem to always want twice the amount of content but with half the words. For fun I like to read up on the latest developments in R and programming various functions.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s