updateMean: Update the Sample Mean Vector

updateMeanR Documentation

Update the Sample Mean Vector

Description

Recursive update of the sample mean vector.

Usage

updateMean(xbar, x, n, f, byrow = TRUE)

Arguments

xbar

current mean vector.

x

vector or matrix of new data.

n

sample size before observing x.

f

forgetting factor: a number in (0,1).

byrow

Are the observation vectors in x stored in rows (TRUE) or in columns (FALSE)?

Details

The forgetting factor f determines the balance between past and present observations in the PCA update: the closer it is to 1 (resp. to 0), the more weight is placed on current (resp. past) observations. At least one of the arguments n and f must be specified. If f is specified, its value overrides the argument n. For a given argument n, the default value off isk/(n+k), with k the number of new vector observations. This corresponds to a stationnary observation process.

Value

The updated mean vector.

See Also

updateCovariance

Examples

n <- 1e4
n0 <- 5e3
d <- 10
x <- matrix(runif(n*d), n, d)

## Direct computation
xbar1 <- colMeans(x)

## Recursive computation
xbar2 <- colMeans(x[1:n0,])
xbar2 <- updateMean(xbar2, x[(n0+1):n,], n0)

## Check equality
all.equal(xbar1, xbar2)

onlinePCA documentation built on Nov. 15, 2023, 9:07 a.m.