pca: Standard PCA accounting for missing data

View source: R/pca.R

pcaR Documentation

Standard PCA accounting for missing data

Description

Standard (linear) PCA accounting for missing data, assuming a 2-d field like structure for inputs.

Usage

pca(A)

Arguments

A

Array, usually represinting a [longitude,latitudade, n] field, where the two first dimensions represent the geographical distribution and the third dimension the sequence over which PCA is to be done (time series or experiment ensemble )

Details

elementary SVD

Value

List of

mean

2-d matrix of mean field over the third dimension

PCA

Array [lon, lat, n], where the third dimesion is the PC order, ranked in decreasing eigenvalue

amps

Matrix [n,n] with each row corresponding to the field number, and columns to PCs

d

Vector of eigenvalues

Author(s)

Michel Crucifix

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (A) 
{
    nlon = dim(A)[1]
    nlat = dim(A)[2]
    nr = dim(A)[3]
    A = matrix(A, nlon * nlat, nr)
    mean = apply(A, 1, mean)
    Am = sweep(A, 1, apply(A, 1, mean))
    o = which(!is.na(Am[, 1]))
    U = svd(Am[o, ])
    O = A
    V = A
    O[o, ] = U$u
    O = array(O, c(nlon, nlat, nr))
    mean = matrix(mean, nlon, nlat)
    d = U$d
    return(list(mean = mean, PCA = O, amps = U$v, d = d))
  }

mcrucifix/gp documentation built on July 29, 2023, 8:58 p.m.