Skip to contents

Use a p-spline (penalised spine) to model main effects or interactions. Typically used with age, but can be used with any variable where outcomes are expected to vary smoothly from one element to the next.

Usage

Sp(n_comp = NULL, s = 1, along = NULL)

Arguments

n_comp

Number of spline basis functions (components) to use.

s

Scale for the prior for the innovations. Default is 1.

along

Name of the variable to be used as the "along" variable. Only used with interactions.

Value

An object of class "bage_prior_spline".

Details

If Sp() is used with an interaction, separate splines are used for the "along" variable within each combination of the "by" variables.

Mathematical details

When Sp() is used with a main effect,

$$\pmb{\beta} = \pmb{X} \pmb{\alpha}$$

and when it is used with an interaction,

$$\pmb{\beta}_u = \pmb{X} \pmb{\alpha}_u$$

where

  • \(\pmb{\beta}\) is the main effect or interaction, with \(J\) elements;

  • \(\pmb{beta}_u\) is a subvector of \(\pmb{\beta}\) holding values for the \(u\)th combination of the "by" variables;

  • \(J\) is the number of elements of \(\pmb{\beta}\);

  • \(U\) is the number of elements of \(\pmb{\beta}_u\);

  • \(X\) is a \(J \times n\) or \(V \times n\) matrix of spline basis functions; and

  • \(n\) is n_comp.

The elements of \(\pmb{\alpha}\) or \(\pmb{alpha}_u\) are assumed to follow a second-order random walk.

References

  • Eilers, P.H.C. and Marx B. (1996). "Flexible smoothing with B-splines and penalties". Statistical Science. 11 (2): 89–121.

See also

  • RW() Smoothing via random walk

  • RW2() Smoothing via second-order random walk

  • SVD() Smoothing of age via singular value decomposition

  • priors Overview of priors implemented in bage

  • set_prior() Specify prior for intercept, main effect, or interaction

  • bage uses function splines::bs() to construct spline basis functions

Examples

Sp()
#>   Sp() 
#>   n_comp: NULL
#>        s: 1
#>    along: NULL
Sp(n_comp = 10)
#>   Sp(n_comp=10) 
#>   n_comp: 10
#>        s: 1
#>    along: NULL