ClaraHapp / MFPCA
Showing 2 of 2 files from the diff.
Newly tracked file
R/MFPCA_calculation.R changed.
Newly tracked file
R/univDecomp.R changed.

@@ -59,188 +59,177 @@
Loading
59 59
#' different (dimensional) domains
60 60
#'
61 61
#' This function calculates a multivariate functional principal component
62 -
#' analysis (MFPCA) based on i.i.d. observations \eqn{x_1, \ldots, x_N} of
63 -
#' a multivariate functional data-generating process \eqn{X = (X^{(1)},
64 -
#' \ldots X^{(p)})}{X = X^(1), \ldots, X^(p)} with elements \eqn{X^{(j)}
65 -
#' \in L^2(\mathcal{T}_j)}{X^(j) in L^2(calT_j)} defined on a domain
66 -
#' \eqn{\mathcal{T}_j \subset IR^{d_j}}{calT_j of IR^{d_j}}. In
67 -
#' particular, the elements can be defined on different (dimensional)
68 -
#' domains. The results contain the mean function, the estimated
69 -
#' multivariate functional principal components \eqn{\hat \psi_1, \ldots,
70 -
#' \hat \psi_M} (having the same structure as \eqn{x_i}), the associated
71 -
#' eigenvalues \eqn{\hat \nu_1 \geq \ldots \geq \hat \nu_M > 0} and the
72 -
#' individual scores \eqn{\hat \rho_{im} = \widehat{<x_i, \psi_m>}}{\hat
73 -
#' \rho_{im} = \hat{<x_i, \psi_m>}}. Moreover, estimated trajectories for
74 -
#' each observation based on the truncated Karhunen-Loeve representation
75 -
#' \deqn{\hat x_i = \sum_{m = 1}^M \hat \rho_{im} \hat \psi_m}{\hat x_i =
76 -
#' \sum_{m = 1}^M \hat \rho_{im} \hat \psi_m} are given if desired
77 -
#' (\code{fit = TRUE}). The implementation of the observations \eqn{x_i =
78 -
#' (x_i^{(1)}, \ldots , x_i^{(p)}),~ i = 1 , \ldots, N}{x_i = (x_i^(1),
79 -
#' \ldots , x_i^(p)), i = 1 , \ldots, N}, the mean function and
80 -
#' multivariate functional principal components \eqn{\hat \psi_1, \ldots,
81 -
#' \hat \psi_M} uses the \code{\link[funData]{multiFunData}} class, which
82 -
#' is defined in the package \pkg{funData}.
62 +
#' analysis (MFPCA) based on i.i.d. observations \eqn{x_1, \ldots, x_N} of a
63 +
#' multivariate functional data-generating process \eqn{X = (X^{(1)}, \ldots
64 +
#' X^{(p)})}{X = X^(1), \ldots, X^(p)} with elements \eqn{X^{(j)} \in
65 +
#' L^2(\mathcal{T}_j)}{X^(j) in L^2(calT_j)} defined on a domain
66 +
#' \eqn{\mathcal{T}_j \subset IR^{d_j}}{calT_j of IR^{d_j}}. In particular, the
67 +
#' elements can be defined on different (dimensional) domains. The results
68 +
#' contain the mean function, the estimated multivariate functional principal
69 +
#' components \eqn{\hat \psi_1, \ldots, \hat \psi_M} (having the same structure
70 +
#' as \eqn{x_i}), the associated eigenvalues \eqn{\hat \nu_1 \geq \ldots \geq
71 +
#' \hat \nu_M > 0} and the individual scores \eqn{\hat \rho_{im} =
72 +
#' \widehat{<x_i, \psi_m>}}{\hat \rho_{im} = \hat{<x_i, \psi_m>}}. Moreover,
73 +
#' estimated trajectories for each observation based on the truncated
74 +
#' Karhunen-Loeve representation \deqn{\hat x_i = \sum_{m = 1}^M \hat \rho_{im}
75 +
#' \hat \psi_m}{\hat x_i = \sum_{m = 1}^M \hat \rho_{im} \hat \psi_m} are given
76 +
#' if desired (\code{fit = TRUE}). The implementation of the observations
77 +
#' \eqn{x_i = (x_i^{(1)}, \ldots , x_i^{(p)}),~ i = 1 , \ldots, N}{x_i =
78 +
#' (x_i^(1), \ldots , x_i^(p)), i = 1 , \ldots, N}, the mean function and
79 +
#' multivariate functional principal components \eqn{\hat \psi_1, \ldots, \hat
80 +
#' \psi_M} uses the \code{\link[funData]{multiFunData}} class, which is defined
81 +
#' in the package \pkg{funData}.
83 82
#'
84 -
#' \subsection{Weighted MFPCA}{If the elements vary considerably in
85 -
#' domain, range or variation, a weight vector \eqn{w_1 , \ldots, w_p} can
86 -
#' be supplied and the MFPCA is based on the weighted scalar product
87 -
#' \deqn{<<f,g>>_w = \sum_{j = 1}^p w_j \int_{\mathcal{T}_j} f^{(j)}(t)
88 -
#' g^{(j)}(t) \mathrm{d} t}{<<f,g>>_w = \sum_{j = 1}^p w_j \int_\calT_j
89 -
#' f^(j)(t) g^(j)(t) d t} and the corresponding weighted covariance
90 -
#' operator \eqn{\Gamma_w}.}
83 +
#' \subsection{Weighted MFPCA}{If the elements vary considerably in domain,
84 +
#' range or variation, a weight vector \eqn{w_1 , \ldots, w_p} can be supplied
85 +
#' and the MFPCA is based on the weighted scalar product \deqn{<<f,g>>_w =
86 +
#' \sum_{j = 1}^p w_j \int_{\mathcal{T}_j} f^{(j)}(t) g^{(j)}(t) \mathrm{d}
87 +
#' t}{<<f,g>>_w = \sum_{j = 1}^p w_j \int_\calT_j f^(j)(t) g^(j)(t) d t} and the
88 +
#' corresponding weighted covariance operator \eqn{\Gamma_w}.}
91 89
#'
92 90
#' \subsection{Bootstrap}{If \code{bootstrap = TRUE}, pointwise bootstrap
93 -
#' confidence bands are generated for the multivariate eigenvalues
94 -
#' \eqn{\hat \nu_1, \ldots, \hat \nu_M } as well as for multivariate
95 -
#' functional principal components \eqn{\hat \psi_1, \ldots, \hat
96 -
#' \psi_M}{\hat \psi_1, \ldots, \hat \psi_M}. The parameter
97 -
#' \code{nBootstrap} gives the number of bootstrap iterations. In each
98 -
#' iteration, the observations are resampled on the level of
99 -
#' (multivariate) functions and the whole MFPCA is recalculated. In
100 -
#' particular, if the univariate basis depends on the data (FPCA
101 -
#' approaches), basis functions and scores are both re-estimated. If the
102 -
#' basis functions are fixed (e.g. splines), the scores from the original
103 -
#' estimate are used to speed up the calculations. The confidence bands
104 -
#' for the eigenfunctions are calculated separately for each element as
105 -
#' pointwise percentile bootstrap confidence intervals. Analogously, the
106 -
#' confidence bands for the eigenvalues are also percentile bootstrap
107 -
#' confidence bands. The significance level(s) can be defined by the
108 -
#' \code{bootstrapAlpha} parameter, which defaults to 5\%. As a result,
109 -
#' the \code{MFPCA} function returns a list \code{CI} of the same length
91 +
#' confidence bands are generated for the multivariate eigenvalues \eqn{\hat
92 +
#' \nu_1, \ldots, \hat \nu_M } as well as for multivariate functional principal
93 +
#' components \eqn{\hat \psi_1, \ldots, \hat \psi_M}{\hat \psi_1, \ldots, \hat
94 +
#' \psi_M}. The parameter \code{nBootstrap} gives the number of bootstrap
95 +
#' iterations. In each iteration, the observations are resampled on the level of
96 +
#' (multivariate) functions and the whole MFPCA is recalculated. In particular,
97 +
#' if the univariate basis depends on the data (FPCA approaches), basis
98 +
#' functions and scores are both re-estimated. If the basis functions are fixed
99 +
#' (e.g. splines), the scores from the original estimate are used to speed up
100 +
#' the calculations. The confidence bands for the eigenfunctions are calculated
101 +
#' separately for each element as pointwise percentile bootstrap confidence
102 +
#' intervals. Analogously, the confidence bands for the eigenvalues are also
103 +
#' percentile bootstrap confidence bands. The significance level(s) can be
104 +
#' defined by the \code{bootstrapAlpha} parameter, which defaults to 5\%. As a
105 +
#' result, the \code{MFPCA} function returns a list \code{CI} of the same length
110 106
#' as \code{bootstrapAlpha}, containing the lower and upper bounds of the
111 -
#' confidence bands for the principal components as \code{multiFunData}
112 -
#' objects of the same structure as \code{mFData}. The confidence bands
113 -
#' for the eigenvalues are returned in a list \code{CIvalues}, containing
114 -
#' the upper and lower bounds for each significance level.}
107 +
#' confidence bands for the principal components as \code{multiFunData} objects
108 +
#' of the same structure as \code{mFData}. The confidence bands for the
109 +
#' eigenvalues are returned in a list \code{CIvalues}, containing the upper and
110 +
#' lower bounds for each significance level.}
115 111
#'
116 112
#'
117 -
#' \subsection{Univariate Expansions}{The multivariate functional
118 -
#' principal component analysis relies on a univariate basis expansion for
119 -
#' each element \eqn{X^{(j)}}{X^(j)}. The univariate basis representation
120 -
#' is calculated using the \code{\link{univDecomp}} function, that passes
121 -
#' the univariate functional observations and optional parameters to the
122 -
#' specific function. The univariate decompositions are specified via the
123 -
#' \code{uniExpansions} argument in the \code{MFPCA} function. It is a
124 -
#' list of the same length as the \code{mFData} object, i.e. having one
125 -
#' entry for each element of the multivariate functional data. For each
126 -
#' element, \code{uniExpansion} must specify at least the type of basis
127 -
#' functions to use. Additionally, one may add further parameters. The
128 -
#' following basis representations are supported: \itemize{\item Given
129 -
#' basis functions. Then \code{uniExpansions[[j]] = list(type = "given",
130 -
#' functions, scores, ortho)}, where \code{functions} is a \code{funData}
131 -
#' object on the same domain as \code{mFData}, containing the given basis
132 -
#' functions. The parameters \code{scores} and \code{ortho} are optional.
133 -
#' \code{scores} is an \code{N x K} matrix containing the scores (or
134 -
#' coefficients) of the observed functions for the given basis functions,
135 -
#' where \code{N} is the number of observed functions and \code{K} is the
136 -
#' number of basis functions. If this is not supplied, the scores are
137 -
#' calculated. The parameter \code{ortho} specifies whether the given
138 -
#' basis functions are orthonormal \code{orhto = TRUE} or not \code{ortho
139 -
#' = FALSE}. If \code{ortho} is not supplied, the functions are treated as
140 -
#' non-orthogonal. \code{scores} and \code{ortho} are not checked for
141 -
#' plausibility, use them on your own risk!  \item Univariate functional
142 -
#' principal component analysis. Then \code{uniExpansions[[j]] = list(type
143 -
#' = "uFPCA", nbasis, pve, npc, makePD)}, where
144 -
#' \code{nbasis,pve,npc,makePD} are parameters passed to the
113 +
#' \subsection{Univariate Expansions}{The multivariate functional principal
114 +
#' component analysis relies on a univariate basis expansion for each element
115 +
#' \eqn{X^{(j)}}{X^(j)}. The univariate basis representation is calculated using
116 +
#' the \code{\link{univDecomp}} function, that passes the univariate functional
117 +
#' observations and optional parameters to the specific function. The univariate
118 +
#' decompositions are specified via the \code{uniExpansions} argument in the
119 +
#' \code{MFPCA} function. It is a list of the same length as the \code{mFData}
120 +
#' object, i.e. having one entry for each element of the multivariate functional
121 +
#' data. For each element, \code{uniExpansion} must specify at least the type of
122 +
#' basis functions to use. Additionally, one may add further parameters. The
123 +
#' following basis representations are supported: \itemize{\item Given basis
124 +
#' functions. Then \code{uniExpansions[[j]] = list(type = "given", functions,
125 +
#' scores, ortho)}, where \code{functions} is a \code{funData} object on the
126 +
#' same domain as \code{mFData}, containing the given basis functions. The
127 +
#' parameters \code{scores} and \code{ortho} are optional. \code{scores} is an
128 +
#' \code{N x K} matrix containing the scores (or coefficients) of the observed
129 +
#' functions for the given basis functions, where \code{N} is the number of
130 +
#' observed functions and \code{K} is the number of basis functions. Note that
131 +
#' the scores need to be demeaned to give meaningful results. If scores are not
132 +
#' supplied, they are calculated using the given basis functions. The parameter
133 +
#' \code{ortho} specifies whether the given basis functions are orthonormal
134 +
#' \code{orhto = TRUE} or not \code{ortho = FALSE}. If \code{ortho} is not
135 +
#' supplied, the functions are treated as non-orthogonal. \code{scores} and
136 +
#' \code{ortho} are not checked for plausibility, use them at your own risk!
137 +
#' \item Univariate functional principal component analysis. Then
138 +
#' \code{uniExpansions[[j]] = list(type = "uFPCA", nbasis, pve, npc, makePD)},
139 +
#' where \code{nbasis,pve,npc,makePD} are parameters passed to the
145 140
#' \code{\link{PACE}} function for calculating the univariate functional
146 141
#' principal component analysis. \item Basis functions expansions from the
147 -
#' package \pkg{fda}. Then \code{uniExpansions[[j]] = list(type = "fda",
148 -
#' ...)}, where \code{...} are passed to
149 -
#' \code{\link[funData]{funData2fd}}, which heavily builds on
150 -
#' \code{\link[fda]{eval.fd}}. If \pkg{fda} is not available, a warning is
151 -
#' thrown. \item Spline basis functions (not penalized). Then
142 +
#' package \pkg{fda}. Then \code{uniExpansions[[j]] = list(type = "fda", ...)},
143 +
#' where \code{...} are passed to \code{\link[funData]{funData2fd}}, which
144 +
#' heavily builds on \code{\link[fda]{eval.fd}}. If \pkg{fda} is not available,
145 +
#' a warning is thrown. \item Spline basis functions (not penalized). Then
152 146
#' \code{uniExpansions[[j]] = list(type = "splines1D", bs, m, k)}, where
153 147
#' \code{bs,m,k} are passed to the functions \code{\link{univDecomp}} and
154 -
#' \code{\link{univExpansion}}. For two-dimensional tensor product
155 -
#' splines, use \code{type = "splines2D"}. \item Spline basis functions
156 -
#' (with smoothness penalty). Then \code{uniExpansions[[j]] = list(type =
157 -
#' "splines1Dpen", bs, m, k)}, where \code{bs,m,k} are passed to the
158 -
#' functions \code{\link{univDecomp}} and \code{\link{univExpansion}}.
159 -
#' Analogously to the unpenalized case, use \code{type = "splines2Dpen"}
160 -
#' for 2D penalized tensor product splines. \item Cosine basis functions.
161 -
#' Use \code{uniExpansions[[j]] = list(type = "DCT2D", qThresh, parallel)}
162 -
#' for functions one two-dimensional domains (images) and \code{type =
163 -
#' "DCT3D"} for 3D images. The calculation is based on the discrete cosine
164 -
#' transform (DCT) implemented in the C-library \code{fftw3}. If this
165 -
#' library is not available, the function will throw  a warning.
166 -
#' \code{qThresh} gives the quantile for hard thresholding the basis
167 -
#' coefficients based on their absolute value. If \code{parallel = TRUE},
168 -
#' the coefficients for different images are calculated in parallel.} See
169 -
#' \code{\link{univDecomp}} and \code{\link{univExpansion}} for details.}
148 +
#' \code{\link{univExpansion}}. For two-dimensional tensor product splines, use
149 +
#' \code{type = "splines2D"}. \item Spline basis functions (with smoothness
150 +
#' penalty). Then \code{uniExpansions[[j]] = list(type = "splines1Dpen", bs, m,
151 +
#' k)}, where \code{bs,m,k} are passed to the functions \code{\link{univDecomp}}
152 +
#' and \code{\link{univExpansion}}. Analogously to the unpenalized case, use
153 +
#' \code{type = "splines2Dpen"} for 2D penalized tensor product splines. \item
154 +
#' Cosine basis functions. Use \code{uniExpansions[[j]] = list(type = "DCT2D",
155 +
#' qThresh, parallel)} for functions one two-dimensional domains (images) and
156 +
#' \code{type = "DCT3D"} for 3D images. The calculation is based on the discrete
157 +
#' cosine transform (DCT) implemented in the C-library \code{fftw3}. If this
158 +
#' library is not available, the function will throw  a warning. \code{qThresh}
159 +
#' gives the quantile for hard thresholding the basis coefficients based on
160 +
#' their absolute value. If \code{parallel = TRUE}, the coefficients for
161 +
#' different images are calculated in parallel.} See \code{\link{univDecomp}}
162 +
#' and \code{\link{univExpansion}} for details.}
170 163
#'
171 -
#' @param mFData A  \code{\link[funData]{multiFunData}} object containing
172 -
#'   the \code{N} observations.
164 +
#' @param mFData A  \code{\link[funData]{multiFunData}} object containing the
165 +
#'   \code{N} observations.
173 166
#' @param M The number of multivariate functional principal components to
174 167
#'   calculate.
175 -
#' @param uniExpansions A list characterizing the (univariate) expansion
176 -
#'   that is calculated for each element. See Details.
177 -
#' @param weights An optional vector of weights, defaults to \code{1} for
178 -
#'   each element. See Details.
179 -
#' @param fit Logical. If \code{TRUE}, a truncated multivariate
180 -
#'   Karhunen-Loeve representation for the data is calculated based on the
181 -
#'   estimated scores and eigenfunctions.
182 -
#' @param approx.eigen Logical. If \code{TRUE}, the eigenanalysis problem
183 -
#'   for the estimated covariance matrix is solved approximately using the
168 +
#' @param uniExpansions A list characterizing the (univariate) expansion that is
169 +
#'   calculated for each element. See Details.
170 +
#' @param weights An optional vector of weights, defaults to \code{1} for each
171 +
#'   element. See Details.
172 +
#' @param fit Logical. If \code{TRUE}, a truncated multivariate Karhunen-Loeve
173 +
#'   representation for the data is calculated based on the estimated scores and
174 +
#'   eigenfunctions.
175 +
#' @param approx.eigen Logical. If \code{TRUE}, the eigenanalysis problem for
176 +
#'   the estimated covariance matrix is solved approximately using the
184 177
#'   \pkg{irlba} package, which is much faster. If the number \code{M} of
185 -
#'   eigenvalues to calculate is high with respect to the number of
186 -
#'   observations in \code{mFData} or the number of estimated univariate
187 -
#'   eigenfunctions, the approximation may be inappropriate. In this case,
188 -
#'   approx.eigen is set to \code{FALSE} and the function throws a
189 -
#'   warning. Defaults to \code{FALSE}.
190 -
#' @param bootstrap Logical. If \code{TRUE}, pointwise bootstrap
191 -
#'   confidence bands are calculated for the multivariate functional
192 -
#'   principal components. Defaults to \code{FALSE}. See Details.
193 -
#' @param nBootstrap The number of bootstrap iterations to use. Defaults
194 -
#'   to \code{NULL}, which leads to an error, if \code{bootstrap = TRUE}.
195 -
#' @param bootstrapAlpha A vector of numerics (or a single number) giving
196 -
#'   the significance level for bootstrap intervals. Defaults to
197 -
#'   \code{0.05}.
198 -
#' @param bootstrapStrat A stratification variable for bootstrap. Must be
199 -
#'   a factor of length \code{nObs(mFData)} or \code{NULL} (default). If
200 -
#'   \code{NULL}, no stratification is made in the bootstrap resampling,
201 -
#'   i.e. the curves are sampled with replacement. If
202 -
#'   \code{bootstrapStrat} is not \code{NULL}, the curves are resampled
203 -
#'   with replacement within the groups defined by \code{bootstrapStrat},
204 -
#'   hence keeping the group proportions fixed.
178 +
#'   eigenvalues to calculate is high with respect to the number of observations
179 +
#'   in \code{mFData} or the number of estimated univariate eigenfunctions, the
180 +
#'   approximation may be inappropriate. In this case, approx.eigen is set to
181 +
#'   \code{FALSE} and the function throws a warning. Defaults to \code{FALSE}.
182 +
#' @param bootstrap Logical. If \code{TRUE}, pointwise bootstrap confidence
183 +
#'   bands are calculated for the multivariate functional principal components.
184 +
#'   Defaults to \code{FALSE}. See Details.
185 +
#' @param nBootstrap The number of bootstrap iterations to use. Defaults to
186 +
#'   \code{NULL}, which leads to an error, if \code{bootstrap = TRUE}.
187 +
#' @param bootstrapAlpha A vector of numerics (or a single number) giving the
188 +
#'   significance level for bootstrap intervals. Defaults to \code{0.05}.
189 +
#' @param bootstrapStrat A stratification variable for bootstrap. Must be a
190 +
#'   factor of length \code{nObs(mFData)} or \code{NULL} (default). If
191 +
#'   \code{NULL}, no stratification is made in the bootstrap resampling, i.e.
192 +
#'   the curves are sampled with replacement. If \code{bootstrapStrat} is not
193 +
#'   \code{NULL}, the curves are resampled with replacement within the groups
194 +
#'   defined by \code{bootstrapStrat}, hence keeping the group proportions
195 +
#'   fixed.
205 196
#' @param verbose Logical. If \code{TRUE}, the function reports
206 197
#'   extra-information about the progress (incl. timestamps). Defaults to
207 198
#'   \code{options()$verbose}.
208 199
#'
209 200
#' @return An object of class \code{MFPCAfit} containing the following
210 -
#'   components: \item{values}{A vector of estimated eigenvalues \eqn{\hat
211 -
#'   \nu_1 , \ldots , \hat \nu_M}.} \item{functions}{A
201 +
#'   components: \item{values}{A vector of estimated eigenvalues \eqn{\hat \nu_1
202 +
#'   , \ldots , \hat \nu_M}.} \item{functions}{A
212 203
#'   \code{\link[funData]{multiFunData}} object containing the estimated
213 -
#'   multivariate functional principal components \eqn{\hat \psi_1,
214 -
#'   \ldots, \hat \psi_M}.} \item{scores}{ A matrix of dimension \code{N x
215 -
#'   M} containing the estimated scores \eqn{\hat \rho_{im}}.}
216 -
#'   \item{vectors}{A matrix representing the eigenvectors associated with
217 -
#'   the combined univariate score vectors. This might be helpful for
218 -
#'   calculating predictions.} \item{normFactors}{The normalizing factors
219 -
#'   used for calculating the multivariate eigenfunctions and scores. This
220 -
#'   might be helpful when calculation predictions.} \item{meanFunction}{A
221 -
#'   multivariate functional data object, corresponding to the mean
222 -
#'   function. The MFPCA is applied to the de-meaned functions in
223 -
#'   \code{mFData}.}\item{fit}{A \code{\link[funData]{multiFunData}}
224 -
#'   object containing estimated trajectories for each observation based
225 -
#'   on the truncated Karhunen-Loeve representation and the estimated
226 -
#'   scores and eigenfunctions.} \item{CI}{A list of the same length as
227 -
#'   \code{bootstrapAlpha}, containing the pointwise lower and upper
228 -
#'   bootstrap confidence bands for each eigenfunction and each
229 -
#'   significance level in form of \code{\link[funData]{multiFunData}}
230 -
#'   objects (only if \code{bootstrap = TRUE}).} \item{CIvalues}{A list of
231 -
#'   the same length as \code{bootstrapAlpha}, containing the lower and
232 -
#'   upper bootstrap confidence bands for each eigenvalue and each
233 -
#'   significance level (only if \code{bootstrap = TRUE}).}
204 +
#'   multivariate functional principal components \eqn{\hat \psi_1, \ldots, \hat
205 +
#'   \psi_M}.} \item{scores}{ A matrix of dimension \code{N x M} containing the
206 +
#'   estimated scores \eqn{\hat \rho_{im}}.} \item{vectors}{A matrix
207 +
#'   representing the eigenvectors associated with the combined univariate score
208 +
#'   vectors. This might be helpful for calculating predictions.}
209 +
#'   \item{normFactors}{The normalizing factors used for calculating the
210 +
#'   multivariate eigenfunctions and scores. This might be helpful when
211 +
#'   calculation predictions.} \item{meanFunction}{A multivariate functional
212 +
#'   data object, corresponding to the mean function. The MFPCA is applied to
213 +
#'   the de-meaned functions in \code{mFData}.}\item{fit}{A
214 +
#'   \code{\link[funData]{multiFunData}} object containing estimated
215 +
#'   trajectories for each observation based on the truncated Karhunen-Loeve
216 +
#'   representation and the estimated scores and eigenfunctions.} \item{CI}{A
217 +
#'   list of the same length as \code{bootstrapAlpha}, containing the pointwise
218 +
#'   lower and upper bootstrap confidence bands for each eigenfunction and each
219 +
#'   significance level in form of \code{\link[funData]{multiFunData}} objects
220 +
#'   (only if \code{bootstrap = TRUE}).} \item{CIvalues}{A list of the same
221 +
#'   length as \code{bootstrapAlpha}, containing the lower and upper bootstrap
222 +
#'   confidence bands for each eigenvalue and each significance level (only if
223 +
#'   \code{bootstrap = TRUE}).}
234 224
#'
235 225
#' @export MFPCA
236 226
#'
237 227
#' @importFrom foreach %do%
238 228
#' @importFrom utils packageVersion
239 229
#'
240 -
#' @references C. Happ, S. Greven (2018): Multivariate Functional
241 -
#'   Principal Component Analysis for Data Observed on Different
242 -
#'   (Dimensional) Domains. Journal of the American Statistical
243 -
#'   Association, 113(522): 649-659. DOI:
230 +
#' @references C. Happ, S. Greven (2018): Multivariate Functional Principal
231 +
#'   Component Analysis for Data Observed on Different (Dimensional) Domains.
232 +
#'   Journal of the American Statistical Association, 113(522): 649-659. DOI:
244 233
#'   \doi{10.1080/01621459.2016.1273115}
245 234
#'
246 235
#' @references C. Happ-Kurz (2020): Object-Oriented Software for Functional
@@ -251,8 +240,7 @@
Loading
251 240
#'   introduction to the \pkg{funData} package and it's interplay with
252 241
#'   \pkg{MFPCA}. This file also includes a case study on how to use
253 242
#'   \code{MFPCA}. Useful functions: \code{\link[funData]{multiFunData}},
254 -
#'   \code{\link{PACE}}, \code{\link{univDecomp}},
255 -
#'   \code{\link{univExpansion}},
243 +
#'   \code{\link{PACE}}, \code{\link{univDecomp}}, \code{\link{univExpansion}},
256 244
#'   \code{\link[=summary.MFPCAfit]{summary}},
257 245
#'   \code{\link[=plot.MFPCAfit]{plot}},
258 246
#'   \code{\link[=scoreplot.MFPCAfit]{scoreplot}}

