R version 3.2.2 (2015-08-14) -- "Fire Safety" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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(-0.424161762,-0.17863807,-0.418493516,-0.132607372,0.0340645085,-0.528085163,0.57857203,0.276024279,-0.965391821,1.11957954,-0.545820594,1.25419459,-0.845197164,-1.55872006,-0.650976559,-1.25637904,-0.889969225) > x <- c(0.916136389,0.0553066729,1.14653716,-1.2084043,0.0553066729,-1.0474444,-0.144444216,0.261295263,0.261295263,1.3829179,-0.879837669,1.14653716,0.916136389,-1.0474444,-1.0474444,-0.524992897,-0.337898185) > ylab = 'y' > xlab = 'x' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 () > #Author: root > #To cite this work: Wessa P., (2014), Box-Cox Linearity Plot (v1.0.6) 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 > # > n <- length(x) > c <- array(NA,dim=c(401)) > l <- array(NA,dim=c(401)) > mymin = min(x) > if(mymin < 0) { + x <- x - mymin +1 + } > 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.3782073 0.3787297 0.3792521 0.3797746 0.3802972 0.3808199 0.3813426 [8] 0.3818654 0.3823883 0.3829112 0.3834341 0.3839571 0.3844801 0.3850032 [15] 0.3855263 0.3860494 0.3865725 0.3870956 0.3876187 0.3881419 0.3886650 [22] 0.3891881 0.3897112 0.3902342 0.3907573 0.3912802 0.3918032 0.3923261 [29] 0.3928489 0.3933717 0.3938944 0.3944170 0.3949396 0.3954621 0.3959845 [36] 0.3965067 0.3970289 0.3975510 0.3980729 0.3985947 0.3991164 0.3996380 [43] 0.4001594 0.4006807 0.4012018 0.4017227 0.4022435 0.4027641 0.4032845 [50] 0.4038047 0.4043247 0.4048445 0.4053642 0.4058835 0.4064027 0.4069216 [57] 0.4074403 0.4079588 0.4084770 0.4089949 0.4095126 0.4100300 0.4105471 [64] 0.4110639 0.4115804 0.4120966 0.4126125 0.4131281 0.4136434 0.4141583 [71] 0.4146729 0.4151871 0.4157010 0.4162145 0.4167277 0.4172404 0.4177528 [78] 0.4182648 0.4187764 0.4192876 0.4197983 0.4203087 0.4208186 0.4213280 [85] 0.4218370 0.4223456 0.4228537 0.4233613 0.4238684 0.4243751 0.4248812 [92] 0.4253869 0.4258920 0.4263966 0.4269007 0.4274043 0.4279073 0.4284097 [99] 0.4289116 0.4294130 0.4299137 0.4304139 0.4309135 0.4314124 0.4319108 [106] 0.4324085 0.4329057 0.4334022 0.4338980 0.4343932 0.4348877 0.4353816 [113] 0.4358748 0.4363673 0.4368591 0.4373503 0.4378407 0.4383304 0.4388194 [120] 0.4393076 0.4397951 0.4402819 0.4407679 0.4412531 0.4417375 0.4422212 [127] 0.4427041 0.4431862 0.4436675 0.4441480 0.4446276 0.4451064 0.4455844 [134] 0.4460615 0.4465378 0.4470132 0.4474878 0.4479615 0.4484342 0.4489061 [141] 0.4493771 0.4498472 0.4503163 0.4507845 0.4512518 0.4517182 0.4521836 [148] 0.4526480 0.4531115 0.4535740 0.4540355 0.4544960 0.4549555 0.4554141 [155] 0.4558716 0.4563281 0.4567835 0.4572379 0.4576913 0.4581436 0.4585949 [162] 0.4590451 0.4594942 0.4599423 0.4603893 0.4608351 0.4612799 0.4617235 [169] 0.4621661 0.4626075 0.4630478 0.4634869 0.4639249 0.4643618 0.4647975 [176] 0.4652320 0.4656653 0.4660975 0.4665285 0.4669583 0.4673869 0.4678143 [183] 0.4682404 0.4686654 0.4690891 0.4695116 0.4699329 0.4703529 0.4707717 [190] 0.4711892 0.4716054 0.4720204 0.4724341 0.4728465 0.4732577 0.4736675 [197] 0.4740761 0.4744833 0.4748893 0.4752939 0.4756972 0.4760992 0.4764998 [204] 0.4768991 0.4772971 0.4776937 0.4780890 0.4784829 0.4788755 0.4792667 [211] 0.4796565 0.4800450 0.4804320 0.4808177 0.4812020 0.4815849 0.4819664 [218] 0.4823466 0.4827253 0.4831026 0.4834784 0.4838529 0.4842260 0.4845976 [225] 0.4849678 0.4853365 0.4857039 0.4860698 0.4864342 0.4867972 0.4871588 [232] 0.4875189 0.4878775 0.4882347 0.4885904 0.4889447 0.4892975 0.4896488 [239] 0.4899987 0.4903471 0.4906940 0.4910394 0.4913834 0.4917258 0.4920668 [246] 0.4924063 0.4927443 0.4930809 0.4934159 0.4937494 0.4940815 0.4944120 [253] 0.4947411 0.4950686 0.4953947 0.4957192 0.4960423 0.4963638 0.4966839 [260] 0.4970024 0.4973195 0.4976350 0.4979490 0.4982615 0.4985725 0.4988820 [267] 0.4991900 0.4994965 0.4998015 0.5001050 0.5004070 0.5007074 0.5010064 [274] 0.5013038 0.5015998 0.5018942 0.5021872 0.5024786 0.5027685 0.5030570 [281] 0.5033439 0.5036293 0.5039133 0.5041957 0.5044766 0.5047561 0.5050341 [288] 0.5053105 0.5055855 0.5058590 0.5061310 0.5064015 0.5066705 0.5069381 [295] 0.5072042 0.5074688 0.5077319 0.5079936 0.5082538 0.5085125 0.5087698 [302] 0.5090256 0.5092799 0.5095328 0.5097843 0.5100343 0.5102828 0.5105299 [309] 0.5107756 0.5110198 0.5112626 0.5115039 0.5117439 0.5119824 0.5122195 [316] 0.5124552 0.5126894 0.5129223 0.5131537 0.5133838 0.5136124 0.5138397 [323] 0.5140655 0.5142900 0.5145131 0.5147349 0.5149552 0.5151742 0.5153918 [330] 0.5156081 0.5158230 0.5160365 0.5162488 0.5164596 0.5166692 0.5168774 [337] 0.5170842 0.5172898 0.5174940 0.5176970 0.5178986 0.5180989 0.5182979 [344] 0.5184957 0.5186921 0.5188873 0.5190811 0.5192738 0.5194651 0.5196552 [351] 0.5198440 0.5200316 0.5202180 0.5204031 0.5205869 0.5207696 0.5209510 [358] 0.5211312 0.5213102 0.5214880 0.5216646 0.5218400 0.5220143 0.5221873 [365] 0.5223592 0.5225299 0.5226994 0.5228678 0.5230350 0.5232011 0.5233660 [372] 0.5235298 0.5236925 0.5238541 0.5240145 0.5241739 0.5243321 0.5244893 [379] 0.5246453 0.5248003 0.5249542 0.5251070 0.5252588 0.5254095 0.5255592 [386] 0.5257078 0.5258553 0.5260019 0.5261474 0.5262919 0.5264354 0.5265779 [393] 0.5267193 0.5268598 0.5269993 0.5271378 0.5272754 0.5274119 0.5275476 [400] 0.5276822 0.5278159 > mx [1] 0.5278159 > 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/wessaorg/rcomp/tmp/1gyi41449669339.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/2oxdu1449669339.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/3c00y1449669339.ps",horizontal=F,onefile=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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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) > if(mymin < 0) { + a<-table.element(a,'added constant term to x',header=TRUE) + a<-table.element(a,-mymin+1) + 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/wessaorg/rcomp/tmp/4mupl1449669339.tab") > > try(system("convert tmp/1gyi41449669339.ps tmp/1gyi41449669339.png",intern=TRUE)) character(0) > try(system("convert tmp/2oxdu1449669339.ps tmp/2oxdu1449669339.png",intern=TRUE)) character(0) > try(system("convert tmp/3c00y1449669339.ps tmp/3c00y1449669339.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.275 0.185 1.467