# MATH 6643 Summer 2012 Applications of Mixed Models/Students/smithce/Model3

(Difference between revisions)
 Revision as of 09:24, 29 May 2012 (view source)Smithce (Talk | contribs)← Older edit Revision as of 09:30, 29 May 2012 (view source)Smithce (Talk | contribs) Newer edit → Line 91: Line 91: L <- list( 'Effect of ses' = rbind( L <- list( 'Effect of ses' = rbind( - "Within-school" =  c( 0,1,0,0,0), + "Within-school" =  c( 0,1,0,0,0), - "Contextual"    =  c( 0,-1,0,1,0), + "Contextual"    =  c( 0,-1,0,1,0), - "Compositional" =  c( 0,0,0,1,0))) + "Compositional" =  c( 0,0,0,1,0))) wald( fitcd,L ) wald( fitcd,L )

## Revision as of 09:30, 29 May 2012

### Model 3 Centered Within Group and Contextual Variable

We can easily create a new variable, ses.d, which we assign how far the student deviates in ses from his or her school's mean ses:

dd$ses.d <- with( dd, dvar(ses,id))  Or equivalently: dd$ses.d <- dd$ses - dd$ses.m


Combined Model

$mathach_{ij} = \underbrace{{\color{Red}\gamma_{00}} + {\color{Red}\gamma_{01}Sector_j} + {\color{Red}\gamma_{02}ses.m_j} + {\color{Blue}\gamma_{10}}ses.d_{ij} + {\color{Blue}\gamma_{11}Sector_j}ses.d_{ij}}_{Fixed} + \underbrace{{\color{Red}u_{0j}} + {\color{Blue}u_{1j}}ses_{ij} + r_{ij}}_{Random}$

Fixed Portion of the Model

${\color{Red}\gamma_{00}} + {\color{Red}\gamma_{01}}Sector_j + {\color{Red}\gamma_{02}}ses.m_j + {\color{Blue}\gamma_{10}}ses.d_{ij} + {\color{Blue}\gamma_{11}}Sector_jses.d_{ij}$
${\color{Red}\gamma_{00}} + {\color{Red}\gamma_{01}}Sector_j + {\color{Red}\gamma_{02}}ses.m_j + {\color{Blue}\gamma_{10}}(ses_{ij} - ses.m_j) +{\color{Blue}\gamma_{11}}Sector_j(ses_{ij} - ses.m_j)$
${\color{Red}\gamma_{00}} + {\color{Red}\gamma_{01}}Sector_j + {\color{Red}\gamma_{02}}ses.m_j + {\color{Blue}\gamma_{10}}ses_{ij} - {\color{Blue}\gamma_{10}}ses.m_j + {\color{Blue}\gamma_{11}}Sector_j ses_{ij} - {\color{Blue}\gamma_{11}}Sector_j ses.m_j$
${\color{Red}\gamma_{00}} + {\color{Red}\gamma_{01}}Sector_j + ({\color{Red}\gamma_{02}} - {\color{Blue}\gamma_{10}} - {\color{Blue}\gamma_{11}}Sector_j)ses.m_j + ({\color{Blue}\gamma_{10}} + {\color{Blue}\gamma_{11}}Sector_j)ses_{ij}$

Random Portion of the Model

${\color{Red}u_{0j}} + {\color{Blue}u_{1j}}ses_{ij} + r_{ij}$

fitcd <- lme( mathach ~ ses.d*Sector + ses.m, dd,random = ~ 1 + ses | id )
# Note that id refers to schools not students!


Linear mixed-effects model fit by REML
Data: dd

 AIC BIC logLik 23891.45 23947.34 -11936.73

Random effects:
Formula: ~1 + ses | id
Structure: General positive-definite, Log-Cholesky parametrization

 StdDev Corr (Intercept) 1.7561 (Intr) ses 0.3522 0.5553 Residual 6.0754

Fixed effects: mathach ~ ses.d * Sector + ses.m

 Value Std.Error DF t-value p-value (Intercept) 13.7675 0.330 3602 41.721 0.00E+00 ses.d 1.4856 0.235 3602 6.321 0.00E+00 SectorPublic -1.8257 0.458 77 -3.983 2.00E-04 ses.m 5.3548 0.568 77 9.418 0.00E+00 ses.d:SectorPublic 1.4229 0.316 3602 4.504 0.00E+00

Correlation:

 (Intr) ses.d SctrPb ses.m ses.d 0.125 SectorPublic -0.736 -0.089 ses.m -0.085 0.008 0.247 ses.d:SectorPublic -0.093 -0.744 0.118 -0.002

Standardized Within-Group Residuals:

 Min Q1 Med Q3 Max -3.095 -0.733 0.026 0.748 2.829

Number of Observations: 3684
Number of Groups: 80

L <- list( 'Effect of ses' = rbind(
"Within-school" =  c( 0,1,0,0,0),
"Contextual"    =  c( 0,-1,0,1,0),
"Compositional" =  c( 0,0,0,1,0)))
wald( fitcd,L )

 numDF denDF F.value p.value Effect of ses 2 77 63.84225 <.00001
 Estimate Std.Error DF t-value p-value Lower 0.95 Upper 0.95 Within-school 1.4856 0.235 3602 6.321 <.00001 1.024 1.946 Contextual 3.86910 0.613 77 6.308 <.00001 2.648 5.090 Compositional 5.3548 0.568 77 9.418 <.00001 4.222 6.486

Notes

1. $Var({\color{Red}u_{0}}) = 1.756^2$
2. $Var({\color{Blue}u_{1}}) = 0.352^2$
3. $Cov({\color{Red}u_{0}},{\color{Blue}u_{1}}) = 0.555$
4. $Var({\color{Black}r_{ij}}) = 6.075^2$
5 ${\color{Red}\gamma_{00}} = 13.767$ Intercept for Catholic schools
6 ${\color{Blue}\gamma_{10}} = 1.485$ Within school effect of ses.d (student deviation from their school mean) for Catholic schools
7 ${\color{Red}\gamma_{01}} = -1.825$ Change in Intercept for Public schools (e.g. Intercept for Public = 13.767 - 1.825 = 11.942)
8 ${\color{Red}\gamma_{02}} = 5.354$ Increase in mathach associated with 1 unit increase in school mean ses holding the student's school relative position constant (e.g. increase in mathach from a student 1 unit below his school mean of X compared to a student 1 unit below a school mean of X + 1). This is the between school effect for Catholic schools (e.g. This is the difference going from a student with ses = X in a school with mean ses = Y to a student with ses = X + 1 in a school with mean ses = Y + 1)!
9 ${\color{Blue}\gamma_{11}} = 1.422$ Change in within-school ses.d for Public schools (e.g. ses.d slope for Public = 1.485 + 1.422 = 2.907)
10 To compute the contextual effect (taking a student with a constant ses and shifting them to a school with ses.m + 1) we need to take the compositional effect and subtract the within school effect, ${\color{Red}\gamma_{02}} - {\color{Blue}\gamma_{10}} = 5.354 - 1.485 = 3.869$