RandomSpl | R Documentation |
Generate a random cubic spline g(x)
on [0, 1] and sample its values at n
unevenly spaced x
-values.
RandomSpl(n, periodic = FALSE, plot = TRUE)
n |
number of unevenly spaced |
periodic |
TRUE to generate a periodic spline; FALSE to generate an ordinary spline. |
plot |
TRUE to plot the generated random spline. |
A random spline is generated as a linear combination of 8 uniform B-splines, whose coefficients are a realization of an AR(1) process with coefficient -1/3. In case g(x)
needs be periodic, these B-spline coefficients are further transformed to satisfy the periodic constraints, i.e., g^{(m)}(0) = g^{(m)}(1)
, m
= 0, 1, 2.
A list of the following components:
x
, n
unevenly spaced x
-values drawn from a "tent" distribution, whose density peaks at g(x)
's local extrema;
y
, g(x)
evaluated at x
;
xg
, 101 equidistant x
-values (i.e., stepsize = 0.01);
yg
, g(x)
evaluated at xg
;
Zheyuan Li zheyuan.li@bath.edu
Li, Z. and Cao, J. (2022). General P-Splines for Non-Uniform B-Splines.
require(gps.mgcv)
op <- par(mfrow = c(1, 2), mar = c(2, 2, 1.5, 0.5))
spl.ordinary <- RandomSpl(200)
title("a random cubic spline")
spl.periodic <- RandomSpl(200, periodic = TRUE)
title("a random periodic cubic spline")
par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.