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.