Description Usage Arguments Details Value Methods (by class) Deviations Reference Grouped data frames (dplyr package)
Given a numeric vector, convert the numbers to z scores or robust z scores. The function accepts raw values as well as normalized ones.
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, ...)
|
x |
a numeric vector, a data.frame, or a grouped data frame |
... |
arguments passed to methods |
robust |
logical flag; if TRUE (the default), calculate robust z scores |
deviations |
logical flag; set to FALSE (the default) if the supplied data is raw and to TRUE (the default) if it has been normalized |
reference |
optional specification of reference observations:
for the default method, a logical vector,
for the data frame method, either a logical vector
or any predicate (bare or as string) that refers to |
variables |
for data frame method, character vector of variables to standardize |
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.
A numeric vector of z scores or a data frame with added columns of z scores.
default
: for numeric vectors
data.frame
: calculates zscores for requested variables in a data frame
grouped_df
: see data.frame__to__grouped_df
Data can be raw or normalized and this is specified 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 behave differently.
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.
dplyr
package)The method for class grouped_df
is home made because the native behavior
of grouped data frames does not readily support functions that return data frames.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.