matching: Single Nearest Neighborhood Matching

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/matching.R

Description

Function for processing matching with propensity score

Usage

1
matching(z, score, replace=FALSE)

Arguments

z

vector of indicators for treatment or control.

score

vector of the propensity scores in the same order as z.

replace

whether the control units could be reused for matching, default is FALSE.

Details

Function for matching each treatment unit in turn the control unit (not previously chosen) with the closest propensity score

Value

The function returns a vector of indices that the corresponding unit is matched to. 0 means matched to nothing.

Author(s)

Jeniffer Hill [email protected]; Yu-Sung Su [email protected]

References

Andrew Gelman and Jennifer Hill. (2006). Data Analysis Using Regression and Multilevel/Hierarchical Models. Cambridge University Press.

See Also

balance

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# matching first
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="response")
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)

Example output

Loading required package: MASS
Loading required package: Matrix
Loading required package: lme4

arm (Version 1.9-3, built: 2016-11-21)

Working directory is /work/tmp

Differences in Means of Unmatched Data
--
                 Treat control   diff diff.std     se      sd
re74           2095.57 2107.03 -11.45     0.00 503.50 5302.42
re75           1532.06 1266.91 265.15     0.08 305.04 3161.65
age              25.82   25.05   0.76     0.11   0.68    7.11
factor(educ)4     0.00    0.00   0.00    -0.09   0.00    0.04
factor(educ)5     0.02    0.00   0.02     0.16   0.01    0.11
factor(educ)6     0.02    0.01   0.01     0.08   0.01    0.11
factor(educ)7     0.01    0.02  -0.01    -0.10   0.01    0.10
factor(educ)8     0.01    0.03  -0.02    -0.12   0.01    0.14
factor(educ)9     0.10    0.08   0.02     0.06   0.03    0.29
factor(educ)10    0.15    0.15   0.00    -0.01   0.03    0.36
factor(educ)11    0.17    0.27  -0.11    -0.26   0.04    0.41
factor(educ)12    0.24    0.27  -0.03    -0.07   0.04    0.44
factor(educ)13    0.21    0.14   0.07     0.19   0.04    0.38
factor(educ)14    0.04    0.02   0.02     0.14   0.02    0.17
factor(educ)15    0.03    0.01   0.02     0.15   0.01    0.13
factor(educ)16    0.01    0.00   0.01     0.10   0.01    0.05
black             0.01    0.00   0.01     0.10   0.01    0.05
hisp              0.84    0.83   0.02     0.04   0.04    0.37
married           0.06    0.11  -0.05    -0.17   0.03    0.28
nodegr            0.19    0.15   0.04     0.09   0.04    0.38
u74               0.71    0.83  -0.13    -0.30   0.04    0.42
u75               0.71    0.75  -0.04    -0.09   0.04    0.44
--

Differences in Means of Matched Data
--
                 Treat control   diff diff.std     se      sd
re74           2095.57 1744.47 351.11     0.07 503.50 5302.42
re75           1532.06 1410.79 121.27     0.04 305.04 3161.65
age              25.82   24.85   0.97     0.14   0.68    7.11
factor(educ)4     0.02    0.01   0.02     0.37   0.01    0.04
factor(educ)5     0.02    0.01   0.01     0.05   0.01    0.11
factor(educ)6     0.01    0.01   0.00     0.00   0.01    0.11
factor(educ)7     0.01    0.01   0.01     0.05   0.01    0.10
factor(educ)8     0.10    0.10  -0.01    -0.04   0.02    0.14
factor(educ)9     0.15    0.18  -0.03    -0.11   0.03    0.29
factor(educ)10    0.17    0.16   0.01     0.01   0.04    0.36
factor(educ)11    0.24    0.30  -0.06    -0.14   0.04    0.41
factor(educ)12    0.21    0.19   0.02     0.05   0.04    0.44
factor(educ)13    0.04    0.03   0.02     0.04   0.03    0.38
factor(educ)14    0.03    0.01   0.02     0.09   0.01    0.17
factor(educ)15    0.01    0.00   0.01     0.04   0.01    0.13
factor(educ)16    0.01    0.00   0.01     0.10   0.01    0.05
black             0.84    0.86  -0.02    -0.31   0.03    0.05
hisp              0.06    0.06   0.00     0.00   0.03    0.37
married           0.19    0.15   0.04     0.14   0.03    0.28
nodegr            0.71    0.77  -0.06    -0.17   0.04    0.38
u74               0.71    0.72  -0.02    -0.04   0.04    0.42
u75               0.60    0.62  -0.02    -0.05   0.05    0.44
--

$raw
          re74           re75            age  factor(educ)4  factor(educ)5 
  -0.002159921    0.083863254    0.107277121   -0.087705802    0.158623414 
 factor(educ)6  factor(educ)7  factor(educ)8  factor(educ)9 factor(educ)10 
   0.078298987   -0.098299879   -0.118377488    0.057923710   -0.006921703 
factor(educ)11 factor(educ)12 factor(educ)13 factor(educ)14 factor(educ)15 
  -0.256078933   -0.072042948    0.190980849    0.138025647    0.148068395 
factor(educ)16          black           hisp        married         nodegr 
   0.103975049    0.103975049    0.043886611   -0.174561071    0.093640701 
           u74            u75 
  -0.303986439   -0.094140477 

$matched
          re74           re75            age  factor(educ)4  factor(educ)5 
    0.06621614     0.03835607     0.13615155     0.36978662     0.04823636 
 factor(educ)6  factor(educ)7  factor(educ)8  factor(educ)9 factor(educ)10 
    0.00000000     0.05324577    -0.03971374    -0.11366162     0.01499702 
factor(educ)11 factor(educ)12 factor(educ)13 factor(educ)14 factor(educ)15 
   -0.14431246     0.04961898     0.04280605     0.09321213     0.04139547 
factor(educ)16          black           hisp        married         nodegr 
    0.10397505    -0.31192515     0.00000000     0.13694015    -0.17185823 
           u74            u75 
   -0.03896622    -0.04858863 

arm documentation built on May 31, 2017, 3:34 a.m.

Related to matching in arm...