updateMean: Update the Sample Mean Vector

Description Usage Arguments Details Value See Also Examples

Description

Recursive update of the sample mean vector.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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 May 2, 2019, 3:28 a.m.