zscore: calculate (robust) zscore

Description Usage Arguments Details Value Methods (by class) Deviations Reference

View source: R/fun-zscore.R

Description

Given a numeric vector, convert the numbers to z scores or robust z scores. The function accepts raw values as well as normalized ones.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
zscore(x, ...)

## Default S3 method:
zscore(x, robust = TRUE, deviations = FALSE, reference, ...)

## S3 method for class 'data.frame'
zscore(x, robust = TRUE, deviations = FALSE, reference, variables, ...)

## S3 method for class 'grouped_df'
zscore(x, robust = TRUE, deviations = FALSE, reference, variables, ...)

Arguments

x

a numeric vector

...

arguments passed to methods

robust

logical flag whether to calculate normal or robust z scores

deviations

logical flag whether the supplied data is raw or normalized

reference

optional determination of reference observations; for the default method, a logical vector; for the data frame method, a logical vector or any predicate (bare or as string) that refers to x's variables

variables

for data frame method, character vector of variables to standardize

Details

The z score is a data point standardized to the distribution it comes from. It is a measure of the deviation of the point from the distribution's location parameter expressed in terms of the dispersion parameter of that distribution.

For a normal z score the difference between a point and the distribution mean is divided by the distribution's standard deviation. For a robust z score the mean and standard deviation are replaced by the median and median absolute deviation, respectively.

Value

a numeric vector of z scores or a data frame with added columns of z scores

Methods (by class)

Deviations

Data is accepted as raw or normalized and the function can be informed of this with a logical flag. For deviations the location parameter is assumed to be 0. If normalization is done by simply subtracting the mean/median of the whole sample from each data point, this is redundant but other normalization methods may introduce differences differences.

Reference

Data points in the sample can be standardized against part of the distribution rather than the whole. Should this be the case, supply a logical vector (or predicate that will be evaluated within the data frame) to determine the reference subpopulation.


olobiolo/acutils documentation built on Nov. 28, 2021, 9:35 p.m.