Description Usage Arguments Details Value See Also Examples
View source: R/Package_Sim.GenerateData.r
Generate Legendre polynomials as an orthogonal basis system in the interval [0, 1]. The set of polynomial functions are used to be the eigenfunctions to generate the covariance matrix of a latent process.
1 | legendre.polynomials(t, degree, normalized = TRUE)
|
t |
the set of values to be evaluated, taking values from [0, 1] |
degree |
the polynomial degree of the function, taking values as 0 (constant), 1 (linear), 2 (quadratic) and 3 (cubic) |
normalized |
logical value; If TRUE (default) then the values are normalized such that the L2 norm of the function values is 1 |
Legendre polynomials can take any integers as degree
, however, it is sufficent for most applications up to degree = 3
.
It is also messy to obtain the exploit expression for a degree greater than 3.
The logical value normalized
take TRUE
as the default, which means the generated eigenfunction basis matrix will be
an orthogonal matrix.
A vector which are the evaluations of the Legendre polynomial function at t
.
1 2 3 4 5 6 7 8 9 10 11 12 | # time points
t <- seq(from = 0, to = 1, length = 100)
# basis matrix evaluated at the time points t
# an intercept column is included
Phi <- cbind(legendre.polynomials(t, degree = 0), legendre.polynomials(t, degree = 1),
legendre.polynomials(t, degree = 2), legendre.polynomials(t, degree = 3))
# check the orthogonality
crossprod(Phi) # is equal to I_4 up to rounding errors
# plot the basis system excluding the constant column
matplot(t, Phi[,2:4], type = "l", lwd = 2, lty = 1:3,
ylab = "basis function", main = "Legendre Polynomials (normalized)")
legend("top", c("linear", "quadratic", "cubic"), col = 1:3, lwd = 2, lty = 1:3)
|
Loading required package: sn
Loading required package: stats4
Attaching package: 'sn'
The following object is masked from 'package:stats':
sd
[,1] [,2] [,3] [,4]
[1,] 1.000000e+00 1.769418e-16 2.213718e-02 -4.510281e-17
[2,] 1.769418e-16 1.000000e+00 2.567391e-16 4.504553e-02
[3,] 2.213718e-02 2.567391e-16 1.000000e+00 3.191891e-16
[4,] -4.510281e-17 4.504553e-02 3.191891e-16 1.000000e+00
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.