A table of results for frequentist mixed-effects models: Grouping variables and specifying random slopes
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Here I share the format applied to tables presenting the results of frequentist models in Bernabeu (2022; the table for Bayesian models is covered in this other post). The sample table presents a mixed-effects model that was fitted using the R package lmerTest
(Kuznetsova et al., 2022). The mixed effects were driven by the maximal principle (Brauer & Curtin, 2018). The format of the table resembles one of the examples published by the American Psychological Association. However, there are also deviations from those examples. For instance, in the present table, the effects are grouped under informative labels to facilitate the readers’ comprehension, using the kableExtra
package (Zhu, 2022). Furthermore, the random slopes are specified using superscript letters and a footnote. The table can be reproduced using the materials at https://osf.io/gt5uf.
Loading packages and the results of the models
library(dplyr) library(knitr) library(tibble) library(stringr) library(lmerTest) library(kableExtra) # Load frequentist coefficients (estimates and confidence intervals) KR_summary_semanticpriming_lmerTest = readRDS(gzcon(url('https://github.com/pablobernabeu/language-sensorimotor-simulation-PhD-thesis/blob/main/semanticpriming/frequentist_analysis/results/KR_summary_semanticpriming_lmerTest.rds?raw=true'))) confint_semanticpriming_lmerTest = readRDS(gzcon(url('https://github.com/pablobernabeu/language-sensorimotor-simulation-PhD-thesis/blob/main/semanticpriming/frequentist_analysis/results/confint_semanticpriming_lmerTest.rds?raw=true')))
Adjusting the names of the effects
First, to facilitate the understanding of the results, the original names of the effects will be adjusted in the lmerTest
summary and in the confidence intervals object.
Incidentally, the confidence intervals were obtained using the confint.merMod
function from the lme4
package, as neither lmerTest
nor lme4
currently provide confidence intervals in their default results output. However, computing the confidence intervals is uncomplicated (see code).
# Rename effects in plain language and specify the random slopes # (if any) for each effect, in the footnote. For this purpose, # superscripts are added to the names of the appropriate effects. # # In the interactions below, word-level variables are presented # first for the sake of consistency (the order does not affect # the results in any way). Also in the interactions, double # colons are used to inform the 'frequentist_model_table' # function that the two terms in the interaction must be split # into two lines. rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_attentional_control'] = 'Attentional control' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_vocabulary_size'] = 'Vocabulary size <sup>a</sup>' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_recoded_participant_gender'] = 'Gender <sup>a</sup>' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_target_word_frequency'] = 'Word frequency' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_target_number_syllables'] = 'Number of syllables' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_word_concreteness_diff'] = 'Word-concreteness difference' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_cosine_similarity'] = 'Language-based similarity <sup>b</sup>' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_visual_rating_diff'] = 'Visual-strength difference <sup>b</sup>' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_recoded_interstimulus_interval'] = 'Stimulus onset asynchrony (SOA) <sup>b</sup>' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_word_concreteness_diff:z_vocabulary_size'] = 'Word-concreteness difference :: Vocabulary size' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_word_concreteness_diff:z_recoded_interstimulus_interval'] = 'Word-concreteness difference : SOA' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_word_concreteness_diff:z_recoded_participant_gender'] = 'Word-concreteness difference : Gender' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_attentional_control:z_cosine_similarity'] = 'Language-based similarity :: Attentional control' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_attentional_control:z_visual_rating_diff'] = 'Visual-strength difference :: Attentional control' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_vocabulary_size:z_cosine_similarity'] = 'Language-based similarity :: Vocabulary size' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_vocabulary_size:z_visual_rating_diff'] = 'Visual-strength difference :: Vocabulary size' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_recoded_participant_gender:z_cosine_similarity'] = 'Language-based similarity : Gender' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_recoded_participant_gender:z_visual_rating_diff'] = 'Visual-strength difference : Gender' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_recoded_interstimulus_interval:z_cosine_similarity'] = 'Language-based similarity : SOA <sup>b</sup>' rownames(KR_summary_semanticpriming_lmerTest$coefficients)[ rownames(KR_summary_semanticpriming_lmerTest$coefficients) == 'z_recoded_interstimulus_interval:z_visual_rating_diff'] = 'Visual-strength difference : SOA <sup>b</sup>' # Next, change the names in the confidence intervals object rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_attentional_control'] = 'Attentional control' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_vocabulary_size'] = 'Vocabulary size <sup>a</sup>' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_recoded_participant_gender'] = 'Gender <sup>a</sup>' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_target_word_frequency'] = 'Word frequency' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_target_number_syllables'] = 'Number of syllables' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_word_concreteness_diff'] = 'Word-concreteness difference' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_cosine_similarity'] = 'Language-based similarity <sup>b</sup>' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_visual_rating_diff'] = 'Visual-strength difference <sup>b</sup>' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_recoded_interstimulus_interval'] = 'Stimulus onset asynchrony (SOA) <sup>b</sup>' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_word_concreteness_diff:z_vocabulary_size'] = 'Word-concreteness difference :: Vocabulary size' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_word_concreteness_diff:z_recoded_interstimulus_interval'] = 'Word-concreteness difference : SOA' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_word_concreteness_diff:z_recoded_participant_gender'] = 'Word-concreteness difference : Gender' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_attentional_control:z_cosine_similarity'] = 'Language-based similarity :: Attentional control' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_attentional_control:z_visual_rating_diff'] = 'Visual-strength difference :: Attentional control' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_vocabulary_size:z_cosine_similarity'] = 'Language-based similarity :: Vocabulary size' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_vocabulary_size:z_visual_rating_diff'] = 'Visual-strength difference :: Vocabulary size' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_recoded_participant_gender:z_cosine_similarity'] = 'Language-based similarity : Gender' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_recoded_participant_gender:z_visual_rating_diff'] = 'Visual-strength difference : Gender' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_recoded_interstimulus_interval:z_cosine_similarity'] = 'Language-based similarity : SOA <sup>b</sup>' rownames(confint_semanticpriming_lmerTest)[ rownames(confint_semanticpriming_lmerTest) == 'z_recoded_interstimulus_interval:z_visual_rating_diff'] = 'Visual-strength difference : SOA <sup>b</sup>'
frequentist_model_table()
The following custom function was used.
Session info
If you encounter any blockers while reproducing the table using the materials at https://osf.io/gt5uf, my current session info may be useful.
sessionInfo() ## R version 4.2.2 (2022-10-31 ucrt) ## Platform: x86_64-w64-mingw32/x64 (64-bit) ## Running under: Windows 10 x64 (build 19045) ## ## Matrix products: default ## ## locale: ## [1] LC_COLLATE=English_United States.utf8 ## [2] LC_CTYPE=English_United States.utf8 ## [3] LC_MONETARY=English_United States.utf8 ## [4] LC_NUMERIC=C ## [5] LC_TIME=English_United States.utf8 ## ## attached base packages: ## [1] stats graphics grDevices utils datasets methods base ## ## other attached packages: ## [1] kableExtra_1.3.4 lmerTest_3.1-3 lme4_1.1-31 ## [4] Matrix_1.5-1 stringr_1.5.0 tibble_3.1.8 ## [7] dplyr_1.0.10 knitr_1.41 xaringanExtra_0.7.0 ## ## loaded via a namespace (and not attached): ## [1] tidyselect_1.2.0 xfun_0.36 bslib_0.4.2 ## [4] splines_4.2.2 lattice_0.20-45 colorspace_2.0-3 ## [7] vctrs_0.5.1 generics_0.1.3 viridisLite_0.4.1 ## [10] htmltools_0.5.4 yaml_2.3.6 utf8_1.2.2 ## [13] rlang_1.0.6 jquerylib_0.1.4 pillar_1.8.1 ## [16] nloptr_2.0.3 withr_2.5.0 glue_1.6.2 ## [19] DBI_1.1.3 uuid_1.1-0 lifecycle_1.0.3 ## [22] munsell_0.5.0 blogdown_1.16 gtable_0.3.1 ## [25] rvest_1.0.3 evaluate_0.19 fastmap_1.1.0 ## [28] fansi_1.0.3 Rcpp_1.0.9 scales_1.2.1 ## [31] cachem_1.0.6 webshot_0.5.4 jsonlite_1.8.4 ## [34] systemfonts_1.0.4 ggplot2_3.3.5 digest_0.6.31 ## [37] stringi_1.7.8 bookdown_0.31 numDeriv_2016.8-1.1 ## [40] grid_4.2.2 cli_3.4.1 tools_4.2.2 ## [43] magrittr_2.0.3 sass_0.4.4 pkgconfig_2.0.3 ## [46] MASS_7.3-58.1 xml2_1.3.3 svglite_2.1.0 ## [49] httr_1.4.4 assertthat_0.2.1 minqa_1.2.5 ## [52] rmarkdown_2.19 rstudioapi_0.14 R6_2.5.1 ## [55] boot_1.3-28 nlme_3.1-160 compiler_4.2.2
References
Bernabeu, P. (2022). Language and sensorimotor simulation in conceptual processing: Multilevel analysis and statistical power. Lancaster University. https://doi.org/10.17635/lancaster/thesis/1795
Brauer, M., & Curtin, J. J. (2018). Linear mixed-effects models and the analysis of nonindependent data: A unified framework to analyze categorical and continuous independent variables that vary within-subjects and/or within-items. Psychological Methods, 23(3), 389–411. https://doi.org/10.1037/met0000159
Kuznetsova, A., Brockhoff, P. B., & Christensen, R. H. B. (2022). Package ’lmerTest’. CRAN. https://cran.r-project.org/web/packages/lmerTest/lmerTest.pdf
Zhu, H. (2022). Package ’kableExtra’. CRAN. https://cran.r-project.org/web/packages/kableExtra/kableExtra.pdf
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.