Skip to content

Instantly share code, notes, and snippets.

@Dpananos
Created July 7, 2023 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dpananos/5304b3ce8a99e78eea33dbe060dd32cb to your computer and use it in GitHub Desktop.
Save Dpananos/5304b3ce8a99e78eea33dbe060dd32cb to your computer and use it in GitHub Desktop.
Risk DIfference using Marginal Effects in ANCOVA style logistic regression
library(tidyverse)
library(marginaleffects)
g <- LETTERS[1:4]
N <- rpois(length(g), 100000)
theta <- c(0.1, 0.12, 0.14, 0.08)
y <- rbinom(length(g), N, theta)
d <- tibble(g, N, y)
fit <- glm(cbind(y, N-y) ~ g, data=d, family = binomial())
avg_comparisons(
fit,
variables = 'g',
wts = 'N'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment