Title: | Regularized Multivariate Functional Principal Component Analysis |
---|---|
Description: | Methods and tools for implementing regularized multivariate functional principal component analysis ('ReMFPCA') for multivariate functional data whose variables might be observed over different dimensional domains. 'ReMFPCA' is an object-oriented interface leveraging the extensibility and scalability of R6. It employs a parameter vector to control the smoothness of each functional variable. By incorporating smoothness constraints as penalty terms within a regularized optimization framework, 'ReMFPCA' generates smooth multivariate functional principal components, offering a concise and interpretable representation of the data. For detailed information on the methods and techniques used in 'ReMFPCA', please refer to Haghbin et al. (2023) <doi:10.48550/arXiv.2306.13980>. |
Authors: | Hossein Haghbin [aut, cre] , Yue Zhao [aut] , Mehdi Maadooliat [aut] |
Maintainer: | Hossein Haghbin <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.0 |
Built: | 2024-11-15 03:06:12 UTC |
Source: | https://github.com/haghbinh/remfpca |
Subtract two 'mfd' objects
## S3 method for class 'mfd' obj1 - obj2 = NULL
## S3 method for class 'mfd' obj1 - obj2 = NULL
obj1 |
An 'mfd' object |
obj2 |
An 'mfd' object or a scalar |
The difference between the two 'mfd' objects
Subtraction of two 'mvmfd' objects
## S3 method for class 'mvmfd' obj1 - obj2 = NULL
## S3 method for class 'mvmfd' obj1 - obj2 = NULL
obj1 |
An 'mvmfd' object |
obj2 |
An optional 'mvmfd' object |
An 'mvmfd' object
Extract subsets of an 'mfd' object
## S3 method for class 'mfd' mfd_obj[i = "index"]
## S3 method for class 'mfd' mfd_obj[i = "index"]
mfd_obj |
An 'mfd' object |
i |
An index or indices specifying the subsets to extract |
An 'mfd' object containing the specified subsets
Extract subsets of an 'mvmfd' object
## S3 method for class 'mvmfd' mvmfd_obj[i = "index", j = "index"]
## S3 method for class 'mvmfd' mvmfd_obj[i = "index", j = "index"]
mvmfd_obj |
An 'mvmfd' object |
i |
An index or indices specifying the subsets to extract for the first dimension |
j |
An index or indices specifying the subsets to extract for the second dimension |
An 'mvmfd' object containing the specified subsets
Scalar multiplication of an 'mfd' object. One object must be an 'mfd', and the other one a scalar
## S3 method for class 'mfd' obj1 * obj2
## S3 method for class 'mfd' obj1 * obj2
obj1 |
An 'mfd' object or an scalar |
obj2 |
An 'mfd' object or an scalar |
An 'mfd' object
Multiplication of an 'mvmfd' object with a scalar
## S3 method for class 'mvmfd' obj1 * obj2
## S3 method for class 'mvmfd' obj1 * obj2
obj1 |
An 'mvmfd' object or a scalar |
obj2 |
An 'mvmfd' object or a scalar |
An 'mvmfd' object
Add two 'mfd' objects
## S3 method for class 'mfd' obj1 + obj2 = NULL
## S3 method for class 'mfd' obj1 + obj2 = NULL
obj1 |
An 'mfd' object |
obj2 |
An 'mfd' object or a scalar |
The sum of the two 'mfd' objects
Addition of two 'mvmfd' objects
## S3 method for class 'mvmfd' obj1 + obj2 = NULL
## S3 method for class 'mvmfd' obj1 + obj2 = NULL
obj1 |
An 'mvmfd' object |
obj2 |
An optional 'mvmfd' object |
An 'mvmfd' object
The 'basismfd' class represents a set of multidimensional basis functions. This class utilizes basis objects from the 'fda' package, such as B-splines and Fourier bases.
Constructor for 'basismfd' objects (same as Basismfd(...) )
Basismfd(...) Basismfd(...)
Basismfd(...) Basismfd(...)
... |
A list of 'basisfd' objects |
basis
A list of basis objects from the 'fda' package.
dimSupp
The dimension of the support domain of the 'basismfd' object.
supp
The matrix representing the ranges of the dimensions.
gram
The Gram matrix.
nbasis
A numeric vector containing the number of bases.
new()
The constructor function for objects of the class 'basismfd' (same as Basismfd(...) )
basismfd$new(...)
...
A list of 'basisfd' objects
eval()
Evaluate the 'basismfd' object at given argument values
basismfd$eval(evalarg)
evalarg
A list of numeric vectors of argument values at which the 'basismfd' is to be evaluated
A list of evaluated values
print()
Print method for 'basismfd' objects
basismfd$print(...)
...
Additional arguments to be passed to 'print' Getter and setter for 'basis' field Getter and setter for 'dimSupp' field Getter and setter for 'nbasis' field Getter and setter for 'supp' field Getter and setter for 'gram' field
clone()
The objects of this class are cloneable with this method.
basismfd$clone(deep = FALSE)
deep
Whether to make a deep clone.
require(fda) bs1 <- create.fourier.basis(c(0, 2 * pi), 5) bs2 <- create.bspline.basis(c(0, 1), 7) bs3 <- create.exponential.basis(c(0, 2), 3) # 1-D Basis ######## (similar to the fd features) mdbs1 <- Basismfd(bs1) mdbs1$basis mdbs1$dimSupp mdbs1$nbasis mdbs1$supp mdbs1$gram mdbs1$eval(1:7 / 10) image(as.matrix(mdbs1$gram)) ####### 2-D Basis ######## (fd cannot handle this) mdbs2 <- Basismfd(bs1, bs2) mdbs2$basis mdbs2$dimSupp mdbs2$nbasis mdbs2$supp dim(mdbs2$gram) arg_mdbs <- list(1:10, 1:9 / 10) mdbs2$eval(arg_mdbs) image(as.matrix(mdbs2$gram))
require(fda) bs1 <- create.fourier.basis(c(0, 2 * pi), 5) bs2 <- create.bspline.basis(c(0, 1), 7) bs3 <- create.exponential.basis(c(0, 2), 3) # 1-D Basis ######## (similar to the fd features) mdbs1 <- Basismfd(bs1) mdbs1$basis mdbs1$dimSupp mdbs1$nbasis mdbs1$supp mdbs1$gram mdbs1$eval(1:7 / 10) image(as.matrix(mdbs1$gram)) ####### 2-D Basis ######## (fd cannot handle this) mdbs2 <- Basismfd(bs1, bs2) mdbs2$basis mdbs2$dimSupp mdbs2$nbasis mdbs2$supp dim(mdbs2$gram) arg_mdbs <- list(1:10, 1:9 / 10) mdbs2$eval(arg_mdbs) image(as.matrix(mdbs2$gram))
Bivariate plot for 'mvmfd' objects
bimfdplot(mvmfd_obj, type = "l", lty = 1, xlab = "", ylab = "", main = "", ...)
bimfdplot(mvmfd_obj, type = "l", lty = 1, xlab = "", ylab = "", main = "", ...)
mvmfd_obj |
An 'mvmfd' object |
type |
Type of plot ('l' for lines, 'p' for points, etc.) |
lty |
Line type |
xlab |
Label for the x-axis |
ylab |
Label for the y-axis |
main |
Main title |
... |
Additional arguments for the matplot function |
Compute the inner product between two objects of class 'mfd'
inprod_mfd(mfd_obj1, mfd_obj2)
inprod_mfd(mfd_obj1, mfd_obj2)
mfd_obj1 |
An 'mfd' object |
mfd_obj2 |
An 'mfd' object |
The inner products matrix between the two 'mfd' objects
Compute the inner product between two objects of class 'mvmfd'
inprod_mvmfd(mvmfd_obj1, mvmfd_obj2)
inprod_mvmfd(mvmfd_obj1, mvmfd_obj2)
mvmfd_obj1 |
An 'mvmfd' object |
mvmfd_obj2 |
An 'mvmfd' object |
The inner products matrix between the two 'mvmfd' objects
Check if an object is of class 'basismfd'
is.basismfd(fdobj)
is.basismfd(fdobj)
fdobj |
The object to check. |
TRUE if the object is of class 'basismfd', FALSE otherwise.
is.mvbasismfd
, is.mfd
, is.mvmfd
Check if an object is of class 'mfd'
is.mfd(fdobj)
is.mfd(fdobj)
fdobj |
The object to check. |
TRUE if the object is of class 'mfd', FALSE otherwise.
is.mvbasismfd
, is.basismfd
, is.mvmfd
Check if an object is of class 'mvbasismfd'
is.mvbasismfd(fdobj)
is.mvbasismfd(fdobj)
fdobj |
The object to check. |
TRUE if the object is of class 'mvbasismfd', FALSE otherwise.
Check if an object is of class 'mvmfd'
is.mvmfd(fdobj)
is.mvmfd(fdobj)
fdobj |
The object to check. |
TRUE if the object is of class 'mvmfd', FALSE otherwise.
is.mvbasismfd
, is.mfd
, is.basismfd
Length of an object of an object of classes 'mfd' or 'mvmfd'.
length(x, ...)
length(x, ...)
x |
An object of classes 'mfd' or 'mvmfd'. |
... |
all 'length' function arguments. |
mean of an object of classes 'mfd'or 'mvmfd'.
mean(x, ...)
mean(x, ...)
x |
An object of classes 'mfd' or 'mvmfd'. |
... |
all 'mean' function arguments. |
An object of class 'mfd'
The 'mfd' class represents a set of multidimensional functional data with 'basismfd' object. Functional data objects are constructed by specifying a set of basis functions and a set of coefficients defining a linear combination of these basis functions.
Constructor for 'mfd' objects (same as Mfd(...) )
Mfd(argval = NULL, X, mdbs, method = "data")
Mfd(argval = NULL, X, mdbs, method = "data")
argval |
A list of numeric vectors of argument values at which the 'mfd' object is to be evaluated |
X |
A numeric matrix corresponds to basis expansion coefficients if 'method="coefs"' and discrete observations if 'method="data"'. |
mdbs |
a basismfd object |
method |
determine the 'X' matrix type as "coefs" and "data". |
basis
an object of the class 'basismfd'.
coefs
a matrix of the coefficients.
nobs
number of the observation
new()
Constructor for 'mfd' objects (same as Mfd(...) )
mfd$new(argval = NULL, X, mdbs, method = "data")
argval
A list of numeric vectors of argument values at which the 'mfd' object is to be evaluated
X
A numeric matrix corresponds to basis expansion coefficients if 'method="coefs"' and discrete observations if 'method="data"'.
mdbs
a basismfd object
method
determine the 'X' matrix type as "coefs" and "data".
eval()
Evaluation an 'mfd' object in some arguments.
mfd$eval(evalarg)
evalarg
a list of numeric vector of argument values at which the mfd
is to be evaluated.
A matrix of evaluated values
print()
Print method for 'mfd' objects
mfd$print(...)
...
Additional arguments to be passed to 'print'
clone()
The objects of this class are cloneable with this method.
mfd$clone(deep = FALSE)
deep
Whether to make a deep clone.
require(fda) bs1 <- create.fourier.basis(c(0,2*pi),5) bs2 <- create.bspline.basis(c(0,1),7) bs3 <- create.exponential.basis(c(0,2),3) #1-D mfd :_____________________________ argval <- seq(0,2*pi,length.out=100) nobs <- 10; X <- outer(sin(argval),seq(0.5,1.5,length.out=nobs)) mdbs1 <- Basismfd(bs1) mfd1 <- Mfd(X=X, mdbs = mdbs1) inprod_mfd(mfd1,mfd1) norm_mfd(mfd1) mfd0 <- 2.5*mfd1 mfd1-mfd0 mfd1[1:3] mfd1$eval(argval) mfd1c <- Mfd(X=mfd1$coefs, mdbs = mdbs1, method = "coefs") all.equal(c(mfd1$basis,mfd1$coefs,mfd1$nobs),c(mfd1c$basis,mfd1c$coefs,mfd1c$nobs)) length(mfd1) mean(mfd1) plot(mfd1)
require(fda) bs1 <- create.fourier.basis(c(0,2*pi),5) bs2 <- create.bspline.basis(c(0,1),7) bs3 <- create.exponential.basis(c(0,2),3) #1-D mfd :_____________________________ argval <- seq(0,2*pi,length.out=100) nobs <- 10; X <- outer(sin(argval),seq(0.5,1.5,length.out=nobs)) mdbs1 <- Basismfd(bs1) mfd1 <- Mfd(X=X, mdbs = mdbs1) inprod_mfd(mfd1,mfd1) norm_mfd(mfd1) mfd0 <- 2.5*mfd1 mfd1-mfd0 mfd1[1:3] mfd1$eval(argval) mfd1c <- Mfd(X=mfd1$coefs, mdbs = mdbs1, method = "coefs") all.equal(c(mfd1$basis,mfd1$coefs,mfd1$nobs),c(mfd1c$basis,mfd1c$coefs,mfd1c$nobs)) length(mfd1) mean(mfd1) plot(mfd1)
The 'mvbasismfd' a set of multivariate multidimensional basis functions. This class utilizes basis objects 'basismfd'.
Constructor for 'mvbasismfd' objects (same as 'Mvbasismfd')
Mvbasismfd(basis) Mvbasismfd(basis) ## S3 method for class 'mvbasismfd' mvbasismfd_obj[i = "index"]
Mvbasismfd(basis) Mvbasismfd(basis) ## S3 method for class 'mvbasismfd' mvbasismfd_obj[i = "index"]
basis |
A list of basisfd objects |
mvbasismfd_obj |
An 'mvmfd' object |
i |
An index or indices specifying the subsets to extract for the first dimension |
An 'mvbasismfd' object containing the specified subsets
nvar
number of variables
basis
A list of 'mvbasisfd' objects
dimSupp
A sequence of positive integers specifying support domain of the 'mvbasismfd' object.
nbasis
A list of integers specifying the number of basis functions
supp
A list of matrices specifying the support of basis functions
gram
The Gram matrix.
new()
Constructor for 'mvbasismfd' objects (same as Mvbasismfd(...) )
mvbasismfd$new(basis)
basis
A list of 'basismfd' objects
eval()
Evaluate the 'mvbasismfd' object at given argument values
mvbasismfd$eval(evalarg)
evalarg
A list of numeric vectors of argument values at which the 'mvbasismfd' is to be evaluated
A list of evaluated values
clone()
The objects of this class are cloneable with this method.
mvbasismfd$clone(deep = FALSE)
deep
Whether to make a deep clone.
The 'mvmfd' class represents functional data ...
Constructor for 'mvmfd' objects (same as 'Mvmfd')
Mvmfd(...)
Mvmfd(...)
... |
A 'mfd' objects which have separated by comma |
basis
A 'mvbasismfd' object
coefs
a matrix of the coefficients.
nobs
number of observation
nvar
number of variables
new()
Constructor for ‘mvmfd' objects (same as ’Mvmfd')
mvmfd$new(...)
...
A 'mfd' objects which have separated by comma
eval()
Eval method for 'mvmfd' objects
mvmfd$eval(evalarg)
evalarg
A list of numeric vectors of argument values at which the 'mvmfd' is to be evaluated.
A list of evaluated values
print()
Print method for 'mvmfd' objects
mvmfd$print(...)
...
Additional arguments to be passed to 'print'
clone()
The objects of this class are cloneable with this method.
mvmfd$clone(deep = FALSE)
deep
Whether to make a deep clone.
require(fda) bs1 <- create.fourier.basis(c(0, 2 * pi), 5) bs2 <- create.bspline.basis(c(0, 1), 7) bs3 <- create.exponential.basis(c(0, 2), 3) nobs <- 10 argval1 <- seq(0, 2 * pi, length.out = 12) X1 <- outer(sin(argval1), seq(0.5, 1.5, length.out = nobs)) mdbs1 <- Basismfd(bs1) mfd1 <- Mfd(argval1, X1, mdbs1) mdbs2 <- Basismfd(bs1) argval2 <- argval1 X2 <- outer(cos(argval2), seq(0.2, 1.5, length.out = nobs)) mfd2 <- Mfd(argval2, X2, mdbs1) mvmfd1 <- Mvmfd(mfd1, mfd2) mvmfd1[1] mvmfd1[1, 1] mvmfd1[1:5, 2] mvmfd1[, 1] mvmfd1[1:5, ] evalarg <- list(argval1, argval2) mvmfd1$eval(evalarg) mvmfd1 + mvmfd1 mean(mvmfd1) inprod_mvmfd(mvmfd1, mvmfd1) norm_mvmfd(mvmfd1) plot(mvmfd1) bimfdplot(mvmfd1)
require(fda) bs1 <- create.fourier.basis(c(0, 2 * pi), 5) bs2 <- create.bspline.basis(c(0, 1), 7) bs3 <- create.exponential.basis(c(0, 2), 3) nobs <- 10 argval1 <- seq(0, 2 * pi, length.out = 12) X1 <- outer(sin(argval1), seq(0.5, 1.5, length.out = nobs)) mdbs1 <- Basismfd(bs1) mfd1 <- Mfd(argval1, X1, mdbs1) mdbs2 <- Basismfd(bs1) argval2 <- argval1 X2 <- outer(cos(argval2), seq(0.2, 1.5, length.out = nobs)) mfd2 <- Mfd(argval2, X2, mdbs1) mvmfd1 <- Mvmfd(mfd1, mfd2) mvmfd1[1] mvmfd1[1, 1] mvmfd1[1:5, 2] mvmfd1[, 1] mvmfd1[1:5, ] evalarg <- list(argval1, argval2) mvmfd1$eval(evalarg) mvmfd1 + mvmfd1 mean(mvmfd1) inprod_mvmfd(mvmfd1, mvmfd1) norm_mvmfd(mvmfd1) plot(mvmfd1) bimfdplot(mvmfd1)
Compute the norm of an object of class 'mfd'
norm_mfd(mfd_obj)
norm_mfd(mfd_obj)
mfd_obj |
An object of class 'mfd' |
The norm vector of the an object of class 'mfd'
Compute the norm of an object of class 'mvmfd'
norm_mvmfd(mvmfd_obj)
norm_mvmfd(mvmfd_obj)
mvmfd_obj |
An 'mvmfd' object |
The norm vector of the an object of class 'mvmfd'
Calculate the penalty matrix for 'mvmfd' objects.
pen_fun(data, devorder = 2, type)
pen_fun(data, devorder = 2, type)
data |
an object of class 'mvmfd'. |
devorder |
The order of the derivative. |
type |
The type of penalty. The types "coefpen" and "basispen" is supported. |
The penalty matrix.
plot an object of classes 'mfd', 'mvmfd' or 'remfpca'
plot(x, ...)
plot(x, ...)
x |
An object of classes 'mfd', 'mvmfd' or 'remfpca' |
... |
all 'plot' function arguments. |
The 'remfpca' class represents regularized functional principal components components.
The ‘remfpca' class represents regularized functional principal components (’ReMFPCs') components.
Remfpca( mvmfd_obj, ncomp, alpha = NULL, centerfns = TRUE, alpha_orth = TRUE, penalty_type = "coefpen" )
Remfpca( mvmfd_obj, ncomp, alpha = NULL, centerfns = TRUE, alpha_orth = TRUE, penalty_type = "coefpen" )
mvmfd_obj |
An 'mvmfd' object representing the multivariate functional data. |
ncomp |
The number of functional principal components to retain. |
alpha |
A list or vector specifying the regularization parameter(s) for each variable. If NULL, the regularization parameter is estimated internally. |
centerfns |
Logical indicating whether to center the functional data before analysis. |
alpha_orth |
Logical indicating whether to perform orthogonalization of the regularization parameters. |
penalty_type |
The type of penalty to be applied on the coefficients. The types "coefpen" and "basispen" is supported. Default is "coefpen". |
pc_mfd
an object of class 'mvmfd' where the first indices (fields) represents harmonics and second indices represents variables
lsv
= Left singular values vectors
values
= the set of eigenvalues
alpha
= The vector of penalties parameters
GCVs
= generalized cross validations
mean_mfd
a multivariate functional data object giving the mean function
new()
remfpca$new( mvmfd_obj, ncomp, alpha = NULL, centerfns = TRUE, alpha_orth = TRUE, penalty_type = "coefpen" )
mvmfd_obj
An 'mvmfd' object representing the multivariate functional data.
ncomp
The number of functional principal components to retain.
alpha
A list or vector specifying the regularization parameter(s) for each variable. If NULL, the regularization parameter is estimated internally.
centerfns
Logical indicating whether to center the functional data before analysis.
alpha_orth
Logical indicating whether to perform orthogonalization of the regularization parameters.
penalty_type
The type of penalty to be applied on the coefficients. The types "coefpen" and "basispen" is supported. Default is "coefpen".
clone()
The objects of this class are cloneable with this method.
remfpca$clone(deep = FALSE)
deep
Whether to make a deep clone.
require(fda) # Brownian Bridge simulation on [0,1] M <- 110 # number of components N <- 20 # number of instances n <- 100 # number of grides t0 <- seq(0, 1, len = n) j <- 1:M alpha1 <- list(a1 = 2^seq(0, 1, length.out = 3), a2 = 2^seq(0, 1, length.out = 3)) psi_1 <- function(t, m) sin(m * pi * t) # eigenfunction of BB psi_2 <- function(t, m) sin((2 * m - 1) * pi / 2 * t) # eigenfunction of BM PC_1 <- outer(t0, j, FUN = psi_1) # n by M matrix PC_2 <- outer(t0, j, FUN = psi_2) # n by M matrix Z <- matrix(rnorm(N * M), nr = M) lambda <- matrix(2 / (pi * (2 * j - 1)), nr = M, nc = N) X_1t <- PC_1 %*% (lambda * Z) X_2t <- PC_2 %*% (lambda * Z) noise <- rnorm(n * N, 0, 0.1) X_1 <- X_1t + noise X_2 <- X_2t + noise bs <- create.bspline.basis(c(0, 1), 51) mdbs <- Basismfd(bs) mfd1 <- Mfd(X = X_1, mdbs = mdbs) mfd2 <- Mfd(X = X_2, mdbs = mdbs) mvmfd_obj <- Mvmfd(mfd1, mfd2) k <- 2 Re0 <- Remfpca(mvmfd_obj, ncomp = k, alpha = c(0, 0)) fpc0 <- Re0$pc_mfd scores0 <- inprod_mvmfd(mvmfd_obj, fpc0) dim(scores0) Re0$alpha Re1 <- Remfpca(mvmfd_obj, ncomp = k, alpha = alpha1) Re1$alpha Re3 <- Remfpca(mfd1, ncomp = k, alpha = alpha1$a1) Re3$alpha
require(fda) # Brownian Bridge simulation on [0,1] M <- 110 # number of components N <- 20 # number of instances n <- 100 # number of grides t0 <- seq(0, 1, len = n) j <- 1:M alpha1 <- list(a1 = 2^seq(0, 1, length.out = 3), a2 = 2^seq(0, 1, length.out = 3)) psi_1 <- function(t, m) sin(m * pi * t) # eigenfunction of BB psi_2 <- function(t, m) sin((2 * m - 1) * pi / 2 * t) # eigenfunction of BM PC_1 <- outer(t0, j, FUN = psi_1) # n by M matrix PC_2 <- outer(t0, j, FUN = psi_2) # n by M matrix Z <- matrix(rnorm(N * M), nr = M) lambda <- matrix(2 / (pi * (2 * j - 1)), nr = M, nc = N) X_1t <- PC_1 %*% (lambda * Z) X_2t <- PC_2 %*% (lambda * Z) noise <- rnorm(n * N, 0, 0.1) X_1 <- X_1t + noise X_2 <- X_2t + noise bs <- create.bspline.basis(c(0, 1), 51) mdbs <- Basismfd(bs) mfd1 <- Mfd(X = X_1, mdbs = mdbs) mfd2 <- Mfd(X = X_2, mdbs = mdbs) mvmfd_obj <- Mvmfd(mfd1, mfd2) k <- 2 Re0 <- Remfpca(mvmfd_obj, ncomp = k, alpha = c(0, 0)) fpc0 <- Re0$pc_mfd scores0 <- inprod_mvmfd(mvmfd_obj, fpc0) dim(scores0) Re0$alpha Re1 <- Remfpca(mvmfd_obj, ncomp = k, alpha = alpha1) Re1$alpha Re3 <- Remfpca(mfd1, ncomp = k, alpha = alpha1$a1) Re3$alpha
Standard deviation an object of class 'mfd'.
sd(x, ...)
sd(x, ...)
x |
An object of class 'mfd' |
... |
all 'sd' function arguments. |
An object of class 'mfd'