boxcoxnc {AID}R Documentation

Box-Cox Transformation for Normality of a Variable

Description

boxcoxnc performs Box-Cox transformation for normality of a variable and provides graphical analysis.

Usage

boxcoxnc(data, method = "sw", lambda = seq(-3,3,0.01), lambda2 = NULL, plot = TRUE, 
  alpha = 0.05, verbose = TRUE)

Arguments

data

a numeric vector of data values.

method

a character string to select the desired method to be used to estimate Box-Cox transformation parameter. To use Shapiro-Wilk test method should be set to "sw". For method = "ad", boxcoxnc function uses Anderson-Darling test to estimate Box-Cox transformation parameter. Similarly, method should be set to "cvm", "pt", "sf", "lt", "jb", "ac", "mle" to use Cramer-von Mises, Pearson Chi-square, Shapiro-Francia, Lilliefors, Jarque-Bera tests, artificial covariate method and maximum likelihood estimation, respectively. Default is set to method = "sw".

lambda

a vector which includes the sequence of candidate lambda values. Default is set to (-3,3) with increment 0.01.

lambda2

a numeric for an additional shifting parameter. Default is set to lambda2 = 0.

plot

a logical to plot histogram with its density line and qqplot of raw and transformed data. Defaults plot = TRUE.

alpha

the level of significance to check the normality after transformation. Default is set to alpha = 0.05.

verbose

a logical for printing output to R console.

Details

Denote y the variable at the original scale and y' the transformed variable. The Box-Cox power transformation is defined by:

y' = \left\{ \begin{array}{ll} \frac{y^\lambda - 1}{\lambda} \mbox{ , if $\lambda \neq 0$} \cr log(y) \mbox{ , if $\lambda = 0$} \end{array} \right.

If the data include any nonpositive observations, a shifting parameter \lambda_2 can be included in the transformation given by:

y' = \left\{ \begin{array}{ll} \frac{(y + \lambda_2)^\lambda - 1}{\lambda} \mbox{ , if $\lambda \neq 0$} \cr log(y + \lambda_2) \mbox{ , if $\lambda = 0$} \end{array} \right.

Value

A list with class "boxcoxnc" containing the following elements:

method

method preferred to estimate Box-Cox transformation parameter

lambda.hat

estimate of Box-Cox Power transformation parameter based on corresponding method

lambda2

additional shifting parameter

statistic

statistic of normality test for transformed data based on specified normality test in method. For artificial covariate method, statistic is obtained by Shapiro-Wilk test for transformed data

p.value

p.value of normality test for transformed data based on specified normality test in method. For artificial covariate method, p.value is obtained by Shapiro-Wilk test for transformed data

alpha

the level of significance to assess normality.

tf.data

transformed data set

var.name

variable name

Author(s)

Osman Dag, Ozgur Asar, Ozlem Ilk

References

Asar, O., Ilk, O., Dag, O. (2017). Estimating Box-Cox Power Transformation Parameter via Goodness of Fit Tests. Communications in Statistics - Simulation and Computation, 46:1, 91–105.

Dag, O., Asar, O., Ilk, O. (2014). A Methodology to Implement Box-Cox Transformation When No Covariate is Available. Communications in Statistics - Simulation and Computation, 43:7, 1740–1759.

Examples


library(AID)

data(textile)

out <- boxcoxnc(textile[,1], method = "sw")
out$lambda.hat # the estimate of Box-Cox parameter based on Shapiro-Wilk test statistic 
out$p.value # p.value of Shapiro-Wilk test for transformed data 
out$tf.data # transformed data set
confInt(out) # mean and confidence interval for back transformed data


out2 <- boxcoxnc(textile[,1], method = "sf")
out2$lambda.hat # the estimate of Box-Cox parameter based on Shapiro-Francia test statistic
out2$p.value # p.value of Shapiro-Francia test for transformed data 
out2$tf.data 
confInt(out2) 

[Package AID version 2.9 Index]