R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-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(38400,38100,38700,38600,38400,37800,38000,37700,37600,37900,38000,38800,39700,36700,38400,38200,35100,38000,38700,44200,38000,39100,39300,39700,38300,38100,38100,38500,38500,38300,39100,38900,37700,39500,39300,37300) > par3 = '2' > par2 = '-2' > par1 = 'Full Box-Cox transform' > par3 <- '2' > par2 <- '-2' > par1 <- 'Full Box-Cox transform' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa P., (2012), Box-Cox Normality Plot (v1.1.3) 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 > numlam <- par2 + par3 + 1 > n <- length(x) > c <- array(NA,dim=c(numlam)) > l <- array(NA,dim=c(numlam)) > mx <- 0 > 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] + } + } > c [1] 0.1130404 0.1130406 0.1130411 0.1130416 0.1130416 0.1130420 0.1130420 [8] 0.1130422 0.1130420 0.1130421 0.1130421 0.1130420 0.1130419 0.1130416 [15] 0.1130414 0.1130410 0.1130406 0.1130401 0.1130397 0.1130392 0.1130386 [22] 0.1130379 0.1130373 0.1130366 0.1130357 0.1130349 0.1130340 0.1130330 [29] 0.1130320 0.1130310 0.1130299 0.1130287 0.1130275 0.1130263 0.1130249 [36] 0.1130236 0.1130221 0.1130207 0.1130191 0.1130176 0.1130159 0.1130143 [43] 0.1130125 0.1130107 0.1130089 0.1130070 0.1130051 0.1130031 0.1130010 [50] 0.1129989 0.1129967 0.1129945 0.1129923 0.1129900 0.1129876 0.1129852 [57] 0.1129827 0.1129802 0.1129776 0.1129750 0.1129723 0.1129696 0.1129668 [64] 0.1129639 0.1129610 0.1129581 0.1129551 0.1129521 0.1129490 0.1129458 [71] 0.1129426 0.1129393 0.1129360 0.1129327 0.1129292 0.1129258 0.1129223 [78] 0.1129187 0.1129151 0.1129114 0.1129076 0.1129039 0.1129000 0.1128961 [85] 0.1128922 0.1128882 0.1128841 0.1128800 0.1128759 0.1128717 0.1128674 [92] 0.1128631 0.1128588 0.1128543 0.1128499 0.1128453 0.1128408 0.1128361 [99] 0.1128315 0.1128267 0.1128220 0.1128171 0.1128122 0.1128073 0.1128023 [106] 0.1127972 0.1127921 0.1127870 0.1127818 0.1127765 0.1127712 0.1127659 [113] 0.1127604 0.1127550 0.1127495 0.1127439 0.1127383 0.1127326 0.1127269 [120] 0.1127211 0.1127152 0.1127094 0.1127034 0.1126974 0.1126914 0.1126853 [127] 0.1126791 0.1126729 0.1126667 0.1126604 0.1126540 0.1126476 0.1126411 [134] 0.1126346 0.1126280 0.1126214 0.1126148 0.1126080 0.1126012 0.1125944 [141] 0.1125875 0.1125806 0.1125736 0.1125666 0.1125595 0.1125523 0.1125451 [148] 0.1125379 0.1125306 0.1125232 0.1125158 0.1125084 0.1125009 0.1124933 [155] 0.1124857 0.1124780 0.1124703 0.1124625 0.1124547 0.1124468 0.1124389 [162] 0.1124309 0.1124229 0.1124148 0.1124066 0.1123985 0.1123902 0.1123819 [169] 0.1123736 0.1123652 0.1123567 0.1123482 0.1123397 0.1123311 0.1123224 [176] 0.1123137 0.1123049 0.1122961 0.1122873 0.1122783 0.1122694 0.1122603 [183] 0.1122513 0.1122421 0.1122330 0.1122237 0.1122145 0.1122051 0.1121957 [190] 0.1121863 0.1121768 0.1121673 0.1121577 0.1121480 0.1121383 0.1121286 [197] 0.1121188 0.1121090 0.1120991 0.1120891 0.1120791 0.1120690 0.1120589 [204] 0.1120488 0.1120386 0.1120283 0.1120180 0.1120076 0.1119972 0.1119867 [211] 0.1119762 0.1119656 0.1119550 0.1119443 0.1119336 0.1119228 0.1119120 [218] 0.1119011 0.1118902 0.1118792 0.1118682 0.1118571 0.1118459 0.1118348 [225] 0.1118235 0.1118122 0.1118009 0.1117895 0.1117781 0.1117666 0.1117550 [232] 0.1117434 0.1117318 0.1117201 0.1117083 0.1116965 0.1116847 0.1116728 [239] 0.1116608 0.1116488 0.1116368 0.1116246 0.1116125 0.1116003 0.1115880 [246] 0.1115757 0.1115634 0.1115509 0.1115385 0.1115260 0.1115134 0.1115008 [253] 0.1114881 0.1114754 0.1114626 0.1114498 0.1114370 0.1114241 0.1114111 [260] 0.1113981 0.1113850 0.1113719 0.1113587 0.1113455 0.1113322 0.1113189 [267] 0.1113055 0.1112921 0.1112786 0.1112651 0.1112516 0.1112379 0.1112243 [274] 0.1112105 0.1111968 0.1111830 0.1111691 0.1111552 0.1111412 0.1111272 [281] 0.1111131 0.1110990 0.1110848 0.1110706 0.1110563 0.1110420 0.1110276 [288] 0.1110132 0.1109987 0.1109842 0.1109697 0.1109550 0.1109404 0.1109257 [295] 0.1109109 0.1108961 0.1108812 0.1108663 0.1108513 0.1108363 0.1108213 [302] 0.1108062 0.1107910 0.1107758 0.1107605 0.1107452 0.1107299 0.1107145 [309] 0.1106990 0.1106835 0.1106679 0.1106523 0.1106367 0.1106210 0.1106052 [316] 0.1105895 0.1105736 0.1105577 0.1105418 0.1105258 0.1105097 0.1104936 [323] 0.1104775 0.1104613 0.1104451 0.1104288 0.1104125 0.1103961 0.1103797 [330] 0.1103632 0.1103467 0.1103301 0.1103135 0.1102968 0.1102801 0.1102633 [337] 0.1102465 0.1102296 0.1102127 0.1101958 0.1101787 0.1101617 0.1101446 [344] 0.1101274 0.1101102 0.1100930 0.1100757 0.1100584 0.1100410 0.1100235 [351] 0.1100060 0.1099885 0.1099709 0.1099533 0.1099356 0.1099179 0.1099001 [358] 0.1098823 0.1098644 0.1098465 0.1098286 0.1098106 0.1097925 0.1097744 [365] 0.1097563 0.1097381 0.1097198 0.1097015 0.1096832 0.1096648 0.1096464 [372] 0.1096279 0.1096094 0.1095908 0.1095722 0.1095535 0.1095348 0.1095161 [379] 0.1094973 0.1094784 0.1094595 0.1094406 0.1094216 0.1094025 0.1093835 [386] 0.1093643 0.1093452 0.1093259 0.1093067 0.1092874 0.1092680 0.1092486 [393] 0.1092291 0.1092096 0.1091901 0.1091705 0.1091509 0.1091312 0.1091115 [400] 0.1090917 0.1090719 > mx [1] 0.1130422 > mxli [1] -1.93 > 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/1l6ls1346980194.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/2cldq1346980194.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/3yox31346980194.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/4885y1346980194.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/58mof1346980194.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) > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/65af21346980194.tab") > > try(system("convert tmp/1l6ls1346980194.ps tmp/1l6ls1346980194.png",intern=TRUE)) character(0) > try(system("convert tmp/2cldq1346980194.ps tmp/2cldq1346980194.png",intern=TRUE)) character(0) > try(system("convert tmp/3yox31346980194.ps tmp/3yox31346980194.png",intern=TRUE)) character(0) > try(system("convert tmp/4885y1346980194.ps tmp/4885y1346980194.png",intern=TRUE)) character(0) > try(system("convert tmp/58mof1346980194.ps tmp/58mof1346980194.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.650 0.393 2.037