I understand that is OK, or sometimes even necessary, to include an independent variable as both a fixed and random effect in a linear mixed model. However, what happens if your model only has a single independent variable and the variable is used as both as a fixed and random variable?
My instinct is that all the variance of the variable should be "soaked up" by the random effect and that the fixed effect should therefore have little significance. Is this a correct supposition?
Here is an example using R.
data(mtcars)
head(mtcars)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
Let's run a mixed model with cyl as both a fixed and random effect and mpg as the dependent variable, using the lme4 package.
library(lme4)
summary(lmer(mpg ~ cyl + (1|cyl),data=mtcars))
boundary (singular) fit: see help('isSingular')
Linear mixed model fit by REML ['lmerMod']
Formula: mpg ~ cyl + (1 | cyl)
Data: mtcars
REML criterion at convergence: 163.1
Scaled residuals:
Min 1Q Median 3Q Max
-1.55383 -0.66082 0.06917 0.33430 2.34523
Random effects:
Groups Name Variance Std.Dev.
cyl (Intercept) 0.00 0.000
Residual 10.28 3.206
Number of obs: 32, groups: cyl, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) 37.8846 2.0738 18.27
cyl -2.8758 0.3224 -8.92
Correlation of Fixed Effects:
(Intr)
cyl -0.962
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
I was surprised to see a pretty hefty t value for the cyl fixed effect (although admittedly the fit is singular). Further, the variance for the cyl random effect is zero. Consistent with these observations, the t value for the cyl fixed effect in the linear mixed model are essentially the same as for a simple linear model:
summary(lm(mpg ~ cyl,data=mtcars))
Call:
lm(formula = mpg ~ cyl, data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-4.9814 -2.1185 0.2217 1.0717 7.5186
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 37.8846 2.0738 18.27 < 2e-16 ***
cyl -2.8758 0.3224 -8.92 6.11e-10 ***
Signif. codes: 0 ‘*’ 0.001 ‘’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.206 on 30 degrees of freedom
Multiple R-squared: 0.7262, Adjusted R-squared: 0.7171
F-statistic: 79.56 on 1 and 30 DF, p-value: 6.113e-10
Is my understanding that the random effects should remove most significance from the fixed effect correct in this context?
Thanks!
lmer(mpg ~ (1|cyl), data = mtcars. However, a full model with fixed effects first has to estimate the aggregated effects of the predictors, then conditional shifts of both random slopes and intercepts after these values are obtained. It would be impossible otherwise to do so (as far as I know). – Shawn Hemelstrand Dec 08 '22 at 07:13