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(93.4,101.5,110.4,105.9,108.4,113.9,86.1,69.4,101.2,100.5,98,106.6,90.1,96.9,125.9,112,100,123.9,79.8,83.4,113.6,112.9,104,109.9,99,106.3,128.9,111.1,102.9,130,87,87.5,117.6,103.4,110.8,112.6,102.5,112.4,135.6,105.1,127.7,137,91,90.5,122.4,123.3,124.3,120,118.1,119,142.7,123.6,129.6,151.6,110.4,99.2,130.5,136.2,129.7,128,121.6,135.8,143.8,147.5,136.2,156.6,123.2) > 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-51)/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.5999679 0.6002636 0.6005584 0.6008524 0.6011456 0.6014378 0.6017293 [8] 0.6020198 0.6023095 0.6025983 0.6028863 0.6031734 0.6034596 0.6037450 [15] 0.6040295 0.6043131 0.6045959 0.6048778 0.6051589 0.6054390 0.6057183 [22] 0.6059967 0.6062743 0.6065510 0.6068268 0.6071018 0.6073758 0.6076490 [29] 0.6079213 0.6081928 0.6084634 0.6087331 0.6090019 0.6092699 0.6095369 [36] 0.6098031 0.6100685 0.6103329 0.6105965 0.6108592 0.6111210 0.6113819 [43] 0.6116420 0.6119011 0.6121594 0.6124169 0.6126734 0.6129291 0.6131838 [50] 0.6134377 0.6136907 0.6139429 0.6141941 0.6144445 0.6146940 0.6149426 [57] 0.6151903 0.6154371 0.6156831 0.6159282 0.6161724 0.6164157 0.6166581 [64] 0.6168996 0.6171403 0.6173800 0.6176189 0.6178569 0.6180940 0.6183303 [71] 0.6185656 0.6188001 0.6190336 0.6192663 0.6194981 0.6197290 0.6199591 [78] 0.6201882 0.6204165 0.6206438 0.6208703 0.6210959 0.6213206 0.6215445 [85] 0.6217674 0.6219895 0.6222106 0.6224309 0.6226503 0.6228688 0.6230865 [92] 0.6233032 0.6235191 0.6237340 0.6239481 0.6241613 0.6243736 0.6245851 [99] 0.6247956 0.6250053 0.6252140 0.6254219 0.6256289 0.6258351 0.6260403 [106] 0.6262446 0.6264481 0.6266507 0.6268524 0.6270532 0.6272531 0.6274522 [113] 0.6276504 0.6278476 0.6280440 0.6282395 0.6284342 0.6286279 0.6288208 [120] 0.6290128 0.6292039 0.6293941 0.6295835 0.6297719 0.6299595 0.6301462 [127] 0.6303320 0.6305170 0.6307010 0.6308842 0.6310665 0.6312480 0.6314285 [134] 0.6316082 0.6317870 0.6319649 0.6321419 0.6323181 0.6324934 0.6326678 [141] 0.6328414 0.6330140 0.6331858 0.6333567 0.6335268 0.6336959 0.6338642 [148] 0.6340316 0.6341982 0.6343639 0.6345287 0.6346926 0.6348557 0.6350179 [155] 0.6351792 0.6353397 0.6354993 0.6356580 0.6358158 0.6359728 0.6361289 [162] 0.6362842 0.6364386 0.6365921 0.6367447 0.6368965 0.6370475 0.6371975 [169] 0.6373467 0.6374951 0.6376426 0.6377892 0.6379349 0.6380798 0.6382239 [176] 0.6383670 0.6385094 0.6386508 0.6387914 0.6389312 0.6390701 0.6392081 [183] 0.6393453 0.6394816 0.6396171 0.6397517 0.6398855 0.6400184 0.6401505 [190] 0.6402817 0.6404121 0.6405416 0.6406702 0.6407981 0.6409250 0.6410512 [197] 0.6411764 0.6413009 0.6414245 0.6415472 0.6416691 0.6417902 0.6419104 [204] 0.6420298 0.6421483 0.6422660 0.6423829 0.6424989 0.6426141 0.6427284 [211] 0.6428419 0.6429546 0.6430664 0.6431774 0.6432876 0.6433969 0.6435054 [218] 0.6436131 0.6437199 0.6438260 0.6439311 0.6440355 0.6441390 0.6442417 [225] 0.6443436 0.6444447 0.6445449 0.6446443 0.6447429 0.6448406 0.6449376 [232] 0.6450337 0.6451290 0.6452235 0.6453171 0.6454100 0.6455020 0.6455932 [239] 0.6456836 0.6457732 0.6458620 0.6459499 0.6460371 0.6461234 0.6462090 [246] 0.6462937 0.6463776 0.6464607 0.6465430 0.6466245 0.6467052 0.6467851 [253] 0.6468642 0.6469424 0.6470199 0.6470966 0.6471725 0.6472476 0.6473219 [260] 0.6473954 0.6474681 0.6475400 0.6476111 0.6476814 0.6477509 0.6478197 [267] 0.6478876 0.6479548 0.6480211 0.6480867 0.6481515 0.6482155 0.6482788 [274] 0.6483412 0.6484029 0.6484638 0.6485239 0.6485832 0.6486417 0.6486995 [281] 0.6487565 0.6488127 0.6488681 0.6489228 0.6489767 0.6490298 0.6490822 [288] 0.6491338 0.6491846 0.6492346 0.6492839 0.6493324 0.6493802 0.6494272 [295] 0.6494734 0.6495188 0.6495636 0.6496075 0.6496507 0.6496931 0.6497348 [302] 0.6497757 0.6498159 0.6498553 0.6498939 0.6499318 0.6499690 0.6500054 [309] 0.6500411 0.6500760 0.6501101 0.6501435 0.6501762 0.6502082 0.6502394 [316] 0.6502698 0.6502995 0.6503285 0.6503567 0.6503842 0.6504110 0.6504370 [323] 0.6504623 0.6504869 0.6505107 0.6505338 0.6505562 0.6505779 0.6505988 [330] 0.6506190 0.6506384 0.6506572 0.6506752 0.6506925 0.6507091 0.6507250 [337] 0.6507401 0.6507546 0.6507683 0.6507813 0.6507936 0.6508052 0.6508160 [344] 0.6508262 0.6508356 0.6508444 0.6508524 0.6508597 0.6508664 0.6508723 [351] 0.6508775 0.6508820 0.6508858 0.6508890 0.6508914 0.6508931 0.6508942 [358] 0.6508945 0.6508941 0.6508931 0.6508914 0.6508889 0.6508858 0.6508820 [365] 0.6508775 0.6508724 0.6508665 0.6508600 0.6508528 0.6508449 0.6508363 [372] 0.6508270 0.6508171 0.6508065 0.6507952 0.6507833 0.6507707 0.6507574 [379] 0.6507434 0.6507288 0.6507135 0.6506975 0.6506809 0.6506636 0.6506456 [386] 0.6506270 0.6506078 0.6505878 0.6505672 0.6505460 0.6505241 0.6505015 [393] 0.6504783 0.6504545 0.6504300 0.6504048 0.6503790 0.6503525 0.6503254 [400] 0.6502977 0.6502693 > mx [1] 0.6508945 > mxli [1] 3.07 > if (mxli != 0) + { + x1 <- (x^mxli - 1) / mxli + } else { + x1 <- log(x) + } > postscript(file="/var/www/html/rcomp/tmp/1x9i01227037786.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/2rt4r1227037786.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/3ycwa1227037786.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/437l81227037786.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/5u48m1227037786.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/66vne1227037786.tab") > > system("convert tmp/1x9i01227037786.ps tmp/1x9i01227037786.png") > system("convert tmp/2rt4r1227037786.ps tmp/2rt4r1227037786.png") > system("convert tmp/3ycwa1227037786.ps tmp/3ycwa1227037786.png") > system("convert tmp/437l81227037786.ps tmp/437l81227037786.png") > system("convert tmp/5u48m1227037786.ps tmp/5u48m1227037786.png") > > > proc.time() user system elapsed 1.071 0.774 2.044