@@ -110,31 +110,31 @@
Loading
110 110
}
111 111
112 112
#' Use given basis functions for univariate representation
113 -
#' 
114 -
#' @param funDataObject An object of class \code{\link[funData]{funData}} 
115 -
#'   containing the observed functional data samples and for which the basis 
116 -
#'   representation is to be calculated.
117 -
#' @param functions A \code{funData} object that contains the basis 
118 -
#'   functions.
119 -
#' @param scores An optional matrix containing the scores or coefficients of 
120 -
#'   the individual observations and each basis function. If \code{N} denotes
121 -
#'   the number of observations and \code{K} denotes the number of basis 
122 -
#'   functions, then \code{scores} must be a matrix of dimensions \code{N x 
123 -
#'   K}. If not supplied, the scores are calculated as projection of each 
124 -
#'   observation on the basis functions.
125 -
#' @param ortho An optional parameter, specifying whether the given basis 
126 -
#'   functions are orthonormal (\code{ortho = TRUE}) or not (\code{ortho = 
127 -
#'   FALSE}). If not supplied, the basis functions are considered as 
128 -
#'   non-orthonormal and their pairwise scalar product is calculated for 
129 -
#'   later use in the MFPCA.
130 -
#'   
131 -
#' @return \item{scores}{The coefficient matrix.} \item{B}{A matrix
132 -
#'   containing the scalar product of all pairs of basis functions. This is
133 -
#'   \code{NULL}, if \code{ortho = TRUE}.}\item{ortho}{Logical, set to 
134 -
#'   \code{TRUE}, if basis functions are orthonormal.} \item{functions}{A 
135 -
#'   functional data object containing the basis functions.}
136 -
#'  
137 -
#'  @keywords internal
113 +
#'
114 +
#' @param funDataObject An object of class \code{\link[funData]{funData}}
115 +
#'   containing the observed functional data samples and for which the basis
116 +
#'   representation is to be calculated. The data is assumed to be demeaned.
117 +
#' @param functions A \code{funData} object that contains the basis functions.
118 +
#' @param scores An optional matrix containing the scores or coefficients of the
119 +
#'   individual observations and each basis function. If \code{N} denotes the
120 +
#'   number of observations and \code{K} denotes the number of basis functions,
121 +
#'   then \code{scores} must be a matrix of dimensions \code{N x K}. As the data
122 +
#'   is assumed to be demeaned, each column must have an average of
123 +
#'   approximately 0. If not supplied, the scores are calculated as projection
124 +
#'   of each observation on the basis functions.
125 +
#' @param ortho An optional parameter, specifying whether the given basis
126 +
#'   functions are orthonormal (\code{ortho = TRUE}) or not (\code{ortho =
127 +
#'   FALSE}). If not supplied, the basis functions are considered as
128 +
#'   non-orthonormal and their pairwise scalar product is calculated for later
129 +
#'   use in the MFPCA.
130 +
#'
131 +
#' @return \item{scores}{The coefficient matrix.} \item{B}{A matrix containing
132 +
#'   the scalar product of all pairs of basis functions. This is \code{NULL}, if
133 +
#'   \code{ortho = TRUE}.}\item{ortho}{Logical, set to \code{TRUE}, if basis
134 +
#'   functions are orthonormal.} \item{functions}{A functional data object
135 +
#'   containing the basis functions.}
136 +
#'
137 +
#' @keywords internal
138 138
givenBasis <- function(funDataObject, functions, scores = NULL, ortho = NULL)
139 139
{
140 140
  # check if funDataObject and functions are defined on the same domain
Files Coverage
R 91.66%
src 100.00%
Project Totals (12 files) 91.71%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading