Learn R Programming

gamlss.util (version 4.2-7)

penLS: Function to fit penalised least squares

Description

The function penLS() can be used to fit a penalised least square to a response variable y. There is no explanatory variable here. The underline model is a random walk.

Usage

penLS(y, w = rep(1, length(y)), df = NULL, lambda = NULL, 
      start = 10, order = 1, plot = FALSE, 
      type = c("level", "trend"), 
      method = c("ML", "GAIC", "GCV"), k = 2, ...)

Arguments

Value

Returns a fitted object of class penLS. The object contains 1) the fitted coefficients 2) the fitted.values 3) the response variable y, 4) the smoothing parameter lambda, 8) the effective degrees of freedom df, 5) the estimete for sigma sigma, 6) the residual sum of squares rss, 7) the Akaike information criterion aic, 8) the Bayesian information criterion sbc and 9) the deviance

Warning

The function can be slow for large response variable

Details

The order refers to differences in the penalty matrix, (i) order = 0 : white noise random effects (ii) order = 1 : random walk (iii) order = 2 : random walk of order 2 (iv) order = 3 : random walk of order 3

References

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. 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. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, http://www.jstatsoft.org/v23/i07.

See Also

penReg

Examples

Run this code
set.seed(1234)
 x<-seq(0,10,length=200); y<-(yt<-1+2*x+.6*x^2-.1*x^3)+rnorm(200,0, 16)
yts <- ts(y)
plot(yts)
#---------------------------------------------------------
#lambda fix
 m1<-penLS(yts,lambda=1) ; deviance(m1) 
#--------------------------------------------------------- 
# fixing df 
 m2<-penLS(yts, df=10) ; deviance(m2)
#---------------------------------------------------------  
# estimating lambda - ML
m3<-penLS(yts) ; deviance(m3)
#---------------------------------------------------------
# estimating lambda - GAIC
m4<-penLS(yts, method="GAIC", k=3) ; deviance(m4)
#---------------------------------------------------------
# different order
PPP <- par(mfrow=c(2,2))
penLS(yts, plot=TRUE, order=0, main="order=0")
penLS(yts, plot=TRUE, order=1, main="order=1")
penLS(yts, plot=TRUE, order=2, main="order=2")
penLS(yts, plot=TRUE, order=3, main="order=3")
par(PPP)

Run the code above in your browser using DataLab