EdPsy/Psych/Stat 587Spring 2019C.J. Anderson
R Homework 4Answer Key
1. (10 points) For models (n) – (v) that you fit to the TIMSS data in computer lab 2,write out the equation of the model in each of the following ways:
(n) modeln ← lmer(science ∼ 1 + grpCmath + third + boy + hoursTV +hourscomputergames + grpMmath + (1 | idschool), lab2, REML=FALSE)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + U0j
β1j = γ10
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where U0j ∼ N (0, τ 20 ) i.i.d and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij + γ01(grpMmath)j+U0j +Rij
Marginal model : (science)ij ∼ N (µij, (τ20 + σ2)) where
µij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij + γ01(grpMmath)j
1
(o) modelo ← lmer(science ∼ 1 + grpCmath + third + boy + hoursTV +hourscomputergames + grpMmath + isolate + rural + suburban + (1 | idschool)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j
+γ04(suburb)j + U0j
β1j = γ10
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where U0j ∼ N (0, τ 20 ) i.i.d and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j + γ04(suburb)j
+U0j +Rij
Marginal model : (science)ij ∼ N (µij, (τ20 + σ2)) where
µij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ijγ01(grpMmath)j + γ02(isolate)j + γ03(rural)j + γ04(suburb)j
2
(p) modelp ← lmer(science ∼ 1 + grpCmath + third + boy + hoursTV +hourscomputergames + grpMmath + isolate + rural + suburban + (1 +grpCmath| idschool)Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j
+γ04(suburb)j + U0j
β1j = γ10 + U1j
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where (U0j
U1j
)∼ N
((00
),
(τ 20 τ01τ01 τ 21
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j + γ04(suburb)j
+U0j + U1j(grpCmath)ij +Rij
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j + γ04(suburb)j
var(Yij) = τ 20 + 2τ12(grpCmath)ij + τ 21(grpCmath)2ij + σ2
3
(q) modelq ← lmer(science ∼ 1 + grpCmath + boy + third + hoursTV +hourscomputergames + grpMmath + (1 + grpCmath| idschool)Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + U0j
β1j = γ10 + U1j
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where (U0j
U1j
)∼ N
((00
),
(τ 20 τ01τ01 τ 21
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + U0j + U1j(grpCmath)ij +Rij
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(grpCmath)ij + γ20(gender)ij + γ30(grade)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j + γ04(suburb)j
var(Yij) = τ 20 + 2τ01(grpCmath)ij + τ 24(grpCmath)2ij + σ2
4
(r) modelr ← lmer(science ∼ 1 + grpCmath + third + boy + hoursTV +hourscomputergames + grpMmath + (1 + hoursTV| idschool),Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + U0j
β1j = γ10
β2j = γ20
β3j = γ30
β4j = γ40 + U4j
β5j = γ5j
where (U0j
U4j
)∼ N
((00
),
(τ 20 τ04τ04 τ 24
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(gender)ij + γ30(grade)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + U0j + U4j(hoursTV)ij +Rij
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(grpCmath)ij + γ20(gender)ij + γ30(grade)ij+γ40(hoursTV)ij + γ4j(hourscomputergames)ij + γ01(grpMmath)j
var(Yij) = τ 20 + 2τ04(hoursTV)ij + τ 24(hoursTV)2ij + σ2
5
(s) models← lmer(science ∼ 1 + grpCmath + third + boy + grpMmath + (1 +hoursTV | idschool), lab2, REML=FALSE)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + U0j
β1j = γ10
β2j = γ20
β3j = γ30
β4j = γ40 + U4j
where (U0j
U4j
)∼ N
((00
),
(τ 20 τ04τ04 τ 24
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(gender)ij + γ30(grade)ij+γ40(hoursTV)ij + γ01(grpMmath)j+U0j + U4j(hoursTV)ij +Rij
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(grpCmath)ij + γ20(gender)ij + γ30(grade)ij+γ40(hoursTV)ij + γ01(grpMmath)j
var(Yij) = τ 20 + 2τ04(hoursTV)ij + τ 24hrsTV 2
ij + σ2
6
(t) modelt ← lmer(science ∼ 1 + grpCmath + third + boy + hoursTV +hourscomputergames + grpMmath + (1 + hourscomputergames| idschool),lab2,REML=FALSE)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + U0j
β1j = γ10
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j + U5j
where (U0j
U5j
)∼ N
((00
),
(τ 20 τ05τ05 τ 25
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij + γ01(grpMmath)j+γ11(grpMmath)j(grpCmath)ij + γ12(isolate)j(grpCmath)ij+U0j + U5j(hourscomputergames)ij +Rij
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j
var(Yij) = τ 20 + 2τ05(hourscomputergames)ij + τ 25(hourscomputergames)2ij + σ2
7
(u) modelu ← lmer(science ∼ 1 + grpCmath + third + boy + hoursTV +hourscomputergames + grpMmath + grpCmath*grpMmath + (1 + gCmath| +idschool), lab2, REML=FALSE)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(grpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + U0j
β1j = γ10 + γ11(grpMmath)j + U1j
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where (U0j
U1j
)∼ N
((00
),
(τ 20 τ01τ01 τ 21
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + γ11(grpMmath)j(grpCmath)ij+U0j + U1j(grpCmath)ij +Rij
8
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(grpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(grpMmath)j + γ11(grpMmath)j(grpCmath)ij
var(Yij) = τ 20 + 2τ01(grpCmath)ij + τ 21(grpCmath)2ij + σ2
Note: re-scale version is the same model. From here on out I willuse (xgrpMmath)ij and (xgrpCmath)ij to indicate these were re-scaledto standard deviations equal 1.
(v) modelv ← lmer(science ∼ 1 + xgrpCmath + third + boy + hoursTV +hourscomputergames + xgrpMmath + short2 + short3 +xgrpCmath*xgrpMmath +(1 + xgrpCmath| idschool),Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(xgrpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(xgrpMmath)j + γ02(short2)j
+γ03(short3)j + U0j
β1j = γ10 + γ11(xgrpMmath)j + U1j
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where (U0j
U1j
)∼ N
((00
),
(τ 20 τ01τ01 τ 21
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(xgrpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(xgrpMmath)j + γ11(xgrpMmath)j(xgrpCmath)ij+γ02(short2)j + γ03(short3)j
+U0j + U1j(xgrpCmath)ij +Rij
9
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(xgrpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(xgrpMmath)j + γ11(xgrpMmath)j(xgrpCmath)ij+γ02(short2)j + γ03(short3)j
var(Yij) = τ 20 + 2τ01(xgrpCmath)ij + τ 21(xgrpCmath)2ij + σ2
(w) modelw ← lmer(science ∼ 1 + xgrpCmath + third + boy + hoursTV +hourscomputergames + xgrpMmath + xgrpCmath*xgrpMmath + short2 +short3 + xgrpCmath*short2 + xgrpCmath*short3 + (1 + xgrpCmath|idschool), lab2, REML=FALSE)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(xgrpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(xgrpMmath)j + γ02(short2)j
+γ03(short3)j + U0j
β1j = γ10 + γ11(xgrpMmath)j + γ02(short2)j
+γ13(short3)j + U1j
β2j = γ20
β3j = γ30
β4j = γ40
β5j = γ5j
where (U0j
U1j
)∼ N
((00
),
(τ 20 τ01τ01 τ 21
))i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(xgrpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(xgrpMmath)j + γ11(xgrpMmath)j(xgrpCmath)ij
10
+γ02(short2)j + γ03(short3)j
+γ02(short2)j(grpCmath)ij + γ03(short3)j(xgrpCmath)ij+U0j + U1j(xgrpCmath)ij +Rij
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(xgrpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(xgrpMmath)j + γ11(xgrpMmath)j(xgrpCmath)ij+γ02(short2)j + γ03(short3)j
+γ02(short2)j(xgrpCmath)ij + γ03(short3)j(xgrpCmath)ij
var(Yij) = τ 20 + 2τ01(xgrpCmath)ij + τ 21(xgrpCmath)2ij + σ2
11
(x) modelx ← lmer(science ∼ 1 + xgrpCmath + boy + third + hoursTV +hourscomputergames + xgrpMmath + shortages + isolate + rural + suburban+ xgrpCmath*xgrpMmath + xgrpCmath*shortages + isolate*xgrpCmath +rural*xgrpCmath + (1 + xgrpCmath + hoursTV | idschool), lab2,REML=FALSE)
Hierarchical model :
Level 1 :
(science)ij = β0j + β1j(xgrpCmath)ij + β2j(third)ij + β3j(boy)ij
+β4j(hoursTV)ij + β5j(hourscomputergames)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(xgrpMmath)j + γ02(shortages)j+γ03(isolate)j + γ04(rural)j
+γ05(suburb)j + U0j
β1j = γ10 + γ11(xgrpMmath)j + γ12(shortages)j+γ13(isolate)j + γ14(rural)j + U1j
β2j = γ20
β3j = γ30
β4j = γ40 + U4j
β5j = γ5j
where U0j
U1j
U4j
∼ N 0
00
,
τ 20 τ01 τ04τ01 τ 21 τ14τ04 τ14 τ 24
i.i.d.
and independent of Rij.
Linear mixed model :
(science)ij = γ00 + γ10(xgrpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(xgrpMmath)j + γ11(xgrpMmath)j(xgrpCmath)ij+γ02(shortages)j + γ03(isolate)j + γ04(rural)j
+γ05(suburb)j + γ11(xgrpMmath)j(xgrpCmath)ij +
+γ12(shortages)j(xgrpCmath)ij + γ13(isolate)j + γ14(rural)j
+U0j + U1j(xgrpCmath)ij + U4j(hoursTV)ij +Rij
12
Marginal model : (science)ij ∼ N (µij, var(Yij)) where
µij = γ00 + γ10(xgrpCmath)ij + γ20(third)ij + γ30(boy)ij+γ40(hoursTV)ij + γ5j(hourscomputergames)ij+γ01(xgrpMmath)j + γ11(xgrpMmath)j(xgrpCmath)ij+γ02(shortages)j + γ03(isolate)j + γ04(rural)j
+γ05(suburb)j + γ11(xgrpMmath)j(grpCmath)ij +
+γ12(shortages)j(xgrpCmath)ij + γ13(isolate)j + γ14(rural)j
var(Yij) = τ 20 + τ 21(xgrpCmath)2ij + τ 24(hoursTV)ij + 2τ01(xgrpCmath)ij
+2τ04(hoursTV)+ 2τ14(xgrpCmath)ij(hoursTV)ij + σ2
13
3.SummaryTab
le(10points)
#of
Fixed
Effects
Ran
dom
Effects
Fitstatistics
est
Between
Within
Model
parms
“Effect”
Estim
ate
SE
τ2
σ2−2loglike
AIC
(j)
7intercept
14.0463
5.9747
3.759
51.7541
48363.7
48377.7
grpMmath
0.9002
0.0396
grpCmath
0.5528
0.0100
third
-0.9253
0.1953
boy
1.1154
0.1720
(n)
9Intercept
16.00461
5.94512
3.672
51.650
48347.2
48365.2
grpCmath
0.55101
0.01002
grad
e3rd
-0.91944
0.19518
gender
boy
1.20886
0.17335
hou
rsTV
-0.08845
0.07456
hou
rscomputer
-0.27949
0.07863
grpMmath
0.89243
0.03926
(o)
12Intercept
15.92880
5.86103
3.376
51.655
48338.6
48362.6
grpCmath
0.55093
0.01002
grad
e3rd
-0.92559
0.19509
gender
boy
1.20747
0.17334
hou
rsTV
-0.08856
0.07455
hou
rscompute
-0.27667
0.07862
grpMmath
0.89136
0.03891
type
isolated
4.32444
2.04458
rural
1.07815
0.50783
suburb
0.08777
0.40302
14
#estimated
Fixed
Effects
Ran
dom
Effects
Fitstatistics
Model
param
eters
“Effect”
Estim
ate
SE
estimate
−2loglike
AIC
(p)
Did
not
converge
(q)
11Intercept
7.91886
5.83771
τ2 0=
3.749
48314.1
48336.1
grpCmath
0.55751
0.01304
τ2 1=
0.009
0.095
grad
e3rd
-0.88966
0.19512
ρ40=
0.41
gender
boy
1.26041
0.17264
hou
rsTV
-0.08269
0.07430
σ2=
50.902
7.135
hou
rscompute
-0.27763
0.07836
grpMmath
0.94563
0.03854
(r)
Did
not
converge
(s)
10Intercept
14.11202
5.91580
τ2 0=
3.7865
48355.5
48375.5
grpCmath
0.55327
0.01001
ρ40=−0.33
grad
e3rd
-0.92637
0.19537
gender
boy
1.13008
0.17232
hou
rsTV
-0.14363
0.08053
τ2 4=
0.1529
grpMmath
0.90276
0.03911
σ2=
51.522
(t)
11Intercept
15.61917
5.91284
τ2 0=
4.252
48346.6
48368.6
grpCmath
0.55099
0.01001
ρ50=−0.58
gender
boy
1.21261
0.17335
grad
e3rd
-0.92220
0.19520
hou
rsTV
-0.08884
0.07456
hou
rscomputer
-0.28393
0.07956
τ2 5=
0.02046
grpMmath
0.89504
0.03904
σ2=
51.627
15
#est
Fixed
Effects
Ran
dom
Effects
Fitstatistics
Model
parms
“Effect”
Estim
ate
SE
estimate−2loglike
AIC
(u)
12Intercept
1.597e+01
5.945e+00
τ2 0=
3.60140
48267.3
48291.3
grpCmath
3.221e+00
3.531e-01
τ2 1=
0.00263
gender
boy
-8.619e-01
1.942e-01
grad
e3rd
1.274e+00
1.724e-01
ρ10=
.54
hou
rsTV
-9.208e-02
7.412e-02
hou
rscomputer
-2.593e-01
7.820e-02
grpMmath
8.921e-01
3.926e-02
σ=
50.90768
grpCmath*grpMmath
-1.797e–1
2.327e-03
(u)
12Intercept
15.97254
5.94483
τ2 0=
3.6914
48267.3
48291.3
grpCmath
28.87296
3.16439
τ2 1=
0.2113
alt
gender
boy
-0.86190
0.19418
grad
e3rd
1.27441
0.17238
ρ50=
.54
hou
rsTV
-0.09208
0.07412
hou
rscomputer
-0.25930
0.07820
grpMmath
134.85837
5.93511
σ2=
50.9077
grpCmath*grpMmath
-23.83720
3.15317
(v)
14Intercept
15.16502
6.03999
τ2 0=
3.6773
48266.7
48294.7
grpCmath
28.87238
3.16487
τ2 1=
0.2119
gender
boy
-0.85941
0.19418
grad
e3rd
1.27500
0.17238
hou
rsTV
-0.09189
0.07411
ρ50=
.55
hou
rscomputer
-0.25953
0.07820
grpMmath
135.60820
6.01623
short2
0.28234
0.55737
σ2=
50.9071
short2
0.62872
0.93909
grpCmath*grpMmath
-23.83569
3.15366
16
#est
Fixed
Effects
Ran
dom
Effects
Fitstatistics
Model
parms
“Effect”
Estim
ate
SE
estimate−2loglike
AIC
(w)
16Intercept
15.16999
6.04258
τ2 0=
3.6747
48265.1
48297.1
grpCmath
28.75455
3.21979
τ2 1=
0.2095
grad
e3rd
-0.86522
0.19421
gender
boy
1.27325
0.17237
ρ10=
.54
hou
rsTV
-0.09386
0.07413
hou
rscomputergam
es-0.25821
0.07820
grpMmath
135.60977
6.01822
short2
0.34908
0.56743
σ2=
50.8954
short3
0.39097
0.96566
grpCmath*grpMmath
-23.71872
3.20098
grpCmath*short2
0.19458
0.30514
grpCmath*short3
-0.47362
0.45433
(x)
22(Intercept)
15.62958
5.99232
τ2 0=
3.3069
48249.5
48293.5
grpCmath
29.50782
r3.23052
τ2 1=
0.2216
grad
eboy
1.26814
0.17228
gender
third
-0.86562
0.19420
hou
rsTV
-0.09164
0.08117
τ2 4=
0.1451
hou
rscomputergam
es-0.25916
0.07821
grpMmath
135.13646
5.98377
shortages
-0.13951
0.21660
ρ10=
.90
isolate
3.94481
1.99681
ρ40=−.30
rural
1.06583
0.50740
ρ14=−.68
suburban
-0.10891
0.39316
Cross-level
grpCmath:grpMmath
-24.49290
3.20201
grpCmath:shortages
-0.06370
0.11332
σ2=
50.6850
grpCmath:isolate
0.85695
0.94369
grpCmath:rural
0.36642
0.27112
17
Table 1: Standard deviations and variances of explanatory variablesgrpCmath third boy hoursTV hrgames grpMmath grpCmath*grpMmath
sd 8.963 0.470 0.500 1.199 1.149 4.549 1360.674var 80.33 0.221 0.250 1.437 1.321 20.695 1,851,434.190
4. (5 points) For some of the models, there was a warning about different scales. We’lllook at model (u). in particular the warning message was that ”Warning message:
Some predictor variables are on very different scales: consider
rescaling’’ first appears in model (u). In model (u) a cross-level
interaction between grpCmath and grpMmath was added.”
(a) The standard deviation for this interaction is much larger than those for allothers; namely,
It seems that adding the cross-level interaction made the difference (modelswithout it we did not get this warning).
(b) After re-scaling the variables we find
• The exact same values of fit statistics (i.e., AIC, BIC, loglik, deviance)
• The exact same values for σ2
• The exact same t-statistics and p-values
• Difference values of γ’s and their standard errors for gCmath and gMmath.
• Difference values for τ 21 and τ 20 (and τ01).
Note the γs for gCmath and gMmath are now with respect a 1 standard deviationhigher. For example, for a 1 standard deviation higher of hours watching TV expectscience scores to be 0.1175 points lower.
5. (5 points) Where there any problems in estimating the new models or problems inthe solutions found by R? If yes, what was/were the error messages?
Yes. Some models yielded the message
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
unable to evaluate scaled gradient
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge: degenerate Hessian with 1 negative eigenvalues
I will be delving into why this model may not be converging (maybe not adding tinynumber of diagonal to Hessian??)
Because there was convergence was not achieved, we also get the error message (fromlmerTest),
18
Error in calculation of the Satterthwaite’s approximation. The output
of lme4 package is returned summary from lme4 is returned some computational
error has occurred in lmerTest
and at the very end
convergence code: 0
unable to evaluate scaled gradient
Model failed to converge: degenerate Hessian with 1 negative eigenvalues
and for model (x),
fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
6. (5 points) Does it appear that you need a random slope for grpCmath, hours tv,and/or hours computer games? Explain your reasoning.
Things that could be said:
• Among the models that are the same except for which variable has a randomslope, model with a random slope for grpCmath fits the best (can look at−2LnLike or AIC.
• It seems to depend on what is in the model. Each variables can be random butwhat’s in the fixed part does matter.
• The following figures (at the end of the answer key) show that only grpCmathappears to have different slopes over groups than the other possible explanatory(micro) variables (not expected, but helpful to understand what’s going on).
• Anything that makes sense.
7. The variable grpMmath appears to be a useful predictors of the slope forgrpCmath (See models (q), (u), (v), (w) and (x)). The cross-level interactionsbetween grpCmath & type of community and between grpCmath & don’t appear“significant” in model (x).
8. (0 points) My favorite model ....from using SAS..... . .
Note that I found in model (v), which is my favorite model of those that we fit, thatγ04, which was the fixed effect parameter for (suburb)j was not significantly differentfrom 0, so I recoded the data as
(isolate)j =
{1 for isolated school0 otherwise
(rural)j =
{1 for isolated school0 otherwise
If a school was urban or suburban, then (isolate)j = (rural)j = 0.
19
Level 1:
(science)ij = β0j + β1j(grpCmath)ij + β2j(gender)ij + β3j(grade)ij
+β4j(hoursTV)ij +Rij
where Rij ∼ N (0, σ2) and independent.
Level 2 :
β0j = γ00 + γ01(grpMmath)j + γ02(isolate)j + γ03(rural)j + U0j
β1j = γ10 + γ11(grpMmath)j + U1j
β2j = γ20
β3j = γ30
β4j = γ40
where (U0j
U4j
)∼ N
((00
),
(τ 20 τ01τ01 τ 21
))i.i.d.
and independent of Rij.
The parameter estimates are
Covariance Parameter Estimates
Standard Z
Cov Parm Subject Estimate Error Value Pr Z
UN(1,1) idschool 3.4325 0.5518 6.22 <.0001
UN(2,1) idschool 0.04390 0.02427 1.81 0.0705
UN(2,2) idschool 0.002514 0.001749 1.44 0.0754
Residual 50.9871 0.8733 58.39 <.0001
Fixed Effects Parameter Estimates
Students
grade Standard
Effect gender level Estimate Error DF t Value Pr > $|$t$|$
Intercept 14.6645 5.7815 143 2.54 0.0123
grpCmath 3.2725 0.3520 144 9.30 <.0001
grade 3 -0.8814 0.1943 6801 -4.54 <.0001
grade 4 0 . . . .
gender boy 1.2081 0.1714 6801 7.05 <.0001
20
gender girl 0 . . . .
hours_TV -0.1440 0.07249 6801 -1.99 0.0470
grpMmath 0.8974 0.03820 6801 23.50 <.0001
community (isolated) 3.9954 2.0066 6801 1.99 0.0465
community (rural) 0.9805 0.4766 6801 2.06 0.0397
community (urban & suburban) 0 . . . .
grpCmath*grpMmath -0.01792 0.002320 6801 -7.72 <.0001
Summary/Interpretation: We find higher science scores for boys in the 4th grade whohave higher math scores relative to their peers, and those who don’t watch a lot of TV. Also,we find higher science scores in schools that have high average math scores. Furthermore,students in schools have the higher science scores in isolated locations, followed by rural.There don’t appear to be differences between students in schools in urban & sub-urbanlocations. Those with the lowest scores are from urban and suburban locations.
We can give a more detailed explanation and put the parameter estimates into the models.For example,
(science)ij = β0j + β1j(grpCmath)ij + 1.21(gender)ij − 0.88(grade)ij − 0.14(hoursTV)ij ,
where the estimates of the random parameters are
β0j = 14.66 + 0.90(grpMmath)j + 4.00(isolate)j + 0.98(rural)j
β1j = 3.27− 0.02(grpMmath)j .
• Science scores for boys are 1.21 points higher than those for girls.
• 3rd graders have science scores that are −.88 points lower then 4th graders (or scoresfor 4th graders are 0.88 points higher).
• Science scores tend to be -.14 of a point lower for every hour of TV watched duringthe week.
• Differences exist between schools.
– Interpretation of random intercept: Overall, students have science scores that are
∗ 0.90 points higher at schools where average math scores are 1 point higher.
∗ 4.00 points higher at isolated schools than at urban or sub-urban schools.
∗ 0.98 points higher at rural schools than at urban or sub-urban schools.
∗ The variance of the intercept over schools is 3.43 (standard deviation of1.85)— this is how much unexplained variation there is between schools interms of the overall level of science scores.
– Interpretation of random slope: For a 1 unit increase in a student’s math scoresrelative to their peers, the expected change in the student’s science score is3.27− 0.02(grpMmath)j . If the student goes to a school with an average mathscore that’s 1 unit higher, then the change in science score would be3.27− .02 = 3.25. In appears that if a student has a higher math score relative to
21
their peers but that the school overall has lower average math scores, we expectthis student to have higher science scores.
This is an example where the micro and macro effects are in opposite directions.If we use student math score (raw) or overall mean centered we get the slope formath equal to (3.2725− 2.3751(grpMmath)j)mathij , which shows this oppositemicro/macro effect even more clearly. This seems to me counter-intuitive— anysuggestions or explanations?The unexplained variance between schools in terms of the effect of student mathscores on science scores is .002 (i.e., standard deviation of the slopes is prettysmall).
In the figures at the end of this answer key are plots of data. The plots of science scoresversus potential micro level predictors suggest that we need a random intercept. The“flatness” of the lines in the plots for gender, hour TV and hours computer games look likethere may not be effects for these or if there are they are relatively small. The figure forscience scores versus math scores indicate that this may be a stronger effect (not positiveslope) and need a random slope.
On the last two pages, are plots of a sample of individual schools by math scores with bestfit regression line for that school drawn in. It looks like linear regression OK (withinschools). Can also see various differences between schools.
These plots and re-coding data are things that we’ll cover in computer labs to come. . .
22
23
.
24
25
Using PROC GPLOT and GREPLAY
26
27
28