R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(1687,1508,1507,1385,1632,1511,1559,1630,1579,1653,2152,2148,1752,1765,1717,1558,1575,1520,1805,1800,1719,2008,2242,2478,2030,1655,1693,1623,1805,1746,1795,1926,1619,1992,2233,2192,2080,1768,1835,1569,1976,1853,1965,1689,1778,1976,2397,2654,2097,1963,1677,1941,2003,1813,2012,1912,2084,2080,2118,2150,1608,1503,1548,1382,1731,1798,1779,1887,2004,2077,2092,2051,1577,1356,1652,1382,1519,1421,1442,1543,1656,1561,1905,2199,1473,1655,1407,1395,1530,1309,1526,1327,1627,1748,1958,2274,1648,1401,1411,1403,1394,1520,1528,1643,1515,1685,2000,2215,1956,1462,1563,1459,1446,1622,1657,1638,1643,1683,2050,2262,1813,1445,1762,1461,1556,1431,1427,1554,1645,1653,2016,2207,1665,1361,1506,1360,1453,1522,1460,1552,1548,1827,1737,1941,1474,1458,1542,1404,1522,1385,1641,1510,1681,1938,1868,1726,1456,1445,1456,1365,1487,1558,1488,1684,1594,1850,1998,2079,1494,1057,1218,1168,1236,1076,1174,1139,1427,1487,1483,1513,1357,1165,1282,1110,1297,1185,1222,1284,1444,1575,1737,1763) > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = '' > par9 = '' > par8 = '' > par7 = '' > par6 = '' > par5 = '' > par4 = '' > par3 = 'Pearson Chi-Squared' > par2 = '6' > par1 = '5' > ylimmax = '' > ylimmin = '' > ylab = '' > xlab = '' > main = '' > #'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] 1670.307 > sqrtn <- sqrt(length(x)) > (armse <- sd(x) / sqrtn) [1] 20.90087 > (armose <- arm / armse) [1] 79.91568 > (geo <- geomean(x)) [1] 1646.007 > (har <- harmean(x)) [1] 1622.258 > (qua <- quamean(x)) [1] 1695.1 > (win <- winmean(x)) [,1] [,2] [1,] 1669.490 20.678970 [2,] 1669.000 20.462043 [3,] 1667.531 20.067075 [4,] 1667.823 19.954726 [5,] 1667.380 19.864390 [6,] 1667.286 19.797484 [7,] 1667.031 19.648563 [8,] 1668.073 19.428304 [9,] 1667.885 19.351450 [10,] 1668.250 19.212305 [11,] 1668.594 18.593820 [12,] 1668.594 18.563244 [13,] 1669.339 18.450612 [14,] 1668.026 18.067624 [15,] 1667.792 17.712558 [16,] 1669.792 17.423981 [17,] 1669.172 17.326302 [18,] 1669.078 17.252962 [19,] 1669.177 17.243691 [20,] 1669.490 17.191887 [21,] 1671.130 16.995537 [22,] 1668.151 16.629674 [23,] 1668.391 16.582972 [24,] 1665.891 16.286014 [25,] 1665.240 15.969468 [26,] 1664.833 15.895314 [27,] 1665.115 15.756588 [28,] 1664.823 15.664732 [29,] 1664.823 15.634413 [30,] 1664.823 15.540576 [31,] 1665.146 15.448267 [32,] 1665.812 15.193569 [33,] 1664.094 14.800521 [34,] 1664.094 14.800521 [35,] 1662.818 14.519583 [36,] 1664.505 14.308493 [37,] 1663.927 14.172186 [38,] 1663.729 14.113156 [39,] 1660.682 13.785758 [40,] 1660.891 13.768713 [41,] 1661.745 13.579247 [42,] 1659.776 13.248511 [43,] 1656.641 12.921333 [44,] 1655.495 12.718696 [45,] 1651.510 12.270869 [46,] 1647.198 11.799287 [47,] 1643.771 11.422867 [48,] 1643.271 11.330139 [49,] 1642.250 10.733758 [50,] 1640.427 10.517530 [51,] 1639.099 9.978135 [52,] 1640.182 9.889842 [53,] 1637.974 9.689154 [54,] 1638.255 9.666238 [55,] 1638.542 9.397989 [56,] 1640.583 9.136244 [57,] 1640.583 8.985977 [58,] 1636.052 8.532637 [59,] 1636.052 8.481385 [60,] 1633.552 8.160171 [61,] 1632.917 8.052952 [62,] 1632.917 7.946436 [63,] 1633.245 7.866568 [64,] 1631.245 7.477930 > (tri <- trimean(x)) [,1] [,2] [1,] 1668.358 20.215706 [2,] 1667.202 19.718156 [3,] 1666.274 19.306197 [4,] 1665.837 19.017683 [5,] 1665.313 18.742518 [6,] 1664.872 18.470377 [7,] 1664.438 18.193199 [8,] 1664.034 17.924120 [9,] 1663.477 17.672552 [10,] 1662.930 17.414565 [11,] 1662.329 17.157412 [12,] 1661.679 16.963020 [13,] 1661.012 16.757809 [14,] 1660.262 16.550066 [15,] 1659.605 16.369610 [16,] 1658.950 16.212804 [17,] 1658.127 16.071995 [18,] 1657.327 15.929264 [19,] 1656.513 15.781579 [20,] 1655.671 15.622236 [21,] 1654.787 15.453936 [22,] 1653.777 15.288023 [23,] 1652.918 15.140867 [24,] 1652.021 14.984395 [25,] 1651.239 14.839921 [26,] 1650.471 14.708551 [27,] 1649.703 14.570901 [28,] 1648.897 14.431184 [29,] 1648.082 14.285402 [30,] 1647.242 14.127710 [31,] 1646.377 13.961991 [32,] 1645.469 13.786971 [33,] 1644.500 13.614562 [34,] 1643.581 13.457148 [35,] 1642.631 13.282896 [36,] 1641.708 13.113720 [37,] 1640.678 12.942136 [38,] 1639.638 12.762943 [39,] 1638.570 12.568366 [40,] 1637.598 12.381520 [41,] 1636.582 12.173937 [42,] 1635.491 11.957476 [43,] 1634.443 11.745895 [44,] 1633.490 11.540218 [45,] 1632.549 11.327973 [46,] 1631.740 11.133049 [47,] 1631.082 10.959143 [48,] 1630.542 10.798665 [49,] 1630.000 10.625044 [50,] 1629.478 10.483982 [51,] 1629.011 10.343604 [52,] 1628.580 10.233707 [53,] 1628.081 10.113761 [54,] 1627.655 9.995029 [55,] 1627.195 9.858490 [56,] 1626.700 9.726585 [57,] 1626.090 9.597619 [58,] 1625.447 9.461416 [59,] 1624.973 9.353698 [60,] 1624.472 9.230062 [61,] 1624.057 9.120720 [62,] 1623.647 9.001238 [63,] 1623.212 8.869200 [64,] 1622.734 8.718431 > (midr <- midrange(x)) [1] 1855.5 > midm <- array(NA,dim=8) > for (j in 1:8) midm[j] <- midmean(x,j) > midm [1] 1628.794 1630.542 1628.794 1630.542 1630.542 1628.794 1630.542 1631.082 > postscript(file="/var/www/html/rcomp/tmp/11kph1290722438.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/2prhd1290722438.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 > > #Note: the /var/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > 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/39u8c1290722438.tab") > > try(system("convert tmp/11kph1290722438.ps tmp/11kph1290722438.png",intern=TRUE)) character(0) > try(system("convert tmp/2prhd1290722438.ps tmp/2prhd1290722438.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.954 0.361 2.146