0
$\begingroup$

I calculated the theoretical mode for X ~ Expo(lambda) and got it as 0. However, when I simulated the scenario in R, I am getting some values. My code is shown below:

sample_mode <- function(x) {
  t <- table(x)
  m <- max(t)
  as.numeric(names(t[t==m]))
}
simfunc <-function(){
  x <- rexp(10000,2)
  median <- median(x)
  mode <- sample_mode(x)

  cat("The median is", median)
  cat("The mode is", mode)
}

The median matches, but I am getting a vector of values for the mode.

$\endgroup$
3
  • 2
    $\begingroup$ Why don't you look at the data? A quick graph, such as a histogram, ought to answer your question immediately. $\endgroup$
    – whuber
    Nov 4, 2017 at 19:21
  • $\begingroup$ I had a look at the histogram and it makes sense, but it my theoretical mode wrongly calculated then? $\endgroup$
    – user180844
    Nov 4, 2017 at 19:23
  • $\begingroup$ It's the way you're calculating the mode in your sample that's the problem. For some similar points to the ones in Tim's answer, also see the discussion of sample mode here (though the mention of smoothing won't be much use when the mode is at the boundary, unless the smoothing also takes account of that) $\endgroup$
    – Glen_b
    Nov 4, 2017 at 23:42

1 Answer 1

4
$\begingroup$

Exponential distribution is a distribution for a continuous random variable. For continuous random variables $\Pr(X=x)=0$ for any $x$, so for your variable you would expect each of the distinct values not more then once in your sample, so your function for calculating mode would not produce any reasonable result. Here you can find some hints how you could calculate mode for continuous variable.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.