Learn R Programming

survMisc (version 0.4.2)

gamTerms: Individual terms of a Generalized Additive or Cox Proportional Hazard 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.fit = TRUE, link = FALSE, weights)

Arguments

fit
The result of a Generalized Additive Model (gam) or a Cox proportional hazards model (coxph)
se.fit
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, data is centered so that the weighted mean is zero

Value

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

See Also

gam, plot.gam

Examples

Run this code
data(air)
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