Professional Documents
Culture Documents
Models
Introduction to Multilevel Models I
Brian Junker
132E Baker Hall
brian@stat.cmu.edu
9/28/2014
Announcements
9/28/2014
Outline
Multi-Level Models
Variance-Component Models
Hierarchical Models
9/28/2014
radon, log(radon)
floor = 0 if measurement was made in basement; = 1 if
measurement on first floor
9/28/2014
2.
3.
4.
9/28/2014
yi = 0 + i
i = house,
no attention paid to county
9/28/2014
yi = j[i] + i
i = house,
j[i] = county that house i is in
6
9/28/2014
cties14
cties15
cties16
.
.
.
cties68
cties69
cties70
cties71
cties72
cties73
cties74
cties75
cties76
cties77
cties78
cties79
cties80
cties81
cties82
cties83
cties84
0.44
-0.37
-0.68
.
.
.
-0.25
-0.10
-0.58
0.03
0.24
0.45
-0.36
0.14
0.48
0.38
-0.35
-0.91
-0.09
0.89
0.89
0.11
0.25
0.21
0.40
0.56
.
.
.
0.28
0.40
0.08
0.16
0.25
0.56
0.40
0.46
0.40
0.30
0.36
0.40
0.12
0.46
0.79
0.22
0.22
2.04
-0.92
-1.21
.
.
.
-0.90
-0.26
-6.82
0.20
0.93
0.80
-0.90
0.31
1.22
1.25
-0.97
-2.29
-0.75
1.94
1.12
0.51
1.11
0.04 *
0.36
0.23
.
.
.
0.37
0.80
1.80e-11 ***
0.84
0.35
0.42
0.37
0.76
0.22
0.21
0.33
0.02 *
0.45
0.05 .
0.26
0.61
0.27
9/28/2014
length(unique(county))
# [1] 85
sum(coef(summary(lm.unpooled.contrast.from.grand.mean))[,4]<0.05)
# [1] 15
15/85
# [1] 0.1764706
Some Equations
> hist(coef(lm.unpooled.contrast.from.grand.mean)[-1],
+
main="Unpooled Contrasts from Grand Mean")
9/28/2014
yi
= j[i] + i , i N (0, 2 )
= 0 + j , j N (0, 2 )
iid
9/28/2014
10
iid
= j[i] + i , i N (0, )
iid
= 0 + j , j N (0, 2 )
Multilevel model (both equations 1 and 2) Unpooled fixed effects (equation 1 only)
library(lme4)
lmer.intercept.only <lmer( y ~ 1 + ( 1 | county.name ) )
summary(lmer.intercept.only)
# Random effects:
2
2
# Groups
Name
Var
SD
# county.name (Intercept)
0.096 0.310
# Residual
0.637 0.798
# Numb. of obs: 919, grps: county.name, 85
#
# Fixed effects:
#
Estimate
SE
t value
# (Intercept)
1.31
0.05
26.84
0
9/28/2014
11
> summary(lm.unpooled.contrast.from.grand.mean)
Call:
lm(formula = y ~ cties)
Coefficients:
Estimate Std. Error t value
Fixed effects:
Pr(>|t|)
Estimate Std. Error t value
(Intercept) 1.343638
0.041980 32.006
(Intercept) 1.31257
0.04891
26.84
cties1
-0.683231
0.396682 -1.722
> fixef(lmer.intercept.only)
cties2
-0.510388
0.117180 -4.356
(Intercept)
cties3
-0.295300
0.457408 -0.646
1.312574
cties4
-0.202652
0.301120 -0.673
> ranef(lmer.intercept.only)
cties5
-0.091202
0.396682 -0.230
$county.name
cties6
0.169372
0.457408
0.370
(Intercept)
cties7
0.565589
0.214984
2.631
AITKIN
-0.245071104
[]
ANOKA
-0.425038053
BECKER
-0.082191868
BELTRAMI
-0.088030506
BENTON
-0.022598796
Fixed effects estimates
Random effects
BIG STONE
0.062346490
of regression coefficients
BLUE EARTH
0.404629013
draws from N(0,2)
[.]
9/28/2014
12
yi
= j[i] + i , i N (0, 2 )
= 0 + j , j N (0, 2 )
iid
= 0 + j[i] + i ,
iid
i N (0, 2 )
iid
j N(0, 2 )
9/28/2014
yi
iid
indep
N (0 , 2 )
N (j[i] , 2 )
13
Multi-level Model
(a.k.a. Hierarchical Linear Model)
iid
= j[i] + i , i N (0, 2 )
iid
= 0 + j , j N (0, 2 )
9/28/2014
14
iid
i N (0, 2 )
= 0 + j[i] + i ,
iid
Var(yj) = Var( + j +
j N (0, 2 )
1
nj
i )
= + /nj;
all i county j
9/28/2014
15
Level 2: j
Level 1:
indep
yi
N (j[i] , 2 )
Prior: j
Likelihood:
N (0 , 2 )
N (0 , 2 )
indep
yi
N (j[i] , 2 )
j[i]
...
County-level differences
from grand mean
9/28/2014
n1 houses
n2 houses
nJ houses
16
plot(aj.coefs ~ u,
xlab="log.uranium, per
county", ylab="Intercept
(mean) for log.radon, per
county")
abline(higher.regression)
9/28/2014
2.0
1.5
1.0
0.5
2.5
-0.8
-0.6
-0.4
-0.2
0.0
0.2
0.4
17
Instead of
iid
yi = j[i] + i , i N (0, 2 )
iid
j = 0 + j , j N (0, 2 )
we could try to fit
iid
yi = j[i] + i , j N (0, 2 )
iid
= 0 + 1 uj + j , j N (0, )
Uj = log(uraniumj)
9/28/2014
18
Var(j)
Random effects:
Groups
Name
Variance Std.Dev.
county.name (Intercept) 0.01406 0.1186
Residual
0.64037 0.8002
Number of obs: 919, groups: county.name, 85
Var(i)
Fixed effects:
Estimate Std. Error t value
(Intercept) 1.33305
0.03397
39.24
log.uranium 0.71912
0.08777
8.19
9/28/2014
> fixef(lmer.intercepts.depend.on.log.uranium)
(Intercept) log.uranium
1.3330508
0.7191188
> ranef(lmer.intercepts.depend.on.log.uranium)
$county.name
(Intercept)
AITKIN
-0.0142971713
ANOKA
0.0583741025
BECKER
-0.0125490841
BELTRAMI
0.0312484900
BENTON
0.0017869830
BIG STONE
-0.0060780289
Estimates of
BLUE EARTH
0.0895241245
the js
BROWN
0.0078003746
themselves
CARLTON
-0.0293551573
CARVER
-0.0230826914
CASS
0.0499879229
CHIPPEWA
0.0161734868
CHISAGO
0.0272838175
CLAY
0.0475401692
[]
19
Outline
Multi-Level Models
Variance-Component Models
Hierarchical Models
9/28/2014
20