cs()
and scs()
are using the cubic smoothing splines function smooth.spline()
to do smoothing. They take a vector and return it with several attributes.
The vector is used in the construction of the model matrix. The functions do not do the smoothing, but assigns the attributes to the vector to aid gamlss in the smoothing.
The function doing the smoothing is gamlss.cs()
.
This function use the Rcs(x, df = 3, spar = NULL, c.spar = NULL, control = cs.control(...), ...)
scs(x, df = NULL, spar = NULL, control = cs.control(...), ...)
cs.control(cv = FALSE, all.knots = TRUE, nknots = NULL, keep.data = TRUE,
df.offset = 0, penalty = 1.4, control.spar = list(), ...)
vc
the x argument is the vector which has its (linear) coefficient change with r
df
. The default values used are the ones given the option control.spar
in the R fsmooth.spline()
, see belowadditive.fit()
.
Since smoothing splines includes linear fits, the linear part will be efficiently computed with the other parametric linear parts of the model.smooth.spline
gamlss()
results with the equivalent gam()
results in S-plus: make sure when using S-plus that the convergence criteria epsilon and bf.epsilon in control.gam()
are decreased sufficiently
to ensure proper convergence in S-plus.
Also note that the degrees of freedom are defined on top of the linear term in gamlss
, but on top of the constant term in S-plus,
(so use an extra degrees of freedom in S-plus in order to obtain comparable results to those in galmss
).Change the upper limit of spar if you received the warning 'The output df are different from the input, change the control.spar'.
For large data sets do not use expressions, e.g. cs(x^0.5)
inside the gamlss
function command but evaluate the expression,
e.g. nx=$x^0.5$, first and then use cs(nx)
.
cs
itself does no smoothing; it simply sets things up for the function gamlss()
which in turn uses the function
additive.fit()
for backfitting which in turn uses gamlss.cs()
Note that cs()
and scs()
functions behave differently at their default values that is if df and lambda are not specified.
cs(x)
by default will use 3 extra degrees of freedom for smoothing for x
.
scs(x)
by default will estimate lambda (and the degrees of freedom) automatically using generalised cross validation (GCV).
Note that if GCV is used the convergence of the gamlss model can be less stable compared to a model where the degrees of freedom are fixed. This will be true for small data sets.
Eilers, P. H. C. and Marx, B. D. (1996). Flexible smoothing with B-splines and penalties (with comments and rejoinder). Statist. Sci, 11, 89-121.
Hastie, T. J. and Tibshirani, R. J. (1993), Varying coefficient models (with discussion),J. R. Statist. Soc. B., 55, 757-796.
Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion), Appl. Statist., 54, part 3, pp 507-554.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R.
Accompanying documentation in the current GAMLSS help files, (see also
Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R.
Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007,
gamlss
, gamlss.cs
, pb
, pvc
# cubic splines example
data(aids)
# fitting a smoothing cubic spline with 7 degrees of freedom
# plus the a quarterly effect
aids1<-gamlss(y~cs(x,df=7)+qrt,data=aids,family=PO) #
aids2<-gamlss(y~scs(x,df=5)+qrt,data=aids,family=PO) #
aids3<-gamlss(y~scs(x)+qrt,data=aids,family=PO) # using GCV
with(aids, plot(x,y))
lines(aids$x,fitted(aids1), col="red")
lines(aids$x,fitted(aids3), col="green")
rm(aids1, aids2, aids3)
Run the code above in your browser using DataLab