Description Usage Arguments Value Examples
Simulate a functional sample using a Karhunen Loève expansion
1 |
grid |
the grid (of length |
size |
a positive integer indicating the size of the functional sample to simulate. |
mean |
a vector representing the mean of the sample. |
covariance |
a matrix from which the eigenvalues and eigenfunctions must be extracted. |
rho |
a vector of the eigenvalues to be used for the simulation. |
theta |
a matrix of the eigenfunctions to be used for the simulation. |
The function returns a functional data object of type funData
.
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 | # Define parameters
n <- 50
P <- 100
K <- 150
# Grid of the functional dataset
t <- seq( 0, 1, length.out = P )
# Define the means and the parameters to use in the simulation
# with the Karhunen - Loève expansion
m1 <- t^2 * ( 1 - t )
lambda <- rep( 0, K )
theta <- matrix( 0, K, P )
for ( k in 1:K ) {
lambda[k] <- 1 / ( k + 1 )^2
if ( k%%2 == 0 )
theta[k, ] <- sqrt( 2 ) * sin( k * pi * t )
else if ( k%%2 != 0 && k != 1 )
theta[k, ] <- sqrt( 2 ) * cos( ( k - 1 ) * pi * t )
else
theta[k, ] <- rep( 1, P )
}
# Simulate the functional data
x <- simulate_KL( t, n, m1, rho = lambda, theta = theta )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.