R version 2.6.0 (2007-10-03) Copyright (C) 2007 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. Natural language support but running in an English locale 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(4.8,-4.2,1.6,5.2,9.2,4.6,10.6) > x <- c(4.2,2.6,3,3.8,4,3.5,4.1) > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: Wessa P., (2007), Box-Cox Linearity Plot (v1.0.3) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_boxcoxlin.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description > 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.9101779 0.9101483 0.9101183 0.9100880 0.9100573 0.9100263 0.9099949 [8] 0.9099632 0.9099311 0.9098986 0.9098658 0.9098326 0.9097991 0.9097652 [15] 0.9097310 0.9096964 0.9096615 0.9096262 0.9095905 0.9095545 0.9095181 [22] 0.9094814 0.9094443 0.9094068 0.9093690 0.9093308 0.9092923 0.9092534 [29] 0.9092141 0.9091745 0.9091345 0.9090942 0.9090535 0.9090124 0.9089710 [36] 0.9089292 0.9088871 0.9088446 0.9088017 0.9087585 0.9087149 0.9086710 [43] 0.9086266 0.9085820 0.9085369 0.9084915 0.9084457 0.9083996 0.9083531 [50] 0.9083062 0.9082590 0.9082114 0.9081635 0.9081151 0.9080665 0.9080174 [57] 0.9079680 0.9079182 0.9078681 0.9078175 0.9077667 0.9077154 0.9076638 [64] 0.9076118 0.9075595 0.9075068 0.9074537 0.9074003 0.9073465 0.9072923 [71] 0.9072377 0.9071828 0.9071276 0.9070719 0.9070159 0.9069595 0.9069028 [78] 0.9068457 0.9067882 0.9067303 0.9066721 0.9066135 0.9065546 0.9064953 [85] 0.9064356 0.9063755 0.9063151 0.9062543 0.9061931 0.9061316 0.9060697 [92] 0.9060075 0.9059448 0.9058818 0.9058184 0.9057547 0.9056906 0.9056261 [99] 0.9055613 0.9054961 0.9054305 0.9053645 0.9052982 0.9052315 0.9051644 [106] 0.9050970 0.9050292 0.9049611 0.9048925 0.9048236 0.9047543 0.9046847 [113] 0.9046147 0.9045443 0.9044736 0.9044025 0.9043310 0.9042591 0.9041869 [120] 0.9041143 0.9040413 0.9039680 0.9038943 0.9038203 0.9037458 0.9036710 [127] 0.9035958 0.9035203 0.9034444 0.9033681 0.9032915 0.9032145 0.9031371 [134] 0.9030593 0.9029812 0.9029027 0.9028239 0.9027447 0.9026651 0.9025851 [141] 0.9025048 0.9024241 0.9023431 0.9022616 0.9021799 0.9020977 0.9020152 [148] 0.9019323 0.9018490 0.9017654 0.9016814 0.9015971 0.9015123 0.9014273 [155] 0.9013418 0.9012560 0.9011698 0.9010832 0.9009963 0.9009090 0.9008214 [162] 0.9007334 0.9006450 0.9005563 0.9004672 0.9003777 0.9002879 0.9001977 [169] 0.9001071 0.9000162 0.8999249 0.8998332 0.8997412 0.8996488 0.8995561 [176] 0.8994630 0.8993695 0.8992757 0.8991815 0.8990870 0.8989920 0.8988968 [183] 0.8988011 0.8987051 0.8986088 0.8985120 0.8984150 0.8983175 0.8982197 [190] 0.8981216 0.8980230 0.8979242 0.8978249 0.8977253 0.8976254 0.8975251 [197] 0.8974244 0.8973234 0.8972220 0.8971202 0.8970181 0.8969157 0.8968128 [204] 0.8967097 0.8966061 0.8965023 0.8963980 0.8962934 0.8961885 0.8960832 [211] 0.8959775 0.8958715 0.8957651 0.8956584 0.8955513 0.8954439 0.8953361 [218] 0.8952280 0.8951195 0.8950106 0.8949014 0.8947919 0.8946820 0.8945717 [225] 0.8944611 0.8943502 0.8942389 0.8941273 0.8940153 0.8939029 0.8937902 [232] 0.8936772 0.8935638 0.8934500 0.8933360 0.8932215 0.8931068 0.8929916 [239] 0.8928762 0.8927603 0.8926442 0.8925277 0.8924108 0.8922936 0.8921761 [246] 0.8920582 0.8919400 0.8918214 0.8917025 0.8915832 0.8914636 0.8913437 [253] 0.8912234 0.8911028 0.8909818 0.8908605 0.8907389 0.8906169 0.8904946 [260] 0.8903719 0.8902489 0.8901256 0.8900019 0.8898779 0.8897536 0.8896289 [267] 0.8895039 0.8893785 0.8892528 0.8891268 0.8890005 0.8888738 0.8887468 [274] 0.8886194 0.8884917 0.8883637 0.8882353 0.8881067 0.8879776 0.8878483 [281] 0.8877186 0.8875886 0.8874583 0.8873276 0.8871967 0.8870653 0.8869337 [288] 0.8868017 0.8866694 0.8865368 0.8864039 0.8862706 0.8861370 0.8860031 [295] 0.8858688 0.8857343 0.8855994 0.8854642 0.8853286 0.8851928 0.8850566 [302] 0.8849201 0.8847833 0.8846461 0.8845087 0.8843709 0.8842328 0.8840944 [309] 0.8839557 0.8838166 0.8836773 0.8835376 0.8833976 0.8832573 0.8831167 [316] 0.8829757 0.8828345 0.8826929 0.8825511 0.8824089 0.8822664 0.8821236 [323] 0.8819804 0.8818370 0.8816933 0.8815492 0.8814049 0.8812602 0.8811153 [330] 0.8809700 0.8808244 0.8806785 0.8805323 0.8803858 0.8802390 0.8800919 [337] 0.8799445 0.8797968 0.8796488 0.8795005 0.8793519 0.8792030 0.8790538 [344] 0.8789043 0.8787544 0.8786043 0.8784539 0.8783032 0.8781522 0.8780009 [351] 0.8778493 0.8776974 0.8775453 0.8773928 0.8772400 0.8770870 0.8769336 [358] 0.8767800 0.8766260 0.8764718 0.8763173 0.8761625 0.8760074 0.8758520 [365] 0.8756963 0.8755404 0.8753841 0.8752276 0.8750708 0.8749137 0.8747563 [372] 0.8745986 0.8744407 0.8742824 0.8741239 0.8739651 0.8738061 0.8736467 [379] 0.8734871 0.8733271 0.8731669 0.8730065 0.8728457 0.8726847 0.8725234 [386] 0.8723618 0.8722000 0.8720378 0.8718754 0.8717127 0.8715498 0.8713866 [393] 0.8712231 0.8710593 0.8708953 0.8707310 0.8705664 0.8704016 0.8702365 [400] 0.8700711 0.8699054 > mx [1] 0.9101779 > mxli [1] -2 > 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/1i2h41193406854.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/2f6zm1193406854.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/35urv1193406854.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 > 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/4ltqi1193406854.tab") > > system("convert tmp/1i2h41193406854.ps tmp/1i2h41193406854.png") > system("convert tmp/2f6zm1193406854.ps tmp/2f6zm1193406854.png") > system("convert tmp/35urv1193406854.ps tmp/35urv1193406854.png") > > > proc.time() user system elapsed 1.875 0.785 1.992