if (FALSE) {
# Note: these models are dumb, but they illustrate how it works.
M1 <- lm(mpg ~ hp, mtcars)
# Note: this function requires the DV to appear somewhere, anywhere in the "new data"
newdat <- data.frame(mpg = 0,
hp = c(mean(mtcars$hp) - sd(mtcars$hp),
mean(mtcars$hp),
mean(mtcars$hp) + sd(mtcars$hp)))
get_sims(M1, newdat, 100, 8675309)
# Note: this is likely a dumb model, but illustrates how it works.
mtcars$mpgd <- ifelse(mtcars$mpg > 25, 1, 0)
M2 <- glm(mpgd ~ hp, mtcars, family=binomial(link="logit"))
# Again: this function requires the DV to be somewhere, anywhere in the "new data"
newdat$mpgd <- 0
# Note: the simulations are returned on their original "link". Here, that's a "logit"
# You can adjust that accordingly. `plogis(y)` will convert those to probabilities.
get_sims(M2, newdat, 100, 8675309)
library(lme4)
M3 <- lmer(mpg ~ hp + (1 | cyl), mtcars)
# Random effects are not required here since we're passing over them.
get_sims(M3, newdat, 100, 8675309)
}
Run the code above in your browser using DataLab