Learn R Programming

face (version 0.1-7)

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,
            p = 3, m = 2, lambda = NULL,
            search.length = 100,
            lower = -20, upper = 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

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.

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.

Author

Luo Xiao <lxiao5@ncsu.edu>

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, William Checkley and Ciprian Crainiceanu, Fast covariance estimation for sparse functional data, Stat. Comput., tools:::Rd_expr_doi("10.1007/s11222-017-9744-8").

See Also

gam in mgcv.

Examples

Run this code
if (FALSE) {
## 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
}

Run the code above in your browser using DataLab