├── .Rbuildignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── coerce.R ├── funDataClass.R ├── funDataMethods.R ├── get_set.R ├── names.R ├── plotMethods.R ├── simulation.R ├── str.R ├── subset.R ├── summary.R └── zzz.R ├── README.md ├── appveyor.yml ├── inst └── CITATION ├── man ├── Arith.funData.Rd ├── Math.funData.Rd ├── X-funData-method.Rd ├── X-irregFunData-method.Rd ├── X-multiFunData-method.Rd ├── X-set-funData-method.Rd ├── X-set-irregFunData-method.Rd ├── X-set-multiFunData-method.Rd ├── addError-funData-method.Rd ├── addError-multiFunData-method.Rd ├── addError.Rd ├── approxNA-funData-method.Rd ├── approxNA.Rd ├── argvals-funData-method.Rd ├── argvals-irregFunData-method.Rd ├── argvals-multiFunData-method.Rd ├── argvals-set-funData-method.Rd ├── argvals-set-irregFunData-method.Rd ├── argvals-set-multiFunData-method.Rd ├── argvals.Rd ├── as.data.frame.funData.Rd ├── as.funData.Rd ├── as.irregFunData.Rd ├── as.multiFunData.Rd ├── autoplot.funData.Rd ├── autoplot.irregFunData.Rd ├── autoplot.multiFunData.Rd ├── dimSupp-funData-method.Rd ├── dimSupp-irregFunData-method.Rd ├── dimSupp-multiFunData-method.Rd ├── dimSupp.Rd ├── dot-intWeights.Rd ├── dot-scalarProduct.Rd ├── eFun.Rd ├── eVal.Rd ├── efFourier.Rd ├── efPoly.Rd ├── efWiener.Rd ├── expand.int.Rd ├── extractObs-funData-method.Rd ├── extractObs-irregFunData-method.Rd ├── extractObs-multiFunData-method.Rd ├── extractObs.Rd ├── extrapolateIrreg.Rd ├── fd2funData.Rd ├── flipFuns-funData-funData-method.Rd ├── flipFuns-funData-irregFunData-method.Rd ├── flipFuns-irregFunData-irregFunData-method.Rd ├── flipFuns-multiFunData-multiFunData-method.Rd ├── flipFuns.Rd ├── funData-class.Rd ├── funData-setAs.Rd ├── funData2fd.Rd ├── ggplot.Rd ├── integrate-funData-method.Rd ├── integrate-irregFunData-method.Rd ├── integrate-multiFunData-method.Rd ├── integrate.Rd ├── integrate3D.Rd ├── irregFunData-class.Rd ├── irregFunData-setAs.Rd ├── meanFunction-funData-method.Rd ├── meanFunction-irregFunData-method.Rd ├── meanFunction-multiFunData-method.Rd ├── meanFunction.Rd ├── multiFunData-class.Rd ├── nObs-funData-method.Rd ├── nObs-irregFunData-method.Rd ├── nObs-multiFunData-method.Rd ├── nObs.Rd ├── nObsPoints-funData-method.Rd ├── nObsPoints-irregFunData-method.Rd ├── nObsPoints-multiFunData-method.Rd ├── nObsPoints.Rd ├── norm-funData-missing-method.Rd ├── norm-irregFunData-missing-method.Rd ├── norm-multiFunData-missing-method.Rd ├── norm.Rd ├── norm.funData.Rd ├── norm.irregFunData.Rd ├── plot.funData.Rd ├── plot.irregFunData.Rd ├── plot.multiFunData.Rd ├── print.funData.Rd ├── print.irregFunData.Rd ├── scalarProduct-funData-funData-method.Rd ├── scalarProduct-funData-irregFunData-method.Rd ├── scalarProduct-irregFunData-funData-method.Rd ├── scalarProduct-irregFunData-irregFunData-method.Rd ├── scalarProduct-multiFunData-multiFunData-method.Rd ├── scalarProduct.Rd ├── simFunData.Rd ├── simMultiFunData.Rd ├── simMultiSplit.Rd ├── simMultiWeight.Rd ├── sparsify-funData-method.Rd ├── sparsify-multiFunData-method.Rd ├── sparsify.Rd ├── tensorProduct-funData-method.Rd └── tensorProduct.Rd └── tests ├── testthat.R └── testthat ├── outputs ├── print_funData.out ├── print_irregFunData.out ├── print_multiFunData.out ├── str_funData.out ├── str_irregFunData.out ├── str_irregFunData_len1.out ├── str_multiFunData.out ├── str_multiFunData_2.out ├── summary_funData.out ├── summary_funData_names.out ├── summary_irregFunData.out ├── summary_irregFunData_names.out └── summary_multiFunData.out ├── test_funDataClass.R ├── test_funDataMethods.R ├── test_plotMethods.R └── test_simulation.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | 4 | # Travis 5 | .travis.yml 6 | # License file 7 | LICENSE 8 | ^appveyor\.yml$ 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | cache: packages 3 | 4 | os: 5 | - linux 6 | - osx 7 | 8 | r: 9 | - release 10 | - devel 11 | 12 | matrix: 13 | exclude: 14 | - os: osx 15 | r: devel 16 | 17 | after_success: 18 | - Rscript -e 'covr::codecov(line_exclusions = list("R/zzz.R"))' -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: funData 2 | Type: Package 3 | Title: An S4 Class for Functional Data 4 | Version: 1.3-9 5 | Date: 2024-02-10 6 | Authors@R: person("Clara", "Happ-Kurz", email = "chk_R@gmx.de", 7 | role = c("aut", "cre")) 8 | Author: Clara Happ-Kurz [aut, cre] 9 | Maintainer: Clara Happ-Kurz 10 | Description: S4 classes for univariate and multivariate functional data with 11 | utility functions. See for a detailed description 12 | of the package functionalities and its interplay with the MFPCA package for 13 | multivariate functional principal component analysis 14 | . 15 | URL: https://github.com/ClaraHapp/funData 16 | License: GPL-2 17 | Depends: 18 | methods 19 | Imports: 20 | abind, 21 | fields, 22 | foreach, 23 | graphics, 24 | grDevices, 25 | stats 26 | Suggests: 27 | covr, 28 | fda, 29 | ggplot2 (>= 3.0.0), 30 | gridExtra, 31 | reshape2, 32 | zoo, 33 | testthat (>= 2.0.0) 34 | RoxygenNote: 7.3.1 35 | Encoding: UTF-8 36 | Collate: 37 | 'funDataClass.R' 38 | 'coerce.R' 39 | 'funDataMethods.R' 40 | 'get_set.R' 41 | 'names.R' 42 | 'plotMethods.R' 43 | 'simulation.R' 44 | 'str.R' 45 | 'subset.R' 46 | 'summary.R' 47 | 'zzz.R' 48 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,summary.funData) 4 | S3method(print,summary.irregFunData) 5 | S3method(print,summary.multiFunData) 6 | export("X<-") 7 | export("argvals<-") 8 | export(.intWeights) 9 | export(X) 10 | export(addError) 11 | export(approxNA) 12 | export(argvals) 13 | export(as.data.frame) 14 | export(as.funData) 15 | export(as.irregFunData) 16 | export(as.multiFunData) 17 | export(autolayer.funData) 18 | export(autolayer.irregFunData) 19 | export(autoplot.funData) 20 | export(autoplot.irregFunData) 21 | export(autoplot.multiFunData) 22 | export(dimSupp) 23 | export(eFun) 24 | export(eVal) 25 | export(extractObs) 26 | export(fd2funData) 27 | export(flipFuns) 28 | export(funData) 29 | export(funData2fd) 30 | export(getArgvals) 31 | export(getX) 32 | export(integrate) 33 | export(irregFunData) 34 | export(meanFunction) 35 | export(multiFunData) 36 | export(nObs) 37 | export(nObsPoints) 38 | export(scalarProduct) 39 | export(setArgvals) 40 | export(setX) 41 | export(simFunData) 42 | export(simMultiFunData) 43 | export(sparsify) 44 | export(tensorProduct) 45 | exportMethods("[") 46 | exportMethods("names<-") 47 | exportMethods(ggplot) 48 | exportMethods(names) 49 | exportMethods(norm) 50 | exportMethods(plot) 51 | exportMethods(show) 52 | exportMethods(str) 53 | exportMethods(subset) 54 | exportMethods(summary) 55 | import(methods) 56 | importFrom(abind,abind) 57 | importFrom(foreach,"%do%") 58 | importFrom(grDevices,rainbow) 59 | importFrom(graphics,image) 60 | importFrom(graphics,matplot) 61 | importFrom(graphics,par) 62 | importFrom(graphics,points) 63 | importFrom(stats,rnorm) 64 | importFrom(stats,runif) 65 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # funData 1.3-9 2 | 3 | ## New features 4 | * Fixing documentation for generator and plot functions, as required by CRAN 5 | * Remove broken link to Travis and update codecov link 6 | 7 | 8 | # funData 1.3-8 9 | 10 | ## New features 11 | * Fixing DOI as required by Journal of Statistical Software. 12 | 13 | 14 | # funData 1.3-7 15 | 16 | ## New features 17 | * Fixing URLs as required by CRAN. 18 | 19 | 20 | # funData 1.3-6 21 | 22 | ## New features 23 | * Changing email address. 24 | 25 | # funData 1.3-5 26 | 27 | ## New features 28 | * Add links to vignette. 29 | 30 | # funData 1.3-4 31 | 32 | ## New features 33 | * Function `.intWeights` is not external any more, as used in MFPCA package. 34 | * Update Author/Maintainer last name 35 | 36 | # funData 1.3-3 37 | 38 | ## New features 39 | * Suppress warnings in unit tests with fixed seed caused by changing the default RNG in latest R development version. 40 | 41 | 42 | # funData 1.3-2 43 | 44 | ## New features 45 | * Fixed typo in DESCRIPTION (testthat requires version >= 2.0.0) 46 | 47 | 48 | # funData 1.3-1 49 | 50 | ## New features 51 | * Consequent use of `seq_len(x)` instead of `1:x`. 52 | * Use of type-safe `vapply` instead of `sapply`, where applicable. 53 | * Standard `ggplot` function (package **ggplot**) as default for (deprecated) generic ggplot. 54 | 55 | 56 | # funData 1.3 57 | 58 | ## New features 59 | * New coercion methods `as.data.frame` and `funData2fd` / `fd2funData` (for `fd` objects from **fda** package). 60 | * New functions `argvals` / `argvals<-` / `X` / `X<-` for accessing and setting slot values. The old functions `getArgvals` / `setArgvals` / `getX` / `setX` are deprecated. 61 | * New functions `autoplot` / `autolayer` for ggplot-type plotting (requires **ggplot2**, version 3.0.0). The old `ggplot` function is deprecated. 62 | * Alias functions `subset` and `"["` for `extractObs` to achieve better compatibility with R's standard API. 63 | * `print.summary` is now registered in `NAMESPACE`. 64 | * Minor adjustments in output of `show` and `str` to fit into the standard 80 columns terminal. 65 | * Documentation of `Arith` functions with more examples for standard operators 66 | * Fixed some typos in the documentation. 67 | * DESCRIPTION file now contains link to GitHub repo. 68 | 69 | # funData 1.2 70 | 71 | ## New features 72 | * Basic generics `names`, `names<-` `str` and `summary` for all functional data classes. 73 | * S4 generic `norm` is now based on function `norm` in package base (no masking). 74 | * More argument checking for user-facing functions including unit tests. 75 | * Bug fixed for `meanFunction` and `irregFunData`. 76 | 77 | 78 | # funData 1.1 79 | 80 | ## New features 81 | * `ggplot` methods for all functional data classes. 82 | * Simulation of univariate functional data on higher-dimensional domains. 83 | * Math functions such as `log()` or `abs()` can be applied to all functional data classes. 84 | * Coercion from `funData` to `irregFunData` class via `as.irregFunData` (useful e.g. for plotting). 85 | * Scalar product method for multivariate functional data accepts weight vector. 86 | * Unit test coverage is now close to 100%. 87 | -------------------------------------------------------------------------------- /R/coerce.R: -------------------------------------------------------------------------------- 1 | #' @include funDataClass.R 2 | NULL 3 | 4 | #### Coercion to data.frame #### 5 | 6 | #' Coerce functional data objects to a data.frame 7 | #' 8 | #' Coerce objects of class \code{funData}, \code{multiFunData} and 9 | #' \code{irregFunData} to a data frame. 10 | #' 11 | #' @param x The functional data object that is to be transformed to a 12 | #' \code{data.frame} 13 | #' 14 | #' @return A data frame with columns \code{obs} (gives index/name of 15 | #' observed curve), \code{argvals1, ... argvalsd} with \code{d} the 16 | #' dimension of the support and \code{X} for the observed values. 17 | #' One-dimensional functions have only \code{argvals1}, two-dimensional 18 | #' functions (images) have \code{argvals1} and \code{argvals2}, etc. 19 | #' 20 | #' @seealso \code{\linkS4class{funData}}, 21 | #' \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}}, 22 | #' \code{\link{data.frame}} 23 | #' 24 | #' @name as.data.frame.funData 25 | #' 26 | #' @examples 27 | #' # one-dimensional domain 28 | #' f1 <- funData(argvals = 1:5, X = matrix(1:20, nrow = 4)) 29 | #' head(as.data.frame(f1)) 30 | #' 31 | #' # two-dimensional domain 32 | #' f2 <- funData(argvals = list(1:5, 1:6), X = array(1:120, c(4,5,6))) 33 | #' head(as.data.frame(f2)) 34 | #' 35 | #' # multivariate functional data 36 | #' m1 <- multiFunData(f1, f2) 37 | #' str(as.data.frame(m1)) 38 | #' 39 | #' # irregular functional data 40 | #' i1 <- irregFunData(argvals = list(1:5, 2:4, 3:5), X = list(1:5, 2:4, -(3:1))) 41 | #' head(as.data.frame(i1)) 42 | NULL 43 | 44 | #' @keywords internal 45 | setAs("funData", "data.frame", 46 | def = function(from){ 47 | 48 | d <- dimSupp(from) 49 | 50 | # expand all argument values 51 | allArgvals <- expand.grid(from@argvals, KEEP.OUT.ATTRS = TRUE) 52 | colnames(allArgvals) <- paste("argvals", seq_len(d), sep = "") 53 | row.names(allArgvals) <- NULL 54 | 55 | if(is.null(names(from))) 56 | nm <- as.character(seq_len(nObs(from))) 57 | else 58 | nm <- names(from) 59 | 60 | return(cbind(obs = rep(nm, each = prod(nObsPoints(from))), 61 | allArgvals, 62 | X = as.numeric(aperm(from@X, c(1 + seq_len(d),1))))) 63 | }) 64 | 65 | 66 | #' @rdname as.data.frame.funData 67 | #' @export as.data.frame 68 | setMethod("as.data.frame", signature = "funData", 69 | function(x){as(x, "data.frame")}) 70 | 71 | #' @keywords internal 72 | setAs("multiFunData", "data.frame", 73 | def = function(from){ 74 | return(lapply(from, as.data.frame)) 75 | }) 76 | 77 | #' @rdname as.data.frame.funData 78 | #' @export as.data.frame 79 | setMethod("as.data.frame", signature = "multiFunData", 80 | function(x){as(x, "data.frame")}) 81 | 82 | #' @keywords internal 83 | setAs("irregFunData", "data.frame", 84 | def = function(from){ 85 | 86 | if(is.null(names(from))) 87 | nm <- as.character(seq_len(nObs(from))) 88 | else 89 | nm <- names(from) 90 | 91 | return(data.frame(obs = rep(nm, times = nObsPoints(from)), 92 | argvals = unlist(from@argvals), 93 | X = unlist(from@X))) 94 | }) 95 | 96 | #' @rdname as.data.frame.funData 97 | #' @export as.data.frame 98 | setMethod("as.data.frame", signature = "irregFunData", 99 | function(x){as(x, "data.frame")}) 100 | 101 | 102 | #### Coercion to fd (from fda) #### 103 | 104 | #' Convert a funData object to fd 105 | #' 106 | #' This function converts an object of class \code{\link{funData}} to an 107 | #' object of class \code{\link[fda]{fd}} (from package \pkg{fda}). It 108 | #' heavily builds on the function \code{\link[fda]{Data2fd}} from the 109 | #' \pkg{fda} package. The \code{\link[fda]{fd}} representation assumes a 110 | #' basis representation for the observed functions and therefore 111 | #' implicitly smoothes the data. In \code{funData} objects, the data is 112 | #' saved in 'raw' format. 113 | #' 114 | #' @section Warning: This function works only for funData objects on 115 | #' one-dimensional domains. 116 | #' 117 | #' @param object A \code{funData} object 118 | #' @param ... Other parameters passed to \code{\link[fda]{Data2fd}}. 119 | #' 120 | #' @return An object of class \code{\link[fda]{fd}}. 121 | #' 122 | #' @export 123 | #' 124 | #' @seealso \code{\linkS4class{funData}}, \code{\link[fda]{fd}}, 125 | #' \code{\link[fda]{Data2fd}}, \code{\link{fd2funData}} 126 | #' 127 | #' @examples 128 | #' # Install / load package fda before running the examples 129 | #' library("fda") 130 | #' 131 | #' # from Data2fd help 132 | #' daybasis <- create.fourier.basis(c(0, 365), nbasis=65) 133 | #' # funData object with temperature 134 | #' tempFun <- funData(day.5, t(CanadianWeather$dailyAv[, , "Temperature.C"])) 135 | #' # convert to fd 136 | #' tempfd <- funData2fd(tempFun, daybasis) 137 | #' 138 | #' # plot to compare 139 | #' par(mfrow = c(1,2)) 140 | #' plot(tempFun, main = "funData object (raw data)") 141 | #' plot(tempfd, main = "fd object (smoothed)") 142 | funData2fd <- function(object, ...) 143 | { 144 | if(!(requireNamespace("fda", quietly = TRUE))) 145 | { 146 | warning("Please install the fda package to use the funData2fd function for funData objects.") 147 | return() 148 | } 149 | 150 | if(!inherits(object,"funData")) 151 | stop("Argument is not of class 'funData'.") 152 | 153 | if(dimSupp(object) > 1) 154 | stop("funData2fd is only defined for functions on one-dimensional domains.") 155 | 156 | return(fda::Data2fd(argvals = object@argvals[[1]], y = t(object@X), ...)) 157 | } 158 | 159 | 160 | #' Convert an fd object to funData 161 | #' 162 | #' This function converts an object of class \code{\link[fda]{fd}} (from 163 | #' package \pkg{fda}) to an object of class \code{\link{funData}}. It 164 | #' heavily builds on the function \code{\link[fda]{eval.fd}} from the 165 | #' \pkg{fda} package. The \code{\link[fda]{fd}} representation assumes a 166 | #' basis representation for the observed functions and therefore 167 | #' implicitly smoothes the data. In \code{funData} objects, the data is 168 | #' saved in 'raw' format. 169 | #' 170 | #' @section Warning: Time names in \code{fdobj$fdnames$time} are not 171 | #' preserved. 172 | #' 173 | #' @param fdobj An \code{fd} object 174 | #' @param argvals A vector or a list of length one, containing a vector 175 | #' with argument values at which the functions in \code{fdobj} should be 176 | #' evaluated. 177 | #' @param ... Other parameters passed to \code{\link[fda]{eval.fd}}. 178 | #' 179 | #' @return An object of class \code{\link{funData}}. 180 | #' 181 | #' @export 182 | #' 183 | #' @seealso \code{\linkS4class{funData}}, \code{\link[fda]{fd}}, 184 | #' \code{\link[fda]{eval.fd}} 185 | #' 186 | #' @examples 187 | #' # Install / load package fda before running the examples 188 | #' library("fda") 189 | #' 190 | #' # from Data2fd help 191 | #' daybasis <- create.fourier.basis(c(0, 365), nbasis=65) 192 | #' # fd object of daily temperatures 193 | #' tempfd <- Data2fd(argvals = day.5, y = CanadianWeather$dailyAv[,,"Temperature.C"], daybasis) 194 | #' # convert to funData 195 | #' tempFun <- fd2funData(tempfd, argvals = day.5) 196 | #' 197 | #' # plot to compare 198 | #' par(mfrow = c(1,2)) 199 | #' plot(tempfd, main = "fd object") 200 | #' plot(tempFun, main = "funData object") 201 | fd2funData <- function(fdobj, argvals, ...) 202 | { 203 | if(!(requireNamespace("fda", quietly = TRUE))) 204 | { 205 | warning("Please install the fda package to use the fd2funData function for funData objects.") 206 | return() 207 | } 208 | 209 | if(!is.numeric(argvals)) 210 | { 211 | if(is.list(argvals) & length(argvals) == 1) 212 | argvals = unlist(argvals) 213 | else 214 | stop("Parameter 'argvals' must be either a vector of argument values or a list containing such a vector.") 215 | } 216 | 217 | # eval.fd checks validity of argvals 218 | return(funData(argvals = argvals, X = t(fda::eval.fd(argvals, fdobj, ...)))) 219 | } -------------------------------------------------------------------------------- /R/names.R: -------------------------------------------------------------------------------- 1 | ### Names for functional data objects 2 | ### no particular method needed for multiFunData! 3 | 4 | #' @describeIn funData Get the names of the \code{funData} object. 5 | #' 6 | #' @param x The \code{funData} object. 7 | #' 8 | #' @docType methods 9 | #' 10 | #' @exportMethod names 11 | setMethod("names", signature = "funData", 12 | function(x) 13 | { 14 | return(dimnames(x@X)[[1]] ) 15 | }) 16 | 17 | 18 | #' @describeIn funData Set the names of the \code{funData} object. 19 | #' 20 | #' @inheritParams names 21 | #' @param value The names to be given to the \code{funData} curves. 22 | #' 23 | #' @docType methods 24 | #' 25 | #' @exportMethod names<- 26 | setMethod("names<-", signature = "funData", 27 | function(x, value) 28 | { 29 | if(!is.null(value) & length(value) != nObs(x)) 30 | stop("Names must have the same length as funData object.") 31 | 32 | dimnames(x@X)[[1]] <- value 33 | 34 | return(x) 35 | }) 36 | 37 | 38 | #' @describeIn multiFunData Get the names of the \code{multiFunData} object. 39 | #' 40 | #' @param x The \code{multiFunData} object. 41 | #' 42 | #' @docType methods 43 | #' 44 | #' @exportMethod names 45 | setMethod("names", signature = "multiFunData", 46 | function(x) 47 | { 48 | return(names(S3Part(x, strictS3 = TRUE))) 49 | }) 50 | 51 | 52 | #' @describeIn multiFunData Set the names of the \code{multiFunData} object. 53 | #' 54 | #' @inheritParams names 55 | #' @param value The names to be given to the \code{multiFunData} curves. 56 | #' 57 | #' @docType methods 58 | #' 59 | #' @exportMethod names<- 60 | setMethod("names<-", signature = "multiFunData", 61 | function(x, value) 62 | { 63 | if(!is.null(value) & length(value) != length(x)) 64 | stop("Names must have the same length as multiFunData object.") 65 | 66 | names(S3Part(x, strictS3 = TRUE)) <- value 67 | 68 | return(x) 69 | }) 70 | 71 | 72 | #' @describeIn irregFunData Get the names of the \code{irregFunData} object. 73 | #' 74 | #' @param x The \code{irregFunData} object. 75 | #' 76 | #' @docType methods 77 | #' 78 | #' @exportMethod names 79 | setMethod("names", signature = "irregFunData", 80 | function(x) 81 | { 82 | return(names(x@argvals)) 83 | }) 84 | 85 | 86 | #' @describeIn irregFunData Set the names of the \code{irregFunData} object. 87 | #' 88 | #' @inheritParams names 89 | #' @param value The names to be given to the \code{irregFunData} curves. 90 | #' 91 | #' @docType methods 92 | #' 93 | #' @exportMethod names<- 94 | setMethod("names<-", signature = "irregFunData", 95 | function(x, value) 96 | { 97 | if(!is.null(value) & length(value) != nObs(x)) 98 | stop("Names must have the same length as irregFunData object.") 99 | 100 | names(x@argvals) <- value 101 | names(x@X) <- value 102 | 103 | return(x) 104 | }) -------------------------------------------------------------------------------- /R/str.R: -------------------------------------------------------------------------------- 1 | ### Str methods for functional data objects 2 | 3 | 4 | #' @describeIn funData A \code{str} method for \code{funData} objects, giving a compact overview of the structure. 5 | #' 6 | #' @docType methods 7 | #' 8 | #' @exportMethod str 9 | setMethod("str", signature = "funData", 10 | function(object, ...) 11 | { 12 | dims <- dimSupp(object) 13 | 14 | cat("Functional data:\n", nObs(object), " observations of ", 15 | dims, "-dimensional support with ", 16 | paste(nObsPoints(object), collapse = " x "), " sampling points.\n", sep = "") 17 | 18 | cat("@argvals:\n") 19 | for(i in seq_len(dims)) 20 | { 21 | cat(" [[",i, "]]: ", sep ="") 22 | str(object@argvals[[i]], ...) 23 | } 24 | 25 | cat("\n@X:\n") 26 | str(object@X,...) 27 | 28 | invisible() 29 | }) 30 | 31 | #' @describeIn multiFunData A \code{str} method for \code{multiFunData} objects, giving a compact overview of the structure. 32 | #' 33 | #' @docType methods 34 | #' 35 | #' @exportMethod str 36 | setMethod("str", signature = "multiFunData", 37 | function(object, ...) 38 | { 39 | cat("MultiFunData with", length(object), "elements:\n---\n") 40 | 41 | elNames <- { 42 | if(is.null(names(object))) 43 | paste("Element", seq_len(length(object))) 44 | else 45 | names(object) 46 | } 47 | 48 | for(i in seq_len(length(object))) 49 | { 50 | cat(elNames[i], ": ") 51 | str(object[[i]]) 52 | cat("--- \n") 53 | } 54 | 55 | invisible() 56 | }) 57 | 58 | 59 | #' @describeIn irregFunData A \code{str} method for \code{irregFunData} objects, giving a compact overview of the structure. 60 | #' 61 | #' @docType methods 62 | #' 63 | #' @exportMethod str 64 | setMethod("str", signature = "irregFunData", 65 | function(object, ...) 66 | { 67 | dims <- dimSupp(object) 68 | 69 | # by default print only the first 10 entries 70 | dots <- list(...) 71 | if(is.null(dots$list.len)) 72 | dots$list.len <- 10 73 | 74 | cat("IrregFunData:\n", nObs(object), " observations of ", 75 | dims, "-dimensional support on " , length(unique(unlist(object@argvals))), " different argvals (", 76 | paste(range(nObsPoints(object)), collapse = " - "), " per curve).\n\n", sep = "") 77 | 78 | cat("@argvals: ") 79 | do.call("str", c(list(object = object@argvals), dots)) 80 | 81 | cat("\n@X: ") 82 | do.call("str", c(list(object = object@X), dots)) 83 | 84 | invisible() 85 | }) -------------------------------------------------------------------------------- /R/subset.R: -------------------------------------------------------------------------------- 1 | ### Subsetting functional data objects 2 | 3 | 4 | #### extractObs #### 5 | 6 | #' Extract observations of functional data 7 | #' 8 | #' This function extracts one or more observations and/or observations on 9 | #' a part of the domain from a \code{funData}, \code{irregFunData} or 10 | #' \code{multiFunData} object. 11 | #' 12 | #' In case of an \code{irregFunData} object, some functions may not have 13 | #' observation points in the given part of the domain. In this case, the 14 | #' functions are removed from the extracted dataset and a warning is 15 | #' thrown. 16 | #' 17 | #' If only observations are to be extracted, the usual notation 18 | #' \code{object[1:3]} is equivalent to \code{extractObs(object, obs = 19 | #' 1:3)}. This works only if the domain remains unchanged. 20 | #' 21 | #' @section Warning: The function is currently implemented only for 22 | #' functional data with up to three-dimensional domains. 23 | #' 24 | #' @section Alias: The function \code{subset} is an alias for 25 | #' \code{extractObs}. 26 | #' 27 | #' @param object An object of class \code{funData}, \code{irregFunData} or 28 | #' \code{multiFunData}. 29 | #' @param obs A numeric vector, giving the indices of the observations to 30 | #' extract (default: all observations). 31 | #' @param argvals The part of the domain to be extracted (default: the 32 | #' whole domain \code{object}@@\code{argvals}). Must be a list or a 33 | #' numeric vector (only for one-dimensional domains, see also the 34 | #' definition of \code{\linkS4class{funData}}, 35 | #' \code{\linkS4class{multiFunData}}). 36 | #' 37 | #' @return An object of class \code{funData}, \code{irregFunData} or 38 | #' \code{multiFunData} containing the desired observations. 39 | #' 40 | #' @seealso \code{\linkS4class{funData}}, 41 | #' \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}} 42 | #' 43 | #' @export extractObs 44 | #' 45 | #' @examples 46 | #' # Univariate - one-dimensional domain 47 | #' object1 <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 48 | #' extractObs(object1, obs = 1) 49 | #' extractObs(object1, argvals = 1:3) 50 | #' extractObs(object1, argvals = list(1:3)) # the same as the statement before 51 | #' # alias 52 | #' subset(object1, argvals = 1:3) 53 | #' 54 | #' # Univariate - two-dimensional domains 55 | #' object2 <- funData(argvals = list(1:5, 1:6), X = array(1:60, dim = c(2, 5, 6))) 56 | #' extractObs(object2, obs = 1) 57 | #' extractObs(object2, argvals = list(1:3, c(2,4,6))) # argvals must be supplied as list 58 | #' 59 | #' # Univariate - irregular 60 | #' irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 61 | #' extractObs(irregObject, obs = 2) 62 | #' extractObs(irregObject, argvals = 1:3) 63 | #' extractObs(irregObject, argvals = c(1,5)) # throws a warning, as second function has no observations 64 | #' 65 | #' # Multivariate 66 | #' multiObject <- multiFunData(object1, object2) 67 | #' extractObs(multiObject, obs = 2) 68 | #' multiObject[2] # shorthand 69 | #' extractObs(multiObject, argvals = list(1:3, list(1:3, c(2,4,6)))) 70 | #' 71 | #' 72 | #' ### Shorthand via "[]" 73 | #' object1[1] 74 | #' object1[argvals = 1:3] 75 | #' object2[1] 76 | #' object2[argvals = list(1:3, c(2,4,6))] 77 | #' irregObject[2] 78 | #' irregObject[argvals = 1:3] 79 | setGeneric("extractObs", function(object, obs = seq_len(nObs(object)), argvals = funData::argvals(object)) { 80 | standardGeneric("extractObs") 81 | }) 82 | 83 | #' extractObs for funData objects 84 | #' 85 | #' @keywords internal 86 | setMethod("extractObs", signature = signature("funData", "ANY", "ANY"), 87 | function(object, obs, argvals){ 88 | 89 | if(dimSupp(object) > 3) 90 | stop("extracting observations is not implemented yet for functional data of dimension > 3") 91 | 92 | if(!is.numeric(obs)) 93 | stop("Supply observations as numeric vector") 94 | 95 | if(!all((seq_len(nObs(object)))[obs] %in% seq_len(nObs(object)))) 96 | stop("Trying to extract observations that do not exist!") 97 | 98 | if(!is.list(argvals)) 99 | { 100 | if(dimSupp(object) == 1 & is.numeric(argvals)) 101 | argvals = list(argvals) 102 | else 103 | stop("Supply argvals for extracted observations either as list or as numeric vector (only if support is one-dimensional)") 104 | } 105 | 106 | if(!all(unlist(mapply(function(x,y){x%in%y}, argvals,object@argvals)))) 107 | stop("Trying to extract x-values that do not exist!") 108 | 109 | if(dimSupp(object) == 1) 110 | return(funData(argvals, object@X[obs, 111 | object@argvals[[1]] %in% argvals[[1]], drop = FALSE])) 112 | 113 | if(dimSupp(object) == 2) 114 | return(funData(argvals, object@X[obs, 115 | object@argvals[[1]] %in% argvals[[1]], 116 | object@argvals[[2]] %in% argvals[[2]], drop = FALSE])) 117 | 118 | if(dimSupp(object) == 3) 119 | return(funData(argvals, object@X[obs, 120 | object@argvals[[1]] %in% argvals[[1]], 121 | object@argvals[[2]] %in% argvals[[2]], 122 | object@argvals[[3]] %in% argvals[[3]], drop = FALSE])) 123 | }) 124 | 125 | #' extractObs for multiFunData objects 126 | #' 127 | #' @keywords internal 128 | setMethod("extractObs", signature = signature("multiFunData", "ANY", "ANY"), def = function(object, obs, argvals){ 129 | if(!missing(argvals) & !is.list(argvals)) 130 | stop("extractObs for multiFunData: argvals must be supplied as list (or missing).") 131 | if(is.list(obs)) 132 | res <- multiFunData(mapply(extractObs, object = object, obs = obs, argvals = argvals)) 133 | else 134 | res <- multiFunData(mapply(extractObs, object = object, argvals = argvals, MoreArgs = list(obs = obs))) 135 | }) 136 | 137 | #' extractObs for irregular functional data 138 | #' 139 | #' @keywords internal 140 | setMethod("extractObs", signature = signature("irregFunData", "ANY", "ANY"), 141 | function(object, obs, argvals){ 142 | # if(dimSupp(object) > 1) 143 | # stop("Extracting observations is not implemented yet for functional data of dimension > 1") 144 | 145 | if(!is.numeric(obs)) 146 | stop("Supply observations as numeric vector") 147 | 148 | if(!all((seq_len(nObs(object)))[obs] %in% seq_len(nObs(object)))) 149 | stop("Trying to extract observations that do not exist!") 150 | 151 | if(!is.list(argvals)) 152 | { 153 | if(is.numeric(argvals)) 154 | argvals = list(argvals) 155 | else 156 | stop("Supply argvals for extracted observations either as list or as numeric vector") 157 | } 158 | 159 | if(!any(unlist(argvals) %in% unlist(object@argvals[obs]))) 160 | stop("Trying to extract x-values that do not exist!") 161 | 162 | extractargvals <- extractX <- vector("list", length(obs)) 163 | omit <- NULL 164 | 165 | for(i in seq_len(length(obs))) 166 | { 167 | ind <- which(object@argvals[[obs[i]]] %in% unlist(argvals)) 168 | 169 | if(length(ind) == 0) 170 | { 171 | warning("Some functions were not observed on the given argvals and therefore removed.") 172 | 173 | omit <- c(omit, i) 174 | } 175 | 176 | extractargvals[[i]] <- object@argvals[[obs[i]]][ind] 177 | extractX[[i]] <- object@X[[obs[i]]][ind] 178 | } 179 | 180 | # omit empty observations 181 | extractargvals[omit] <- NULL 182 | extractX[omit] <- NULL 183 | 184 | return(irregFunData(extractargvals, extractX)) 185 | }) 186 | 187 | #### Alias: subset #### 188 | #' @rdname extractObs 189 | #' 190 | #' @param x An object of class \code{funData}, \code{irregFunData} or 191 | #' \code{multiFunData} (for \code{subset}). 192 | #' @exportMethod subset 193 | setMethod("subset", c("funData"), 194 | function(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x)) 195 | { 196 | extractObs(x, obs = obs, argvals = argvals) 197 | }) 198 | 199 | #' @rdname extractObs 200 | #' @exportMethod subset 201 | setMethod("subset", c("multiFunData"), 202 | function(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x)) 203 | { 204 | extractObs(x, obs = obs, argvals = argvals) 205 | }) 206 | 207 | #' @rdname extractObs 208 | #' @exportMethod subset 209 | setMethod("subset", c("irregFunData"), 210 | function(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x)) 211 | { 212 | extractObs(x, obs = obs, argvals = argvals) 213 | }) 214 | 215 | #### Alternative via [ (only observations) #### 216 | 217 | #' @describeIn extractObs 218 | #' 219 | #' @param i A numeric vector, giving the indices of the observations to 220 | #' extract when using \code{x[i]}. Defaults to all observations. 221 | #' @param ... Used to pass further arguments to \code{extractObs}. Here 222 | #' only usable for \code{argvals}. 223 | #' @param j,drop not used 224 | #' 225 | #' @exportMethod [ 226 | setMethod("[", c(x = "funData", i = "ANY", j = "missing", drop = "missing"), 227 | function(x, i, j, ..., drop) 228 | { 229 | if(missing(i)) # default value not found... 230 | i = seq_len(nObs(x)) 231 | 232 | extractObs(x, obs = i, ...) 233 | }) 234 | 235 | #' @rdname extractObs 236 | #' @exportMethod [ 237 | setMethod("[", c("multiFunData", i = "ANY", j = "missing", drop = "missing"), 238 | function(x, i, j, ..., drop) 239 | { 240 | if(missing(i)) # default value not found... 241 | i = seq_len(nObs(x)) 242 | 243 | extractObs(x, obs = i, ...) 244 | }) 245 | 246 | #' @rdname extractObs 247 | #' @exportMethod [ 248 | setMethod("[", c("irregFunData", i = "ANY", j = "missing", drop = "missing"), 249 | function(x, i = seq_len(nObs(x)), j, ..., drop) 250 | { 251 | if(missing(i)) # default value not found... 252 | i = seq_len(nObs(x)) 253 | 254 | extractObs(x, obs = i, ...) 255 | }) -------------------------------------------------------------------------------- /R/summary.R: -------------------------------------------------------------------------------- 1 | ### Summary methods for functional data classes ### 2 | 3 | #' @describeIn funData A \code{summary} method for \code{funData} objects. 4 | #' 5 | #' @param ... Other parameters passed to \code{summary}. 6 | #' 7 | #' @docType methods 8 | #' 9 | #' @exportMethod summary 10 | setMethod("summary", signature = "funData", 11 | function(object, ...) 12 | { 13 | argvalsSummary <- do.call("rbind", lapply(object@argvals, summary, ...)) 14 | rownames(argvalsSummary) <- paste("Dim.", seq_len(dimSupp(object)), ":") 15 | 16 | XSummary <- apply(object@X, 1, function(x){summary(as.numeric(x))}) 17 | colnames(XSummary) <- { 18 | if(is.null(names(object))) 19 | paste("Obs", seq_len(nObs(object))) 20 | else 21 | names(object) 22 | } 23 | 24 | res <- list(argvals = argvalsSummary, X = XSummary) 25 | class(res) <- "summary.funData" 26 | 27 | return(res) 28 | }) 29 | 30 | 31 | #' @describeIn multiFunData A \code{summary} method for \code{multiFunData} objects. 32 | #' 33 | #' @param object A \code{multiFunData} object. 34 | #' 35 | #' @docType methods 36 | #' 37 | #' @exportMethod summary 38 | setMethod("summary", signature = "multiFunData", 39 | function(object, ...) 40 | { 41 | res <- lapply(object, summary, ...) 42 | class(res) <- "summary.multiFunData" 43 | 44 | return(res) 45 | }) 46 | 47 | 48 | #' @describeIn irregFunData A \code{summary} method for \code{irregFunData} objects. 49 | #' 50 | #' @param ... Other parameters passed to \code{summary}. 51 | #' 52 | #' @docType methods 53 | #' 54 | #' @exportMethod summary 55 | setMethod("summary", signature = "irregFunData", 56 | function(object, ...) 57 | { 58 | obsNames <- { 59 | if(is.null(names(object))) 60 | paste("Obs", seq_len(nObs(object))) 61 | else 62 | names(object) 63 | } 64 | 65 | argvalsSummary <- do.call("cbind", lapply(object@argvals, summary)) 66 | colnames(argvalsSummary) <- obsNames 67 | 68 | XSummary <- do.call("cbind", lapply(object@X, summary)) 69 | colnames(XSummary) <- obsNames 70 | 71 | res <- list(argvals = argvalsSummary, X = XSummary) 72 | class(res) <- c("summary.irregFunData") 73 | 74 | return(res) 75 | }) 76 | 77 | 78 | #' @keywords internal 79 | #' 80 | #' @export 81 | print.summary.funData <- function(x, ...) 82 | { 83 | if(!inherits(x, "summary.funData")) 84 | stop("Argument is not of class 'summary.funData'.") 85 | 86 | cat("Argument values (@argvals):\n") 87 | print(x$argvals) 88 | 89 | cat("\nObserved functions (@X):\n") 90 | print(x$X) 91 | 92 | cat("\n") 93 | invisible(x) 94 | } 95 | 96 | 97 | #' @keywords internal 98 | #' 99 | #' @export 100 | print.summary.multiFunData <- function(x, ...) 101 | { 102 | if(!inherits(x, "summary.multiFunData")) 103 | stop("Argument is not of class 'summary.multiFunData'.") 104 | 105 | sapply(seq_len(length(x)), function(i){ 106 | cat("--- Element", i, " ---\n") 107 | print.summary.funData(x[[i]])}) 108 | 109 | invisible(x) 110 | } 111 | 112 | 113 | #' @keywords internal 114 | #' 115 | #' @export 116 | print.summary.irregFunData <- function(x, ...) 117 | { 118 | if(!inherits(x, "summary.irregFunData")) 119 | stop("Argument is not of class 'summary.irregFunData'.") 120 | 121 | cat("Argument values (@argvals):\n") 122 | print(x$argvals) 123 | 124 | cat("\nObserved functions (@X):\n") 125 | print(x$X) 126 | 127 | cat("\n") 128 | invisible(x) 129 | } -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | ### Register ggplot stuff conditionally (from zoo/zzz.R) ### 2 | 3 | register_s3_method <- function(pkg, generic, class, fun = NULL) { 4 | stopifnot(is.character(pkg), length(pkg) == 1L) 5 | stopifnot(is.character(generic), length(generic) == 1L) 6 | stopifnot(is.character(class), length(class) == 1L) 7 | 8 | if (is.null(fun)) { 9 | fun <- get(paste0(generic, ".", class), envir = parent.frame()) 10 | } else { 11 | stopifnot(is.function(fun)) 12 | } 13 | 14 | if (isNamespaceLoaded(pkg)) { 15 | registerS3method(generic, class, fun, envir = asNamespace(pkg)) 16 | } 17 | 18 | # Always register hook in case package is later unloaded & reloaded 19 | setHook( 20 | packageEvent(pkg, "onLoad"), 21 | function(...) { 22 | registerS3method(generic, class, fun, envir = asNamespace(pkg)) 23 | } 24 | ) 25 | } 26 | 27 | .onLoad <- function(libname, pkgname) { 28 | register_s3_method("ggplot2", "autoplot", "funData") 29 | register_s3_method("ggplot2", "autolayer", "funData") 30 | register_s3_method("ggplot2", "autoplot", "multiFunData") 31 | register_s3_method("ggplot2", "autoplot", "irregFunData") 32 | register_s3_method("ggplot2", "autolayer", "irregFunData") 33 | invisible() 34 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # funData 2 | 3 | [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/ClaraHapp/funData?branch=master&svg=true)](https://ci.appveyor.com/project/ClaraHapp/funData) 4 | [![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/funData)](https://CRAN.R-project.org/package=funData ) 5 | [![Coverage Status](https://img.shields.io/codecov/c/github/ClaraHapp/funData/master.svg)](https://app.codecov.io/github/ClaraHapp/funData?branch=master) 6 | 7 | 8 | 9 | `funData` is an `R`-package that allows users to easily handle functional data. The data is stored in an object-oriented manner using S4 classes and methods. 10 | 11 | ## Highlights ## 12 | 13 | `funData` provides a unified framework for different types of functional data: 14 | 15 | * Univariate and multivariate data 16 | * Regularly and irregularly sampled data 17 | * Data with one-, two- (images) and even higher-dimensional domains 18 | 19 | Important functionalities include: 20 | 21 | * Displaying, Plotting, including an interface to [`ggplot2`](https://CRAN.R-project.org/package=ggplot2) 22 | * Subsetting (samples, domain) 23 | * Basic arithmetics and averaging 24 | * Integration over the domain 25 | * A fully integrated simulation toolbox 26 | 27 | 28 | ## Installation ## 29 | 30 | The `funData` package is available on [`CRAN`](https://CRAN.R-project.org/package=funData). 31 | To install the latest version directly from Github, please use `devtools::install_github("ClaraHapp/funData")` (install [`devtools`](https://github.com/r-lib/devtools) before). 32 | 33 | ## Dependencies ## 34 | 35 | The `funData` package depends on the `R`-packages [`fields`](https://CRAN.R-project.org/package=fields), [`foreach`](https://CRAN.R-project.org/package=foreach), [`abind`](https://CRAN.R-project.org/package=abind) and `methods`. 36 | 37 | ## References ## 38 | 39 | The functionalities of the `funData` package and its interplay with the [`MFPCA`](https://CRAN.R-project.org/package=MFPCA) package for multivariate functional principal component analysis are described in: 40 | 41 | C. Happ-Kurz (2020): [Object-Oriented Software for Functional Data.](https://doi.org/10.18637/jss.v093.i05) *Journal of 42 | Statistical Software*, 93(5): 1-38 . 43 | 44 | ## Bug reports ## 45 | 46 | Please use [GitHub issues](https://github.com/ClaraHapp/funData/issues) for reporting bugs or issues. 47 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | cache: 14 | - C:\RLibrary 15 | 16 | # Adapt as necessary starting from here 17 | 18 | build_script: 19 | - travis-tool.sh install_deps 20 | 21 | test_script: 22 | - travis-tool.sh run_tests 23 | 24 | on_failure: 25 | - 7z a failure.zip *.Rcheck\* 26 | - appveyor PushArtifact failure.zip 27 | 28 | artifacts: 29 | - path: '*.Rcheck\**\*.log' 30 | name: Logs 31 | 32 | - path: '*.Rcheck\**\*.out' 33 | name: Logs 34 | 35 | - path: '*.Rcheck\**\*.fail' 36 | name: Logs 37 | 38 | - path: '*.Rcheck\**\*.Rout' 39 | name: Logs 40 | 41 | - path: '\*_*.tar.gz' 42 | name: Bits 43 | 44 | - path: '\*_*.zip' 45 | name: Bits 46 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry(bibtype = "Article", 2 | title = "Object-Oriented Software for Functional Data", 3 | author = person(given = "Clara", 4 | family = "Happ-Kurz", 5 | email = "clara.happ@stat.uni-muenchen.de"), 6 | journal = "Journal of Statistical Software", 7 | year = "2020", 8 | volume = "93", 9 | number = "5", 10 | pages = "1--38", 11 | doi = "10.18637/jss.v093.i05", 12 | 13 | header = "To cite funData in publications use:" 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /man/Arith.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{Arith.funData} 4 | \alias{Arith.funData} 5 | \alias{Arith,funData,funData-method} 6 | \alias{Arith,funData,numeric-method} 7 | \alias{Arith,numeric,funData-method} 8 | \alias{Arith,multiFunData,multiFunData-method} 9 | \alias{Arith,multiFunData,numeric-method} 10 | \alias{Arith,numeric,multiFunData-method} 11 | \alias{Arith,irregFunData,numeric-method} 12 | \alias{Arith,numeric,irregFunData-method} 13 | \alias{Arith,irregFunData,irregFunData-method} 14 | \alias{Arith,irregFunData,funData-method} 15 | \alias{Arith,funData,irregFunData-method} 16 | \title{Arithmetics for functional data objects} 17 | \usage{ 18 | \S4method{Arith}{funData,funData}(e1, e2) 19 | 20 | \S4method{Arith}{funData,numeric}(e1, e2) 21 | 22 | \S4method{Arith}{numeric,funData}(e1, e2) 23 | 24 | \S4method{Arith}{multiFunData,multiFunData}(e1, e2) 25 | 26 | \S4method{Arith}{multiFunData,numeric}(e1, e2) 27 | 28 | \S4method{Arith}{numeric,multiFunData}(e1, e2) 29 | 30 | \S4method{Arith}{irregFunData,numeric}(e1, e2) 31 | 32 | \S4method{Arith}{numeric,irregFunData}(e1, e2) 33 | 34 | \S4method{Arith}{irregFunData,irregFunData}(e1, e2) 35 | 36 | \S4method{Arith}{irregFunData,funData}(e1, e2) 37 | 38 | \S4method{Arith}{funData,irregFunData}(e1, e2) 39 | } 40 | \arguments{ 41 | \item{e1, e2}{Objects of class \code{funData}, \code{irregFunData}, 42 | \code{multiFunData} or \code{numeric}. If two functional data objects are 43 | used, they must be of the same class, have the same domain and the same 44 | number of observations. For exceptions, see Details.} 45 | } 46 | \value{ 47 | An object of the same functional data class as \code{e1} or 48 | \code{e2}, respectively. 49 | } 50 | \description{ 51 | These functions allow basic arithmetics (such as `+`, `-`, `*`, `sqrt`) for 52 | functional data and numerics based on \code{\link[methods]{Arith}}. The 53 | operations are made pointwise for each observation. See examples below. 54 | } 55 | \details{ 56 | If two objects of a functional data class (\code{funData}, 57 | \code{irregFunData} or \code{multiFunData}) are used, they normally must be 58 | of the same class, have the same domain and the same number of observations. 59 | Exceptions are accepted if \itemize{\item one object has only one 60 | observation. In this case, the arithmetic operations (`+`, `-`, `*`, ...) are 61 | done pairwise for this single function and all functions of the other object. 62 | A typical example would be when subtracting the mean function from all 63 | observations in a \code{funData} object. This single function must be defined 64 | on the same domain as the other functions (or, in case of 65 | \code{irregFunData}, on the union of all observation grids). \item one of the 66 | two objects is of class \code{irregFunData}. Then, the other object can be of 67 | class \code{funData}, too, if it is defined on the union of all observation 68 | grids. The result is an \code{irregFunData} object which is defined on the 69 | same observation grid as the original \code{irregFunData} object.} 70 | } 71 | \section{Warning}{ 72 | Note that not all combinations of operations and classes 73 | make sense, e.g. \code{e1 ^ e2} is sensible if \code{e1} is of class 74 | \code{funData}, \code{irregFunData} or \code{multiFunData} and \code{e2} is 75 | numeric. The reverse is not true. 76 | } 77 | 78 | \examples{ 79 | oldpar <- par(no.readonly = TRUE) 80 | par(mfrow = c(3,2), mar = rep(2.1,4)) 81 | 82 | argvals <- seq(0, 2*pi, 0.01) 83 | object1 <- funData(argvals, outer(seq(0.75, 1.25, by = 0.05), sin(argvals))) 84 | object2 <- funData(argvals, outer(seq(0.75, 1.25, by = 0.05), cos(argvals))) 85 | 86 | plot(object1, main = "Object1") 87 | plot(object2, main = "Object2") 88 | 89 | # Only functional data objects 90 | plot(object1 + object2, main = "Sum") 91 | plot(object1 - object2, main = "Difference") 92 | 93 | # Mixed 94 | plot(4 * object1 + 5, main = "4 * Object1 + 5") # Note y-axis! 95 | plot(object1^2 + object2^2, main = "Pythagoras") 96 | 97 | ### Irregular 98 | ind <- replicate(11, sort(sample(1:length(argvals), sample(5:10, 1)))) 99 | i1 <- irregFunData( 100 | argvals = lapply(1:11, function(i, ind, x){x[ind[[i]]]}, ind = ind, x = object1@argvals[[1]]), 101 | X = lapply(1:11, function(i, ind, y){y[i, ind[[i]]]}, ind = ind, y = object1@X)) 102 | i2 <- irregFunData( 103 | argvals = lapply(1:11, function(i, ind, x){x[ind[[i]]]}, ind = ind, x = object2@argvals[[1]]), 104 | X = lapply(1:11, function(i, ind, y){y[i, ind[[i]]]}, ind = ind, y = object2@X)) 105 | 106 | plot(i1, main = "Object 1 (irregular)") 107 | plot(i2, main = "Object 2 (irregular)") 108 | 109 | # Irregular and regular functional data objects 110 | plot(i1 + i2, main = "Sum") 111 | plot(i1 - object2, main = "Difference") 112 | 113 | # Mixed 114 | plot(4 * i1 + 5, main = "4 * i1 + 5") # Note y-axis! 115 | plot(i1^2 + i2^2, main = "Pythagoras") 116 | par(oldpar) 117 | } 118 | \seealso{ 119 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, 120 | \code{\linkS4class{multiFunData}}, \link[methods]{Arith} 121 | } 122 | -------------------------------------------------------------------------------- /man/Math.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{Math.funData} 4 | \alias{Math.funData} 5 | \alias{Math,funData-method} 6 | \alias{Math,multiFunData-method} 7 | \alias{Math,irregFunData-method} 8 | \title{Mathematical operations for functional data objects} 9 | \usage{ 10 | \S4method{Math}{funData}(x) 11 | 12 | \S4method{Math}{multiFunData}(x) 13 | 14 | \S4method{Math}{irregFunData}(x) 15 | } 16 | \arguments{ 17 | \item{x}{An object of class \code{funData}, \code{irregFunData} or 18 | \code{multiFunData}.} 19 | } 20 | \value{ 21 | An object of the same functional data class as \code{x}. 22 | } 23 | \description{ 24 | These functions allow to apply mathematical operations (such as \eqn{exp(), 25 | log(), sin(), cos()} or \eqn{abs()} to functional data objects based on 26 | \code{\link[methods]{Math}}. The operations are made pointwise for each 27 | observation. 28 | } 29 | \examples{ 30 | oldpar <- par(no.readonly = TRUE) 31 | par(mfrow = c(1,2)) 32 | 33 | # simulate a funData object on 0..1 with 10 observations 34 | argvals <- seq(0, 1, 0.01) 35 | f <- simFunData(argvals = argvals, N = 10, 36 | M = 5, eFunType = "Fourier", eValType = "linear")$simData 37 | 38 | ### FunData 39 | plot(f, main = "Original data") 40 | plot(abs(f), main = "Absolute values") 41 | 42 | ### Irregular 43 | # create an irrgFunData object by sparsifying f 44 | i <- as.irregFunData(sparsify(f, minObs = 5, maxObs = 10)) 45 | 46 | plot(i, main = "Sparse data") 47 | plot(cumsum(i), main = "'cumsum' of sparse data") 48 | 49 | ### Multivariate 50 | m <- multiFunData(f, -1*f) 51 | plot(m, main = "Multivariate Data") 52 | plot(exp(m), main = "Exponential") 53 | 54 | par(oldpar) 55 | } 56 | \seealso{ 57 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, 58 | \code{\linkS4class{multiFunData}}, \link[methods]{Math} 59 | } 60 | -------------------------------------------------------------------------------- /man/X-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{X,funData-method} 4 | \alias{X,funData-method} 5 | \title{Get X slot for funData objects} 6 | \usage{ 7 | \S4method{X}{funData}(object) 8 | } 9 | \description{ 10 | Get X slot for funData objects 11 | } 12 | \seealso{ 13 | \code{\link{X}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/X-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{X,irregFunData-method} 4 | \alias{X,irregFunData-method} 5 | \title{Get X slot for irregular functional data objects} 6 | \usage{ 7 | \S4method{X}{irregFunData}(object) 8 | } 9 | \description{ 10 | Get X slot for irregular functional data objects 11 | } 12 | \seealso{ 13 | \code{\link{X}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/X-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{X,multiFunData-method} 4 | \alias{X,multiFunData-method} 5 | \title{Get X slot for multiFunData objects} 6 | \usage{ 7 | \S4method{X}{multiFunData}(object) 8 | } 9 | \description{ 10 | Get X slot for multiFunData objects 11 | } 12 | \seealso{ 13 | \code{\link{X}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/X-set-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{X<-,funData-method} 4 | \alias{X<-,funData-method} 5 | \title{Set X slot for funData objects} 6 | \usage{ 7 | \S4method{X}{funData}(object) <- value 8 | } 9 | \description{ 10 | Set X slot for funData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/X-set-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{X<-,irregFunData-method} 4 | \alias{X<-,irregFunData-method} 5 | \title{Set X slot for irregular functional data objects} 6 | \usage{ 7 | \S4method{X}{irregFunData}(object) <- value 8 | } 9 | \description{ 10 | Set X slot for irregular functional data objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/X-set-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{X<-,multiFunData-method} 4 | \alias{X<-,multiFunData-method} 5 | \title{Set X slot for multiFunData objects} 6 | \usage{ 7 | \S4method{X}{multiFunData}(object) <- value 8 | } 9 | \description{ 10 | Set X slot for multiFunData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/addError-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{addError,funData-method} 4 | \alias{addError,funData-method} 5 | \title{Add gaussian white noise to functional data} 6 | \usage{ 7 | \S4method{addError}{funData}(funDataObject, sd) 8 | } 9 | \description{ 10 | Add gaussian white noise to functional data 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/addError-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{addError,multiFunData-method} 4 | \alias{addError,multiFunData-method} 5 | \title{Add gaussian white noise to multivariate functional data} 6 | \usage{ 7 | \S4method{addError}{multiFunData}(funDataObject, sd) 8 | } 9 | \description{ 10 | Add gaussian white noise to multivariate functional data 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/addError.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{addError} 4 | \alias{addError} 5 | \title{Add Gaussian white noise to functional data objects} 6 | \usage{ 7 | addError(funDataObject, sd) 8 | } 9 | \arguments{ 10 | \item{funDataObject}{A functional data object of class 11 | \code{\linkS4class{funData}} or \code{\linkS4class{multiFunData}}.} 12 | 13 | \item{sd}{The standard deviation \eqn{\sigma} of the Gaussian white noise 14 | that is added to the data. Defaults to \code{1}. See Description.} 15 | } 16 | \value{ 17 | An object of the same class as \code{funDataObject}, which is a noisy 18 | version of the original data. 19 | } 20 | \description{ 21 | This function generates an artificial noisy version of a functional data 22 | object of class \code{\linkS4class{funData}} (univariate) or 23 | \code{\linkS4class{multiFunData}} (multivariate) by adding iid. realizations 24 | of Gaussian random variables \eqn{\varepsilon \sim \mathcal{N}(0, 25 | \sigma^2)}{\eps ~ N(0, \sigma^2)} to the observations. The standard deviation 26 | \eqn{\sigma} can be supplied by the user. 27 | } 28 | \examples{ 29 | oldPar <- par(no.readonly = TRUE) 30 | set.seed(1) 31 | 32 | # Univariate functional data 33 | plain <- simFunData(argvals = seq(0,1,0.01), M = 10, eFunType = "Fourier", 34 | eValType = "linear", N = 1)$simData 35 | noisy <- addError(plain , sd = 0.5) 36 | veryNoisy <- addError(plain, sd = 2) 37 | 38 | plot(plain, main = "Add error", ylim = range(veryNoisy@X)) 39 | plot(noisy, type = "p", pch = 20, add = TRUE) 40 | plot(veryNoisy, type = "p", pch = 4, add = TRUE) 41 | legend("topright", c("Plain", "Noisy", "Very Noisy"), lty = c(1, NA, NA), pch = c(NA, 20 ,4)) 42 | 43 | # Multivariate functional data 44 | plain <- simMultiFunData(type = "split", argvals = list(seq(0,1,0.01), seq(-.5,.5,0.02)), M = 10, 45 | eFunType = "Fourier", eValType = "linear", N = 1)$simData 46 | noisy <- addError(plain , sd = 0.5) 47 | veryNoisy <- addError(plain, sd = 2) 48 | 49 | par(mfrow = c(1,2)) 50 | plot(plain[[1]], main = "Add error (multivariate)", ylim = range(veryNoisy[[1]]@X)) 51 | plot(noisy[[1]], type = "p", pch = 20, add = TRUE) 52 | plot(veryNoisy[[1]], type = "p", pch = 4, add = TRUE) 53 | 54 | plot(plain[[2]], main = "Add error (multivariate)", ylim = range(veryNoisy[[2]]@X)) 55 | plot(noisy[[2]], type = "p", pch = 20, add = TRUE) 56 | plot(veryNoisy[[2]], type = "p", pch = 4, add = TRUE) 57 | legend("topright", c("Plain", "Noisy", "Very Noisy"), lty = c(1, NA, NA), pch = c(NA, 20 ,4)) 58 | 59 | par(oldPar) 60 | } 61 | \seealso{ 62 | \code{\linkS4class{funData}}, \code{\linkS4class{multiFunData}}, 63 | \code{\link{simFunData}}, \code{\link{simMultiFunData}}. 64 | } 65 | -------------------------------------------------------------------------------- /man/approxNA-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{approxNA,funData-method} 4 | \alias{approxNA,funData-method} 5 | \title{approxNA for funData objects} 6 | \usage{ 7 | \S4method{approxNA}{funData}(object) 8 | } 9 | \description{ 10 | approxNA for funData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/approxNA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{approxNA} 4 | \alias{approxNA} 5 | \title{Approximate missing values for funData objects} 6 | \usage{ 7 | approxNA(object) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{funData} with missing values (coded 11 | by \code{NA}).} 12 | } 13 | \value{ 14 | A \code{funData} object where missing values have been imputed. 15 | } 16 | \description{ 17 | This function approximates missing values for \code{funData} objects based on 18 | the \link[zoo]{na.approx} interpolation method from the package \pkg{zoo}. 19 | } 20 | \section{Warning}{ 21 | This function requires the package \pkg{zoo} to be 22 | installed, otherwise it will throw a warning. 23 | } 24 | 25 | \examples{ 26 | # Simulate some data 27 | f <- simFunData(N = 10, M = 8, eVal = "linear", eFun = "Poly", argvals = seq(0, 1, 0.01))$simData 28 | 29 | # Sparsify, i.e. generate artificial missings in the data 30 | fSparse <- sparsify(f, minObs = 10, maxObs = 50) 31 | 32 | # plot 33 | oldpar <- par(no.readonly = TRUE) 34 | par(mfrow = c(1,3)) 35 | plot(f, main = "Original Data") 36 | plot(fSparse, main = "Sparse Data") 37 | plot(approxNA(fSparse), main = "Reconstructed Data") 38 | # faster with plot(fSparse, plotNA = TRUE, main = "Reconstructed Data") 39 | 40 | par(oldpar) 41 | } 42 | -------------------------------------------------------------------------------- /man/argvals-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals,funData-method} 4 | \alias{argvals,funData-method} 5 | \title{Get argvals slot for funData objects} 6 | \usage{ 7 | \S4method{argvals}{funData}(object) 8 | } 9 | \description{ 10 | Get argvals slot for funData objects 11 | } 12 | \seealso{ 13 | \code{\link{argvals}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/argvals-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals,irregFunData-method} 4 | \alias{argvals,irregFunData-method} 5 | \title{Get argvals slot for irregular functional data objects} 6 | \usage{ 7 | \S4method{argvals}{irregFunData}(object) 8 | } 9 | \description{ 10 | Get argvals slot for irregular functional data objects 11 | } 12 | \seealso{ 13 | \code{\link{argvals}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/argvals-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals,multiFunData-method} 4 | \alias{argvals,multiFunData-method} 5 | \title{Get argvals slot for multiFunData objects} 6 | \usage{ 7 | \S4method{argvals}{multiFunData}(object) 8 | } 9 | \description{ 10 | Get argvals slot for multiFunData objects 11 | } 12 | \seealso{ 13 | \code{\link{argvals}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/argvals-set-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals<-,funData-method} 4 | \alias{argvals<-,funData-method} 5 | \title{Set argvals slot for funData objects} 6 | \usage{ 7 | \S4method{argvals}{funData}(object) <- value 8 | } 9 | \description{ 10 | Set argvals slot for funData objects 11 | } 12 | \seealso{ 13 | \code{\link{argvals<-}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/argvals-set-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals<-,irregFunData-method} 4 | \alias{argvals<-,irregFunData-method} 5 | \title{Set argvals slot for irregular functional objects} 6 | \usage{ 7 | \S4method{argvals}{irregFunData}(object) <- value 8 | } 9 | \description{ 10 | Set argvals slot for irregular functional objects 11 | } 12 | \seealso{ 13 | \code{\link{argvals<-}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/argvals-set-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals<-,multiFunData-method} 4 | \alias{argvals<-,multiFunData-method} 5 | \title{Set argvals slot for multiFunData objects} 6 | \usage{ 7 | \S4method{argvals}{multiFunData}(object) <- value 8 | } 9 | \description{ 10 | Set argvals slot for multiFunData objects 11 | } 12 | \seealso{ 13 | \code{\link{argvals<-}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/argvals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_set.R 3 | \name{argvals} 4 | \alias{argvals} 5 | \alias{getArgvals} 6 | \alias{getArgvals,funData-method} 7 | \alias{getArgvals,multiFunData-method} 8 | \alias{getArgvals,irregFunData-method} 9 | \alias{X} 10 | \alias{getX} 11 | \alias{getX,funData-method} 12 | \alias{getX,multiFunData-method} 13 | \alias{getX,irregFunData-method} 14 | \alias{argvals<-} 15 | \alias{setArgvals} 16 | \alias{setArgvals,funData-method} 17 | \alias{setArgvals,multiFunData-method} 18 | \alias{setArgvals,irregFunData-method} 19 | \alias{X<-} 20 | \alias{setX} 21 | \alias{setX,funData-method} 22 | \alias{setX,multiFunData-method} 23 | \alias{setX,irregFunData-method} 24 | \title{Extract and set slots from functional data objects} 25 | \usage{ 26 | argvals(object) 27 | 28 | getArgvals(object) 29 | 30 | \S4method{getArgvals}{funData}(object) 31 | 32 | \S4method{getArgvals}{multiFunData}(object) 33 | 34 | \S4method{getArgvals}{irregFunData}(object) 35 | 36 | X(object) 37 | 38 | getX(object) 39 | 40 | \S4method{getX}{funData}(object) 41 | 42 | \S4method{getX}{multiFunData}(object) 43 | 44 | \S4method{getX}{irregFunData}(object) 45 | 46 | argvals(object) <- value 47 | 48 | setArgvals(object, value) 49 | 50 | \S4method{setArgvals}{funData}(object, value) 51 | 52 | \S4method{setArgvals}{multiFunData}(object, value) 53 | 54 | \S4method{setArgvals}{irregFunData}(object, value) 55 | 56 | X(object) <- value 57 | 58 | setX(object, value) 59 | 60 | \S4method{setX}{funData}(object, value) 61 | 62 | \S4method{setX}{multiFunData}(object, value) 63 | 64 | \S4method{setX}{irregFunData}(object, value) 65 | } 66 | \arguments{ 67 | \item{object}{An object of class \code{funData}, \code{irregFunData} or 68 | \code{multiFunData}.} 69 | 70 | \item{value}{New \code{argvals} or \code{X}. See Details.} 71 | } 72 | \value{ 73 | See Details. 74 | } 75 | \description{ 76 | These functions can be used to extract and set the slots of 77 | \code{funData}, \code{irregFunData} and \code{multiFunData} objects. 78 | } 79 | \details{ 80 | Objects of class \code{funData} or \code{irregFunData} have two slots, 81 | \code{argvals} (for the x-values) and \code{X} (for the y-values for 82 | each observation). Using the \code{argvals} (alias: \code{getArgvals}) 83 | and \code{X} (alias: \code{getX}) methods for the classes 84 | \code{funData} and \code{irregFunData} is equivalent to accessing the 85 | slots directly via \code{object@argvals} and \code{object@X}. 86 | Analogously, the \code{argvals<-} and \code{X<-} functions are 87 | equivalent to setting \code{object@argvals} to \code{value} or 88 | \code{object@X} to \code{value}, respectively. The new values must 89 | hence have the same structure as the original ones. As an exception, 90 | for an object of class \code{funData} the number of new X values may 91 | differ from the current (e.g. when adding new observations). In this 92 | case, the function throws a warning. 93 | 94 | Objects of class \code{multiFunData} are lists of several 95 | \code{funData} objects. The functions \code{argvals} and \code{X} for 96 | \code{multiFunData} objects therefore return a list of the same length 97 | as \code{object}, where each list element corresponds to the 98 | \code{argvals} or \code{X} slot of the univariate element. The 99 | \code{argvals<-} and \code{X<-} functions for \code{multiFunData} 100 | objects must receive lists of the same length as \code{object}, where 101 | each list element corresponds to the new \code{argvals} or new \code{X} 102 | slot for the univariate elements. 103 | } 104 | \section{Warning}{ 105 | The functions \code{getArgvals} / \code{getX} and 106 | \code{setArgvals} / \code{setX} from former package versions are 107 | deprecated. use \code{argvals} and \code{X} instead. 108 | } 109 | 110 | \examples{ 111 | ### Univariate 112 | object <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 113 | object 114 | 115 | # get-methods 116 | argvals(object) 117 | X(object) 118 | 119 | # set-methods 120 | argvals(object) <- 0:4 121 | object 122 | \dontrun{argvals(object) <- 1:4} # wrong length 123 | X(object) <- rbind(0:4, 5:9) 124 | \dontrun{X(object) <- rbind(0:4, 5:9, 10:14) # warning: now 3 observations (was 2 before)} 125 | \dontrun{X(object) <- rbind(1:4, 5:8)} # wrong length 126 | 127 | ### Univariate (irregular) 128 | irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 129 | irregObject 130 | 131 | # get-methods 132 | argvals(irregObject) 133 | X(irregObject) 134 | 135 | # set-methods 136 | argvals(irregObject) <- list(0:4, 1:3) 137 | X(irregObject) <- list(12:16, 13:15) 138 | 139 | ### Multivariate 140 | multiObject <- multiFunData(object, funData(argvals = 1:3, X = rbind(3:5, 6:8))) 141 | multiObject 142 | 143 | # get-methods 144 | argvals(multiObject) 145 | X(multiObject) 146 | 147 | # set-methods (for special cases see univariate version) 148 | argvals(multiObject) <- list(5:1, 3:1) 149 | X(multiObject) <- list(rbind(5:1, 10:6), rbind(5:3, 8:6)) 150 | } 151 | \seealso{ 152 | \code{\linkS4class{funData}}, 153 | \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}} 154 | } 155 | \keyword{internal} 156 | -------------------------------------------------------------------------------- /man/as.data.frame.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coerce.R 3 | \name{as.data.frame.funData} 4 | \alias{as.data.frame.funData} 5 | \alias{as.data.frame,funData-method} 6 | \alias{as.data.frame,multiFunData-method} 7 | \alias{as.data.frame,irregFunData-method} 8 | \title{Coerce functional data objects to a data.frame} 9 | \usage{ 10 | \S4method{as.data.frame}{funData}(x) 11 | 12 | \S4method{as.data.frame}{multiFunData}(x) 13 | 14 | \S4method{as.data.frame}{irregFunData}(x) 15 | } 16 | \arguments{ 17 | \item{x}{The functional data object that is to be transformed to a 18 | \code{data.frame}} 19 | } 20 | \value{ 21 | A data frame with columns \code{obs} (gives index/name of 22 | observed curve), \code{argvals1, ... argvalsd} with \code{d} the 23 | dimension of the support and \code{X} for the observed values. 24 | One-dimensional functions have only \code{argvals1}, two-dimensional 25 | functions (images) have \code{argvals1} and \code{argvals2}, etc. 26 | } 27 | \description{ 28 | Coerce objects of class \code{funData}, \code{multiFunData} and 29 | \code{irregFunData} to a data frame. 30 | } 31 | \examples{ 32 | # one-dimensional domain 33 | f1 <- funData(argvals = 1:5, X = matrix(1:20, nrow = 4)) 34 | head(as.data.frame(f1)) 35 | 36 | # two-dimensional domain 37 | f2 <- funData(argvals = list(1:5, 1:6), X = array(1:120, c(4,5,6))) 38 | head(as.data.frame(f2)) 39 | 40 | # multivariate functional data 41 | m1 <- multiFunData(f1, f2) 42 | str(as.data.frame(m1)) 43 | 44 | # irregular functional data 45 | i1 <- irregFunData(argvals = list(1:5, 2:4, 3:5), X = list(1:5, 2:4, -(3:1))) 46 | head(as.data.frame(i1)) 47 | } 48 | \seealso{ 49 | \code{\linkS4class{funData}}, 50 | \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}}, 51 | \code{\link{data.frame}} 52 | } 53 | -------------------------------------------------------------------------------- /man/as.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R 3 | \name{as.funData} 4 | \alias{as.funData} 5 | \alias{as.funData,irregFunData-method} 6 | \title{Coerce an irregFunData object to class funData} 7 | \usage{ 8 | as.funData(object) 9 | 10 | \S4method{as.funData}{irregFunData}(object) 11 | } 12 | \arguments{ 13 | \item{object}{The \code{irregFunData} object that is to be converted to a 14 | \code{funData} object with missing values.} 15 | } 16 | \description{ 17 | This function coerces an object of class \code{irregFunData} to a 18 | \code{funData} object with missing values, which is defined on the union of 19 | all observation points. 20 | } 21 | \seealso{ 22 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}} 23 | } 24 | -------------------------------------------------------------------------------- /man/as.irregFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R 3 | \name{as.irregFunData} 4 | \alias{as.irregFunData} 5 | \alias{as.irregFunData,funData-method} 6 | \title{Coerce a funData object to class irregFunData} 7 | \usage{ 8 | as.irregFunData(object) 9 | 10 | \S4method{as.irregFunData}{funData}(object) 11 | } 12 | \arguments{ 13 | \item{object}{The \code{funData} object that is to be converted to a 14 | \code{irregFunData} object.} 15 | } 16 | \description{ 17 | This function coerces an object of class \code{funData} to a 18 | \code{irregFunData} object. 19 | } 20 | \seealso{ 21 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}} 22 | } 23 | -------------------------------------------------------------------------------- /man/as.multiFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R 3 | \name{as.multiFunData} 4 | \alias{as.multiFunData} 5 | \alias{as.multiFunData,funData-method} 6 | \title{Coerce a funData object to class multiFunData} 7 | \usage{ 8 | as.multiFunData(object) 9 | 10 | \S4method{as.multiFunData}{funData}(object) 11 | } 12 | \arguments{ 13 | \item{object}{The \code{funData} object that is to be converted to a 14 | \code{multiFunData} object of length 1.} 15 | } 16 | \description{ 17 | Coerce a \code{funData} object to class \code{multiFunData} with one element. 18 | } 19 | \examples{ 20 | # create funData object with 5 observations 21 | x <- seq(0,1,0.01) 22 | f1 <- funData(argvals = x, X = 1:5 \%o\% x) 23 | f1 24 | class(f1) 25 | 26 | # coerce to multiFunData object (of length 1) 27 | m1 <- as.multiFunData(f1) 28 | m1 29 | class(m1) 30 | } 31 | \seealso{ 32 | \code{\linkS4class{funData}}, \code{\linkS4class{multiFunData}} 33 | } 34 | -------------------------------------------------------------------------------- /man/autoplot.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{autoplot.funData} 4 | \alias{autoplot.funData} 5 | \alias{autolayer.funData} 6 | \title{Visualize functional data objects using ggplot} 7 | \usage{ 8 | autoplot.funData( 9 | object, 10 | obs = seq_len(nObs(object)), 11 | geom = "line", 12 | plotNA = FALSE, 13 | ... 14 | ) 15 | 16 | autolayer.funData( 17 | object, 18 | obs = seq_len(nObs(object)), 19 | geom = "line", 20 | plotNA = FALSE, 21 | ... 22 | ) 23 | } 24 | \arguments{ 25 | \item{object}{A \code{funData} object on a one- or two-dimensional domain.} 26 | 27 | \item{obs}{A vector of numerics giving the observations to plot. Defaults to 28 | all observations in \code{object}. For two-dimensional functions (images) 29 | \code{obs} must have length 1.} 30 | 31 | \item{geom}{A character string describing the geometric object to use. 32 | Defaults to \code{"line"}. See \pkg{ggplot2} for details.} 33 | 34 | \item{plotNA}{Logical. If \code{TRUE}, missing values are interpolated using 35 | the \code{\link{approxNA}} function (only for one-dimensional functions). 36 | Defaults to \code{FALSE}. See Details.} 37 | 38 | \item{...}{Further parameters passed to \code{\link[ggplot2]{geom_line}} (for 39 | one dimensional domains, e.g. \code{alpha, color, fill, linetype, size}) or 40 | to \code{\link[ggplot2]{geom_raster}} (for two-dimensional domains, e.g. 41 | \code{hjust, vjust, interpolate}).} 42 | } 43 | \value{ 44 | A \code{\link[ggplot2]{ggplot}} object that can be customized using 45 | all functionalities of the \pkg{ggplot2} package. 46 | } 47 | \description{ 48 | This function allows to plot \code{funData} objects based on the 49 | \pkg{ggplot2} package. The function provides a wrapper that rearranges the 50 | data in a \code{funData} object on a one- or two-dimensional domain and 51 | provides a basic \code{\link[ggplot2]{ggplot}} object, which can be 52 | customized using all functionalities of the \pkg{ggplot2} package. 53 | } 54 | \details{ 55 | If some observations contain missing values (coded via \code{NA}), the 56 | functions can be interpolated using the option \code{plotNA = TRUE}. This 57 | option relies on the \code{\link[zoo]{na.approx}} function in package 58 | \code{\link[zoo]{zoo}} and is currently implemented for one-dimensional 59 | functions only in the function \code{\link{approxNA}}. 60 | } 61 | \examples{ 62 | # Install / load package ggplot2 before running the examples 63 | library("ggplot2") 64 | 65 | # One-dimensional 66 | argvals <- seq(0,2*pi,0.01) 67 | object <- funData(argvals, 68 | outer(seq(0.75, 1.25, length.out = 11), sin(argvals))) 69 | 70 | g <- autoplot(object) # returns ggplot object 71 | g # plot the object 72 | 73 | # add the mean function in red 74 | g + autolayer(meanFunction(object), col = 2) 75 | 76 | # Two-dimensional 77 | X <- array(0, dim = c(2, length(argvals), length(argvals))) 78 | X[1,,] <- outer(argvals, argvals, function(x,y){sin((x-pi)^2 + (y-pi)^2)}) 79 | X[2,,] <- outer(argvals, argvals, function(x,y){sin(2*x*pi) * cos(2*y*pi)}) 80 | object2D <- funData(list(argvals, argvals), X) 81 | 82 | \donttest{ 83 | autoplot(object2D, obs = 1) 84 | autoplot(object2D, obs = 2)} 85 | \dontrun{autoplot(object2D)} # must specify obs! 86 | 87 | ### More examples ### 88 | \donttest{ 89 | par(mfrow = c(1,1)) 90 | 91 | # using plotNA (needs packages zoo and gridExtra) 92 | \dontshow{requireNamespace("zoo", quietly = TRUE)} 93 | \dontshow{requireNamespace("gridExtra", quietly = TRUE)} 94 | objectMissing <- funData(1:5, rbind(c(1, NA, 5, 4, 3), c(10, 9, NA, NA, 6))) 95 | g1 <- autoplot(objectMissing) # the default 96 | g2 <- autoplot(objectMissing, plotNA = TRUE) # requires zoo 97 | 98 | gridExtra::grid.arrange(g1 + ggtitle("plotNA = FALSE (default)"), 99 | g2 + ggtitle("plotNA = TRUE")) # requires gridExtra 100 | 101 | # Customizing plots (see ggplot2 documentation for more details) 102 | # parameters passed to geom_line are passed via the ... argument 103 | gFancy <- autoplot(object, color = "red", linetype = 2) 104 | gFancy 105 | 106 | # new layers can be added directly to the ggplot object 107 | gFancy + theme_bw() # add new layers to the ggplot object 108 | gFancy + ggtitle("Fancy Plot with Title and Axis Legends") + 109 | xlab("The x-Axis") + ylab("The y-Axis") 110 | 111 | autoplot(object2D, obs = 1) + ggtitle("Customized 2D plot") + theme_minimal() + 112 | scale_fill_gradient(high = "green", low = "blue", name = "Legend here") 113 | } 114 | } 115 | \seealso{ 116 | \code{\linkS4class{funData}}, \code{\link[ggplot2]{ggplot}}, 117 | \code{\link{plot.funData}} 118 | } 119 | -------------------------------------------------------------------------------- /man/autoplot.irregFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{autoplot.irregFunData} 4 | \alias{autoplot.irregFunData} 5 | \alias{autolayer.irregFunData} 6 | \title{Visualize irregular functional data objects using ggplot} 7 | \usage{ 8 | autoplot.irregFunData(object, obs = seq_len(nObs(object)), geom = "line", ...) 9 | 10 | autolayer.irregFunData(object, obs = seq_len(nObs(object)), geom = "line", ...) 11 | } 12 | \arguments{ 13 | \item{object}{A \code{irregFunData} object.} 14 | 15 | \item{obs}{A vector of numerics giving the observations to plot. Defaults to 16 | all observations in \code{object}. For two-dimensional functions (images) 17 | \code{obs} must have length 1.} 18 | 19 | \item{geom}{A character string describing the geometric object to use. 20 | Defaults to \code{"line"}. See \pkg{ggplot2} for details.} 21 | 22 | \item{...}{Further parameters passed to \code{\link[ggplot2]{stat_identity}}, 23 | e.g. \code{alpha, color, fill, linetype, size}).} 24 | } 25 | \value{ 26 | A \code{\link[ggplot2]{ggplot}} object that can be customized using 27 | all functionalities of the \pkg{ggplot2} package. 28 | } 29 | \description{ 30 | This function allows to plot \code{irregFunData} objects on their domain 31 | based on the \pkg{ggplot2} package. The function provides a wrapper that 32 | returns a basic 33 | \code{\link[ggplot2]{ggplot}} object, which can be customized using all 34 | functionalities of the \pkg{ggplot2} package. 35 | } 36 | \examples{ 37 | # Install / load package ggplot2 before running the examples 38 | library("ggplot2") 39 | 40 | # Generate data 41 | argvals <- seq(0,2*pi,0.01) 42 | ind <- replicate(5, sort(sample(1:length(argvals), sample(5:10,1)))) 43 | object <- irregFunData(argvals = lapply(ind, function(i){argvals[i]}), 44 | X = lapply(ind, function(i){sample(1:10,1) / 10 * argvals[i]^2})) 45 | 46 | # Plot the data 47 | autoplot(object) 48 | 49 | # Parameters passed to geom_line are passed via the ... argument 50 | autoplot(object, color = "red", linetype = 3) 51 | 52 | # Plot the data and add green dots for the 2nd function 53 | autoplot(object) + autolayer(object, obs = 2, geom = "point", color = "green") 54 | 55 | # New layers can be added directly to the ggplot object using functions from the ggplot2 package 56 | g <- autoplot(object) 57 | g + theme_bw() + ggtitle("Plot with minimal theme and axis labels") + 58 | xlab("The x-Axis") + ylab("The y-Axis") 59 | } 60 | \seealso{ 61 | \code{\linkS4class{irregFunData}}, \code{\link[ggplot2]{ggplot}}, 62 | \code{\link{plot.irregFunData}} 63 | } 64 | -------------------------------------------------------------------------------- /man/autoplot.multiFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{autoplot.multiFunData} 4 | \alias{autoplot.multiFunData} 5 | \title{Visualize multivariate functional data objects using ggplot} 6 | \usage{ 7 | autoplot.multiFunData( 8 | object, 9 | obs = seq_len(nObs(object)), 10 | dim = seq_len(length(object)), 11 | plotGrid = FALSE, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{A \code{multiFunData} object that is to be plotted.} 17 | 18 | \item{obs}{A vector of numerics giving the observations to plot. Defaults to all observations in 19 | \code{object}. For two-dimensional functions (images) \code{obs} must have length 1.} 20 | 21 | \item{dim}{The dimensions to plot. Defaults to \code{length(object)}, i.e. all functions in 22 | \code{object} are plotted.} 23 | 24 | \item{plotGrid}{Logical. If \code{TRUE}, the data is plotted using 25 | \code{\link[gridExtra]{grid.arrange}} and the list of \code{\link[ggplot2]{ggplot}} objects is 26 | returned invisibly. If \code{FALSE}, only the list of objects is returned. Defaults to 27 | \code{FALSE}.} 28 | 29 | \item{...}{Further parameters passed to the univariate \code{\link{autoplot.funData}} functions for 30 | \code{funData} objects.} 31 | } 32 | \value{ 33 | A list of \code{\link[ggplot2]{ggplot}} objects that are also printed directly as a grid 34 | if \code{plotGrid = TRUE}. 35 | } 36 | \description{ 37 | This function allows to plot \code{multiFunData} objects based on the \pkg{ggplot2} package. The 38 | function applies the \code{\link{autoplot.funData}} function to each element and returns either a 39 | combined plot with all elements plotted in one row or a list containing the different subplots as 40 | \code{\link[ggplot2]{ggplot}} objects. The individual objects can be customized using all 41 | functionalities of the \pkg{ggplot2} package. 42 | } 43 | \section{Warning}{ 44 | Currently, the function does not accept different parameters for the univariate 45 | elements. 46 | } 47 | 48 | \examples{ 49 | # Load packages ggplot2 and gridExtra before running the examples 50 | library("ggplot2"); library("gridExtra") 51 | 52 | # One-dimensional elements 53 | argvals <- seq(0, 2*pi, 0.01) 54 | f1 <- funData(argvals, outer(seq(0.75, 1.25, length.out = 11), sin(argvals))) 55 | f2 <- funData(argvals, outer(seq(0.75, 1.25, length.out = 11), cos(argvals))) 56 | 57 | m1 <- multiFunData(f1, f2) 58 | 59 | g <- autoplot(m1) # default 60 | g[[1]] # plot first element 61 | g[[2]] # plot second element 62 | gridExtra::grid.arrange(grobs = g, nrow = 1) # requires gridExtra package 63 | 64 | autoplot(m1, plotGrid = TRUE) # the same directly with plotGrid = TRUE 65 | 66 | \donttest{ 67 | # Mixed-dimensional elements 68 | X <- array(0, dim = c(11, length(argvals), length(argvals))) 69 | X[1,,] <- outer(argvals, argvals, function(x,y){sin((x-pi)^2 + (y-pi)^2)}) 70 | f2 <- funData(list(argvals, argvals), X) 71 | 72 | m2 <- multiFunData(f1, f2) 73 | 74 | autoplot(m2, obs = 1, plotGrid = TRUE) 75 | 76 | # Customizing plots (see ggplot2 documentation for more details) 77 | g2 <- autoplot(m2, obs = 1) 78 | g2[[1]] <- g2[[1]] + ggtitle("First element") + theme_bw() 79 | g2[[2]] <- g2[[2]] + ggtitle("Second element") + 80 | scale_fill_gradient(high = "green", low = "blue") 81 | gridExtra::grid.arrange(grobs = g2, nrow = 1) # requires gridExtra package 82 | } 83 | } 84 | \seealso{ 85 | \code{\linkS4class{multiFunData}}, \code{\link[ggplot2]{ggplot}}, 86 | \code{\link{plot.multiFunData}} 87 | } 88 | -------------------------------------------------------------------------------- /man/dimSupp-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{dimSupp,funData-method} 4 | \alias{dimSupp,funData-method} 5 | \title{dimSupp for funData objects} 6 | \usage{ 7 | \S4method{dimSupp}{funData}(object) 8 | } 9 | \description{ 10 | dimSupp for funData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/dimSupp-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{dimSupp,irregFunData-method} 4 | \alias{dimSupp,irregFunData-method} 5 | \title{dimSupp for irregular functional data objects} 6 | \usage{ 7 | \S4method{dimSupp}{irregFunData}(object) 8 | } 9 | \description{ 10 | dimSupp for irregular functional data objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/dimSupp-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{dimSupp,multiFunData-method} 4 | \alias{dimSupp,multiFunData-method} 5 | \title{dimSupp for multiFunData objects} 6 | \usage{ 7 | \S4method{dimSupp}{multiFunData}(object) 8 | } 9 | \description{ 10 | dimSupp for multiFunData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/dimSupp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{dimSupp} 4 | \alias{dimSupp} 5 | \title{Support dimension of functional data} 6 | \usage{ 7 | dimSupp(object) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{funData}, \code{irregFunData} or \code{multiFunData}.} 11 | } 12 | \value{ 13 | If \code{object} is univariate (i.e. of class \code{funData} or \code{irregFunData}), the 14 | function returns the dimension of the support of \code{object}. If 15 | \code{object} is multivariate (i.e. of class \code{multiFunData}), the 16 | function returns a vector, giving the support dimension of each element. 17 | } 18 | \description{ 19 | This function returns the support dimension of an object of class 20 | \code{funData}, \code{irregFunData} or \code{multiFunData}. 21 | } 22 | \examples{ 23 | # Univariate (one-dimensional) 24 | object1 <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 25 | dimSupp(object1) 26 | 27 | # Univariate (two-dimensional) 28 | object2 <- funData(argvals = list(1:10, 1:5), X = array(rnorm(100), dim = c(2,10,5))) 29 | dimSupp(object2) 30 | 31 | # Univariate (irregular) 32 | irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 33 | dimSupp(irregObject) 34 | 35 | # Multivariate 36 | multiObject <- multiFunData(object1, object2) 37 | dimSupp(multiObject) 38 | } 39 | \seealso{ 40 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}} 41 | } 42 | -------------------------------------------------------------------------------- /man/dot-intWeights.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{.intWeights} 4 | \alias{.intWeights} 5 | \title{Calculate weights for numerical integration} 6 | \usage{ 7 | .intWeights(argvals, method = "trapezoidal") 8 | } 9 | \arguments{ 10 | \item{argvals}{A numeric vector of x-Values} 11 | 12 | \item{method}{A character string, giving the numerical integration method to use (default is \code{trapezoidal}, alternatively use \code{midpoint})} 13 | } 14 | \value{ 15 | A vector of integration weights 16 | } 17 | \description{ 18 | This function calculates the weights for numerical integration 19 | } 20 | \seealso{ 21 | \code{\link{integrate}} 22 | } 23 | -------------------------------------------------------------------------------- /man/dot-scalarProduct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{.scalarProduct} 4 | \alias{.scalarProduct} 5 | \title{Generic method for scalar products, based on integrate} 6 | \usage{ 7 | .scalarProduct(object1, object2, ...) 8 | } 9 | \arguments{ 10 | \item{object1, object2}{Generic objects} 11 | 12 | \item{...}{Further objects passed to \code{\link{integrate}}} 13 | } 14 | \description{ 15 | Generic method for scalar products, based on integrate 16 | } 17 | -------------------------------------------------------------------------------- /man/eFun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{eFun} 4 | \alias{eFun} 5 | \title{Generate orthonormal eigenfunctions} 6 | \usage{ 7 | eFun(argvals, M, ignoreDeg = NULL, type) 8 | } 9 | \arguments{ 10 | \item{argvals}{A vector of numerics, defining a (fine) grid on the interval 11 | for which the basis functions are computed.} 12 | 13 | \item{M}{An integer, specifying the number of functions that are calculated.} 14 | 15 | \item{ignoreDeg}{A vector of numerics, specifying the degrees to be ignored 16 | for type \code{"PolyHigh"}. Defaults to \code{NULL}. See Details.} 17 | 18 | \item{type}{A character string, specifying the type of functions that are 19 | calculated. See Details.} 20 | } 21 | \value{ 22 | A univariate functional data object of class 23 | \code{\linkS4class{funData}} containing the basis functions on the given 24 | interval. 25 | } 26 | \description{ 27 | This function calculates \eqn{M} (orthonormal) basis functions on a given 28 | interval, that can be interpreted as the first \eqn{M} eigenfunctions of an 29 | appropriate data generating process of functional data. 30 | } 31 | \details{ 32 | The function implements three families of orthonormal basis functions plus 33 | variations of them. The parameter \code{type}, that specifies the functions 34 | to be calculated, can have the following values: \itemize{\item 35 | \code{"Poly"}: Calculate orthonormal Legendre polynomials of degree 36 | 0,...,M-1. \item \code{"PolyHigh"}: Calculate \eqn{M} orthonormal Legendre 37 | Polynomials of higher degree. The vector of indices \code{ignoreDeg} 38 | specifies the functions to be ignored. If \code{ignoreDeg} is not specified, 39 | the function returns an error. \item \code{"Fourier"}: Calculate the first 40 | \eqn{M} Fourier basis functions. \item \code{"FourierLin"}: Calculate the 41 | first \eqn{M-1} Fourier basis functions plus the linear function, 42 | orthonormalized to the previous functions via Gram-Schmidts method. This type 43 | is currently implemented for functions on the unit interval \eqn{[0,1]} only. 44 | If the function is called with other \code{argvals}, an error is thrown. 45 | \item \code{"Wiener"}: Calculate the first \eqn{M} orthonormal eigenfunctions 46 | of the Wiener process. } 47 | } 48 | \examples{ 49 | oldPar <- par(no.readonly = TRUE) 50 | 51 | argvals <- seq(0,1,0.01) 52 | 53 | par(mfrow = c(3,2)) 54 | plot(eFun(argvals, M = 4, type = "Poly"), main = "Poly", ylim = c(-3,3)) 55 | plot(eFun(argvals, M = 4, ignoreDeg = 1:2, type = "PolyHigh"), main = "PolyHigh", ylim = c(-3,3)) 56 | plot(eFun(argvals, M = 4, type = "Fourier"), main = "Fourier", ylim = c(-3,3)) 57 | plot(eFun(argvals, M = 4, type = "FourierLin"), main = "FourierLin", ylim = c(-3,3)) 58 | plot(eFun(argvals, M = 4, type = "Wiener"), main = "Wiener", ylim = c(-3,3)) 59 | par(oldPar) 60 | } 61 | \seealso{ 62 | \code{\linkS4class{funData}}, \code{\link{simFunData}}, 63 | \code{\link{simMultiFunData}} 64 | } 65 | -------------------------------------------------------------------------------- /man/eVal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{eVal} 4 | \alias{eVal} 5 | \title{Generate a sequence of simulated eigenvalues} 6 | \usage{ 7 | eVal(M, type) 8 | } 9 | \arguments{ 10 | \item{M}{An integer, the number of eigenvalues to be generated.} 11 | 12 | \item{type}{A character string specifying the type of eigenvalues that should 13 | be calculated. See Details.} 14 | } 15 | \value{ 16 | A vector containing the \code{M} decreasing eigenvalues. 17 | } 18 | \description{ 19 | This function generates \eqn{M} decreasing eigenvalues. 20 | } 21 | \details{ 22 | The function implements three types of eigenvalues: \itemize{\item 23 | \code{"linear":} The eigenvalues start at \eqn{1} and decrease linearly 24 | towards \eqn{0}: \deqn{\nu_m = \frac{M+1-m}{m}.}{\nu_m = (M+1-m)/m.} \item 25 | \code{"exponential":} The eigenvalues start at \eqn{1} and decrease 26 | exponentially towards \eqn{0}: \deqn{\nu_m = 27 | \exp\left(-\frac{m-1}{2}\right).}{\nu_m = exp(-(m-1)/2).}\item 28 | \code{"wiener":} The eigenvalues correspond to the eigenvalues of the Wiener 29 | process: \deqn{\nu_m = \frac{1}{(\pi/2 \cdot (2m-1))^2}.}{\nu_m = (pi/2 * 30 | (2m-1))^(-2)} } 31 | } 32 | \examples{ 33 | oldpar <- par(no.readonly = TRUE) 34 | 35 | # simulate M = 10 eigenvalues 36 | M <- 10 37 | eLin <- eVal(M = M, type = "linear") 38 | eExp <- eVal(M = M, type = "exponential") 39 | eWien <- eVal(M = M, type = "wiener") 40 | 41 | par(mfrow = c(1,1)) 42 | plot(1:M, eLin, pch = 20, xlab = "m", ylab = expression(nu[m]), ylim = c(0,1)) 43 | points(1:M, eExp, pch = 20, col = 3) 44 | points(1:M, eWien, pch = 20, col = 4) 45 | legend("topright", legend = c("linear", "exponential", "wiener"), pch = 20, col = c(1,3,4)) 46 | 47 | par(oldpar) 48 | } 49 | -------------------------------------------------------------------------------- /man/efFourier.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{efFourier} 4 | \alias{efFourier} 5 | \title{Calculate the first M Fourier basis functions} 6 | \usage{ 7 | efFourier(argvals, M, linear = FALSE) 8 | } 9 | \arguments{ 10 | \item{argvals}{A vector, defining a (fine) grid on the interval for which the 11 | Fourier basis functions are computed.} 12 | 13 | \item{M}{An integer, specifying the number of basis functions that are 14 | calculated.} 15 | 16 | \item{linear}{Logical. If \code{TRUE}, the last function is not a Fourier 17 | function but the linear function orthogonalized to all previous Fourier 18 | basis functions. Defaults to \code{FALSE}. See Details.} 19 | } 20 | \value{ 21 | A univariate functional data object of class 22 | \code{\linkS4class{funData}} containing the Fourier basis functions on 23 | the given interval. 24 | } 25 | \description{ 26 | This function calculates the first M orthonormal Fourier basis functions on 27 | an arbitrary interval. 28 | } 29 | \details{ 30 | If \code{linear}, the last basis function does not belong to the Fourier 31 | basis, but is the linear function orthogonalized to all previous Fourier 32 | basis functions via the Gram-Schmidt method. This is implemented only if 33 | \code{argvalss} is a grid defining the unit interval \eqn{[0,1]}. 34 | } 35 | \seealso{ 36 | \code{\linkS4class{funData}}, \code{\link{simFunData}}, \code{\link{simMultiFunData}} 37 | } 38 | \keyword{internal} 39 | -------------------------------------------------------------------------------- /man/efPoly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{efPoly} 4 | \alias{efPoly} 5 | \title{Legendre Polynomials of degree 0,...,M-1} 6 | \usage{ 7 | efPoly(argvals, M) 8 | } 9 | \arguments{ 10 | \item{argvals}{A vector, defining a (fine) grid on the interval for which the 11 | Legendre polynomials are computed.} 12 | 13 | \item{M}{An integer, specifying the number (and hence the degree) of 14 | polynomials that are calculated.} 15 | } 16 | \value{ 17 | A univariate functional data object of class \code{\linkS4class{funData}} 18 | containing the Legendre polynomials on the given interval. 19 | } 20 | \description{ 21 | This function iteratively calculates orthonormal Legendre polynomials of 22 | degree 0,...,M-1 on an arbitrary interval. 23 | } 24 | \seealso{ 25 | \code{\linkS4class{funData}}, \code{\link{simFunData}}, \code{\link{simMultiFunData}} 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/efWiener.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{efWiener} 4 | \alias{efWiener} 5 | \title{Calculate the first M eigenfunctions of the Wiener process} 6 | \usage{ 7 | efWiener(argvals, M) 8 | } 9 | \arguments{ 10 | \item{argvals}{A vector, defining a (fine) grid on the interval for which the 11 | eigenfunctions are computed.} 12 | 13 | \item{M}{An integer, specifying the number of eigenfunctions that are 14 | calculated.} 15 | } 16 | \value{ 17 | A univariate functional data object of class 18 | \code{\linkS4class{funData}} containing the eigenfunctions of the Wiener 19 | process on the given interval. 20 | } 21 | \description{ 22 | This function calculates the first M (orthonormal) eigenfunctions of the 23 | Wiener process on an arbitrary interval. 24 | } 25 | \seealso{ 26 | \code{\linkS4class{funData}}, \code{\link{simFunData}}, \code{\link{simMultiFunData}} 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/expand.int.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{expand.int} 4 | \alias{expand.int} 5 | \title{Function to expand integers to a grid of indices} 6 | \usage{ 7 | expand.int(...) 8 | } 9 | \arguments{ 10 | \item{...}{An arbitrary number of integer values.} 11 | } 12 | \value{ 13 | A dataframe with the same number of columns as integers supplied and containing all 14 | combinations of indices from 1 to the given integers. If no number is supplied, the function 15 | returns \code{NULL}. 16 | } 17 | \description{ 18 | This function takes an arbitrary number \eqn{K} of integer values \eqn{n_1,\ldots, n_K} and 19 | creates a data frame with all combinations from \code{1:}\eqn{n_k}, where the first column 20 | (taking values from 1 to \eqn{n_1}) varies slowest and the last column (())taking values from 1 21 | to \eqn{n_K}) varies fastest. Internally, this function depends on \code{\link{expand.grid}} 22 | } 23 | \examples{ 24 | # For two integers 25 | funData:::expand.int(2,5) # first column varies slowest 26 | 27 | # For three integers 28 | funData:::expand.int(2,3,4) 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/extractObs-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset.R 3 | \name{extractObs,funData-method} 4 | \alias{extractObs,funData-method} 5 | \title{extractObs for funData objects} 6 | \usage{ 7 | \S4method{extractObs}{funData}( 8 | object, 9 | obs = seq_len(nObs(object)), 10 | argvals = funData::argvals(object) 11 | ) 12 | } 13 | \description{ 14 | extractObs for funData objects 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/extractObs-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset.R 3 | \name{extractObs,irregFunData-method} 4 | \alias{extractObs,irregFunData-method} 5 | \title{extractObs for irregular functional data} 6 | \usage{ 7 | \S4method{extractObs}{irregFunData}( 8 | object, 9 | obs = seq_len(nObs(object)), 10 | argvals = funData::argvals(object) 11 | ) 12 | } 13 | \description{ 14 | extractObs for irregular functional data 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/extractObs-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset.R 3 | \name{extractObs,multiFunData-method} 4 | \alias{extractObs,multiFunData-method} 5 | \title{extractObs for multiFunData objects} 6 | \usage{ 7 | \S4method{extractObs}{multiFunData}( 8 | object, 9 | obs = seq_len(nObs(object)), 10 | argvals = funData::argvals(object) 11 | ) 12 | } 13 | \description{ 14 | extractObs for multiFunData objects 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/extractObs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset.R 3 | \name{extractObs} 4 | \alias{extractObs} 5 | \alias{subset,funData-method} 6 | \alias{subset,multiFunData-method} 7 | \alias{subset,irregFunData-method} 8 | \alias{[,funData,ANY,missing,missing-method} 9 | \alias{[,multiFunData,ANY,missing,missing-method} 10 | \alias{[,irregFunData,ANY,missing,missing-method} 11 | \title{Extract observations of functional data} 12 | \usage{ 13 | extractObs( 14 | object, 15 | obs = seq_len(nObs(object)), 16 | argvals = funData::argvals(object) 17 | ) 18 | 19 | \S4method{subset}{funData}(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x)) 20 | 21 | \S4method{subset}{multiFunData}(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x)) 22 | 23 | \S4method{subset}{irregFunData}(x, obs = seq_len(nObs(x)), argvals = funData::argvals(x)) 24 | 25 | \S4method{[}{funData,ANY,missing,missing}(x, i, j, ..., drop = TRUE) 26 | 27 | \S4method{[}{multiFunData,ANY,missing,missing}(x, i, j, ..., drop = TRUE) 28 | 29 | \S4method{[}{irregFunData,ANY,missing,missing}(x, i = seq_len(nObs(x)), j, ..., drop = TRUE) 30 | } 31 | \arguments{ 32 | \item{object}{An object of class \code{funData}, \code{irregFunData} or 33 | \code{multiFunData}.} 34 | 35 | \item{obs}{A numeric vector, giving the indices of the observations to 36 | extract (default: all observations).} 37 | 38 | \item{argvals}{The part of the domain to be extracted (default: the 39 | whole domain \code{object}@\code{argvals}). Must be a list or a 40 | numeric vector (only for one-dimensional domains, see also the 41 | definition of \code{\linkS4class{funData}}, 42 | \code{\linkS4class{multiFunData}}).} 43 | 44 | \item{x}{An object of class \code{funData}, \code{irregFunData} or 45 | \code{multiFunData} (for \code{subset}).} 46 | 47 | \item{i}{A numeric vector, giving the indices of the observations to 48 | extract when using \code{x[i]}. Defaults to all observations.} 49 | 50 | \item{j, drop}{not used} 51 | 52 | \item{...}{Used to pass further arguments to \code{extractObs}. Here 53 | only usable for \code{argvals}.} 54 | } 55 | \value{ 56 | An object of class \code{funData}, \code{irregFunData} or 57 | \code{multiFunData} containing the desired observations. 58 | } 59 | \description{ 60 | This function extracts one or more observations and/or observations on 61 | a part of the domain from a \code{funData}, \code{irregFunData} or 62 | \code{multiFunData} object. 63 | } 64 | \details{ 65 | In case of an \code{irregFunData} object, some functions may not have 66 | observation points in the given part of the domain. In this case, the 67 | functions are removed from the extracted dataset and a warning is 68 | thrown. 69 | 70 | If only observations are to be extracted, the usual notation 71 | \code{object[1:3]} is equivalent to \code{extractObs(object, obs = 72 | 1:3)}. This works only if the domain remains unchanged. 73 | } 74 | \section{Functions}{ 75 | \itemize{ 76 | \item \code{x[i}: 77 | 78 | }} 79 | \section{Warning}{ 80 | The function is currently implemented only for 81 | functional data with up to three-dimensional domains. 82 | } 83 | 84 | \section{Alias}{ 85 | The function \code{subset} is an alias for 86 | \code{extractObs}. 87 | } 88 | 89 | \examples{ 90 | # Univariate - one-dimensional domain 91 | object1 <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 92 | extractObs(object1, obs = 1) 93 | extractObs(object1, argvals = 1:3) 94 | extractObs(object1, argvals = list(1:3)) # the same as the statement before 95 | # alias 96 | subset(object1, argvals = 1:3) 97 | 98 | # Univariate - two-dimensional domains 99 | object2 <- funData(argvals = list(1:5, 1:6), X = array(1:60, dim = c(2, 5, 6))) 100 | extractObs(object2, obs = 1) 101 | extractObs(object2, argvals = list(1:3, c(2,4,6))) # argvals must be supplied as list 102 | 103 | # Univariate - irregular 104 | irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 105 | extractObs(irregObject, obs = 2) 106 | extractObs(irregObject, argvals = 1:3) 107 | extractObs(irregObject, argvals = c(1,5)) # throws a warning, as second function has no observations 108 | 109 | # Multivariate 110 | multiObject <- multiFunData(object1, object2) 111 | extractObs(multiObject, obs = 2) 112 | multiObject[2] # shorthand 113 | extractObs(multiObject, argvals = list(1:3, list(1:3, c(2,4,6)))) 114 | 115 | 116 | ### Shorthand via "[]" 117 | object1[1] 118 | object1[argvals = 1:3] 119 | object2[1] 120 | object2[argvals = list(1:3, c(2,4,6))] 121 | irregObject[2] 122 | irregObject[argvals = 1:3] 123 | } 124 | \seealso{ 125 | \code{\linkS4class{funData}}, 126 | \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}} 127 | } 128 | -------------------------------------------------------------------------------- /man/extrapolateIrreg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{extrapolateIrreg} 4 | \alias{extrapolateIrreg} 5 | \title{Extrapolate irregular functional data to a given domain} 6 | \usage{ 7 | extrapolateIrreg(object, rangex = range(object@argvals)) 8 | } 9 | \description{ 10 | This function extrapolates an \code{irregFunData} object to a given domain. 11 | If only one point is observed, the function is extrapolated as a constant; in 12 | all other cases it is extrapolated linearly. 13 | } 14 | \keyword{internal} 15 | -------------------------------------------------------------------------------- /man/fd2funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coerce.R 3 | \name{fd2funData} 4 | \alias{fd2funData} 5 | \title{Convert an fd object to funData} 6 | \usage{ 7 | fd2funData(fdobj, argvals, ...) 8 | } 9 | \arguments{ 10 | \item{fdobj}{An \code{fd} object} 11 | 12 | \item{argvals}{A vector or a list of length one, containing a vector 13 | with argument values at which the functions in \code{fdobj} should be 14 | evaluated.} 15 | 16 | \item{...}{Other parameters passed to \code{\link[fda]{eval.fd}}.} 17 | } 18 | \value{ 19 | An object of class \code{\link{funData}}. 20 | } 21 | \description{ 22 | This function converts an object of class \code{\link[fda]{fd}} (from 23 | package \pkg{fda}) to an object of class \code{\link{funData}}. It 24 | heavily builds on the function \code{\link[fda]{eval.fd}} from the 25 | \pkg{fda} package. The \code{\link[fda]{fd}} representation assumes a 26 | basis representation for the observed functions and therefore 27 | implicitly smoothes the data. In \code{funData} objects, the data is 28 | saved in 'raw' format. 29 | } 30 | \section{Warning}{ 31 | Time names in \code{fdobj$fdnames$time} are not 32 | preserved. 33 | } 34 | 35 | \examples{ 36 | # Install / load package fda before running the examples 37 | library("fda") 38 | 39 | # from Data2fd help 40 | daybasis <- create.fourier.basis(c(0, 365), nbasis=65) 41 | # fd object of daily temperatures 42 | tempfd <- Data2fd(argvals = day.5, y = CanadianWeather$dailyAv[,,"Temperature.C"], daybasis) 43 | # convert to funData 44 | tempFun <- fd2funData(tempfd, argvals = day.5) 45 | 46 | # plot to compare 47 | par(mfrow = c(1,2)) 48 | plot(tempfd, main = "fd object") 49 | plot(tempFun, main = "funData object") 50 | } 51 | \seealso{ 52 | \code{\linkS4class{funData}}, \code{\link[fda]{fd}}, 53 | \code{\link[fda]{eval.fd}} 54 | } 55 | -------------------------------------------------------------------------------- /man/flipFuns-funData-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{flipFuns,funData,funData-method} 4 | \alias{flipFuns,funData,funData-method} 5 | \title{Flip univariate functional data} 6 | \usage{ 7 | \S4method{flipFuns}{funData,funData}(refObject, newObject) 8 | } 9 | \description{ 10 | Flip univariate functional data 11 | } 12 | \seealso{ 13 | \code{\link{flipFuns}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/flipFuns-funData-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{flipFuns,funData,irregFunData-method} 4 | \alias{flipFuns,funData,irregFunData-method} 5 | \title{Flip irregular functional data - funData as reference} 6 | \usage{ 7 | \S4method{flipFuns}{funData,irregFunData}(refObject, newObject, ...) 8 | } 9 | \description{ 10 | Flip irregular functional data - funData as reference 11 | } 12 | \seealso{ 13 | \code{\link{flipFuns}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/flipFuns-irregFunData-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{flipFuns,irregFunData,irregFunData-method} 4 | \alias{flipFuns,irregFunData,irregFunData-method} 5 | \title{Flip irregular functional data - irregFunData as reference} 6 | \usage{ 7 | \S4method{flipFuns}{irregFunData,irregFunData}(refObject, newObject, ...) 8 | } 9 | \description{ 10 | Flip irregular functional data - irregFunData as reference 11 | } 12 | \seealso{ 13 | \code{\link{flipFuns}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/flipFuns-multiFunData-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{flipFuns,multiFunData,multiFunData-method} 4 | \alias{flipFuns,multiFunData,multiFunData-method} 5 | \title{Flip multivariate functional data} 6 | \usage{ 7 | \S4method{flipFuns}{multiFunData,multiFunData}(refObject, newObject) 8 | } 9 | \description{ 10 | Flip multivariate functional data 11 | } 12 | \seealso{ 13 | \code{\link{flipFuns}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/flipFuns.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{flipFuns} 4 | \alias{flipFuns} 5 | \title{Flip functional data objects} 6 | \usage{ 7 | flipFuns(refObject, newObject, ...) 8 | } 9 | \arguments{ 10 | \item{refObject}{An object of class \code{funData}, \code{irregFunData} or 11 | \code{multiFunData} that serves as reference. It must have the same number 12 | of observations as \code{newObject} or have only one observation. In this 13 | case, all observations in \code{newObject} are flipped with respect to this 14 | single observation.} 15 | 16 | \item{newObject}{An object of class \code{funData}, \code{irregFunData} or 17 | \code{multiFunData} that is to be flipped with respect to \code{refObject}.} 18 | 19 | \item{...}{Further parameters passed to \code{\link{norm}}.} 20 | } 21 | \value{ 22 | An object of the same class as \code{newData} with flipped 23 | observations. 24 | } 25 | \description{ 26 | This function flips an object \code{newObject} of class \code{funData}, 27 | \code{irregFunData} or \code{multiFunData} with respect to a reference object 28 | \code{refObject} of the same class (or of class \code{funData}, if 29 | \code{newObject} is irregular). This is particularly useful when dealing with 30 | functional principal components, as they are only defined up to a sign 31 | change. For details, see below. 32 | } 33 | \details{ 34 | Functional principal component analysis is an important tool in functional 35 | data analysis. Just as eigenvectors, eigenfunctions (or functional principal 36 | components) are only defined up to a sign change. This may lead to 37 | difficulties in simulation studies or when bootstrapping pointwise confidence 38 | bands, as in these cases one wants the estimates to have the same 39 | "orientation" as the true function (in simulation settings) or the 40 | non-bootstrapped estimate (when calculating bootstrap confidence bands). This 41 | function allows to flip (i.e. multiply by \eqn{-1}{-1}) all observations in 42 | \code{newObject} that have a different orientation than their counterparts in 43 | \code{refData}. 44 | 45 | Technically, the function compares the distance between \code{newObject} and 46 | \code{refObject} \deqn{|||f_\mathrm{new} - f_\mathrm{ref}|||}{||| f_{new} - 47 | f_{ref}|||} and the distance between \code{newObject} and 48 | \code{-1 * refObject} \deqn{|||f_\mathrm{new} + f_\mathrm{ref}|||.}{||| f_{new} + 49 | f_{ref}|||.} If \code{newObject} is closer to \code{-1 * refObject}, it is 50 | flipped, i.e. multiplied by -1. 51 | } 52 | \section{Warning}{ 53 | 54 | The function is currently implemented only for functional data with one- and 55 | two-dimensional domains. 56 | } 57 | 58 | \examples{ 59 | 60 | ### Univariate 61 | argvals <- seq(0,2*pi,0.01) 62 | refData <- funData(argvals, rbind(sin(argvals))) # one observation as reference 63 | newData <- funData(argvals, outer(sample(c(-1,1), 11, replace = TRUE) * seq(0.75, 1.25, by = 0.05), 64 | sin(argvals))) 65 | 66 | oldpar <- par(no.readonly = TRUE) 67 | par(mfrow = c(1,2)) 68 | 69 | plot(newData, col = "grey", main = "Original data") 70 | plot(refData, col = "red", lwd = 2, add = TRUE) 71 | 72 | plot(flipFuns(refData, newData), col = "grey", main = "Flipped data") 73 | plot(refData, col = "red", lwd = 2, add = TRUE) 74 | 75 | ### Univariate (irregular) 76 | ind <- replicate(11, sort(sample(1:length(argvals), sample(5:10,1)))) # sample observation points 77 | argvalsIrreg <- lapply(ind, function(i){argvals[i]}) 78 | argvalsIrregAll <- unique(sort(unlist(argvalsIrreg))) 79 | # one observation as reference (fully observed) 80 | refDataFull <- funData(argvals, rbind(sin(argvals))) 81 | # one observation as reference (irregularly observed) 82 | refDataIrreg <- irregFunData(argvals = list(argvalsIrregAll), X = list(sin(argvalsIrregAll))) 83 | newData <- irregFunData(argvals = argvalsIrreg, X = mapply(function(x, a, s){s * a * sin(x)}, 84 | x = argvalsIrreg, a = seq(0.75, 1.25, by = 0.05), s = sample(c(-1,1), 11, replace = TRUE))) 85 | 86 | plot(newData, col = "grey", main = "Original data (regular reference)") 87 | plot(refDataFull, col = "red", lwd = 2, add = TRUE) 88 | 89 | plot(flipFuns(refDataFull, newData), col = "grey", main = "Flipped data") 90 | plot(refDataFull, col = "red", lwd = 2, add = TRUE) 91 | 92 | plot(newData, col = "grey", main = "Original data (irregular reference)") 93 | plot(refDataIrreg, col = "red", lwd = 2, add = TRUE) 94 | 95 | plot(flipFuns(refDataIrreg, newData), col = "grey", main = "Flipped data") 96 | plot(refDataIrreg, col = "red", lwd = 2, add = TRUE) 97 | 98 | ### Multivariate 99 | refData <- multiFunData(funData(argvals, rbind(sin(argvals))), # one observation as reference 100 | funData(argvals, rbind(cos(argvals)))) 101 | sig <- sample(c(-1,1), 11, replace = TRUE) 102 | newData <- multiFunData(funData(argvals, outer(sig * seq(0.75, 1.25, by = 0.05), sin(argvals))), 103 | funData(argvals, outer(sig * seq(0.75, 1.25, by = 0.05), cos(argvals)))) 104 | 105 | par(mfrow = c(2,2)) 106 | 107 | plot(newData[[1]], col = topo.colors(11), main = "Original data") 108 | plot(refData[[1]], col = "red", lwd = 2, add = TRUE) 109 | 110 | plot(newData[[2]], col = topo.colors(11), main = "Original data") 111 | plot(refData[[2]], col = "red", lwd = 2, add = TRUE) 112 | 113 | plot(flipFuns(refData, newData)[[1]], col = topo.colors(11), main = "Flipped data") 114 | plot(refData[[1]], col = "red", lwd = 2, add = TRUE) 115 | 116 | plot(flipFuns(refData, newData)[[2]], col = topo.colors(11), main = "Flipped data") 117 | plot(refData[[2]], col = "red", lwd = 2, add = TRUE) 118 | 119 | par(oldpar) 120 | } 121 | \seealso{ 122 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, 123 | \code{\linkS4class{multiFunData}}, \code{\link{Arith.funData}} 124 | } 125 | -------------------------------------------------------------------------------- /man/funData-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R, R/funDataMethods.R, R/names.R, 3 | % R/str.R, R/summary.R 4 | \docType{class} 5 | \name{funData-class} 6 | \alias{funData-class} 7 | \alias{funData} 8 | \alias{funData,list,array-method} 9 | \alias{funData,numeric,array-method} 10 | \alias{show,funData-method} 11 | \alias{names,funData-method} 12 | \alias{names<-,funData-method} 13 | \alias{str,funData-method} 14 | \alias{summary,funData-method} 15 | \title{A class for (univariate) functional data} 16 | \usage{ 17 | funData(argvals, X) 18 | 19 | \S4method{funData}{list,array}(argvals, X) 20 | 21 | \S4method{funData}{numeric,array}(argvals, X) 22 | 23 | \S4method{show}{funData}(object) 24 | 25 | \S4method{names}{funData}(x) 26 | 27 | \S4method{names}{funData}(x) <- value 28 | 29 | \S4method{str}{funData}(object, ...) 30 | 31 | \S4method{summary}{funData}(object, ...) 32 | } 33 | \arguments{ 34 | \item{argvals}{A list of numeric vectors or a single numeric vector, giving the 35 | sampling points in the domains. See Details.} 36 | 37 | \item{X}{An array of dimension \eqn{N \times M}{N x M} (for one-dimensional 38 | domains, or \eqn{N \times M_1 \times \ldots \times M_d}{N x M_1 x \ldots x 39 | M_d} for higher-dimensional domains), giving the observed values for 40 | \eqn{N}{N} individuals. Missing values can be included via \code{NA}. See 41 | Details.} 42 | 43 | \item{object}{A \code{funData} object.} 44 | 45 | \item{x}{The \code{funData} object.} 46 | 47 | \item{value}{The names to be given to the \code{funData} curves.} 48 | 49 | \item{...}{Other parameters passed to \code{summary}.} 50 | } 51 | \description{ 52 | The \code{funData} class represents functional data on \eqn{d}{d}-dimensional 53 | domains. The two slots represent the domain (x-values) and the values of the 54 | different observations (y-values). 55 | } 56 | \details{ 57 | Functional data can be seen as realizations of a random process \deqn{X: 58 | \mathcal{T} \to \mathrm{IR}}{X: T -> IR} on a \eqn{d}{d}-dimensional 59 | domain \eqn{\mathcal{T}}{T}. The data is usually sampled on a fine grid 60 | \eqn{T \subset \mathcal{T}}{T subset of T}, which is represented in the 61 | \code{argvals} slot of a \code{funData} object. All observations are assumed 62 | to be sampled over the same grid \eqn{T}{T}, but can contain missing values 63 | (see below). If \eqn{\mathcal{T}}{T} is one-dimensional, \code{argvals} 64 | can be supplied either as a numeric vector, containing the x-values or as a 65 | list, containing such a vector. If \eqn{\mathcal{T}}{T} is 66 | higher-dimensional, \code{argvals} must always be supplied as a list, 67 | containing numeric vectors of the x-values in dimensions 68 | \eqn{1,\ldots,d}{1,\ldots,d}. 69 | 70 | The observed values are represented in the \code{X} slot of a \code{funData} 71 | object, which is an array of dimension \eqn{N \times M}{N x M} (for 72 | one-dimensional domains, or \eqn{N \times M_1 \times \ldots \times M_d}{N x 73 | M_1 x \ldots x M_d} for higher-dimensional domains). Here \eqn{N}{N} equals 74 | the number of observations and \eqn{M}{M} denotes the number of sampling 75 | points (for higher dimensional domains \eqn{M_i}{M_i} denotes the number of 76 | sampling points in dimension \eqn{i, i = 1,\ldots, d}{i, i = 1,\ldots, d}). 77 | Missing values in the observations are allowed and must be marked by 78 | \code{NA}. If missing values occur due to irregular observation points, the 79 | data can be stored alternatively as an object of class 80 | \code{\linkS4class{irregFunData}}. 81 | 82 | Generic functions for the \code{funData} class include a print method, 83 | \link[=plot.funData]{plotting} and \link[=Arith.funData]{basic arithmetics}. 84 | Further methods for \code{funData}: \itemize{ \item \code{\link{dimSupp}}, 85 | \code{\link{nObs}}: Informations about the support dimensions and the number 86 | of observations, \item \code{\link{getArgvals}}, \code{\link{extractObs}}: 87 | Getting/Setting slot values (instead of accessing them directly via 88 | \code{funData@argvals, funData@X}) and extracting single observations or 89 | data on a subset of the domain, \item \code{\link{integrate}}, 90 | \code{\link{norm}}: Integrate all observations over their domain or 91 | calculating the \eqn{L^2}{L^2} norm.} 92 | 93 | A \code{funData} object can be coerced to a \code{multiFunData} object using 94 | \code{as.multiFunData(funDataObject).} 95 | } 96 | \section{Methods (by generic)}{ 97 | \itemize{ 98 | \item \code{funData(argvals = list, X = array)}: Constructor for functional data objects with \code{argvals} given as list. 99 | 100 | \item \code{funData(argvals = numeric, X = array)}: Constructor for functional data objects with \code{argvals} 101 | given as vector of numerics (only valid for one-dimensional domains). 102 | 103 | \item \code{show(funData)}: Print basic information about the \code{funData} object 104 | in the console. The default console output for \code{funData} objects. 105 | 106 | \item \code{names(funData)}: Get the names of the \code{funData} object. 107 | 108 | \item \code{names(funData) <- value}: Set the names of the \code{funData} object. 109 | 110 | \item \code{str(funData)}: A \code{str} method for \code{funData} objects, giving a compact overview of the structure. 111 | 112 | \item \code{summary(funData)}: A \code{summary} method for \code{funData} objects. 113 | 114 | }} 115 | \section{Functions}{ 116 | \itemize{ 117 | \item \code{funData()}: Constructor for functional data objects, first argument (argvals) passed as list or vector of numerics 118 | 119 | }} 120 | \section{Slots}{ 121 | 122 | \describe{ 123 | \item{\code{argvals}}{The domain \eqn{\mathcal{T}}{T} of the data. See Details.} 124 | 125 | \item{\code{X}}{The functional data samples. See Details.} 126 | }} 127 | 128 | \examples{ 129 | ### Creating a one-dimensional funData object with 2 observations 130 | # Basic 131 | f1 <- new("funData", argvals = list(1:5), X = rbind(1:5,6:10)) 132 | # Using the constructor with first argument supplied as array 133 | f2 <- funData(argvals = list(1:5), X = rbind(1:5, 6:10)) 134 | # Using the constructor with first argument supplied as numeric vector 135 | f3 <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 136 | # Test if all the same 137 | all.equal(f1,f2) 138 | all.equal(f1,f3) 139 | # Display funData object in the console 140 | f3 141 | 142 | # A more realistic object 143 | argvals <- seq(0,2*pi,0.01) 144 | object <- funData(argvals, outer(seq(0.75, 1.25, by = 0.05), sin(argvals))) 145 | # Display / summary give basic information 146 | object 147 | summary(object) 148 | # Use the plot function to get an impression of the data 149 | plot(object) 150 | 151 | 152 | ### Higher-dimensional funData objects with 2 observations 153 | # Basic 154 | g1 <- new("funData", argvals = list(1:5, 1:3), 155 | X = array(1:30, dim = c(2,5,3))) 156 | # Using the constructor 157 | g2 <- funData(argvals = list(1:5, 1:3), 158 | X = array(1:30, dim = c(2,5,3))) 159 | # Test if the same 160 | all.equal(g1,g2) 161 | # Display funData object in the console 162 | g2 163 | # Summarize information 164 | summary(g2) 165 | } 166 | \seealso{ 167 | \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}} 168 | } 169 | -------------------------------------------------------------------------------- /man/funData-setAs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R 3 | \name{funData-setAs} 4 | \alias{funData-setAs} 5 | \title{Coerce a funData object to class multiFunData} 6 | \description{ 7 | Coerce a funData object to class multiFunData 8 | 9 | Coerce a funData object to class irregFunData 10 | } 11 | \examples{ 12 | # create funData object with 5 observations 13 | f <- simFunData(N = 5, M = 7, eValType = "linear", 14 | eFunType = "Fourier", argvals = seq(0,1,0.01))$simData 15 | 16 | # sparsify artificially 17 | fSparse <- sparsify(f, minObs = 4, maxObs = 10) 18 | 19 | # coerce to irregFunData object 20 | i <- as.irregFunData(fSparse) 21 | i 22 | } 23 | \seealso{ 24 | \code{\linkS4class{funData}}, \code{\link{as.multiFunData}} 25 | 26 | \code{\linkS4class{funData}}, \code{\link{as.irregFunData}} 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/funData2fd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coerce.R 3 | \name{funData2fd} 4 | \alias{funData2fd} 5 | \title{Convert a funData object to fd} 6 | \usage{ 7 | funData2fd(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A \code{funData} object} 11 | 12 | \item{...}{Other parameters passed to \code{\link[fda]{Data2fd}}.} 13 | } 14 | \value{ 15 | An object of class \code{\link[fda]{fd}}. 16 | } 17 | \description{ 18 | This function converts an object of class \code{\link{funData}} to an 19 | object of class \code{\link[fda]{fd}} (from package \pkg{fda}). It 20 | heavily builds on the function \code{\link[fda]{Data2fd}} from the 21 | \pkg{fda} package. The \code{\link[fda]{fd}} representation assumes a 22 | basis representation for the observed functions and therefore 23 | implicitly smoothes the data. In \code{funData} objects, the data is 24 | saved in 'raw' format. 25 | } 26 | \section{Warning}{ 27 | This function works only for funData objects on 28 | one-dimensional domains. 29 | } 30 | 31 | \examples{ 32 | # Install / load package fda before running the examples 33 | library("fda") 34 | 35 | # from Data2fd help 36 | daybasis <- create.fourier.basis(c(0, 365), nbasis=65) 37 | # funData object with temperature 38 | tempFun <- funData(day.5, t(CanadianWeather$dailyAv[, , "Temperature.C"])) 39 | # convert to fd 40 | tempfd <- funData2fd(tempFun, daybasis) 41 | 42 | # plot to compare 43 | par(mfrow = c(1,2)) 44 | plot(tempFun, main = "funData object (raw data)") 45 | plot(tempfd, main = "fd object (smoothed)") 46 | } 47 | \seealso{ 48 | \code{\linkS4class{funData}}, \code{\link[fda]{fd}}, 49 | \code{\link[fda]{Data2fd}}, \code{\link{fd2funData}} 50 | } 51 | -------------------------------------------------------------------------------- /man/ggplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{ggplot} 4 | \alias{ggplot} 5 | \alias{ggplot,funData-method} 6 | \alias{ggplot,multiFunData-method} 7 | \alias{ggplot,irregFunData-method} 8 | \title{ggplot Graphics for Functional Data Objects} 9 | \usage{ 10 | ggplot(data, ...) 11 | 12 | \S4method{ggplot}{funData}(data, add = FALSE, ...) 13 | 14 | \S4method{ggplot}{multiFunData}(data, ...) 15 | 16 | \S4method{ggplot}{irregFunData}(data, add = FALSE, ...) 17 | } 18 | \arguments{ 19 | \item{data}{A \code{funData}, \code{multiFunData} or 20 | \code{irregFunData} object.} 21 | 22 | \item{...}{Further parameters passed to the class-specific methods.} 23 | 24 | \item{add}{Logical. If \code{TRUE}, add to current plot (only for 25 | one-dimensional functions). Defaults to \code{FALSE}.} 26 | } 27 | \value{ 28 | A \code{\link[ggplot2]{ggplot}} object 29 | } 30 | \description{ 31 | This function is deprecated. Use \code{\link{autoplot.funData}} / 32 | \code{\link{autolayer.funData}} for \code{funData} objects, 33 | \code{\link{autoplot.multiFunData}} for \code{multiFunData} objects and 34 | \code{\link{autoplot.irregFunData}} / 35 | \code{\link{autolayer.irregFunData}} for \code{irregFunData} objects 36 | instead. 37 | } 38 | \details{ 39 | In the default case, this function calls \link[ggplot2]{ggplot} (if available). 40 | } 41 | \seealso{ 42 | \code{\link[ggplot2]{ggplot}}, 43 | \code{\link[ggplot2]{autoplot}}, \code{\link[ggplot2]{autolayer}} 44 | from package \pkg{ggplot2} 45 | } 46 | -------------------------------------------------------------------------------- /man/integrate-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{integrate,funData-method} 4 | \alias{integrate,funData-method} 5 | \title{Integrate method for funData objects} 6 | \usage{ 7 | \S4method{integrate}{funData}(object, method = "trapezoidal") 8 | } 9 | \description{ 10 | Integrate method for funData objects 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\linkS4class{funData}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/integrate-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{integrate,irregFunData-method} 4 | \alias{integrate,irregFunData-method} 5 | \title{Integrate method for irregular functional data objects} 6 | \usage{ 7 | \S4method{integrate}{irregFunData}(object, method = "trapezoidal", fullDom = FALSE) 8 | } 9 | \description{ 10 | Integrate method for irregular functional data objects 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\linkS4class{irregFunData}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/integrate-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{integrate,multiFunData-method} 4 | \alias{integrate,multiFunData-method} 5 | \title{Integrate method for multiFunData objects} 6 | \usage{ 7 | \S4method{integrate}{multiFunData}(object, ...) 8 | } 9 | \description{ 10 | Integrate method for multiFunData objects 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\linkS4class{multiFunData}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/integrate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{integrate} 4 | \alias{integrate} 5 | \title{Integrate functional data} 6 | \usage{ 7 | integrate(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{funData}, \code{irregFunData} or 11 | \code{multiFunData}.} 12 | 13 | \item{...}{Further parameters (see Details).} 14 | } 15 | \value{ 16 | A vector of numerics, containing the integral values for each 17 | observation. 18 | } 19 | \description{ 20 | Integrate all observations of a \code{funData}, \code{irregFunData} or 21 | \code{multiFunData} object over their domain. 22 | } 23 | \details{ 24 | Further parameters passed to this function may include: \itemize{ \item 25 | \code{method}: Character string. The integration rule to be used, passed to 26 | the internal function \code{.intWeights}. Defaults to \code{"trapezoidal"} 27 | (alternative: \code{"midpoint"}). \item \code{fullDom}: Logical. If 28 | \code{object} is of class \code{irregFunData}, setting fullDom = \code{TRUE} 29 | extrapolates all functions linearly to the full domain before calculating the 30 | integrals. Defaults to \code{FALSE}. For details on the extrapolation, see 31 | \code{\link{extrapolateIrreg}}.} 32 | } 33 | \section{Warning}{ 34 | The function is currently implemented only for functional 35 | data with up to three-dimensional domains. In the default case, this 36 | function calls \link[stats]{integrate}. 37 | } 38 | 39 | \examples{ 40 | # Univariate 41 | object <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 42 | integrate(object) 43 | 44 | # Univariate (irregular) 45 | irregObject <-irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 46 | integrate(irregObject) # fullDom = FALSE 47 | integrate(irregObject, fullDom = TRUE) 48 | 49 | # Multivariate 50 | multiObject <- multiFunData(object, funData(argvals = 1:3, X = rbind(3:5, 6:8))) 51 | integrate(multiObject) 52 | } 53 | \seealso{ 54 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, 55 | \code{\linkS4class{multiFunData}} 56 | } 57 | -------------------------------------------------------------------------------- /man/integrate3D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{integrate3D} 4 | \alias{integrate3D} 5 | \title{Integrate a function on a rectangular 3D grid} 6 | \usage{ 7 | integrate3D(f, argvals) 8 | } 9 | \arguments{ 10 | \item{f}{A 3D array, representing the function evaluations on the grid} 11 | 12 | \item{argvals}{A list with 3 elements, representing the grid points in the first, second and third dimension of f} 13 | } 14 | \value{ 15 | The result of the numerical integration of f on the given grid. 16 | } 17 | \description{ 18 | Integrate a function on a rectangular 3D grid 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/irregFunData-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R, R/funDataMethods.R, R/names.R, 3 | % R/str.R, R/summary.R 4 | \docType{class} 5 | \name{irregFunData-class} 6 | \alias{irregFunData-class} 7 | \alias{irregFunData} 8 | \alias{irregFunData,list,list-method} 9 | \alias{show,irregFunData-method} 10 | \alias{names,irregFunData-method} 11 | \alias{names<-,irregFunData-method} 12 | \alias{str,irregFunData-method} 13 | \alias{summary,irregFunData-method} 14 | \title{A class for irregularly sampled functional data} 15 | \usage{ 16 | irregFunData(argvals, X) 17 | 18 | \S4method{irregFunData}{list,list}(argvals, X) 19 | 20 | \S4method{show}{irregFunData}(object) 21 | 22 | \S4method{names}{irregFunData}(x) 23 | 24 | \S4method{names}{irregFunData}(x) <- value 25 | 26 | \S4method{str}{irregFunData}(object, ...) 27 | 28 | \S4method{summary}{irregFunData}(object, ...) 29 | } 30 | \arguments{ 31 | \item{argvals}{A list of numerics, corresponding to the observation points for each realization \eqn{X_i} (see Details).} 32 | 33 | \item{X}{A list of numerics, corresponding to the observed functions \eqn{X_i} (see Details).} 34 | 35 | \item{object}{An \code{irregFunData} object.} 36 | 37 | \item{x}{The \code{irregFunData} object.} 38 | 39 | \item{value}{The names to be given to the \code{irregFunData} curves.} 40 | 41 | \item{...}{Other parameters passed to \code{summary}.} 42 | } 43 | \description{ 44 | The \code{irregFunData} class represents functional data that is sampled 45 | irregularly on one-dimensional domains. The two slots represent the 46 | observation points (x-values) and the observed function values (y-values). 47 | } 48 | \details{ 49 | Irregular functional data are realizations of a random process \deqn{X: 50 | \mathcal{T} \to \mathrm{IR},}{X: T -> IR,} where each realization 51 | \eqn{X_i} of \eqn{X} is given on an individual grid \eqn{T_i \subset 52 | \mathcal{T}}{T_i \subset T} of observation points. As for the 53 | \code{\linkS4class{funData}} class, each object of the \code{irregFunData} 54 | class has two slots; the \code{argvals} slot represents the observation 55 | points and the \code{X} slot represents the observed data. In contrast to the 56 | regularly sampled data, both slots are defined as lists of vectors, where 57 | each entry corresponds to one observed function: \itemize{\item 58 | \code{argvals[[i]]} contains the vector of observation points \eqn{T_i} for 59 | the i-th function, \item \code{X[[i]]} contains the corresponding observed 60 | data \eqn{X_i(t_{ij}), t_{ij} \in T_i}.} 61 | 62 | Generic functions for the \code{irregFunData} class include a print method, 63 | \link[=plot.irregFunData]{plotting} and \link[=Arith.funData]{basic 64 | arithmetics}. Further methods for \code{irregFunData}: \itemize{ \item 65 | \code{\link{dimSupp}}, \code{\link{nObs}}: Informations about the support 66 | dimensions and the number of observations, \item \code{\link{getArgvals}}, 67 | \code{\link{extractObs}}: Getting/setting slot values (instead of accessing 68 | them directly via \code{irregObject@argvals, irregObject@X}) and extracting 69 | single observations or data on a subset of the domain, \item 70 | \code{\link{integrate}}, \code{\link{norm}}: Integrate all observations over 71 | their domain or calculating the \eqn{L^2}{L^2} norm.} 72 | 73 | An \code{irregFunData} object can be coerced to a \code{funData} object using 74 | \code{as.funData(irregObject)}. The regular functional data object is defined 75 | on the union of all observation grids of the irregular object. The value of 76 | the new object is marked as missing (\code{NA}) for observation points that 77 | are in the union, but not in the original observation grid. 78 | } 79 | \section{Methods (by generic)}{ 80 | \itemize{ 81 | \item \code{irregFunData(argvals = list, X = list)}: Constructor for irregular functional data 82 | objects. 83 | 84 | \item \code{show(irregFunData)}: Print basic information about the \code{irregFunData} object 85 | in the console. The default console output for \code{irregFunData} objects. 86 | 87 | \item \code{names(irregFunData)}: Get the names of the \code{irregFunData} object. 88 | 89 | \item \code{names(irregFunData) <- value}: Set the names of the \code{irregFunData} object. 90 | 91 | \item \code{str(irregFunData)}: A \code{str} method for \code{irregFunData} objects, giving a compact overview of the structure. 92 | 93 | \item \code{summary(irregFunData)}: A \code{summary} method for \code{irregFunData} objects. 94 | 95 | }} 96 | \section{Functions}{ 97 | \itemize{ 98 | \item \code{irregFunData()}: Constructor for irregular functional data objects 99 | 100 | }} 101 | \section{Slots}{ 102 | 103 | \describe{ 104 | \item{\code{argvals}}{A list of numerics, representing the observation grid \eqn{T_i} 105 | for each realization \eqn{X_i} of \eqn{X}.} 106 | 107 | \item{\code{X}}{A list of numerics, representing the values of each observation 108 | \eqn{X_i} of \eqn{X} on the corresponding observation points \eqn{T_i}.} 109 | }} 110 | 111 | \section{Warning}{ 112 | Currently, the class is implemented only for functional 113 | data on one-dimensional domains \eqn{\mathcal{T} \subset \mathrm{IR}}{T 114 | \subset IR}. 115 | } 116 | 117 | \examples{ 118 | # Construct an irregular functional data object 119 | i1 <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 120 | # Display in the console 121 | i1 122 | # Summarize 123 | summary(i1) 124 | 125 | # A more realistic object 126 | argvals <- seq(0,2*pi, 0.01) 127 | ind <- replicate(11, sort(sample(1:length(argvals), sample(5:10,1)))) # sample observation points 128 | argvalsIrreg <- lapply(ind, function(i){argvals[i]}) 129 | i2 <- irregFunData(argvals = argvalsIrreg, X = mapply(function(x, a){a * sin(x)}, 130 | x = argvalsIrreg, a = seq(0.75, 1.25, by = 0.05))) 131 | # Display/summary gives basic information 132 | i2 133 | summary(i2) 134 | # Use the plot function to get an impression of the data 135 | plot(i2) 136 | } 137 | \seealso{ 138 | \code{\linkS4class{funData}}, \code{\linkS4class{multiFunData}} 139 | } 140 | -------------------------------------------------------------------------------- /man/irregFunData-setAs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R 3 | \name{irregFunData-setAs} 4 | \alias{irregFunData-setAs} 5 | \title{Coerce an irregFunData object to class funData} 6 | \description{ 7 | Coerce an irregFunData object to class funData 8 | } 9 | \examples{ 10 | # create irregFunData object with 2 observations 11 | i1 <- irregFunData(argvals = list(1:5, 3:6), X = list(2:6, 4:7)) 12 | i1@argvals # argvals and X are both lists with 2 entries 13 | i1@X 14 | 15 | # coerce to funData object (with missing values) 16 | f1 <- as.funData(i1) 17 | # argvals is a list containing one vector 18 | # (one-dimensional domain, union of all observation points) 19 | f1@argvals 20 | # X is a matrix with 2 rows and missing values 21 | f1@X 22 | } 23 | \seealso{ 24 | \code{\linkS4class{funData}}, \code{\link{as.funData}} 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/meanFunction-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{meanFunction,funData-method} 4 | \alias{meanFunction,funData-method} 5 | \title{Mean for functional data} 6 | \usage{ 7 | \S4method{meanFunction}{funData}(object, na.rm = FALSE) 8 | } 9 | \description{ 10 | Mean for functional data 11 | } 12 | \seealso{ 13 | \code{\link{meanFunction}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/meanFunction-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{meanFunction,irregFunData-method} 4 | \alias{meanFunction,irregFunData-method} 5 | \title{Mean for irregular functional data} 6 | \usage{ 7 | \S4method{meanFunction}{irregFunData}(object, na.rm = FALSE) 8 | } 9 | \description{ 10 | Mean for irregular functional data 11 | } 12 | \seealso{ 13 | \code{\link{meanFunction}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/meanFunction-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{meanFunction,multiFunData-method} 4 | \alias{meanFunction,multiFunData-method} 5 | \title{Mean for multivariate functional data} 6 | \usage{ 7 | \S4method{meanFunction}{multiFunData}(object, na.rm = FALSE) 8 | } 9 | \description{ 10 | Mean for multivariate functional data 11 | } 12 | \seealso{ 13 | \code{\link{meanFunction}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/meanFunction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{meanFunction} 4 | \alias{meanFunction} 5 | \title{Mean for functional data} 6 | \usage{ 7 | meanFunction(object, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{funData}, \code{irregFunData} or 11 | \code{multiFunData}.} 12 | 13 | \item{na.rm}{Logical. If \code{TRUE}, NA values are removed before computing 14 | the mean. Defaults to \code{FALSE}.} 15 | } 16 | \value{ 17 | An object of the same class as \code{object} with one observation 18 | that corresponds to the pointwise mean function of the functions in 19 | \code{object}. 20 | } 21 | \description{ 22 | This function calculates the pointwise mean function for objects of class 23 | \code{funData}, \code{irregFunData} or \code{multiFunData}. 24 | } 25 | \section{Warning}{ 26 | 27 | If \code{object} is of class \code{irregFunData}, the option \code{na.rm = 28 | TRUE} is not implemented and throws an error. If \code{na.rm = FALSE}, the 29 | functions must be observed on the same domain. 30 | } 31 | 32 | \examples{ 33 | ### Univariate (one-dimensional support) 34 | x <- seq(0, 2*pi, 0.01) 35 | f1 <- funData(x, outer(seq(0.75, 1.25, 0.05), sin(x))) 36 | 37 | plot(f1) 38 | plot(meanFunction(f1), col = 1, lwd = 2, add = TRUE) 39 | 40 | ### Univariate (two-dimensional support) 41 | f2 <- funData(list(1:5, 1:3), array(rep(1:5,each = 11, times = 3), dim = c(11,5,3))) 42 | all.equal(f2[1], meanFunction(f2)) # f2 has 11 identical observations 43 | 44 | ### Multivariate 45 | m1 <- multiFunData(f1,f2) 46 | all.equal(m1[6], meanFunction(m1)) # observation 6 equals the pointwise mean 47 | 48 | ### Irregular 49 | i1 <- irregFunData(argvals = list(1:3,1:3,1:3), X = list(1:3,2:4,3:5)) 50 | all.equal(meanFunction(i1), i1[2]) 51 | # don't run: functions are not defined on the same domain 52 | \dontrun{meanFunction(irregFunData(argvals = list(1:3,1:5), X = list(1:3,1:5))) } 53 | } 54 | \seealso{ 55 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, 56 | \code{\linkS4class{multiFunData}}, \code{\link{Arith.funData}} 57 | } 58 | -------------------------------------------------------------------------------- /man/multiFunData-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataClass.R, R/names.R, R/str.R, R/summary.R 3 | \docType{class} 4 | \name{multiFunData-class} 5 | \alias{multiFunData-class} 6 | \alias{multiFunData} 7 | \alias{multiFunData,ANY-method} 8 | \alias{names,multiFunData-method} 9 | \alias{names<-,multiFunData-method} 10 | \alias{str,multiFunData-method} 11 | \alias{summary,multiFunData-method} 12 | \title{A class for multivariate functional data} 13 | \usage{ 14 | multiFunData(...) 15 | 16 | \S4method{multiFunData}{ANY}(...) 17 | 18 | \S4method{names}{multiFunData}(x) 19 | 20 | \S4method{names}{multiFunData}(x) <- value 21 | 22 | \S4method{str}{multiFunData}(object, ...) 23 | 24 | \S4method{summary}{multiFunData}(object, ...) 25 | } 26 | \arguments{ 27 | \item{...}{A list of funData objects or several funData objects passed as one 28 | argument, each. See Details.} 29 | 30 | \item{x}{The \code{multiFunData} object.} 31 | 32 | \item{value}{The names to be given to the \code{multiFunData} curves.} 33 | 34 | \item{object}{A \code{multiFunData} object.} 35 | } 36 | \description{ 37 | The \code{multiFunData} class represents multivariate functional data on 38 | (potentially) different domains, i.e. a multivariate functional data object 39 | is a vector of (univariate) functional data objects, just as a vector in 40 | \eqn{\mathrm{IR}^n}{IR^n} is a vector of \eqn{n}{n} scalars. In this implementation, a 41 | \code{multiFunData} object is represented as a list of univariate 42 | \code{funData} objects, see Details. 43 | } 44 | \details{ 45 | A \code{multiFunData} object is represented as a list of univariate 46 | \code{funData} objects, each having a \code{argvals} and \code{X} slot, 47 | representing the x-values and the observed y-values (see the 48 | \code{\link{funData}} class). When constructing a \code{multiFunData} object, 49 | the elements can be supplied as a list of \code{funData} objects or can be 50 | passed directly as arguments to the constructor function. 51 | 52 | Most functions implemented for the \code{\link{funData}} class are also 53 | implemented for \code{multiFunData} objects. In most cases, they simply apply 54 | the corresponding univariate method to each element of the multivariate 55 | object and return it as a vector (if the result of the univariate function is 56 | scalar, such as \code{\link{dimSupp}}) or as a \code{multiFunData} object (if 57 | the result of the univariate function is a \code{funData} object, such as 58 | \code{\link{extractObs}}). 59 | 60 | The norm of a multivariate functional data \eqn{f = (f_1 , \ldots, f_p)}{f = 61 | (f_1 , \ldots, f_p)} is defined as \deqn{||| f ||| := \left(\sum_{j=1}^p || 62 | f_j ||^2 \right) ^{1/2}.}{||| f ||| := ( \sum || f_j ||^2 )^{1/2}.} 63 | 64 | A \code{funData} object can be coerced to a \code{multiFunData} object with 65 | one element using \code{as.multiFunData(funDataObject).} 66 | } 67 | \section{Methods (by generic)}{ 68 | \itemize{ 69 | \item \code{multiFunData(ANY)}: Constructor for multivariate functional data 70 | objects. 71 | 72 | \item \code{names(multiFunData)}: Get the names of the \code{multiFunData} object. 73 | 74 | \item \code{names(multiFunData) <- value}: Set the names of the \code{multiFunData} object. 75 | 76 | \item \code{str(multiFunData)}: A \code{str} method for \code{multiFunData} objects, giving a compact overview of the structure. 77 | 78 | \item \code{summary(multiFunData)}: A \code{summary} method for \code{multiFunData} objects. 79 | 80 | }} 81 | \section{Functions}{ 82 | \itemize{ 83 | \item \code{multiFunData()}: Constructor for multivariate functional data objects 84 | 85 | }} 86 | \examples{ 87 | ### Creating a multifunData object with 2 observations on the same domain 88 | # Univariate elements 89 | x <- 1:5 90 | f1 <- funData(x, rbind(x, x+1)) 91 | f2 <- funData(x,rbind(x^2, sin(x))) 92 | # Basic 93 | m1 <- new("multiFunData", list(f1,f2)) 94 | # Using the constructor, passing the elements as list 95 | m2 <- multiFunData(list(f1,f2)) 96 | # Using the constructor, passing the elements directly 97 | m3 <- multiFunData(f1,f2) 98 | # Test if all the same 99 | all.equal(m1,m2) 100 | all.equal(m1,m3) 101 | # Display multiFunData object in the console 102 | m3 103 | # Summarize 104 | summary(m3) 105 | 106 | ### Creating a multifunData object with 2 observations on different domains (both 1D) 107 | # A new element 108 | y <- 1:3 109 | g1 <- funData(y, rbind(3*y, y+4)) 110 | # Create the multiFunData object 111 | m4 <- multiFunData(f1,g1) 112 | # Display multiFunData object in the console 113 | m4 114 | 115 | ### Creating a multifunData object with 2 observations on different domains (1D and 2D) 116 | # A new element 117 | y <- 1:3; z <- 1:4 118 | g2 <- funData(list(y,z), array(rnorm(24), dim = c(2,3,4))) 119 | # Create the multiFunData object 120 | m5 <- multiFunData(f1,g2) 121 | # Display multiFunData object in the console 122 | m5 123 | 124 | ### A more realistic object 125 | # element 1 126 | x <- seq(0,2*pi, 0.01) 127 | f1 <- funData(x, outer(seq(0.75, 1.25, length.out = 6), sin(x))) 128 | # element 2 129 | y <- seq(-1,1, 0.01); z <- seq(-0.5, 0.5, 0.01) 130 | X2 <- array(NA, c(6, length(y), length(z))) 131 | for(i in 1:6) X2[i,,] <- outer(y, z, function(x,y){sin(i*pi*y)*cos(i*pi*z)}) 132 | f2 <- funData(list(y,z), X2) 133 | # MultiFunData Object 134 | m6 <- multiFunData(f1,f2) 135 | # Display multiFunData object in the console for basic information 136 | m6 137 | # Summarize 138 | summary(m6) 139 | # Use the plot function to get an impression of the data 140 | \dontrun{plot(m6)} # m6 has 2D element, must specify one observation for plotting 141 | plot(m6, obs = 1, main = c("1st element (obs 1)", "2nd element (obs 1)")) 142 | plot(m6, obs = 6, main = c("1st element (obs 6)", "2nd element (obs 6)")) 143 | } 144 | \seealso{ 145 | \code{\linkS4class{funData}} 146 | } 147 | -------------------------------------------------------------------------------- /man/nObs-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObs,funData-method} 4 | \alias{nObs,funData-method} 5 | \title{nObs for funData objects} 6 | \usage{ 7 | \S4method{nObs}{funData}(object) 8 | } 9 | \description{ 10 | nObs for funData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/nObs-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObs,irregFunData-method} 4 | \alias{nObs,irregFunData-method} 5 | \title{nObs for irregular functional data objects} 6 | \usage{ 7 | \S4method{nObs}{irregFunData}(object) 8 | } 9 | \description{ 10 | nObs for irregular functional data objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/nObs-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObs,multiFunData-method} 4 | \alias{nObs,multiFunData-method} 5 | \title{nObs for multiFunData objects} 6 | \usage{ 7 | \S4method{nObs}{multiFunData}(object) 8 | } 9 | \description{ 10 | nObs for multiFunData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/nObs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObs} 4 | \alias{nObs} 5 | \title{Get the number of observations} 6 | \usage{ 7 | nObs(object) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{funData}, \code{irregFunData} or \code{multiFunData}.} 11 | } 12 | \value{ 13 | The number of observations in \code{object}. 14 | } 15 | \description{ 16 | This functions returns the number of observations in a \code{funData}, \code{irregFunData} or \code{multiFunData} object. 17 | } 18 | \examples{ 19 | # Univariate 20 | object <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 21 | nObs(object) 22 | 23 | # Univariate (irregular) 24 | irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 25 | nObs(irregObject) 26 | 27 | # Multivariate 28 | multiObject <- multiFunData(object, funData(argvals = 1:3, X = rbind(3:5, 6:8))) 29 | nObs(multiObject) 30 | } 31 | \seealso{ 32 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, \code{\linkS4class{multiFunData}} 33 | } 34 | -------------------------------------------------------------------------------- /man/nObsPoints-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObsPoints,funData-method} 4 | \alias{nObsPoints,funData-method} 5 | \title{nObsPoints for funData objects} 6 | \usage{ 7 | \S4method{nObsPoints}{funData}(object) 8 | } 9 | \description{ 10 | nObsPoints for funData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/nObsPoints-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObsPoints,irregFunData-method} 4 | \alias{nObsPoints,irregFunData-method} 5 | \title{nObsPoints for irregular functional data objects} 6 | \usage{ 7 | \S4method{nObsPoints}{irregFunData}(object) 8 | } 9 | \description{ 10 | nObsPoints for irregular functional data objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/nObsPoints-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObsPoints,multiFunData-method} 4 | \alias{nObsPoints,multiFunData-method} 5 | \title{nObsPoints for multiFunData objects} 6 | \usage{ 7 | \S4method{nObsPoints}{multiFunData}(object) 8 | } 9 | \description{ 10 | nObsPoints for multiFunData objects 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/nObsPoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{nObsPoints} 4 | \alias{nObsPoints} 5 | \title{Get the number of observation points} 6 | \usage{ 7 | nObsPoints(object) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{funData}, \code{multiFunData} or 11 | \code{irregFunData}.} 12 | } 13 | \value{ 14 | The number of observation points in \code{object}. See Details. 15 | } 16 | \description{ 17 | This functions returns the number of observation points in an object of class 18 | \code{funData}, \code{multiFunData} or \code{irregFunData}. 19 | } 20 | \details{ 21 | Depending on the class of \code{object}, the function returns different 22 | values: \itemize{ \item If \code{object} is of class \code{funData}, the 23 | function returns a vector of length \code{dimSupp(object)}, giving the number 24 | of observations in each dimension. \item If \code{object} is of class 25 | \code{multiFunData}, the function returns a list of the same length as 26 | \code{object}, where the \code{j}-th entry is a vector, corresponding to the 27 | observations point of \code{object[[j]]}. \item If \code{object} is of class 28 | \code{irregFunData}, the function returns an array of length 29 | \code{nObs(object)}, where the \code{j}-th entry corresponds to the number of 30 | observations in the \code{j}-th observed function.} 31 | } 32 | \section{Warning}{ 33 | Do not confound with \code{\link{nObs}}, which returns the 34 | number of observations (i.e. the number of observed functions) in an object 35 | of a functional data class. 36 | } 37 | 38 | \examples{ 39 | # Univariate (one-dimensional) 40 | object1 <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 41 | nObsPoints(object1) 42 | 43 | # Univariate (two-dimensional) 44 | object2 <- funData(argvals = list(1:5, 1:6), X = array(1:60, dim = c(2, 5, 6))) 45 | nObsPoints(object2) 46 | 47 | # Multivariate 48 | multiObject <- multiFunData(object1, object2) 49 | nObsPoints(multiObject) 50 | 51 | # Univariate (irregular) 52 | irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 53 | nObsPoints(irregObject) 54 | } 55 | \seealso{ 56 | \code{\linkS4class{irregFunData}}, \code{\link{extractObs}} 57 | } 58 | -------------------------------------------------------------------------------- /man/norm-funData-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{norm,funData,missing-method} 4 | \alias{norm,funData,missing-method} 5 | \title{Calculate the norm for univariate functional data} 6 | \usage{ 7 | \S4method{norm}{funData,missing}( 8 | x, 9 | squared = TRUE, 10 | obs = seq_len(nObs(x)), 11 | method = "trapezoidal", 12 | weight = 1 13 | ) 14 | } 15 | \description{ 16 | Calculate the norm for univariate functional data 17 | } 18 | \seealso{ 19 | \code{\link{norm}}, \code{\linkS4class{funData}} 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/norm-irregFunData-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{norm,irregFunData,missing-method} 4 | \alias{norm,irregFunData,missing-method} 5 | \title{Calculate the norm for irregular functional data} 6 | \usage{ 7 | \S4method{norm}{irregFunData,missing}( 8 | x, 9 | squared = TRUE, 10 | obs = seq_len(nObs(x)), 11 | method = "trapezoidal", 12 | weight = 1, 13 | fullDom = FALSE 14 | ) 15 | } 16 | \description{ 17 | Calculate the norm for irregular functional data 18 | } 19 | \seealso{ 20 | \code{\link{norm}}, \code{\linkS4class{irregFunData}} 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/norm-multiFunData-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{norm,multiFunData,missing-method} 4 | \alias{norm,multiFunData,missing-method} 5 | \title{Calculate the norm for multivariate functional data} 6 | \usage{ 7 | \S4method{norm}{multiFunData,missing}( 8 | x, 9 | squared = TRUE, 10 | obs = seq_len(nObs(x)), 11 | method = "trapezoidal", 12 | weight = rep(1, length(x)) 13 | ) 14 | } 15 | \description{ 16 | Calculate the norm for multivariate functional data 17 | } 18 | \seealso{ 19 | \code{\link{norm}}, \code{\linkS4class{multiFunData}} 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/norm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{norm} 4 | \alias{norm} 5 | \title{Calculate the norm of functional data} 6 | \arguments{ 7 | \item{object}{An object of class \code{funData}, \code{irregFunData} or 8 | \code{multiFunData}.} 9 | 10 | \item{...}{Further parameters (see Details).} 11 | } 12 | \value{ 13 | A numeric vector representing the norm of each observation. 14 | } 15 | \description{ 16 | This function calculates the norm for each observation of a \code{funData}, 17 | \code{irregFunData} or \code{multiFunData} object. 18 | } 19 | \details{ 20 | For \code{funData} objects, the standard \eqn{L^2} norm is calculated: 21 | \deqn{||f|| = \left( \int_{\mathcal{T}} f(t)^2 dt \right)^{1/2}.}{||f|| = (\int 22 | f(t)^2 dt)^{1/2}.} For \code{irregFunData} objects, each observed function is 23 | integrated only on the observed grid points (unless \code{fullDom = TRUE}). 24 | 25 | The (weighted) norm of a multivariate functional data object \eqn{f = (f_1 , 26 | \ldots, f_p)}{f = (f_1 , \ldots, f_p)} is defined as \deqn{||| f ||| := 27 | \left(\sum_{j=1}^p w_j || f_j ||^2 \right) ^{1/2}.}{||| f ||| := ( \sum w_j 28 | || f_j ||^2 )^{1/2}.} 29 | 30 | Further parameters passed to this function may include: \itemize{ \item 31 | \code{squared}: Logical. If \code{TRUE} (default), the function calculates 32 | the squared norm, otherwise the result is not squared. \item \code{obs}: A 33 | numeric vector, giving the indices of the observations, for which the norm is 34 | to be calculated. Defaults to all observations. \item \code{method}: A 35 | character string, giving the integration method to be used. See 36 | \code{\link{integrate}} for details. \item \code{weight}: An optional vector 37 | of weights for the scalar product; particularly useful for multivariate 38 | functional data, where each entry can be weighted in the scalar product / 39 | norm. Defaults to \code{1} for each element. \item \code{fullDom}: Logical. 40 | If \code{object} is of class \code{\linkS4class{irregFunData}} and 41 | \code{fullDom = TRUE}, all functions are extrapolated to the same domain. 42 | Defaults to \code{FALSE}. See \code{\link{integrate}} for details. } 43 | } 44 | \section{Warning}{ 45 | The function is currently implemented only for functional 46 | data with one- and two-dimensional domains. 47 | } 48 | 49 | \examples{ 50 | # Univariate 51 | object <- funData(argvals = 1:5, X = rbind(1:5, 6:10)) 52 | norm(object) 53 | 54 | # Univariate (irregular) 55 | irregObject <- irregFunData(argvals = list(1:5, 2:4), X = list(2:6, 3:5)) 56 | norm(irregObject) # no extrapolation 57 | norm(irregObject, fullDom = TRUE) # extrapolation (of second function) 58 | 59 | # Multivariate 60 | multiObject <- multiFunData(object, funData(argvals = 1:3, X = rbind(3:5, 6:8))) 61 | norm(multiObject) 62 | norm(multiObject, weight = c(2,1)) # with weight vector, giving more weight to the first element 63 | } 64 | \seealso{ 65 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}}, 66 | \code{\linkS4class{multiFunData}}, \code{\link{integrate}} 67 | } 68 | -------------------------------------------------------------------------------- /man/norm.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{norm.funData} 4 | \alias{norm.funData} 5 | \title{Calculate the norm for univariate functional data} 6 | \usage{ 7 | norm.funData(object, squared, obs, method, weight) 8 | } 9 | \description{ 10 | Calculate the norm for univariate functional data 11 | } 12 | \seealso{ 13 | \code{\link{norm}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/norm.irregFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{norm.irregFunData} 4 | \alias{norm.irregFunData} 5 | \title{Calculate the norm for irregular functional data} 6 | \usage{ 7 | norm.irregFunData(object, squared, obs, method, weight, fullDom) 8 | } 9 | \description{ 10 | Calculate the norm for irregular functional data 11 | } 12 | \seealso{ 13 | \code{\link{norm}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/plot.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{plot.funData} 4 | \alias{plot.funData} 5 | \alias{plot,funData,missing-method} 6 | \title{Plotting univariate functional data} 7 | \usage{ 8 | \method{plot}{funData}( 9 | x, 10 | y, 11 | obs = seq_len(nObs(x)), 12 | type = "l", 13 | lty = 1, 14 | lwd = 1, 15 | col = NULL, 16 | xlab = "argvals", 17 | ylab = "", 18 | legend = TRUE, 19 | plotNA = FALSE, 20 | add = FALSE, 21 | ... 22 | ) 23 | 24 | \S4method{plot}{funData,missing}(x, y, ...) 25 | } 26 | \arguments{ 27 | \item{x}{An object of class \code{funData}.} 28 | 29 | \item{y}{Missing.} 30 | 31 | \item{obs}{A vector of numerics giving the observations to plot. Defaults to 32 | all observations in \code{x}. For two-dimensional functions (images) 33 | \code{obs} must have length 1.} 34 | 35 | \item{type}{The type of plot. Defaults to \code{"l"} (line plot). See 36 | \code{\link[graphics]{plot}} for details.} 37 | 38 | \item{lty}{The line type. Defaults to \code{1} (solid line). See 39 | \code{\link[graphics]{par}} for details.} 40 | 41 | \item{lwd}{The line width. Defaults to \code{1}. See 42 | \code{\link[graphics]{par}} for details.} 43 | 44 | \item{col}{The color of the functions. If not supplied (\code{NULL}, default 45 | value), one-dimensional functions are plotted in the 46 | \code{\link[grDevices]{rainbow}} palette and two-dimensional functions are 47 | plotted using \code{\link[fields]{tim.colors}} from package 48 | \code{\link[fields]{fields-package}}.} 49 | 50 | \item{xlab, ylab}{The titles for x- and y-axis. Defaults to \code{"argvals"} 51 | for the x-axis and no title for the y-axis. See 52 | \code{\link[graphics]{plot}} for details.} 53 | 54 | \item{legend}{Logical. If \code{TRUE}, a color legend is plotted for 55 | two-dimensional functions (images). Defaults to \code{TRUE}.} 56 | 57 | \item{plotNA}{Logical. If \code{TRUE}, missing values are interpolated using 58 | the \link{approxNA} function (only for one-dimensional functions). Defaults 59 | to \code{FALSE}.} 60 | 61 | \item{add}{Logical. If \code{TRUE}, add to current plot (only for 62 | one-dimensional functions). Defaults to \code{FALSE}.} 63 | 64 | \item{...}{Additional arguments to \code{\link[graphics]{matplot} } 65 | (one-dimensional functions) or \code{\link[fields]{image.plot}}/ 66 | \code{\link[graphics]{image}} (two-dimensional functions).} 67 | } 68 | \description{ 69 | This function plots observations of univariate functional data on their 70 | domain. 71 | } 72 | \details{ 73 | If some observations contain missing values (coded via \code{NA}), the 74 | functions can be interpolated using the option \code{plotNA = TRUE}. This 75 | option relies on the \code{\link[zoo]{na.approx}} function in package 76 | \code{\link[zoo]{zoo}} and is currently implemented for one-dimensional 77 | functions only in the function \code{\link{approxNA}}. 78 | } 79 | \section{Warning}{ 80 | The function is currently implemented only for functional 81 | data with one- and two-dimensional domains. 82 | } 83 | 84 | \examples{ 85 | oldpar <- par(no.readonly = TRUE) 86 | 87 | # One-dimensional 88 | argvals <- seq(0,2*pi,0.01) 89 | object <- funData(argvals, 90 | outer(seq(0.75, 1.25, length.out = 11), sin(argvals))) 91 | 92 | plot(object, main = "One-dimensional functional data") 93 | 94 | # Two-dimensional 95 | X <- array(0, dim = c(2, length(argvals), length(argvals))) 96 | X[1,,] <- outer(argvals, argvals, function(x,y){sin((x-pi)^2 + (y-pi)^2)}) 97 | X[2,,] <- outer(argvals, argvals, function(x,y){sin(2*x*pi) * cos(2*y*pi)}) 98 | object2D <- funData(list(argvals, argvals), X) 99 | 100 | plot(object2D, main = "Two-dimensional functional data (obs 1)", obs = 1) 101 | plot(object2D, main = "Two-dimensional functional data (obs 2)", obs = 2) 102 | \dontrun{plot(object2D, main = "Two-dimensional functional data")} # must specify obs! 103 | 104 | \donttest{ 105 | ### More examples ### 106 | par(mfrow = c(1,1)) 107 | 108 | # using plotNA 109 | if(requireNamespace("zoo", quietly = TRUE)) 110 | { 111 | objectMissing <- funData(1:5, rbind(c(1, NA, 5, 4, 3), c(10, 9, NA, NA, 6))) 112 | par(mfrow = c(1,2)) 113 | plot(objectMissing, type = "b", pch = 20, main = "plotNA = FALSE") # the default 114 | plot(objectMissing, type = "b", pch = 20, plotNA = TRUE, main = "plotNA = TRUE") # requires zoo 115 | } 116 | 117 | # Changing colors 118 | plot(object, main = "1D functional data in grey", col = "grey") 119 | plot(object, main = "1D functional data in heat.colors", col = heat.colors(nObs(object))) 120 | 121 | plot(object2D, main = "2D functional data in topo.colors", obs = 1, col = topo.colors(64)) 122 | par(oldpar) 123 | } 124 | } 125 | \seealso{ 126 | \code{\linkS4class{funData}}, \code{\link[graphics]{matplot}}, 127 | \code{\link[fields]{image.plot}}, \code{\link[graphics]{image}} 128 | } 129 | -------------------------------------------------------------------------------- /man/plot.irregFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{plot.irregFunData} 4 | \alias{plot.irregFunData} 5 | \alias{plot,irregFunData,missing-method} 6 | \title{Plotting irregular functional data} 7 | \usage{ 8 | \method{plot}{irregFunData}( 9 | x, 10 | y, 11 | obs = seq_len(nObs(x)), 12 | type = "b", 13 | pch = 20, 14 | col = grDevices::rainbow(length(obs)), 15 | xlab = "argvals", 16 | ylab = "", 17 | xlim = range(x@argvals[obs]), 18 | ylim = range(x@X[obs]), 19 | log = "", 20 | add = FALSE, 21 | ... 22 | ) 23 | 24 | \S4method{plot}{irregFunData,missing}(x, y, ...) 25 | } 26 | \arguments{ 27 | \item{x}{An object of class \code{irregFunData}.} 28 | 29 | \item{y}{Missing.} 30 | 31 | \item{obs}{A vector of numerics giving the observations to plot. Defaults to all observations in 32 | \code{x}.} 33 | 34 | \item{type}{The type of plot. Defaults to \code{"b"} (line and point plot). See 35 | \code{\link[graphics]{plot}} for details.} 36 | 37 | \item{pch}{The point type. Defaults to \code{20} (solid small circles). See 38 | \code{\link[graphics]{par}} for details.} 39 | 40 | \item{col}{The color of the functions. Defaults to the \code{\link[grDevices]{rainbow}} palette.} 41 | 42 | \item{xlab, ylab}{The titles for x- and y-axis. Defaults to \code{"argvals"} for the x-axis and no 43 | title for the y-axis. See \code{\link[graphics]{plot}} for details.} 44 | 45 | \item{xlim, ylim}{The limits for x- and y-axis. Defaults to the total range of the data that is to 46 | plot. See \code{\link[graphics]{plot}} for details.} 47 | 48 | \item{log}{A character string, specifying the axis that is to be logarithmic. Can be \code{""} 49 | (non-logarithmic axis, the default), \code{"x", "y", "xy"} or \code{"yx"}. See 50 | \code{\link[graphics]{plot.default}} for details. This parameter is ignored, if \code{add = 51 | TRUE}.} 52 | 53 | \item{add}{Logical. If \code{TRUE}, add to current plot (only for one-dimensional functions). 54 | Defaults to \code{FALSE}.} 55 | 56 | \item{...}{Additional arguments to \code{\link[graphics]{plot}}.} 57 | } 58 | \description{ 59 | This function plots observations of irregular functional data on their domain. 60 | } 61 | \examples{ 62 | oldpar <- par(no.readonly = TRUE) 63 | 64 | # Generate data 65 | argvals <- seq(0,2*pi,0.01) 66 | ind <- replicate(5, sort(sample(1:length(argvals), sample(5:10,1)))) 67 | object <- irregFunData(argvals = lapply(ind, function(i){argvals[i]}), 68 | X = lapply(ind, function(i){sample(1:10,1) / 10 * argvals[i]^2})) 69 | 70 | plot(object, main = "Irregular functional data") 71 | 72 | par(oldpar) 73 | } 74 | \seealso{ 75 | \code{\link{plot.funData}}, \code{\linkS4class{irregFunData}}, 76 | \code{\link[graphics]{plot}} 77 | } 78 | -------------------------------------------------------------------------------- /man/plot.multiFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotMethods.R 3 | \name{plot.multiFunData} 4 | \alias{plot.multiFunData} 5 | \alias{plot,multiFunData,missing-method} 6 | \title{Plotting multivariate functional data} 7 | \usage{ 8 | \method{plot}{multiFunData}( 9 | x, 10 | y, 11 | obs = seq_len(nObs(x)), 12 | dim = seq_len(length(x)), 13 | par.plot = NULL, 14 | main = names(x), 15 | xlab = "argvals", 16 | ylab = "", 17 | log = "", 18 | ylim = NULL, 19 | ... 20 | ) 21 | 22 | \S4method{plot}{multiFunData,missing}(x, y, ...) 23 | } 24 | \arguments{ 25 | \item{x}{An object of class \code{multiFunData}.} 26 | 27 | \item{y}{Missing.} 28 | 29 | \item{obs}{A vector of numerics giving the observations to plot. Defaults to 30 | all observations in \code{x}. For two-dimensional functions (images) 31 | \code{obs} must have length 1.} 32 | 33 | \item{dim}{The dimensions to plot. Defaults to \code{length(x)}, i.e. all 34 | functions in \code{x} are plotted.} 35 | 36 | \item{par.plot}{Graphic parameters to be passed to the plotting regions. The 37 | option \code{mfrow} is ignored. Defaults to \code{NULL}. See 38 | \code{\link[graphics]{par}} for details.} 39 | 40 | \item{main}{A string vector, giving the title of the plot. Can have the same 41 | length as \code{dim} (different titles for each dimension) or length 42 | \code{1} (one title for all dimensions). Defaults to \code{names(x)}.} 43 | 44 | \item{xlab, ylab}{The titles for x- and y-axis. Defaults to \code{"argvals"} 45 | for the x-axis and no title for the y-axis for all elements. Can be 46 | supplied as a vector of the same length as \code{dim} (one x-/y-lab for each 47 | element) or a single string that is applied for all elements. See 48 | \code{\link[graphics]{plot}} for details.} 49 | 50 | \item{log}{A character string, specifying the axis that is to be logarithmic. 51 | Can be \code{""} (non-logarithmic axis), \code{"x", "y", "xy"} or 52 | \code{"yx"}. Defaults to \code{""} for all plots. Can be supplied as a 53 | vector of the same length as \code{dim} (one log-specification for each 54 | element) or a single string that is applied for all elements. See 55 | \code{\link[graphics]{plot.default}} for details.} 56 | 57 | \item{ylim}{Specifies the limits of the y-Axis. Can be either \code{NULL} 58 | (the default, limits are chosen automatically), a vector of length 2 59 | (giving the minimum and maximum range for all elements at the same time) or 60 | a list of the same length as \code{dim} (specifying the limits for each 61 | element separately).} 62 | 63 | \item{...}{Additional arguments to \code{plot}.} 64 | } 65 | \description{ 66 | This function plots observations of multivariate functional data on their domain. The graphic 67 | device is split in a number of subplots (specified by \code{dim}) via \code{mfrow} 68 | (\code{\link[graphics]{par}}) and the univariate elements are plotted using \code{plot}. 69 | } 70 | \section{Warning}{ 71 | The function is currently implemented only for functional data with one- and 72 | two-dimensional domains. 73 | } 74 | 75 | \examples{ 76 | oldpar <- par(no.readonly = TRUE) 77 | argvals <- seq(0, 2*pi, 0.1) 78 | 79 | # One-dimensional elements 80 | f1 <- funData(argvals, outer(seq(0.75, 1.25, length.out = 11), sin(argvals))) 81 | f2 <- funData(argvals, outer(seq(0.75, 1.25, length.out = 11), cos(argvals))) 82 | 83 | m1 <- multiFunData(f1, f2) 84 | plot(m1, main = c("1st element", "2nd element")) # different titles 85 | plot(m1, main = "Multivariate Functional Data") # one title for all 86 | 87 | # Mixed-dimensional elements 88 | X <- array(0, dim = c(11, length(argvals), length(argvals))) 89 | X[1,,] <- outer(argvals, argvals, function(x,y){sin((x-pi)^2 + (y-pi)^2)}) 90 | g <- funData(list(argvals, argvals), X) 91 | 92 | m2 <- multiFunData(f1, g) 93 | # different titles and labels 94 | plot(m2, main = c("1st element", "2nd element"), obs = 1, 95 | xlab = c("xlab1", "xlab2"), 96 | ylab = "one ylab for all") 97 | # one title for all 98 | plot(m2, main = "Multivariate Functional Data", obs = 1) 99 | 100 | \dontrun{plot(m2, main = c("1st element", "2nd element")) # must specify obs!} 101 | 102 | par(oldpar) 103 | } 104 | \seealso{ 105 | \code{\linkS4class{funData}}, \code{\linkS4class{multiFunData}}, 106 | \code{\link{plot.funData}} 107 | } 108 | -------------------------------------------------------------------------------- /man/print.funData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{print.funData} 4 | \alias{print.funData} 5 | \title{A print method for univariate functional data} 6 | \usage{ 7 | \method{print}{funData}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \code{funData} object.} 11 | } 12 | \description{ 13 | This function prints basic information about a \code{funData} object. This is 14 | the standard console output for \code{funData} objects. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/print.irregFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{print.irregFunData} 4 | \alias{print.irregFunData} 5 | \title{A print method for irregular functional data} 6 | \usage{ 7 | \method{print}{irregFunData}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An \code{irregFunData} object.} 11 | } 12 | \description{ 13 | This function prints basic information about a \code{irregFunData} object. This is 14 | the standard console output for \code{irregFunData} objects. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/scalarProduct-funData-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{scalarProduct,funData,funData-method} 4 | \alias{scalarProduct,funData,funData-method} 5 | \title{Scalar product for functional data} 6 | \usage{ 7 | \S4method{scalarProduct}{funData,funData}(object1, object2, ...) 8 | } 9 | \description{ 10 | Scalar product for functional data 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\link{norm}}. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/scalarProduct-funData-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{scalarProduct,funData,irregFunData-method} 4 | \alias{scalarProduct,funData,irregFunData-method} 5 | \title{Scalar product for irregular and functional data} 6 | \usage{ 7 | \S4method{scalarProduct}{funData,irregFunData}(object1, object2, ...) 8 | } 9 | \description{ 10 | Scalar product for irregular and functional data 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\link{norm}}. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/scalarProduct-irregFunData-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{scalarProduct,irregFunData,funData-method} 4 | \alias{scalarProduct,irregFunData,funData-method} 5 | \title{Scalar product for irregular and functional data} 6 | \usage{ 7 | \S4method{scalarProduct}{irregFunData,funData}(object1, object2, ...) 8 | } 9 | \description{ 10 | Scalar product for irregular and functional data 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\link{norm}}. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/scalarProduct-irregFunData-irregFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{scalarProduct,irregFunData,irregFunData-method} 4 | \alias{scalarProduct,irregFunData,irregFunData-method} 5 | \title{Scalar product for irregular functional data} 6 | \usage{ 7 | \S4method{scalarProduct}{irregFunData,irregFunData}(object1, object2, ...) 8 | } 9 | \description{ 10 | Scalar product for irregular functional data 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\link{norm}}. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/scalarProduct-multiFunData-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{scalarProduct,multiFunData,multiFunData-method} 4 | \alias{scalarProduct,multiFunData,multiFunData-method} 5 | \title{Scalar product for multivariate functional data} 6 | \usage{ 7 | \S4method{scalarProduct}{multiFunData,multiFunData}(object1, object2, weight = rep(1, length(object1)), ...) 8 | } 9 | \description{ 10 | Scalar product for multivariate functional data 11 | } 12 | \seealso{ 13 | \code{\link{integrate}}, \code{\link{norm}}. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/scalarProduct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{scalarProduct} 4 | \alias{scalarProduct} 5 | \title{Calculate the scalar product for functional data objects} 6 | \usage{ 7 | scalarProduct(object1, object2, ...) 8 | } 9 | \arguments{ 10 | \item{object1, object2}{Two objects of class\code{\link{funData}}, 11 | \code{\link{irregFunData}} or \code{\link{multiFunData}}, for that the 12 | scalar product is to be calculated.} 13 | 14 | \item{...}{Additional parameters passed to \code{\link{integrate}}. For 15 | \code{\linkS4class{multiFunData}} objects, one can also pass a 16 | \code{weight} argument. See Details.} 17 | } 18 | \value{ 19 | A vector of length \code{nObs(object1)} (or \code{nObs(object2)}, if 20 | \code{object1} has only one observation), containing the pairwise scalar 21 | product for each observation. 22 | } 23 | \description{ 24 | This function calculates the scalar product between two objects of the class 25 | \code{\linkS4class{funData}}, \code{\linkS4class{irregFunData}} and 26 | \code{\linkS4class{multiFunData}}. For univariate functions \eqn{f,g} on a 27 | domain \eqn{\mathcal{T}}{T}, the scalar product is defined as 28 | \deqn{\int_\mathcal{T} f(t) g(t) \mathrm{d}t}{\int_T f(t) g(t) dt} and 29 | for multivariate functions \eqn{f,g} on domains \eqn{\mathcal{T}_1, \ldots, 30 | \mathcal{T}_p}{T_1,\ldots,T_p}, it is defined as \deqn{\sum_{j = 1}^p 31 | \int_{\mathcal{T}_j} f^{(j)}(t) g^{(j)}(t) \mathrm{d}t.}{\sum_{j = 1}^p 32 | \int_T_j f^{(j)}(t) g^{(j)}(t) dt.} As seen in the formula, the objects 33 | must be defined on the same domain. The scalar product is calculated pairwise 34 | for all observations, thus the objects must also have the same number of 35 | observations or one object may have only one observation (for which the 36 | scalar product is calculated with all observations of the other object)). 37 | Objects of the classes \code{\link{funData}} and \code{\link{irregFunData}} 38 | can be combined, see \code{\link{integrate}} for details. 39 | } 40 | \details{ 41 | For \code{\linkS4class{multiFunData}} one can pass an optional vector 42 | \code{weight} for calculating a weighted scalar product. This vector must 43 | have the same number of elements as the \code{\link{multiFunData}} objects 44 | and have to be non-negative with at least one weight that is different from 45 | 0. Defaults to \code{1} for each element. See also \code{\link{norm}}. 46 | } 47 | \examples{ 48 | # create two funData objectw with 5 observations on [0,1] 49 | f <- simFunData(N = 5, M = 7, eValType = "linear", 50 | eFunType = "Fourier", argvals = seq(0,1,0.01))$simData 51 | g <- simFunData(N = 5, M = 4, eValType = "linear", 52 | eFunType = "Poly", argvals = seq(0,1,0.01))$simData 53 | 54 | # calculate the scalar product 55 | scalarProduct(f,g) 56 | 57 | # the scalar product of an object with itself equals the squared norm 58 | all.equal(scalarProduct(f,f), norm(f, squared = TRUE)) 59 | 60 | # This works of course also for multiFunData objects... 61 | m <- multiFunData(f,g) 62 | all.equal(scalarProduct(m,m), norm(m, squared = TRUE)) 63 | 64 | # ...and for irregFunData objects 65 | i <- as.irregFunData(sparsify(f, minObs = 5, maxObs = 10)) 66 | all.equal(scalarProduct(i,i), norm(i, squared = TRUE)) 67 | 68 | # Scalar product between funData and irregFunData objects 69 | scalarProduct(i,f) 70 | 71 | # Weighted scalar product for multiFunData objects 72 | scalarProduct(m,m, weight = c(1,2)) 73 | } 74 | \seealso{ 75 | \code{\link{integrate}}, \code{\link{norm}}, 76 | } 77 | -------------------------------------------------------------------------------- /man/simFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{simFunData} 4 | \alias{simFunData} 5 | \title{Simulate univariate functional data} 6 | \usage{ 7 | simFunData(argvals, M, eFunType, ignoreDeg = NULL, eValType, N) 8 | } 9 | \arguments{ 10 | \item{argvals}{A numeric vector, containing the observation points (a fine grid on a real 11 | interval) of the functional data that is to be simulated or a list of the marginal observation points.} 12 | 13 | \item{M}{An integer, giving the number of univariate basis functions to use. For higher-dimensional data, \code{M} is a vector with the marginal number of eigenfunctions. See Details.} 14 | 15 | \item{eFunType}{A character string specifying the type of univariate orthonormal basis functions 16 | to use. For data on higher-dimensional domains, \code{eFunType} can be a vector, specifying the marginal type of eigenfunctions to use in the tensor product. See \code{\link{eFun}} for details.} 17 | 18 | \item{ignoreDeg}{A vector of integers, specifying the degrees to ignore when generating the 19 | univariate orthonormal bases. Defaults to \code{NULL}. For higher-dimensional data, \code{ignoreDeg} can be supplied as list with vectors for each marginal. See \code{\link{eFun}} for details.} 20 | 21 | \item{eValType}{A character string, specifying the type of eigenvalues/variances used for the 22 | generation of the simulated functions based on the truncated Karhunen-Loeve representation. See 23 | \code{\link{eVal}} for details.} 24 | 25 | \item{N}{An integer, specifying the number of multivariate functions to be generated.} 26 | } 27 | \value{ 28 | \item{simData}{A \code{\linkS4class{funData}} object with \code{N} observations, 29 | representing the simulated functional data.} \item{trueFuns}{A \code{\linkS4class{funData}} 30 | object with \code{M} observations, representing the true eigenfunction basis used for 31 | simulating the data.} \item{trueVals}{A vector of numerics, representing the true eigenvalues 32 | used for simulating the data.} 33 | } 34 | \description{ 35 | This functions simulates (univariate) functional data \eqn{f_1,\ldots, f_N} based on a truncated 36 | Karhunen-Loeve representation: \deqn{f_i(t) = \sum_{m = 1}^M \xi_{i,m} \phi_m(t).} on one- or 37 | higher-dimensional domains. The eigenfunctions (basis functions) \eqn{\phi_m(t)} are generated 38 | using \code{\link{eFun}}, the scores \eqn{\xi_{i,m}} are simulated independently from a normal 39 | distribution with zero mean and decreasing variance based on the \code{\link{eVal}} function. For 40 | higher-dimensional domains, the eigenfunctions are constructed as tensors of marginal orthonormal 41 | function systems. 42 | } 43 | \examples{ 44 | oldPar <- par(no.readonly = TRUE) 45 | 46 | # Use Legendre polynomials as eigenfunctions and a linear eigenvalue decrease 47 | test <- simFunData(seq(0,1,0.01), M = 10, eFunType = "Poly", eValType = "linear", N = 10) 48 | 49 | plot(test$trueFuns, main = "True Eigenfunctions") 50 | plot(test$simData, main = "Simulated Data") 51 | 52 | # The use of ignoreDeg for eFunType = "PolyHigh" 53 | test <- simFunData(seq(0,1,0.01), M = 4, eFunType = "Poly", eValType = "linear", N = 10) 54 | test_noConst <- simFunData(seq(0,1,0.01), M = 4, eFunType = "PolyHigh", 55 | ignoreDeg = 1, eValType = "linear", N = 10) 56 | test_noLinear <- simFunData(seq(0,1,0.01), M = 4, eFunType = "PolyHigh", 57 | ignoreDeg = 2, eValType = "linear", N = 10) 58 | test_noBoth <- simFunData(seq(0,1,0.01), M = 4, eFunType = "PolyHigh", 59 | ignoreDeg = 1:2, eValType = "linear", N = 10) 60 | 61 | par(mfrow = c(2,2)) 62 | plot(test$trueFuns, main = "Standard polynomial basis (M = 4)") 63 | plot(test_noConst$trueFuns, main = "No constant basis function") 64 | plot(test_noLinear$trueFuns, main = "No linear basis function") 65 | plot(test_noBoth$trueFuns, main = "Neither linear nor constant basis function") 66 | 67 | # Higher-dimensional domains 68 | simImages <- simFunData(argvals = list(seq(0,1,0.01), seq(-pi/2, pi/2, 0.02)), 69 | M = c(5,4), eFunType = c("Wiener","Fourier"), eValType = "linear", N = 4) 70 | for(i in 1:4) 71 | plot(simImages$simData, obs = i, main = paste("Observation", i)) 72 | 73 | par(oldPar) 74 | } 75 | \seealso{ 76 | \code{\linkS4class{funData}}, \code{\link{eFun}}, \code{\link{eVal}}, 77 | \code{\link{addError}}, \code{\link{sparsify}} 78 | } 79 | -------------------------------------------------------------------------------- /man/simMultiFunData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{simMultiFunData} 4 | \alias{simMultiFunData} 5 | \title{Simulate multivariate functional data} 6 | \usage{ 7 | simMultiFunData(type, argvals, M, eFunType, ignoreDeg = NULL, eValType, N) 8 | } 9 | \arguments{ 10 | \item{type}{A character string, specifying the construction method for the 11 | multivariate eigenfunctions (either \code{"split"} or \code{"weighted"}). 12 | See Details.} 13 | 14 | \item{argvals}{A list, containing the observation points for each element of 15 | the multivariate functional data that is to be simulated. The length of 16 | \code{argvals} determines the number of elements in the resulting simulated 17 | multivariate functional data. See Details.} 18 | 19 | \item{M}{An integer (\code{type = "split"}) or a list of integers (\code{type 20 | = "weighted"}), giving the number of univariate basis functions to use. See 21 | Details.} 22 | 23 | \item{eFunType}{A character string (\code{type = "split"}) or a list of 24 | character strings (\code{type = "weighted"}), specifying the type of 25 | univariate orthonormal basis functions to use. See Details.} 26 | 27 | \item{ignoreDeg}{A vector of integers (\code{type = "split"}) or a list of 28 | integer vectors (\code{type = "weighted"}), specifying the degrees to 29 | ignore when generating the univariate orthonormal bases. Defaults to 30 | \code{NULL}. See Details.} 31 | 32 | \item{eValType}{A character string, specifying the type of 33 | eigenvalues/variances used for the simulation of the multivariate functions 34 | based on the truncated Karhunen-Loeve representation. See 35 | \code{\link{eVal}} for details.} 36 | 37 | \item{N}{An integer, specifying the number of multivariate functions to be 38 | generated.} 39 | } 40 | \value{ 41 | \item{simData}{A \code{\linkS4class{multiFunData}} object with 42 | \code{N} observations, representing the simulated multivariate functional 43 | data.} \item{trueFuns}{A \code{\linkS4class{multiFunData}} object with 44 | \code{M} observations, representing the multivariate eigenfunction basis 45 | used for simulating the data.} \item{trueVals}{A vector of numerics, 46 | representing the eigenvalues used for simulating the data.} 47 | } 48 | \description{ 49 | This function provides a unified simulation structure for multivariate 50 | functional data \eqn{f_1, \ldots, f_N} on one- or two-dimensional domains, 51 | based on a truncated multivariate Karhunen-Loeve representation: \deqn{f_i(t) 52 | = \sum_{m = 1}^M \rho_{i,m} \psi_m(t).} The multivariate eigenfunctions 53 | (basis functions) \eqn{\psi_m} are constructed from univariate orthonormal 54 | bases. There are two different concepts for the construction, that can be 55 | chosen by the parameter \code{type}: A split orthonormal basis (\code{split}, 56 | only one-dimensional domains) and weighted univariate orthonormal bases 57 | (\code{weighted}, one- and two-dimensional domains). The scores 58 | \eqn{\rho_{i,m}} in the Karhunen-Loeve representation are simulated 59 | independently from a normal distribution with zero mean and decreasing 60 | variance. See Details. 61 | } 62 | \details{ 63 | The parameter \code{type} defines how the eigenfunction basis for the 64 | multivariate Karhunen-Loeve representation is constructed: \itemize{ \item 65 | \code{type = "split"}: The basis functions of an underlying 'big' orthonormal 66 | basis are split in \code{M} parts, translated and possibly reflected. This 67 | yields an orthonormal basis of multivariate functions with \code{M} 68 | elements. This option is implemented only for one-dimensional domains. \item 69 | \code{type = "weighted":} The multivariate eigenfunction basis consists of 70 | weighted univariate orthonormal bases. This yields an orthonormal basis of 71 | multivariate functions with \code{M} elements. For data on two-dimensional 72 | domains (images), the univariate basis is constructed as a tensor product of 73 | univariate bases in each direction (x- and y-direction). } 74 | 75 | Depending on \code{type}, the other parameters have to be specified as 76 | follows: \subsection{Split 'big' orthonormal basis}{ The parameters \code{M} 77 | (integer), \code{eFunType} (character string) and \code{ignoreDeg} (integer 78 | vector or \code{NULL}) are passed to the function \code{\link{eFun}} to 79 | generate a univariate orthonormal basis on a 'big' interval. Subsequently, 80 | the basis functions are split and translated, such that the \eqn{j}-th part 81 | of the split function is defined on the interval corresponding to 82 | \code{argvals[[j]]}. The elements of the multivariate basis functions are 83 | given by these split parts of the original basis functions multiplied by a 84 | random sign \eqn{\sigma_j \in \{-1,1\}, j = 1, \ldots, p}{\sigma_j in {-1,1}, 85 | j = 1, \ldots, p}.} 86 | 87 | \subsection{Weighted orthonormal bases}{ The parameters \code{argvals, M, 88 | eFunType} and \code{ignoreDeg} are all lists of a similar structure. They are 89 | passed element-wise to the function \code{\link{eFun}} to generate 90 | orthonormal basis functions for each element of the multivariate functional 91 | data to be simulated. In case of bivariate elements (images), the 92 | corresponding basis functions are constructed as tensor products of 93 | orthonormal basis functions in each direction (x- and y-direction). 94 | 95 | If the \eqn{j}-th element of the simulated data should be defined on a 96 | one-dimensional domain, then \itemize{ \item \code{argvals[[j]]} is a list, 97 | containing one vector of observation points. \item \code{M[[j]]} is an 98 | integer, specifying the number of basis functions to use for this entry. 99 | \item \code{eFunType[[j]]} is a character string, specifying the type of 100 | orthonormal basis functions to use for this entry (see \code{\link{eFun}} for 101 | possible options). \item \code{ignoreDeg[[j]]} is a vector of integers, 102 | specifying the degrees to ignore when constructing the orthonormal basis 103 | functions. The default value is \code{NULL}. } 104 | 105 | If the \eqn{j}-th element of the simulated data should be defined on a 106 | two-dimensional domain, then \itemize{ \item \code{argvals[[j]]} is a list, 107 | containing two vectors of observation points, one for each direction 108 | (observation points in x-direction and in y-direction). \item \code{M[[j]]} 109 | is a vector of two integers, giving the number of basis functions for each 110 | direction (x- and y-direction). \item \code{eFunType[[j]]} is a vector of two 111 | character strings, giving the type of orthonormal basis functions for each 112 | direction (x- and y-direction, see \code{\link{eFun}} for possible options). 113 | The corresponding basis functions are constructed as tensor products of 114 | orthonormal basis functions in each direction. \item \code{ignoreDeg[[j]]} is 115 | a list, containing two integer vectors that specify the degrees to ignore 116 | when constructing the orthonormal basis functions in each direction. The 117 | default value is \code{NULL}. } The total number of basis functions (i.e. the 118 | product of \code{M[[j]]} for all \code{j}) must be equal!} 119 | } 120 | \examples{ 121 | oldPar <- par(no.readonly = TRUE) 122 | 123 | # split 124 | split <- simMultiFunData(type = "split", argvals = list(seq(0,1,0.01), seq(-0.5,0.5,0.02)), 125 | M = 5, eFunType = "Poly", eValType = "linear", N = 7) 126 | 127 | par(mfrow = c(1,2)) 128 | plot(split$trueFuns, main = "Split: True Eigenfunctions", ylim = c(-2,2)) 129 | plot(split$simData, main = "Split: Simulated Data") 130 | 131 | # weighted (one-dimensional domains) 132 | weighted1D <- simMultiFunData(type = "weighted", 133 | argvals = list(list(seq(0,1,0.01)), list(seq(-0.5,0.5,0.02))), 134 | M = c(5,5), eFunType = c("Poly", "Fourier"), eValType = "linear", N = 7) 135 | 136 | plot(weighted1D$trueFuns, main = "Weighted (1D): True Eigenfunctions", ylim = c(-2,2)) 137 | plot(weighted1D$simData, main = "Weighted (1D): Simulated Data") 138 | 139 | # weighted (one- and two-dimensional domains) 140 | weighted <- simMultiFunData(type = "weighted", 141 | argvals = list(list(seq(0,1,0.01), seq(0,10,0.1)), list(seq(-0.5,0.5,0.01))), 142 | M = list(c(5,4), 20), eFunType = list(c("Poly", "Fourier"), "Wiener"), 143 | eValType = "linear", N = 7) 144 | 145 | plot(weighted$trueFuns, main = "Weighted: True Eigenfunctions (m = 2)", obs = 2) 146 | plot(weighted$trueFuns, main = "Weighted: True Eigenfunctions (m = 15)", obs = 15) 147 | plot(weighted$simData, main = "Weighted: Simulated Data (1st observation)", obs = 1) 148 | plot(weighted$simData, main = "Weighted: Simulated Data (2nd observation)", obs = 2) 149 | 150 | par(oldPar) 151 | } 152 | \references{ 153 | C. Happ, S. Greven (2018): Multivariate Functional Principal 154 | Component Analysis for Data Observed on Different (Dimensional) Domains. 155 | Journal of the American Statistical Association, 113(522): 649-659. 156 | } 157 | \seealso{ 158 | \code{\linkS4class{multiFunData}}, \code{\link{eFun}}, 159 | \code{\link{eVal}}, \code{\link{simFunData}}, \code{\link{addError}}, 160 | \code{\link{sparsify}}. 161 | } 162 | -------------------------------------------------------------------------------- /man/simMultiSplit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{simMultiSplit} 4 | \alias{simMultiSplit} 5 | \title{Simulate multivariate eigenfunctions based on a split 'big' ONB} 6 | \usage{ 7 | simMultiSplit(argvals, M, eFunType, ignoreDeg = NULL, eValType, N) 8 | } 9 | \description{ 10 | Simulate multivariate eigenfunctions based on a split 'big' ONB 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/simMultiWeight.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{simMultiWeight} 4 | \alias{simMultiWeight} 5 | \title{Simulate multivariate eigenfunctions based on weighted orthonormal bases} 6 | \usage{ 7 | simMultiWeight(argvals, M, eFunType, ignoreDeg = NULL, eValType, N) 8 | } 9 | \description{ 10 | Simulate multivariate eigenfunctions based on weighted orthonormal bases 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sparsify-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{sparsify,funData-method} 4 | \alias{sparsify,funData-method} 5 | \title{sparsify for univariate functional data} 6 | \usage{ 7 | \S4method{sparsify}{funData}(funDataObject, minObs, maxObs) 8 | } 9 | \description{ 10 | sparsify for univariate functional data 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sparsify-multiFunData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{sparsify,multiFunData-method} 4 | \alias{sparsify,multiFunData-method} 5 | \title{sparsify for multivariate functional data} 6 | \usage{ 7 | \S4method{sparsify}{multiFunData}(funDataObject, minObs, maxObs) 8 | } 9 | \description{ 10 | sparsify for multivariate functional data 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sparsify.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation.R 3 | \name{sparsify} 4 | \alias{sparsify} 5 | \title{Generate a sparse version of functional data objects} 6 | \usage{ 7 | sparsify(funDataObject, minObs, maxObs) 8 | } 9 | \arguments{ 10 | \item{funDataObject}{A functional data object of class 11 | \code{\linkS4class{funData}} or \code{\linkS4class{multiFunData}}.} 12 | 13 | \item{minObs, maxObs}{The minimal/maximal number of observation points. Must be a scalar for 14 | univariate functional data (\code{\linkS4class{funData}} class) or a 15 | vector of the same length as \code{funDataObject} for multivariate 16 | functional data (\code{\linkS4class{multiFunData}} class), giving the 17 | minimal/maximal number of observations for each element. See Details.} 18 | } 19 | \value{ 20 | An object of the same class as \code{funDataObject}, which is a 21 | sparse version of the original data. 22 | } 23 | \description{ 24 | This function generates an artificially sparsified version of a functional 25 | data object of class \code{\linkS4class{funData}} (univariate) or 26 | \code{\linkS4class{multiFunData}} (multivariate). The minimal and maximal number 27 | of observation points for all observations can be supplied by the user. 28 | } 29 | \details{ 30 | The technique for artificially sparsifying the data is as described in Yao et 31 | al. (2005): For each element \eqn{x_i^{(j)}}{x_i^(j)} of an observed 32 | (multivariate) functional data object \eqn{x_i}, a random number 33 | \eqn{R_i^{(j)} \in \{\mathrm{minObs}, \ldots, \mathrm{maxObs}\}}{R_i^(j) 34 | in {\code{minObs}, \ldots, \code{maxObs}}} of observation points is generated. The points 35 | are sampled uniformly from the full grid \eqn{\{t_{j,1} , \ldots , t_{j, 36 | S_j}\} \subset \mathcal{T}_j}{{t_{j,1} , \ldots , t_{j, S_j}} in T_j}, resulting in 37 | observations \deqn{ x_{i,r}^{(j)} = x_i^{(j)}(t_{j,r}), \quad r = 1 38 | ,\ldots,R_i^{(j)},~ j = 1, \ldots, p.}{ x_{i,r}^(j) = x_i^(j)(t_{j,r}), r = 1 39 | ,\ldots,R_i^(j), j = 1, \ldots, p.} 40 | } 41 | \section{Warning}{ 42 | 43 | This function is currently implemented for 1D data only. 44 | } 45 | 46 | \examples{ 47 | oldPar <- par(no.readonly = TRUE) 48 | par(mfrow = c(1,1)) 49 | set.seed(1) 50 | 51 | # univariate functional data 52 | full <- simFunData(argvals = seq(0,1, 0.01), M = 10, eFunType = "Fourier", 53 | eValType = "linear", N = 3)$simData 54 | sparse <- sparsify(full, minObs = 4, maxObs = 10) 55 | 56 | plot(full, main = "Sparsify") 57 | plot(sparse, type = "p", pch = 20, add = TRUE) 58 | legend("topright", c("Full", "Sparse"), lty = c(1, NA), pch = c(NA, 20)) 59 | 60 | # Multivariate 61 | full <- simMultiFunData(type = "split", argvals = list(seq(0,1, 0.01), seq(-.5,.5, 0.02)), 62 | M = 10, eFunType = "Fourier", eValType = "linear", N = 3)$simData 63 | sparse <- sparsify(full, minObs = c(4, 30), maxObs = c(10, 40)) 64 | 65 | par(mfrow = c(1,2)) 66 | plot(full[[1]], main = "Sparsify (multivariate)", sub = "minObs = 4, maxObs = 10") 67 | plot(sparse[[1]], type = "p", pch = 20, add = TRUE) 68 | 69 | plot(full[[2]], main = "Sparsify (multivariate)", sub = "minObs = 30, maxObs = 40") 70 | plot(sparse[[2]], type = "p", pch = 20, add = TRUE) 71 | legend("bottomright", c("Full", "Sparse"), lty = c(1, NA), pch = c(NA, 20)) 72 | 73 | par(oldPar) 74 | } 75 | \references{ 76 | Yao, F., H.-G. Mueller and J.-L. Wang (2005): Functional Data 77 | Analysis for Sparse Longitudinal Data. Journal of the American Statistical 78 | Association, 100 (470), 577--590. 79 | } 80 | \seealso{ 81 | \code{\linkS4class{funData}}, \code{\linkS4class{multiFunData}}, 82 | \code{\link{simFunData}}, \code{\link{simMultiFunData}}, 83 | \code{\link{addError}}. 84 | } 85 | -------------------------------------------------------------------------------- /man/tensorProduct-funData-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{tensorProduct,funData-method} 4 | \alias{tensorProduct,funData-method} 5 | \title{Tensor product for functional data} 6 | \usage{ 7 | \S4method{tensorProduct}{funData}(...) 8 | } 9 | \description{ 10 | Tensor product for functional data 11 | } 12 | \seealso{ 13 | \code{\link{tensorProduct}} 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/tensorProduct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funDataMethods.R 3 | \name{tensorProduct} 4 | \alias{tensorProduct} 5 | \title{Tensor product for univariate functions on one-dimensional domains} 6 | \usage{ 7 | tensorProduct(...) 8 | } 9 | \arguments{ 10 | \item{...}{Two or three objects of class \code{funData}, that must be defined 11 | on a one-dimensional domain, each.} 12 | } 13 | \value{ 14 | An object of class as \code{funData} that corresponds to the tensor 15 | product of the input functions. 16 | } 17 | \description{ 18 | This function calculates tensor product functions for up to three objects of 19 | class \code{funData} defined on one-dimensional domains. 20 | } 21 | \section{Warning}{ 22 | The function is only implemented for up to three functions 23 | on one-dimensional domains. 24 | } 25 | 26 | \examples{ 27 | 28 | ### Tensor product of two functional data objects 29 | x <- seq(0, 2*pi, 0.1) 30 | f1 <- funData(x, outer(seq(0.75, 1.25, 0.1), sin(x))) 31 | y <- seq(-pi, pi, 0.1) 32 | f2 <- funData(y, outer(seq(0.25, 0.75, 0.1), sin(y))) 33 | 34 | plot(f1, main = "f1") 35 | plot(f2, main = "f2") 36 | 37 | tP <- tensorProduct(f1, f2) 38 | dimSupp(tP) 39 | plot(tP, obs = 1) 40 | 41 | ### Tensor product of three functional data objects 42 | z <- seq(-1, 1, 0.05) 43 | f3 <- funData(z, outer(seq(0.75, 1.25, 0.1), z^2)) 44 | 45 | plot(f1, main = "f1") 46 | plot(f2, main = "f2") 47 | plot(f3, main = "f3") 48 | 49 | tP2 <- tensorProduct(f1, f2, f3) 50 | dimSupp(tP2) 51 | } 52 | \seealso{ 53 | \code{\linkS4class{funData}} 54 | } 55 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(funData) 3 | 4 | test_check("funData") 5 | -------------------------------------------------------------------------------- /tests/testthat/outputs/print_funData.out: -------------------------------------------------------------------------------- 1 | Functional data with 4 observations of 1-dimensional support 2 | argvals: 3 | 1 2 3 4 5 (5 sampling points) 4 | X: 5 | array of size 4 x 5 6 | -------------------------------------------------------------------------------- /tests/testthat/outputs/print_irregFunData.out: -------------------------------------------------------------------------------- 1 | Irregular functional data with 3 observations of 1-dimensional support 2 | argvals: 3 | Values in 1 ... 5. 4 | X: 5 | Values in -3 ... 5. 6 | Total: 7 | 11 observations on 5 different argvals (3 - 5 per observation). 8 | -------------------------------------------------------------------------------- /tests/testthat/outputs/print_multiFunData.out: -------------------------------------------------------------------------------- 1 | An object of class "multiFunData" 2 | [[1]] 3 | Functional data with 4 observations of 1-dimensional support 4 | argvals: 5 | 1 2 3 4 5 (5 sampling points) 6 | X: 7 | array of size 4 x 5 8 | 9 | [[2]] 10 | Functional data with 4 observations of 2-dimensional support 11 | argvals: 12 | 1 2 3 4 5 (5 sampling points) 13 | 1 2 ... 6 (6 sampling points) 14 | X: 15 | array of size 4 x 5 x 6 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/outputs/str_funData.out: -------------------------------------------------------------------------------- 1 | Functional data: 2 | 4 observations of 1-dimensional support with 5 sampling points. 3 | @argvals: 4 | [[1]]: int [1:5] 1 2 3 4 5 5 | 6 | @X: 7 | int [1:4, 1:5] 1 2 3 4 5 6 7 8 9 10 ... 8 | -------------------------------------------------------------------------------- /tests/testthat/outputs/str_irregFunData.out: -------------------------------------------------------------------------------- 1 | IrregFunData: 2 | 3 observations of 1-dimensional support on 5 different argvals (3 - 5 per curve). 3 | 4 | @argvals: List of 3 5 | $ : int [1:5] 1 2 3 4 5 6 | $ : int [1:3] 2 3 4 7 | $ : int [1:3] 3 4 5 8 | 9 | @X: List of 3 10 | $ : int [1:5] 1 2 3 4 5 11 | $ : int [1:3] 2 3 4 12 | $ : int [1:3] -3 -2 -1 13 | -------------------------------------------------------------------------------- /tests/testthat/outputs/str_irregFunData_len1.out: -------------------------------------------------------------------------------- 1 | IrregFunData: 2 | 3 observations of 1-dimensional support on 5 different argvals (3 - 5 per curve). 3 | 4 | @argvals: List of 3 5 | $ : int [1:5] 1 2 3 4 5 6 | [list output truncated] 7 | 8 | @X: List of 3 9 | $ : int [1:5] 1 2 3 4 5 10 | [list output truncated] 11 | -------------------------------------------------------------------------------- /tests/testthat/outputs/str_multiFunData.out: -------------------------------------------------------------------------------- 1 | MultiFunData with 2 elements: 2 | --- 3 | Element 1 : Functional data: 4 | 4 observations of 1-dimensional support with 5 sampling points. 5 | @argvals: 6 | [[1]]: int [1:5] 1 2 3 4 5 7 | 8 | @X: 9 | int [1:4, 1:5] 1 2 3 4 5 6 7 8 9 10 ... 10 | --- 11 | Element 2 : Functional data: 12 | 4 observations of 2-dimensional support with 5 x 6 sampling points. 13 | @argvals: 14 | [[1]]: int [1:5] 1 2 3 4 5 15 | [[2]]: int [1:6] 1 2 3 4 5 6 16 | 17 | @X: 18 | int [1:4, 1:5, 1:6] 1 2 3 4 5 6 7 8 9 10 ... 19 | --- 20 | -------------------------------------------------------------------------------- /tests/testthat/outputs/str_multiFunData_2.out: -------------------------------------------------------------------------------- 1 | MultiFunData with 2 elements: 2 | --- 3 | a : Functional data: 4 | 4 observations of 1-dimensional support with 5 sampling points. 5 | @argvals: 6 | [[1]]: int [1:5] 1 2 3 4 5 7 | 8 | @X: 9 | int [1:4, 1:5] 1 2 3 4 5 6 7 8 9 10 ... 10 | --- 11 | b : Functional data: 12 | 4 observations of 2-dimensional support with 5 x 6 sampling points. 13 | @argvals: 14 | [[1]]: int [1:5] 1 2 3 4 5 15 | [[2]]: int [1:6] 1 2 3 4 5 6 16 | 17 | @X: 18 | int [1:4, 1:5, 1:6] 1 2 3 4 5 6 7 8 9 10 ... 19 | --- 20 | -------------------------------------------------------------------------------- /tests/testthat/outputs/summary_funData.out: -------------------------------------------------------------------------------- 1 | Argument values (@argvals): 2 | Min. 1st Qu. Median Mean 3rd Qu. Max. 3 | Dim. 1 : 1 2 3 3 4 5 4 | 5 | Observed functions (@X): 6 | Obs 1 Obs 2 Obs 3 Obs 4 7 | Min. 1 2 3 4 8 | 1st Qu. 5 6 7 8 9 | Median 9 10 11 12 10 | Mean 9 10 11 12 11 | 3rd Qu. 13 14 15 16 12 | Max. 17 18 19 20 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/outputs/summary_funData_names.out: -------------------------------------------------------------------------------- 1 | Argument values (@argvals): 2 | Min. 1st Qu. Median Mean 3rd Qu. Max. 3 | Dim. 1 : 1 2 3 3 4 5 4 | 5 | Observed functions (@X): 6 | a b c d 7 | Min. 1 2 3 4 8 | 1st Qu. 5 6 7 8 9 | Median 9 10 11 12 10 | Mean 9 10 11 12 11 | 3rd Qu. 13 14 15 16 12 | Max. 17 18 19 20 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/outputs/summary_irregFunData.out: -------------------------------------------------------------------------------- 1 | Argument values (@argvals): 2 | Obs 1 Obs 2 Obs 3 3 | Min. 1 2.0 3.0 4 | 1st Qu. 2 2.5 3.5 5 | Median 3 3.0 4.0 6 | Mean 3 3.0 4.0 7 | 3rd Qu. 4 3.5 4.5 8 | Max. 5 4.0 5.0 9 | 10 | Observed functions (@X): 11 | Obs 1 Obs 2 Obs 3 12 | Min. 1 2.0 -3.0 13 | 1st Qu. 2 2.5 -2.5 14 | Median 3 3.0 -2.0 15 | Mean 3 3.0 -2.0 16 | 3rd Qu. 4 3.5 -1.5 17 | Max. 5 4.0 -1.0 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/outputs/summary_irregFunData_names.out: -------------------------------------------------------------------------------- 1 | Argument values (@argvals): 2 | a b c d 3 | Min. 1 1 1 1 4 | 1st Qu. 2 2 2 2 5 | Median 3 3 3 3 6 | Mean 3 3 3 3 7 | 3rd Qu. 4 4 4 4 8 | Max. 5 5 5 5 9 | 10 | Observed functions (@X): 11 | a b c d 12 | Min. 1 2 3 4 13 | 1st Qu. 5 6 7 8 14 | Median 9 10 11 12 15 | Mean 9 10 11 12 16 | 3rd Qu. 13 14 15 16 17 | Max. 17 18 19 20 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/outputs/summary_multiFunData.out: -------------------------------------------------------------------------------- 1 | --- Element 1 --- 2 | Argument values (@argvals): 3 | Min. 1st Qu. Median Mean 3rd Qu. Max. 4 | Dim. 1 : 1 2 3 3 4 5 5 | 6 | Observed functions (@X): 7 | Obs 1 Obs 2 Obs 3 Obs 4 8 | Min. 1 2 3 4 9 | 1st Qu. 5 6 7 8 10 | Median 9 10 11 12 11 | Mean 9 10 11 12 12 | 3rd Qu. 13 14 15 16 13 | Max. 17 18 19 20 14 | 15 | --- Element 2 --- 16 | Argument values (@argvals): 17 | Min. 1st Qu. Median Mean 3rd Qu. Max. 18 | Dim. 1 : 1 2.00 3.0 3.0 4.00 5 19 | Dim. 2 : 1 2.25 3.5 3.5 4.75 6 20 | 21 | Observed functions (@X): 22 | Obs 1 Obs 2 Obs 3 Obs 4 23 | Min. 1 2 3 4 24 | 1st Qu. 30 31 32 33 25 | Median 59 60 61 62 26 | Mean 59 60 61 62 27 | 3rd Qu. 88 89 90 91 28 | Max. 117 118 119 120 29 | 30 | -------------------------------------------------------------------------------- /tests/testthat/test_funDataClass.R: -------------------------------------------------------------------------------- 1 | context("Testing class definitions") 2 | 3 | test_that("funData class constructor", { 4 | # validity 5 | expect_error(funData(argvals = "Test", X = matrix(2, nrow = 1)), 6 | "unable to find an inherited method") # argvals is neither list nor vector of numerics 7 | expect_error(funData(argvals = list(1,"Test"), X = array(1:2, dim = c(1,1,1))), 8 | "All argvals elements must be numeric") # argvals contains non-numeric 9 | expect_error(funData(argvals = list(1:5), X = list(cbind(1:5,6:10))), 10 | "unable to find an inherited method") # X is not an array 11 | expect_error(funData(argvals = list(1:5), X = array(1:25, dim = c(1,5,5))), 12 | "argvals and X element have different support dimensions! X-Dimensions must be of the form N x M1 x ... x Md") # X has wrong dimensional support 13 | expect_error(funData(argvals = list(1:5, 1:4), X = array(1:25, dim = c(1,5,5))), 14 | "argvals and X have different number of sampling points! X-Dimensions must be of the form N x M1 x ... x Md") # X has wrong dimension (sampling points) 15 | 16 | # acception of NA values 17 | expect_is(funData(argvals = c(1:5), X = matrix(c(1:19, NA), nrow = 4)), "funData") 18 | 19 | # special cases: one-dimensional domain 20 | expect_equal(funData(argvals = 1:5, X = matrix(1:20, nrow = 4)), funData(argvals = list(1:5), X = matrix(1:20, nrow = 4))) 21 | }) 22 | 23 | 24 | test_that("multiFunData class constructor", { 25 | f1 <- funData(argvals = 1:5, X = matrix(1:20, nrow = 4)) 26 | 27 | # validity 28 | expect_error(multiFunData(list(5, 5)), 29 | "Elements of multiFunData must be of class funData!") 30 | expect_error(multiFunData(list(f1, funData(argvals = list(1:5, 6:10), X = array(1:125, c(5,5,5))))), 31 | "All elements must have the same number of observations!") 32 | 33 | # conversion 34 | expect_is(as(f1, "multiFunData"), "multiFunData") 35 | 36 | # different construction methods 37 | expect_equal(multiFunData(f1,f1), multiFunData(list(f1,f1))) 38 | }) 39 | 40 | 41 | test_that("irregfunData class constructor", { 42 | # Validity: 43 | # argvals 44 | expect_error(irregFunData(argvals = "Test", X = list(5)), 45 | "unable to find an inherited method") # argvals is no list 46 | expect_error(irregFunData(argvals = list("Test"), X = list(5)), 47 | "argvals must be supplied as list of numerics") # argvals is no list of numerics 48 | # X 49 | expect_error(irregFunData(argvals = list(5), X = "Test"), 50 | "unable to find an inherited method") # X is no list 51 | expect_error(irregFunData(argvals = list(5), X = list("Test")), 52 | "X must be supplied as list of numerics") # X is no list of numerics 53 | # relation between argvals and X 54 | expect_error(irregFunData(argvals = list(1:5), X = list(1:5, 2:4)), 55 | "Different number of observations for argvals and X") 56 | expect_error(irregFunData(argvals = list(1:5, 1:4), X = list(1:5, 2:4)), 57 | "Different numbers of observation points in argvals and X") 58 | }) 59 | 60 | test_that("coerce methods", { 61 | x <- seq(0,1,0.01) 62 | f <- funData(argvals = x, X = 1:5 %o% x) 63 | i1 <- irregFunData(argvals = list(1:5, 3:6), X = list(2:6, 4:7)) 64 | 65 | expect_error(as.irregFunData(tensorProduct(f,f)), 66 | "The funData object must be defined on a one-dimensional domain.") 67 | 68 | # coercion between methods 69 | expect_equal(f, as.multiFunData(f)[[1]]) 70 | expect_equal(as.funData(i1), {f1 <- funData(1:6, rbind(c(2:6, NA), c(NA,NA,4:7)))}) 71 | expect_equal(unique(unlist(i1@argvals)), f1@argvals[[1]]) 72 | expect_equal(i1@X, apply(f1@X, 1, na.omit), check.attributes = FALSE) 73 | expect_equal(i1, as.irregFunData(f1)) 74 | 75 | # coercion to data.frame 76 | fName <- f; names(fName) <- letters[1:nObs(fName)] 77 | expect_equal(head(as.data.frame(f), nObsPoints(f)), data.frame(obs = "1", argvals1 = x, X = f@X[1,]), check.attributes = FALSE) 78 | expect_equal(tail(as.data.frame(f), nObsPoints(f)), data.frame(obs = "5", argvals1 = x, X = f@X[5,]), check.attributes = FALSE) 79 | expect_equal(tail(as.data.frame(fName), nObsPoints(fName)), data.frame(obs = "e", argvals1 = x, X = f@X[5,]), check.attributes = FALSE) 80 | expect_equal(as.data.frame(as.multiFunData(f)), list(as.data.frame(f))) 81 | expect_equal(as.data.frame(i1), data.frame(obs = rep(c("1","2"), times = c(5,4)), argvals = unlist(argvals(i1)), X = unlist(X(i1)))) 82 | 83 | # coercion to fd from fda package 84 | if(!(requireNamespace("fda", quietly = TRUE))) 85 | { 86 | expect_warning(funData2fd(f), "Please install the fda package to use the funData2fd function for funData objects.") 87 | expect_warning(fd2funData(NULL), "Please install the fda package to use the fd2funData function for funData objects.") 88 | } 89 | else 90 | { 91 | library("fda") 92 | 93 | # from Data2fd help 94 | daybasis <- create.fourier.basis(c(0, 365), nbasis=65) 95 | tempfd <- Data2fd(argvals = day.5, y = CanadianWeather$dailyAv[,,"Temperature.C"], daybasis) 96 | 97 | # check errors 98 | expect_error(funData2fd("fun", daybasis), "Argument is not of class 'funData'.") 99 | expect_error(funData2fd(funData(argvals = list(1:5, 1:4), X = 3:1 %o% 1:5 %o% 1:4)), "funData2fd is only defined for functions on one-dimensional domains.") 100 | expect_error(fd2funData(tempfd, letters[1:5]), "Parameter 'argvals' must be either a vector of argument values or a list containing such a vector.") 101 | 102 | # check functionality 103 | tempFun <- fd2funData(tempfd, argvals = day.5) 104 | tempFun2 <- fd2funData(tempfd, argvals = list(day.5)) 105 | expect_equal(nObs(tempFun), 35) 106 | expect_equal(nObsPoints(tempFun), 365) 107 | expect_equal(mean(norm(tempFun)), 60906.17, tol = 1e-5) 108 | expect_equal(norm(tempFun)[1], 27068, tol = 1e-5) 109 | expect_equal(tempFun, tempFun2) 110 | 111 | reTempfd <- funData2fd(tempFun, daybasis) 112 | reTempfd$fdnames$time <- tempfd$fdnames$time # time names are not preserved 113 | expect_equal(tempfd, reTempfd) 114 | 115 | } 116 | }) 117 | 118 | -------------------------------------------------------------------------------- /tests/testthat/test_plotMethods.R: -------------------------------------------------------------------------------- 1 | context("Test plot methods") 2 | 3 | pdf(file=NULL) 4 | 5 | argvals <- seq(0,2*pi,0.01) 6 | # 1D 7 | object1D <- funData(argvals, outer(seq(0.75, 1.25, length.out = 11), sin(argvals))) 8 | 9 | # 2D 10 | X <- array(0, dim = c(2, length(argvals), length(argvals))) 11 | X[1,,] <- outer(argvals, argvals, function(x,y){sin((x-pi)^2 + (y-pi)^2)}) 12 | X[2,,] <- outer(argvals, argvals, function(x,y){sin(2*x*pi) * cos(2*y*pi)}) 13 | object2D <- funData(list(argvals, argvals), X) 14 | 15 | # multivariate 16 | m <- multiFunData(extractObs(object1D, obs = 1:2), object2D) 17 | 18 | # irreg 19 | i <- as.irregFunData(object1D) 20 | 21 | test_that("plots", { 22 | 23 | # funData 1D / 2D 24 | 25 | # check errors 26 | expect_error(plot(object1D, obs = "1"), 27 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 28 | expect_error(plot(object1D, obs = 0), 29 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 30 | expect_error(plot(object1D, obs = 50), 31 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 32 | expect_error(plot(object1D, plotNA = "Yes"), "Parameter 'plotNA' must be passed as a logical.") 33 | expect_error(plot(object1D, plotNA = c(TRUE, FALSE)), "Parameter 'plotNA' must be passed as a logical.") 34 | expect_error(plot(object1D, add = "Yes"), "Parameter 'add' must be passed as a logical.") 35 | expect_error(plot(object1D, add = c(TRUE, FALSE)), "Parameter 'add' must be passed as a logical.") 36 | 37 | expect_error(plot(funData(argvals = list(1:5,2:6,3:7), X = array(10*5*5*5, dim = c(10,5,5,5)))), 38 | "plot is implemented only for functional data with one- or two-dimensional domain") 39 | expect_error(plot(funData(argvals = list(1:5,2:6), X = array(10*5*5, dim = c(10,5,5))), obs = 1:2), 40 | "Specify one observation for plotting") 41 | expect_error(plot(funData(argvals = list(1:5,2:6), X = array(10*5*5, dim = c(10,5,5))), obs = 1, add = TRUE), 42 | "Option add = TRUE not implemented for images") 43 | 44 | # check functionality 45 | expect_null(plot(object1D, main = "One-dimensional functional data")) 46 | expect_null(plot(object1D, plotNA = TRUE)) 47 | 48 | expect_null(plot(object2D, main = "Two-dimensional functional data (obs 1)", obs = 1)) 49 | expect_null(plot(object2D, main = "Two-dimensional functional data (obs 1)", obs = 1, legend = FALSE)) 50 | 51 | # multiFunData 52 | # check errors 53 | expect_error(plot(m, obs = "1"), 54 | "Parameter 'obs' must be a vector of numerics with values between 1 and 2.") 55 | expect_error(plot(m, obs = 0), 56 | "Parameter 'obs' must be a vector of numerics with values between 1 and 2.") 57 | expect_error(plot(m, obs = 50), 58 | "Parameter 'obs' must be a vector of numerics with values between 1 and 2.") 59 | expect_error(plot(m, dim = "1"), 60 | "Parameter 'dim' must be a vector of numerics with values between 1 and 2.") 61 | expect_error(plot(m, dim = 0), 62 | "Parameter 'dim' must be a vector of numerics with values between 1 and 2.") 63 | expect_error(plot(m, dim = 5), 64 | "Parameter 'dim' must be a vector of numerics with values between 1 and 2.") 65 | expect_error(plot(m, par.plot = 1:2), 66 | "Parameter 'par.plot' must be either NULL or passed as a list.") 67 | expect_error(plot(m, main = 1:3), 68 | "Parameter 'main' must be either NULL or have lengths 1 or 2.") 69 | expect_error(plot(m, ylim = list(1:2,3:4,4:5)), 70 | "The ylim argument must be either a vector (used for all elements) or a list with values for each element.", fixed = TRUE) 71 | 72 | # check functionality 73 | expect_null(plot(m, xlab = "x", ylab = "y", main = "title", obs = 1)) 74 | expect_null(plot(m, xlab = c("x1", "x2"), ylab = c("y1", "y2"), 75 | main = c("title1", "title2"), obs = 2, par.plot = list(cex = 5))) 76 | expect_null(plot(multiFunData(object1D, exp(object1D)), log = c("","y"), ylim = list(c(-2,2), c(0.1,4)))) 77 | expect_null(plot(multiFunData(object1D + 2, exp(object1D)), log = "y", ylim = c(0.2,5))) 78 | 79 | # irregFunData 80 | # check errors 81 | expect_error(plot(i, obs = "1"), 82 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 83 | expect_error(plot(i, obs = 0), 84 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 85 | expect_error(plot(i, obs = 50), 86 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 87 | expect_error(plot(i, add = "Yes"), "Parameter 'add' must be passed as a logical.") 88 | expect_error(plot(i, add = c(TRUE, FALSE)), "Parameter 'add' must be passed as a logical.") 89 | 90 | expect_warning(plot(as.irregFunData(object1D), add = TRUE, log = "y"), 91 | "Parameter 'log' cannot be reset when 'add = TRUE'.", fixed = TRUE) 92 | 93 | # check functionality 94 | expect_null(plot(i)) 95 | expect_null(plot(i, col = c("green", "red"))) 96 | }) 97 | 98 | 99 | test_that("ggplots", { 100 | if(!(requireNamespace("ggplot2", quietly = TRUE))) # if ggplot2 is not available 101 | { 102 | expect_warning(autoplot(object1D), "Please install the ggplot2 package to use the autoplot function for funData objects.") 103 | expect_warning(autolayer(object1D), "Please install the ggplot2 package to use the autolayer function for funData objects.") 104 | expect_warning(autoplot(m), "Please install the ggplot2 package to use the autoplot function for multifunData objects.") 105 | expect_warning(autoplot(i), "Please install the ggplot2 package to use the autoplot function for irregfunData objects.") 106 | expect_warning(autolayer(i), "Please install the ggplot2 package to use the autolayer function for irregfunData objects.") 107 | } 108 | else 109 | { 110 | library("ggplot2") # load package 111 | g <- ggplot2::ggplot() # empty plot 112 | 113 | # funData 1D / 2D 114 | # check errors 115 | expect_error(autoplot(object1D, obs = "1"), 116 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 117 | expect_error(autoplot(object1D, obs = 0), 118 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 119 | expect_error(autoplot(object1D, obs = 50), 120 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 121 | expect_error(autoplot(object1D, plotNA = "Yes"), "Parameter 'plotNA' must be passed as a logical.") 122 | expect_error(g + autolayer(object1D, obs = "1"), 123 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 124 | expect_error(g + autolayer(object1D, obs = 0), 125 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 126 | expect_error(g + autolayer(object1D, obs = 50), 127 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 128 | expect_error(g + autolayer(object1D, plotNA = "Yes"), "Parameter 'plotNA' must be passed as a logical.") 129 | 130 | expect_error(autoplot(object1D, plotNA = c(TRUE, FALSE)), "Parameter 'plotNA' must be passed as a logical.") 131 | expect_error(autoplot(funData(argvals = list(1:5,2:6,3:7), X = array(10*5*5*5, dim = c(10,5,5,5)))), 132 | "plot is implemented only for functional data with one- or two-dimensional domain") 133 | expect_error(autoplot(funData(argvals = list(1:5,2:6), X = array(10*5*5, dim = c(10,5,5))), obs = 1:2), 134 | "Specify one observation for plotting") 135 | expect_error(autolayer(funData(argvals = list(1:5,2:6), X = array(10*5*5, dim = c(10,5,5))), obs = 1), 136 | "autolayer is implemented only for functional data with one-dimensional domain") 137 | 138 | # check functionality 139 | expect_s3_class(autoplot(object1D), "ggplot") 140 | expect_s3_class(autoplot(object2D, obs = 1), "ggplot") 141 | expect_s3_class(autoplot(object1D, plotNA = TRUE), "ggplot") 142 | expect_s3_class(g + autolayer(object1D), "ggplot") 143 | expect_s3_class(g + autolayer(object1D, plotNA = TRUE), "ggplot") 144 | 145 | # multiFunData 146 | # check errors 147 | expect_error(autoplot(m, dim = "1"), 148 | "Parameter 'dim' must be a vector of numerics with values between 1 and 2.") 149 | expect_error(autoplot(m, dim = 0), 150 | "Parameter 'dim' must be a vector of numerics with values between 1 and 2.") 151 | expect_error(autoplot(m, dim = 5), 152 | "Parameter 'dim' must be a vector of numerics with values between 1 and 2.") 153 | expect_error(autoplot(m, plotGrid = "Yes"), 154 | "Parameter 'plotGrid' must be passed as a logical.") 155 | expect_error(autoplot(m, plotGrid = c(TRUE, FALSE)), 156 | "Parameter 'plotGrid' must be passed as a logical.") 157 | 158 | # check functionality 159 | expect_equal(length(autoplot(multiFunData(object1D, 2*object1D), plotGrid = TRUE)), 2) 160 | expect_equal(length(autoplot(multiFunData(object1D, 2*object1D), plotGrid = FALSE)), 2) 161 | 162 | 163 | # irregFunData 164 | # check errors 165 | expect_error(autoplot(i, obs = "1"), 166 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 167 | expect_error(autoplot(i, obs = 0), 168 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 169 | expect_error(autoplot(i, obs = 50), 170 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 171 | expect_error(g + autolayer(i, obs = "1"), 172 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 173 | expect_error(g + autolayer(i, obs = 0), 174 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 175 | expect_error(g + autolayer(i, obs = 50), 176 | "Parameter 'obs' must be a vector of numerics with values between 1 and 11.") 177 | 178 | # check functionality 179 | expect_s3_class(autoplot(as.irregFunData(object1D)), "ggplot") 180 | 181 | 182 | ### deprecated ggplot functions 183 | expect_warning({tmp <- funData::ggplot(object1D)}); expect_s3_class(tmp, "ggplot") 184 | expect_warning({tmp <- funData::ggplot(object2D, obs = 1)}); expect_s3_class(tmp, "ggplot") 185 | expect_warning({tmp <- g + funData::ggplot(object1D, add = TRUE)}); expect_s3_class(tmp, "ggplot") 186 | 187 | expect_warning({tmp <- funData::ggplot(multiFunData(object1D, 2*object1D), plotGrid = TRUE)}); expect_equal(length(tmp), 2) 188 | expect_warning({tmp <- funData::ggplot(multiFunData(object1D, 2*object1D), plotGrid = FALSE)}); expect_equal(length(tmp), 2) 189 | expect_warning({tmp <- funData::ggplot(as.irregFunData(object1D))}); expect_s3_class(tmp, "ggplot") 190 | expect_warning({tmp <- g + funData::ggplot(as.irregFunData(object1D), add = TRUE)}); expect_s3_class(tmp, "ggplot") 191 | } 192 | }) 193 | 194 | dev.off() 195 | --------------------------------------------------------------------------------