R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: i686-pc-linux-gnu (32-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. > x <- c(46,62,66,59,58,61,41,27,58,70,49,59,44,36,72,45,56,54,53,35,61,52,47,51,52,63,74,45,51,64,36,30,55,64,39,40,63,45,59,55,40,64,27,28,45,57,45,69,60,56,58,50,51,53,37,22,55,70,62,58,39,49,58,47,42,62,39,40,72,70,54,65) > par5 = 'No' > par4 = '0' > par3 = '2' > par2 = '-1' > par1 = 'Full Box-Cox transform' > par5 <- 'No' > par4 <- '0' > par3 <- '2' > par2 <- '-1' > par1 <- 'Full Box-Cox transform' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 () > #Author: root > #To cite this work: Wessa P., (2013), Box-Cox Normality Plot (v1.1.5) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_boxcoxnorm.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > # > par2 <- abs(as.numeric(par2)*100) > par3 <- as.numeric(par3)*100 > if(par4=='') par4 <- 0 > par4 <- as.numeric(par4) > numlam <- par2 + par3 + 1 > x <- x + par4 > n <- length(x) > c <- array(NA,dim=c(numlam)) > l <- array(NA,dim=c(numlam)) > mx <- -1 > mxli <- -999 > for (i in 1:numlam) + { + l[i] <- (i-par2-1)/100 + if (l[i] != 0) + { + if (par1 == 'Full Box-Cox transform') x1 <- (x^l[i] - 1) / l[i] + if (par1 == 'Simple Box-Cox transform') x1 <- x^l[i] + } else { + x1 <- log(x) + } + c[i] <- cor(qnorm(ppoints(x), mean=0, sd=1),x1) + if (mx < c[i]) + { + mx <- c[i] + mxli <- l[i] + x1.best <- x1 + } + } > c [1] -1.005659e-02 -9.956708e-03 -9.856809e-03 -9.756889e-03 -9.656949e-03 [6] -9.556989e-03 -9.457008e-03 -9.357008e-03 -9.256989e-03 -9.156949e-03 [11] -9.056891e-03 -8.956814e-03 -8.856717e-03 -8.756603e-03 -8.656469e-03 [16] -8.556318e-03 -8.456148e-03 -8.355961e-03 -8.255756e-03 -8.155534e-03 [21] -8.055294e-03 -7.955038e-03 -7.854765e-03 -7.754475e-03 -7.654168e-03 [26] -7.553846e-03 -7.453507e-03 -7.353153e-03 -7.252783e-03 -7.152398e-03 [31] -7.051998e-03 -6.951582e-03 -6.851152e-03 -6.750707e-03 -6.650248e-03 [36] -6.549775e-03 -6.449288e-03 -6.348787e-03 -6.248272e-03 -6.147744e-03 [41] -6.047203e-03 -5.946649e-03 -5.846083e-03 -5.745503e-03 -5.644912e-03 [46] -5.544308e-03 -5.443693e-03 -5.343065e-03 -5.242427e-03 -5.141777e-03 [51] -5.041116e-03 -4.940444e-03 -4.839761e-03 -4.739068e-03 -4.638365e-03 [56] -4.537651e-03 -4.436928e-03 -4.336195e-03 -4.235453e-03 -4.134701e-03 [61] -4.033941e-03 -3.933172e-03 -3.832394e-03 -3.731607e-03 -3.630813e-03 [66] -3.530010e-03 -3.429200e-03 -3.328382e-03 -3.227557e-03 -3.126725e-03 [71] -3.025886e-03 -2.925040e-03 -2.824187e-03 -2.723329e-03 -2.622464e-03 [76] -2.521593e-03 -2.420717e-03 -2.319835e-03 -2.218948e-03 -2.118055e-03 [81] -2.017158e-03 -1.916257e-03 -1.815351e-03 -1.714440e-03 -1.613526e-03 [86] -1.512608e-03 -1.411687e-03 -1.310762e-03 -1.209833e-03 -1.108902e-03 [91] -1.007969e-03 -9.070323e-04 -8.060936e-04 -7.051529e-04 -6.042103e-04 [96] -5.032661e-04 -4.023204e-04 -3.013734e-04 -2.004254e-04 -9.947663e-05 [101] 1.472773e-06 1.024226e-04 2.033725e-04 3.043225e-04 4.052722e-04 [106] 5.062214e-04 6.071699e-04 7.081176e-04 8.090641e-04 9.100093e-04 [111] 1.010953e-03 1.111895e-03 1.212835e-03 1.313773e-03 1.414708e-03 [116] 1.515641e-03 1.616571e-03 1.717497e-03 1.818421e-03 1.919341e-03 [121] 2.020257e-03 2.121170e-03 2.222078e-03 2.322982e-03 2.423882e-03 [126] 2.524776e-03 2.625666e-03 2.726550e-03 2.827429e-03 2.928302e-03 [131] 3.029170e-03 3.130031e-03 3.230886e-03 3.331734e-03 3.432576e-03 [136] 3.533410e-03 3.634237e-03 3.735057e-03 3.835870e-03 3.936674e-03 [141] 4.037470e-03 4.138258e-03 4.239037e-03 4.339808e-03 4.440569e-03 [146] 4.541322e-03 4.642065e-03 4.742798e-03 4.843521e-03 4.944234e-03 [151] 5.044937e-03 5.145629e-03 5.246311e-03 5.346981e-03 5.447640e-03 [156] 5.548288e-03 5.648924e-03 5.749547e-03 5.850159e-03 5.950758e-03 [161] 6.051345e-03 6.151919e-03 6.252480e-03 6.353027e-03 6.453561e-03 [166] 6.554081e-03 6.654587e-03 6.755079e-03 6.855556e-03 6.956018e-03 [171] 7.056466e-03 7.156898e-03 7.257315e-03 7.357716e-03 7.458102e-03 [176] 7.558471e-03 7.658824e-03 7.759160e-03 7.859479e-03 7.959782e-03 [181] 8.060067e-03 8.160334e-03 8.260584e-03 8.360815e-03 8.461029e-03 [186] 8.561224e-03 8.661400e-03 8.761557e-03 8.861694e-03 8.961813e-03 [191] 9.061911e-03 9.161990e-03 9.262048e-03 9.362086e-03 9.462104e-03 [196] 9.562100e-03 9.662075e-03 9.762029e-03 9.861961e-03 9.961871e-03 [201] 1.006176e-02 1.016162e-02 1.026147e-02 1.036129e-02 1.046108e-02 [206] 1.056086e-02 1.066061e-02 1.076033e-02 1.086003e-02 1.095971e-02 [211] 1.105936e-02 1.115899e-02 1.125859e-02 1.135817e-02 1.145772e-02 [216] 1.155725e-02 1.165675e-02 1.175622e-02 1.185567e-02 1.195509e-02 [221] 1.205448e-02 1.215384e-02 1.225318e-02 1.235249e-02 1.245177e-02 [226] 1.255102e-02 1.265024e-02 1.274944e-02 1.284860e-02 1.294774e-02 [231] 1.304685e-02 1.314592e-02 1.324497e-02 1.334398e-02 1.344297e-02 [236] 1.354192e-02 1.364084e-02 1.373973e-02 1.383859e-02 1.393742e-02 [241] 1.403621e-02 1.413497e-02 1.423370e-02 1.433239e-02 1.443105e-02 [246] 1.452968e-02 1.462828e-02 1.472683e-02 1.482536e-02 1.492385e-02 [251] 1.502230e-02 1.512072e-02 1.521911e-02 1.531746e-02 1.541577e-02 [256] 1.551404e-02 1.561228e-02 1.571048e-02 1.580865e-02 1.590678e-02 [261] 1.600486e-02 1.610292e-02 1.620093e-02 1.629890e-02 1.639684e-02 [266] 1.649473e-02 1.659259e-02 1.669041e-02 1.678819e-02 1.688592e-02 [271] 1.698362e-02 1.708127e-02 1.717889e-02 1.727646e-02 1.737399e-02 [276] 1.747148e-02 1.756893e-02 1.766634e-02 1.776370e-02 1.786102e-02 [281] 1.795829e-02 1.805552e-02 1.815271e-02 1.824986e-02 1.834696e-02 [286] 1.844401e-02 1.854102e-02 1.863799e-02 1.873491e-02 1.883178e-02 [291] 1.892861e-02 1.902539e-02 1.912212e-02 1.921881e-02 1.931545e-02 [296] 1.941204e-02 1.950859e-02 1.960508e-02 1.970153e-02 1.979793e-02 [301] 1.989428e-02 > mx [1] 0.01989428 > mxli [1] 2 > x1.best [1] 1057.5 1921.5 2177.5 1740.0 1681.5 1860.0 840.0 364.0 1681.5 2449.5 [11] 1200.0 1740.0 967.5 647.5 2591.5 1012.0 1567.5 1457.5 1404.0 612.0 [21] 1860.0 1351.5 1104.0 1300.0 1351.5 1984.0 2737.5 1012.0 1300.0 2047.5 [31] 647.5 449.5 1512.0 2047.5 760.0 799.5 1984.0 1012.0 1740.0 1512.0 [41] 799.5 2047.5 364.0 391.5 1012.0 1624.0 1012.0 2380.0 1799.5 1567.5 [51] 1681.5 1249.5 1300.0 1404.0 684.0 241.5 1512.0 2449.5 1921.5 1681.5 [61] 760.0 1200.0 1681.5 1104.0 881.5 1921.5 760.0 799.5 2591.5 2449.5 [71] 1457.5 2112.0 > if (mxli != 0) + { + if (par1 == 'Full Box-Cox transform') x1 <- (x^mxli - 1) / mxli + if (par1 == 'Simple Box-Cox transform') x1 <- x^mxli + } else { + x1 <- log(x) + } > postscript(file="/var/wessaorg/rcomp/tmp/1ujcw1384975199.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(l,c,main='Box-Cox Normality Plot', xlab='Lambda',ylab='correlation') > mtext(paste('Optimal Lambda =',mxli)) > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/25xr71384975200.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > hist(x,main='Histogram of Original Data',xlab='X',ylab='frequency') > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/3p1vv1384975200.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > hist(x1,main='Histogram of Transformed Data', xlab='X',ylab='frequency') > grid() > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/42qz61384975200.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(x) > qqline(x) > grid() > mtext('Original Data') > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/5orv11384975200.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqnorm(x1) > qqline(x1) > grid() > mtext('Transformed Data') > dev.off() null device 1 > > #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Box-Cox Normality Plot',2,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'# observations x',header=TRUE) > a<-table.element(a,n) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'maximum correlation',header=TRUE) > a<-table.element(a,mx) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'optimal lambda',header=TRUE) > a<-table.element(a,mxli) > a<-table.row.end(a) > if(mx<0) { + a<-table.row.start(a) + a<-table.element(a,'Warning: maximum correlation is negative! The Box-Cox transformation must not be used.',2) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/6tsa91384975200.tab") > if(par5=='Yes') { + a<-table.start() + a<-table.row.start(a) + a<-table.element(a,'Obs.',header=T) + a<-table.element(a,'Original',header=T) + a<-table.element(a,'Transformed',header=T) + a<-table.row.end(a) + for (i in 1:n) { + a<-table.row.start(a) + a<-table.element(a,i) + a<-table.element(a,x[i]) + a<-table.element(a,x1.best[i]) + a<-table.row.end(a) + } + a<-table.end(a) + table.save(a,file="/var/wessaorg/rcomp/tmp/720v51384975200.tab") + } > > try(system("convert tmp/1ujcw1384975199.ps tmp/1ujcw1384975199.png",intern=TRUE)) character(0) > try(system("convert tmp/25xr71384975200.ps tmp/25xr71384975200.png",intern=TRUE)) character(0) > try(system("convert tmp/3p1vv1384975200.ps tmp/3p1vv1384975200.png",intern=TRUE)) character(0) > try(system("convert tmp/42qz61384975200.ps tmp/42qz61384975200.png",intern=TRUE)) character(0) > try(system("convert tmp/5orv11384975200.ps tmp/5orv11384975200.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.236 0.996 6.216