clone_base | R Documentation |
Extract basis parameters from an existing B-splines basis matrix,
and use them for computing a new basis at new values of x
.
clone_base(B, x)
B |
a B-splines basis matrix, computed with |
x |
a vector of new argument values. |
If values in x
are outside the domain used for computing B
, they will be discarded, with a warning.
A matrix with number of rows=length(xnew)
.
Paul Eilers
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.
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.