Learn R Programming

face (version 0.1-1)

pspline: Univariate P-spline smoothing

Description

Univariate P-spline smoothing with the smoothing parameter selected by leave-one-subject-out cross validation.

Usage

pspline(data, argvals.new = NULL, knots = 35, knots.option="quantile", p = 3, m = 2, lambda = NULL, search.length = 100, lower = -20, upper = 20)

Arguments

data
a data frame with three arguments: (1) argvals: observation times; (2) subj: subject indices; (3) y: values of observations. Missing values not allowed.
argvals.new
a vector of observations times for prediction; if NULL, then the same as data$argvals.
knots
a vector of interior knots or the number of knots for B-spline basis functions to be used; defaults to 35.
knots.option
if knots specifies the number of knots, then knots.option will be used. Default "quantile", then quantiles of the observed time points will be selected; alternatively, "equally-spaced": equally-spaced knots in the range of observed time points will be selected.
p
the degrees of B-splines; defaults to 3.
m
the order of differencing penalty; defaults to 2.
lambda
the value of the smoothing parameter; defaults to NULL.
search.length
the number of equidistant (log scale) smoothing parameters to search; defaults to 100.
lower, upper
bounds for log smoothing parameter; defaults are -20 and 20.

Value

fitted.values
Fitted mean values
B
B-spline design matrix
theta
Estimated coefficients
s
Eigenvalues
knots
Knots
p
The degrees of B-splines
m
The order of differencing penalty
lambda
The value of the smoothing parameter
argvals.new
A vector of observations times
mu.new
Fitted mean values at argvals.new

Details

The function is an implementation of the P-spline smoothing in Eilers and Marx (1996). P-splines uses B-splines as basis functions and employs a differencing penalty on the coefficients. Leave-one-subject-out cross validation is used for selecting the smoothing parameter and a fast algorithm is implemented.

References

Paul Eilers and Brian Marx, Flexible smoothing with B-splines and penalties, Statist. Sci., 11, 89-121, 1996.

Luo Xiao, Cai Li, Will Checkley and Ciprian Crainiceanu, Fast covariance estimation for sparse functional data, manuscript.

See Also

gam in mgcv.

Examples

Run this code
## Not run: 
# ## cd4 data
# require(refund)
# data(cd4)
# n <- nrow(cd4)
# T <- ncol(cd4)
# 
# id <- rep(1:n,each=T)
# t <- rep(-18:42,times=n)
# y <- as.vector(t(cd4))
# sel <- which(is.na(y))
# 
# ## organize data
# data <- data.frame(y=log(y[-sel]),
# argvals = t[-sel],
# subj = id[-sel])
# data <- data[data$y>4.5,]
# 
# ## smooth
# fit <- pspline(data)
# 
# ## plot
# plot(data$argvals,fit$mu.new,type="p")
# 
# ## prediction
# pred <- predict(fit,quantile(data$argvals,c(0.2,0.6)))
# pred
# ## End(Not run)

Run the code above in your browser using DataLab