R version 3.3.3 (2017-03-06) -- "Another Canoe" Copyright (C) 2017 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. > > RC.capture <- function (expression, collapse = NULL) { + resultConn <- textConnection('RC.resultText', open = 'w', local=TRUE) + sink(resultConn) + on.exit(function() { + sink() + close(resultConn) + }) + expression + on.exit(NULL) + sink() + close(resultConn) + return(paste(c(RC.resultText, ''), collapse = collapse, sep = '')) + } > RC.texteval <- function (sourceText, collapse = NULL, echo = TRUE) { + sourceConn <- textConnection(sourceText, open = 'r') + on.exit(close(sourceConn)) + result <- RC.capture(source(file = sourceConn, local = FALSE, echo = echo, print.eval = TRUE), collapse = collapse) + on.exit(NULL) + close(sourceConn) + res <- '' + for(i in 1:length(result)) { + if (result[i]!='') res <- paste(res,result[i],' + ',sep='') + } + return(res) + } > x <- c(0.79,1.08,1.09,1.00,1.12,1.19,0.90,1.05,1.14,1.17,1.09,1.20,0.79,1.14,1.13,0.74,1.11,1.05,0.95,1.09,1.09,0.74,1.15,1.11) > par5 = 'No' > par4 = '0' > par3 = '2' > par2 = '-2' > par1 = 'Full Box-Cox transform' > par5 <- 'No' > par4 <- '0' > par3 <- '2' > par2 <- '-2' > par1 <- 'Full Box-Cox transform' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 (Mon, 14 Sep 2015 12:57:53 +0100) > #Author: root > #To cite this work: Wessa P., (2015), Box-Cox Normality Plot (v1.1.11) 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 > # > library(car) > 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),sort(x1)) + if (mx < c[i]) + { + mx <- c[i] + mxli <- l[i] + x1.best <- x1 + } + } > c [1] 0.8546087 0.8548150 0.8550214 0.8552278 0.8554341 0.8556405 0.8558469 [8] 0.8560534 0.8562598 0.8564662 0.8566727 0.8568792 0.8570857 0.8572922 [15] 0.8574986 0.8577052 0.8579117 0.8581182 0.8583247 0.8585313 0.8587378 [22] 0.8589443 0.8591509 0.8593574 0.8595640 0.8597706 0.8599771 0.8601837 [29] 0.8603902 0.8605968 0.8608034 0.8610099 0.8612165 0.8614230 0.8616296 [36] 0.8618361 0.8620427 0.8622492 0.8624557 0.8626623 0.8628688 0.8630753 [43] 0.8632818 0.8634883 0.8636948 0.8639013 0.8641077 0.8643142 0.8645206 [50] 0.8647270 0.8649335 0.8651399 0.8653462 0.8655526 0.8657590 0.8659653 [57] 0.8661716 0.8663779 0.8665842 0.8667905 0.8669968 0.8672030 0.8674092 [64] 0.8676154 0.8678215 0.8680277 0.8682338 0.8684399 0.8686460 0.8688520 [71] 0.8690580 0.8692640 0.8694700 0.8696759 0.8698818 0.8700877 0.8702936 [78] 0.8704994 0.8707052 0.8709110 0.8711167 0.8713224 0.8715280 0.8717337 [85] 0.8719392 0.8721448 0.8723503 0.8725558 0.8727612 0.8729666 0.8731720 [92] 0.8733773 0.8735826 0.8737879 0.8739931 0.8741982 0.8744034 0.8746084 [99] 0.8748135 0.8750185 0.8752234 0.8754283 0.8756332 0.8758380 0.8760427 [106] 0.8762474 0.8764521 0.8766567 0.8768612 0.8770658 0.8772702 0.8774746 [113] 0.8776790 0.8778832 0.8780875 0.8782917 0.8784958 0.8786999 0.8789039 [120] 0.8791078 0.8793117 0.8795156 0.8797194 0.8799231 0.8801267 0.8803303 [127] 0.8805339 0.8807373 0.8809407 0.8811441 0.8813473 0.8815506 0.8817537 [134] 0.8819568 0.8821598 0.8823627 0.8825656 0.8827684 0.8829711 0.8831738 [141] 0.8833764 0.8835789 0.8837813 0.8839837 0.8841860 0.8843882 0.8845903 [148] 0.8847924 0.8849944 0.8851963 0.8853981 0.8855999 0.8858016 0.8860031 [155] 0.8862047 0.8864061 0.8866074 0.8868087 0.8870099 0.8872110 0.8874120 [162] 0.8876129 0.8878137 0.8880145 0.8882151 0.8884157 0.8886162 0.8888166 [169] 0.8890169 0.8892171 0.8894172 0.8896172 0.8898172 0.8900170 0.8902168 [176] 0.8904164 0.8906160 0.8908154 0.8910148 0.8912140 0.8914132 0.8916123 [183] 0.8918112 0.8920101 0.8922088 0.8924075 0.8926061 0.8928045 0.8930029 [190] 0.8932011 0.8933992 0.8935973 0.8937952 0.8939930 0.8941907 0.8943883 [197] 0.8945858 0.8947832 0.8949805 0.8951777 0.8953747 0.8955716 0.8957685 [204] 0.8959652 0.8961618 0.8963583 0.8965546 0.8967509 0.8969470 0.8971430 [211] 0.8973389 0.8975347 0.8977303 0.8979259 0.8981213 0.8983166 0.8985118 [218] 0.8987068 0.8989017 0.8990965 0.8992912 0.8994858 0.8996802 0.8998745 [225] 0.9000686 0.9002627 0.9004566 0.9006504 0.9008440 0.9010375 0.9012309 [232] 0.9014242 0.9016173 0.9018103 0.9020031 0.9021959 0.9023884 0.9025809 [239] 0.9027732 0.9029654 0.9031574 0.9033493 0.9035411 0.9037327 0.9039242 [246] 0.9041155 0.9043067 0.9044978 0.9046887 0.9048794 0.9050701 0.9052605 [253] 0.9054509 0.9056410 0.9058311 0.9060210 0.9062107 0.9064003 0.9065898 [260] 0.9067790 0.9069682 0.9071572 0.9073460 0.9075347 0.9077232 0.9079116 [267] 0.9080998 0.9082879 0.9084758 0.9086636 0.9088512 0.9090386 0.9092259 [274] 0.9094131 0.9096000 0.9097868 0.9099735 0.9101600 0.9103463 0.9105324 [281] 0.9107184 0.9109043 0.9110899 0.9112755 0.9114608 0.9116460 0.9118310 [288] 0.9120158 0.9122005 0.9123850 0.9125693 0.9127535 0.9129375 0.9131213 [295] 0.9133050 0.9134884 0.9136717 0.9138549 0.9140378 0.9142206 0.9144032 [302] 0.9145857 0.9147679 0.9149500 0.9151319 0.9153136 0.9154952 0.9156765 [309] 0.9158577 0.9160387 0.9162196 0.9164002 0.9165807 0.9167610 0.9169411 [316] 0.9171210 0.9173007 0.9174802 0.9176596 0.9178388 0.9180178 0.9181966 [323] 0.9183752 0.9185536 0.9187318 0.9189099 0.9190877 0.9192654 0.9194429 [330] 0.9196201 0.9197972 0.9199741 0.9201508 0.9203273 0.9205036 0.9206798 [337] 0.9208557 0.9210314 0.9212069 0.9213823 0.9215574 0.9217323 0.9219071 [344] 0.9220816 0.9222560 0.9224301 0.9226040 0.9227778 0.9229513 0.9231246 [351] 0.9232978 0.9234707 0.9236434 0.9238159 0.9239882 0.9241603 0.9243322 [358] 0.9245039 0.9246754 0.9248467 0.9250177 0.9251886 0.9253592 0.9255297 [365] 0.9256999 0.9258699 0.9260397 0.9262093 0.9263787 0.9265479 0.9267168 [372] 0.9268856 0.9270541 0.9272224 0.9273905 0.9275584 0.9277260 0.9278935 [379] 0.9280607 0.9282277 0.9283945 0.9285611 0.9287274 0.9288936 0.9290595 [386] 0.9292252 0.9293906 0.9295559 0.9297209 0.9298857 0.9300503 0.9302147 [393] 0.9303788 0.9305427 0.9307064 0.9308698 0.9310331 0.9311961 0.9313589 [400] 0.9315214 0.9316837 > mx [1] 0.9316837 > mxli [1] 2 > x1.best [1] -0.18795 0.08320 0.09405 0.00000 0.12720 0.20805 -0.09500 0.05125 [9] 0.14980 0.18445 0.09405 0.22000 -0.18795 0.14980 0.13845 -0.22620 [17] 0.11605 0.05125 -0.04875 0.09405 0.09405 -0.22620 0.16125 0.11605 > 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) + } > mypT <- powerTransform(x) > summary(mypT) bcPower Transformation to Normality Est.Power Std.Err. Wald Lower Bound Wald Upper Bound x 5.4641 1.7344 2.0646 8.8636 Likelihood ratio tests about transformation parameters LRT df pval LR test, lambda = (0) 11.298744 1 0.0007755954 LR test, lambda = (1) 7.412399 1 0.0064775897 > postscript(file="/var/wessaorg/rcomp/tmp/1qchv1495043043.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/28msk1495043043.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/323r21495043043.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/462hk1495043043.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqPlot(x) > grid() > mtext('Original Data') > dev.off() null device 1 > postscript(file="/var/wessaorg/rcomp/tmp/5fjk61495043043.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > qqPlot(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) > a<-table.row.start(a) > a<-table.element(a,'transformation formula',header=TRUE) > if (par1 == 'Full Box-Cox transform') { + a<-table.element(a,'for all lambda <> 0 : T(Y) = (Y^lambda - 1) / lambda') + } else { + a<-table.element(a,'for all lambda <> 0 : T(Y) = Y^lambda') + } > 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/6k3nz1495043043.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/7kq0m1495043043.tab") + } > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Maximum Likelihood Estimation of Lambda',1,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,paste('
',RC.texteval('summary(mypT)'),'
',sep='')) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/8mmtf1495043043.tab") > > try(system("convert tmp/1qchv1495043043.ps tmp/1qchv1495043043.png",intern=TRUE)) character(0) > try(system("convert tmp/28msk1495043043.ps tmp/28msk1495043043.png",intern=TRUE)) character(0) > try(system("convert tmp/323r21495043043.ps tmp/323r21495043043.png",intern=TRUE)) character(0) > try(system("convert tmp/462hk1495043043.ps tmp/462hk1495043043.png",intern=TRUE)) character(0) > try(system("convert tmp/5fjk61495043043.ps tmp/5fjk61495043043.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 9.769 0.542 10.609