#install.packages("remotes")
#remotes::install_github("DevPsyLab/petersenlab")
library("petersenlab")
library("lme4")
library("nlme")
library("lmerTest")
library("MASS")
library("MCMCglmm")
library("performance")
library("ggplot2")
mydata <- read.csv("https://osf.io/cqn3d/download")
set.seed(52242)
mydata$outcome <- rpois(nrow(mydata), 4)
These models go by a variety of different terms:
https://isaactpetersen.github.io/Principles-Psychological-Assessment/reliability.html#mixedModels
It can be helpful to center the age/time variable so that the intercept in a growth curve model has meaning. For instance, we can subtract the youngest participant age to set the intercepts to be the earliest age in the sample.
mydata$ageYears <- mydata$age / 12
mydata$ageMonthsCentered <- mydata$age - min(mydata$age, na.rm = TRUE)
mydata$ageYearsCentered <- mydata$ageMonthsCentered / 12
For small sample sizes, restricted maximum likelihood (REML) is preferred over maximum likelihood (ML). ML preferred when there is a small number (< 4) of fixed effects; REML is preferred when there are more (> 4) fixed effects. The greater the number of fixed effects, the greater the difference between REML and ML estimates. Likelihood ratio (LR) tests for REML require exactly the same fixed effects specification in both models. So, to compare models with different fixed effects with an LR test (to determine whether to include a particular fixed effect), ML must be used. In contrast to the maximum likelihood estimation, REML can produce unbiased estimates of variance and covariance parameters, variance estimates are larger in REML than ML. To compare whether an effect should be fixed or random, use REML. To simultaneously compare fixed and random effects, use ML.
The following models are models that are fit in a linear mixed modeling framework.
ggplot(
data = mydata,
mapping = aes(
x = ageYears,
y = math,
group = id)) +
geom_line() +
scale_x_continuous(
name = "Age (Years)") +
scale_y_continuous(
name = "Math Score")
lme4
linearMixedModel <- lmer(
math ~ female + ageYearsCentered + female:ageYearsCentered + (1 + ageYearsCentered | id), # random intercepts and slopes; sex as a fixed-effect predictor of the intercepts and slopes
data = mydata,
REML = FALSE, #for ML
na.action = na.exclude,
control = lmerControl(optimizer = "bobyqa"))
summary(linearMixedModel)
Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
method [lmerModLmerTest]
Formula: math ~ female + ageYearsCentered + female:ageYearsCentered +
(1 + ageYearsCentered | id)
Data: mydata
Control: lmerControl(optimizer = "bobyqa")
AIC BIC logLik deviance df.resid
15857.9 15903.5 -7920.9 15841.9 2213
Scaled residuals:
Min 1Q Median 3Q Max
-3.3750 -0.5174 0.0051 0.5239 2.6396
Random effects:
Groups Name Variance Std.Dev. Corr
id (Intercept) 62.5365 7.9080
ageYearsCentered 0.6767 0.8226 0.08
Residual 32.1505 5.6701
Number of obs: 2221, groups: id, 932
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 30.51401 0.56142 752.48747 54.352 <2e-16 ***
female -0.61290 0.79482 736.39886 -0.771 0.441
ageYearsCentered 4.26792 0.11253 610.09410 37.925 <2e-16 ***
female:ageYearsCentered -0.02558 0.16092 598.89155 -0.159 0.874
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) female agYrsC
female -0.706
ageYrsCntrd -0.635 0.448
fml:gYrsCnt 0.444 -0.631 -0.699
newData <- expand.grid(
female = c(0, 1),
ageYears = c(
min(mydata$ageYears, na.rm = TRUE),
max(mydata$ageYears, na.rm = TRUE))
)
newData$ageYearsCentered <- newData$ageYears - min(newData$ageYears)
newData$sex <- NA
newData$sex[which(newData$female == 0)] <- "male"
newData$sex[which(newData$female == 1)] <- "female"
newData$sex <- as.factor(newData$sex)
newData$predictedValue <- predict( # predict.merMod
linearMixedModel,
newdata = newData,
re.form = NA
)
ggplot(
data = newData,
mapping = aes(x = ageYears, y = predictedValue, color = sex)) +
xlab("Age (Years)") +
ylab("Math Score") +
geom_line()
mydata$predictedValue <- predict(
linearMixedModel,
newdata = mydata,
re.form = NULL
)
ggplot(
data = mydata,
mapping = aes(x = ageYears, y = predictedValue, group = factor(id))) +
xlab("Age (Years)") +
ylab("Math Score") +
geom_line()
ggplot(
data = mydata,
mapping = aes(x = ageYears, y = predictedValue, group = factor(id))) +
xlab("Age (Years)") +
ylab("Math Score") +
geom_line() +
geom_line(
data = newData,
mapping = aes(x = ageYears, y = predictedValue, group = sex, color = sex),
linewidth = 2)
ranef(linearMixedModel)
$id
(Intercept) ageYearsCentered
201 1.125313761 0.214025701
303 -12.515508864 -0.661489657
2702 12.257492354 0.430762981
4303 2.727957524 0.285002116
5002 1.943700949 0.170789619
5005 4.045982598 0.120286722
5701 12.299499720 0.346624148
6102 10.023593786 0.863981478
6801 10.850796246 0.310493680
6802 11.821009201 0.402109281
6803 13.002187545 0.661133879
9603 4.893027085 0.449774173
12401 2.267934250 0.215890170
12801 3.118093119 0.121909799
13702 9.965512365 0.174385818
13801 14.860587450 0.466936045
13803 12.244139122 0.342974140
17201 8.389382622 0.541441962
18601 -9.114431785 -0.325174564
22104 -8.224888366 -0.162602823
22901 -3.619019303 -0.120180576
23602 8.688461076 0.339697533
23701 3.179383329 -0.022949766
24402 5.504641645 0.352394764
26201 9.719849574 0.702414569
28503 -8.430258804 0.354120841
29201 12.005754759 0.186774027
29202 8.417070934 0.781161659
34401 13.282239330 0.463013476
35401 6.780780604 0.582522293
35402 5.591003405 -0.049981300
36901 15.699222750 0.479509729
36902 10.244502566 0.276867605
37403 -1.843161415 -0.402326018
38202 -3.239859256 -0.028890813
38802 -5.250923211 -0.340856108
40501 3.463053677 0.153135154
40702 7.971281145 0.173100533
42504 2.888138805 0.321177217
42505 6.585722700 -0.155175248
43103 4.433636752 0.238674652
45201 8.183501056 0.541547032
45903 15.716178377 0.502448721
46201 11.011297054 0.881456660
47201 14.720202046 0.427719979
47402 0.880121442 -0.190353845
47601 1.216021904 -0.017165043
48502 -2.519553727 0.312149007
49501 1.743541361 0.182682300
53601 -2.357792771 -0.378382000
55201 8.475516854 0.442472479
55801 2.607026981 0.226992780
56301 -5.108650931 0.279722834
56302 -0.069098635 0.007631557
57604 10.137559691 0.648424109
58503 -9.038592483 -0.145716134
62102 7.594264242 0.514296379
62103 -11.659099523 0.062806196
62202 12.282894687 0.512176358
62703 0.465584787 0.534532255
64002 0.758192010 -0.318985718
65601 12.288113181 0.422395609
65701 11.634539842 0.659937401
66002 4.577549270 0.481784449
70801 -1.720978172 -0.098222417
73602 3.129767946 0.121536903
74602 4.600091569 0.228352651
75603 -8.954581426 -0.158125796
76402 0.105445380 -0.276301811
76403 4.265544047 0.284415843
80102 3.858025733 0.287026976
82901 -3.386576272 -0.285969402
83001 -1.334354997 -0.271017391
83101 -6.092041392 -0.315778466
83102 -0.060917140 -0.148750133
83602 4.330407333 -0.021683400
83603 -0.359555292 0.065349949
85402 -2.755742657 -0.098799494
87501 -1.199237512 -0.175971326
87901 3.270068645 0.148146826
88902 -5.915202379 -0.317691655
89303 -0.058364793 -0.053342839
89803 6.548041328 0.642729376
90002 10.903475521 0.450119296
92303 1.585091240 -0.179298523
93202 -3.666591112 -0.040016525
93901 -3.564923756 -0.080818748
94002 0.625658727 0.677971537
96201 -2.014940963 -0.158988595
96202 -4.068449608 -0.163941086
98102 6.960679147 0.369901362
101701 0.168658221 -0.517413498
101702 -3.629285495 0.142066301
103501 -5.892939203 -0.645193590
108201 16.298148686 0.607038953
113001 8.357403604 0.635293810
113201 5.570042678 0.382727677
114101 -8.066311147 -0.029666619
114702 4.802081813 0.209318715
115901 2.373140471 0.543510541
116002 0.862849698 -0.047444533
116004 11.272635078 0.530370201
118402 11.180501318 0.376954789
122301 -7.041208476 -0.087766848
124201 -2.235992657 -0.057998101
124402 -6.654073179 -0.360197908
125002 -2.036353581 -0.270098667
126101 3.297895109 0.262547616
129502 -6.797821803 -0.419879120
129601 -4.382931097 -0.160115222
129602 0.466740158 0.017451223
132301 9.786381148 0.576039297
132402 -8.839831108 -0.350099054
132403 0.438064947 -0.144665332
136001 -5.458706565 -0.412198348
138901 2.422614923 -0.241055794
138902 -0.353560559 -0.051066863
139902 10.080325125 0.725346721
140004 -3.496297543 0.282378348
140104 -8.512781578 -0.655296107
140901 -0.115083608 0.716800588
140902 0.707055960 -0.308476123
141001 9.865281000 0.428920620
141601 3.020939622 -0.023542778
141603 0.627584701 -0.092923215
143901 3.106422910 0.127377649
144004 0.045069645 -0.112213249
153203 16.087092196 0.356217483
153204 -17.430077261 -0.616817016
153801 0.564118516 -0.113333334
155902 -8.936419914 -0.348618461
156401 12.187261187 0.348144705
156605 10.323654494 0.486995803
158701 8.513660697 0.336830662
158702 10.497163871 0.545777637
159605 -14.147922125 -0.755640107
159606 -11.066745066 -0.540698054
159801 -9.058337641 0.180842500
165501 -8.160174645 -0.377886697
165602 4.162599565 0.224329239
165701 -10.200591739 -0.555846787
165801 7.416486078 0.158087240
166602 -1.002994170 0.072206197
166603 -11.911124448 -0.292497710
167501 11.597707011 0.876649436
167502 17.304114029 0.737624890
169003 -0.779869964 -0.052336104
170403 -3.714540532 -0.672213772
170404 -5.285749530 -0.231791835
171401 -9.836468983 -0.069591914
172502 4.642796953 -0.407352298
173001 -5.588181640 -1.754863314
173201 0.578502007 0.031869950
174001 10.240215969 0.382702555
175405 -10.792035414 -0.348151265
175801 -7.789717327 -0.412713911
176003 8.715520376 -0.004390948
178901 -8.060279252 -0.232927660
179401 -5.537013298 -0.293072902
179701 -2.918516341 -0.698092331
180301 7.530934833 0.497157407
181801 -1.508291042 -0.134899316
182903 -0.244975730 -0.013902331
185304 2.293821497 -0.050900857
187803 2.406041176 0.434335498
188002 5.547847871 -0.253696393
188502 7.326775168 0.461852110
189601 7.020803583 0.239798464
189602 2.295523328 0.565604150
190202 2.361864346 0.109192928
190501 11.272910613 0.411262167
191202 0.109786069 0.287007128
193601 -6.460102071 0.726747858
193803 5.864314159 0.349916488
196002 -6.930064877 -0.316839993
196201 3.816025703 0.426787984
196202 -0.173952604 -0.230887906
204602 9.043456136 0.353334576
205802 8.940355783 0.987958401
207102 10.906815310 0.632212233
207202 3.946083434 0.614767925
207301 -0.305794959 -0.219240732
212001 5.175627775 0.307630681
213101 -1.604988068 -0.157754955
213702 1.853348987 0.136708618
215304 -1.680247506 0.283103740
216701 7.463945088 0.259872555
217402 4.141544076 0.234240048
219003 2.764968942 0.701685107
220401 3.029593716 0.699986352
221202 8.544703486 0.357270902
223002 15.104320740 0.623124524
224901 -4.469678843 -0.379986217
226001 -8.061210006 0.098195084
226502 -7.274549310 -0.100782710
226704 -7.527709790 -0.321128624
227002 2.461705710 -0.802262248
227101 -10.912047462 -0.095120844
227102 3.993605419 0.448123850
227201 -3.041064530 -0.137936840
231502 -7.742581030 0.041937232
233301 -1.019109719 -0.378574893
233901 9.003114610 0.382666793
233902 5.981925269 0.186142904
235503 -8.586220486 -0.338828100
236002 -3.383562465 -0.415619283
236201 -6.061759642 0.038488620
236202 -10.602033124 -0.071094358
236901 5.500138415 0.331178677
237501 6.492126787 0.518736481
238301 -1.069920262 -0.345037345
239603 -4.794009822 -0.505654150
239604 -3.138157293 -0.053065007
240701 -2.633824808 -0.230222843
240702 -5.845413982 0.313454961
244201 0.821623905 -0.010520847
244702 0.386389868 0.049039506
245903 -1.389917735 -0.441635774
248402 -9.640091283 -0.385119312
250502 1.575879281 0.185416145
252902 -8.705342925 -0.428989701
253001 -3.472250915 -0.321775121
253603 -3.952048624 -0.234004326
253802 0.813068757 -0.321677569
254901 1.557440949 0.242732961
255201 4.499756962 0.033367834
255901 -12.966621777 -0.095135814
255902 -6.408643305 -0.249179468
255903 -0.068506317 0.018661532
258801 10.066745258 0.473779137
260702 10.140891704 0.574527205
261501 -6.274288059 -0.078233942
261502 -5.275763532 0.442941285
261503 -3.768648304 -0.388219736
262601 3.713484558 -0.009543953
262602 13.156712564 0.474759507
263801 11.035679006 0.567834817
265902 0.656276991 -0.696886948
268301 -7.098532980 -0.305426775
268303 -3.792822734 -0.106412940
268901 -2.171914979 -0.078913196
268902 -0.431021818 -0.352369652
269001 -6.011169857 -0.488260650
269101 1.858122812 0.001046154
269102 -2.443573441 0.415726816
269902 4.732520442 0.381227590
271001 -2.477610234 -0.146752234
272903 3.562984351 -0.084305656
273501 6.570778698 0.281221305
274401 -2.812921787 -0.263584631
277002 -1.087288775 -0.304425636
277003 2.438031125 0.050445057
277502 -0.269337940 -0.041138191
278103 4.245009083 0.708932977
281001 -0.006211057 -0.564986398
281901 0.663646457 0.008984918
282602 2.931241086 0.373471582
282603 9.565849274 0.545267076
287702 11.892041859 0.660432677
288501 5.787422166 0.216667586
290901 13.929416909 0.821404683
290902 1.730188742 0.132665289
291101 6.259580343 0.294992854
294902 12.621060269 0.244878842
294903 4.072045749 0.087980535
295901 15.894522897 0.084921874
295902 14.439897307 0.297412167
296401 5.254230369 0.531416207
297901 0.856386616 -0.254469811
297902 -0.317311625 0.087017537
298301 -0.060917140 -0.148750133
301101 12.475974495 0.832250226
301401 2.948685577 -0.147761333
302301 0.416783844 0.060061145
302702 0.821664368 -0.089719049
302703 -0.236039902 0.125432324
304103 -4.456206190 0.013561574
304605 -4.255831240 -0.130330842
307301 3.310356602 -0.241802776
307501 -6.283556136 -0.083599724
309802 9.967256858 0.457526730
309901 3.484441714 -0.116828550
310101 1.290473853 0.216435818
311301 -0.080565206 -0.101463857
311701 1.194153804 0.038496161
312102 4.729692013 0.239638219
312201 6.695393683 0.210621990
312901 -2.426393020 -0.576742792
314501 12.287217891 0.539511886
315001 4.880252353 0.291273041
315002 13.783249241 0.739403986
315602 9.531309188 0.466146167
316301 7.479274636 0.567983219
316501 3.430731315 0.177619705
316502 4.093043825 0.093542139
319002 -0.169959992 -0.006645019
319801 2.316432546 -0.055008041
320101 -0.590631906 -0.433742436
320102 5.817675834 0.281357695
322505 8.674753283 0.562890678
324401 12.299517798 0.797447725
324402 4.946384990 0.388171137
324801 8.928434794 0.521462250
325401 -1.069020836 0.078768504
325402 13.458927332 0.509744340
325904 -7.522413853 -0.525541971
326901 -1.850392851 -0.213568608
328702 5.099223572 -0.092063809
328703 4.774712475 0.172466962
330601 -2.762453096 -0.532733818
331506 -6.722315938 -0.032499717
334201 0.565220953 -0.702132818
335001 7.357640498 0.275755052
335002 6.382367575 0.176234888
335501 -2.374164673 0.235733420
336401 1.185753997 -0.636458965
336902 -2.810051956 -0.539564109
340702 5.691374442 0.431253177
340801 -1.079168948 -0.042968743
342301 8.287865554 0.418811940
342302 2.963952990 0.322217400
342402 8.445022113 0.305838605
343302 0.814012955 -0.236369473
344602 3.405934612 0.408305541
346501 5.906782681 0.108977062
347603 -0.806916394 -0.093040005
348103 3.580506175 0.234122072
349101 1.276366531 0.448666727
352201 3.186328990 0.040560676
353101 -1.947908706 -0.288351018
353102 -2.380699827 -0.099749105
354502 9.850394404 0.528654400
354503 9.198698723 0.503643488
354801 -3.600435817 -0.005165597
356402 -5.925097334 -0.571168841
357203 5.670392546 0.505695693
358401 7.765470294 0.330832752
358601 6.140216902 0.314740464
360901 7.365502773 0.282066811
360903 2.573338090 0.148418657
362402 12.566228909 0.502017802
363501 -4.845935868 -0.025504536
364103 4.081607768 0.345151016
367903 -7.797804095 -0.300318789
369702 -3.537069987 -0.288148448
369704 -5.367416735 -0.466579600
370303 -12.143514791 -0.661565047
371502 -1.070681969 0.405907424
371503 9.158128639 0.370666653
372901 -2.054821266 -0.007560218
373401 2.089441579 -0.635811582
373402 0.662371372 0.159297299
373701 -0.288263307 0.003967021
373702 5.644432823 0.322687131
374001 -0.110747486 -0.287723126
374601 0.735524428 0.466568380
374603 13.910932960 0.652962737
375303 2.546408677 -0.043788948
379301 -4.467474981 -0.061563521
379801 2.594953809 0.092579877
379805 6.491025148 0.348084566
380201 8.253721688 0.600937233
381701 11.880686797 0.601939035
382101 -3.172071996 -0.512316258
389902 8.452419713 0.525815025
389903 8.152486867 0.455231844
389904 7.664125643 0.176022901
392102 3.039081126 0.530694935
392103 5.318129275 0.121889968
392301 5.085592795 0.793953355
392303 12.050125677 0.437434640
392401 7.264713421 0.552898978
392402 13.512432396 0.609820206
396202 -13.398745317 -0.946938695
397202 8.679382924 0.091041479
399503 -0.705322629 -0.146010479
400101 8.118709048 0.075614547
403701 -0.287986671 -0.051668622
404503 2.423199648 0.012482426
405002 6.685913424 0.373602320
407702 -9.576743777 -0.251857014
408501 -3.236321500 -0.053226091
411002 -0.617464682 -0.225721762
413202 -6.634279519 -1.016926229
413203 -2.213288415 -0.954349714
413301 -2.882921861 -0.161289727
419401 -6.373053672 0.189996879
420001 -4.571501859 -0.058357128
421001 3.075297678 -0.268336113
422401 5.343843769 0.178984109
424602 5.060375861 0.294690080
425401 5.432593598 0.382583700
425402 2.867481495 0.648454212
425601 2.336594616 0.003970176
427502 -7.140019026 -0.228993677
427703 -1.422417256 0.034062131
431002 1.334772249 -0.038506921
433901 15.572315818 0.288654765
433902 11.537290700 0.286677735
435201 8.604062734 0.596907622
436602 1.286319883 0.083146056
437201 8.199462385 0.436321271
439602 -1.165039552 -0.145739082
442301 9.283673513 0.599666755
442401 5.058711460 0.149529313
442801 12.422994645 0.514664140
443701 3.372151631 0.034408513
443702 2.965683552 0.327947098
443902 3.330639612 0.094353232
444702 2.245534630 0.067226124
448304 -2.523919127 -0.125969751
449401 6.124366003 0.278531064
449501 8.108084433 0.541782203
449601 0.408119166 -0.532499979
449602 6.202286590 0.358563313
452601 5.409230887 0.243634746
453601 5.693903038 0.213866602
453602 -5.393656916 0.057688338
453801 1.806629624 0.220752263
453802 -2.973447072 -0.002836201
453901 7.956689417 0.239268753
453902 8.794889567 0.541355860
456401 5.376041588 0.429696055
457002 5.982731795 0.382596107
458902 -6.884003869 -0.177102358
459201 9.832842881 0.295319911
461402 -5.223562473 0.143944877
463102 -5.914604999 -0.038007959
463702 6.741926582 0.487732984
466201 11.510648679 0.483259001
468301 9.663006601 0.603336592
468302 -8.402799551 0.015900699
468303 8.048645994 0.423556521
471701 4.069906707 0.601552192
471702 3.402939075 0.080496875
472303 7.309057094 0.598630621
474602 2.784221554 0.020671451
474603 4.789628688 -0.036726535
474604 -0.450573465 0.677573886
475401 16.015447512 0.789573937
476601 5.337282412 0.220270084
478501 -0.685925717 0.332780434
480103 9.355832661 0.208839722
481502 7.147688434 0.171696892
482002 9.281364359 0.374158855
482602 8.743116208 0.661362831
487101 -1.809375644 -0.304686432
488001 11.916067532 0.506033601
488201 6.919367836 0.797842059
488202 6.038326722 0.291781413
489902 -0.996170096 -0.085142207
492501 6.359078522 0.793704749
492502 4.793253305 0.217510522
492503 0.006056732 0.009332454
493003 -5.864683724 0.089100729
493301 2.406904487 -0.194779821
495202 5.167157506 0.281204854
497302 -0.429859827 0.381261492
497303 1.799132506 0.107613092
497304 4.510515532 0.277992784
497403 3.287678510 0.373230303
499703 -0.080124222 -0.004679628
502802 6.182310300 0.839743266
503201 11.013937291 0.385017956
504101 13.683756959 0.341837997
506601 -5.937988210 -0.115904557
506602 -1.847719318 -0.128445017
509801 -1.217008558 -0.013977666
509802 0.352609641 0.119905736
510002 0.591354117 0.692573879
510301 0.260699490 -0.357018778
510401 1.629703525 0.313254488
511901 1.470324831 0.126388948
513404 -5.060626103 0.282216269
513405 -3.196731473 -0.480975630
515102 8.546242755 0.295816500
516401 1.572021876 0.083987753
518003 8.172798539 0.353413081
519101 -18.415106357 -0.896889938
519503 -1.371753014 -0.455152222
521602 -3.960317289 -0.532474702
522401 -3.695855272 -0.143703661
523101 -4.384639987 -0.047785062
523201 -4.113749884 0.146941763
523202 0.153012710 0.031958709
524701 1.313244150 0.003955181
524702 4.278511592 -0.264326940
525801 10.488039492 0.466797622
527204 -4.047762593 -0.234372042
531401 0.940685154 0.455729347
531402 7.289578167 0.190362256
531404 7.240013774 0.331596609
531704 -1.650361063 -0.144601048
532601 1.800864423 -0.097583415
532802 -1.677542168 -0.824563729
533002 -5.703553240 0.170866305
533003 6.363244048 0.404819652
534103 15.151287734 0.685514121
537002 4.332209827 -0.447212584
537302 1.937192727 0.519193957
537304 14.199697268 0.744478103
537602 3.141027671 0.439343803
538102 -0.138505963 0.111396227
538703 1.378764507 0.785718978
538704 4.075748871 0.100023981
542702 -1.409693646 -0.230369024
542703 -6.687669938 -0.266286499
542802 13.407691263 0.356698396
543601 -2.350160514 -0.672815693
543602 -9.889088825 -0.257651627
545402 -8.688790180 -0.309988996
546505 -10.734656936 -1.346391440
546702 -13.593010749 -0.531453404
547701 1.515062357 0.166183160
548501 0.782912576 -0.319916183
549801 2.108432062 -0.070117907
550901 -12.207590324 -0.606792845
551501 -9.483258820 -0.249028575
552203 5.375345633 0.119472457
553701 -8.159310369 0.044498342
553702 -2.139811693 -0.069649375
556101 -4.916585005 -0.608556695
556801 -0.653108704 0.014812013
558301 -6.651518096 -0.724535151
559302 -4.998455197 -0.009225589
560902 -5.080406456 -0.546036745
561202 0.914299930 -0.105581452
561402 -1.650460891 -0.401645200
564001 -3.981210746 -0.997318240
564002 -11.964061394 -0.375078260
565601 7.228780094 0.587282473
567002 4.506841997 0.120062683
570601 -4.581916892 -0.394347202
571201 -4.006401224 -0.588944245
571801 2.377697356 0.299360222
571802 6.439438876 0.347286433
572402 -7.448997941 -0.192697636
572801 3.456546909 0.949451425
572802 1.284389677 0.013912093
572803 2.021954122 0.124533751
574003 -9.727922929 -0.477835144
574102 -0.320307604 0.020758475
574602 2.463196484 0.058340403
574603 2.549465760 0.313163093
580202 12.203823999 0.289767654
581303 -6.584442932 -0.299183252
581802 -6.327584741 -0.271856705
586102 5.668892816 0.647542806
587301 -4.796456987 -0.357614187
587303 -3.866231378 -0.114613742
591903 8.151266437 0.427276109
594102 1.983288336 0.760855980
600203 -7.951308547 -0.219342937
602301 -0.089742545 0.088702303
602302 -0.541409817 -0.028474326
602304 -0.129231552 0.002468560
604004 -8.578060685 -0.654845280
604607 -5.359169800 0.124050372
604902 -5.221372571 -0.217412244
607201 1.664383330 0.036623129
607601 -2.474126536 -0.483079001
607602 -13.455962660 -0.348304721
607802 -1.271410157 -0.087873134
610101 -9.640993658 -0.633241497
611802 -0.940294528 0.512491849
613201 5.447005406 0.140823109
613402 -8.043157025 -0.603994188
616105 3.646540805 0.040434304
616402 -2.003597206 -0.432065590
617501 -16.753064578 -0.758201897
621501 2.090728189 -0.090591099
621701 8.017513094 0.061602739
622001 -3.117404067 -0.380963728
623801 -1.096552561 -0.213769511
626201 7.057285064 0.090615207
627702 -2.395033070 -0.162102298
627703 -8.597452591 -0.055319927
627802 -9.020002885 -0.368023234
629404 3.783652406 -0.355473733
629502 4.176765010 0.230099968
631801 -7.316391315 -0.406402539
632205 -12.132319077 -0.249051645
632702 -5.990892500 -0.171403525
632703 -3.234462913 0.043606143
632704 -5.733829052 -0.409870166
634401 -8.312459893 -0.465527636
634503 0.303502674 -0.086974048
635302 -1.498033432 -0.406668296
636402 -15.901044465 -0.608122091
636802 -4.385982190 -0.388351268
637110 -8.842661707 -0.116288161
638402 -1.728818916 -0.404144561
640002 -11.992489942 -0.411548816
640402 -8.845688784 -0.421731402
642601 -13.796063897 -0.693958033
642701 -5.756427948 -0.057758542
642702 -6.808932201 -0.248756386
642901 1.603616016 -0.101585257
642902 -8.239333907 -0.046044308
642903 -10.242537352 -0.208712577
642904 -3.080639103 -0.178553328
643402 -9.413446438 -0.854906422
644203 -2.938326170 -0.327776407
644901 -12.965869279 -0.836975804
648601 -2.497626187 -0.111582921
648602 -1.817813178 -0.165024349
651601 -9.206421401 -0.306663180
665803 -7.937622756 -0.400586179
668403 -3.094074869 -0.203791032
669301 4.288543841 0.203992881
671102 1.650096523 0.192741072
675701 -6.926768526 -0.314028073
677201 -2.217690247 0.184501031
677202 -3.902369697 -0.142733255
678804 -0.983163384 -0.077600270
681601 0.310723059 0.325327512
682502 -3.046918186 -0.108704560
682903 2.590643226 -0.096908763
684201 16.280078439 0.460490211
684203 9.192836006 0.772579781
687602 3.841932936 0.036274111
689101 1.106616352 -0.011870061
690101 -3.325980888 -0.747269213
693001 -1.091016676 -0.435950300
696601 -5.322948686 -0.193431191
700002 -12.025093976 -0.339720875
700003 -15.132582305 -0.552851222
707701 -1.166124231 0.072680470
708401 15.893806763 0.599080922
711602 -9.495807218 -0.228793930
711603 -5.049071022 -0.049297748
712303 0.462837788 -0.633538578
714801 -4.255894456 -0.412541945
714802 6.314626282 -0.095917002
715601 0.853826544 0.537570571
715803 -14.172000226 -0.603752918
716601 12.221371403 0.630392854
716602 7.679000983 0.171371224
717002 -7.515821696 -0.402873460
717003 -7.575151040 -0.504060469
717901 -9.823411841 -0.664607092
717902 -5.873793984 -0.323729629
717903 -6.289457181 -0.088526651
718602 1.131820917 0.511550310
722401 -1.006228629 -0.483989774
722803 4.130434882 0.093201533
723501 0.307440660 0.125419848
725801 -1.696320252 0.438759492
725903 -17.079275454 -1.211660542
737702 -4.388651435 -0.022318441
738201 -2.323832074 -0.082662961
739002 -8.937134009 -0.727537671
739102 -5.479622388 -0.066710565
739301 -5.602359628 -0.445973585
739401 2.968561068 0.001870184
739601 6.194291875 0.076760325
742301 1.224247223 0.083866088
743601 -1.021533187 -0.055151050
743602 -5.660397705 -0.963156384
743801 -4.592250489 0.003493467
743802 -10.643702763 -0.507328981
744102 -17.016481993 -0.373824109
744103 -5.158549836 -0.284186961
744703 -3.259785398 -0.092759390
744704 -8.163758988 0.005928817
745103 5.381951413 0.177010141
745904 0.971919319 0.042952211
748003 -0.722331879 -0.164563391
748502 4.174223809 0.139650670
749802 8.449572727 0.231523244
749803 -1.198480879 -0.318137067
750104 -11.024695311 -0.334826635
750404 1.351435367 -0.527974811
751001 -6.099653262 -0.167631898
752003 0.697845101 -0.445791062
752501 -1.991270419 -0.087024018
760102 -1.034728367 -0.174004389
763603 -8.387036288 -0.315786406
764503 -2.673395685 -0.260101723
765702 1.706178547 -0.085713644
767901 2.219000694 0.054666413
771002 -8.432172662 -0.310977053
775002 7.417445319 0.358097656
778902 -11.782707125 -0.612757333
778903 -1.249249505 -0.704340836
783001 -8.898763592 -0.470550225
783002 -2.057987793 -0.263859943
783301 4.724730332 0.462334273
783502 1.208861841 0.170083010
783602 -1.253856860 -0.045073631
783801 1.319050503 0.284306191
785601 2.710879360 0.164296175
786402 5.178327920 0.242087618
788302 -10.726817911 -0.427258426
788303 -12.016494569 -0.009831985
792103 -2.449710306 0.266315368
792704 -3.273626706 -0.225207718
793001 1.210479848 0.539971187
794301 -10.932162723 -0.450055577
794503 -7.218166115 -0.425840929
795201 -4.249738333 -0.343959448
795901 4.579265935 0.094186547
799803 13.971047989 0.503724235
800602 1.913478000 -0.046791426
804701 -1.519177743 0.205194007
804702 -0.462858324 -0.180163109
809102 -5.218471720 -0.585442071
809103 -8.899982617 -0.839757022
809301 -6.655780200 -0.705423986
810303 1.045058979 0.084625194
811002 -7.206412024 -0.269444781
812504 1.486334628 0.056843620
814101 -0.979875492 -0.047576390
817402 -3.257668016 -0.497166854
817403 -5.087137975 -0.711031193
817404 -5.750879086 -0.581238557
822602 7.013043086 0.420185194
825702 -9.690081735 -0.278014140
825902 -8.608742948 -0.209946447
825903 -3.395839756 -0.527164765
826503 1.469347140 -0.189504850
826504 -18.358242061 -0.978124604
826904 -17.309569594 -0.814240170
826905 -9.616835993 -0.241896347
827101 3.170957010 0.133926977
827302 -6.417483438 -0.062114513
828302 2.747989097 0.196935471
828604 -0.432451327 -0.218443012
828902 -4.744880520 -0.496371189
828903 -4.962825174 -0.391887535
828905 -12.837447967 -0.515666464
829401 -7.300494921 -0.451136076
829403 2.278496761 0.226701780
833601 -0.954648942 -0.046110514
834301 0.185859752 -0.232313965
835202 2.006143445 -0.110537831
835703 -2.622647289 0.215727790
837503 -7.211226372 -0.265336449
837504 -8.857256944 -0.212978546
837602 -13.024762525 -0.390023252
838301 -8.233751839 -0.348036919
838903 3.304616402 0.392749927
841601 0.886759956 0.215410809
841602 0.537895525 0.013521833
846301 10.279980222 0.313542745
847301 -4.210466823 -0.624023570
847302 3.291690158 -0.002044838
847701 8.235072091 0.400242080
847901 -0.432079542 0.114558409
847902 -6.633722012 -0.097355701
848201 4.468851642 0.670151752
849401 0.189416375 -0.149836441
853202 -0.429397010 0.218005012
856103 -3.586214102 -0.092203244
857003 -6.720617097 -0.493204616
858302 -4.204535539 -0.609410105
861503 -3.966967748 0.293400309
861803 -3.135359757 0.264874987
862201 4.653017738 0.132082293
863101 -12.297582748 -0.439929413
863403 -6.477163797 -0.474134043
864302 2.085691014 0.074949397
866203 -9.169437523 -0.147097347
866205 -3.492643017 -0.061050645
866402 -2.782792441 -0.029554824
867903 11.942822075 0.499397590
869001 -7.702502070 -0.202251421
869501 0.806896368 0.352096898
869601 -10.485942895 -0.461798451
870803 8.928434794 0.521462250
878701 -17.568709144 -0.626957686
879403 11.121309995 0.417858606
879404 3.311343239 0.047788637
885801 3.486722522 0.081372459
885802 -16.039468436 -1.050718441
886401 11.077378767 0.671794102
891202 -1.785951488 0.135840571
892601 -6.248449211 -0.100279844
894201 -4.410948902 -0.294281539
894802 -0.313453837 -0.115560234
894803 -5.508871671 -0.307101576
894804 -4.959265629 -0.273862791
897001 -3.323415615 -0.358621058
905003 -6.766784958 -0.578860310
907001 -0.044475957 -0.120023417
908102 -0.826610098 0.037276094
910103 -9.997531168 -0.318016485
911701 1.189104202 0.248190222
914402 4.330045404 0.059557193
918002 1.312890067 -0.031666983
918201 2.010858048 0.084121892
918202 2.960751078 0.071789615
918301 -0.253494219 0.421761227
922901 4.736230982 0.019599188
925503 -2.952847689 -0.184075604
925504 -8.155463950 -0.407774825
925701 -1.560286833 -0.085956943
926102 -11.384931242 -0.440643401
928101 -2.561314916 -0.175971001
929805 2.299878514 0.120028438
931202 6.182482161 0.760747880
931703 -5.921728745 0.253419327
938001 -4.268374580 -0.150332673
938002 -5.203853762 -0.359216554
938205 1.452960485 0.154925383
940103 -2.332263976 -0.136215098
951602 -9.264136115 -0.794456772
952201 -3.740749071 -0.123357170
964101 3.547967803 0.131810129
964102 7.585006320 0.091026089
966001 9.257072985 0.418793561
968001 -0.898120469 -0.728569335
968002 -4.421070337 0.099825430
968003 -8.385332673 -0.022239581
968401 2.945108480 0.304805734
968402 7.276622407 0.604626813
976803 -9.628901937 -0.742544730
982001 -4.695771491 -0.306490550
983703 3.745534505 0.165550609
983902 2.596009547 0.125200150
983903 -3.667967858 -0.155126491
984402 -1.217021320 -0.058975181
984404 -0.789019406 -0.327117617
985802 -3.353538083 -0.397301364
985803 0.978668861 -0.062038203
986203 -2.764543447 -0.702253665
986505 0.235705952 -0.568761949
986506 -5.064852532 -0.934175547
987401 -6.339050700 0.154132170
987701 -4.792430373 -0.496558484
988701 -8.738498236 -0.368233827
989201 -5.672395817 -0.500824137
989503 -3.963618084 -0.191185511
992201 3.713250289 0.037354172
993803 -0.339041448 -0.033276656
995101 -16.855431161 -0.793196728
995102 -16.732009976 -0.816271483
995304 1.141931270 0.039760624
997002 -7.890837919 -0.120332271
998001 2.904616596 -0.099911409
999202 -4.209454375 -0.249228417
999203 -3.445087389 -0.642747361
1002601 -12.615996043 -0.681804312
1003202 -4.900766767 -0.081557288
1003203 -7.168505838 -0.337373360
1003204 -7.477961633 -0.234615583
1003601 4.142234535 0.087851091
1003802 6.694641940 0.582885762
1004802 -6.010511003 -0.127669923
1004903 -5.696529302 0.321126050
1005201 -5.061927500 -0.154374548
1005203 7.744852438 0.359834771
1007201 1.485163277 -0.137844389
1007301 -12.207661253 -0.289172581
1007302 -12.256018327 -0.141761798
1007901 -1.587140380 0.168986153
1013201 -7.449018493 -0.201116136
1017504 -15.113587952 -0.217160076
1018402 -8.195378280 -0.336645460
1018404 -6.060598198 -0.384207768
1019104 -3.898712489 -0.395718677
1019105 -10.441463111 -0.495045209
1023702 0.230071978 -0.062853597
1030801 9.614192285 0.359470695
1031001 7.309989035 0.957296774
1031002 3.338190748 0.463618589
1031302 -7.796511938 -0.032990651
1033202 -13.370171847 -0.281812065
1033601 -5.677419865 -0.172171992
1034001 -6.334557499 -0.663053901
1036001 -2.492905799 0.635495607
1036003 -1.474746601 -0.133442885
1037502 -2.665942104 -0.015951671
1040101 4.276289331 0.440820891
1042101 -2.553330890 -0.258232185
1042201 -6.059952254 -0.189338564
1044801 4.128417062 0.245711117
1047801 -2.849801051 -0.185397056
1050001 -2.717825315 -0.095089574
1050701 -5.872749060 0.457585048
1053201 -0.250978709 -0.100236571
1053202 -6.760663767 -0.293314450
1053802 -6.284836936 0.080095322
1053804 -7.223993827 -0.248573995
1056501 -3.896931891 -0.118419463
1081101 -5.400851712 -0.293731045
1081103 -4.680976218 -0.137297987
1176403 -1.958564728 -0.236731201
1176502 -4.966749948 0.109135738
1179201 5.308169099 -0.088424313
1179202 1.720621134 0.117183301
1180202 -0.431475168 -0.508419596
1181201 -11.704987647 -0.583519704
1181902 -2.349190562 -0.066365192
1181904 -6.320454193 -0.333828815
1182604 -0.232940420 -0.239191587
1185003 -13.222234389 -0.226450008
1187001 3.002185759 -0.284717029
1187303 6.481394612 0.381759227
1189901 8.842299522 0.382244575
1190501 -2.594795950 -0.242898294
1191001 3.134902432 0.262260144
1191901 5.116734779 0.307548594
1194901 -2.642814420 0.740744619
1197902 -7.270379750 -0.242315430
1198101 -1.607639092 -0.129777591
1198901 15.013179772 0.359981902
1201701 -0.835329508 -0.169484890
1201702 -1.378932676 -0.575885435
1203201 -2.032124763 -0.578525839
1205201 -4.566609451 0.130473364
1207601 4.894676196 0.201302925
1209201 0.014426741 -0.133074642
1211502 8.396956305 0.333608159
1211503 5.392613109 0.178489598
1212303 -2.575279428 -0.048814312
1213501 -5.356118638 0.908621520
1217202 -1.881659801 -0.624995211
1217204 -6.521048243 -0.094817905
1217702 -3.406869123 -0.086193891
1217704 -2.337403065 -0.153791714
1219103 -7.263847297 -0.311537184
1219105 -12.688070163 -0.592413772
1219106 -13.168088281 -0.487925838
1219108 2.752059171 0.271825037
1221003 -0.763516936 -0.102460692
1221702 -3.839403600 -0.221064459
1224001 3.233736846 -0.091309850
1225402 -3.826603058 -0.116909854
1228103 -0.096753765 -0.003285703
1230302 -10.049267721 -0.752222025
1256601 -7.299006078 -0.291423458
with conditional variances for "id"
nlme
linearMixedModel_nlme <- lme(
math ~ female + ageYearsCentered + female:ageYearsCentered, # sex as a fixed-effect predictor of the intercepts and slopes
random = ~ 1 + ageYearsCentered|id, # random intercepts and slopes
data = mydata,
method = "ML",
na.action = na.exclude)
summary(linearMixedModel_nlme)
Linear mixed-effects model fit by maximum likelihood
Data: mydata
AIC BIC logLik
15857.85 15903.5 -7920.926
Random effects:
Formula: ~1 + ageYearsCentered | id
Structure: General positive-definite, Log-Cholesky parametrization
StdDev Corr
(Intercept) 7.9079987 (Intr)
ageYearsCentered 0.8225933 0.082
Residual 5.6701380
Fixed effects: math ~ female + ageYearsCentered + female:ageYearsCentered
Value Std.Error DF t-value p-value
(Intercept) 30.514011 0.5619217 1287 54.30296 0.0000
female -0.612896 0.7955333 930 -0.77042 0.4412
ageYearsCentered 4.267923 0.1126360 1287 37.89130 0.0000
female:ageYearsCentered -0.025585 0.1610671 1287 -0.15885 0.8738
Correlation:
(Intr) female agYrsC
female -0.706
ageYearsCentered -0.635 0.448
female:ageYearsCentered 0.444 -0.631 -0.699
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-3.375034869 -0.517409797 0.005105047 0.523910718 2.639557775
Number of Observations: 2221
Number of Groups: 932
icc(linearMixedModel)
icc(linearMixedModel_nlme)
https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html (archived at https://perma.cc/9RFS-BCE7; source code: https://github.com/bbolker/mixedmodels-misc/blob/master/glmmFAQ.rmd)
lmer
generalizedLinearMixedModel <- glmer(
outcome ~ female + ageYearsCentered + (ageYearsCentered | id),
family = poisson(link = "log"),
data = mydata,
na.action = na.exclude)
boundary (singular) fit: see help('isSingular')
summary(generalizedLinearMixedModel)
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: poisson ( log )
Formula: outcome ~ female + ageYearsCentered + (ageYearsCentered | id)
Data: mydata
AIC BIC logLik deviance df.resid
9329.7 9363.9 -4658.8 9317.7 2215
Scaled residuals:
Min 1Q Median 3Q Max
-2.0331 -0.5546 -0.0205 0.5350 5.0222
Random effects:
Groups Name Variance Std.Dev. Corr
id (Intercept) 0.0058309 0.07636
ageYearsCentered 0.0002845 0.01687 -1.00
Number of obs: 2221, groups: id, 932
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.343986 0.027432 48.994 <2e-16 ***
female 0.007439 0.021264 0.350 0.7265
ageYearsCentered 0.010279 0.005877 1.749 0.0803 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) female
female -0.414
ageYrsCntrd -0.835 0.037
optimizer (Nelder_Mead) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
MASS
glmmPQLmodel <- glmmPQL(
outcome ~ female + ageYearsCentered,
random = ~ 1 + ageYearsCentered|id,
family = poisson(link = "log"),
data = mydata)
iteration 1
summary(glmmPQLmodel)
Linear mixed-effects model fit by maximum likelihood
Data: mydata
AIC BIC logLik
NA NA NA
Random effects:
Formula: ~1 + ageYearsCentered | id
Structure: General positive-definite, Log-Cholesky parametrization
StdDev Corr
(Intercept) 5.533290e-05 (Intr)
ageYearsCentered 9.320922e-08 0
Residual 1.014184e+00
Variance function:
Structure: fixed weights
Formula: ~invwt
Fixed effects: outcome ~ female + ageYearsCentered
Value Std.Error DF t-value p-value
(Intercept) 1.3453017 0.027100741 1288 49.64077 0.0000
female 0.0074130 0.021543030 930 0.34410 0.7308
ageYearsCentered 0.0100806 0.005850753 1288 1.72296 0.0851
Correlation:
(Intr) female
female -0.423
ageYearsCentered -0.829 0.036
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-2.00970268 -0.55110605 -0.02158036 0.53179575 4.98914420
Number of Observations: 2221
Number of Groups: 932
MCMCglmm
MCMCglmmModel <- MCMCglmm(
outcome ~ female + ageYearsCentered,
random = ~ us(ageYearsCentered):id,
family = "poisson",
data = na.omit(mydata[,c("id","outcome","female","ageYearsCentered")]))
MCMC iteration = 0
Acceptance ratio for liability set 1 = 0.000410
MCMC iteration = 1000
Acceptance ratio for liability set 1 = 0.439819
MCMC iteration = 2000
Acceptance ratio for liability set 1 = 0.439977
MCMC iteration = 3000
Acceptance ratio for liability set 1 = 0.444608
MCMC iteration = 4000
Acceptance ratio for liability set 1 = 0.496749
MCMC iteration = 5000
Acceptance ratio for liability set 1 = 0.490778
MCMC iteration = 6000
Acceptance ratio for liability set 1 = 0.512362
MCMC iteration = 7000
Acceptance ratio for liability set 1 = 0.428231
MCMC iteration = 8000
Acceptance ratio for liability set 1 = 0.412336
MCMC iteration = 9000
Acceptance ratio for liability set 1 = 0.471726
MCMC iteration = 10000
Acceptance ratio for liability set 1 = 0.428491
MCMC iteration = 11000
Acceptance ratio for liability set 1 = 0.400078
MCMC iteration = 12000
Acceptance ratio for liability set 1 = 0.346435
MCMC iteration = 13000
Acceptance ratio for liability set 1 = 0.276170
summary(MCMCglmmModel)
Iterations = 3001:12991
Thinning interval = 10
Sample size = 1000
DIC: 9323.524
G-structure: ~us(ageYearsCentered):id
post.mean l-95% CI u-95% CI eff.samp
ageYearsCentered:ageYearsCentered.id 6.754e-06 1.087e-08 4.053e-05 7.788
R-structure: ~units
post.mean l-95% CI u-95% CI eff.samp
units 0.00877 0.001634 0.01728 7.797
Location effects: outcome ~ female + ageYearsCentered
post.mean l-95% CI u-95% CI eff.samp pMCMC
(Intercept) 1.338707 1.281096 1.387614 55.58 <0.001 ***
female 0.007688 -0.031193 0.052271 58.65 0.706
ageYearsCentered 0.010561 0.000813 0.021420 57.32 0.046 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
nonlinearModel <- nlme(
height ~ SSasymp(age, Asym, R0, lrc),
data = Loblolly,
fixed = Asym + R0 + lrc ~ 1,
random = Asym ~ 1)
summary(nonlinearModel)
Nonlinear mixed-effects model fit by maximum likelihood
Model: height ~ SSasymp(age, Asym, R0, lrc)
Data: Loblolly
AIC BIC logLik
239.486 251.6401 -114.743
Random effects:
Formula: Asym ~ 1 | Seed
Asym Residual
StdDev: 3.650645 0.7188624
Fixed effects: list(Asym ~ 1, R0 ~ 1, lrc ~ 1)
Value Std.Error DF t-value p-value
Asym 101.44830 2.4616151 68 41.21209 0
R0 -8.62749 0.3179519 68 -27.13459 0
lrc -3.23373 0.0342695 68 -94.36168 0
Correlation:
Asym R0
R0 0.704
lrc -0.908 -0.827
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-2.23604174 -0.62389999 0.05912777 0.65724316 1.95790785
Number of Observations: 84
Number of Groups: 14
To evaluate the extent to which a finding could driven by outliers, this could be done in a number of different ways, such as:
The within-group errors:
The random effects:
Pinheiro and Bates (2000) book (p. 174, section 4.3.1)
https://stats.stackexchange.com/questions/77891/checking-assumptions-lmer-lme-mixed-models-in-r (archived at https://perma.cc/J5GC-PCUT)
Make QQ plots for each level of the random effects. Vary the level from 0, 1, to 2 so that you can check the between- and within-subject residuals.
qqnorm(linearMixedModel_nlme,
~ ranef(., level = 1))
ppPlot(linearMixedModel)
qqnorm(resid(linearMixedModel))
qqline(resid(linearMixedModel))
plot(linearMixedModel)
plot(linearMixedModel,
as.factor(id) ~ resid(.),
abline = 0,
xlab = "Residuals")
plot(linearMixedModel_nlme,
resid(., type = "p") ~ fitted(.) | female) #type = "p" specifies standardized residuals
linearMixedModel_nlmeVarStructure <- lme(
math ~ female + ageYearsCentered,
random = ~ 1 + ageYearsCentered|id,
weights = varIdent(form = ~ 1 | female),
method = "ML",
data = mydata,
na.action = na.exclude)
summary(linearMixedModel_nlmeVarStructure)
Linear mixed-effects model fit by maximum likelihood
Data: mydata
AIC BIC logLik
15857.83 15903.48 -7920.915
Random effects:
Formula: ~1 + ageYearsCentered | id
Structure: General positive-definite, Log-Cholesky parametrization
StdDev Corr
(Intercept) 7.9177716 (Intr)
ageYearsCentered 0.8278343 0.076
Residual 5.6410162
Variance function:
Structure: Different standard deviations per stratum
Formula: ~1 | female
Parameter estimates:
1 0
1.000000 1.009161
Fixed effects: math ~ female + ageYearsCentered
Value Std.Error DF t-value p-value
(Intercept) 30.554856 0.5040373 1288 60.62022 0.0000
female -0.692653 0.6172485 930 -1.12216 0.2621
ageYearsCentered 4.255258 0.0805531 1288 52.82553 0.0000
Correlation:
(Intr) female
female -0.614
ageYearsCentered -0.507 0.014
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-3.37982974 -0.51663213 0.00445497 0.52228733 2.63205084
Number of Observations: 2221
Number of Groups: 932
plot(linearMixedModel,
math ~ fitted(.))
qqnorm(linearMixedModel_nlme, ~ resid(.) | female)
qqnorm(linearMixedModel_nlme, ~ resid(.))
Make QQ plots for each level of the random effects. Vary the level from 0, 1, to 2 so that you can check the between- and within-subject residuals.
qqnorm(linearMixedModel_nlme,
~ ranef(., level = 0))
Error in effects[[1L]]: subscript out of bounds
qqnorm(linearMixedModel_nlme,
~ ranef(., level = 1))
qqnorm(linearMixedModel_nlme,
~ ranef(., level = 2))
Error in eval(i, data, env): object '.y' not found
qqnorm(linearMixedModel_nlme,
~ ranef(., level = 1) | female)
pairs(linearMixedModel_nlme)
pairs(linearMixedModel_nlme,
~ ranef(., level = 1) | female)
varFixed
: fixed variancevarIdent
: different variances per stratumvarPower
: power of covariatevarExp
: exponential of covariatevarConstPower
: constant plus power of covariatevarComb
: combination of variance functionscorCompSymm
: compound symmetrycorSymm
: generalcorAR1
: autoregressive of order 1corCAR1
: continuous-time AR(1)corARMA
: autoregressive-moving averagecorExp
: exponentialcorGaus
: GaussiancorLin
: linearcorRatio
: rational quadraticcorSpher
: sphericalsessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
time zone: UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.5.1 performance_0.13.0 MCMCglmm_2.36 ape_5.8-1
[5] coda_0.19-4.1 MASS_7.3-61 lmerTest_3.1-3 nlme_3.1-166
[9] lme4_1.1-36 Matrix_1.7-1 petersenlab_1.1.1
loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 psych_2.4.12 viridisLite_0.4.2
[4] farver_2.1.2 dplyr_1.1.4 fastmap_1.2.0
[7] tensorA_0.36.2.1 digest_0.6.37 rpart_4.1.23
[10] lifecycle_1.0.4 cluster_2.1.6 magrittr_2.0.3
[13] compiler_4.4.2 rlang_1.1.5 Hmisc_5.2-2
[16] sass_0.4.9 tools_4.4.2 yaml_2.3.10
[19] data.table_1.16.4 knitr_1.49 labeling_0.4.3
[22] htmlwidgets_1.6.4 mnormt_2.1.1 plyr_1.8.9
[25] RColorBrewer_1.1-3 withr_3.0.2 foreign_0.8-87
[28] purrr_1.0.4 numDeriv_2016.8-1.1 nnet_7.3-19
[31] grid_4.4.2 stats4_4.4.2 lavaan_0.6-19
[34] xtable_1.8-4 colorspace_2.1-1 scales_1.3.0
[37] insight_1.0.2 cli_3.6.4 mvtnorm_1.3-3
[40] rmarkdown_2.29 reformulas_0.4.0 generics_0.1.3
[43] rstudioapi_0.17.1 reshape2_1.4.4 minqa_1.2.8
[46] DBI_1.2.3 cachem_1.1.0 stringr_1.5.1
[49] splines_4.4.2 parallel_4.4.2 base64enc_0.1-3
[52] mitools_2.4 vctrs_0.6.5 boot_1.3-31
[55] jsonlite_1.9.0 Formula_1.2-5 htmlTable_2.4.3
[58] jquerylib_0.1.4 glue_1.8.0 nloptr_2.1.1
[61] cubature_2.1.1 stringi_1.8.4 gtable_0.3.6
[64] quadprog_1.5-8 munsell_0.5.1 tibble_3.2.1
[67] pillar_1.10.1 htmltools_0.5.8.1 R6_2.6.1
[70] Rdpack_2.6.2 mix_1.0-13 evaluate_1.0.3
[73] pbivnorm_0.6.0 lattice_0.22-6 rbibutils_2.3
[76] backports_1.5.0 corpcor_1.6.10 bslib_0.9.0
[79] Rcpp_1.0.14 gridExtra_2.3 checkmate_2.3.2
[82] xfun_0.51 pkgconfig_2.0.3