load_mgcv()
# \dontshow{
op <- options(pillar.sigfig = 2, cli.unicode = FALSE)
# }
dat <- data_sim("eg1", n = 1000, dist = "normal", scale = 2, seed = 2)
mod <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")
# new data to evaluate the smooths at, say over the middle 50% of range
# of each covariate
middle <- function(x, n = 50, coverage = 0.5) {
v <- (1 - coverage) / 2
q <- quantile(x, prob = c(0 + v, 1 - v), type = 8)
seq(q[1], q[2], length = n)
}
new_data <- sapply(dat[c("x0", "x1", "x2", "x3")], middle)
new_data <- data.frame(new_data)
## point-wise interval for smooth of x2
ci <- confint(mod, parm = "s(x2)", type = "confidence", data = new_data)
ci
# \dontshow{
options(op)
# }
Run the code above in your browser using DataLab