R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(1.8,1.6,1.9,1.7,1.6,1.3,1.1,1.9,2.6,2.3,2.4,2.2,2,2.9,2.6,2.3,2.3,2.6,3.1,2.8,2.5,2.9,3.1,3.1,3.2,2.5,2.6,2.9,2.6,2.4,1.7,2,2.2,1.9,1.6,1.6,1.2,1.2,1.5,1.6,1.7,1.8,1.8,1.8,1.3,1.3,1.4,1.1,1.5,2.2,2.9,3.1,3.5,3.6,4.4,4.2,5.2,5.8,5.9,5.4,5.5) > n <- length(x) > c <- array(NA,dim=c(401)) > l <- array(NA,dim=c(401)) > mx <- 0 > mxli <- -999 > for (i in 1:401) + { + l[i] <- (i-201)/100 + if (l[i] != 0) + { + x1 <- (x^l[i] - 1) / 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.2060684 0.2070290 0.2079931 0.2089606 0.2099316 0.2109061 0.2118841 [8] 0.2128656 0.2138505 0.2148389 0.2158307 0.2168260 0.2178247 0.2188269 [15] 0.2198325 0.2208416 0.2218541 0.2228700 0.2238893 0.2249121 0.2259383 [22] 0.2269678 0.2280008 0.2290371 0.2300768 0.2311199 0.2321664 0.2332162 [29] 0.2342694 0.2353259 0.2363857 0.2374489 0.2385154 0.2395851 0.2406582 [36] 0.2417346 0.2428142 0.2438971 0.2449832 0.2460726 0.2471652 0.2482610 [43] 0.2493600 0.2504622 0.2515676 0.2526762 0.2537879 0.2549027 0.2560207 [50] 0.2571417 0.2582659 0.2593931 0.2605234 0.2616568 0.2627932 0.2639326 [57] 0.2650750 0.2662203 0.2673687 0.2685200 0.2696742 0.2708313 0.2719913 [64] 0.2731542 0.2743199 0.2754885 0.2766599 0.2778341 0.2790110 0.2801907 [71] 0.2813732 0.2825583 0.2837461 0.2849366 0.2861297 0.2873255 0.2885238 [78] 0.2897247 0.2909282 0.2921341 0.2933426 0.2945535 0.2957669 0.2969827 [85] 0.2982009 0.2994215 0.3006444 0.3018696 0.3030971 0.3043268 0.3055588 [92] 0.3067929 0.3080293 0.3092677 0.3105083 0.3117510 0.3129957 0.3142424 [99] 0.3154911 0.3167418 0.3179944 0.3192488 0.3205052 0.3217633 0.3230233 [106] 0.3242850 0.3255484 0.3268135 0.3280802 0.3293486 0.3306186 0.3318901 [113] 0.3331631 0.3344375 0.3357135 0.3369908 0.3382694 0.3395494 0.3408307 [120] 0.3421132 0.3433970 0.3446819 0.3459679 0.3472550 0.3485431 0.3498323 [127] 0.3511224 0.3524135 0.3537054 0.3549982 0.3562918 0.3575861 0.3588812 [134] 0.3601769 0.3614733 0.3627702 0.3640677 0.3653657 0.3666641 0.3679630 [141] 0.3692622 0.3705617 0.3718615 0.3731615 0.3744617 0.3757621 0.3770625 [148] 0.3783630 0.3796635 0.3809640 0.3822643 0.3835645 0.3848645 0.3861643 [155] 0.3874638 0.3887630 0.3900617 0.3913601 0.3926580 0.3939553 0.3952521 [162] 0.3965482 0.3978437 0.3991385 0.4004324 0.4017256 0.4030179 0.4043093 [169] 0.4055997 0.4068891 0.4081774 0.4094646 0.4107506 0.4120354 0.4133190 [176] 0.4146012 0.4158821 0.4171615 0.4184395 0.4197160 0.4209909 0.4222641 [183] 0.4235357 0.4248056 0.4260737 0.4273400 0.4286045 0.4298670 0.4311275 [190] 0.4323860 0.4336425 0.4348968 0.4361490 0.4373989 0.4386466 0.4398920 [197] 0.4411350 0.4423755 0.4436137 0.4448493 0.4460823 0.4473128 0.4485405 [204] 0.4497656 0.4509879 0.4522074 0.4534241 0.4546379 0.4558487 0.4570565 [211] 0.4582613 0.4594630 0.4606616 0.4618570 0.4630492 0.4642381 0.4654237 [218] 0.4666060 0.4677848 0.4689602 0.4701321 0.4713005 0.4724652 0.4736264 [225] 0.4747839 0.4759377 0.4770877 0.4782340 0.4793764 0.4805150 0.4816496 [232] 0.4827803 0.4839070 0.4850296 0.4861482 0.4872627 0.4883730 0.4894791 [239] 0.4905810 0.4916787 0.4927720 0.4938610 0.4949456 0.4960259 0.4971017 [246] 0.4981730 0.4992398 0.5003020 0.5013597 0.5024128 0.5034612 0.5045050 [253] 0.5055440 0.5065783 0.5076079 0.5086326 0.5096526 0.5106677 0.5116779 [260] 0.5126832 0.5136835 0.5146789 0.5156693 0.5166547 0.5176351 0.5186104 [267] 0.5195806 0.5205457 0.5215056 0.5224604 0.5234100 0.5243545 0.5252937 [274] 0.5262276 0.5271563 0.5280797 0.5289979 0.5299107 0.5308181 0.5317203 [281] 0.5326170 0.5335084 0.5343943 0.5352749 0.5361500 0.5370197 0.5378839 [288] 0.5387427 0.5395959 0.5404437 0.5412860 0.5421228 0.5429540 0.5437797 [295] 0.5445999 0.5454145 0.5462235 0.5470270 0.5478249 0.5486172 0.5494040 [302] 0.5501851 0.5509607 0.5517306 0.5524950 0.5532537 0.5540068 0.5547544 [309] 0.5554963 0.5562325 0.5569632 0.5576883 0.5584077 0.5591215 0.5598297 [316] 0.5605323 0.5612293 0.5619207 0.5626064 0.5632866 0.5639611 0.5646301 [323] 0.5652935 0.5659513 0.5666035 0.5672502 0.5678912 0.5685268 0.5691567 [330] 0.5697811 0.5704000 0.5710134 0.5716212 0.5722236 0.5728204 0.5734118 [337] 0.5739976 0.5745780 0.5751530 0.5757225 0.5762866 0.5768452 0.5773985 [344] 0.5779463 0.5784888 0.5790259 0.5795577 0.5800841 0.5806052 0.5811210 [351] 0.5816315 0.5821367 0.5826367 0.5831314 0.5836209 0.5841052 0.5845843 [358] 0.5850582 0.5855270 0.5859906 0.5864491 0.5869025 0.5873508 0.5877940 [365] 0.5882322 0.5886654 0.5890935 0.5895167 0.5899349 0.5903482 0.5907565 [372] 0.5911599 0.5915585 0.5919522 0.5923410 0.5927250 0.5931042 0.5934787 [379] 0.5938484 0.5942133 0.5945736 0.5949291 0.5952800 0.5956263 0.5959679 [386] 0.5963049 0.5966374 0.5969653 0.5972887 0.5976075 0.5979219 0.5982319 [393] 0.5985374 0.5988385 0.5991352 0.5994276 0.5997156 0.5999993 0.6002787 [400] 0.6005539 0.6008248 > mx [1] 0.6008248 > mxli [1] 2 > if (mxli != 0) + { + x1 <- (x^mxli - 1) / mxli + } else { + x1 <- log(x) + } > postscript(file="/var/www/html/rcomp/tmp/14flk1261134899.ps",horizontal=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/www/html/rcomp/tmp/217tf1261134899.ps",horizontal=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/www/html/rcomp/tmp/3kb551261134899.ps",horizontal=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/www/html/rcomp/tmp/4oj3u1261134899.ps",horizontal=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/www/html/rcomp/tmp/5e2931261134899.ps",horizontal=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/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/www/html/rcomp/tmp/667bi1261134899.tab") > > try(system("convert tmp/14flk1261134899.ps tmp/14flk1261134899.png",intern=TRUE)) character(0) > try(system("convert tmp/217tf1261134899.ps tmp/217tf1261134899.png",intern=TRUE)) character(0) > try(system("convert tmp/3kb551261134899.ps tmp/3kb551261134899.png",intern=TRUE)) character(0) > try(system("convert tmp/4oj3u1261134899.ps tmp/4oj3u1261134899.png",intern=TRUE)) character(0) > try(system("convert tmp/5e2931261134899.ps tmp/5e2931261134899.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.063 0.788 1.804