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(8.7,10.6,9.0,9.2,8.3,7.6,9.0,8.2,9.0,8.7,9.1,8.0,7.7,9.9,8.4,9.0,8.8,8.3,8.8,9.8,8.1,8.9,7.4,8.9,9.8,8.5,9.7,7.7,8.8,9.6,9.6,7.8,9.4,9.4,8.8,10.1,9.0,8.0,7.8,10.0,8.9,8.9,8.6,9.0,9.3,8.9,7.0,9.3,8.4,9.0,8.9,9.4,8.3,8.8,7.5,7.5,8.2,8.1,8.2,8.4,9.3,9.2,8.3,8.6,9.2,9.5,9.2,9.4,8.8,8.4,9.3,9.1,8.9,9.3,8.9,8.8,8.6,9.7,10.4,9.7,10.0,9.8,9.3,9.5,8.4,9.8,8.6,9.7,10.5,8.6,9.3,9.1,9.1,9.9,9.3,9.7,8.9,10.0,9.1,9.7,9.1,10.3,9.7,9.6,9.8,9.8,9.8,8.7,9.1,8.9,10.1,9.5,10.3,9.3,10.2,10.1,10.3,9.8,9.8,9.3,9.9,9.3,9.2,8.4,10.1,9.6,10.6,10.0,10.4,8.6,8.4,9.6,9.1,10.0,10.0,9.3,9.6,9.6,9.9,9.3,9.7,10.0,9.9,10.4,9.8,9.4,9.0,9.4,9.7,10.5,10.5,9.9,8.9,9.4,9.2,10.6,11.3,11.2,10.0,10.6,10.1,11.1,10.9,9.1,10.8,10.6,11.1,11.2,10.7,11.2,11.1,10.7,11.0,11.4,11.5,10.9) > ylimmax = '' > ylimmin = '' > main = 'Robustness of Central Tendency Temp.' > #'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] 9.386932 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 0.06685416 > (armose <- arm / armse) [1] 140.4091 > (geo <- geomean(x)) [1] 9.344992 > (har <- harmean(x)) [1] 9.302686 > (qua <- quamean(x)) [1] 9.428502 > (win <- winmean(x)) [,1] [,2] [1,] 9.388636 0.06632693 [2,] 9.388636 0.06594401 [3,] 9.386932 0.06566838 [4,] 9.389205 0.06530386 [5,] 9.392045 0.06486972 [6,] 9.388636 0.06433912 [7,] 9.392614 0.06375694 [8,] 9.392614 0.06375694 [9,] 9.397727 0.06159121 [10,] 9.392045 0.06076591 [11,] 9.398295 0.05997009 [12,] 9.391477 0.05901717 [13,] 9.391477 0.05712745 [14,] 9.391477 0.05712745 [15,] 9.382955 0.05604059 [16,] 9.392045 0.05497605 [17,] 9.392045 0.05497605 [18,] 9.392045 0.05497605 [19,] 9.392045 0.05497605 [20,] 9.392045 0.05231301 [21,] 9.392045 0.05231301 [22,] 9.392045 0.05231301 [23,] 9.378977 0.05077075 [24,] 9.378977 0.05077075 [25,] 9.378977 0.05077075 [26,] 9.364205 0.04911704 [27,] 9.379545 0.04744319 [28,] 9.395455 0.04581030 [29,] 9.378977 0.04400126 [30,] 9.361932 0.04224040 [31,] 9.361932 0.04224040 [32,] 9.361932 0.04224040 [33,] 9.361932 0.04224040 [34,] 9.381250 0.04031053 [35,] 9.361364 0.03834959 [36,] 9.361364 0.03834959 [37,] 9.382386 0.03634940 [38,] 9.382386 0.03634940 [39,] 9.382386 0.03634940 [40,] 9.382386 0.03634940 [41,] 9.382386 0.03634940 [42,] 9.382386 0.03634940 [43,] 9.357955 0.03404965 [44,] 9.382955 0.03179115 [45,] 9.382955 0.03179115 [46,] 9.382955 0.03179115 [47,] 9.382955 0.03179115 [48,] 9.382955 0.03179115 [49,] 9.355114 0.02928554 [50,] 9.355114 0.02928554 [51,] 9.355114 0.02928554 [52,] 9.355114 0.02928554 [53,] 9.355114 0.02928554 [54,] 9.355114 0.02928554 [55,] 9.386364 0.02659660 [56,] 9.386364 0.02659660 [57,] 9.386364 0.02659660 [58,] 9.386364 0.02659660 > (tri <- trimean(x)) [,1] [,2] [1,] 9.388506 0.06508072 [2,] 9.388372 0.06374054 [3,] 9.388235 0.06251390 [4,] 9.388690 0.06130080 [5,] 9.388554 0.06010465 [6,] 9.387805 0.05892435 [7,] 9.387654 0.05776666 [8,] 9.386875 0.05662912 [9,] 9.386076 0.05539847 [10,] 9.384615 0.05441739 [11,] 9.383766 0.05347980 [12,] 9.382237 0.05257488 [13,] 9.381333 0.05172104 [14,] 9.380405 0.05102965 [15,] 9.380405 0.05027950 [16,] 9.379167 0.04958917 [17,] 9.378169 0.04895386 [18,] 9.377143 0.04826212 [19,] 9.376087 0.04750803 [20,] 9.375000 0.04668475 [21,] 9.373881 0.04605317 [22,] 9.372727 0.04536192 [23,] 9.371538 0.04460433 [24,] 9.371094 0.04392404 [25,] 9.370635 0.04317653 [26,] 9.370161 0.04235371 [27,] 9.370492 0.04160590 [28,] 9.370000 0.04093788 [29,] 9.368644 0.04034652 [30,] 9.368644 0.03985730 [31,] 9.368421 0.03946773 [32,] 9.368750 0.03903253 [33,] 9.369091 0.03854626 [34,] 9.369444 0.03800262 [35,] 9.368868 0.03756667 [36,] 9.369231 0.03724745 [37,] 9.369608 0.03688484 [38,] 9.369000 0.03664448 [39,] 9.368367 0.03636656 [40,] 9.367708 0.03604623 [41,] 9.367021 0.03567784 [42,] 9.366304 0.03525476 [43,] 9.365556 0.03476912 [44,] 9.365909 0.03443401 [45,] 9.365116 0.03425052 [46,] 9.364286 0.03402788 [47,] 9.363415 0.03376024 [48,] 9.362500 0.03344062 [49,] 9.362500 0.03306070 [50,] 9.361842 0.03287227 [51,] 9.362162 0.03263696 [52,] 9.362500 0.03234676 [53,] 9.362857 0.03199194 [54,] 9.363235 0.03156055 [55,] 9.363636 0.03103771 [56,] 9.362500 0.03073988 [57,] 9.361290 0.03036486 [58,] 9.360000 0.02989624 > (midr <- midrange(x)) [1] 9.25 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 9.330208 9.371910 9.330208 9.371910 9.371910 9.330208 9.371910 9.330208 > postscript(file="/var/www/rcomp/tmp/19a3y1292159979.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/2k1k11292159979.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/3xeev1292159980.tab") > > try(system("convert tmp/19a3y1292159979.ps tmp/19a3y1292159979.png",intern=TRUE)) character(0) > try(system("convert tmp/2k1k11292159979.ps tmp/2k1k11292159979.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.070 0.430 1.501