This image was updated on 2021-09-16. “TRUE” means that both functions calculate unit-specific standard errors. Note that the scale in the right panel goes from milliseconds to minutes.
library(bench)
library(ggplot2)
library(margins)
library(marginaleffects)
function(mod, dat, unit_ses) {
margins_pkg <-margins(mod, unit_ses = unit_ses)
}
function(mod, dat, unit_ses) {
marginaleffects_pkg <-marginaleffects(mod, vcov = unit_ses)
}
function(N) {
simulate <- data.frame(
dat <-x2 = rnorm(N),
x1 = rnorm(N),
x3 = rnorm(N),
x4 = rnorm(N))
plogis(dat$x1 + dat$x2 + dat$x3 + dat$x4 + dat$x3 * dat$x4)
pr <-$y <- rbinom(N, 1, pr)
datreturn(dat)
}
function(dat) {
fit <-glm(y ~ x1 + x2 + x3 * x4, data = dat, family = binomial)
}
bench::press(
results <-N = c(25, 50, 100, 200, 400, 800, 1500, 5000, 10000),
unit_ses = c(FALSE, TRUE),
{ simulate(N)
dat <- fit(dat)
mod <-::mark(
benchcheck = FALSE,
max_iterations = 3,
margins_pkg(mod, dat, unit_ses),
marginaleffects_pkg(mod, dat, unit_ses))
} )
$pkg = as.character(results$expression)
resultsggplot(results, aes(N, median, linetype = pkg)) +
geom_line() +
facet_wrap(~unit_ses, scales = "free_y") +
theme_minimal() +
theme(legend.position = "bottom")