In statistics, a \(z\)-score (standard score) is a signed value that indicates the number of standard deviations by which a data point is above or below the mean. A positive value indicates that the data point is above the mean. A negative value indicates that the data point is below the mean. It is calculated by subtracting the mean \(\left(\mu\right)\) from the data point \(\left(x\right)\) and dividing by the standard deviation \(\left(\sigma = \sqrt{\sigma^2}\right)\).

The z function

The z function performs this calculation.

Example

Generating \(x\)

set.seed(42)
x <- rnorm(n = 1000, mean = 100, sd = 15)
hist(x)

Calculating \(z\)-scores

library(boilerplatePackage)
std <- z(x = x, mu = 100, sigma = 15)
hist(std, main = "Histogram of z")