glm_data {postcard} | R Documentation |
Generate data simulated from a GLM
Description
Provide a formula, variables and a family to generate a linear predictor using the formula and provided variables before using the inverse link of the family to generate the GLM modelled mean, mu, which is then used to simulate the response with this mean from the generating function according to the chosen family.
Usage
glm_data(formula, ..., family = gaussian(), family_args = list(sd = 1))
Arguments
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under ‘Details’ in the glm documentation. |
... |
a |
family |
the |
family_args |
a named |
Value
a data.frame
Examples
# Generate a gaussian response from a single covariate
glm_data(Y ~ 1+2*x1,
x1 = rnorm(10))
# Generate a gaussian response from a single covariate with non-linear
# effects. Specify that the response should have standard deviation sqrt(3)
glm_data(Y ~ 1+2*abs(sin(x1)),
x1 = runif(10, min = -2, max = 2),
family_args = list(sd = sqrt(3)))
# Generate a negative binomial response
glm_data(Y ~ 1+2*x1-x2,
x1 = rnorm(10),
x2 = rgamma(10, shape = 2),
family = MASS::negative.binomial(2))
# Provide variables as a list/data.frame
glm_data(resp ~ 1+2*x1-x2,
data.frame(
x1 = rnorm(10),
x2 = rgamma(10, shape = 2)
),
family = MASS::negative.binomial(2))