zise: Normal quantile transform data

Description Usage Arguments Details Value Author(s) Examples

Description

Transforms data so that it is normally distributed, using only the ranks of the data.

Usage

1
zise(x, only, by)

Arguments

x

a vector of values to be transformed

only

optional, logical vector of same length as x

by

optional, factor of same length as x

Details

The transformation is sometimes known as a normal quantile transform, an inverse normal transformation, or as a quantile-quantile normalisation of x.

If the argument only is provided, only the corresponding values of x are transformed, and the remainder are returned as NA.

If the argument by is provided, it is coerced to a factor if necessary, and the transformation is applied separately by subsets of x corresponding to each level of by.

Value

The vector of transformed values.

Author(s)

Toby Johnson Toby.x.Johnson@gsk.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  x <- rbeta(500, shape1 = 0.6, shape2 = 1)
  oldpar <- par(mfrow = c(1, 2))
  hist(x, breaks = 20, col = "red"); box()
  hist(zise(x), breaks = 20, col = "yellow"); box()

  par(mfrow = c(1, 3))
  x <- data.frame(gender = c(rep("Male", 100), rep("Female", 100)),
                  BMI = exp(c(rnorm(100, 3.3, 0.1), rnorm(100, 3.2, 0.2))))
  boxplot(BMI ~ gender, data = x) # not normal
  boxplot(zise(BMI) ~ gender, data = x) # normal overall but not within genders
  boxplot(zise(BMI, by = gender) ~ gender, data = x) # normal overall and within genders

  par(oldpar)

tobyjohnson/gtx documentation built on Aug. 30, 2019, 8:07 p.m.