线性混合效应模型表格生成求助:sjt.lmer报错及Broom输出问题
Hey there! Let's work through your linear mixed-effects model table generation problems one by one.
sjt.lmer() Issue First off, that message you're seeing:
Computing p-values via Kenward-Roger approximation. Use
p.kr = FALSEif computation takes too long.
is actually an informational prompt, not a hard error—but it might cause delays or prevent table rendering if the approximation takes too long (especially with larger datasets). Here's how to address it:
- Switch to faster p-value calculation: As the message suggests, add the
p.kr = FALSEargument to use Wald tests instead, which are quicker. Try this code:sjt.lmer(fit1, p.kr = FALSE) - Install required dependencies: The Kenward-Roger approximation relies on the
pbkrtestpackage. If you haven't installed it yet, run:
Reloadinstall.packages("pbkrtest")sjPlotand try generating the table again. - Update
sjPlot: Outdated versions might have compatibility issues withlme4. Refresh the package with:install.packages("sjPlot")
If you still hit snags, check if your model has convergence problems using isSingular(fit1)—singular models can sometimes break table generation tools.
The core issue here is that the base broom package has limited support for lmer objects. You'll want to use broom.mixed, which is built specifically for mixed-effects models. Here's how to get the exact outputs you need:
Install and load
broom.mixed:install.packages("broom.mixed") library(broom.mixed)Extract fixed effects (with confidence intervals and p-values):
This gives you the same core details assummary(fit1)for fixed effects, formatted for easy table use:fixed_table <- tidy(fit1, effects = "fixed", conf.int = TRUE) # Format it nicely (round values, select key columns) fixed_table %>% select(term, estimate, std.error, conf.low, conf.high, p.value) %>% mutate(across(c(estimate, std.error, conf.low, conf.high), round, 3))Extract random effect variance components:
To get variance estimates for yourWeekandPairrandom intercepts (matching the output fromrand(fit1)), use:random_vars <- tidy(fit1, effects = "ran_pars")Extract ANOVA-style results:
If you want a table equivalent ofanova(fit1), run:anova_table <- tidy(anova(fit1))
You can combine or rearrange these tables using dplyr or formatting packages like gt/kableExtra to match the exact report-ready format you need.
内容的提问来源于stack exchange,提问作者Amanda

