step psm r

6
7/21/2019 step psm R http://slidepdf.com/reader/full/step-psm-r 1/6  A peer-reviewed electronic journal. Copyright is retained by the first or sole author, who grants right of first publication to Practical Assessment, Research & Evaluation. Permission is granted to distribute this article for nonprofit, educational purposes if it is copied in its entirety and the journal is credited. PARE has the right to authorize third party reproduction of this article in print, electronic and database forms.  Volume !, "umber #, "o$ember %&' ())" *+--'  A Step-by-Step Guide to Propensity Score Matching in R  ustus . Randolph, /ristina 0albe, Austin /ureethara 1anuel, oseph 2. 3alloun  Mercer University Propensity score matching is a statistical techni4ue in which a treatment case is matched with one or more control cases based on each case5s propensity score. 6his matching can help strengthen causal arguments in 4uasie7perimental and obser$ational studies by reducing selection bias. (n this article  we concentrate on how to conduct propensity score matching using an e7ample from the field of education. 8ur goal is to pro$ide information that will bring propensity score matching within the reach of research and e$aluation practitioners.  Propensity score matching is a statistical techni4ue in which a treatment case is matched with one or more control cases based on each case5s propensity score.  6his matching can help strengthen causal arguments in 4uasie7perimental and obser$ational studies by reducing selection bias. 3ecause there ha$e been many thorough e7planations and rationales for propensity score matching published elsewhere 9Adelson, %&+: ;olland, !#<: Rubin, %&&*: Rudner = Peyton, %&&<: )hadish, Coo>, = Campbell, %&&%: )tone = 6ang, %&+?, in this article we will concentrate on how to conduct propensity score matching using an e7ample from the field of education. )pecifically, in this document we pro$ide a stepbystep e7ample of conducting propensity score matching in R using the 1atch(t pac>age with nearestneighbor to matching. @hile there is other software than R for conducting propensity score matching, we ha$e chosen  R because it is opensource software and is widely used by data scientists across many different fields. 8ur goal in this article is to pro$ide information that will bring propensity score matching within the reach of research and e$aluation practitioners. Information on the Dataset Used Here ata from an obser$ational study by 0albe 9%&'? are used here to illustrate propensity score matching. (n that study, 0albe used publicly a$ailable schoolle$e data from se$eral states to in$estigate whether an inter$ention 9i.e., being designated a )chools to @atch B 9 stw  ? school? was a predictor of success in reading and mathematics achie$ement, when controlling for school size 9 tot  ?, percentage of minority students 9 min  ? and percentage of students recei$ing free and reduced lunch 9 dis  ?. 0or our e7ample here, we use 0albe5s schoolle$el data only from the state of "ew or>. (n the "ew or> data set, there were %* stw  schools and *<& nonstw  schools. As matching $ariables, 0albe chose school size, percentage of minority students, and percentage of students recei$ing free and reduced lunch. ;er rationale for choosing those matching  $ariables was that pre$ious research had shown that they tended to co$ary with academic achie$ement. 3y matching on those $ariables, her goal was to reduce selection bias between Dtreated 9i.e., stw  ? and Dcontrol 9i.e., nonstw  ? schools. "ote that although 0albe5s study  was correlational and not e7perimental, we use the

Upload: rr

Post on 09-Mar-2016

228 views

Category:

Documents


0 download

DESCRIPTION

ss

TRANSCRIPT

Page 1: step psm R

7/21/2019 step psm R

http://slidepdf.com/reader/full/step-psm-r 1/6

 

A peer-reviewed electronic journal.

Copyright is retained by the first or sole author, who grants right of first publication to Practical Assessment, Research & Evaluation. Permissionis granted to distribute this article for nonprofit, educational purposes if it is copied in its entirety and the journal is credited. PARE has the

right to authorize third party reproduction of this article in print, electronic and database forms. Volume !, "umber #, "o$ember %&' ())" *+--'

 A Step-by-Step Guide to Propensity Score Matching in R

 ustus . Randolph, /ristina 0albe, Austin /ureethara 1anuel, oseph 2. 3alloun Mercer University

