I add a very small demos with hierarchial modeling for ozone layer where the modeling acknowledges that it varies by month. You can find comparisons below. I could find the R squared
term only in MuMIn
package.
MuMIn package
> data(airquality)
> MuMIn::r.squaredGLMM(lme4::lmer(data=airquality, Ozone ~ 1 + (1|Month)))
R2m R2c
[1,] 0 0.2390012
> summary(lm(data=airquality, Ozone ~ 1 + (1|Month)))$r.squared
[1] 0
where we compare the linear regression and the mixed effect model aka hierarchial regression model.
Linear regression
> summary(lm(data=airquality, Ozone ~ 1 + (1|Month)))
Call:
lm(formula = Ozone ~ 1 + (1 | Month), data = airquality)
Residuals:
Min 1Q Median 3Q Max
-41.13 -24.13 -10.63 21.12 125.87
Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 42.129 3.063 13.76 <2e-16 ***
1 | MonthTRUE NA NA NA NA
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 32.99 on 115 degrees of freedom
(37 observations deleted due to missingness)
lmer4
> summary(lme4::lmer(data=airquality, Ozone ~ 1 + (1|Month)))
Linear mixed model fit by REML ['lmerMod']
Formula: Ozone ~ 1 + (1 | Month)
Data: airquality
REML criterion at convergence: 1116.5
Scaled residuals:
Min 1Q Median 3Q Max
-1.7084 -0.6269 -0.2669 0.4121 3.7507
Random effects:
Groups Name Variance Std.Dev.
Month (Intercept) 270.6 16.45
Residual 861.6 29.35
Number of obs: 116, groups: Month, 5
Fixed effects:
Estimate Std. Error t value
(Intercept) 41.093 7.922 5.187
lmerTest
library(lmerTest)
> lmerTest::lmer(data=airquality, Ozone ~ 1 + (1|Month))
Linear mixed model fit by REML ['lmerModLmerTest']
Formula: Ozone ~ 1 + (1 | Month)
Data: airquality
REML criterion at convergence: 1116.544
Random effects:
Groups Name Std.Dev.
Month (Intercept) 16.45
Residual 29.35
Number of obs: 116, groups: Month, 5
Fixed Effects:
(Intercept)
41.09
> summary(lmerTest::lmer(data=airquality, Ozone ~ 1 + (1|Month)))
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: Ozone ~ 1 + (1 | Month)
Data: airquality
REML criterion at convergence: 1116.5
Scaled residuals:
Min 1Q Median 3Q Max
-1.7084 -0.6269 -0.2669 0.4121 3.7507
Random effects:
Groups Name Variance Std.Dev.
Month (Intercept) 270.6 16.45
Residual 861.6 29.35
Number of obs: 116, groups: Month, 5
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 41.093 7.922 4.096 5.187 0.00616 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1