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(-0.554046479470557 + ,-0.583025666609207 + ,0.506250798932448 + ,-0.573670050105768 + ,-0.53299634233786 + ,-0.487644826318229 + ,-155638538359647.00 + ,-0.566653337728184 + ,-0.480628113940645 + ,-0.583025666609214 + ,143334666227182.00 + ,14099576210132.00 + ,-0.456326735053768 + ,-0.517138242326169 + ,0.465178982405618 + ,0.547438735569693 + ,-14118875566624.00 + ,-0.421243173165842 + ,13809784338746.00 + ,0.536656552568649 + ,-1620448132623.00 + ,0.45297023290697 + ,-167138979452262.00 + ,23505726802384.00 + ,150533846130419.00 + ,0.505338461304186 + ,0.434258999900078 + ,0.491305036549017 + ,0.517032981933495 + ,147961051591971.00 + ,-14726990639348.00 + ,-151337277170271.00 + ,153665655256865.00 + ,-0.609665949621953 + ,-152181605057789.00 + ,0.366945009119433 + ,0.603970543349293 + ,155017574845448.00 + ,152171079018522.00 + ,-0.432025356166891 + ,0.567974643833109 + ,-146100454330549.00 + ,0.471681465913864 + ,-158211332898095.00 + ,150767736543005.00 + ,-155170757534475.00 + ,0.459986945284555 + ,-141097521903414.00 + ,0.498321748926601 + ,-255638538359647.00 + ,-0.520389484080292 + ,0.415547766893185 + ,0.507677365430048 + ,146089928291282.00 + ,-0.57509661660337 + ,0.521710790185217 + ,0.478698178291448 + ,248520066179969.00 + ,-0.506356059325122 + ,-0.536761812961322 + ,-154235195884131.00 + ,0.464150524666937 + ,0.534317648442787 + ,0.402940908635617 + ,-0.597059091364383 + ,0.460899282912816 + ,0.43659790402594 + ,-0.573670050105768 + ,-0.429686452041032 + ,0.65308752999239 + ,0.42165214164251 + ,0.54133436082037 + ,138656857975459.00 + ,246089928291282.00 + ,-0.555473045968216 + ,0.456735703530433 + ,-154702976709303.00 + ,0.413208862767323 + ,-157743552072923.00 + ,-0.5624897583458 + ,0.362267200867709 + ,147584504529625.00 + ,-0.627464845000585 + ,-0.468933593311338 + ,-145866563917963.00 + ,-0.537674150589584 + ,-146009220567723.00 + ,0.392672954503909 + ,-0.491410296941691 + ,-0.60875361199369 + ,0.405279812761477 + ,0.415547766893185 + ,-0.5610631918482 + ,0.42165214164251 + ,0.439849145780062 + ,-0.539100717087184 + ,-0.513372771702707 + ,140202857100736.00) > 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] -1.015592e+12 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 8.78329e+12 > (armose <- arm / armse) [1] -0.1156277 > (geo <- geomean(x)) [1] NaN Warning message: In log(x) : NaNs produced > (har <- harmean(x)) [1] 5.332908 > (qua <- quamean(x)) [1] 8.651133e+13 > (win <- winmean(x)) [,1] [,2] [1,] -1.373323e+11 8.549513e+12 [2,] -1.813755e+12 8.047590e+12 [3,] -1.840820e+12 8.036439e+12 [4,] -1.815905e+12 8.007207e+12 [5,] -1.863637e+12 7.988333e+12 [6,] -1.849317e+12 7.979852e+12 [7,] -1.999676e+12 7.937263e+12 [8,] -1.862774e+12 7.898252e+12 [9,] -1.922491e+12 7.856326e+12 [10,] -1.669270e+12 7.697648e+12 [11,] -2.010559e+12 7.627742e+12 [12,] -2.182397e+12 7.588033e+12 [13,] -1.682492e+13 5.225014e+12 [14,] -1.157220e+11 8.349231e+11 [15,] -6.699906e+10 8.103989e+11 [16,] -2.810981e+11 6.230030e+10 [17,] -4.940786e-03 5.531196e-02 [18,] -8.283093e-03 5.419763e-02 [19,] -1.208766e-02 5.374550e-02 [20,] -1.094682e-02 5.334040e-02 [21,] -8.942042e-03 5.289503e-02 [22,] -9.467102e-03 5.283926e-02 [23,] -1.056495e-02 5.231951e-02 [24,] -1.136118e-02 5.216077e-02 [25,] -1.374781e-02 5.191258e-02 [26,] -1.226471e-02 5.166694e-02 [27,] -1.136896e-02 5.151424e-02 [28,] -1.296615e-02 5.126257e-02 [29,] -1.338830e-02 5.086759e-02 [30,] -1.681083e-02 5.042676e-02 [31,] -1.430266e-02 4.968537e-02 [32,] -1.596011e-02 4.942106e-02 > (tri <- trimean(x)) [,1] [,2] [1,] -1.015592e+12 8.153209e+12 [2,] -9.625991e+11 7.694190e+12 [3,] -1.827899e+12 7.480465e+12 [4,] -1.827899e+12 7.241052e+12 [5,] -1.825243e+12 6.976353e+12 [6,] -1.816492e+12 6.676153e+12 [7,] -1.810110e+12 6.328515e+12 [8,] -1.810110e+12 5.929989e+12 [9,] -1.764724e+12 5.463254e+12 [10,] -1.742700e+12 4.903345e+12 [11,] -1.752169e+12 4.240870e+12 [12,] -1.721060e+12 3.375571e+12 [13,] -1.668733e+12 2.030138e+12 [14,] -3.652791e+10 4.090760e+11 [15,] -2.837558e+10 2.935597e+11 [16,] -2.837558e+10 2.455224e+10 [17,] -1.324905e-03 6.336834e-02 [18,] -9.887030e-04 6.387836e-02 [19,] -3.268047e-04 6.452348e-02 [20,] 7.190792e-04 6.523195e-02 [21,] 1.739845e-03 6.600387e-02 [22,] 2.662971e-03 6.684965e-02 [23,] 3.702086e-03 6.772587e-02 [24,] 4.917886e-03 6.869264e-02 [25,] 6.302736e-03 6.971206e-02 [26,] 8.011392e-03 7.079863e-02 [27,] 8.011392e-03 7.195969e-02 [28,] 1.157328e-02 7.318832e-02 [29,] 1.372048e-02 7.450229e-02 [30,] 1.613125e-02 7.593249e-02 [31,] 1.912043e-02 7.749676e-02 [32,] 1.912043e-02 7.927080e-02 > (midr <- midrange(x)) [1] -3.559236e+12 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] -0.005533443 0.004917886 0.004917886 0.004917886 -0.005533443 [6] 0.004917886 0.004917886 0.004917886 > postscript(file="/var/www/rcomp/tmp/1d13m1324395245.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/2yopq1324395245.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/3bpql1324395245.tab") > > try(system("convert tmp/1d13m1324395245.ps tmp/1d13m1324395245.png",intern=TRUE)) character(0) > try(system("convert tmp/2yopq1324395245.ps tmp/2yopq1324395245.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.390 0.080 1.468