(load("~/Desktop/megan/IPVandCognitionDataSet2.rda"))
[1] "IPVandCognitionDataSet2"
IPV = IPVandCognitionDataSet2
IPV$Age = ifelse(IPV$Time == 1, IPV$Age1, IPV$Age3) - 50
library(lme4)
library(lmerTest)
(mm1 = lmer(TrailsBtestSec ~ Age * IPVstatus * Sex * Race + (Age | HNDid), data = IPV))
Linear mixed model fit by REML ['merModLmerTest']
Formula: TrailsBtestSec ~ Age * IPVstatus * Sex * Race + (Age | HNDid)
Data: IPV
REML criterion at convergence: 1661
Random effects:
Groups Name Std.Dev. Corr
HNDid (Intercept) 122.63
Age 8.21 0.54
Residual 88.41
Number of obs: 144, groups: HNDid, 65
Fixed Effects:
(Intercept) Age IPVstatus SexMen RaceAfrAm Age:IPVstatus
101.114 2.869 -34.595 -74.314 65.033 -2.539
Age:SexMen IPVstatus:SexMen Age:RaceAfrAm IPVstatus:RaceAfrAm SexMen:RaceAfrAm Age:IPVstatus:SexMen
-5.669 387.595 0.348 -42.048 27.395 25.474
Age:IPVstatus:RaceAfrAm Age:SexMen:RaceAfrAm IPVstatus:SexMen:RaceAfrAm Age:IPVstatus:SexMen:RaceAfrAm
1.890 -0.491 -173.571 -24.519
summary(mm1)
Linear mixed model fit by REML ['merModLmerTest']
Formula: TrailsBtestSec ~ Age * IPVstatus * Sex * Race + (Age | HNDid)
Data: IPV
REML criterion at convergence: 1661
Random effects:
Groups Name Variance Std.Dev. Corr
HNDid (Intercept) 15037.6 122.63
Age 67.5 8.21 0.54
Residual 7816.0 88.41
Number of obs: 144, groups: HNDid, 65
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 101.114 88.586 22.400 1.14 0.27
Age 2.869 9.717 58.700 0.30 0.77
IPVstatus -34.595 134.283 42.800 -0.26 0.80
SexMen -74.314 230.676 73.600 -0.32 0.75
RaceAfrAm 65.033 98.711 24.900 0.66 0.52
Age:IPVstatus -2.539 13.870 80.900 -0.18 0.86
Age:SexMen -5.669 28.057 84.400 -0.20 0.84
IPVstatus:SexMen 387.595 272.442 61.000 1.42 0.16
Age:RaceAfrAm 0.348 10.524 58.700 0.03 0.97
IPVstatus:RaceAfrAm -42.048 159.417 42.000 -0.26 0.79
SexMen:RaceAfrAm 27.395 238.287 71.200 0.11 0.91
Age:IPVstatus:SexMen 25.474 31.164 86.700 0.82 0.42
Age:IPVstatus:RaceAfrAm 1.890 16.442 76.100 0.11 0.91
Age:SexMen:RaceAfrAm -0.491 28.653 85.500 -0.02 0.99
IPVstatus:SexMen:RaceAfrAm -173.571 296.839 56.600 -0.58 0.56
Age:IPVstatus:SexMen:RaceAfrAm -24.519 33.401 87.000 -0.73 0.46
Correlation of Fixed Effects:
(Intr) Age IPVstt SexMen RcAfrA Ag:IPV Ag:SxM IPVs:SM Ag:RAA IPV:RA SM:RAA Ag:IPV:SM A:IPV:R A:SM:R IPV:SM:
Age 0.440
IPVstatus -0.660 -0.291
SexMen -0.384 -0.169 0.253
RaceAfrAm -0.897 -0.395 0.592 0.345
Age:IPVstts -0.309 -0.701 0.653 0.118 0.277
Age:SexMen -0.153 -0.346 0.101 0.770 0.137 0.243
IPVstts:SxM 0.325 0.143 -0.493 -0.847 -0.292 -0.322 -0.652
Age:RcAfrAm -0.407 -0.923 0.268 0.156 0.495 0.647 0.320 -0.132
IPVstts:RAA 0.556 0.245 -0.842 -0.213 -0.619 -0.550 -0.085 0.415 -0.307
SxMn:RcAfrA 0.372 0.164 -0.245 -0.968 -0.414 -0.115 -0.746 0.820 -0.205 0.257
Ag:IPVst:SM 0.137 0.312 -0.291 -0.693 -0.123 -0.445 -0.900 0.764 -0.288 0.245 0.671
Ag:IPVs:RAA 0.260 0.591 -0.551 -0.100 -0.317 -0.844 -0.205 0.272 -0.640 0.685 0.131 0.375
Ag:SxMn:RAA 0.149 0.339 -0.099 -0.754 -0.182 -0.238 -0.979 0.639 -0.367 0.113 0.767 0.882 0.235
IPVs:SM:RAA -0.298 -0.131 0.452 0.777 0.333 0.296 0.599 -0.918 0.165 -0.537 -0.803 -0.701 -0.368 -0.616
A:IPV:SM:RA -0.128 -0.291 0.271 0.647 0.156 0.415 0.840 -0.713 0.315 -0.337 -0.658 -0.933 -0.492 -0.858 0.756
(st = step(mm1))
Random effects:
Chi.sq Chi.DF elim.num p.value
(Age | HNDid) 1.15 1 1 0.2839
(Age + 0 | HNDid) 0.63 1 2 0.4271
(1 | HNDid) 52.75 1 kept <1e-07
Fixed effects:
Sum Sq Mean Sq NumDF DenDF F.value elim.num Pr(>F)
Age:IPVstatus:Sex:Race 4918.60 4918.60 1 110.39 0.5890 1 0.4444
IPVstatus:Sex:Race 59.21 59.21 1 59.42 0.0069 2 0.9341
Age:IPVstatus:Race 10828.17 10828.17 1 129.72 0.0896 3 0.7651
Age:IPVstatus:Sex 11345.57 11345.57 1 119.35 0.1404 4 0.7086
Age:IPVstatus 8647.36 8647.36 1 120.20 0.0070 5 0.9334
IPVstatus:Race 6848.53 6848.53 1 65.05 0.3598 6 0.5507
Age 5880.34 5880.34 1 115.87 3.4313 kept 0.0665
IPVstatus 3374.53 3374.53 1 62.22 1.5173 kept 0.2227
Sex 36403.79 36403.79 1 70.88 0.0694 kept 0.7930
Race 4738.87 4738.87 1 74.35 0.2068 kept 0.6506
Age:Sex 7183.55 7183.55 1 115.87 0.8634 kept 0.3547
IPVstatus:Sex 68964.90 68964.90 1 62.22 8.4142 kept 0.0051
Age:Race 15438.05 15438.05 1 116.42 3.7511 kept 0.0552
Sex:Race 941.77 941.77 1 74.35 1.4194 kept 0.2373
Age:Sex:Race 17675.06 17675.06 1 116.42 5.5475 kept 0.0202
Least squares means:
Sex Race Estimate Standard Error DF t-value Lower CI Upper CI p-value
Sex Women 2.0 NA 108.9 26.4 61.6 4.12 56.097 162 0.0001
Sex Men 1.0 NA 163.9 35.5 60.4 4.61 92.839 235 <2e-16
Race White NA 2.0 114.1 41.6 60.9 2.74 30.940 197 0.0080
Race AfrAm NA 1.0 158.7 18.0 61.3 8.82 122.746 195 <2e-16
Sex:Race Women White 2.0 2.0 95.8 48.0 61.9 2.00 -0.124 192 0.0503
Sex:Race Men White 1.0 2.0 132.3 67.9 60.4 1.95 -3.464 268 0.0559
Sex:Race Women AfrAm 2.0 1.0 121.9 24.7 62.1 4.93 72.532 171 <2e-16
Sex:Race Men AfrAm 1.0 1.0 195.5 26.2 60.6 7.47 143.203 248 <2e-16
Differences of LSMEANS:
Estimate Standard Error DF t-value Lower CI Upper CI p-value
Sex Women-Men -55.1 44.3 60.8 -1.24 -144 33.46 0.22
Race White-AfrAm -44.6 46.3 61.1 -0.96 -137 47.96 0.34
Sex:Race Women White- Men White -36.5 83.2 60.9 -0.44 -203 129.73 0.66
Sex:Race Women White- Women AfrAm -26.1 55.1 62.4 -0.47 -136 84.10 0.64
Sex:Race Women White- Men AfrAm -99.7 54.7 61.6 -1.82 -209 9.56 0.07
Sex:Race Men White- Women AfrAm 10.4 72.3 60.6 0.14 -134 154.96 0.89
Sex:Race Men White- Men AfrAm -63.2 74.4 60.4 -0.85 -212 85.66 0.40
Sex:Race Women AfrAm- Men AfrAm -73.6 36.0 61.3 -2.05 -146 -1.66 0.05
Final model:
lme4::lmer(formula = TrailsBtestSec ~ Age + IPVstatus + Sex +
Race + (1 | HNDid) + Age:Sex + IPVstatus:Sex + Age:Race +
Sex:Race + Age:Sex:Race, data = IPV, REML = reml, contrasts = l)
plot(st)