R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 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. > x <- c(36,36,36,36,36,37.5,36.5,36,36.5,36.6,36,36.6,36.6,36.5,36.6,36.6,36.5,36.5,36.6,36,36,36,36,36,36,37,36,36.9,36.9,36,33.6,34.6,37.1,36.9,37.4,36.6,37,37.5,37.5,37,36.9,36.9,36,36.5,36,37.1,36,36.6,37,37,36,37.9,39.1,38.1,38.5,38,38,37.9,37.6,37,37,37.6,37,36.5) > par5 = 'Yes' > par4 = '0' > par3 = '2' > par2 = '-2' > par1 = 'Full Box-Cox transform' > par5 <- 'Yes' > par4 <- '0' > par3 <- '2' > par2 <- '-2' > par1 <- 'Full Box-Cox transform' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 () > #Author: root > #To cite this work: Wessa P., (2013), Box-Cox Normality Plot (v1.1.5) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_boxcoxnorm.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > # > par2 <- abs(as.numeric(par2)*100) > par3 <- as.numeric(par3)*100 > if(par4=='') par4 <- 0 > par4 <- as.numeric(par4) > numlam <- par2 + par3 + 1 > x <- x + par4 > n <- length(x) > c <- array(NA,dim=c(numlam)) > l <- array(NA,dim=c(numlam)) > mx <- -1 > mxli <- -999 > for (i in 1:numlam) + { + l[i] <- (i-par2-1)/100 + if (l[i] != 0) + { + if (par1 == 'Full Box-Cox transform') x1 <- (x^l[i] - 1) / l[i] + if (par1 == 'Simple Box-Cox transform') x1 <- x^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] + x1.best <- x1 + } + } > c [1] 0.4415971 0.4416631 0.4417290 0.4417949 0.4418608 0.4419266 0.4419923 [8] 0.4420580 0.4421237 0.4421893 0.4422548 0.4423203 0.4423858 0.4424511 [15] 0.4425165 0.4425818 0.4426470 0.4427122 0.4427774 0.4428425 0.4429075 [22] 0.4429725 0.4430375 0.4431024 0.4431672 0.4432320 0.4432968 0.4433615 [29] 0.4434261 0.4434907 0.4435553 0.4436198 0.4436842 0.4437486 0.4438130 [36] 0.4438773 0.4439415 0.4440057 0.4440698 0.4441339 0.4441980 0.4442620 [43] 0.4443259 0.4443898 0.4444537 0.4445175 0.4445812 0.4446449 0.4447085 [50] 0.4447721 0.4448357 0.4448992 0.4449626 0.4450260 0.4450894 0.4451527 [57] 0.4452159 0.4452791 0.4453422 0.4454053 0.4454684 0.4455314 0.4455943 [64] 0.4456572 0.4457200 0.4457828 0.4458456 0.4459082 0.4459709 0.4460335 [71] 0.4460960 0.4461585 0.4462209 0.4462833 0.4463457 0.4464080 0.4464702 [78] 0.4465324 0.4465945 0.4466566 0.4467186 0.4467806 0.4468426 0.4469044 [85] 0.4469663 0.4470281 0.4470898 0.4471515 0.4472131 0.4472747 0.4473362 [92] 0.4473977 0.4474591 0.4475205 0.4475819 0.4476431 0.4477044 0.4477655 [99] 0.4478267 0.4478878 0.4479488 0.4480098 0.4480707 0.4481316 0.4481924 [106] 0.4482532 0.4483139 0.4483746 0.4484352 0.4484958 0.4485563 0.4486168 [113] 0.4486772 0.4487376 0.4487979 0.4488582 0.4489184 0.4489786 0.4490387 [120] 0.4490987 0.4491588 0.4492187 0.4492787 0.4493385 0.4493983 0.4494581 [127] 0.4495178 0.4495775 0.4496371 0.4496967 0.4497562 0.4498157 0.4498751 [134] 0.4499344 0.4499938 0.4500530 0.4501122 0.4501714 0.4502305 0.4502896 [141] 0.4503486 0.4504075 0.4504664 0.4505253 0.4505841 0.4506429 0.4507016 [148] 0.4507602 0.4508188 0.4508774 0.4509359 0.4509944 0.4510528 0.4511111 [155] 0.4511694 0.4512277 0.4512859 0.4513440 0.4514021 0.4514602 0.4515182 [162] 0.4515761 0.4516340 0.4516919 0.4517497 0.4518074 0.4518651 0.4519228 [169] 0.4519804 0.4520379 0.4520954 0.4521529 0.4522103 0.4522676 0.4523249 [176] 0.4523822 0.4524393 0.4524965 0.4525536 0.4526106 0.4526676 0.4527246 [183] 0.4527815 0.4528383 0.4528951 0.4529518 0.4530085 0.4530651 0.4531217 [190] 0.4531783 0.4532348 0.4532912 0.4533476 0.4534039 0.4534602 0.4535164 [197] 0.4535726 0.4536288 0.4536848 0.4537409 0.4537968 0.4538528 0.4539087 [204] 0.4539645 0.4540203 0.4540760 0.4541317 0.4541873 0.4542429 0.4542984 [211] 0.4543539 0.4544093 0.4544647 0.4545200 0.4545753 0.4546305 0.4546857 [218] 0.4547408 0.4547959 0.4548509 0.4549059 0.4549608 0.4550157 0.4550705 [225] 0.4551253 0.4551800 0.4552347 0.4552893 0.4553438 0.4553984 0.4554528 [232] 0.4555072 0.4555616 0.4556159 0.4556702 0.4557244 0.4557786 0.4558327 [239] 0.4558867 0.4559408 0.4559947 0.4560486 0.4561025 0.4561563 0.4562101 [246] 0.4562638 0.4563174 0.4563711 0.4564246 0.4564781 0.4565316 0.4565850 [253] 0.4566384 0.4566917 0.4567449 0.4567981 0.4568513 0.4569044 0.4569574 [260] 0.4570104 0.4570634 0.4571163 0.4571692 0.4572220 0.4572747 0.4573274 [267] 0.4573801 0.4574327 0.4574852 0.4575377 0.4575902 0.4576426 0.4576949 [274] 0.4577472 0.4577995 0.4578517 0.4579038 0.4579559 0.4580080 0.4580600 [281] 0.4581119 0.4581638 0.4582157 0.4582675 0.4583192 0.4583709 0.4584225 [288] 0.4584741 0.4585257 0.4585772 0.4586286 0.4586800 0.4587314 0.4587827 [295] 0.4588339 0.4588851 0.4589362 0.4589873 0.4590384 0.4590894 0.4591403 [302] 0.4591912 0.4592420 0.4592928 0.4593436 0.4593943 0.4594449 0.4594955 [309] 0.4595460 0.4595965 0.4596470 0.4596973 0.4597477 0.4597980 0.4598482 [316] 0.4598984 0.4599485 0.4599986 0.4600487 0.4600986 0.4601486 0.4601985 [323] 0.4602483 0.4602981 0.4603478 0.4603975 0.4604471 0.4604967 0.4605463 [330] 0.4605958 0.4606452 0.4606946 0.4607439 0.4607932 0.4608424 0.4608916 [337] 0.4609407 0.4609898 0.4610389 0.4610879 0.4611368 0.4611857 0.4612345 [344] 0.4612833 0.4613320 0.4613807 0.4614293 0.4614779 0.4615265 0.4615749 [351] 0.4616234 0.4616718 0.4617201 0.4617684 0.4618166 0.4618648 0.4619129 [358] 0.4619610 0.4620090 0.4620570 0.4621049 0.4621528 0.4622007 0.4622484 [365] 0.4622962 0.4623439 0.4623915 0.4624391 0.4624866 0.4625341 0.4625815 [372] 0.4626289 0.4626762 0.4627235 0.4627708 0.4628179 0.4628651 0.4629122 [379] 0.4629592 0.4630062 0.4630531 0.4631000 0.4631468 0.4631936 0.4632404 [386] 0.4632870 0.4633337 0.4633803 0.4634268 0.4634733 0.4635197 0.4635661 [393] 0.4636124 0.4636587 0.4637050 0.4637511 0.4637973 0.4638434 0.4638894 [400] 0.4639354 0.4639813 > mx [1] 0.4639813 > mxli [1] 2 > x1.best [1] 647.500 647.500 647.500 647.500 647.500 702.625 665.625 647.500 665.625 [10] 669.280 647.500 669.280 669.280 665.625 669.280 669.280 665.625 665.625 [19] 669.280 647.500 647.500 647.500 647.500 647.500 647.500 684.000 647.500 [28] 680.305 680.305 647.500 563.980 598.080 687.705 680.305 698.880 669.280 [37] 684.000 702.625 702.625 684.000 680.305 680.305 647.500 665.625 647.500 [46] 687.705 647.500 669.280 684.000 684.000 647.500 717.705 763.905 725.305 [55] 740.625 721.500 721.500 717.705 706.380 684.000 684.000 706.380 684.000 [64] 665.625 > if (mxli != 0) + { + if (par1 == 'Full Box-Cox transform') x1 <- (x^mxli - 1) / mxli + if (par1 == 'Simple Box-Cox transform') x1 <- x^mxli + } else { + x1 <- log(x) + } > postscript(file="/var/wessaorg/rcomp/tmp/1qcyk1423603477.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/2uw4v1423603477.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/36e651423603477.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/4fkf61423603477.ps",horizontal=F,onefile=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/wessaorg/rcomp/tmp/55sqs1423603477.ps",horizontal=F,onefile=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/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 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) > if(mx<0) { + a<-table.row.start(a) + a<-table.element(a,'Warning: maximum correlation is negative! The Box-Cox transformation must not be used.',2) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/6jh3s1423603477.tab") > if(par5=='Yes') { + a<-table.start() + a<-table.row.start(a) + a<-table.element(a,'Obs.',header=T) + a<-table.element(a,'Original',header=T) + a<-table.element(a,'Transformed',header=T) + a<-table.row.end(a) + for (i in 1:n) { + a<-table.row.start(a) + a<-table.element(a,i) + a<-table.element(a,x[i]) + a<-table.element(a,x1.best[i]) + a<-table.row.end(a) + } + a<-table.end(a) + table.save(a,file="/var/wessaorg/rcomp/tmp/7cxj41423603477.tab") + } > > try(system("convert tmp/1qcyk1423603477.ps tmp/1qcyk1423603477.png",intern=TRUE)) character(0) > try(system("convert tmp/2uw4v1423603477.ps tmp/2uw4v1423603477.png",intern=TRUE)) character(0) > try(system("convert tmp/36e651423603477.ps tmp/36e651423603477.png",intern=TRUE)) character(0) > try(system("convert tmp/4fkf61423603477.ps tmp/4fkf61423603477.png",intern=TRUE)) character(0) > try(system("convert tmp/55sqs1423603477.ps tmp/55sqs1423603477.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.019 0.312 2.349