 | :: Central Tendency - Free Statistics Software (Calculator) :: | |
|
All rights reserved. The non-commercial (academic) use of this software is free of charge. The only thing that is asked in return is to cite this software when results are used in publications.
This free online software (calculator) computes the following statistics: arithmetic mean, geometric mean, harmonic mean, quadratic mean, winsorized mean, trimmed mean, median, midrange, and midmean.
Click here to edit the underlying code of this R Module.Enter (or paste) your data delimited by hard returns. Click here to edit the underlying code of this R Module.
| Cite this software as: | | Wessa, P., (2008), Central Tendency (v1.0.3) in Free Statistics Software (v1.1.22-r6), Office for Research Development and Education, URL http://www.wessa.net/rwasp_centraltendency.wasp/ | | | The R code is based on : | | | Borghers, E, and P. Wessa, Statistics - Econometrics - Forecasting, Office for Research Development and Education, http://www.xycoon.com/ | | | | | | | | | | | | | |
|
| Source code of R module | | 1 | geomean <- function(x) { | | 2 | return(exp(mean(log(x)))) | | 3 | } | | 4 | harmean <- function(x) { | | 5 | return(1/mean(1/x)) | | 6 | } | | 7 | quamean <- function(x) { | | 8 | return(sqrt(mean(x*x))) | | 9 | } | | 10 | winmean <- function(x) { | | 11 | x <-sort(x[!is.na(x)]) | | 12 | n<-length(x) | | 13 | denom <- 3 | | 14 | nodenom <- n/denom | | 15 | if (nodenom>40) denom <- n/40 | | 16 | sqrtn = sqrt(n) | | 17 | roundnodenom = floor(nodenom) | | 18 | win <- array(NA,dim=c(roundnodenom,2)) | | 19 | for (j in 1:roundnodenom) { | | 20 | win[j,1] <- (j*x[j+1]+sum(x[(j+1):(n-j)])+j*x[n-j])/n | | 21 | win[j,2] <- sd(c(rep(x[j+1],j),x[(j+1):(n-j)],rep(x[n-j],j)))/sqrtn | | 22 | } | | 23 | return(win) | | 24 | } | | 25 | trimean <- function(x) { | | 26 | x <-sort(x[!is.na(x)]) | | 27 | n<-length(x) | | 28 | denom <- 3 | | 29 | nodenom <- n/denom | | 30 | if (nodenom>40) denom <- n/40 | | 31 | sqrtn = sqrt(n) | | 32 | roundnodenom = floor(nodenom) | | 33 | tri <- array(NA,dim=c(roundnodenom,2)) | | 34 | for (j in 1:roundnodenom) { | | 35 | tri[j,1] <- mean(x,trim=j/n) | | 36 | tri[j,2] <- sd(x[(j+1):(n-j)]) / sqrt(n-j*2) | | 37 | } | | 38 | return(tri) | | 39 | } | | 40 | midrange <- function(x) { | | 41 | return((max(x)+min(x))/2) | | 42 | } | | 43 | q1 <- function(data,n,p,i,f) { | | 44 | np <- n*p; | | 45 | i <<- floor(np) | | 46 | f <<- np - i | | 47 | qvalue <- (1-f)*data[i] + f*data[i+1] | | 48 | } | | 49 | q2 <- function(data,n,p,i,f) { | | 50 | np <- (n+1)*p | | 51 | i <<- floor(np) | | 52 | f <<- np - i | | 53 | qvalue <- (1-f)*data[i] + f*data[i+1] | | 54 | } | | 55 | q3 <- function(data,n,p,i,f) { | | 56 | np <- n*p | | 57 | i <<- floor(np) | | 58 | f <<- np - i | | 59 | if (f==0) { | | 60 | qvalue <- data[i] | | 61 | } else { | | 62 | qvalue <- data[i+1] | | 63 | } | | 64 | } | | 65 | q4 <- function(data,n,p,i,f) { | | 66 | np <- n*p | | 67 | i <<- floor(np) | | 68 | f <<- np - i | | 69 | if (f==0) { | | 70 | qvalue <- (data[i]+data[i+1])/2 | | 71 | } else { | | 72 | qvalue <- data[i+1] | | 73 | } | | 74 | } | | 75 | q5 <- function(data,n,p,i,f) { | | 76 | np <- (n-1)*p | | 77 | i <<- floor(np) | | 78 | f <<- np - i | | 79 | if (f==0) { | | 80 | qvalue <- data[i+1] | | 81 | } else { | | 82 | qvalue <- data[i+1] + f*(data[i+2]-data[i+1]) | | 83 | } | | 84 | } | | 85 | q6 <- function(data,n,p,i,f) { | | 86 | np <- n*p+0.5 | | 87 | i <<- floor(np) | | 88 | f <<- np - i | | 89 | qvalue <- data[i] | | 90 | } | | 91 | q7 <- function(data,n,p,i,f) { | | 92 | np <- (n+1)*p | | 93 | i <<- floor(np) | | 94 | f <<- np - i | | 95 | if (f==0) { | | 96 | qvalue <- data[i] | | 97 | } else { | | 98 | qvalue <- f*data[i] + (1-f)*data[i+1] | | 99 | } | | 100 | } | | 101 | q8 <- function(data,n,p,i,f) { | | 102 | np <- (n+1)*p | | 103 | i <<- floor(np) | | 104 | f <<- np - i | | 105 | if (f==0) { | | 106 | qvalue <- data[i] | | 107 | } else { | | 108 | if (f == 0.5) { | | 109 | qvalue <- (data[i]+data[i+1])/2 | | 110 | } else { | | 111 | if (f < 0.5) { | | 112 | qvalue <- data[i] | | 113 | } else { | | 114 | qvalue <- data[i+1] | | 115 | } | | 116 | } | | 117 | } | | 118 | } | | 119 | midmean <- function(x,def) { | | 120 | x <-sort(x[!is.na(x)]) | | 121 | n<-length(x) | | 122 | if (def==1) { | | 123 | qvalue1 <- q1(x,n,0.25,i,f) | | 124 | qvalue3 <- q1(x,n,0.75,i,f) | | 125 | } | | 126 | if (def==2) { | | 127 | qvalue1 <- q2(x,n,0.25,i,f) | | 128 | qvalue3 <- q2(x,n,0.75,i,f) | | 129 | } | | 130 | if (def==3) { | | 131 | qvalue1 <- q3(x,n,0.25,i,f) | | 132 | qvalue3 <- q3(x,n,0.75,i,f) | | 133 | } | | 134 | if (def==4) { | | 135 | qvalue1 <- q4(x,n,0.25,i,f) | | 136 | qvalue3 <- q4(x,n,0.75,i,f) | | 137 | } | | 138 | if (def==5) { | | 139 | qvalue1 <- q5(x,n,0.25,i,f) | | 140 | qvalue3 <- q5(x,n,0.75,i,f) | | 141 | } | | 142 | if (def==6) { | | 143 | qvalue1 <- q6(x,n,0.25,i,f) | | 144 | qvalue3 <- q6(x,n,0.75,i,f) | | 145 | } | | 146 | if (def==7) { | | 147 | qvalue1 <- q7(x,n,0.25,i,f) | | 148 | qvalue3 <- q7(x,n,0.75,i,f) | | 149 | } | | 150 | if (def==8) { | | 151 | qvalue1 <- q8(x,n,0.25,i,f) | | 152 | qvalue3 <- q8(x,n,0.75,i,f) | | 153 | } | | 154 | midm <- 0 | | 155 | myn <- 0 | | 156 | roundno4 <- round(n/4) | | 157 | round3no4 <- round(3*n/4) | | 158 | for (i in 1:n) { | | 159 | if ((x[i]>=qvalue1) & (x[i]<=qvalue3)){ | | 160 | midm = midm + x[i] | | 161 | myn = myn + 1 | | 162 | } | | 163 | } | | 164 | midm = midm / myn | | 165 | return(midm) | | 166 | } | | 167 | (arm <- mean(x)) | | 168 | sqrtn <- sqrt(length(x)) | | 169 | (armse <- sd(x) / sqrtn) | | 170 | (armose <- arm / armse) | | 171 | (geo <- geomean(x)) | | 172 | (har <- harmean(x)) | | 173 | (qua <- quamean(x)) | | 174 | (win <- winmean(x)) | | 175 | (tri <- trimean(x)) | | 176 | (midr <- midrange(x)) | | 177 | midm <- array(NA,dim=8) | | 178 | for (j in 1:8) midm[j] <- midmean(x,j) | | 179 | midm | | 180 | bitmap(file="test1.png") | | 181 | lb <- win[,1] - 2*win[,2] | | 182 | ub <- win[,1] + 2*win[,2] | | 183 | 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)) | | 184 | lines(ub,lty=3) | | 185 | lines(lb,lty=3) | | 186 | grid() | | 187 | dev.off() | | 188 | bitmap(file="test2.png") | | 189 | lb <- tri[,1] - 2*tri[,2] | | 190 | ub <- tri[,1] + 2*tri[,2] | | 191 | 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)) | | 192 | lines(ub,lty=3) | | 193 | lines(lb,lty=3) | | 194 | grid() | | 195 | dev.off() | | 196 | load(file="createtable") | | 197 | a<-table.start() | | 198 | a<-table.row.start(a) | | 199 | a<-table.element(a,"Central Tendency - Ungrouped Data",4,TRUE) | | 200 | a<-table.row.end(a) | | 201 | a<-table.row.start(a) | | 202 | a<-table.element(a,"Measure",header=TRUE) | | 203 | a<-table.element(a,"Value",header=TRUE) | | 204 | a<-table.element(a,"S.E.",header=TRUE) | | 205 | a<-table.element(a,"Value/S.E.",header=TRUE) | | 206 | a<-table.row.end(a) | | 207 | a<-table.row.start(a) | | 208 | 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) | | 209 | a<-table.element(a,arm) | | 210 | 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")) | | 211 | a<-table.element(a,armose) | | 212 | a<-table.row.end(a) | | 213 | a<-table.row.start(a) | | 214 | 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) | | 215 | a<-table.element(a,geo) | | 216 | a<-table.element(a,"") | | 217 | a<-table.element(a,"") | | 218 | a<-table.row.end(a) | | 219 | a<-table.row.start(a) | | 220 | 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) | | 221 | a<-table.element(a,har) | | 222 | a<-table.element(a,"") | | 223 | a<-table.element(a,"") | | 224 | a<-table.row.end(a) | | 225 | a<-table.row.start(a) | | 226 | 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) | | 227 | a<-table.element(a,qua) | | 228 | a<-table.element(a,"") | | 229 | a<-table.element(a,"") | | 230 | a<-table.row.end(a) | | 231 | for (j in 1:length(win[,1])) { | | 232 | a<-table.row.start(a) | | 233 | mylabel <- paste("Winsorized Mean (",j) | | 234 | mylabel <- paste(mylabel,"/") | | 235 | mylabel <- paste(mylabel,length(win[,1])) | | 236 | mylabel <- paste(mylabel,")") | | 237 | a<-table.element(a,hyperlink("http://www.xycoon.com/winsorized_mean.htm", mylabel, "click to view the definition of the Winsorized Mean"),header=TRUE) | | 238 | a<-table.element(a,win[j,1]) | | 239 | a<-table.element(a,win[j,2]) | | 240 | a<-table.element(a,win[j,1]/win[j,2]) | | 241 | a<-table.row.end(a) | | 242 | } | | 243 | for (j in 1:length(tri[,1])) { | | 244 | a<-table.row.start(a) | | 245 | mylabel <- paste("Trimmed Mean (",j) | | 246 | mylabel <- paste(mylabel,"/") | | 247 | mylabel <- paste(mylabel,length(tri[,1])) | | 248 | mylabel <- paste(mylabel,")") | | 249 | a<-table.element(a,hyperlink("http://www.xycoon.com/arithmetic_mean.htm", mylabel, "click to view the definition of the Trimmed Mean"),header=TRUE) | | 250 | a<-table.element(a,tri[j,1]) | | 251 | a<-table.element(a,tri[j,2]) | | 252 | a<-table.element(a,tri[j,1]/tri[j,2]) | | 253 | a<-table.row.end(a) | | 254 | } | | 255 | a<-table.row.start(a) | | 256 | a<-table.element(a,hyperlink("http://www.xycoon.com/median_1.htm", "Median", "click to view the definition of the Median"),header=TRUE) | | 257 | a<-table.element(a,median(x)) | | 258 | a<-table.element(a,"") | | 259 | a<-table.element(a,"") | | 260 | a<-table.row.end(a) | | 261 | a<-table.row.start(a) | | 262 | a<-table.element(a,hyperlink("http://www.xycoon.com/midrange.htm", "Midrange", "click to view the definition of the Midrange"),header=TRUE) | | 263 | a<-table.element(a,midr) | | 264 | a<-table.element(a,"") | | 265 | a<-table.element(a,"") | | 266 | a<-table.row.end(a) | | 267 | a<-table.row.start(a) | | 268 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 269 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_1.htm","Weighted Average at Xnp",""),sep=" - ") | | 270 | a<-table.element(a,mylabel,header=TRUE) | | 271 | a<-table.element(a,midm[1]) | | 272 | a<-table.element(a,"") | | 273 | a<-table.element(a,"") | | 274 | a<-table.row.end(a) | | 275 | a<-table.row.start(a) | | 276 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 277 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_2.htm","Weighted Average at X(n+1)p",""),sep=" - ") | | 278 | a<-table.element(a,mylabel,header=TRUE) | | 279 | a<-table.element(a,midm[2]) | | 280 | a<-table.element(a,"") | | 281 | a<-table.element(a,"") | | 282 | a<-table.row.end(a) | | 283 | a<-table.row.start(a) | | 284 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 285 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_3.htm","Empirical Distribution Function",""),sep=" - ") | | 286 | a<-table.element(a,mylabel,header=TRUE) | | 287 | a<-table.element(a,midm[3]) | | 288 | a<-table.element(a,"") | | 289 | a<-table.element(a,"") | | 290 | a<-table.row.end(a) | | 291 | a<-table.row.start(a) | | 292 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 293 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_4.htm","Empirical Distribution Function - Averaging",""),sep=" - ") | | 294 | a<-table.element(a,mylabel,header=TRUE) | | 295 | a<-table.element(a,midm[4]) | | 296 | a<-table.element(a,"") | | 297 | a<-table.element(a,"") | | 298 | a<-table.row.end(a) | | 299 | a<-table.row.start(a) | | 300 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 301 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_5.htm","Empirical Distribution Function - Interpolation",""),sep=" - ") | | 302 | a<-table.element(a,mylabel,header=TRUE) | | 303 | a<-table.element(a,midm[5]) | | 304 | a<-table.element(a,"") | | 305 | a<-table.element(a,"") | | 306 | a<-table.row.end(a) | | 307 | a<-table.row.start(a) | | 308 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 309 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_6.htm","Closest Observation",""),sep=" - ") | | 310 | a<-table.element(a,mylabel,header=TRUE) | | 311 | a<-table.element(a,midm[6]) | | 312 | a<-table.element(a,"") | | 313 | a<-table.element(a,"") | | 314 | a<-table.row.end(a) | | 315 | a<-table.row.start(a) | | 316 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 317 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_7.htm","True Basic - Statistics Graphics Toolkit",""),sep=" - ") | | 318 | a<-table.element(a,mylabel,header=TRUE) | | 319 | a<-table.element(a,midm[7]) | | 320 | a<-table.element(a,"") | | 321 | a<-table.element(a,"") | | 322 | a<-table.row.end(a) | | 323 | a<-table.row.start(a) | | 324 | mymid <- hyperlink("http://www.xycoon.com/midmean.htm", "Midmean", "click to view the definition of the Midmean") | | 325 | mylabel <- paste(mymid,hyperlink("http://www.xycoon.com/method_8.htm","MS Excel (old versions)",""),sep=" - ") | | 326 | a<-table.element(a,mylabel,header=TRUE) | | 327 | a<-table.element(a,midm[8]) | | 328 | a<-table.element(a,"") | | 329 | a<-table.element(a,"") | | 330 | a<-table.row.end(a) | | 331 | a<-table.row.start(a) | | 332 | a<-table.element(a,"Number of observations",header=TRUE) | | 333 | a<-table.element(a,length(x)) | | 334 | a<-table.element(a,"") | | 335 | a<-table.element(a,"") | | 336 | a<-table.row.end(a) | | 337 | a<-table.end(a) | | 338 | table.save(a,file="mytable.tab") |
|
To cite Wessa.net in publications use: Wessa, P. (2008), Free Statistics Software, Office for Research Development and Education, version 1.1.22-r6, URL http://www.wessa.net/
© Resa
R&D, and the 'Office for Research, Development, and Education' - All rights reserved. Academic license for non-commercial use only. This website is an intellectual
and physical property of Resa R&D. This includes: html content,
graphical illustrations (gif files), computer software, online or electronic
documentation, associated media, and printed materials. The free use of the scientific content, services, and applications in this website is
granted for non commercial use only. In any case,
the source (url) should always be clearly displayed. Under no circumstances are
you allowed to reproduce, copy or redistribute the design, layout, or any
content of this website (for commercial use) including any materials contained
herein without the express written permission of Resa R&D or the Office for Research, Development, and Education.
Information provided
on this web site is provided "AS IS" without warranty of any kind, either
express or implied, including, without limitation, warranties of
merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information
and periodically update the information, and software without notice. However, Resa
R&D makes no warranties or representations
as to the accuracy or completeness of such information (or software), and it assumes no
liability or responsibility for errors or omissions in the content of this web
site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and
under no legal theory shall Resa R&D be liable to you or any other
person for any direct, indirect, special, incidental, exemplary, or
consequential damages arising from your access to, or use of, this web site.
Software Version : 1.1.22-r6 Algorithms & Software : Prof. dr. P. Wessa Facilities : Resa R&D - Office for Research, Development, and Education Server : www.wessa.net
Comments, Feedback & Errors | Privacy Policy | Statistics Resources | Wessa.net Home
|
|
|