[R] trimmed mean in R seems to round the trimming fraction

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Sun Sep 18 22:11:11 CEST 2005



VINOD at FORDHAM.EDU wrote:
> 
> 
> subject: trimmed mean in R seems to round the trimming fraction
> to r-help at stat.math.ethz.ch.
> 
> Consider the following example of 10 numbers.  10% trimmed mean is correct
> but you can see that the result is the same for many trimming fractions
> till 0.20!
> 
> For example 13% trimmed mean should use interpolation of second and
> eighth ordered observation.  R does not seem to do this.
> The correct 13% trimmed mean is the average of 7.4 middle observations
> (28+46+50+52+54+63+82+64.4)/7.4
> Answer=(439.4)/7.4= 59.3784
> 
> 
> 
>>z=c(23, 40,     46,      50,      52,      54,    63,    82,92,98)
>>mean(z, trim=0.10)
> 
> [1] 59.875
> 
>>mean(z, trim=0.13) # wrong result is  59.875
> 
> [1] 59.875
> 
>>mean(z, trim=0.15)
> 
> [1] 59.875
> 
>>mean(z, trim=0.18)
> 
> [1] 59.875
> 
>>mean(z, trim=0.1999999)
> 
> [1] 59.875
> 
>>mean(z, trim=0.20)
> 
> [1] 57.83333
> 
>>mean(z, trim=0.40)
> 
> [1] 53
> 
> 

Hi,

The "trim" argument works as documented. Did you read ?mean:

      If 'trim' is non-zero, a symmetrically trimmed mean is computed
      with a fraction of 'trim' observations deleted from each end
      before the mean is computed.

Also, I don't recall ever learning your method for trimmed mean, but R 
is a programming language and you can always write your own trimmed mean 
function.

HTH,

--sundar




More information about the R-help mailing list