Variance creates a streaming algorithm that can be used to calculate the population and sample variance of incoming values

Format

An R6Class generator object

Methods


Method new()

Creates a new Variance streamer object.

Usage

Variance$new(x = NULL, sample = FALSE)

Arguments

x

values to be used during initialization (optional)

Returns

The new Variance (invisibly)

Examples

variance <- Variance$new()


Method update()

Updates the Variance with a stream of new values

Usage

Variance$update(x)

Arguments

x

a vector of values to update the Variance

sample

for choosing between the population and sample variance. If `TRUE` the sample variance is returned. If `FALSE` the population variance is returned.

Returns

The updated Variance (invisibly)

Examples

variance <- Variance$new(c(1,2))
variance$update(c(3,4))


Method clone()

The objects of this class are cloneable with this method.

Usage

Variance$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

variance <- Variance$new(c(1, 2))
variance$update(c(3, 4))
variance$value
#> [1] 1.25
#> [1] 1.25


## ------------------------------------------------
## Method `Variance$new`
## ------------------------------------------------

variance <- Variance$new()


## ------------------------------------------------
## Method `Variance$update`
## ------------------------------------------------

variance <- Variance$new(c(1,2))
variance$update(c(3,4))