R version 2.8.0 (2008-10-20) 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(92.3,95.5,92.5,89.6,84.3,76.3,80.7,96.3,81,82.9,90.3,74.8,70.1,86.7,86.4,89.9,88.1,78.8,81.1,85.4,82.6,80.3,81.2,68,67.4,91.3,94.9,82.8,88.6,73.1,76.7,93.2,84.9,83.8,93.5,91.9,69.6,87,90.2,82.7,91.4,74.6,76.1,87.1,78.4,81.3,99.3,71,73.2,95.6,84,90.8,93.6,80.9,84.4,97.3,83.5,88.8,100.7,69.4,74.6,96.6,96.6,93.1,91.8,85.7,79.1,91.3,84.2,85.8,94.6,77.1,76.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.005004252 0.005024647 0.005045107 0.005065632 0.005086222 0.005106878 [7] 0.005127599 0.005148385 0.005169236 0.005190152 0.005211133 0.005232180 [13] 0.005253291 0.005274468 0.005295709 0.005317016 0.005338388 0.005359824 [19] 0.005381326 0.005402893 0.005424524 0.005446221 0.005467983 0.005489809 [25] 0.005511701 0.005533657 0.005555678 0.005577764 0.005599915 0.005622131 [31] 0.005644412 0.005666757 0.005689167 0.005711642 0.005734182 0.005756787 [37] 0.005779456 0.005802189 0.005824988 0.005847851 0.005870779 0.005893771 [43] 0.005916828 0.005939950 0.005963136 0.005986387 0.006009702 0.006033081 [49] 0.006056525 0.006080034 0.006103607 0.006127244 0.006150946 0.006174712 [55] 0.006198543 0.006222437 0.006246396 0.006270420 0.006294507 0.006318659 [61] 0.006342875 0.006367155 0.006391500 0.006415908 0.006440380 0.006464917 [67] 0.006489518 0.006514182 0.006538911 0.006563704 0.006588560 0.006613481 [73] 0.006638465 0.006663513 0.006688625 0.006713801 0.006739041 0.006764344 [79] 0.006789712 0.006815143 0.006840637 0.006866195 0.006891817 0.006917502 [85] 0.006943251 0.006969064 0.006994940 0.007020879 0.007046882 0.007072948 [91] 0.007099078 0.007125271 0.007151527 0.007177847 0.007204230 0.007230676 [97] 0.007257185 0.007283758 0.007310393 0.007337092 0.007363853 0.007390678 [103] 0.007417566 0.007444517 0.007471530 0.007498607 0.007525746 0.007552948 [109] 0.007580213 0.007607541 0.007634932 0.007662385 0.007689901 0.007717479 [115] 0.007745120 0.007772824 0.007800590 0.007828418 0.007856309 0.007884263 [121] 0.007912278 0.007940357 0.007968497 0.007996700 0.008024964 0.008053291 [127] 0.008081681 0.008110132 0.008138645 0.008167221 0.008195858 0.008224557 [133] 0.008253318 0.008282141 0.008311026 0.008339973 0.008368981 0.008398052 [139] 0.008427183 0.008456377 0.008485632 0.008514948 0.008544327 0.008573766 [145] 0.008603267 0.008632829 0.008662453 0.008692138 0.008721884 0.008751692 [151] 0.008781560 0.008811490 0.008841481 0.008871533 0.008901645 0.008931819 [157] 0.008962054 0.008992349 0.009022706 0.009053123 0.009083601 0.009114139 [163] 0.009144739 0.009175398 0.009206119 0.009236899 0.009267741 0.009298642 [169] 0.009329604 0.009360627 0.009391709 0.009422852 0.009454055 0.009485318 [175] 0.009516642 0.009548025 0.009579468 0.009610971 0.009642534 0.009674157 [181] 0.009705840 0.009737582 0.009769385 0.009801246 0.009833168 0.009865149 [187] 0.009897189 0.009929289 0.009961448 0.009993667 0.010025945 0.010058282 [193] 0.010090678 0.010123133 0.010155648 0.010188222 0.010220854 0.010253546 [199] 0.010286296 0.010319105 0.010351973 0.010384900 0.010417885 0.010450929 [205] 0.010484032 0.010517193 0.010550413 0.010583690 0.010617027 0.010650421 [211] 0.010683874 0.010717385 0.010750954 0.010784582 0.010818267 0.010852010 [217] 0.010885811 0.010919670 0.010953587 0.010987562 0.011021594 0.011055684 [223] 0.011089832 0.011124037 0.011158299 0.011192619 0.011226996 0.011261431 [229] 0.011295923 0.011330472 0.011365078 0.011399741 0.011434461 0.011469238 [235] 0.011504072 0.011538963 0.011573911 0.011608915 0.011643976 0.011679094 [241] 0.011714268 0.011749499 0.011784786 0.011820129 0.011855529 0.011890985 [247] 0.011926497 0.011962065 0.011997690 0.012033370 0.012069106 0.012104898 [253] 0.012140746 0.012176650 0.012212610 0.012248625 0.012284695 0.012320821 [259] 0.012357003 0.012393240 0.012429532 0.012465880 0.012502283 0.012538741 [265] 0.012575254 0.012611822 0.012648445 0.012685122 0.012721855 0.012758642 [271] 0.012795485 0.012832381 0.012869333 0.012906338 0.012943399 0.012980513 [277] 0.013017682 0.013054905 0.013092182 0.013129514 0.013166899 0.013204339 [283] 0.013241832 0.013279379 0.013316980 0.013354635 0.013392343 0.013430105 [289] 0.013467921 0.013505790 0.013543712 0.013581688 0.013619716 0.013657798 [295] 0.013695934 0.013734122 0.013772363 0.013810657 0.013849004 0.013887404 [301] 0.013925856 0.013964361 0.014002919 0.014041529 0.014080191 0.014118906 [307] 0.014157674 0.014196493 0.014235365 0.014274288 0.014313264 0.014352292 [313] 0.014391371 0.014430503 0.014469686 0.014508921 0.014548207 0.014587545 [319] 0.014626934 0.014666375 0.014705867 0.014745410 0.014785005 0.014824651 [325] 0.014864347 0.014904095 0.014943893 0.014983743 0.015023643 0.015063593 [331] 0.015103595 0.015143647 0.015183749 0.015223902 0.015264105 0.015304358 [337] 0.015344661 0.015385015 0.015425419 0.015465872 0.015506375 0.015546929 [343] 0.015587532 0.015628184 0.015668886 0.015709638 0.015750439 0.015791290 [349] 0.015832189 0.015873138 0.015914137 0.015955184 0.015996280 0.016037425 [355] 0.016078619 0.016119862 0.016161153 0.016202493 0.016243882 0.016285319 [361] 0.016326804 0.016368338 0.016409920 0.016451550 0.016493228 0.016534955 [367] 0.016576729 0.016618551 0.016660421 0.016702338 0.016744304 0.016786316 [373] 0.016828377 0.016870484 0.016912639 0.016954841 0.016997091 0.017039387 [379] 0.017081731 0.017124121 0.017166559 0.017209043 0.017251573 0.017294151 [385] 0.017336775 0.017379445 0.017422162 0.017464925 0.017507735 0.017550591 [391] 0.017593492 0.017636440 0.017679434 0.017722473 0.017765558 0.017808689 [397] 0.017851866 0.017895088 0.017938356 0.017981669 0.018025027 > mx [1] 0.01802503 > mxli [1] 2 > if (mxli != 0) + { + x1 <- (x^mxli - 1) / mxli + } else { + x1 <- log(x) + } > postscript(file="/var/www/html/rcomp/tmp/1j5g81226910475.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/2bi271226910475.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/3wwh61226910475.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/4353z1226910475.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/5di871226910475.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/6tdy61226910475.tab") > > system("convert tmp/1j5g81226910475.ps tmp/1j5g81226910475.png") > system("convert tmp/2bi271226910475.ps tmp/2bi271226910475.png") > system("convert tmp/3wwh61226910475.ps tmp/3wwh61226910475.png") > system("convert tmp/4353z1226910475.ps tmp/4353z1226910475.png") > system("convert tmp/5di871226910475.ps tmp/5di871226910475.png") > > > proc.time() user system elapsed 1.095 0.787 1.850