0

I am doing a histogram of means, where I sample 25 observations 1000 times. Everything works well apart from the fact that I keep getting a different number of bins.

Here's my code:

samp_25hist<-replicate(1000, {
   samp<-sample(df, 25, replace = F)
   mean(samp)
})
hist(samp_25hist, freq = F, breaks = 12,
     main = "Histogram of Means",
     ylab = "Y",
     xlab = "X",
     col = "orange")

I tried defining the number of bins, as you can see from the code, but I keep getting either 12, 13, or 14 bins.

Can anyone help me to sort this out?

Thanks!

  • Please provide `dput(df)` in case you don't mean the density distribution function `df()`. – jay.sf Jun 10 '20 at 16:40
  • You are not defining the number of bins, but rather the number of break points that distinguish the bins. Given the small sample size relative to the number of break points, many if not most of your histograms will have bins with 0 observations. – lmo Jun 10 '20 at 16:44
  • 1
    Does this answer your question? [Exact number of bins in Histogram in R](https://stackoverflow.com/questions/16931895/exact-number-of-bins-in-histogram-in-r) – hamagust Jun 10 '20 at 16:44

0 Answers0