在特定统计信息中删除 R 中 modelsummary 的某些部分

Removing certain parts of modelsummary in R at specific statistics

我正在使用 gamm4:gamm4 来模拟纵向变化。

我正在尝试使用 modelsummary::modelsummary 函数创建以下结果的输出 table:

我想将 t-valuesstd.error 添加到 fixed effects 的输出,并从 random effects

中删除空标签值
model_lmer <- gamm4(Y ~ Tract + s(Age, by = Tract, k = 10) + Sex,
            data = (DF1),
            random = ~ (0 + Tract | ID))


modelsummary(model_lmer$mer,   
             statistic = c("s.e. = {std.error}", 
                           "t = {statistic}"))

但我正在努力编写正确的语法来删除“t”和“s.e”。来自随机效应输出。

实际上,这有点棘手。问题是 modelsummary() 当它们被 NA 或一个填充时自动删除空行 空字符串 ""。但是,由于 glue 字符串可以包含任意 文本,很难想出一种 general 方法来确定该行是否 是否为空,因为 modelsummary() 无法知道 事前 什么 构成一个空字符串。

如果您对如何实施此检查有任何想法,请报告 在 Github:

https://github.com/vincentarelbundock/modelsummary

在此期间,您可以使用强大的 tidy_custom.CLASSNAME 机制 直接自定义 statisticp.value 统计数据 通过 glue 字符串:

library(gamm4)
library(modelsummary)

# simulate
x <- runif(100)
fac <- sample(1:20,100,replace=TRUE)
eta <- x^2*3 + fac/20; fac <- as.factor(fac)
y <- rpois(100,exp(eta))

# fit
mod <- gamm4(y~s(x),family=poisson,random=~(1|fac))

# customize
tidy_custom.glmerMod <- function(x) {
    out <- parameters::parameters(x)
    out <- insight::standardize_names(out, style = "broom")
    out$statistic <- sprintf("t = %.3f", out$statistic)
    out$p.value <- sprintf("p = %.3f", out$p.value)
    out
}


# summarize
modelsummary(mod$mer,
             statistic = c("{statistic}", "{p.value}"))
Model 1
X(Intercept) 1.550
t = 17.647
p = 0.000
Xs(x)Fx1 0.855
t = 4.445
p = 0.000
Num.Obs. 100
RMSE 2.49

请注意,我在 statistic = "{p.value}" 中使用了简单的粘合字符串,否则它们将被括在括号中,这是标准错误的默认设置。