Learn R Programming

funData (version 1.3-9)

Arith.funData: Arithmetics for functional data objects

Description

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.

Usage

# S4 method for funData,funData
Arith(e1, e2)

# S4 method for funData,numeric Arith(e1, e2)

# S4 method for numeric,funData Arith(e1, e2)

# S4 method for multiFunData,multiFunData Arith(e1, e2)

# S4 method for multiFunData,numeric Arith(e1, e2)

# S4 method for numeric,multiFunData Arith(e1, e2)

# S4 method for irregFunData,numeric Arith(e1, e2)

# S4 method for numeric,irregFunData Arith(e1, e2)

# S4 method for irregFunData,irregFunData Arith(e1, e2)

# S4 method for irregFunData,funData Arith(e1, e2)

# S4 method for funData,irregFunData Arith(e1, e2)

Value

An object of the same functional data class as e1 or

e2, respectively.

Arguments

e1, e2

Objects of class funData, irregFunData, multiFunData or numeric. If two functional data objects are used, they must be of the same class, have the same domain and the same number of observations. For exceptions, see Details.

Warning

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.

Details

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 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.

See Also

funData, irregFunData, multiFunData, Arith

Examples

Run this code
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)

Run the code above in your browser using DataLab