Learn R Programming

JOPS (version 0.2.0)

cdiff: Compute a second order circular differencing matrix

Description

Compute difference matrix used for circular penalities.

Usage

cdiff(n)

Value

A square matrix with n rows and columns.

Arguments

n

number of rows (and columns) of the square differencing matrix.

Author

Paul Eilers

References

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.

Examples

Run this code
# Compare standard and circular differencing matrix
n = 8
D1 = diff(diag(n), diff = 2)
D2 = cdiff(n)
oldpar = par(no.readonly = TRUE)
on.exit(par(oldpar))
par(mfrow = c(1, 2))
image(t(D1))
title('Linear differencing matrix')
image(t(D2))
title('Circular differencing matrix')


Run the code above in your browser using DataLab