Learn R Programming

survMisc (version 0.4.6)

gamTerms: Individual terms of a Generalized Additive or Cox Proportional Hazards Model

Description

Returns the individual terms of a gam or coxph object, along with the standard errors, in a way useful for plotting.

Usage

gamTerms(fit, se = TRUE, link = FALSE, weights, data)

Arguments

fit
The result of a Generalized Additive Model (gam) or a Cox proportional hazards model (coxph)
se
If TRUE, also return the standard errors
link
If TRUE, then the individual terms are centered so that the average of the inverse-link of the data, i.e., the data on the original scale, has mean zero
weights
A vector of case weights. If not supplied (the default), the data is centered so that the weighted mean is zero.
data
A data.frame in which to evaluate the model. If missing, eval(fit$call$data) is used.

Value

  • A list with one element per term. Each element is a matrix whose columns are x, y, and (optionally) se(y). There is one row per unique x value, and the matrix is sorted by these values. (This makes it easy to plot the results). The first element of the list, constant, contains an overall mean for the decomposition.

See Also

air ?gam::gam ?gam::plot.gam

Examples

Run this code
data(air, package="survMisc")
gfit <- gam::gam(ozone ~ gam::s(temperature) + gam::s(wind), data=air)
temp <- gamTerms(gfit)
identical(names(temp), c("constant", "temperature", "wind"))
### air has 111 rows, but only 28 unique wind speeds:
dim(temp$wind)
### plot the fit versus square root of wind speed
yy <- cbind(temp$wind[, 2],
            temp$wind[, 2] - 1.96 * temp$wind[, 3],
            temp$wind[, 2] + 1.96 * temp$wind[, 3])
### Adding the constant makes this a plot of
### actual y (ozone) at the mean temp
yy <- yy + temp$constant
graphics::matplot(sqrt(temp$wind[, 1]), yy, lty=c(1, 2, 2),
                 type='l', col=1, xaxt='n', xlab='Wind Speed', ylab='Ozone')
temp <- seq(3, 19, 2)
graphics::axis(1, sqrt(temp), format(temp))

Run the code above in your browser using DataLab