Skip to content

Instantly share code, notes, and snippets.

@markhwhiteii
Created October 18, 2018 14:55
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 markhwhiteii/cb5635d75589dcbedc48859b2a1f3dd4 to your computer and use it in GitHub Desktop.
Save markhwhiteii/cb5635d75589dcbedc48859b2a1f3dd4 to your computer and use it in GitHub Desktop.
library(emmeans)
inv_logit <- function(x) exp(x) / (1 + exp(x))
set.seed(1839)
n <- 100
x <- rbinom(n, 1, .5)
y <- rbinom(n, 1, inv_logit(x))
model <- glm(y ~ factor(x), binomial)
ci <- confint(model)
# getting y_hat | x = 1 --> my suggestion was too wide
my_lb <- inv_logit(ci[2, 1] + coef(model)[[1]])
em_lb <- inv_logit(as.data.frame(emmeans(model, ~ factor(x)))$asymp.LCL[[2]])
my_ub <- inv_logit(ci[2, 2] + coef(model)[[1]])
em_ub <- inv_logit(as.data.frame(emmeans(model, ~ factor(x)))$asymp.UCL[[2]])
my_lb; my_ub
em_lb; em_ub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment