Simulate responses from a generalized additive linear model gam
By sampling from the vector of coefficients it is possible to simulate data from a ‘gam’ model.
simulate_gam( object, nsim = 1, psim = 1, resid.type = c("none", "resample", "normal", "wild"), value = c("matrix", "data.frame"), ... )
These are the options that control the parameter simulation level
returns the fitted values
simulates from a beta vector (mean response)
simulates observations according to the residual type (similar to observed data)
simulates a beta vector, considers uncertainty in the variance covariance matrix of beta and adds residuals (prediction)
The residual type (resid.type) controls how the residuals are generated. They are either resampled, simulated from a normal distribution or ‘wild’ where the Rademacher distribution is used (https://en.wikipedia.org/wiki/Rademacher_distribution). Resampled and normal both assume iid, but ‘normal’ makes the stronger assumption of normality. ‘wild’ does not assume constant variance, but it assumes symmetry.
matrix or data.frame with responses
psim = 3 is not implemented at the moment.
The purpose of this function is to make it compatible with other functions in this package. It has some limitations compared to the functions in the ‘see also’ section.
Generalized Additive Models. An Introduction with R. Second Edition. (2017) Simon N. Wood. CRC Press.
predict
, predict.gam
, simulate
and simulate_lm
.
require(ggplot2) require(mgcv) ## These count data are from GAM book by Simon Wood (pg. 132) - see reference y <- c(12, 14, 33, 50, 67, 74, 123, 141, 165, 204, 253, 246, 240) t <- 1:13 dat <- data.frame(y = y, t = t) fit <- gam(y ~ t + I(t^2), family = poisson, data = dat) sims <- simulate_gam(fit, nsim = 100, value = "data.frame") ggplot(data = sims) + geom_line(aes(x = t, y = sim.y, group = ii), color = "gray", alpha = 0.5) + geom_point(aes(x = t, y = y))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.