R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 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(221102 + ,220892 + ,225537 + ,219334 + ,216126 + ,224573 + ,213991 + ,221865 + ,215382 + ,213962 + ,217009 + ,318110 + ,219662 + ,212650 + ,209307 + ,210541 + ,210609 + ,208910 + ,207541 + ,207699 + ,205005 + ,205747 + ,203644 + ,229937 + ,214446 + ,210194 + ,206535 + ,216524 + ,198243 + ,208274 + ,207493 + ,215525 + ,207562 + ,213355 + ,209048 + ,220497 + ,214563 + ,211571 + ,216385 + ,211496 + ,209683 + ,206304 + ,213925 + ,204829 + ,205729 + ,200296 + ,207960 + ,207729 + ,208327 + ,207794 + ,213700 + ,213136 + ,210354 + ,202205 + ,220425 + ,210038 + ,205201 + ,197441 + ,200021 + ,203165 + ,201699 + ,201003 + ,232308 + ,211412 + ,209661 + ,213587 + ,193611 + ,192543 + ,196040 + ,191407 + ,189726 + ,191272 + ,187924 + ,198213 + ,199352 + ,199289 + ,195475 + ,198045 + ,197615 + ,189015 + ,189668 + ,189120 + ,194168 + ,192304 + ,185913 + ,197599 + ,186085 + ,190566 + ,187054 + ,193222 + ,189856 + ,190608 + ,190588 + ,186773 + ,183510 + ,180106 + ,180150 + ,178412 + ,182353 + ,203805 + ,186054 + ,184290 + ,187483 + ,187111 + ,189561 + ,184439 + ,182985 + ,183828 + ,184036 + ,183214 + ,183464 + ,173718 + ,180210 + ,171252 + ,172705 + ,174006 + ,172043 + ,169445 + ,169449 + ,177073 + ,170799 + ,171648 + ,172220 + ,165795 + ,167466 + ,165528 + ,162851 + ,165864 + ,162094 + ,162385 + ,164293 + ,165983 + ,159680 + ,161739 + ,159302 + ,167795 + ,164242 + ,159743 + ,160887 + ,163844 + ,161172 + ,159330 + ,155570 + ,156749 + ,155012 + ,163419 + ,153630 + ,154535 + ,151543 + ,152955 + ,150166 + ,151416 + ,150332 + ,152196 + ,153422 + ,147435) > ylimmax = '' > ylimmin = '' > main = 'Robustness of Central Tendency' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa, P., (2012), Central Tendency (v1.0.4) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_centraltendency.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > # > geomean <- function(x) { + return(exp(mean(log(x)))) + } > harmean <- function(x) { + return(1/mean(1/x)) + } > quamean <- function(x) { + return(sqrt(mean(x*x))) + } > winmean <- function(x) { + x <-sort(x[!is.na(x)]) + n<-length(x) + denom <- 3 + nodenom <- n/denom + if (nodenom>40) denom <- n/40 + sqrtn = sqrt(n) + roundnodenom = floor(nodenom) + win <- array(NA,dim=c(roundnodenom,2)) + for (j in 1:roundnodenom) { + win[j,1] <- (j*x[j+1]+sum(x[(j+1):(n-j)])+j*x[n-j])/n + win[j,2] <- sd(c(rep(x[j+1],j),x[(j+1):(n-j)],rep(x[n-j],j)))/sqrtn + } + return(win) + } > trimean <- function(x) { + x <-sort(x[!is.na(x)]) + n<-length(x) + denom <- 3 + nodenom <- n/denom + if (nodenom>40) denom <- n/40 + sqrtn = sqrt(n) + roundnodenom = floor(nodenom) + tri <- array(NA,dim=c(roundnodenom,2)) + for (j in 1:roundnodenom) { + tri[j,1] <- mean(x,trim=j/n) + tri[j,2] <- sd(x[(j+1):(n-j)]) / sqrt(n-j*2) + } + return(tri) + } > midrange <- function(x) { + return((max(x)+min(x))/2) + } > q1 <- function(data,n,p,i,f) { + np <- n*p; + i <<- floor(np) + f <<- np - i + qvalue <- (1-f)*data[i] + f*data[i+1] + } > q2 <- function(data,n,p,i,f) { + np <- (n+1)*p + i <<- floor(np) + f <<- np - i + qvalue <- (1-f)*data[i] + f*data[i+1] + } > q3 <- function(data,n,p,i,f) { + np <- n*p + i <<- floor(np) + f <<- np - i + if (f==0) { + qvalue <- data[i] + } else { + qvalue <- data[i+1] + } + } > q4 <- function(data,n,p,i,f) { + np <- n*p + i <<- floor(np) + f <<- np - i + if (f==0) { + qvalue <- (data[i]+data[i+1])/2 + } else { + qvalue <- data[i+1] + } + } > q5 <- function(data,n,p,i,f) { + np <- (n-1)*p + i <<- floor(np) + f <<- np - i + if (f==0) { + qvalue <- data[i+1] + } else { + qvalue <- data[i+1] + f*(data[i+2]-data[i+1]) + } + } > q6 <- function(data,n,p,i,f) { + np <- n*p+0.5 + i <<- floor(np) + f <<- np - i + qvalue <- data[i] + } > q7 <- function(data,n,p,i,f) { + np <- (n+1)*p + i <<- floor(np) + f <<- np - i + if (f==0) { + qvalue <- data[i] + } else { + qvalue <- f*data[i] + (1-f)*data[i+1] + } + } > q8 <- function(data,n,p,i,f) { + np <- (n+1)*p + i <<- floor(np) + f <<- np - i + if (f==0) { + qvalue <- data[i] + } else { + if (f == 0.5) { + qvalue <- (data[i]+data[i+1])/2 + } else { + if (f < 0.5) { + qvalue <- data[i] + } else { + qvalue <- data[i+1] + } + } + } + } > midmean <- function(x,def) { + x <-sort(x[!is.na(x)]) + n<-length(x) + if (def==1) { + qvalue1 <- q1(x,n,0.25,i,f) + qvalue3 <- q1(x,n,0.75,i,f) + } + if (def==2) { + qvalue1 <- q2(x,n,0.25,i,f) + qvalue3 <- q2(x,n,0.75,i,f) + } + if (def==3) { + qvalue1 <- q3(x,n,0.25,i,f) + qvalue3 <- q3(x,n,0.75,i,f) + } + if (def==4) { + qvalue1 <- q4(x,n,0.25,i,f) + qvalue3 <- q4(x,n,0.75,i,f) + } + if (def==5) { + qvalue1 <- q5(x,n,0.25,i,f) + qvalue3 <- q5(x,n,0.75,i,f) + } + if (def==6) { + qvalue1 <- q6(x,n,0.25,i,f) + qvalue3 <- q6(x,n,0.75,i,f) + } + if (def==7) { + qvalue1 <- q7(x,n,0.25,i,f) + qvalue3 <- q7(x,n,0.75,i,f) + } + if (def==8) { + qvalue1 <- q8(x,n,0.25,i,f) + qvalue3 <- q8(x,n,0.75,i,f) + } + midm <- 0 + myn <- 0 + roundno4 <- round(n/4) + round3no4 <- round(3*n/4) + for (i in 1:n) { + if ((x[i]>=qvalue1) & (x[i]<=qvalue3)){ + midm = midm + x[i] + myn = myn + 1 + } + } + midm = midm / myn + return(midm) + } > (arm <- mean(x)) [1] 191728 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 1895.908 > (armose <- arm / armse) [1] 101.1273 > (geo <- geomean(x)) [1] 190305.4 > (har <- harmean(x)) [1] 188896.2 > (qua <- quamean(x)) [1] 193175.5 > (win <- winmean(x)) [,1] [,2] [1,] 191195.5 1729.3009 [2,] 191167.2 1724.4395 [3,] 191103.5 1709.6491 [4,] 191082.0 1705.9905 [5,] 191016.1 1692.2750 [6,] 191016.0 1684.5706 [7,] 191027.5 1680.4475 [8,] 191017.9 1676.6000 [9,] 191066.0 1668.6855 [10,] 191047.7 1658.8859 [11,] 191063.9 1650.8353 [12,] 190975.7 1619.1989 [13,] 191148.1 1586.7292 [14,] 191138.1 1585.1194 [15,] 191146.8 1578.2254 [16,] 191091.7 1571.1544 [17,] 191200.8 1553.7193 [18,] 191139.1 1540.2047 [19,] 191193.9 1530.1846 [20,] 191181.1 1518.8614 [21,] 191216.4 1513.6561 [22,] 191276.9 1505.1081 [23,] 191327.5 1491.7368 [24,] 191375.5 1482.1915 [25,] 191402.1 1470.9836 [26,] 191374.1 1466.4665 [27,] 191503.7 1433.2033 [28,] 191358.0 1409.4183 [29,] 191356.8 1406.6290 [30,] 191363.6 1402.4641 [31,] 191498.7 1353.7517 [32,] 191552.2 1344.7704 [33,] 191861.7 1301.8696 [34,] 191827.7 1298.5839 [35,] 192095.6 1262.0521 [36,] 192118.2 1243.2105 [37,] 192206.9 1232.5955 [38,] 192216.9 1214.4087 [39,] 192196.4 1203.8054 [40,] 192285.4 1187.3366 [41,] 192398.4 1145.3684 [42,] 192461.7 1135.9444 [43,] 193220.5 1041.4313 [44,] 193551.4 999.7961 [45,] 194021.3 951.1117 [46,] 194025.4 949.0651 [47,] 194002.2 943.5283 [48,] 194655.1 882.1200 [49,] 194838.5 862.9684 [50,] 194604.9 827.6510 [51,] 194611.1 813.3956 [52,] 194440.8 794.9080 > (tri <- trimean(x)) [,1] [,2] [1,] 191195.0 1710.4782 [2,] 191194.4 1690.1202 [3,] 191208.6 1670.8017 [4,] 191245.5 1655.5478 [5,] 191289.1 1640.0513 [6,] 191348.3 1626.5381 [7,] 191409.1 1613.4065 [8,] 191469.9 1599.8153 [9,] 191533.7 1585.5836 [10,] 191593.3 1571.2389 [11,] 191656.9 1556.9183 [12,] 191720.6 1542.2871 [13,] 191795.1 1530.2236 [14,] 191855.7 1520.8642 [15,] 191919.2 1510.6072 [16,] 191984.0 1499.9477 [17,] 192055.3 1488.7995 [18,] 192120.6 1478.2318 [19,] 192192.7 1467.7500 [20,] 192263.4 1457.0027 [21,] 192337.5 1446.0221 [22,] 192411.8 1434.1682 [23,] 192485.0 1421.6650 [24,] 192557.7 1408.8766 [25,] 192630.2 1395.3659 [26,] 192703.8 1381.1738 [27,] 192782.1 1365.5131 [28,] 192855.9 1351.0682 [29,] 192941.1 1336.8200 [30,] 193029.9 1320.7954 [31,] 193029.9 1302.8843 [32,] 193210.8 1287.3590 [33,] 193300.7 1270.4180 [34,] 193378.0 1255.4686 [35,] 193460.7 1238.4313 [36,] 193533.1 1222.6724 [37,] 193607.9 1206.2838 [38,] 193681.7 1188.3224 [39,] 193758.8 1169.2936 [40,] 193841.1 1148.1101 [41,] 193923.0 1125.1880 [42,] 194003.6 1103.3281 [43,] 194085.4 1078.5878 [44,] 194131.6 1061.8409 [45,] 194131.6 1047.0390 [46,] 194170.4 1035.2717 [47,] 194178.3 1020.9142 [48,] 194188.1 1003.8916 [49,] 194161.9 991.3719 [50,] 194123.4 978.0834 [51,] 194095.6 966.4838 [52,] 194065.3 953.5290 > (midr <- midrange(x)) [1] 232772.5 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 193483.9 193758.8 193483.9 193758.8 193758.8 193483.9 193758.8 193681.7 > postscript(file="/var/fisher/rcomp/tmp/1x6h21381579279.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > lb <- win[,1] - 2*win[,2] > ub <- win[,1] + 2*win[,2] > if ((ylimmin == '') | (ylimmax == '')) plot(win[,1],type='b',main=main, xlab='j', pch=19, ylab='Winsorized Mean(j/n)', ylim=c(min(lb),max(ub))) else plot(win[,1],type='l',main=main, xlab='j', pch=19, ylab='Winsorized Mean(j/n)', ylim=c(ylimmin,ylimmax)) > lines(ub,lty=3) > lines(lb,lty=3) > grid() > dev.off() null device 1 > postscript(file="/var/fisher/rcomp/tmp/2sv0c1381579279.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > lb <- tri[,1] - 2*tri[,2] > ub <- tri[,1] + 2*tri[,2] > if ((ylimmin == '') | (ylimmax == '')) plot(tri[,1],type='b',main=main, xlab='j', pch=19, ylab='Trimmed Mean(j/n)', ylim=c(min(lb),max(ub))) else plot(tri[,1],type='l',main=main, xlab='j', pch=19, ylab='Trimmed Mean(j/n)', ylim=c(ylimmin,ylimmax)) > lines(ub,lty=3) > lines(lb,lty=3) > grid() > dev.off() null device 1 > > #Note: the /var/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Central Tendency - Ungrouped Data',4,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Measure',header=TRUE) > a<-table.element(a,'Value',header=TRUE) > a<-table.element(a,'S.E.',header=TRUE) > a<-table.element(a,'Value/S.E.',header=TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink('http://www.xycoon.com/arithmetic_mean.htm', 'Arithmetic Mean', 'click to view the definition of the Arithmetic Mean'),header=TRUE) > a<-table.element(a,arm) > a<-table.element(a,hyperlink('http://www.xycoon.com/arithmetic_mean_standard_error.htm', armse, 'click to view the definition of the Standard Error of the Arithmetic Mean')) > a<-table.element(a,armose) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink('http://www.xycoon.com/geometric_mean.htm', 'Geometric Mean', 'click to view the definition of the Geometric Mean'),header=TRUE) > a<-table.element(a,geo) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink('http://www.xycoon.com/harmonic_mean.htm', 'Harmonic Mean', 'click to view the definition of the Harmonic Mean'),header=TRUE) > a<-table.element(a,har) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink('http://www.xycoon.com/quadratic_mean.htm', 'Quadratic Mean', 'click to view the definition of the Quadratic Mean'),header=TRUE) > a<-table.element(a,qua) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > for (j in 1:length(win[,1])) { + a<-table.row.start(a) + mylabel <- paste('Winsorized Mean (',j) + mylabel <- paste(mylabel,'/') + mylabel <- paste(mylabel,length(win[,1])) + mylabel <- paste(mylabel,')') + a<-table.element(a,hyperlink('http://www.xycoon.com/winsorized_mean.htm', mylabel, 'click to view the definition of the Winsorized Mean'),header=TRUE) + a<-table.element(a,win[j,1]) + a<-table.element(a,win[j,2]) + a<-table.element(a,win[j,1]/win[j,2]) + a<-table.row.end(a) + } > for (j in 1:length(tri[,1])) { + a<-table.row.start(a) + mylabel <- paste('Trimmed Mean (',j) + mylabel <- paste(mylabel,'/') + mylabel <- paste(mylabel,length(tri[,1])) + mylabel <- paste(mylabel,')') + a<-table.element(a,hyperlink('http://www.xycoon.com/arithmetic_mean.htm', mylabel, 'click to view the definition of the Trimmed Mean'),header=TRUE) + a<-table.element(a,tri[j,1]) + a<-table.element(a,tri[j,2]) + a<-table.element(a,tri[j,1]/tri[j,2]) + a<-table.row.end(a) + } > a<-table.row.start(a) > a<-table.element(a,hyperlink('http://www.xycoon.com/median_1.htm', 'Median', 'click to view the definition of the Median'),header=TRUE) > a<-table.element(a,median(x)) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink('http://www.xycoon.com/midrange.htm', 'Midrange', 'click to view the definition of the Midrange'),header=TRUE) > a<-table.element(a,midr) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_1.htm','Weighted Average at Xnp',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[1]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_2.htm','Weighted Average at X(n+1)p',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[2]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_3.htm','Empirical Distribution Function',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[3]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_4.htm','Empirical Distribution Function - Averaging',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[4]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_5.htm','Empirical Distribution Function - Interpolation',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[5]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_6.htm','Closest Observation',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[6]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_7.htm','True Basic - Statistics Graphics Toolkit',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[7]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > mymid <- hyperlink('http://www.xycoon.com/midmean.htm', 'Midmean', 'click to view the definition of the Midmean') > mylabel <- paste(mymid,hyperlink('http://www.xycoon.com/method_8.htm','MS Excel (old versions)',''),sep=' - ') > a<-table.element(a,mylabel,header=TRUE) > a<-table.element(a,midm[8]) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Number of observations',header=TRUE) > a<-table.element(a,length(x)) > a<-table.element(a,'') > a<-table.element(a,'') > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/fisher/rcomp/tmp/3sxw21381579279.tab") > > try(system("convert tmp/1x6h21381579279.ps tmp/1x6h21381579279.png",intern=TRUE)) character(0) > try(system("convert tmp/2sv0c1381579279.ps tmp/2sv0c1381579279.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.719 0.249 1.950