Do the mixed model.
library(lme4)
library(zStat)
(load('/Users/alanzonderman/Desktop/tmp/DanThesisFinal.rdata'))
[1] "DanThesisFinal"
zQuick(DanThesisFinal)
Dimensions: 2806 44
HNDid time Race Sex PovStat Age.1 Age.3
Min. :8031460601 Min. :1.000000 White:1122 Women:1669 Above:1703 Min. :30.10000 Min. :32.9000
1st Qu.:8142708026 1st Qu.:1.000000 AfrAm:1684 Men :1137 Below:1103 1st Qu.:41.50000 1st Qu.:46.1000
Median :8171783651 Median :3.000000 Median :48.70000 Median :53.4000
Mean :8168396628 Mean :2.008553 Mean :48.51137 Mean :53.0933
3rd Qu.:8194086251 3rd Qu.:3.000000 3rd Qu.:55.87500 3rd Qu.:60.4000
Max. :8224521902 Max. :3.000000 Max. :66.20000 Max. :70.8000
Attention DigitSpanBck DigitSpanFwd FluencyWord TrailsBtestSec BMI
Min. : 0.000000 Min. : 0.000000 Min. : 0.000000 Min. : 5.00000 Min. : 5.0000 Min. :14.35524
1st Qu.: 5.000000 1st Qu.: 4.000000 1st Qu.: 6.000000 1st Qu.:15.00000 1st Qu.: 63.0000 1st Qu.:24.83074
Median : 7.000000 Median : 5.000000 Median : 7.000000 Median :19.00000 Median : 92.0000 Median :29.18744
Mean : 6.474341 Mean : 5.554882 Mean : 7.224519 Mean :19.01247 Mean :161.6123 Mean :30.34786
3rd Qu.: 8.000000 3rd Qu.: 7.000000 3rd Qu.: 9.000000 3rd Qu.:22.00000 3rd Qu.:154.0000 3rd Qu.:34.74891
Max. :10.000000 Max. :14.000000 Max. :14.000000 Max. :44.00000 Max. :600.0000 Max. :63.50000
NA's :2
AlzheimersDisease Brain CVstroke DementiaAny Epilepsy MultipleSclerosis ParkinsonDisease PhyPerfDomHand
No :2806 No :2806 No :2806 No :2806 No :2806 No :2806 No :2806 Right :2012
Yes: 0 Yes: 0 Yes: 0 Yes: 0 Yes: 0 Yes: 0 Yes: 0 Left : 262
Ambidextrous: 38
Ambidex : 42
NA's : 452
PhyPerfLeft PhyPerfPain PhyPerfRight PhyPerfSafeStand PhyPerfSecsTandem PhyPerfSingle1
Min. : 4.00000 No :1920 Min. : 5.00000 Min. :0.0000000 Min. : 1.00000 Min. : 2.00000
1st Qu.:26.00000 Yes : 451 1st Qu.:26.00000 1st Qu.:1.0000000 1st Qu.:30.00000 1st Qu.:29.00000
Median :33.00000 NA's: 435 Median :33.00000 Median :1.0000000 Median :30.00000 Median :30.00000
Mean :35.37554 Mean :34.49314 Mean :0.8575581 Mean :29.42076 Mean :26.70857
3rd Qu.:44.00000 3rd Qu.:41.00000 3rd Qu.:1.0000000 3rd Qu.:30.00000 3rd Qu.:30.00000
Max. :95.00000 Max. :83.00000 Max. :1.0000000 Max. :30.00000 Max. :31.00000
NA's :484 NA's :473 NA's :398 NA's :610 NA's :905
PhyPerfSingle2 PhyPerfSingle3 PhyPerfStands10 PhyPerfSurgery id Age
Min. : 1.00000 Min. : 1.0000 Min. : 14.27000 No :2366 Min. : 1.0000 Min. :-19.90000
1st Qu.:30.00000 1st Qu.:30.0000 1st Qu.: 28.34999 Yes : 11 1st Qu.: 409.5000 1st Qu.: -6.10000
Median :30.00000 Median :30.0000 Median : 33.00000 NA's: 429 Median : 850.5000 Median : 1.20000
Mean :27.90412 Mean :28.6926 Mean : 33.98763 Mean : 846.4665 Mean : 0.80866
3rd Qu.:30.00000 3rd Qu.:30.0000 3rd Qu.: 38.00000 3rd Qu.:1287.7500 3rd Qu.: 8.20000
Max. :31.00000 Max. :31.0000 Max. :109.88995 Max. :1678.0000 Max. : 20.80000
NA's :1106 NA's :1212 NA's :733
PhyPerfSingleMN ZAttention.V1 ZDigitSpanFwd.V1 ZDigitSpanBck.V1 ZFluencyWord.V1
Min. : 4.333333 Min. :-2.9675886678 Min. :-2.8853094843 Min. :-2.343980252 Min. :-2.571692365
1st Qu.:30.000000 1st Qu.:-0.6821822243 1st Qu.:-0.4392545254 1st Qu.:-0.616229330 1st Qu.:-0.727302244
Median :30.000000 Median : 0.2319803530 Median :-0.0315786989 Median :-0.184291599 Median : 0.010453804
Mean :28.608077 Mean :-0.0082886779 Mean : 0.0599522243 Mean : 0.055383043 Mean : 0.012754362
3rd Qu.:30.000000 3rd Qu.: 0.6890616417 3rd Qu.: 0.7837729540 3rd Qu.: 0.679583862 3rd Qu.: 0.563770841
Max. :30.000000 Max. : 1.6032242191 Max. : 2.8221520865 Max. : 3.703147976 Max. : 4.621429106
NA's :1213
ZTrailsBtestSec.V1 EF.V1 HNDwave WRATtotal ValidEF DomHand
Min. :-0.9206138871 Min. :-6.974311844 Min. :1.00000 Min. :14.00000 Min. :0 Ambidextrous: 80
1st Qu.:-0.5726305677 1st Qu.:-1.617107331 1st Qu.:1.00000 1st Qu.:38.00000 1st Qu.:0 Left : 262
Median :-0.3986389079 Median :-0.001669087 Median :1.00000 Median :44.00000 Median :0 Right :2012
Mean : 0.0190146285 Mean : 0.138815580 Mean :1.04134 Mean :42.58553 Mean :0 NA's : 452
3rd Qu.:-0.0266567389 3rd Qu.: 1.723758268 3rd Qu.:1.00000 3rd Qu.:49.00000 3rd Qu.:0
Max. : 2.6492149933 Max. : 8.989384863 Max. :3.00000 Max. :57.00000 Max. :0
mm5 = lmer(PhyPerfSingleMN~Age + Sex + EF + Race + BMI + PovStat + WRATtotal + (1|HNDid) + Age*Race + Age*EF ,data=DanThesisFinal,REML=F)
summary(mm5)
Linear mixed model fit by maximum likelihood ['lmerMod']
Formula: PhyPerfSingleMN ~ Age + Sex + EF + Race + BMI + PovStat + WRATtotal + (1 | HNDid) + Age * Race + Age * EF
Data: DanThesisFinal
AIC BIC logLik deviance df.resid
8520.5 8584.9 -4248.2 8496.5 1579
Scaled residuals:
Min 1Q Median 3Q Max
-5.1364581 -0.0658631 0.1568661 0.3788438 2.6633921
Random effects:
Groups Name Variance Std.Dev.
HNDid (Intercept) 4.814149 2.194117
Residual 7.989653 2.826597
Number of obs: 1591, groups: HNDid, 1112
Fixed effects:
Estimate Std. Error t value
(Intercept) 30.532718539 0.840497823 36.32695
Age -0.155171546 0.018435234 -8.41712
SexMen 0.136980103 0.200465461 0.68331
EF 0.156002314 0.045417791 3.43483
RaceAfrAm 0.762687838 0.215179342 3.54443
BMI -0.121514157 0.014638391 -8.30106
PovStatBelow -0.353121880 0.217219669 -1.62564
WRATtotal 0.021199001 0.015262331 1.38898
Age:RaceAfrAm 0.068311024 0.023155677 2.95008
Age:EF 0.012199973 0.004556671 2.67739
Correlation of Fixed Effects:
(Intr) Age SexMen EF RcAfrA BMI PvSttB WRATtt Ag:RAA
Age 0.052
SexMen -0.194 -0.060
EF 0.223 -0.001 -0.002
RaceAfrAm -0.312 -0.108 -0.020 0.136
BMI -0.502 0.024 0.142 0.036 -0.030
PovStatBelw -0.275 0.049 0.049 0.076 -0.043 0.100
WRATtotal -0.819 -0.048 0.017 -0.361 0.228 -0.028 0.172
Age:RcAfrAm -0.064 -0.797 0.038 0.028 0.128 0.003 0.035 0.045
Age:EF -0.020 -0.309 0.050 0.228 0.058 -0.026 -0.041 0.031 0.264
Plot 3 levels of EF. Note new routine zHat. Also, note aggregate command, which will occur in the zHat routine in the next version.
plotData = zHat(DanThesisFinal, mm5, xAxis='Age', cutVars=list(EF=c(-2.306585887,0.138815580,2.584217047)))
# plotData = aggregate(Hat~Age+EF, data=plotData, FUN=mean)
lineTypes = c(1,2,3)
par(las=1, lwd=2)
plotData$AgeUn = plotData$Age + 50
with(plotData[plotData$EF==-2.306585887,], plot (AgeUn, Hat, lty=lineTypes[1], typ='l', ylim=c(22,32), ylab='Single Leg Stand', xlab='Age'))
with(plotData[plotData$EF== 0.138815580,], lines(AgeUn, Hat, lty=lineTypes[2]))
with(plotData[plotData$EF== 2.584217047,], lines(AgeUn, Hat, lty=lineTypes[3]))
legend(55, 32, c('-1SD EF','Mean EF','+1SD EF'), lty=lineTypes)
For extra credit, plot sex and EF.
plotData = zHat(DanThesisFinal, mm5, xAxis='Age', factors='Sex', cutVars=list(EF=c(-2.306585887,0.138815580,2.584217047)))
par(las=1, lwd=2)
plotData$AgeUn = plotData$Age + 50
with(plotData[plotData$EF==-2.306585887 & plotData$Sex=='Women',], plot (AgeUn, Hat, lty=lineTypes[1], col='red', typ='l', ylim=c(22,32), ylab='Single Leg Stand', xlab='Age'))
with(plotData[plotData$EF== 0.138815580 & plotData$Sex=='Women',], lines(AgeUn, Hat, lty=lineTypes[2], col='red'))
with(plotData[plotData$EF== 2.584217047 & plotData$Sex=='Women',], lines(AgeUn, Hat, lty=lineTypes[3], col='red'))
with(plotData[plotData$EF==-2.306585887 & plotData$Sex=='Men',], lines(AgeUn, Hat, lty=lineTypes[1], col='blue'))
with(plotData[plotData$EF== 0.138815580 & plotData$Sex=='Men',], lines(AgeUn, Hat, lty=lineTypes[2], col='blue'))
with(plotData[plotData$EF== 2.584217047 & plotData$Sex=='Men',], lines(AgeUn, Hat, lty=lineTypes[3], col='blue'))
legend(55, 32, c('-1SD EF','Mean EF','+1SD EF'), lty=lineTypes)
text(30, 24, 'Women in red; men in blue', pos=4)