Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + (1 | id)
Data: dat
REML criterion at convergence: 50018.8
Scaled residuals:
Min 1Q Median 3Q Max
-3.1288 -0.5133 -0.0030 0.5213 3.2586
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.6961 0.8343
Residual 0.3007 0.5484
Number of obs: 20000, groups: id, 10000
Fixed effects:
Estimate Std. Error t value
(Intercept) -0.008000 0.009984 -0.801
x 0.303728 0.007755 39.166
Correlation of Fixed Effects:
(Intr)
x -0.388
sb0^2/ (sb0^2+ s^2)
[1] 0.7
summary(fit)
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + (1 | id)
Data: dat
REML criterion at convergence: 50018.8
Scaled residuals:
Min 1Q Median 3Q Max
-3.1288 -0.5133 -0.0030 0.5213 3.2586
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.6961 0.8343
Residual 0.3007 0.5484
Number of obs: 20000, groups: id, 10000
Fixed effects:
Estimate Std. Error t value
(Intercept) -0.008000 0.009984 -0.801
x 0.303728 0.007755 39.166
Correlation of Fixed Effects:
(Intr)
x -0.388
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + age + (x | id)
Data: dat
REML criterion at convergence: 582.7
Scaled residuals:
Min 1Q Median 3Q Max
-3.2763 -0.5854 0.0459 0.6215 2.4063
Random effects:
Groups Name Variance Std.Dev. Corr
id (Intercept) 7.060e-02 0.265698
x 4.231e-06 0.002057 1.00
Residual 9.979e-01 0.998936
Number of obs: 200, groups: id, 10
Fixed effects:
Estimate Std. Error t value
(Intercept) -3.03737 0.87610 -3.467
x 0.35413 0.14127 2.507
age 0.12548 0.03282 3.824
Correlation of Fixed Effects:
(Intr) x
x -0.080
age -0.989 0.000
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
performance::r2(fit)
Random effect variances not available. Returned R2 does not account for random effects.
# R2 for Mixed Models
Conditional R2: NA
Marginal R2: 0.173
library(ggplot2)dat |>ggplot(aes(x = age, y = y)) +geom_point(aes(color =factor(x)))