R version 2.7.0 (2008-04-22) 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. > y <- c(110.40,96.40,101.90,106.20,81.00,94.70,101.00,109.40,102.30,90.70,96.20,96.10,106.00,103.10,102.00,104.70,86.00,92.10,106.90,112.60,101.70,92.00,97.40,97.00,105.40,102.70,98.10,104.50,87.40,89.90,109.80,111.70,98.60,96.90,95.10,97.00,112.70,102.90,97.40,111.40,87.40,96.80,114.10,110.30,103.90,101.60,94.60,95.90,104.70,102.80,98.10,113.90,80.90,95.70,113.20,105.90,108.80,102.30,99.00,100.70,115.50) > x <- c(109.20,88.60,94.30,98.30,86.40,80.60,104.10,108.20,93.40,71.90,94.10,94.90,96.40,91.10,84.40,86.40,88.00,75.10,109.70,103.00,82.10,68.00,96.40,94.30,90.00,88.00,76.10,82.50,81.40,66.50,97.20,94.10,80.70,70.50,87.80,89.50,99.60,84.20,75.10,92.00,80.80,73.10,99.80,90.00,83.10,72.40,78.80,87.30,91.00,80.10,73.60,86.40,74.50,71.20,92.40,81.50,85.30,69.90,84.20,90.70,100.30) > 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(x1,y) + if (mx < abs(c[i])) + { + mx <- abs(c[i]) + mxli <- l[i] + } + } > c [1] 0.5463253 0.5464291 0.5465326 0.5466359 0.5467389 0.5468418 0.5469444 [8] 0.5470467 0.5471489 0.5472508 0.5473525 0.5474540 0.5475552 0.5476562 [15] 0.5477569 0.5478575 0.5479578 0.5480578 0.5481577 0.5482572 0.5483566 [22] 0.5484557 0.5485546 0.5486533 0.5487517 0.5488499 0.5489478 0.5490455 [29] 0.5491429 0.5492402 0.5493371 0.5494339 0.5495304 0.5496266 0.5497226 [36] 0.5498184 0.5499139 0.5500092 0.5501043 0.5501991 0.5502936 0.5503879 [43] 0.5504820 0.5505758 0.5506693 0.5507626 0.5508557 0.5509485 0.5510411 [50] 0.5511334 0.5512255 0.5513173 0.5514089 0.5515002 0.5515912 0.5516820 [57] 0.5517726 0.5518629 0.5519529 0.5520427 0.5521323 0.5522216 0.5523106 [64] 0.5523993 0.5524879 0.5525761 0.5526641 0.5527518 0.5528393 0.5529265 [71] 0.5530135 0.5531002 0.5531866 0.5532728 0.5533587 0.5534444 0.5535297 [78] 0.5536149 0.5536997 0.5537843 0.5538686 0.5539527 0.5540365 0.5541200 [85] 0.5542033 0.5542863 0.5543690 0.5544515 0.5545337 0.5546156 0.5546973 [92] 0.5547787 0.5548598 0.5549406 0.5550212 0.5551015 0.5551815 0.5552613 [99] 0.5553408 0.5554200 0.5554989 0.5555776 0.5556560 0.5557341 0.5558119 [106] 0.5558895 0.5559668 0.5560438 0.5561205 0.5561969 0.5562731 0.5563490 [113] 0.5564246 0.5565000 0.5565750 0.5566498 0.5567243 0.5567985 0.5568724 [120] 0.5569461 0.5570194 0.5570925 0.5571653 0.5572378 0.5573100 0.5573820 [127] 0.5574536 0.5575250 0.5575961 0.5576669 0.5577374 0.5578076 0.5578776 [134] 0.5579472 0.5580166 0.5580857 0.5581544 0.5582229 0.5582911 0.5583590 [141] 0.5584267 0.5584940 0.5585610 0.5586278 0.5586942 0.5587604 0.5588262 [148] 0.5588918 0.5589571 0.5590221 0.5590868 0.5591512 0.5592153 0.5592791 [155] 0.5593426 0.5594058 0.5594687 0.5595313 0.5595936 0.5596556 0.5597173 [162] 0.5597788 0.5598399 0.5599007 0.5599612 0.5600214 0.5600813 0.5601410 [169] 0.5602003 0.5602593 0.5603180 0.5603764 0.5604345 0.5604923 0.5605498 [176] 0.5606070 0.5606639 0.5607205 0.5607767 0.5608327 0.5608884 0.5609437 [183] 0.5609988 0.5610535 0.5611080 0.5611621 0.5612159 0.5612694 0.5613226 [190] 0.5613755 0.5614281 0.5614804 0.5615323 0.5615840 0.5616354 0.5616864 [197] 0.5617371 0.5617875 0.5618376 0.5618874 0.5619369 0.5619860 0.5620349 [204] 0.5620834 0.5621316 0.5621796 0.5622271 0.5622744 0.5623214 0.5623680 [211] 0.5624144 0.5624604 0.5625061 0.5625515 0.5625965 0.5626413 0.5626857 [218] 0.5627298 0.5627736 0.5628171 0.5628603 0.5629031 0.5629456 0.5629878 [225] 0.5630297 0.5630713 0.5631125 0.5631535 0.5631941 0.5632343 0.5632743 [232] 0.5633139 0.5633533 0.5633923 0.5634309 0.5634693 0.5635073 0.5635450 [239] 0.5635824 0.5636195 0.5636562 0.5636926 0.5637287 0.5637644 0.5637999 [246] 0.5638350 0.5638698 0.5639042 0.5639384 0.5639722 0.5640057 0.5640388 [253] 0.5640717 0.5641042 0.5641364 0.5641682 0.5641997 0.5642309 0.5642618 [260] 0.5642923 0.5643225 0.5643524 0.5643820 0.5644112 0.5644401 0.5644687 [267] 0.5644969 0.5645248 0.5645524 0.5645796 0.5646066 0.5646332 0.5646594 [274] 0.5646853 0.5647109 0.5647362 0.5647611 0.5647857 0.5648100 0.5648339 [281] 0.5648576 0.5648808 0.5649038 0.5649264 0.5649487 0.5649706 0.5649922 [288] 0.5650135 0.5650344 0.5650550 0.5650753 0.5650953 0.5651149 0.5651342 [295] 0.5651531 0.5651717 0.5651900 0.5652079 0.5652255 0.5652428 0.5652597 [302] 0.5652763 0.5652926 0.5653085 0.5653241 0.5653394 0.5653543 0.5653689 [309] 0.5653831 0.5653970 0.5654106 0.5654238 0.5654367 0.5654493 0.5654615 [316] 0.5654734 0.5654850 0.5654962 0.5655071 0.5655176 0.5655279 0.5655377 [323] 0.5655473 0.5655565 0.5655653 0.5655738 0.5655820 0.5655899 0.5655974 [330] 0.5656046 0.5656114 0.5656179 0.5656240 0.5656299 0.5656353 0.5656405 [337] 0.5656453 0.5656497 0.5656539 0.5656577 0.5656611 0.5656642 0.5656670 [344] 0.5656694 0.5656715 0.5656733 0.5656747 0.5656758 0.5656765 0.5656769 [351] 0.5656770 0.5656767 0.5656761 0.5656751 0.5656738 0.5656722 0.5656702 [358] 0.5656679 0.5656652 0.5656622 0.5656589 0.5656552 0.5656512 0.5656469 [365] 0.5656422 0.5656372 0.5656318 0.5656261 0.5656201 0.5656137 0.5656069 [372] 0.5655999 0.5655925 0.5655847 0.5655767 0.5655682 0.5655595 0.5655504 [379] 0.5655410 0.5655312 0.5655211 0.5655106 0.5654998 0.5654887 0.5654772 [386] 0.5654654 0.5654533 0.5654408 0.5654279 0.5654148 0.5654013 0.5653874 [393] 0.5653733 0.5653587 0.5653439 0.5653287 0.5653132 0.5652973 0.5652811 [400] 0.5652645 0.5652477 > mx [1] 0.565677 > mxli [1] 1.5 > if (mxli != 0) + { + x1 <- (x^mxli - 1) / mxli + } else { + x1 <- log(x) + } > r<-lm(y~x) > se <- sqrt(var(r$residuals)) > r1 <- lm(y~x1) > se1 <- sqrt(var(r1$residuals)) > postscript(file="/var/www/html/rcomp/tmp/1vwbu1226326719.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(l,c,main='Box-Cox Linearity Plot',xlab='Lambda',ylab='correlation') > grid() > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2gpjv1226326719.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(x,y,main='Linear Fit of Original Data',xlab='x',ylab='y') > abline(r) > grid() > mtext(paste('Residual Standard Deviation = ',se)) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/31kmh1226326719.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(x1,y,main='Linear Fit of Transformed Data',xlab='x',ylab='y') > abline(r1) > grid() > mtext(paste('Residual Standard Deviation = ',se1)) > 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 Linearity 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(x)',header=TRUE) > a<-table.element(a,mxli) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Residual SD (orginial)',header=TRUE) > a<-table.element(a,se) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Residual SD (transformed)',header=TRUE) > a<-table.element(a,se1) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/4vh011226326719.tab") > > system("convert tmp/1vwbu1226326719.ps tmp/1vwbu1226326719.png") > system("convert tmp/2gpjv1226326719.ps tmp/2gpjv1226326719.png") > system("convert tmp/31kmh1226326719.ps tmp/31kmh1226326719.png") > > > proc.time() user system elapsed 1.899 0.849 2.003