Plotting beta coefficients from lmList?

208 Views Asked by At

I have used the following code to compute coefficients for a logistic regression:

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

A sample of the output is:

  (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

Now I'd like to plot these values. Thank you!!

1

There are 1 best solutions below

2
On BEST ANSWER

We can pivot the data into 'long' format and then plot with 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()