Dense2dFPCA {fdarep}R Documentation

Two-Dimensional Functional Principal Component Analysis for dense repeated functional data.

Description

Note: The code works for dense functional data observed on a regular grid, missing values are allowed.

Usage

Dense2dFPCA(
  X.age.year,
  n,
  num.years,
  num.ages,
  fpca.op = list(),
  pc.num = NULL
)

Arguments

X.age.year

An n by (num.years x num.ages) input data matrix, such that the ith row of the matrix gives the observed values for the ith individual. The values in each row are sorted first by years (dimension 1) and then by ages (dimension 2) within each year.

n

The sample size.

num.years

Dimension 1

num.ages

Dimension 2

fpca.op

A list of options control parameters specified by list(name=value) for the two-dimesnional FPCA; check fdapace::FPCA for available control options and default settings.

pc.num

A scalar denoting the maximum number of components to consider for the two-dimensional FPCA; default: chosen by FVE if NULL.

Details

The code works for dense functional data (with missing values), with density in both the direction of (age) dimension 2 and (year) dimension 1.

Value

A list containing the following fields:

mu

An num.ages by num.years matrix containing the bivariate mean function estimate.

pc.num

A scalar denoting the selected number of components for the two-dimensional FPCA.

res.2D.FPCA

A list containing the FPCA output for the fitted two-dimensional FPCA.

scores

An n by pc.num matrix of the estimated scores, such that the ith row of the matrix comprises estimated scores for the ith individual.

eig

An (num.years x num.ages) by pc.num matrix of the estimated product eigen functions. The estimated eigenfunctions in the otput eig are in the form of a vector rather than a matrix. For example, the first column in eig gives the first estimated eigenfunction such that gamma(s,t) -> eig[ ( (s-1)*num.ages + t ), 1] where LHS is the bivariate function in the usual form and RHS gives the corresponding element in the output vector. The rows are sorted first by years (dimension 1) and then by ages (dimension 2) within each year.

FVE

A vector of length pc.num, indicating the fraction of total variance explained by each product function, with corresponding 'FVEthreshold'.

References

Examples


n <- 100 ### sample size
N <- 100
num.ages <- 20 ### dimension 2
num.years <- 15 ### dimension 1
dense_grid <- seq(0,1,length=N)
Lt <- list()
Ly <- list()
for (i in 1:n) {
  Lt[[i]] <- dense_grid ### dense time grid
  y_temp <- matrix(0,num.ages,num.years)
  for (s in 1:num.ages) {
    for (t in 1:num.years) {
      y_temp[s,t] <- y_temp[s,t]+cos(Lt[[i]][t])+rnorm(1,0,0.5)
    }
  }
  Ly[[i]] <- y_temp ### dense functional data
}
X.age.year <- matrix(0,n,num.years*num.ages)
for (i in 1:n) {
  X.age.year[i,] <- as.vector(Ly[[i]]) ### data matrix
}
res <- Dense2dFPCA(X.age.year, n , 15, 20, fpca.op=NULL,pc.num=2)
# Basic output
res$mu
res$pc.num
res$res.2D.FPCA
res$eig
res$FVE
res$pc.num
cumsum(res$FVE)



[Package fdarep version 0.1.1 Index]