[R-sig-ME] Scatterplot of predicted country-specific intercepts and slopes

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sat Jan 20 11:20:11 CET 2024


Dear R-experts,

Here below a toy example with lmer (lme4).

I would like to draw a scatterplot of the predicted country-specific intercepts and slopes. I guess my scatterplot is not complete. Something is missing. How to finish my R code, thanks.

################################################### 
Score=c(423,412,543,354,564,435,467,567,501,567,512,435,467,589,691,564,345,412,423,501,456,567,534,456,478,498,490,561,456,432,345,322,612,589,512,498,567,564,555,456)
 
Time=c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
 
Country=c("France", "France", "France", "France", "Germany", "Germany", "Germany", "Germany", "Italy", "Italy", "Italy", "Italy", "UK", "UK", "UK", "UK", "USA", "USA", "USA", "USA", "Australia", "Australia", "Australia", "Australia", "Japan", "Japan", "Japan", "Japan", "Korea", "Korea", "Korea", "Korea", "Spain", "Spain", "Spain", "Spain", "Belgium", "Belgium", "Belgium", "Belgium")
 
library(lme4)
 
a <- lmer(Score ~ Time + (Time | Country))
 
 
plot(Time, Score, type="n")
for (i in ranef(a)[[1]] [,1] ) {
abline(fixef(a)[1] + i, fixef(a)[2])
}

###########################################################



More information about the R-sig-mixed-models mailing list