# Examining the relative efficiency of the trimmed mean

Using the following reference A survey of sampling from contaminated distributions, I am trying to investigate the relative efficiency (RE) for the mean vs the trimmed mean, given the following contaminated exponential distribution \begin{align} F(x) = F_\lambda(x) + F_{k\lambda} (x) \end{align}

When trying to simulate the RE for the this distribution in R for trim = 0, 0.01, 0.03 and 0.05, I am getting the following plots

Unfortunately, like the reference above, I suspect that the plots should crossover each other at some point, but this is not happening.

So far I have come up with the following code

number.of.simulations <- 100
n <- 1000
error <- 0

#using random uniform variables to create exponential distribution
uniform.variables <- runif(n)

no.trim.mean <- trim.mean <- rep(0,number.of.simulations)

uncensored <- rep(0,n)
fraction.of.trim <- seq(from = 0 , to = 0.1, by = 0.001)

amount.trim <- c(0, 0.01, 0.03, 0.05)
relative.efficiency <- matrix(
NA,nrow= length(fraction.of.trim) , ncol = length(amount.trim)
)

for(i in 1:length(amount.trim)){
for(j in 1:length(fraction.of.trim)){
uncensored <- matrix(
(uniform.variables <= 1 - error) * rexp(n = n * number.of.simulations) +
(uniform.variables > 1  - error) * rexp(n = n * number.of.simulations),
ncol = number.of.simulations
)
no.trim.mean <- apply(uncensored, 2, mean, trim = amount.trim[i])
trim.mean <- apply(uncensored, 2, mean, trim = fraction.of.trim[j])
relative.efficiency[j,i] <- mean((no.trim.mean - 1)^2)/mean((trim.mean - 1)^2)
}
}


What is it that I am missing or doing wrong with this simulation?

• To begin with, you do not appear to be generating from an exponential distribution. (To do that, you would need to compute the logarithms of the reciprocals of the uniform variates.) Why not use the built-in generators such as rgamma? – whuber May 2 '13 at 16:28
• The uncensored variable contains the contaminated exponential distribution. The uniform variates are there to help generate the simulated data for the contaminated distribution. Well, at least that is what I thought I was doing. – user7045 May 2 '13 at 16:43
• Draw a histogram of some of your data to see what they look like. – whuber May 2 '13 at 17:25
• @whuber +1 ... looking at what you're actually producing should be a mantra when doing simulation. I wish there was a way I could spend reputation in order to give additional upvotes to that comment. – Glen_b May 3 '13 at 0:25