clone_base: Clone a B-spline basis for new x

View source: R/clone_base.R

clone_baseR Documentation

Clone a B-spline basis for new x

Description

Extract basis parameters from an existing B-splines basis matrix, and use them for computing a new basis at new values of x.

Usage

clone_base(B, x)

Arguments

B

a B-splines basis matrix, computed with bbase() or cbase().

x

a vector of new argument values.

Details

If values in x are outside the domain used for computing B, they will be discarded, with a warning.

Value

A matrix with number of rows=length(xnew).

Author(s)

Paul Eilers

References

Eilers, P.H.C. and Marx, B.D. (2021). Practical Smoothing, The Joys of P-splines. Cambridge University Press.

Eilers, P.H.C., Marx, B.D., and Durban, M. (2015). Twenty years of P-splines, SORT, 39(2): 149-186.

Examples


x = seq(0, 10, length = 20)
n = length(x)
y = sin(x / 2) + rnorm(n) * 0.2
B = bbase(x)
nb = ncol(B)
D = diff(diag(nb), diff = 2)
lambda = 1
a = solve(t(B) %*% B + lambda * t(D)%*% D, t(B) %*% y)
# Clone basis on finer grid
xg = seq(0, 10, length = 200)
Bg = clone_base(B, xg)
yg = Bg %*% a
plot(x, y)
lines(xg, yg, col = 'blue')


JOPS documentation built on Sept. 8, 2023, 5:42 p.m.

Related to clone_base in JOPS...