A table of results for frequentist mixed-effects models: Grouping variables and specifying random slopes

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.

Loading the function from GitHub

source('https://github.com/pablobernabeu/language-sensorimotor-simulation-PhD-thesis/raw/main/R_functions/frequentist_model_table.R')

The function in use

# Create table (using custom function from the 'R_functions' folder)
frequentist_model_table(
  KR_summary_semanticpriming_lmerTest, 
  confint_semanticpriming_lmerTest,
  order_effects = c('(Intercept)',
                    'Attentional control',
                    'Vocabulary size <sup>a</sup>',
                    'Gender <sup>a</sup>',
                    'Word frequency',
                    'Number of syllables',
                    'Word-concreteness difference',
                    'Language-based similarity <sup>b</sup>',
                    'Visual-strength difference <sup>b</sup>',
                    'Stimulus onset asynchrony (SOA) <sup>b</sup>',
                    'Word-concreteness difference :: Vocabulary size',
                    'Word-concreteness difference : SOA',
                    'Word-concreteness difference : Gender',
                    'Language-based similarity :: Attentional control',
                    'Visual-strength difference :: Attentional control',
                    'Language-based similarity :: Vocabulary size',
                    'Visual-strength difference :: Vocabulary size',
                    'Language-based similarity : Gender',
                    'Visual-strength difference : Gender',
                    'Language-based similarity : SOA <sup>b</sup>',
                    'Visual-strength difference : SOA <sup>b</sup>'),
  
  # Replace colons in the names of interactions with times symbols
  interaction_symbol_x = TRUE, 
  
  # No title
  caption = NULL) %>%
  
  # Group predictors under headings
  pack_rows('Individual differences', 2, 4) %>% 
  pack_rows('Target-word lexical covariates', 5, 6) %>% 
  pack_rows('Prime--target relationship', 7, 9) %>% 
  pack_rows('Task condition', 10, 10) %>% 
  pack_rows('Interactions', 11, 21) %>% 
  
  # Apply white background to override default shading in HTML output
  row_spec(1:21, background = 'white') %>%
  
  # Highlight covariates
  row_spec(c(2, 5:7, 11:15), background = '#FFFFF1') %>%
  
  # Format
  kable_classic(full_width = FALSE, html_font = 'Cambria') %>%
  
  # Footnote describing abbreviations, random slopes, etc. 
  # LaTeX code used to format the text.
  footnote(escape = FALSE, threeparttable = TRUE, general_title = '<br>', 
           general = paste('*Note*. &beta; = Estimate based on $z$-scored predictors; *SE* = standard error;',
                           'CI = confidence interval. Yellow rows contain covariates. Some interactions are ',
                           'split over two lines, with the second line indented. <br>', 
                           '<sup>a</sup> By-word random slopes were included for this effect.',
                           '<sup>b</sup> By-participant random slopes were included for this effect.'))
β SE 95% CI t p
(Intercept) 0.00 0.00 [0.00, 0.01] 1.59 .112
Individual differences
Attentional control 0.00 0.00 [0.00, 0.00] -0.56 .577
Vocabulary size a 0.00 0.00 [0.00, 0.00] 0.02 .987
Gender a 0.00 0.00 [0.00, 0.00] -0.03 .979
Target-word lexical covariates
Word frequency -0.16 0.00 [-0.16, -0.15] -49.40 <.001
Number of syllables 0.07 0.00 [0.07, 0.08] 22.81 <.001
Prime–target relationship
Word-concreteness difference 0.01 0.00 [0.01, 0.02] 3.48 .001
Language-based similarity b -0.08 0.00 [-0.08, -0.07] -22.44 <.001
Visual-strength difference b 0.01 0.00 [0.01, 0.02] 4.18 <.001
Task condition
Stimulus onset asynchrony (SOA) b 0.06 0.01 [0.04, 0.07] 7.47 <.001
Interactions
Word-concreteness difference ×
   Vocabulary size
