R version 2.7.2 (2008-08-25) Copyright (C) 2008 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(148.8,146.7,118.8,99.4,97.6,110.2,146.6,136.4,126.2,154.9,109,128.5,144.9,136.3,134.8,103.4,106.6,119.2,149.3,150.2,142.9,163.6,98.2,138.2,143.7,132.8,149.4,128.8,98.9,106.2,140.7,133,156.4,157.7,107.9,133.6,148.1,205.6,193.1,117.5,116.4,129.5,157.1,157,158.4,161.7,116.9,161.1,155.7,160.8,145.4,111,144.8,149.2,156.6,182.5,171.3,172.7,133,148.1) > 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.3635850 0.3636908 0.3637964 0.3639019 0.3640073 0.3641126 0.3642178 [8] 0.3643229 0.3644278 0.3645326 0.3646373 0.3647419 0.3648464 0.3649507 [15] 0.3650549 0.3651590 0.3652630 0.3653668 0.3654705 0.3655740 0.3656775 [22] 0.3657808 0.3658839 0.3659869 0.3660898 0.3661926 0.3662952 0.3663976 [29] 0.3664999 0.3666021 0.3667041 0.3668060 0.3669077 0.3670092 0.3671106 [36] 0.3672119 0.3673130 0.3674139 0.3675147 0.3676153 0.3677158 0.3678161 [43] 0.3679162 0.3680162 0.3681160 0.3682156 0.3683151 0.3684144 0.3685135 [50] 0.3686124 0.3687112 0.3688098 0.3689082 0.3690064 0.3691044 0.3692023 [57] 0.3692999 0.3693974 0.3694947 0.3695918 0.3696887 0.3697854 0.3698820 [64] 0.3699783 0.3700744 0.3701703 0.3702661 0.3703616 0.3704569 0.3705520 [71] 0.3706469 0.3707416 0.3708361 0.3709304 0.3710245 0.3711183 0.3712119 [78] 0.3713053 0.3713985 0.3714915 0.3715843 0.3716768 0.3717691 0.3718611 [85] 0.3719530 0.3720446 0.3721360 0.3722271 0.3723180 0.3724087 0.3724991 [92] 0.3725893 0.3726792 0.3727689 0.3728584 0.3729476 0.3730365 0.3731252 [99] 0.3732137 0.3733019 0.3733898 0.3734775 0.3735649 0.3736521 0.3737390 [106] 0.3738256 0.3739120 0.3739981 0.3740839 0.3741695 0.3742548 0.3743398 [113] 0.3744246 0.3745090 0.3745932 0.3746771 0.3747607 0.3748441 0.3749271 [120] 0.3750099 0.3750923 0.3751745 0.3752564 0.3753380 0.3754193 0.3755003 [127] 0.3755810 0.3756614 0.3757415 0.3758212 0.3759007 0.3759799 0.3760588 [134] 0.3761373 0.3762155 0.3762934 0.3763710 0.3764483 0.3765253 0.3766019 [141] 0.3766782 0.3767542 0.3768299 0.3769052 0.3769802 0.3770548 0.3771292 [148] 0.3772032 0.3772768 0.3773501 0.3774231 0.3774957 0.3775680 0.3776399 [155] 0.3777115 0.3777827 0.3778536 0.3779241 0.3779943 0.3780641 0.3781335 [162] 0.3782026 0.3782714 0.3783397 0.3784077 0.3784753 0.3785426 0.3786094 [169] 0.3786759 0.3787421 0.3788078 0.3788732 0.3789382 0.3790028 0.3790670 [176] 0.3791308 0.3791943 0.3792573 0.3793200 0.3793823 0.3794441 0.3795056 [183] 0.3795667 0.3796273 0.3796876 0.3797475 0.3798069 0.3798660 0.3799246 [190] 0.3799828 0.3800407 0.3800980 0.3801550 0.3802116 0.3802677 0.3803234 [197] 0.3803787 0.3804336 0.3804880 0.3805420 0.3805956 0.3806488 0.3807015 [204] 0.3807537 0.3808056 0.3808570 0.3809079 0.3809584 0.3810085 0.3810581 [211] 0.3811073 0.3811560 0.3812042 0.3812520 0.3812994 0.3813463 0.3813927 [218] 0.3814387 0.3814842 0.3815292 0.3815738 0.3816179 0.3816615 0.3817047 [225] 0.3817473 0.3817895 0.3818313 0.3818725 0.3819133 0.3819536 0.3819934 [232] 0.3820327 0.3820715 0.3821099 0.3821477 0.3821851 0.3822220 0.3822583 [239] 0.3822942 0.3823296 0.3823644 0.3823988 0.3824326 0.3824660 0.3824988 [246] 0.3825312 0.3825630 0.3825943 0.3826251 0.3826554 0.3826851 0.3827144 [253] 0.3827431 0.3827713 0.3827989 0.3828261 0.3828527 0.3828788 0.3829043 [260] 0.3829294 0.3829538 0.3829778 0.3830012 0.3830241 0.3830464 0.3830682 [267] 0.3830894 0.3831101 0.3831303 0.3831499 0.3831689 0.3831874 0.3832054 [274] 0.3832228 0.3832396 0.3832559 0.3832716 0.3832867 0.3833013 0.3833153 [281] 0.3833288 0.3833417 0.3833540 0.3833658 0.3833769 0.3833875 0.3833976 [288] 0.3834070 0.3834159 0.3834242 0.3834319 0.3834390 0.3834456 0.3834515 [295] 0.3834569 0.3834617 0.3834659 0.3834695 0.3834725 0.3834750 0.3834768 [302] 0.3834780 0.3834786 0.3834787 0.3834781 0.3834769 0.3834752 0.3834728 [309] 0.3834698 0.3834662 0.3834620 0.3834572 0.3834518 0.3834457 0.3834391 [316] 0.3834318 0.3834239 0.3834154 0.3834063 0.3833966 0.3833862 0.3833752 [323] 0.3833636 0.3833514 0.3833385 0.3833250 0.3833109 0.3832962 0.3832808 [330] 0.3832648 0.3832481 0.3832309 0.3832129 0.3831944 0.3831752 0.3831554 [337] 0.3831349 0.3831138 0.3830920 0.3830696 0.3830466 0.3830229 0.3829986 [344] 0.3829736 0.3829480 0.3829217 0.3828948 0.3828672 0.3828389 0.3828100 [351] 0.3827805 0.3827503 0.3827194 0.3826879 0.3826557 0.3826229 0.3825894 [358] 0.3825552 0.3825204 0.3824849 0.3824488 0.3824120 0.3823745 0.3823364 [365] 0.3822975 0.3822581 0.3822179 0.3821771 0.3821356 0.3820934 0.3820506 [372] 0.3820071 0.3819629 0.3819180 0.3818725 0.3818263 0.3817794 0.3817318 [379] 0.3816836 0.3816347 0.3815851 0.3815348 0.3814838 0.3814322 0.3813798 [386] 0.3813268 0.3812731 0.3812188 0.3811637 0.3811079 0.3810515 0.3809944 [393] 0.3809366 0.3808781 0.3808189 0.3807590 0.3806985 0.3806372 0.3805753 [400] 0.3805126 0.3804493 > mx [1] 0.3834787 > mxli [1] 1.03 > if (mxli != 0) + { + x1 <- (x^mxli - 1) / mxli + } else { + x1 <- log(x) + } > postscript(file="/var/www/html/rcomp/tmp/14vgj1226149498.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/2q9tv1226149498.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/3x9ly1226149499.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/4r2o11226149499.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/5ozhk1226149499.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/60ukh1226149499.tab") > > system("convert tmp/14vgj1226149498.ps tmp/14vgj1226149498.png") > system("convert tmp/2q9tv1226149498.ps tmp/2q9tv1226149498.png") > system("convert tmp/3x9ly1226149499.ps tmp/3x9ly1226149499.png") > system("convert tmp/4r2o11226149499.ps tmp/4r2o11226149499.png") > system("convert tmp/5ozhk1226149499.ps tmp/5ozhk1226149499.png") > > > proc.time() user system elapsed 1.355 0.835 1.589