I am using the lmer function to gather the random effects and fixed effects. When running my function I am able to get the random effects for all coefficients by group. When I search for the fixed effects though, I only get it for the intercept. How do I get the fixed effect for all the coefficients?
Here is my example:
form_lmer <- "y ~ 1 + Var1 + 1 | group"
fm3<- lmer(as.formula(form_lmer), df, REML = FALSE, verbose = TRUE)
final<-ranef(fm3)
head(final)
$group
(Intercept) Var1
500 0.0429171100 -0.0114512020
501 -0.0483822296 0.0793030797
502 0.0368572644 -0.0060213102
504 0.0390749512 -0.0075918832
505 0.0608323336 -0.0294764946
506 0.0030031361 0.0278525937
final2<-fixef(fm3)
final2
(Intercept)
0.9716914
I want my final output for fixed effects to be something like this:
new_output
(Intercept) Var1
0.9716914 ###
Instead of
y ~ 1 + Var1 + 1 | group
,
write
y ~ 1 + Var1 + (1+Var1 | group)
.
If you have multiple variables then write it as: y ~ 1 + Var1 + Var2 + (1+Var1+Var2 | group)