从 lmList 绘制 beta 系数?

Plotting beta coefficients from lmList?

我使用以下代码计算逻辑回归的系数:

model<-lmList(VariableD ~ VariableE + VariableF + VariableG | Participant, database, family = binomial(link = "logit"))

输出样本是:

  (Intercept)     VariableE   VariableF   VariableG
19   3.2665591 -0.0132012216 -0.25732617  0.26778854
20  -3.4393826  0.0194122526  1.03047235  0.78898713
21   1.2678461 -0.0010176256  0.09012313 -0.01289391
22  -0.7699174  0.0023954388  0.54327987 -0.31296745
23   1.3254696 -0.0034261267 -0.51176849 -0.71606725
24  -4.7511126  0.0435291070  0.31071099  0.10152898
25   0.4081270  0.0007494644 -0.16591073 -0.23714568
26  -2.7565715  0.0085388717  0.18503239  0.24941414
27  -2.2610725  0.0138908941 -0.34104256 -0.87318270

现在我想绘制这些值。谢谢!!

我们可以将数据转换为 'long' 格式,然后用 ggplot

绘图
library(dplyr)
library(tidyr)
library(ggplot2)
model %>%
   coef(.) %>%
   mutate(rn = row_number()) %>%
   pivot_longer(cols = -rn) %>%
   ggplot(aes(x = rn, y = value, color = name)) + 
        geom_line()