R version 3.0.3 (2014-03-06) -- "Warm Puppy" Copyright (C) 2014 The R Foundation for Statistical Computing Platform: i686-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(0.078125,0.078125,0.078125,0.921875,1.078125,1.921875,0.078125,1.078125,1.078125,0.921875,0.078125,1.078125,0.078125,1.078125,2.921875,0.078125,1.078125,0.078125,0.078125,2.921875,0.078125,1.921875,0.078125,1.078125,0.078125,0.078125,0.078125,1.921875,0.078125,0.078125,0.078125,0.078125,0.078125,1.921875,0.078125,0.078125,0.078125,0.078125,0.078125,0.078125,0.921875,0.921875,1.078125,1.078125,1.078125,1.921875,0.078125,0.078125,0.078125,1.078125,0.078125,0.078125,0.078125,1.078125,1.078125,1.078125,0.078125,0.921875,1.078125,1.078125,1.078125,0.078125,1.078125,1.921875) > par5 = 'No' > par4 = '0' > par3 = '2' > par2 = '-2' > par1 = 'Full Box-Cox transform' > par5 <- 'No' > 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.1382666759 0.1382633947 0.1382600235 0.1382565601 0.1382530019 [6] 0.1382493465 0.1382455914 0.1382417339 0.1382377715 0.1382337013 [11] 0.1382295207 0.1382252267 0.1382208163 0.1382162867 0.1382116348 [16] 0.1382068573 0.1382019511 0.1381969129 0.1381917393 0.1381864268 [21] 0.1381809719 0.1381753709 0.1381696202 0.1381637160 0.1381576543 [26] 0.1381514312 0.1381450426 0.1381384843 0.1381317521 0.1381248415 [31] 0.1381177482 0.1381104675 0.1381029947 0.1380953251 0.1380874537 [36] 0.1380793755 0.1380710855 0.1380625782 0.1380538485 0.1380448907 [41] 0.1380356993 0.1380262685 0.1380165924 0.1380066650 0.1379964802 [46] 0.1379860317 0.1379753130 0.1379643176 0.1379530388 0.1379414697 [51] 0.1379296033 0.1379174324 0.1379049496 0.1378921476 0.1378790186 [56] 0.1378655547 0.1378517481 0.1378375905 0.1378230736 0.1378081889 [61] 0.1377929276 0.1377772808 0.1377612396 0.1377447945 0.1377279361 [66] 0.1377106547 0.1376929405 0.1376747833 0.1376561729 0.1376370987 [71] 0.1376175500 0.1375975158 0.1375769850 0.1375559461 0.1375343875 [76] 0.1375122973 0.1374896633 0.1374664733 0.1374427145 0.1374183741 [81] 0.1373934389 0.1373678956 0.1373417305 0.1373149296 0.1372874788 [86] 0.1372593635 0.1372305690 0.1372010803 0.1371708819 0.1371399583 [91] 0.1371082934 0.1370758711 0.1370426748 0.1370086876 0.1369738923 [96] 0.1369382715 0.1369018073 0.1368644815 0.1368262756 0.1367871708 [101] 0.1367471480 0.1367061875 0.1366642696 0.1366213739 0.1365774799 [106] 0.1365325666 0.1364866128 0.1364395966 0.1363914960 0.1363422886 [111] 0.1362919515 0.1362404615 0.1361877949 0.1361339278 0.1360788356 [116] 0.1360224936 0.1359648765 0.1359059587 0.1358457141 0.1357841162 [121] 0.1357211381 0.1356567524 0.1355909314 0.1355236469 0.1354548703 [126] 0.1353845724 0.1353127237 0.1352392944 0.1351642539 0.1350875715 [131] 0.1350092157 0.1349291550 0.1348473569 0.1347637889 0.1346784179 [136] 0.1345912102 0.1345021318 0.1344111482 0.1343182244 0.1342233250 [141] 0.1341264140 0.1340274552 0.1339264117 0.1338232462 0.1337179211 [146] 0.1336103980 0.1335006383 0.1333886030 0.1332742524 0.1331575466 [151] 0.1330384451 0.1329169070 0.1327928909 0.1326663551 0.1325372574 [156] 0.1324055551 0.1322712051 0.1321341640 0.1319943880 0.1318518326 [161] 0.1317064533 0.1315582049 0.1314070421 0.1312529189 0.1310957893 [166] 0.1309356066 0.1307723241 0.1306058944 0.1304362701 0.1302634032 [171] 0.1300872458 0.1299077494 0.1297248652 0.1295385444 0.1293487378 [176] 0.1291553959 0.1289584692 0.1287579079 0.1285536620 0.1283456813 [181] 0.1281339156 0.1279183146 0.1276988278 0.1274754045 0.1272479943 [186] 0.1270165465 0.1267810105 0.1265413356 0.1262974712 0.1260493670 [191] 0.1257969724 0.1255402371 0.1252791111 0.1250135443 0.1247434870 [196] 0.1244688896 0.1241897030 0.1239058780 0.1236173662 0.1233241191 [201] 0.1230260890 0.1227232283 0.1224154901 0.1221028278 0.1217851955 [206] 0.1214625478 0.1211348398 0.1208020274 0.1204640670 0.1201209160 [211] 0.1197725323 0.1194188747 0.1190599027 0.1186955769 0.1183258585 [216] 0.1179507100 0.1175700946 0.1171839767 0.1167923217 0.1163950961 [221] 0.1159922675 0.1155838049 0.1151696784 0.1147498592 0.1143243200 [226] 0.1138930350 0.1134559793 0.1130131300 0.1125644653 0.1121099649 [231] 0.1116496103 0.1111833843 0.1107112715 0.1102332581 0.1097493319 [236] 0.1092594825 0.1087637013 0.1082619813 0.1077543176 0.1072407068 [241] 0.1067211477 0.1061956408 0.1056641886 0.1051267955 0.1045834679 [246] 0.1040342144 0.1034790451 0.1029179728 0.1023510118 0.1017781788 [251] 0.1011994925 0.1006149736 0.1000246451 0.0994285320 0.0988266613 [256] 0.0982190625 0.0976057668 0.0969868078 0.0963622212 0.0957320449 [261] 0.0950963186 0.0944550846 0.0938083869 0.0931562719 0.0924987878 [266] 0.0918359852 0.0911679165 0.0904946362 0.0898162008 0.0891326689 [271] 0.0884441010 0.0877505595 0.0870521088 0.0863488150 0.0856407462 [276] 0.0849279724 0.0842105652 0.0834885979 0.0827621456 0.0820312851 [281] 0.0812960947 0.0805566543 0.0798130453 0.0790653507 0.0783136547 [286] 0.0775580431 0.0767986027 0.0760354220 0.0752685902 0.0744981982 [291] 0.0737243376 0.0729471011 0.0721665825 0.0713828765 0.0705960786 [296] 0.0698062851 0.0690135931 0.0682181004 0.0674199055 0.0666191071 [301] 0.0658158049 0.0650100986 0.0642020886 0.0633918755 0.0625795601 [306] 0.0617652435 0.0609490269 0.0601310116 0.0593112988 0.0584899899 [311] 0.0576671859 0.0568429880 0.0560174969 0.0551908131 0.0543630370 [316] 0.0535342683 0.0527046065 0.0518741506 0.0510429991 0.0502112497 [321] 0.0493789998 0.0485463460 0.0477133841 0.0468802093 0.0460469159 [326] 0.0452135974 0.0443803465 0.0435472548 0.0427144132 0.0418819114 [331] 0.0410498382 0.0402182812 0.0393873273 0.0385570618 0.0377275692 [336] 0.0368989326 0.0360712342 0.0352445548 0.0344189739 0.0335945700 [341] 0.0327714201 0.0319496000 0.0311291842 0.0303102458 0.0294928568 [346] 0.0286770876 0.0278630073 0.0270506838 0.0262401835 0.0254315715 [351] 0.0246249113 0.0238202653 0.0230176944 0.0222172580 0.0214190144 [356] 0.0206230202 0.0198293308 0.0190380001 0.0182490808 0.0174626240 [361] 0.0166786796 0.0158972960 0.0151185203 0.0143423984 0.0135689746 [366] 0.0127982921 0.0120303925 0.0112653164 0.0105031030 0.0097437901 [371] 0.0089874142 0.0082340109 0.0074836141 0.0067362567 0.0059919703 [376] 0.0052507855 0.0045127314 0.0037778361 0.0030461266 0.0023176287 [381] 0.0015923669 0.0008703649 0.0001516451 -0.0005637711 -0.0012758634 [386] -0.0019846124 -0.0026900000 -0.0033920087 -0.0040906223 -0.0047858255 [391] -0.0054776039 -0.0061659441 -0.0068508335 -0.0075322605 -0.0082102143 [396] -0.0088846850 -0.0095556636 -0.0102231417 -0.0108871120 -0.0115475677 [401] -0.0122045031 > mx [1] 0.1382667 > mxli [1] -2 > x1.best [1] -81.42000000 -81.42000000 -81.42000000 -0.08833668 0.06983827 [6] 0.36463084 -81.42000000 0.06983827 0.06983827 -0.08833668 [11] -81.42000000 0.06983827 -81.42000000 0.06983827 0.44143384 [16] -81.42000000 0.06983827 -81.42000000 -81.42000000 0.44143384 [21] -81.42000000 0.36463084 -81.42000000 0.06983827 -81.42000000 [26] -81.42000000 -81.42000000 0.36463084 -81.42000000 -81.42000000 [31] -81.42000000 -81.42000000 -81.42000000 0.36463084 -81.42000000 [36] -81.42000000 -81.42000000 -81.42000000 -81.42000000 -81.42000000 [41] -0.08833668 -0.08833668 0.06983827 0.06983827 0.06983827 [46] 0.36463084 -81.42000000 -81.42000000 -81.42000000 0.06983827 [51] -81.42000000 -81.42000000 -81.42000000 0.06983827 0.06983827 [56] 0.06983827 -81.42000000 -0.08833668 0.06983827 0.06983827 [61] 0.06983827 -81.42000000 0.06983827 0.36463084 > 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/1fmcp1395251166.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/2ki591395251166.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/3io4w1395251166.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/4omz01395251166.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/5u1461395251166.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/6xh6u1395251166.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/7vinu1395251166.tab") + } > > try(system("convert tmp/1fmcp1395251166.ps tmp/1fmcp1395251166.png",intern=TRUE)) character(0) > try(system("convert tmp/2ki591395251166.ps tmp/2ki591395251166.png",intern=TRUE)) character(0) > try(system("convert tmp/3io4w1395251166.ps tmp/3io4w1395251166.png",intern=TRUE)) character(0) > try(system("convert tmp/4omz01395251166.ps tmp/4omz01395251166.png",intern=TRUE)) character(0) > try(system("convert tmp/5u1461395251166.ps tmp/5u1461395251166.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.075 1.065 6.159