confint.gam {gratia} | R Documentation |
Point-wise and simultaneous confidence intervals for smooths
Description
Calculates point-wise confidence or simultaneous intervals for the smooth terms of a fitted GAM.
Usage
## S3 method for class 'gam'
confint(
object,
parm,
level = 0.95,
data = newdata,
n = 100,
type = c("confidence", "simultaneous"),
nsim = 10000,
shift = FALSE,
transform = FALSE,
unconditional = FALSE,
ncores = 1,
partial_match = FALSE,
...,
newdata = NULL
)
## S3 method for class 'gamm'
confint(object, ...)
## S3 method for class 'list'
confint(object, ...)
Arguments
object |
an object of class |
parm |
which parameters (smooth terms) are to be given intervals as a vector of terms. If missing, all parameters are considered, although this is not currently implemented. |
level |
numeric, |
data |
data frame; new values of the covariates used in the model fit. The selected smooth(s) wil be evaluated at the supplied values. |
n |
numeric; the number of points to evaluate smooths at. |
type |
character; the type of interval to compute. One of |
nsim |
integer; the number of simulations used in computing the simultaneous intervals. |
shift |
logical; should the constant term be add to the smooth? |
transform |
logical; should the smooth be evaluated on a transformed scale? For generalised models, this involves applying the inverse of the link function used to fit the model. Alternatively, the name of, or an actual, function can be supplied to transform the smooth and it's confidence interval. |
unconditional |
logical; if |
ncores |
number of cores for generating random variables from a
multivariate normal distribution. Passed to |
partial_match |
logical; should matching |
... |
additional arguments for methods |
newdata |
DEPRECATED! data frame; containing new values of the covariates used in the model fit. The selected smooth(s) wil be evaluated at the supplied values. |
Value
a tibble with components:
-
.smooth
; character indicating to which term each row relates, -
.type
; the type of smooth, -
.by
the name of the by variable if a by smooth,NA
otherwise, one or more vectors of values at which the smooth was evaluated, named as per the variables in the smooth,
zero or more variables containing values of the by variable,
-
.estimate
; estimated value of the smooth, -
.se
; standard error of the estimated value of the smooth, -
.crit
; critical value for the100 * level
% confidence interval. -
.lower_ci
; lower limit of the confidence or simultaneous interval, -
.upper_ci
; upper limit of the confidence or simultaneous interval,
Author(s)
Gavin L. Simpson
Examples
load_mgcv()
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