# from help("glm")
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)
model <- glm(counts ~ outcome + treatment, family = poisson())
new_responses <- replicate(100, MASS::rnegbin(fitted.values(model), theta = 4.5), simplify = FALSE)
simulate_wald_pvalues(model, responses = new_responses, nsim = 100)
## Using custom refit_fn
if (require("survival")) {
fit <- survreg(Surv(futime, fustat) ~ ecog.ps + rx, ovarian,
dist = "exponential"
)
fitted_rate <- 1 / fitted(fit)
new_responses <- replicate(100, rexp(length(fitted_rate), fitted_rate), simplify = FALSE)
refit_surv_ovarian <- function(.y) {
survreg(Surv(.y, fustat) ~ ecog.ps + rx, ovarian, dist = "exponential")
}
simulate_wald_pvalues(fit, responses = new_responses, refit_fn = refit_surv_ovarian)
}
Run the code above in your browser using DataLab