### Download and install MatchIt install.packages("MatchIt") library(MatchIt) ### Read your data into R trialdata=read.csv("nameofyourfile.csv") ### First let's include ONLY the variables we will be working with ### So let's get rid of "OutpatientCost", "InpatientCost" and ### "Residential" ...keep olny total cost trialdata=trialdata[,-(1:3)] ### Perform the following regression m.out=matchit(trialdata[,2]~ trialdata[,3] + trialdata[,4] + trialdata[,5] + trialdata[,6] + trialdata[,7] + trialdata[,8] +trialdata[,9] + trialdata[,10] + trialdata[,11] + trialdata[,12] + trialdata[,13] + trialdata[,14] + trialdata[,15] + trialdata[,16] + trialdata[,17] + trialdata[,18] + trialdata[,19] + trialdata[,20] + trialdata[,21] + trialdata[,22] + trialdata[,23] + trialdata[,24] + trialdata[,25] + trialdata[,26] + trialdata[,27] + trialdata[,28] + trialdata[,29] + trialdata[,30] + trialdata[,31] + trialdata[,32] +trialdata[,33] + trialdata[,34] + trialdata[,35] + trialdata[,36] + trialdata[,37] + trialdata[,38] + trialdata[,39] + trialdata[,40] + trialdata[,41] , data=trialdata,method="exact") ### Now let's find the weights generated by propensity score matching for ### the entire data set m.data=match.data(m.out) fix(m.data) ### Now perform a weighted regression gweights=lm(m.data[,1]~.,data=m.data[,(2:41)],weights=m.data[,42]) summary(gweights) ### and once without weights gnoweights=lm(m.data[,1]~.,data=m.data[,(2:41)]) summary(gnoweights)