R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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(9.25191650214777 + ,22.2914871231093 + ,-37.1571787652725 + ,34.2241616971526 + ,-175.791407724228 + ,104.976083789095 + ,-61.2440566196127 + ,-396.729670521475 + ,-396.444398116046 + ,-260.009316249011 + ,127.969010842559 + ,-36.0298439891068 + ,204.138369307228 + ,44.2385868225793 + ,-159.706287587307 + ,203.135138015573 + ,121.756524240115 + ,-16.201912213436 + ,-243.900810018248 + ,391.694842812422 + ,-164.230167511809 + ,293.821184036089 + ,150.197655606598 + ,-191.027489040204 + ,251.842321753795 + ,-153.374881206835 + ,8.18402595915808 + ,276.197036933044 + ,7.49356404026701 + ,290.310133584149 + ,154.709015296672 + ,-344.563215955918 + ,-268.812624672229 + ,308.788007355503 + ,53.4487117440732 + ,309.745158451771 + ,86.3072721968555 + ,-34.8646306315522 + ,196.561770309702 + ,226.513512287148 + ,-188.002590167187 + ,-58.5622808865756 + ,209.148059688065 + ,145.969099712344 + ,129.401752382899 + ,-33.029934043082 + ,-386.049808215712 + ,144.248501282334 + ,117.138964771591 + ,129.897118044206 + ,-152.218688907773 + ,-55.0236881924031 + ,144.022136077333 + ,-16.8566548273021 + ,144.685804574834 + ,-160.202973636103 + ,329.620650922733 + ,138.317376113334 + ,9.00038368194928 + ,50.5918463808212 + ,313.87529752068 + ,236.907637607133 + ,110.05132904939 + ,-383.848947466715) > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = '' > par9 = '' > par8 = '' > par7 = '' > par6 = '' > par5 = '' > par4 = '' > par3 = '' > par2 = '' > par1 = '' > main = 'Robustness of Central Tendency' > 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] 29.01231 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 25.00636 > (armose <- arm / armse) [1] 1.160197 > (geo <- geomean(x)) [1] NaN Warning message: In log(x) : NaNs produced > (har <- harmean(x)) [1] 149.815 > (qua <- quamean(x)) [1] 200.591 > (win <- winmean(x)) [,1] [,2] [1,] 28.04686 24.799828 [2,] 27.87965 24.619495 [3,] 27.78921 24.556512 [4,] 30.18475 23.913206 [5,] 34.93348 22.318827 [6,] 35.42963 22.081583 [7,] 35.64788 21.433085 [8,] 39.21271 19.595858 [9,] 37.53789 19.162089 [10,] 37.82181 18.544048 [11,] 36.82421 17.711555 [12,] 36.63999 17.431679 [13,] 36.53710 17.382556 [14,] 36.48417 16.917714 [15,] 26.94591 15.485617 [16,] 48.56173 11.461948 [17,] 48.15087 11.196966 [18,] 48.78517 10.997115 [19,] 53.95946 10.204980 [20,] 54.24102 10.145202 [21,] 52.75148 9.830341 > (tri <- trimean(x)) [,1] [,2] [1,] 30.02940 24.16465 [2,] 32.14411 23.38888 [3,] 34.49692 22.55558 [4,] 37.05223 21.55332 [5,] 39.08704 20.57104 [6,] 40.10945 19.91081 [7,] 41.10781 19.15179 [8,] 42.14780 18.37949 [9,] 42.65825 17.90656 [10,] 43.48579 17.39918 [11,] 44.34887 16.88856 [12,] 45.44336 16.41691 [13,] 46.67893 15.84308 [14,] 48.06584 15.05988 [15,] 49.62304 14.09972 [16,] 52.64666 13.12856 [17,] 53.19132 13.06413 [18,] 53.86903 12.98018 [19,] 54.56425 12.84564 [20,] 54.64914 12.82551 [21,] 54.70850 12.70633 > (midr <- midrange(x)) [1] -2.517414 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 46.43862 52.64666 46.43862 52.64666 52.64666 46.43862 52.64666 49.62304 > postscript(file="/var/fisher/rcomp/tmp/1xvam1355829969.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)) Error: object 'ylimmin' not found Execution halted