Arithmetics for functional data objects
These functions allow basic arithmetics (such as '+', '-', '*', 'sqrt') for
functional data and numerics based on Arith
. The
operations are made pointwise for each observation. See examples below.
## S4 method for signature 'funData,funData' Arith(e1, e2) ## S4 method for signature 'funData,numeric' Arith(e1, e2) ## S4 method for signature 'numeric,funData' Arith(e1, e2) ## S4 method for signature 'multiFunData,multiFunData' Arith(e1, e2) ## S4 method for signature 'multiFunData,numeric' Arith(e1, e2) ## S4 method for signature 'numeric,multiFunData' Arith(e1, e2) ## S4 method for signature 'irregFunData,numeric' Arith(e1, e2) ## S4 method for signature 'numeric,irregFunData' Arith(e1, e2) ## S4 method for signature 'irregFunData,irregFunData' Arith(e1, e2) ## S4 method for signature 'irregFunData,funData' Arith(e1, e2) ## S4 method for signature 'funData,irregFunData' Arith(e1, e2)
e1, e2 |
Objects of class |
If two objects of a functional data class (funData
,
irregFunData
or multiFunData
) are used, they normally must be
of the same class, have the same domain and the same number of observations.
Exceptions are accepted if
one object has only one
observation. In this case, the arithmetic operations ('+', '-', '*', ...) are
done pairwise for this single function and all functions of the other object.
A typical example would be when subtracting the mean function from all
observations in a funData
object. This single function must be defined
on the same domain as the other functions (or, in case of
irregFunData
, on the union of all observation grids).
one of the
two objects is of class irregFunData
. Then, the other object can be of
class funData
, too, if it is defined on the union of all observation
grids. The result is an irregFunData
object which is defined on the
same observation grid as the original irregFunData
object.
An object of the same functional data class as e1
or
e2
, respectively.
Note that not all combinations of operations and classes
make sense, e.g. e1 ^ e2
is sensible if e1
is of class
funData
, irregFunData
or multiFunData
and e2
is
numeric. The reverse is not true.
oldpar <- par(no.readonly = TRUE) par(mfrow = c(3,2), mar = rep(2.1,4)) argvals <- seq(0, 2*pi, 0.01) object1 <- funData(argvals, outer(seq(0.75, 1.25, by = 0.05), sin(argvals))) object2 <- funData(argvals, outer(seq(0.75, 1.25, by = 0.05), cos(argvals))) plot(object1, main = "Object1") plot(object2, main = "Object2") # Only functional data objects plot(object1 + object2, main = "Sum") plot(object1 - object2, main = "Difference") # Mixed plot(4 * object1 + 5, main = "4 * Object1 + 5") # Note y-axis! plot(object1^2 + object2^2, main = "Pythagoras") ### Irregular ind <- replicate(11, sort(sample(1:length(argvals), sample(5:10, 1)))) i1 <- irregFunData( argvals = lapply(1:11, function(i, ind, x){x[ind[[i]]]}, ind = ind, x = object1@argvals[[1]]), X = lapply(1:11, function(i, ind, y){y[i, ind[[i]]]}, ind = ind, y = object1@X)) i2 <- irregFunData( argvals = lapply(1:11, function(i, ind, x){x[ind[[i]]]}, ind = ind, x = object2@argvals[[1]]), X = lapply(1:11, function(i, ind, y){y[i, ind[[i]]]}, ind = ind, y = object2@X)) plot(i1, main = "Object 1 (irregular)") plot(i2, main = "Object 2 (irregular)") # Irregular and regular functional data objects plot(i1 + i2, main = "Sum") plot(i1 - object2, main = "Difference") # Mixed plot(4 * i1 + 5, main = "4 * i1 + 5") # Note y-axis! plot(i1^2 + i2^2, main = "Pythagoras") par(oldpar)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.