0.00 0.00 [0.00, 0.01] 1.31 .189
Word-concreteness difference × SOA 0.00 0.00 [0.00, 0.01] 2.57 .010
Word-concreteness difference × Gender 0.00 0.00 [-0.01, 0.00] -0.97 .332
Language-based similarity ×
   Attentional control
-0.01 0.00 [-0.01, 0.00] -2.46 .014
Visual-strength difference ×
   Attentional control
0.00 0.00 [0.00, 0.00] 0.24 .810
Language-based similarity ×
   Vocabulary size
-0.01 0.00 [-0.01, 0.00] -2.34 .020
Visual-strength difference ×
   Vocabulary size
0.00 0.00 [-0.01, 0.00] -1.37 .172
Language-based similarity × Gender 0.00 0.00 [-0.01, 0.00] -0.79 .433
Visual-strength difference × Gender 0.00 0.00 [0.00, 0.01] 1.46 .144
Language-based similarity × SOA b 0.01 0.00 [0.00, 0.01] 3.22 .001
Visual-strength difference × SOA b 0.00 0.00 [-0.01, 0.00] -2.25 .025

Note. β = Estimate based on \(z\)-scored predictors; SE = standard error; CI = confidence interval. Yellow rows contain covariates. Some interactions are split over two lines, with the second line indented.
a By-word random slopes were included for this effect. b By-participant random slopes were included for this effect.

Shading specific rows

Shading specific rows is done differently when the output is PDF, as shown below (see p. 62 in Bernabeu, 2022).

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.3.2 (2023-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 11 x64 (build 22621)
## 
## Matrix products: default
## 
## 
## locale:
## [1] LC_COLLATE=English_United Kingdom.utf8 
## [2] LC_CTYPE=English_United Kingdom.utf8   
## [3] LC_MONETARY=English_United Kingdom.utf8
## [4] LC_NUMERIC=C                           
## [5] LC_TIME=English_United Kingdom.utf8    
## 
## time zone: Europe/Oslo
## tzcode source: internal
## 
## 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-35.1      
## [4] Matrix_1.6-4        stringr_1.5.1       tibble_3.2.1       
## [7] dplyr_1.1.4         knitr_1.45          xaringanExtra_0.7.0
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.4.8          utf8_1.2.4          generics_0.1.3     
##  [4] xml2_1.3.6          blogdown_1.18       stringi_1.8.3      
##  [7] lattice_0.22-5      digest_0.6.33       magrittr_2.0.3     
## [10] evaluate_0.23       grid_4.3.2          bookdown_0.37      
## [13] fastmap_1.1.1       jsonlite_1.8.8      httr_1.4.7         
## [16] rvest_1.0.3         fansi_1.0.6         viridisLite_0.4.2  
## [19] scales_1.3.0        numDeriv_2016.8-1.1 jquerylib_0.1.4    
## [22] cli_3.6.2           rlang_1.1.2         munsell_0.5.0      
## [25] splines_4.3.2       withr_2.5.2         cachem_1.0.8       
## [28] yaml_2.3.8          tools_4.3.2         uuid_1.1-1         
## [31] nloptr_2.0.3        minqa_1.2.6         colorspace_2.1-0   
## [34] ggplot2_3.4.4       webshot_0.5.5       boot_1.3-28.1      
## [37] vctrs_0.6.5         R6_2.5.1            lifecycle_1.0.4    
## [40] MASS_7.3-60         pkgconfig_2.0.3     pillar_1.9.0       
## [43] bslib_0.6.1         gtable_0.3.4        glue_1.6.2         
## [46] Rcpp_1.0.11         systemfonts_1.0.5   xfun_0.41          
## [49] tidyselect_1.2.0    rstudioapi_0.15.0   htmltools_0.5.7    
## [52] nlme_3.1-164        svglite_2.1.3       rmarkdown_2.25     
## [55] compiler_4.3.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

comments powered by Disqus