VarMeasures: Variability Measures

Description Usage Arguments Value Note Author(s) Examples

Description

Variability Measures

by_id - Internal function to allow a simple statistic (e.g., SD) to be calculated individually by an ID variable and returned either as per ID (i.e., wide form) or for every observation of an ID (i.e., long form).

sd_id - Calculates the standard deviation of observations by ID.

rmssd - Calculates the root mean square of successive differences (RMSSD). Note that missing values are removed.

rmssd_id - Calculates the RMSSD by ID.

rolling_diff - Calculates the average rolling difference of the data. Within each window, the difference between the maximum and minimum value is computed and these are averaged across all windows. The equation is:

\frac{∑_{t = 1}^{N - k} max(x_{t}, …, x_{t + k}) - min(x_{t}, …, x_{t + k})}{N - k}

rolling_diff_id - Calculates the average rolling difference by ID

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
by_id(x, ID, fun, long = TRUE, ...)

sd_id(x, ID, long = TRUE)

rmssd(x)

rmssd_id(x, ID, long = TRUE)

rolling_diff(x, window = 4)

rolling_diff_id(x, ID, long = TRUE, window = 4)

Arguments

x

A data vector to operate on. Should be a numeric or integer vector, or coercible to such (e.g., logical).

ID

an ID variable indicating how to split up the x vector. Should be the same length as x.

fun

The function to calculate by ID

long

A logical indicating whether to return results in “long” form (the default) or wide (if FALSE).

window

An integer indicating the size of the rolling window. Must be at least the length of x.

...

Additional arguments passed on to fun

Value

by_id - A vector the same length as x if long=TRUE, or the length of unique IDs if long=FALSE.

sd_id - A vector of the standard deviations by ID

rmssd - The RMSSD for the data.

rmssd_id - A vector of the RMSSDs by ID

rolling_diff - The average of the rolling differences between maximum and minimum.

rolling_diff_id - A vector of the average rolling differences by ID

Note

These are a set of functions designed to calculate various measures of variability either on a single data vector, or calculate them by an ID.

Author(s)

Joshua F. Wiley <[email protected]>

Examples

1
2
3
4
5
6
7
8
9
sd_id(mtcars$mpg, mtcars$cyl, long=TRUE)
sd_id(mtcars$mpg, mtcars$cyl, long=FALSE)
rmssd(1:4)
rmssd(c(1, 3, 2, 4))
rmssd_id(mtcars$mpg, mtcars$cyl)
rmssd_id(mtcars$mpg, mtcars$cyl, long=FALSE)
rolling_diff(1:7, window = 4)
rolling_diff(c(1, 4, 3, 4, 5))
rolling_diff_id(mtcars$mpg, mtcars$cyl, window = 3)

varian documentation built on May 29, 2017, 7:14 p.m.