RandomSpl: A random cubic spline on [0, 1].

RandomSplR Documentation

A random cubic spline on [0, 1].

Description

Generate a random cubic spline g(x) on [0, 1] and sample its values at n unevenly spaced x-values.

Usage

RandomSpl(n, periodic = FALSE, plot = TRUE)

Arguments

n

number of unevenly spaced x-values.

periodic

TRUE to generate a periodic spline; FALSE to generate an ordinary spline.

plot

TRUE to plot the generated random spline.

Details

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.

Value

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;

Author(s)

Zheyuan Li zheyuan.li@bath.edu

References

Li, Z. and Cao, J. (2022). General P-Splines for Non-Uniform B-Splines.

Examples

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)

ZheyuanLi/gps.mgcv documentation built on Sept. 19, 2024, 9:11 p.m.