Rank-transformation to normality of a variable or residuals from GLM analysis.
Usage
rntransform(formula,data,family=gaussian)
Arguments
formula
GLM formula for the variable to be transformed, or just the variable
data
data.frame or gwaa.data object containing the data
family
GLM family
Details
Rank-transformation to normality generates perfectly normal distribution
from ANY distribution, unless many/heavy ties are present in variable
(or residuals, if formula is used).
When formula is supplied, this procedure first calls ztransform,
and then applies rank transformation to residuals.
Value
Vector containing transformed variable, distributed as standard normal.
Author(s)
Yurii Aulchenko
See Also
ztransform
Examples
# uniformly distributed variable
x <- round(runif(200)*100)
# get 7 missing values
x[round(runif(7,min=1,max=100))] <- NA
# Z-transform
y0 <- ztransform(x)
# Rank-transform to normality
y1 <- rntransform(x)
# test normality of the original and transformed var
shapiro.test(x)
shapiro.test(y0)
shapiro.test(y1)
# plot histogram
par(mfcol=c(3,1))
hist(x)
hist(y0)
hist(y1)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(GenABEL)
Loading required package: MASS
Loading required package: GenABEL.data
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GenABEL/rntransform.Rd_%03d_medium.png", width=480, height=480)
> ### Name: rntransform
> ### Title: Rank-transformation to normality
> ### Aliases: rntransform
> ### Keywords: utilities
>
> ### ** Examples
>
> # uniformly distributed variable
> x <- round(runif(200)*100)
> # get 7 missing values
> x[round(runif(7,min=1,max=100))] <- NA
> # Z-transform
> y0 <- ztransform(x)
> # Rank-transform to normality
> y1 <- rntransform(x)
> # test normality of the original and transformed var
> shapiro.test(x)
Shapiro-Wilk normality test
data: x
W = 0.9655, p-value = 0.0001114
> shapiro.test(y0)
Shapiro-Wilk normality test
data: y0
W = 0.9655, p-value = 0.0001114
> shapiro.test(y1)
Shapiro-Wilk normality test
data: y1
W = 0.99843, p-value = 0.9997
> # plot histogram
> par(mfcol=c(3,1))
> hist(x)
> hist(y0)
> hist(y1)
>
>
>
>
>
> dev.off()
null device
1
>