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