Learn R Programming

ssym (version 1.5.1)

lambda.hat: Choosing the smoothing parameter

Description

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

Usage

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

Arguments

response
the response variable.
xx
values of 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 behavior of the cross-validation score.

Value

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

References

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