sim: Simulate from a fitted 'glm' object based on new data, with...

View source: R/sim_tools.R

simR Documentation

Simulate from a fitted glm object based on new data, with automatic detection of family and link.

Description

Simulate from a fitted glm object based on new data, with automatic detection of family and link.

Usage

sim(model, newdata, binomial_n = 1)

Arguments

model

a fitted glm object

newdata

data frame with values of the covariates based on which to simulate the response, similar to predict.glm

binomial_n

int length nrow(newdata). If model was fit with link=binomial, you can optionally pass a vector of group sizes to simulate aggregate binomial data.

Value

A vector of length nrow(newdata) with simulated responses.

Examples

n  = 100
df = tibble::tibble(x = rnorm(n), y = rpois(n, lambda = exp(x)))
mod = glm(y~x, poisson('log'), df)
sims = sim(mod, newdata=df)
qqplot(df$y, sims)


audreyrenson/didgformula documentation built on Oct. 9, 2022, 11:45 a.m.