Propensity score matching is a statistical techni4ue in which a treatment case is matched with one ormore control cases based on each case5s propensity score. 6his matching can help strengthen causalarguments in 4uasie7perimental and obser$ational studies by reducing selection bias. (n this article we concentrate on how to conduct propensity score matching using an e7ample from the field ofeducation. 8ur goal is to pro$ide information that will bring propensity score matching within thereach of research and e$aluation practitioners. 

Propensity score matching is a statistical techni4uein which a treatment case is matched with one or morecontrol cases based on each case5s propensity score. 6his matching can help strengthen causal arguments in4uasie7perimental and obser$ational studies byreducing selection bias. 3ecause there ha$e been manythorough e7planations and rationales for propensityscore matching published elsewhere 9Adelson, %&+:;olland, !#<: Rubin, %&&*: Rudner = Peyton, %&&<:)hadish, Coo>, = Campbell, %&&%: )tone = 6ang,%&+?, in this article we will concentrate on how toconduct propensity score matching using an e7amplefrom the field of education. )pecifically, in thisdocument we pro$ide a stepbystep e7ample ofconducting propensity score matching in  R using the

1atch(t pac>age with nearestneighbor tomatching. @hile there is other software than  R forconducting propensity score matching, we ha$e chosen R because it is opensource software and is widely usedby data scientists across many different fields. 8ur goalin this article is to pro$ide information that will bringpropensity score matching within the reach of researchand e$aluation practitioners.

Information on the Dataset UsedHere

ata from an obser$ational study by 0albe 9%&'?

are used here to illustrate propensity score matching. (nthat study, 0albe used publicly a$ailable schoolle$edata from se$eral states to in$estigate whether aninter$ention 9i.e., being designated a )chools to @atchB 9 stw  ? school? was a predictor of success in readingand mathematics achie$ement, when controlling forschool size 9 tot  ?, percentage of minority students 9 min  ?and percentage of students recei$ing free and reducedlunch 9 dis  ?. 0or our e7ample here, we use 0albe5sschoolle$el data only from the state of "ew or>. (nthe "ew or> data set, there were %* stw   schools and

*<& nonstw   schools. As matching $ariables, 0albechose school size, percentage of minority students, andpercentage of students recei$ing free and reducedlunch. ;er rationale for choosing those matching $ariables was that pre$ious research had shown thatthey tended to co$ary with academic achie$ement. 3ymatching on those $ariables, her goal was to reduceselection bias between Dtreated 9i.e., stw  ? and Dcontrol9i.e., nonstw  ? schools. "ote that although 0albe5s study was correlational and not e7perimental, we use the

Page 2: step psm R

7/21/2019 step psm R

http://slidepdf.com/reader/full/step-psm-r 2/6

Practical Assessment, Research & Evaluation, Vol 19, No 1 Page % Randolph = 8thers, Propensity )core 1atching

terms treated and control here because those are the termsreported in the output of the 1atch(t pac>age.

The Steps in ConductingPropensity Score Matching in R

Step 1. Install R.

R   is a free statistical pac>age that can bedownloaded from the FR2 in the R Core 6eam 9%&'?reference in the References section of this article.)pecific installation instructions are pro$ided afterdownloading and opening the software.  R is a$ailablefor @indows, 1ac 8) G, and 2inu7 operating systems. 6he directions presented in this article are based on R   $ersion +.&.+.

Step 2. Install and load the MatchIt package.

1atch(t is an R pac>age that easily enables R usersto conduct propensity score matching: specificinformation on the 1atch(t pac>age can be found from;o, /oso>e, /ing, and )tuart 9%&&-a, %&&-b, %&,%&+?. 6o use the 1atch(t pac>age, you must firstinstall and load it. ou only need to install 1atch(t thefirst time you use it: howe$er, you will need to load iteach time you reopen R software.

 6o install a pac>age, open  R and select Pac>ages

menu from the top of the screen. 6hen choose (nstallPac>age9s?. . . A popup window, CRA" 1irror, will bedisplayed. Choose the site you prefer from the list andclic> 8/. Another window labeled DPac>ages will bedisplayed. )croll down the list in the window to select1atch(t and clic> 8/. 6he pac>age will getdownloaded immediately.

"e7t, to load the 1atch(t pac>age, choose 2oadPac>ageH from the dropdown menu under thePac>ages menu in R. A window D)elect one with thelist of a$ailable pac>ages will be displayed. Choose

1atch(t from the list and hit 8/. 6he 1atch(t pac>ageshould now be loaded. ou should only ha$e to installthe pac>age one time. ;owe$er, you will need to loadthe 1atch(t pac>age in R e$ery time you wish to run it.

Step 3. Prepare and load the data.

 6o perform propensity score matching, you willneed a data set that consists of cases in rows and $ariables in columns. ou will need a grouping $ariable and one or more matching $ariables. 6he

grouping $ariable is the $ariable that specifies whichgroup a case belongs to 9e.g., treatment or control? 6he matching $ariables are the ones that you want toattempt to e4ualize the groups on. 0or e7ample, in the0albe 9%&'? data set, the stw $ariable is the grouping

 $ariable. (t specifies whether a particular case 9aschool? has been designated as a )chools to @atch Bschool 9? or not 9&?. 6he other $ariables tot 9schoolsize?, min 9percentage of minority students in theschool?, and dis 9percentage of students recei$ing freeand reduced lunch? are the matching $ariables. 6hedataset we used here can be downloaded fromRandolph 9%&'a?. (n your own datasets, ma>e surethat there are no missing data or R may not be able toperform the analysis.

 Although there are functions to import E7cel

)P)), or other data formats into R, we ha$e found it ismost con$enient to sa$e it as a .cs$ file before trying toload the data into R. @hen you sa$e the file in E7cel,you will ha$e the option to sa$e it as a .cs$ file. As yousa$e the file, note its location.

"e7t, you will need to replace the file locationbetween the parentheses in the first line of   R code in0igure with your own file location. "ote that in thefirst line, forward slashes rather than bac>slashes areused to specify the file location. 6he e7ample below is afile location in @indows, where the data are located in

a file called newyork.csv  in folder called r on theC dri$e. 6he first line of code reads the data from yourcomputer and renames it mydata. 6he second linema>es those data a$ailable in the current  R session 6he third line of the code below prints the $ariablenames and the first ten cases in the data set. @e do thisjust to chec> the data set and understand what eachcolumn represents.

mydata <- read.csv ("C:/r/newyork.csv")

attach(mydata)

mydata[1:10,] igure 1. Code e7ample for inputting a data set.

0igure % shows the results of running the code in0igure . (t shows the first ten cases in the data set and what $ariables are included in the columns. (t showsthat the columns from left to right are the case number9a uni4ue id number for each school?, school 9the nameof each school?, tot 9the total number of students in theschool?, min 9the percentage of minority students in theschool?, dis 9the number of students recei$ing free or

Page 3: step psm R

7/21/2019 step psm R

http://slidepdf.com/reader/full/step-psm-r 3/6

Practical Assessment, Research & Evaluation,

Randolph = 8thers, Propensity )core 1

reduced lunch?, and stw 9whether a schooas 9? )chools to @atch B or 9&? not?.

igure 2. Results of running the code infirst ten cases are displayed.

Step !. Per"or# #atching and e$results.

 6he ne7t step is to perform the

e$aluate the results. 6he first line in the0igure + performs the matching where $ariable is stw and the $ariables being mtot, min, and dis. ou will need to $ariable names in the code with the $ariyour own data set. 6he method commaspecifies that the nearest neighbor metho 6he ratio command indicates onetooe$ery treatment case will be matched wicase. ou can increase the number ofmatched to each treatment case by i

number: usually this number is between

m.out = matchit(stw ~ tot + mi

data = mydata, method = "

ratio = 1)

summary(m.out)

plot(m.out, type = "jitter")

plot(m.out, type = "hist") 

igure 3. Code to perform propensity scand get results.

 6here are many matching methodused: a short description of them can blist below. @e encourage 1atch(t usersdifferent matching methods to see wor>s best for a particular data set. (ntried all of the matching methods curren1atch(t and chose the nearest neigbecause it resulted in the lowest mebetween groups. )ome of the other methe installation of additional pac>ages.

Vol 19, No 1

tching

l is designated

igure . 6he

aluate the

matching and

ode shown inthe groupingatched on arereplace these

able names ofd in 0igure +

d will be used.e matchingI 

  h one controlcontrol casescreasing this

and *.

n + dis,

nearest",

re matching

that can befound in the

to try out thehich methodthis case, we

tly a$ailable inhbor methodn differencesthods call for

  E7act 1atching J 6his

treated unit with a cothe same $alues on eaare many co$ariates ata>e a large range of $

not be possible 9meth

 

)ubclassification J 6data set into subdistributions of theeach subclass 9method

  "earest "eighbor Jtreated unit to a contrterms of a distance9method L Dnearest?.

  8ptimal 1atching J

minimizing the a$eragall matched pairs 9memethod of matchingpac>age.

  Menetic 1atching Jcomputationally intalgorithm to match tr9method L Dgenetic?pac>age.

  Coarsened E7act 1techni4ue matchesmaintaining the balancclaimed to wor>treatments, determinidesigns, andcounterfactuals 9;o,%&, p.%? 9

)ee the documentationdetails on the matching me9;o, /osu>e, /ing, = )tew%&+?.

 6he results of matchingcalled m.out. 6he second linea summary of the matching rthird and fourth lines prhistograms.

 6he results show that mfor this data set. (n the summsection of 0igure ', before mof students 9tot? in the tr

Page + 

techni4ue matches eachtrol unit that has e7actly

ch co$ariate. @hen theredKor co$ariates that canlues, e7act matching may

d L De7act?.is techni4ue brea>s thelasses such that theo$ariates are similar inL Dsubclass?.

his techni4ue matches al unit9s? that is closest ineasure such as a logit

his techni4ue focuses on

absolute distance acrossthod L Doptimal?. 6hisre4uires the optmatch

 6his techni4ue uses ansi$e genetic searchatment and control units. (t re4uires the 1atching

atching J 0inally, thison a co$ariate whilee of other co$ariates. (t is well for multicategoryg bloc>s in e7perimentae$aluating e7treme

/osu>e, /ing, = )tuartethod L Dcem?

on 1atch(t for morehods mentioned abo$eart, %&&-a, %&&-b, %&

are sa$ed in a $ariableof code in 0igure + printssults 9see 0igure '?. 6heduce jitter plots and

tching wor>ed $ery welry of balance for all datatching the mean numbereated schools 9i.e., stw

Page 4: step psm R

7/21/2019 step psm R

http://slidepdf.com/reader/full/step-psm-r 4/6

Practical Assessment, Research & Evaluation,

Randolph = 8thers, Propensity )core 1

schools? was %<+.-' students less than9i.e., nonstw schools? schools. 6he treatN less minority students 9min? and %%students of po$erty 9dis? than controlmatching, howe$er, those differendramatically as shown in the summarymatched data section of 0igure '. 6he min number of students between treateschools reduced to %: it was %<+ beforepercent difference in minority students band control schools reduced to N: it wmatching. 0inally, the mean difference band control schools in terms ofimpo$erished students reduced to +K&th

it was %%N before matching. (n short, tcontrol schools after matching are $eryterms of number of students, percentastudents, and percentage of students recreduced lunch. 3efore matching, the t were on a$erage larger, had less minorityhad less impo$erished students than co 6he rightmost columns in these summthe median, mean, and ma7imum 4uartbetween the treated and control data: $alues indicates better matching. "ote

igure !. Results showing the eff

Vol 19, No 1

tching

in the controld schools had

percent lesschools. Afterces reducedf balance for

ean differenceand controlatching. 6he

tween treateds N beforetween treatedpercent of

s of a percent:

e treated andimilar now ine of minorityi$ing free andeated schoolsstudents, andntrol schools.ry data showiledifferences

smaller OOthat the OO

 $alues are all smaller aftermatching. 6he third and fou0igure % creates jitter plots athe 4uality of the matching.

0igure * is a jitter plot wa case5s propensity score. 6huppermost stratification indiunmatched treatment units.show the close match betweethe matched control units.shows the unmatched control

igure %. istribution of pro

ecti$eness of the propensity scores matching.

Page ' 

matching than beforerth lines of the code ind histograms to $isualize

ere each circle representsabsence of cases in the

ates that there were nohe middle stratificationsthe treatment units and

 6he final stratificationunits, which will not be

ensity scores.

Page 5: step psm R

7/21/2019 step psm R

http://slidepdf.com/reader/full/step-psm-r 5/6

Practical Assessment, Research & Evaluation,

Randolph = 8thers, Propensity )core 1

used in any followup analyses. 0igurehistograms before and after matching. 6before matching on the left differ to a 6he histograms after matching on thesimilar howe$er. (n sum, both the numer

data show that the matching was successf

Step %. &'port a data "ile to do " analyses

8nce the matching has been comp want to create a data set that only hascases to do follow up statistical analysesdata are matched. (n 0igure -, the firscreates an R data set that only has the mand treatment cases 9i.e., it deleted thecases that were unmatched.? 6he seconcon$erts the matched data set bac> intocan either be further analyzed in  R orother statistical software: in this case, t

set was sa$ed as a file callednewyork_ 

a folder called r on the C dri$e. 96he mafor the "ew or> data can be dowRandolph 9%&'b??.

m.data1 <- match.data(m.out)

write.csv(m.data1, file =

"C:/r/newyork_nearest100.

igure ). Code to output a matched data

igure *. ;istograms of propensity scorafter matching.

Vol 19, No 1

tching

< shows thehe histogramsgreat degree.

right are $eryical and $isual

ul.

llo(-up

leted, you willthe matchednow that the

t line of codetched control*&& controld line of dataa .cs$ file thate7ported intoe output dataearest1

 intched data setnloaded from

csv") 

set.

(n terms of the follow was interested in whether stwthan nonstw schools inachie$ement. 6o do thatmathematics achie$ement sco

set and predicted mathemfollowing $ariablesQ whether aan stw school or not, the schominority students in a schoostudents who recei$ed free oout that matching was importmatching, stw schools hadbetter achie$ement than non with matching, 0able founddifference between stw andof academic achie$ement.matching, 0albe would haconclusion about the efficacyli>ely as a result of selection bi

(t is clear that propensuseful tool for reducinstrengthening causal conclusistepbystep guide will enaresearchers and e$aluators tmatching to their repertoire o

Refer

 Adelson, . 2. 9%&+?. EducationdataQ Reducing selection biaanalysis. Practical Assessme#9*?. Retrie$ed fromhttpQKKpareonline.netKget$n

0albe, /. 9%&'?. 6he relationshi @atch B designation and astudy of Colorado, "ew o9octoral dissertation?. A$aissertations and 6heses da

;o, ., /osu>e, (., /ing, M., ="onparametric preprocessi

inference. Political Analysis,;o, ., /osu>e, (., /ing, M., =

as nonparametric preprocesdependence in parametric c)tatistical )oftware. Retrie$httpQKKg>ing.har$ard.eduKm

;o, ., /osu>e, (. /ing, M., = )"onparametric preprocessiinference Ssoftware documehttpQKKg>ing.har$ard.eduKm

 s before and

Page * 

p analysis, 0albe 9%&'?schools performed betterterms of mathematics

analysis, she addedres to the matched data

atics scores from theschool was designated asol size, the percentage ofl, and the percentage ofreduced lunch. (t turns

ant in this case. @ithoutstatistically significantly

stw schools. ;owe$ero statistically significantonstw schools in termsithout propensity scoree come to a differentof the inter$ention, mostas.

ity score matching is aselection bias and

ons. @e hope that thisble a wide $ariety ofo add propensity scoredata analysis techni4ues.

nces

l research with realworld with propensity scoret Research = E$aluation,

.asp$L#=nL* 

between )chools toademic achie$ementQ A>, 8hio, and Virginialable from Pro4uesttabase. 9F1( "o. +*#%-%?

tuart, E. 9%&&-a?. 1atch(tQg for parametric causal

*9+?, !!%+<.tuart, E. 9%&&-b?. 1atchinging for reducing modelusal inference. ournal ofed fromatchitK 

tuart, E. 9%&?. 1atch(tQg for parametric causaltationT. Retrie$ed from

atchit 

Page 6: step psm R

7/21/2019 step psm R

http://slidepdf.com/reader/full/step-psm-r 6/6

Practical Assessment, Research & Evaluation, Vol 19, No 1 Page < Randolph = 8thers, Propensity )core 1atching

;o, ., /osu>e, (., /ing, M., = )tuart, E. 9%&+?. 1atch(tQ"onparametric preprocessing for parametric causalinference SsoftwareT. Retri$ed fromhttpQKKg>ing.har$ard.eduKmatchit 

;olland, P. @. 9!#<?. )tatistics and causal inference. ournal of the American )tatistical Association,#9+!<?, !'*!<&.

Randolph, . . 9%&'a?. "ew or> educational data sete7ample before matching. Retrie$ed fromhttpQKKjustusrandolph.netKpsmKnewyor>.cs$  

Randolph, . . 9%&'b?. "ew or> educational data sete7ample after matching. Retrie$ed fromhttpQKKjustusrandolph.netKpsmKnewyor>Unearest&&.cs$  

R Core 6eam 9%&'?. R+ A language and en$ironment forstatistical computing. 9+.&.+ ? SComputer softwareT.

 Vienna, AustriaQ 0oundation for )tatistical Computing.

Retrie$ed from httpQKKwww.Rproject.orgK.

Rubin . 3. 9%&&*?. Causal inference using potentialoutcomesQ esign, modeling, decisions. ournal of the

 American )tatistical Association, &&9'!<?, +%%++.

Rudner, 2. 1., = Peyton, . 9%&&<?. Consider propensityscores to compare treatments. Practical AssessmentResearch = E$aluation, 9!?. Retrie$ed fromQhttpQKKpareonline.netKget$n.asp$L=nL! 

)hadish, @. R., Coo>, 6. ., = Campbell, . 6. 9%&&%?.E7perimental and 4uasie7perimental designs forgeneralized causal inference. 3oston, 1AQ ;oughton1ifflin.

)tone, C. A. = 6ang, . 9%&+?. Comparing propensity scoremethods in balancing co$ariates and reco$ering impactin small sample educational program e$aluations.Practical Assessment, Research = E$aluation, #9+?.Retrie$ed fromQhttpQKKpareonline.netKget$n.asp$L#=nL+ 

,ote+

 A pre$ious $ersion of this paper was deli$ered at the %&' annual meeting of 1ercer Fni$ersity AtlantaResearch Conference, Atlanta, MA.

itation+

Randolph, ustus ., 0albe, /ristina, 1anuel, Austin /ureethara, = 3alloun, oseph 2. 9%&'?. A )tepby)tep Muide to Propensity )core 1atching in R . Practical Assessment, Research & Evaluation , !9#?. A$ailableonlineQ httpQKKpareonline.netKget$n.asp$L!=nL# 

orresponding Author+

 ustus . Randolph 6ift College of Education1ercer Fni$ersity+&& 1ercer Fni$ersity r. Atlanta, MA +&+'randolphUjj SatT mercer.edu