I am trying to present an average partial effects table of multiple binary-response models. Back in December last year, I had no issue calling modelsummary
in a list of objects of the class "margins" "data.frame"
to produce a table like the one below:
However, when I try to call modelsummary
on a list of margins
or marginaleffects
objects, I get the following:
# Working example
df<-mtcars
df$cyl<-as.factor(df$cyl)
library(modelsummary)
library(tidyverse)
library(marginaleffects)
# Binary response Models
model1<-glm(am ~ mpg + cyl,
data = df,
family = quasibinomial(link = 'logit'))
model2<-glm(am ~ mpg + cyl,
data = df,
family = quasibinomial(link = 'probit'))
model3<-glm(am ~ wt + cyl,
data = df,
family = quasibinomial(link = 'logit'))
model4<-glm(am ~ wt + cyl,
data = df,
family = quasibinomial(link = 'probit'))
models<-list(model1,model2,model3,model4)
mfx<-lapply(models, marginaleffects)
modelsummary(mfx,
output = 'markdown')
Model 1 | Model 2 | Model 3 | Model 4 | |
---|---|---|---|---|
mpg | 0.056 | 0.057 | ||
(0.027) | (0.026) | |||
cyl | 0.093 | 0.091 | 0.120 | 0.121 |
0.093 | 0.091 | 0.120 | 0.260 | |
0.093 | 0.091 | 0.253 | 0.121 | |
0.093 | 0.091 | 0.253 | 0.260 | |
0.093 | 0.102 | 0.120 | 0.121 | |
0.093 | 0.102 | 0.120 | 0.260 | |
0.093 | 0.102 | 0.253 | 0.121 | |
0.093 | 0.102 | 0.253 | 0.260 | |
0.097 | 0.091 | 0.120 | 0.121 | |
0.097 | 0.091 | 0.120 | 0.260 | |
0.097 | 0.091 | 0.253 | 0.121 | |
0.097 | 0.091 | 0.253 | 0.260 | |
0.097 | 0.102 | 0.120 | 0.121 | |
0.097 | 0.102 | 0.120 | 0.260 | |
0.097 | 0.102 | 0.253 | 0.121 | |
0.097 | 0.102 | 0.253 | 0.260 | |
(0.169) | (0.174) | (0.058) | (0.053) | |
(0.169) | (0.174) | (0.058) | (0.063) | |
(0.169) | (0.174) | (0.068) | (0.053) | |
(0.169) | (0.174) | (0.068) | (0.063) | |
(0.169) | (0.236) | (0.058) | (0.053) | |
(0.169) | (0.236) | (0.058) | (0.063) | |
(0.169) | (0.236) | (0.068) | (0.053) | |
(0.169) | (0.236) | (0.068) | (0.063) | |
(0.238) | (0.174) | (0.058) | (0.053) | |
(0.238) | (0.174) | (0.058) | (0.063) | |
(0.238) | (0.174) | (0.068) | (0.053) | |
(0.238) | (0.174) | (0.068) | (0.063) | |
(0.238) | (0.236) | (0.058) | (0.053) | |
(0.238) | (0.236) | (0.058) | (0.063) | |
(0.238) | (0.236) | (0.068) | (0.053) | |
(0.238) | (0.236) | (0.068) | (0.063) | |
wt | -0.533 | -0.556 | ||
(0.080) | (0.072) | |||
Num.Obs. | 32 | 32 | 32 | 32 |
F | 2.157 | 2.707 | 4.417 | 5.832 |
RMSE | 0.39 | 0.39 | 0.27 | 0.27 |
I get the following warning messages:
---
Objects of class 'NULL' are currently not supported.
Objects of class 'NULL' are currently not supported.
Objects of class 'NULL' are currently not supported.
Objects of class 'NULL' are currently not supported.
Warning message:
There are duplicate term names in the table. The `shape` argument of the `modelsummary` function can be used to print related terms together, and to label them appropriately. You can find the group identifier to use in the `shape` argument by calling `get_estimates()` on one of your models. Candidate group identifiers include: type, contrast. See `?modelsummary` for details.
I tried listening to the warning message and added a shape
argument as shape = ~ term + contrast ~ model
, which results in a better table. But I still get the "objects of class NULL" warning and I also get another new column on my table:
Model 1 | Model 2 | Model 3 | Model 4 | ||
---|---|---|---|---|---|
mpg | dY/dX | 0.056 | 0.057 | ||
(0.027) | (0.026) | ||||
cyl | 6 - 4 | 0.097 | 0.091 | 0.120 | 0.121 |
(0.169) | (0.174) | (0.058) | (0.053) | ||
8 - 4 | 0.093 | 0.102 | 0.253 | 0.260 | |
(0.238) | (0.236) | (0.068) | (0.063) | ||
wt | dY/dX | -0.533 | -0.556 | ||
(0.080) | (0.072) | ||||
Num.Obs. | 32 | 32 | 32 | 32 | |
F | 2.157 | 2.707 | 4.417 | 5.832 | |
RMSE | 0.39 | 0.39 | 0.27 | 0.27 |
I would like to know if there is any way to get rid of that warning message, and also how to ommit/edit the new column that appears in the table with the shape
argument.