ObjCov {frechet}R Documentation

Object Covariance

Description

Calculating covariance for time varying object data

Usage

ObjCov(tgrid, I, K, smooth = TRUE)

Arguments

tgrid

Time grid for the time varying object data and covariance function

I

A four dimension array of n x n matrix of squared distances between the time point u of the ith process and process and the time point v of the jth object process, e.g.: I[i,j,u,v] = d^2(X_i(u) X_j(v))

K

Numbers of principal components

smooth

Logical indicating if the smoothing is enabled when calculating the eigenvalues and eigenfunctions

Value

A list of the following:

C

Estimated object covariance (non-smooth) on the 2D grid of dimension length(tgrid) X length(tgrid)

sC

Estimated object covariance (smooth) on the 2D grid of dimension length(tgrid) X length(tgrid)

tgrid

Time grid for the time varying object data and covariance function

K

Numbers of principal components

phi

Matrix of smooth eigenfunctions (dimension: length(tgrid) X K)

lambda

Vector of eigenvalues of dimension K

References

Dubey, P., & Müller, H. G. (2020). Functional models for time‐varying random objects. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 82(2), 275-327.

Examples


### functional covariate
phi1 <- function(x) -cos(pi*x/10)/sqrt(5)
phi2 <- function(x)  sin(pi*x/10)/sqrt(5)

lambdaX <- c(4,2)
# training set
n <- 100
N <- 50
tgrid <- seq(0,10,length.out = N)

Xi <- matrix(rnorm(2*n),nrow=n,ncol=2)
CovX <- lambdaX[1] * phi1(tgrid) %*% t(phi1(tgrid)) + lambdaX[2] * phi2(tgrid) %*% t(phi2(tgrid))
comp1 = lambdaX[1]^(1/2) * Xi[,1] %*% t(phi1(tgrid))
comp2 = lambdaX[2]^(1/2) * Xi[,2] %*% t(phi2(tgrid))
SampleX <- comp1 + comp2

I <- array(0, c(n,n,N,N))
for (u in 1:N){
  for (v in 1:N){
    temp1 <- SampleX[,u]
   temp2 <- SampleX[,v]
    I[,,u,v] <- outer(temp1, temp2, function(v1,v2){
     (v1 - v2)^2
   })
 }
}

result_cov <- ObjCov(tgrid, I, 2)
result_cov$lambda #4 2

sC <- result_cov$sC
sum((sC-CovX)^2) / sum(sC^2)
sum((phi1(tgrid)-result_cov$phi[,1])^2)/sum(phi1(tgrid)^2)


[Package frechet version 0.3.0 Index]