Learn R Programming

ssym (version 1.5.2)

lambda.hat: Tool to choose smoothing parameters.

Description

lambda.hat is used to choose the smoothing parameter using the unweighted cross-validation score.

Usage

lambda.hat(response,xx,lambda,type,plot)

Arguments

response
the response variable.
xx
the explanatory variable.
lambda
an optional numeric value of starting estimate for the smoothing parameter. Default is 1.
type
an integer indicating the type of nonparametric effect, e.g., 1 indicates natural cubic spline, and 2 indicates P-spline.
plot
logical. If plot=TRUE, it shows a graph with the shape of the cross-validation score.

Value

  • lha list with the chosen smoothing parameter and the value of the cross-validation score.

References

Eilers, P.H.C. and Marx, B.D. (1996). Flexible smoothing with B-splines and penalties. Statistical Science, 11, 89-121. Green, P.J. and Silverman, B.W. (1994) Nonparametric Regression and Generalized Linear Models, Boca Raton: Chapman and Hall.

Examples

Run this code
n <- 300
t <- sort(round(runif(n),digits=2))
y <- cos(4*pi*t) + rnorm(n)
datas <- data.frame(t,y)

par(mfrow=c(1,2))
lambda <- lambda.hat(y,t,1,1,plot=TRUE)
lambda <- lambda$lambda_hat
fit <- ssym.l(y ~ ncs(t, lambda=lambda), family="Normal", data=datas)
np.graph(fit, which=1, main="Natural Cubic Spline")

#x11()
par(mfrow=c(1,2))
lambda <- lambda.hat(y,t,1,2,plot=TRUE)
lambda <- lambda$lambda_hat
fit2 <- ssym.l(y ~ psp(t, lambda=lambda), family="Normal", data=datas)
np.graph(fit2, which=1, main="P-spline")

Run the code above in your browser using DataLab