R version 2.12.0 (2010-10-15) Copyright (C) 2010 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(28.23472222 + ,28.05861111 + ,1.993333333 + ,26.82222222 + ,48.84 + ,94.88055556 + ,28.77694444 + ,31.28083333 + ,23.77055556 + ,61.33361111 + ,25.73916667 + ,37.03555556 + ,17.04472222 + ,34.98055556 + ,22.86555556 + ,28.33611111 + ,28.20083333 + ,11.54611111 + ,27.75638889 + ,6.291111111 + ,12.97166667 + ,36.58277778 + ,25.48194444 + ,22.18416667 + ,30.01194444 + ,27.46277778 + ,33.45694444 + ,32.23555556 + ,69.4575 + ,37.80111111 + ,25.69416667 + ,37.71694444 + ,20.66888889 + ,22.56666667 + ,37.04666667 + ,27.26277778 + ,22.11638889 + ,16.44277778 + ,38.87277778 + ,32.94777778 + ,20.24444444 + ,18.1875 + ,27.67861111 + ,19.99027778 + ,21.46444444 + ,13.69138889 + ,37.53638889 + ,30.12388889 + ,24.92944444 + ,12.30444444 + ,21.56888889 + ,50.42444444 + ,37.2275 + ,34.46222222 + ,25.73055556 + ,33.84666667 + ,14.69861111 + ,22.74222222 + ,16.38361111 + ,14.86527778 + ,16.89222222 + ,15.65972222 + ,18.19166667 + ,22.48583333 + ,21.195 + ,28.89194444 + ,27.25111111 + ,18.88583333 + ,8.608055556 + ,37.62722222 + ,20.41777778 + ,17.53416667 + ,17.015 + ,20.80944444 + ,8.826111111 + ,22.62138889 + ,24.21833333 + ,13.91388889 + ,18.2625 + ,15.73694444 + ,43.99972222 + ,12.90416667 + ,20.45111111 + ,10.66527778 + ,25.5275 + ,38.75722222 + ,14.49 + ,14.32416667 + ,19.5975 + ,23.57111111 + ,28.48277778 + ,24.07722222 + ,23.80805556 + ,9.628333333 + ,41.82777778 + ,27.66972222 + ,5.374722222 + ,27.60361111 + ,23.95277778 + ,8.565833333 + ,8.807222222 + ,24.94611111 + ,17.24666667 + ,11.15305556 + ,7.676111111 + ,21.38611111 + ,10.40555556 + ,15.04361111 + ,13.85055556 + ,23.42694444 + ,17.82638889 + ,16.495 + ,33.14111111 + ,21.30611111 + ,28.72916667 + ,19.54 + ,12.05833333 + ,29.12166667 + ,17.28194444 + ,19.25111111 + ,14.75472222 + ,5.49 + ,24.07777778 + ,23.3625 + ,21.65138889 + ,24.75361111 + ,25.27916667 + ,11.18 + ,17.82972222 + ,14.12694444 + ,15.72583333 + ,17.44222222 + ,20.14861111) > 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] 23.80232 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 1.060803 > (armose <- arm / armse) [1] 22.43803 > (geo <- geomean(x)) [1] 21.08132 > (har <- harmean(x)) [1] 17.89194 > (qua <- quamean(x)) [1] 26.74117 > (win <- winmean(x)) [,1] [,2] [1,] 23.63659 0.9738075 [2,] 23.51616 0.9329623 [3,] 23.28816 0.8628667 [4,] 23.28216 0.8457114 [5,] 23.13365 0.8022377 [6,] 23.03757 0.7834095 [7,] 22.89253 0.7553134 [8,] 22.88671 0.7540418 [9,] 22.87630 0.7363790 [10,] 22.92841 0.7276128 [11,] 22.94247 0.7236904 [12,] 22.97828 0.7168516 [13,] 22.95072 0.7119059 [14,] 22.97023 0.7042368 [15,] 23.02674 0.6970530 [16,] 23.00188 0.6853017 [17,] 22.87374 0.6463610 [18,] 22.81273 0.6354419 [19,] 22.82761 0.6114762 [20,] 22.79294 0.6008313 [21,] 22.75307 0.5930413 [22,] 22.75633 0.5848489 [23,] 22.66727 0.5650004 [24,] 22.52491 0.5399968 [25,] 22.34666 0.5096070 [26,] 22.33574 0.5058377 [27,] 22.17745 0.4830335 [28,] 22.16663 0.4735054 [29,] 22.27590 0.4557544 [30,] 22.28003 0.4529536 [31,] 22.22519 0.4465230 [32,] 22.34549 0.4259499 [33,] 22.33502 0.4217214 [34,] 22.33971 0.4193924 [35,] 22.40681 0.4045122 [36,] 22.35824 0.3924901 [37,] 22.34487 0.3893875 [38,] 22.40003 0.3832092 [39,] 22.39099 0.3801389 [40,] 22.39684 0.3708535 [41,] 22.36353 0.3616310 [42,] 22.45212 0.3519890 [43,] 22.31454 0.3377061 [44,] 22.07459 0.2904401 > (tri <- trimean(x)) [,1] [,2] [1,] 23.42622 0.9134451 [2,] 23.20932 0.8438790 [3,] 23.04865 0.7900458 [4,] 22.96371 0.7601721 [5,] 22.87762 0.7325495 [6,] 22.82134 0.7139546 [7,] 22.78106 0.6978226 [8,] 22.76296 0.6858208 [9,] 22.74507 0.6727508 [10,] 22.72790 0.6613026 [11,] 22.70388 0.6499644 [12,] 22.67741 0.6379153 [13,] 22.64625 0.6254426 [14,] 22.61658 0.6121904 [15,] 22.58396 0.5983728 [16,] 22.54509 0.5837641 [17,] 22.50674 0.5688806 [18,] 22.47714 0.5572777 [19,] 22.45104 0.5455572 [20,] 22.42269 0.5352459 [21,] 22.39564 0.5248280 [22,] 22.37020 0.5139061 [23,] 22.34337 0.5024037 [24,] 22.32134 0.4917134 [25,] 22.30774 0.4825345 [26,] 22.30519 0.4755949 [27,] 22.30321 0.4679453 [28,] 22.31126 0.4617072 [29,] 22.32041 0.4554695 [30,] 22.32321 0.4502048 [31,] 22.32591 0.4442222 [32,] 22.33217 0.4378273 [33,] 22.33134 0.4327162 [34,] 22.33112 0.4269933 [35,] 22.33058 0.4202841 [36,] 22.32583 0.4140838 [37,] 22.32380 0.4080814 [38,] 22.32248 0.4010186 [39,] 22.31754 0.3931082 [40,] 22.31281 0.3836581 [41,] 22.30734 0.3733363 [42,] 22.30362 0.3619197 [43,] 22.29361 0.3491438 [44,] 22.29217 0.3356857 > (midr <- midrange(x)) [1] 48.43694 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 22.24190 22.33134 22.33134 22.33134 22.33134 22.24388 22.33134 22.33134 > postscript(file="/var/www/rcomp/tmp/1ontr1323786644.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/www/rcomp/tmp/22d8t1323786644.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/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/35kx41323786645.tab") > > try(system("convert tmp/1ontr1323786644.ps tmp/1ontr1323786644.png",intern=TRUE)) character(0) > try(system("convert tmp/22d8t1323786644.ps tmp/22d8t1323786644.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.070 0.080 1.122