R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(227.86 + ,198.24 + ,194.97 + ,184.88 + ,196.79 + ,205.36 + ,226.72 + ,226.05 + ,202.50 + ,194.79 + ,192.43 + ,219.25 + ,217.47 + ,192.34 + ,196.83 + ,186.07 + ,197.31 + ,215.02 + ,242.67 + ,225.17 + ,206.69 + ,197.75 + ,196.43 + ,213.55 + ,222.75 + ,194.03 + ,201.85 + ,189.50 + ,206.07 + ,225.59 + ,247.91 + ,247.64 + ,213.01 + ,203.01 + ,200.26 + ,220.50 + ,237.90 + ,216.94 + ,214.01 + ,196.00 + ,208.37 + ,232.75 + ,257.46 + ,267.69 + ,220.18 + ,210.61 + ,209.59 + ,232.75 + ,232.75 + ,219.82 + ,226.74 + ,208.04 + ,220.12 + ,235.69 + ,257.05 + ,258.69 + ,227.15 + ,219.91 + ,219.30 + ,259.04 + ,237.29 + ,212.88 + ,226.03 + ,211.07 + ,222.91 + ,249.18 + ,266.38 + ,268.53 + ,238.02 + ,224.69 + ,213.75 + ,237.43 + ,248.46 + ,210.82 + ,221.40 + ,209.00 + ,234.37 + ,248.43 + ,271.98 + ,268.11 + ,233.88 + ,223.43 + ,221.38 + ,233.76 + ,243.97 + ,217.76 + ,224.66 + ,210.84 + ,220.35 + ,236.84 + ,266.15 + ,255.20 + ,234.76 + ,221.29 + ,221.26 + ,244.13 + ,245.78 + ,224.62 + ,234.80 + ,211.37 + ,222.39 + ,249.63 + ,282.29 + ,279.13 + ,236.60 + ,223.62 + ,225.86 + ,246.41 + ,261.70 + ,225.01 + ,231.54 + ,214.82 + ,227.70 + ,263.86 + ,278.15 + ,274.64 + ,237.66 + ,227.97 + ,224.75 + ,242.91 + ,253.08 + ,228.13 + ,233.68 + ,217.38 + ,236.38 + ,256.08 + ,292.83 + ,304.71 + ,245.57 + ,234.41 + ,234.12 + ,258.17 + ,268.66 + ,245.31 + ,247.47 + ,226.25 + ,251.67 + ,268.79 + ,288.94 + ,290.16 + ,250.69 + ,240.80) > ylimmax = '' > ylimmin = '' > main = 'Robustness of Central Tendency' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > 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] 231.0894 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 2.045293 > (armose <- arm / armse) [1] 112.9859 > (geo <- geomean(x)) [1] 229.8437 > (har <- harmean(x)) [1] 228.6268 > (qua <- quamean(x)) [1] 232.3621 > (win <- winmean(x)) [,1] [,2] [1,] 231.0141 2.0242147 [2,] 231.0248 2.0088705 [3,] 231.0590 1.9949997 [4,] 230.8742 1.9579151 [5,] 230.8193 1.9299414 [6,] 230.8100 1.9183329 [7,] 230.6458 1.8876993 [8,] 230.5540 1.8557259 [9,] 230.3791 1.8209881 [10,] 230.3953 1.8162800 [11,] 230.3883 1.8143704 [12,] 230.3934 1.8037940 [13,] 230.3952 1.7928858 [14,] 230.3144 1.7677860 [15,] 230.5035 1.7373552 [16,] 230.4246 1.6784664 [17,] 230.2438 1.6331435 [18,] 229.9713 1.5802969 [19,] 230.2389 1.5370842 [20,] 230.2656 1.5160972 [21,] 230.2523 1.4921305 [22,] 230.3980 1.4608466 [23,] 230.2943 1.4348715 [24,] 230.2520 1.4045408 [25,] 229.9827 1.3471731 [26,] 229.9113 1.2962131 [27,] 229.7649 1.2700113 [28,] 229.5598 1.2454337 [29,] 229.5149 1.2299697 [30,] 229.4261 1.2060966 [31,] 229.7492 1.1710099 [32,] 229.6613 1.1548195 [33,] 229.7241 1.1350327 [34,] 229.7313 1.1256489 [35,] 229.5341 1.0902416 [36,] 229.5797 1.0521664 [37,] 229.5771 1.0410214 [38,] 230.0213 0.9836540 [39,] 229.8181 0.9368391 [40,] 229.7984 0.9295750 [41,] 229.5761 0.8888575 [42,] 229.9458 0.8405871 [43,] 229.3946 0.7793894 [44,] 228.6944 0.6775837 [45,] 228.6849 0.6712296 [46,] 228.6751 0.6573832 [47,] 228.6189 0.6481905 > (tri <- trimean(x)) [,1] [,2] [1,] 230.8936 1.9787650 [2,] 230.7696 1.9289786 [3,] 230.6363 1.8832426 [4,] 230.4870 1.8386051 [5,] 230.3829 1.8014021 [6,] 230.2875 1.7679044 [7,] 230.2875 1.7337249 [8,] 230.1177 1.7023869 [9,] 230.0552 1.6737677 [10,] 230.0134 1.6481033 [11,] 229.9682 1.6205007 [12,] 229.9222 1.5902562 [13,] 229.8741 1.5582654 [14,] 229.8741 1.5242638 [15,] 229.7798 1.4898756 [16,] 229.7175 1.4555132 [17,] 229.6594 1.4247712 [18,] 229.6134 1.3961154 [19,] 229.5863 1.3705046 [20,] 229.5384 1.3467821 [21,] 229.4868 1.3225012 [22,] 229.4340 1.2978776 [23,] 229.3692 1.2735491 [24,] 229.3084 1.2489847 [25,] 229.2477 1.2245523 [26,] 229.2013 1.2033792 [27,] 229.1573 1.1848929 [28,] 229.1573 1.1666109 [29,] 229.0936 1.1483415 [30,] 229.0684 1.1289575 [31,] 229.0684 1.1092409 [32,] 229.0060 1.0902515 [33,] 228.9678 1.0699793 [34,] 228.9238 1.0485418 [35,] 228.8769 1.0244288 [36,] 228.8389 1.0006494 [37,] 228.7959 0.9774250 [38,] 228.7505 0.9511784 [39,] 228.6763 0.9273296 [40,] 228.6092 0.9054416 [41,] 228.5388 0.8798182 [42,] 228.4769 0.8550952 [43,] 228.3882 0.8316559 [44,] 228.3267 0.8133740 [45,] 228.3038 0.8069932 [46,] 228.2798 0.7991095 [47,] 228.2544 0.7905441 > (midr <- midrange(x)) [1] 244.795 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 228.6300 228.8769 228.8769 228.8769 228.8389 228.8769 228.8769 228.8769 > postscript(file="/var/www/html/rcomp/tmp/18xt61268842330.ps",horizontal=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/www/html/rcomp/tmp/2j6ab1268842330.ps",horizontal=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/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/www/html/rcomp/tmp/3l3sh1268842330.tab") > > try(system("convert tmp/18xt61268842330.ps tmp/18xt61268842330.png",intern=TRUE)) character(0) > try(system("convert tmp/2j6ab1268842330.ps tmp/2j6ab1268842330.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.808 0.336 1.153