# The only function included in this package which users are intended
# to call directly is summary().
# This example requires the mgcv package.
library("mgcv")
data("chicagoNMMAPS") # loads as object 'chic'
# Model 1 includes a standard cubic regression fixed-df smooth function of time,
# with k chosen to give the same EDF as the second model
Model1 <- as.formula("death ~ pm10tmean + s(tmpd, k=6, fx=TRUE) + s(dptp, k=3, fx=TRUE) +
as.factor(dow) + s(time, bs='cr', k=196, fx=TRUE)")
# Model 2 uses spsmooth and changes the smooth function of time to use
# the Slepian basis, 2NW-1 basis vectors.
#
# Choosing W: there are two approaches that can be taken. The first is
# to select the df first, i.e. to constrain 2NW-1=df. As N is fixed
# for a given problem, this constrains W. The second is to choose W
# based on model concerns, and then given N, this constrains df. In
# the case of Model 2, we have chosen W = 7/365, i.e. 7 cycles/year,
# and there is no correction factor for delta-t needed as our data
# is daily.
#
# W needs to be in the same units as your data series.
#
Model2 <- as.formula("death ~ pm10tmean + s(tmpd, k=6, fx=TRUE) + s(dptp, k=3, fx=TRUE) +
as.factor(dow) + s(time, bs='sp', xt=list(W=7/365, mask=chic$mask))")
# Using the quasi(log, mu) link, and demonstrating the use of control arguments
# that can be used in the case of poor convergence
fit1 <- gam(Model1, data=chic, na.action=na.exclude, family=quasi(log,mu),
control=list(epsilon=1e-6, maxit=50))
fit2 <- gam(Model2, data=chic, na.action=na.exclude, family=quasi(log,mu),
control=list(epsilon=1e-6, maxit=50))
summary(fit1)
summary(fit2)
Run the code above in your browser using DataLab