simulate_gam | R Documentation |
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"),
...
)
object |
object of class |
nsim |
number of simulations to perform |
psim |
parameter simulation level (an integer, 0, 1, 2 or 3). |
resid.type |
type of residual to use. ‘none’, ‘resample’, ‘normal’ or ‘wild’. |
value |
either ‘matrix’ or ‘data.frame’ |
... |
additional arguments (none used at the moment) |
This function is probably redundant. Simply using simulate
generates data from the correct distribution for objects which inherit
class lm
. The difference is that I'm trying to add the
uncertainty in the parameter estimates.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.