zscore: Compute z-Scores

View source: R/zscore.R

zscoreR Documentation

Compute z-Scores

Description

The functions compute the classical z-score as well as two robust versions of z-scores.

Usage

zscore(x, na.rm = FALSE)
medZscore(x, na.rm = FALSE, constant = 1/qnorm(0.75))
iqrZscore(x, na.rm = FALSE, type = 7, constant = 2*qnorm(0.75))

Arguments

x

numeric vector with positive numbers.

na.rm

logical. Should missing values be removed?

type

an integer between 1 and 9 selecting one of nine quantile algorithms; for more details see quantile.

constant

standardizing contant; see mad and sIQR, respectively.

Details

The functions compute the (classical) zscore as well as two robust variants.

medZscore uses the (standardized) MAD instead of SD and median instead of mean.

iqrZscore uses the (standardized) IQR instead of SD and median instead of mean.

Value

z-score.

Author(s)

Matthias Kohl Matthias.Kohl@stamats.de

Examples

## 10% outliers
out <- rbinom(100, prob = 0.1, size = 1)
sum(out)
x <- (1-out)*rnorm(100, mean = 10, sd = 2) + out*25
z <- zscore(x)
z.med <- medZscore(x)
z.iqr <- iqrZscore(x)
## mean without outliers (should by close to 0)
mean(z[!out])
mean(z.med[!out])
mean(z.iqr[!out])
## sd without outliers (should by close to 1)
sd(z[!out])
sd(z.med[!out])
sd(z.iqr[!out])

stamats/MKdescr documentation built on Feb. 24, 2024, 2:11 p.m.