Computational Statistics

Chapter 12 - Probability Density Estimation

Dr. Mehdi Maadooliat

Marquette University
MATH 4750 - Spring 2025

Probability Density Estimation

Histogram Density Estimates

  • Introduction to density estimation using histograms
  • Example: Histogram density estimates using Sturges’ Rule
set.seed(12345)
n <- 25
x <- rnorm(n)

# Calculate breaks according to Sturges' Rule
nclass <- ceiling(1 + log2(n))
cwidth <- diff(range(x) / nclass)
breaks <- min(x) + cwidth * 0:nclass

# Default histogram
h.default <- hist(x, freq = FALSE, xlab = "default", main = "Histogram: Default")

Kernel Density Estimation

  • Introduction to kernel density estimation (KDE)
  • Example: Applying KDE to data
# Kernel density estimate
dens <- density(x)
plot(dens, main = "Kernel Density Estimate", col = "blue", lwd = 2)

Visualizing Kernel Density

# Overlay histogram and KDE
hist(x, freq = FALSE, col = "lightgray", border = "white", main = "Histogram with KDE")
lines(dens, col = "red", lwd = 2)

Conclusion

  • Recap of histogram density estimation and kernel density estimation
  • Practice: Apply density estimation techniques to other datasets