Phillip M. Alday
14 May 2019 (Nijmegen)
You need to remember that “likelihood” is a technical term. The likelihood of \( H \), \( Pr(O\|H) \), and the posterior probability of \( H \), \( Pr(H\|O) \), are different quantities and they can have different values. The likelihood of \( H \) is the probability that \( H \) confers on \( O \), not the probability that \( O \) confers on \( H \). Suppose you hear a noise coming from the attic of your house. You consider the hypothesis that there are gremlins up there bowling. The likelihood of this hypothesis is very high, since if there are gremlins bowling in the attic, there probably will be noise. But surely you don’t think that the noise makes it very probable that there are gremlins up there bowling. In this example, \( Pr(O\|H) \) is high and \( Pr(H\|O) \) is low. The gremlin hypothesis has a high likelihood (in the technical sense) but a low probability.
Sober, E. (2008). Evidence and Evolution: the Logic Behind the Science. Cambridge University Press.
anova()
lme4 allows you to pick your optimizer and change its settings. ?convergence ?lmerControllibrary("lme4")
library("lattice")
xyplot(Reaction ~ Days | Subject, sleepstudy, type = c("g","p","r"),
index = function(x,y) coef(lm(y ~ x))[1],
xlab = "Days of sleep deprivation",
ylab = "Average reaction time (ms)", aspect = "xy")
m <- lmer(Reaction ~ 1 + Days + (1|Subject), data=sleepstudy, REML=FALSE)
summary(m)
Linear mixed model fit by maximum likelihood ['lmerMod']
Formula: Reaction ~ 1 + Days + (1 | Subject)
Data: sleepstudy
AIC BIC logLik deviance df.resid
1802.1 1814.9 -897.0 1794.1 176
Scaled residuals:
Min 1Q Median 3Q Max
-3.2347 -0.5544 0.0155 0.5257 4.2648
Random effects:
Groups Name Variance Std.Dev.
Subject (Intercept) 1296.9 36.01
Residual 954.5 30.90
Number of obs: 180, groups: Subject, 18
Fixed effects:
Estimate Std. Error t value
(Intercept) 251.4051 9.5062 26.45
Days 10.4673 0.8017 13.06
Correlation of Fixed Effects:
(Intr)
Days -0.380
theta <- getME(m,"theta")
print(theta)
Subject.(Intercept)
1.165612
print(VarCorr(m))
Groups Name Std.Dev.
Subject (Intercept) 36.012
Residual 30.895
ff <- as.function(m)
tvec <- seq(0,2,length=101)
Lvec <- sapply(tvec,ff)
par(bty="l",las=1)
par(lwd=2, cex=2)
par(mar=c(4,4,1,2))
plot(tvec,Lvec,type="l",
ylab="Deviance",
xlab="scaled random effects standard deviation",
ylim=c(1750,1901))
points(theta,ff(theta),pch=16,col=1)
m2 <- lmer(Reaction ~ 1 + Days + (1 + Days | Subject), data=sleepstudy, REML=FALSE)
anova(m,m2)
Data: sleepstudy
Models:
m: Reaction ~ 1 + Days + (1 | Subject)
m2: Reaction ~ 1 + Days + (1 + Days | Subject)
Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
m 4 1802.1 1814.8 -897.04 1794.1
m2 6 1763.9 1783.1 -875.97 1751.9 42.139 2 7.072e-10 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print(VarCorr(m2))
Groups Name Std.Dev. Corr
Subject (Intercept) 23.7798
Days 5.7168 0.081
Residual 25.5919
Partial image for intercept with constant (optimal) slope and correlation.
Linear mixed model fit by maximum likelihood ['lmerMod']
Formula: Reaction ~ 1 + Days + ((1 | Subject) + (0 + Days | Subject))
Data: sleepstudy
AIC BIC logLik deviance df.resid
1762 1778 -876 1752 175
Scaled residuals:
Min 1Q Median 3Q Max
-3.9536 -0.4673 0.0239 0.4625 5.1884
Random effects:
Groups Name Variance Std.Dev.
Subject (Intercept) 584.22 24.17
Subject.1 Days 33.64 5.80
Residual 653.11 25.56
Number of obs: 180, groups: Subject, 18
Fixed effects:
Estimate Std. Error t value
(Intercept) 251.405 6.708 37.481
Days 10.467 1.519 6.889
Correlation of Fixed Effects:
(Intr)
Days -0.194
maxeval)ftol_abs, ftol_rel)theta / RE estimates with additional steps (xtol_abs, xtol_rel)
Option names are all for nloptwrap, the current default lmer() optimizer. glmer still uses bobyqa, which has different names ….
0.1 + 0.1 + 0.1 - 0.3
[1] 5.551115e-17
ftol_rel, xtol_rel, maxeval).control=lmerControl(calc.derivs=FALSE).
Successfully completed optimization may not be the global optimum, but only a local one.
adapted from https://stats.stackexchange.com/questions/384528/lme-and-lmer-giving-conflicting-results/
singularity at the center of galaxy the galaxy M87; from the Event Horizon Telescope
Linear mixed model fit by maximum likelihood ['lmerMod']
Formula: Height ~ Weight + (1 | ID)
Data: DFsing
Control: lmerControl(optimizer = "nloptwrap", calc.derivs = FALSE)
AIC BIC logLik deviance df.resid
60.9 64.9 -26.5 52.9 16
Scaled residuals:
Min 1Q Median 3Q Max
-2.2393 -0.8435 0.2213 0.6692 1.6312
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.0000 0.0000
Residual 0.8251 0.9083
Number of obs: 20, groups: ID, 10
Fixed effects:
Estimate Std. Error t value
(Intercept) 2.53589 0.50572 5.014
Weight 0.75121 0.06368 11.797
Correlation of Fixed Effects:
(Intr)
Weight -0.916
rePCA() performs PCA on the random-effects matrix.sleepstudy, we could get 96% of the variance explained with one RE term!summary(rePCA(m2))
$Subject
Importance of components:
[,1] [,2]
Standard deviation 0.9294 0.22260
Proportion of Variance 0.9457 0.05425
Cumulative Proportion 0.9457 1.00000
I am working on an R-package that will fit models in Julia and then turn them into lme4 fits …
Some interesting reading on that note: https://nextjournal.com/dmbates/complexity-in-fitting-linear-mixed-models/