make_basis_fct: Generate basis function

Description Usage Arguments Details Examples

Description

Method for generating a 'basis function' function, that outputs a functional basis.

Usage

1
2
make_basis_fct(kts = NULL, df = NULL, type = "B-spline",
  intercept = FALSE, control = list())

Arguments

kts

a sequence of increasing points specifying the placement of the knots.

df

degrees of freedom of the spline basis. Knots are chosen equidistantly.

type

the type of basis function you want. Currently supported choices are 'B-spline', 'increasing' and 'intercept'. See details for more information.

intercept

logical. Should the basis include an intercept?

control

list of control parameters. Most importantly is boundary which contains boundary points for a B-spline basis. See details for more options.

Details

Basis types 'Fourier' and 'wavelet' will become available soon. If needed please contact the developer.

The control argument takes a list with the following entries order and constraints and sparse

boundary

boundary knots for the basis spline.

order

order of the spline, if NULL, B-splines have order 4 (cubic spline) and I-splines (type = 'increasing') have order 3.

constraints

positivity constraints, if set to 'positive', only positive weights are allowed

sparse

logical. Should sparse matrices be used?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Basis function knots
kts <- seq(0, 1, length = 12)[2:11]

# Construct B-spline basis function
basis_fct <- make_basis_fct(kts = kts, control = list(boundary = c(0, 1)))

# Evaluation points
t <- seq(0, 1, length = 100)
A <- basis_fct(t)
plot(t, t, type = 'n', ylim = range(A))
for (i in 1:ncol(A)) lines(t, A[, i], col = rainbow(ncol(A))[i])

# Evaluate derivatives
Ad <- basis_fct(t, TRUE)
plot(t, t, type = 'n', ylim = range(Ad))
for (i in 1:ncol(A)) lines(t, Ad[, i], col = rainbow(ncol(Ad))[i])

# Construct I-spline
# Knots should contain the left and right endpoints
kts_inc <- seq(0, 1, length = 10)
basis_fct_inc <- make_basis_fct(kts = kts_inc, type = 'increasing')
A_inc <- basis_fct_inc(t)
plot(t, t, type = 'n', ylim = range(A_inc))
for (i in 1:ncol(A_inc)) lines(t, A_inc[, i], col = rainbow(ncol(A))[i])

# Evaluate derivatives
Ad_inc <- basis_fct_inc(t, deriv = TRUE)
plot(t, t, type = 'n', ylim = range(Ad_inc))
for (i in 1:ncol(Ad_inc)) lines(t, Ad_inc[, i], col = rainbow(ncol(Ad))[i])

# Simulate data
y <- t^2 * sin(8 * t) + t
plot(t, y, type = 'l', lwd = 2, lty = 2)

# Add noise to data
y <- y + rnorm(length(y), sd = 0.1)
points(t, y, pch = 19, cex = 0.5)

# Fit B-spline to data assuming iid. noise
weights <- spline_weights(y, t, basis_fct = basis_fct)
lines(t, A %*% weights, col = 'red', lwd = 2)

# Fit increasing spline
pos_weights <- spline_weights(y, t, basis_fct = basis_fct_inc)
lines(t, A_inc %*% pos_weights, col = 'blue', lwd = 2)

larslau/pavpop documentation built on June 14, 2019, 2:18 p.m.