meanFunction: Mean for functional data

meanFunctionR Documentation

Mean for functional data

Description

This function calculates the pointwise mean function for objects of class funData, irregFunData or multiFunData.

Usage

meanFunction(object, na.rm = FALSE)

Arguments

object

An object of class funData, irregFunData or multiFunData.

na.rm

Logical. If TRUE, NA values are removed before computing the mean. Defaults to FALSE.

Value

An object of the same class as object with one observation that corresponds to the pointwise mean function of the functions in object.

Warning

If object is of class irregFunData, the option na.rm = TRUE is not implemented and throws an error. If na.rm = FALSE, the functions must be observed on the same domain.

See Also

funData, irregFunData, multiFunData, Arith.funData

Examples

### Univariate (one-dimensional support)
x <- seq(0, 2*pi, 0.01)
f1 <- funData(x, outer(seq(0.75, 1.25, 0.05), sin(x)))

plot(f1)
plot(meanFunction(f1), col = 1, lwd = 2, add = TRUE)

### Univariate (two-dimensional support)
f2 <- funData(list(1:5, 1:3), array(rep(1:5,each = 11, times = 3), dim = c(11,5,3)))
all.equal(f2[1], meanFunction(f2)) # f2 has 11 identical observations

### Multivariate
m1 <- multiFunData(f1,f2)
all.equal(m1[6], meanFunction(m1)) # observation 6 equals the pointwise mean

### Irregular
i1 <- irregFunData(argvals = list(1:3,1:3,1:3), X = list(1:3,2:4,3:5))
all.equal(meanFunction(i1), i1[2])
# don't run: functions are not defined on the same domain
## Not run: meanFunction(irregFunData(argvals = list(1:3,1:5), X = list(1:3,1:5))) 

funData documentation built on May 29, 2024, 6:08 a.m.