load_mgcv()
# \dontshow{
op <- options(pillar.sigfig = 3, cli.unicode = FALSE)
# }
dat <- data_sim("eg1", n = 1000, dist = "normal", scale = 2, seed = 2)
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")
predicted_samples(m, n = 5, seed = 42)
## Can pass arguments to predict.gam()
# \dontshow{
set.seed(6791)
# }
newd <- data.frame(
x0 = runif(10), x1 = runif(10), x2 = runif(10),
x3 = runif(10)
)
## Exclude s(x2)
predicted_samples(m, n = 5, newd, exclude = "s(x2)", seed = 25)
## Exclude s(x1)
predicted_samples(m, n = 5, newd, exclude = "s(x1)", seed = 25)
## Select which terms --- result should be the same as previous
## but note that we have to include any parametric terms, including the
## constant term
predicted_samples(m,
n = 5, newd, seed = 25,
terms = c("Intercept", "s(x0)", "s(x2)", "s(x3)")
)
# \dontshow{
options(op)
# }
Run the code above in your browser using DataLab