R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(112,118,132,129,121,135,148,148,136,119,104,118,115,126,141,135,125,149,170,170,158,133,114,140,145,150,178,163,172,178,199,199,184,162,146,166,171,180,193,181,183,218,230,242,209,191,172,194,196,196,236,235,229,243,264,272,237,211,180,201,204,188,235,227,234,264,302,293,259,229,203,229,242,233,267,269,270,315,364,347,312,274,237,278,284,277,317,313,318,374,413,405,355,306,271,306,315,301,356,348,355,422,465,467,404,347,305,336,340,318,362,348,363,435,491,505,404,359,310,337,360,342,406,396,420,472,548,559,463,407,362,405,417,391,419,461,472,535,622,606,508,461,390,432) > par3 = '2' > par2 = '-2' > par1 = 'Full Box-Cox transform' > par3 <- '2' > par2 <- '-2' > par1 <- 'Full Box-Cox transform' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa P., (2012), Box-Cox Normality Plot (v1.1.3) 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 > numlam <- par2 + par3 + 1 > n <- length(x) > c <- array(NA,dim=c(numlam)) > l <- array(NA,dim=c(numlam)) > mx <- 0 > 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] + } + } > c [1] 0.8571024 0.8577127 0.8583215 0.8589290 0.8595350 0.8601396 0.8607427 [8] 0.8613444 0.8619445 0.8625431 0.8631401 0.8637356 0.8643296 0.8649219 [15] 0.8655126 0.8661016 0.8666890 0.8672748 0.8678588 0.8684411 0.8690217 [22] 0.8696005 0.8701776 0.8707528 0.8713263 0.8718979 0.8724676 0.8730355 [29] 0.8736015 0.8741656 0.8747277 0.8752879 0.8758462 0.8764024 0.8769566 [36] 0.8775088 0.8780589 0.8786070 0.8791530 0.8796968 0.8802385 0.8807781 [43] 0.8813155 0.8818507 0.8823836 0.8829144 0.8834428 0.8839690 0.8844929 [50] 0.8850145 0.8855338 0.8860507 0.8865652 0.8870773 0.8875869 0.8880942 [57] 0.8885990 0.8891012 0.8896010 0.8900983 0.8905930 0.8910851 0.8915747 [64] 0.8920616 0.8925460 0.8930276 0.8935066 0.8939829 0.8944565 0.8949274 [71] 0.8953955 0.8958609 0.8963234 0.8967831 0.8972400 0.8976941 0.8981452 [78] 0.8985935 0.8990388 0.8994813 0.8999207 0.9003572 0.9007907 0.9012211 [85] 0.9016485 0.9020729 0.9024942 0.9029123 0.9033274 0.9037393 0.9041481 [92] 0.9045537 0.9049561 0.9053552 0.9057512 0.9061438 0.9065332 0.9069193 [99] 0.9073021 0.9076815 0.9080576 0.9084303 0.9087996 0.9091655 0.9095280 [106] 0.9098870 0.9102426 0.9105947 0.9109432 0.9112883 0.9116297 0.9119677 [113] 0.9123020 0.9126328 0.9129599 0.9132834 0.9136032 0.9139194 0.9142319 [120] 0.9145407 0.9148457 0.9151471 0.9154446 0.9157384 0.9160284 0.9163146 [127] 0.9165969 0.9168754 0.9171501 0.9174209 0.9176878 0.9179508 0.9182098 [134] 0.9184649 0.9187161 0.9189633 0.9192065 0.9194457 0.9196809 0.9199121 [141] 0.9201392 0.9203622 0.9205812 0.9207961 0.9210069 0.9212135 0.9214161 [148] 0.9216144 0.9218087 0.9219987 0.9221846 0.9223663 0.9225437 0.9227169 [155] 0.9228859 0.9230507 0.9232111 0.9233673 0.9235192 0.9236668 0.9238101 [162] 0.9239491 0.9240838 0.9242141 0.9243400 0.9244616 0.9245788 0.9246916 [169] 0.9248000 0.9249040 0.9250036 0.9250988 0.9251895 0.9252758 0.9253576 [176] 0.9254350 0.9255079 0.9255763 0.9256403 0.9256997 0.9257546 0.9258050 [183] 0.9258509 0.9258923 0.9259291 0.9259614 0.9259892 0.9260124 0.9260310 [190] 0.9260451 0.9260546 0.9260595 0.9260598 0.9260556 0.9260467 0.9260333 [197] 0.9260153 0.9259926 0.9259654 0.9259335 0.9258970 0.9258559 0.9258101 [204] 0.9257598 0.9257048 0.9256451 0.9255809 0.9255120 0.9254384 0.9253602 [211] 0.9252774 0.9251899 0.9250978 0.9250010 0.9248996 0.9247936 0.9246829 [218] 0.9245675 0.9244475 0.9243228 0.9241935 0.9240596 0.9239210 0.9237777 [225] 0.9236298 0.9234773 0.9233201 0.9231583 0.9229919 0.9228208 0.9226451 [232] 0.9224648 0.9222798 0.9220903 0.9218961 0.9216973 0.9214939 0.9212858 [239] 0.9210732 0.9208560 0.9206342 0.9204078 0.9201768 0.9199413 0.9197011 [246] 0.9194565 0.9192072 0.9189534 0.9186951 0.9184322 0.9181648 0.9178928 [253] 0.9176164 0.9173354 0.9170499 0.9167600 0.9164655 0.9161666 0.9158632 [260] 0.9155553 0.9152430 0.9149262 0.9146050 0.9142794 0.9139493 0.9136149 [267] 0.9132760 0.9129328 0.9125852 0.9122332 0.9118768 0.9115161 0.9111511 [274] 0.9107818 0.9104081 0.9100302 0.9096479 0.9092614 0.9088706 0.9084756 [281] 0.9080763 0.9076728 0.9072651 0.9068532 0.9064370 0.9060167 0.9055923 [288] 0.9051637 0.9047309 0.9042941 0.9038531 0.9034080 0.9029589 0.9025056 [295] 0.9020484 0.9015871 0.9011217 0.9006524 0.9001790 0.8997017 0.8992205 [302] 0.8987352 0.8982461 0.8977530 0.8972560 0.8967552 0.8962504 0.8957419 [309] 0.8952294 0.8947132 0.8941932 0.8936693 0.8931417 0.8926104 0.8920753 [316] 0.8915365 0.8909940 0.8904478 0.8898979 0.8893444 0.8887873 0.8882265 [323] 0.8876622 0.8870942 0.8865228 0.8859477 0.8853692 0.8847871 0.8842015 [330] 0.8836125 0.8830200 0.8824241 0.8818248 0.8812221 0.8806160 0.8800066 [337] 0.8793938 0.8787777 0.8781583 0.8775356 0.8769097 0.8762805 0.8756481 [344] 0.8750125 0.8743737 0.8737317 0.8730866 0.8724384 0.8717870 0.8711326 [351] 0.8704751 0.8698146 0.8691511 0.8684845 0.8678150 0.8671425 0.8664670 [358] 0.8657886 0.8651074 0.8644232 0.8637362 0.8630463 0.8623536 0.8616581 [365] 0.8609598 0.8602588 0.8595550 0.8588485 0.8581393 0.8574275 0.8567129 [372] 0.8559957 0.8552760 0.8545536 0.8538286 0.8531011 0.8523710 0.8516385 [379] 0.8509034 0.8501659 0.8494259 0.8486835 0.8479386 0.8471914 0.8464418 [386] 0.8456899 0.8449357 0.8441791 0.8434202 0.8426591 0.8418958 0.8411302 [393] 0.8403624 0.8395924 0.8388203 0.8380460 0.8372697 0.8364912 0.8357106 [400] 0.8349280 0.8341433 > mx [1] 0.9260598 > mxli [1] -0.08 > 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/1rm4l1355125060.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/2y6my1355125060.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/3zd0f1355125060.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/4gqdp1355125060.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/59p801355125060.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) > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/6xt421355125060.tab") > > try(system("convert tmp/1rm4l1355125060.ps tmp/1rm4l1355125060.png",intern=TRUE)) character(0) > try(system("convert tmp/2y6my1355125060.ps tmp/2y6my1355125060.png",intern=TRUE)) character(0) > try(system("convert tmp/3zd0f1355125060.ps tmp/3zd0f1355125060.png",intern=TRUE)) character(0) > try(system("convert tmp/4gqdp1355125060.ps tmp/4gqdp1355125060.png",intern=TRUE)) character(0) > try(system("convert tmp/59p801355125060.ps tmp/59p801355125060.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.628 0.413 3.034