R version 2.6.0 (2007-10-03) 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.000249254412317267 + ,0.000299603588409276 + ,0.000322518965091164 + ,-0.000329538636649367 + ,-6.43325994869136e-05 + ,0.000218734547908577 + ,-0.000186123790106601 + ,0.000320044464404368 + ,0.000105079817925291 + ,-3.21375723064676e-05 + ,-9.31379372201002e-05 + ,0.000863880329915967 + ,-0.000955068293604838 + ,0.000191654585176615 + ,-0.000687217159304088 + ,-0.00133295077536133 + ,-8.40818637339591e-05 + ,0.000480643586810492 + ,-0.00133724173345948 + ,-0.00078463864413933 + ,-9.63012198662017e-05 + ,-0.000267289029594886 + ,-0.000415973064666258 + ,-0.00145962546732839 + ,0.00114159591731011 + ,-0.00146064163655782 + ,-0.00105351430012057 + ,0.000585759739068242 + ,-0.00113140931418457 + ,-0.00138720915811827 + ,0.000330704048772557 + ,0.00089730707501226 + ,-0.00282718491905784 + ,0.00130177229774819 + ,0.000106725469179531 + ,0.00194958872561832 + ,0.000635002216373137 + ,-0.000802593879913022 + ,0.000669740048378942 + ,-0.00184856803744929 + ,-0.00115402862422859 + ,0.000720565693177494 + ,0.00127635646932789 + ,0.000280808847524822 + ,-0.00124166740902709 + ,0.00220850912079990 + ,0.00014951799778537 + ,0.000246824748826507 + ,-0.000329567131906322 + ,-0.000100055638308394 + ,-0.000843374093922739 + ,-0.00182816513524967 + ,0.000762276721414934 + ,0.000547214397100731 + ,-0.000261835368196878 + ,-0.000145977686326793 + ,-0.000418138010040314 + ,-0.000275994456749945 + ,0.00096506287877901 + ,-0.000122679144738069 + ,-0.00077104475183501 + ,-0.000772836964526374 + ,-9.74711304966847e-05 + ,0.00132936498148101 + ,0.000993746723184863 + ,-0.000451847013386047 + ,-0.000138456169144319 + ,-0.00109488862631829 + ,-0.000236567991803771 + ,0.000228265967558205 + ,-0.000141243730919727 + ,7.13248149721013e-05 + ,0.000100146168015486 + ,-0.000101542587067266 + ,-0.00103071143157252 + ,-0.000910687763439777 + ,-0.00169775499641645 + ,0.000648520060953617 + ,-0.00081739205188841 + ,-0.000440416182630077 + ,-0.000143836644462325 + ,-0.00086105174113707 + ,0.00118491489582653 + ,0.00092521493356959 + ,0.000685499195885314 + ,-0.00170870319900812 + ,-0.000681671133016343 + ,-0.00207056008076914 + ,0.000710534206097013 + ,-0.00163014844752510 + ,-0.00123315260753790 + ,-0.000307767159812872 + ,-0.000896177657593727 + ,0.000651475976366861 + ,0.00196454841594412 + ,0.000447156493560086) > 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.0001648618 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 9.572845e-05 > (armose <- arm / armse) [1] -1.722182 > (geo <- geomean(x)) [1] NaN Warning message: In log(x) : NaNs produced > (har <- harmean(x)) [1] -0.001006701 > (qua <- quamean(x)) [1] 0.0009474985 > (win <- winmean(x)) [,1] [,2] [1,] -0.0001595215 9.308173e-05 [2,] -0.0001552084 9.205903e-05 [3,] -0.0001739528 8.784228e-05 [4,] -0.0001701249 8.667740e-05 [5,] -0.0001708784 8.633595e-05 [6,] -0.0001723681 8.457203e-05 [7,] -0.0001631669 8.188680e-05 [8,] -0.0001754030 7.988929e-05 [9,] -0.0001713031 7.834775e-05 [10,] -0.0001702490 7.687847e-05 [11,] -0.0001729551 7.632402e-05 [12,] -0.0001657230 7.392185e-05 [13,] -0.0001783288 7.178603e-05 [14,] -0.0001728727 6.919902e-05 [15,] -0.0001709059 6.846156e-05 [16,] -0.0001689916 6.700655e-05 [17,] -0.0001644556 6.557664e-05 [18,] -0.0001636045 6.451206e-05 [19,] -0.0001492185 6.235570e-05 [20,] -0.0001427888 6.073188e-05 [21,] -0.0001503865 5.887381e-05 [22,] -0.0001511701 5.665153e-05 [23,] -0.0001628841 5.405664e-05 [24,] -0.0001647604 5.215684e-05 [25,] -0.0001912328 4.803238e-05 [26,] -0.0001885867 4.712959e-05 [27,] -0.0001859635 4.660919e-05 [28,] -0.0001914027 4.586315e-05 [29,] -0.0001717573 4.189427e-05 [30,] -0.0001798850 4.055925e-05 [31,] -0.0001064555 3.125341e-05 [32,] -0.0001088315 3.007768e-05 > (tri <- trimean(x)) [,1] [,2] [1,] -0.0001617878 9.002742e-05 [2,] -0.0001641527 8.653226e-05 [3,] -0.0001689229 8.315030e-05 [4,] -0.0001670939 8.112219e-05 [5,] -0.0001662481 7.919611e-05 [6,] -0.0001651897 7.707893e-05 [7,] -0.0001637891 7.509176e-05 [8,] -0.0001638957 7.341885e-05 [9,] -0.0001621254 7.189872e-05 [10,] -0.0001608373 7.043233e-05 [11,] -0.0001596163 6.899141e-05 [12,] -0.0001579995 6.739410e-05 [13,] -0.0001571168 6.593789e-05 [14,] -0.0001548132 6.457193e-05 [15,] -0.0001529369 6.337708e-05 [16,] -0.0001511400 6.205846e-05 [17,] -0.0001494124 6.070587e-05 [18,] -0.0001479966 5.930127e-05 [19,] -0.0001465614 5.776238e-05 [20,] -0.0001463217 5.624796e-05 [21,] -0.0001466357 5.465691e-05 [22,] -0.0001463059 5.300778e-05 [23,] -0.0001458814 5.134840e-05 [24,] -0.0001444029 4.973636e-05 [25,] -0.0001426327 4.804224e-05 [26,] -0.0001383913 4.664930e-05 [27,] -0.0001339785 4.499579e-05 [28,] -0.0001293576 4.290170e-05 [29,] -0.0001237595 4.021905e-05 [30,] -0.0001193460 3.771704e-05 [31,] -0.0001136482 3.454911e-05 [32,] -0.0001143442 3.322289e-05 > (midr <- midrange(x)) [1] -0.0003093379 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] -0.0001586677 -0.0001444029 -0.0001586677 -0.0001444029 -0.0001444029 [6] -0.0001586677 -0.0001444029 -0.0001458814 > postscript(file="/var/www/html/rcomp/tmp/1kcpx1197555920.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/2ksjz1197555920.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/3oldh1197555920.tab") > > system("convert tmp/1kcpx1197555920.ps tmp/1kcpx1197555920.png") > system("convert tmp/2ksjz1197555920.ps tmp/2ksjz1197555920.png") > > > proc.time() user system elapsed 1.000 0.318 1.270