General outline and example R code for estimating parameters of a compound distribution, such as a Poisson-Gamma (Negative Binomial) distribution, which is common in modeling count data with overdispersion often seen in clinical coding.
Suppose your data are counts of clinical codes per patient, and you hypothesize the data follow a Negative Binomial distribution, which is a compound distribution of Poisson with Gamma mixing.
1. Simulate or load your data
# Example data: counts of clinical codes per patient