R version 2.5.1 (2007-06-27) Copyright (C) 2007 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(0.0257493744938832 + ,0.021734532514729 + ,0.0181409407214812 + ,0.0152701505942662 + ,0.0130169628370724 + ,0.0113755336274530 + ,0.0104102672587416 + ,0.0100957980377989 + ,0.0102701844619835 + ,0.0107193845356072 + ,0.0112601657760742 + ,0.0117752995862039 + ,0.0122043778163178 + ,0.0125298799458765 + ,0.0127639590477691 + ,0.012937217037477 + ,0.0130890257027324 + ,0.0132543391742880 + ,0.0134562040704081 + ,0.0137014134900641 + ,0.0139761760838112 + ,0.014254906668871 + ,0.0145009100196785 + ,0.0146742460172555 + ,0.0147425838993809 + ,0.0146806157352704 + ,0.0144813558459163 + ,0.0141518828509622 + ,0.0137166291746623 + ,0.0132144865802642 + ,0.0126954985073174 + ,0.0122127590106538 + ,0.0118197530780406 + ,0.0115605302029674 + ,0.0114653295564385 + ,0.0115477666075857 + ,0.0118008984086779 + ,0.0122015373336842 + ,0.0127161972913673 + ,0.0133047190084541 + ,0.0139270942039374 + ,0.0145468382768111 + ,0.0151326313986313 + ,0.0156627183912659 + ,0.0161249314936152 + ,0.0165157734928721 + ,0.0168385143727890 + ,0.0171040905359246 + ,0.0173246160284153 + ,0.0175143229302128 + ,0.0176871470530748 + ,0.0178499332357475 + ,0.0180101805121891 + ,0.0181670326317408 + ,0.0183152217343903 + ,0.0184445154323164 + ,0.0185417822082271 + ,0.0185853019135757 + ,0.0185546256675338 + ,0.0184274237550889 + ,0.0181815126038245 + ,0.0178003184355686 + ,0.0172750557804465 + ,0.0166064564640451 + ,0.0158060406733841 + ,0.0148957772281856 + ,0.0139084949432564 + ,0.0128841617006653 + ,0.0118732217969068 + ,0.0109276070046339 + ,0.0101118222886584 + ,0.0094955906524746 + ,0.00916083841819465 + ,0.00919703433683982 + ,0.00968438506916855 + ,0.0106742913471305 + ,0.0121649595096515 + ,0.0140954137567437 + ,0.0163422947029298 + ,0.0187253547553665 + ,0.0210153504000639 + ,0.0229581518854807 + ,0.0243101462873557 + ,0.024886670194248 + ,0.0246046329518060 + ,0.0235246397989794 + ,0.0218629790162297 + ,0.0199805985887911 + ,0.0183298783311204 + ,0.0173304254644116 + ,0.0171531920939682 + ,0.0175490373660681 + ,0.0179383444747054 + ,0.0177538738190025 + ,0.0168765909408637 + ,0.0161209786732948 + ,0.0174324825582754 + ,0.0223196274919401 + ,0.0295050170940449) > 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: Wessa, P., (2007), Central Tendency (v1.0.2) 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 > #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] 0.01557588 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 0.0004081118 > (armose <- arm / armse) [1] 38.16571 > (geo <- geomean(x)) [1] 0.01508576 > (har <- harmean(x)) [1] 0.01462557 > (qua <- quamean(x)) [1] 0.01609131 > (win <- winmean(x)) [,1] [,2] [1,] 0.01553831 0.0003964379 [2,] 0.01552691 0.0003910512 [3,] 0.01552408 0.0003880977 [4,] 0.01552881 0.0003828042 [5,] 0.01548995 0.0003736876 [6,] 0.01546521 0.0003649206 [7,] 0.01542997 0.0003542720 [8,] 0.01541440 0.0003440371 [9,] 0.01540682 0.0003412401 [10,] 0.01535521 0.0003249651 [11,] 0.01527719 0.0003004328 [12,] 0.01513902 0.0002761871 [13,] 0.01513242 0.0002721476 [14,] 0.01513974 0.0002699940 [15,] 0.01513973 0.0002694808 [16,] 0.01515872 0.0002628328 [17,] 0.01516018 0.0002618824 [18,] 0.01514588 0.0002591930 [19,] 0.01515332 0.0002575017 [20,] 0.01518525 0.0002466185 [21,] 0.01518994 0.0002452707 [22,] 0.01518477 0.0002444755 [23,] 0.01515634 0.0002405193 [24,] 0.01521580 0.0002290031 [25,] 0.01523530 0.0002213513 [26,] 0.01522770 0.0002191495 [27,] 0.01522806 0.0002161161 [28,] 0.01524319 0.0002099427 [29,] 0.01521827 0.0002033937 [30,] 0.01523192 0.0001994120 [31,] 0.01522886 0.0001938797 [32,] 0.01523642 0.0001855277 [33,] 0.01524777 0.0001838310 > (tri <- trimean(x)) [,1] [,2] [1,] 0.01549841 0.0003849849 [2,] 0.01545684 0.0003719157 [3,] 0.01541954 0.0003602863 [4,] 0.01538163 0.0003482440 [5,] 0.01534070 0.0003362325 [6,] 0.01530673 0.0003251482 [7,] 0.01527597 0.0003146773 [8,] 0.01524973 0.0003051306 [9,] 0.01522457 0.0002963120 [10,] 0.01519919 0.0002866221 [11,] 0.01517914 0.0002785683 [12,] 0.01516737 0.0002736784 [13,] 0.01517057 0.0002719288 [14,] 0.01517466 0.0002703548 [15,] 0.01517824 0.0002686705 [16,] 0.01518204 0.0002665950 [17,] 0.01518426 0.0002649539 [18,] 0.01518648 0.0002629487 [19,] 0.01519014 0.0002607535 [20,] 0.01519339 0.0002581706 [21,] 0.01519410 0.0002564843 [22,] 0.01519446 0.0002543820 [23,] 0.01519528 0.0002516758 [24,] 0.01519857 0.0002487201 [25,] 0.01519712 0.0002466777 [26,] 0.01519390 0.0002450462 [27,] 0.01519390 0.0002429721 [28,] 0.01518788 0.0002404671 [29,] 0.01518311 0.0002379748 [30,] 0.01518003 0.0002355607 [31,] 0.01517541 0.0002326662 [32,] 0.01517053 0.0002294636 [33,] 0.01516435 0.0002264791 > (midr <- midrange(x)) [1] 0.01933293 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 0.01514377 0.01519857 0.01519857 0.01519857 0.01519712 0.01514377 0.01519857 [8] 0.01519857 > postscript(file="/var/www/html/rcomp/tmp/12psv1192985821.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/2cotz1192985821.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 > 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/3qsjy1192985822.tab") > > system("convert tmp/12psv1192985821.ps tmp/12psv1192985821.png") > system("convert tmp/2cotz1192985821.ps tmp/2cotz1192985821.png") > > > proc.time() user system elapsed 0.917 0.327 1.007