Description Usage Format Source Examples
Data set used by Kreft and De Leeuw in their book Introducing Multilevel Modeling, Sage (1988) to analyse the relationship between math score and time spent by students to do math homework. The data set is a subsample of NELS-88 data consisting of 10 handpicked schools from the 1003 schools in the full data set. Students are nested within schools and information is available both at the school and student level.
1 | data("schools")
|
A data frame with 260 observations on the following 19 variables.
schid
School ID: a numeric vector identyfing each school.
stuid
The student ID.
ses
Socioeconomic status.
meanses
Mean ses for the school.
homework
The number of hours spent weekly doing homeworks.
white
A dummy for white race (=1) versus non-white (=0).
parented
Parents highest education level.
public
Public school: 1=public, 0=non public.
ratio
Student-teacher ratio.
percmin
Percent minority in school.
math
Math score
sex
Sex: 1=male, 2=female.
race
Race of student, 1=asian, 2=Hispanic, 3=Black, 4=White, 5=Native American.
sctype
Type of school: 1=public, 2=catholic, 3= Private other religion, 4=Private non-r.
cstr
Classroom environment structure: ordinal from 1=not accurate to 5=very much accurate.
scsize
School size: ordinal from 1=[1,199) to 7=[1200+).
urban
Urbanicity: 1=Urban, 2=Suburban, 3=Rural.
region
Geographic region of the school: NE=1,NC=2,South=3,West=4.
schnum
Standardized school ID.
Ita G G Kreft, Jan De Leeuw 1988. Introducing Multilevel Modeling, Sage National Education Longitudinal Study of 1988 (NELS:88): https://nces.ed.gov/surveys/nels88/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | data(schools)
# Kreft and De Leeuw, Introducing Multilevel Modeling, Sage (1988).
# The data set is the subsample of NELS-88 data consisting of 10 handpicked schools
# from the 1003 schools in the full data set.
# Suppose that the effect of homeworks on math score is unconfounded conditional on X and
# unobserved school features (we assume this only for illustrative purpouse)
# Let us consider the following variables:
X<-schools$ses #X<-as.matrix(schools[,c("ses","white","public")])
Y<-schools$math
Tr<-ifelse(schools$homework>1,1,0)
Group<-schools$schid
# Note that when Group is missing, NULL or there is only one Group the function
# returns the output of the Match function with a warning.
# Let us assume that the effect of homeworks (Tr) on math score (Y)
# is unconfounded conditional on X and other unobserved schools features.
# Several strategies to handle unobserved group characteristics
# are described in Arpino & Cannas, 2016 (see References).
# Multivariate Matching on covariates in X
#(default parameters: one-to-one matching on X with replacement with a caliper of 0.25).
### Matching within schools
mw<-MatchW(Y=Y, Tr=Tr, X=X, Group=Group, caliper=0.1)
# compare balance before and after matching
bmw <- MatchBalance(Tr~X,data=schools,match.out=mw)
# calculate proportion of matched observations
(mw$orig.treated.nobs-mw$ndrops)/mw$orig.treated.nobs
# check number of drops by school
mw$orig.ndrops.by.group
# examine output
mw # complete list of results
summary(mw) # basic statistics
#### Propensity score matching
# estimate the propensity score (ps) model
mod <- glm(Tr~ses+parented+public+sex+race+urban,
family=binomial(link="logit"),data=schools)
eps <- fitted(mod)
# eg 1: within-school propensity score matching
psmw <- MatchW(Y=schools$math, Tr=Tr, X=eps, Group=schools$schid, caliper=0.1)
# We can use other strategies for controlling unobserved cluster covariates
# by using different specifications of ps (see Arpino and Mealli for details):
# eg 2: standard propensity score matching using ps estimated
# from a logit model with dummies for schools
mod <- glm(Tr ~ ses + parented + public + sex + race + urban
+schid - 1,family=binomial(link="logit"),data=schools)
eps <- fitted(mod)
dpsm <- MatchW(Y=schools$math, Tr=Tr, X=eps, caliper=0.1)
# this is equivalent to run Match with X=eps
# eg3: standard propensity score matching using ps estimated from
# multilevel logit model (random intercept at the school level)
require(lme4)
mod<-glmer(Tr ~ ses + parented + public + sex + race + urban + (1|schid),
family=binomial(link="logit"), data=schools)
eps <- fitted(mod)
mpsm<-MatchW(Y=schools$math, Tr=Tr, X=eps, Group=NULL, caliper=0.1)
# this is equivalent to run Match with X=eps
|
Loading required package: Matching
Loading required package: MASS
##
## Matching (Version 4.9-2, Build Date: 2015-12-25)
## See http://sekhon.berkeley.edu/matching for additional documentation.
## Please cite software as:
## Jasjeet S. Sekhon. 2011. ``Multivariate and Propensity Score Matching
## Software with Automated Balance Optimization: The Matching package for R.''
## Journal of Statistical Software, 42(7): 1-52.
##
***** (V1) X *****
Before Matching After Matching
mean treatment........ 0.23211 0.25282
mean control.......... -0.36947 0.25541
std mean diff......... 61.315 -0.26998
mean raw eQQ diff..... 0.61617 0.030444
med raw eQQ diff..... 0.59 0.03
max raw eQQ diff..... 1.12 0.09
mean eCDF diff........ 0.17801 0.012232
med eCDF diff........ 0.18324 0.011111
max eCDF diff........ 0.35227 0.055556
var ratio (Tr/Co)..... 1.2849 1.0154
T-test p-value........ 3.4478e-07 0.61904
KS Bootstrap p-value.. < 2.22e-16 0.996
KS Naive p-value...... 1.979e-07 0.99907
KS Statistic.......... 0.35227 0.055556
[1] 0.6640625
NULL
$index.control
[1] 4 3 8 35 27 35 30 27 30 30 67 65 52 46 72 70 84 74 69
[20] 81 88 101 100 102 106 122 131 178 158 154 141 161 139 139 156 147 170 147
[39] 183 170 139 139 164 139 164 170 187 154 187 164 147 187 164 147 164 170 149
[58] 149 139 147 147 170 147 149 164 187 143 158 183 147 187 139 210 204 205 214
[77] 202 217 214 204 225 224 220 249 243 254 259 247 254 258
$index.treated
[1] 5 7 16 28 31 34 38 41 42 43 44 45 48 49 76 78 83 85 86
[20] 87 89 91 97 103 111 120 128 133 134 135 136 136 137 138 140 142 144 146
[39] 150 151 153 155 157 159 160 160 163 166 167 168 171 171 172 173 174 176 179
[58] 180 181 182 184 185 186 186 191 192 193 194 195 197 197 198 201 203 206 207
[77] 211 215 216 218 226 231 238 241 242 244 248 251 253 256
$index.dropped
[1] 10 14 18 24 25 29 32 33 39 40 47 51 54 58 59 60 62 64 96
[20] 118 126 132 145 148 152 162 165 169 175 188 189 190 196 199 208 209 213 219
[39] 222 223 234 246 252
$weights
[1] 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
[20] 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 1.0 1.0
[39] 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 1.0
[58] 1.0 1.0 1.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 1.0 1.0
[77] 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
$est
[1] 4.341176
$se
[1] 1.832278
$mdata
$mdata$Y
[1] 43 33 36 35 42 41 37 41 39 36 65 62 43 68 36 62 40 64 54 65 48 33 49 32 43
[26] 39 47 68 56 68 61 61 61 62 68 71 60 70 67 62 64 67 69 69 63 63 71 65 69 61
[51] 61 61 60 65 64 70 63 64 56 63 54 55 67 67 70 69 68 52 63 69 69 68 46 65 54
[76] 58 34 60 50 65 40 37 60 68 50 44 43 62 64 43 42 53 64 32 42 32 35 42 35 35
[101] 41 54 53 44 33 48 42 40 39 37 45 58 56 46 47 51 44 63 54 57 63 43 60 60 57
[126] 66 56 66 67 56 60 60 63 60 63 56 58 57 58 63 66 58 63 66 63 56 63 63 60 66
[151] 66 56 66 63 63 58 61 54 67 66 58 60 40 52 40 41 44 35 41 52 56 43 48 36 43
[176] 37 34 37 37 47
$mdata$Tr
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[112] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[149] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
$mdata$X
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] -0.74 -0.83 -0.50 -1.63 -0.02 -1.67 -1.16 0.03 -1.09 -1.10 0.98 0.24
[2,] -0.72 -0.80 -0.51 -1.64 -0.02 -1.64 -1.07 -0.02 -1.07 -1.07 0.95 0.29
[,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
[1,] -0.03 0.39 -1.96 -0.48 -1.28 -0.02 -0.60 -0.13 -0.26 -0.75 -0.43 -0.21
[2,] -0.11 0.35 -2.04 -0.45 -1.31 -0.07 -0.52 -0.14 -0.19 -0.71 -0.49 -0.21
[,25] [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36]
[1,] 0.14 -1.05 -0.33 0.48 0.69 0.60 0.77 0.77 1.19 1.17 1.85 1
[2,] 0.22 -1.11 -0.30 0.40 0.68 0.64 0.75 0.79 1.12 1.12 1.82 1
[,37] [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48]
[1,] 1.43 0.98 0.18 1.48 1.18 1.13 1.34 1.11 1.40 1.40 1.03 0.56
[2,] 1.42 1.00 0.26 1.42 1.12 1.12 1.38 1.12 1.38 1.42 1.02 0.64
[,49] [,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60]
[1,] 1.03 1.30 1.01 1.01 1.32 0.97 1.31 1.48 0.86 0.85 1.09 1
[2,] 1.02 1.38 1.00 1.02 1.38 1.00 1.38 1.42 0.86 0.86 1.12 1
[,61] [,62] [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72]
[1,] 0.98 1.50 0.93 0.93 1.34 1.05 1.8 0.68 0.23 1.01 1.01 1.18
[2,] 1.00 1.42 1.00 0.86 1.38 1.02 1.8 0.68 0.26 1.00 1.02 1.12
[,73] [,74] [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84]
[1,] -0.54 0.90 -0.13 -0.88 -0.02 -2.04 -0.99 1.05 -0.29 -0.56 0.82 -0.86
[2,] -0.55 0.97 -0.14 -0.92 0.01 -1.96 -0.92 0.97 -0.32 -0.49 0.76 -0.84
[,85] [,86] [,87] [,88] [,89] [,90]
[1,] -0.41 -0.19 -1.28 -0.67 -0.19 -0.23
[2,] -0.44 -0.16 -1.19 -0.72 -0.16 -0.29
$mdata$orig.weighted.treated.nobs
[1] 128
$mdata$orig.weighted.control.nobs
[1] 132
$orig.nobs
[1] 260
$orig.wnobs
[1] 260
$orig.weighted.treated.nobs
[1] 128
$orig.weighted.control.nobs
[1] 132
$orig.treated.nobs
[1] 128
$orig.control.nobs
[1] 132
$wnobs
[1] 85
$caliper
[1] 0.1
$intcaliper
[1] 0.2157358
$exact
[1] FALSE
$ndrops
[1] 43
$ndrops.matches
[1] 43
$estimand
[1] "ATT"
$orig.treated.nobs.by.group
7472 7829 7930 24725 25456 25642 62821 68448 68493 72292
6 14 12 7 5 4 52 13 6 9
$orig.dropped.nobs.by.group
7472 7829 7930 25456 25642 62821 68448 68493 72292
3 7 8 1 2 12 5 3 2
$version
[1] "matchwithin"
attr(,"class")
[1] "Match"
Estimate... 4.3412
AI SE...... 1.8323
T-stat..... 2.3693
p.val...... 0.017823
Original number of observations.............. 260
Original number of treated obs............... 128
Matched number of observations............... 85
Matched number of observations (unweighted). 90
Number of obs dropped by 'exact' or 'caliper' 43
Warning message:
In MatchW(Y = schools$math, Tr = Tr, X = eps, caliper = 0.1) :
There is only one group: same output of Match
Loading required package: lme4
Loading required package: Matrix
Warning message:
In MatchW(Y = schools$math, Tr = Tr, X = eps, Group = NULL, caliper = 0.1) :
There is only one group: same output of Match
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.