Skip to content

Instantly share code, notes, and snippets.

@gatoravi
Last active May 29, 2018 20:05
Show Gist options
  • Save gatoravi/b23db7deca3ef3b9ce3b63fc746ee988 to your computer and use it in GitHub Desktop.
Save gatoravi/b23db7deca3ef3b9ce3b63fc746ee988 to your computer and use it in GitHub Desktop.
Estimate parameters of a negative binomial distribution using method of moments
> counts <- rnbinom(1000, size = 10, p = 0.1)
> mu <- mean(counts)
> p <- mu/var(counts)
> r <- mu ^ 2/(var(counts) - mu)
> hist(counts, freq = F)
> curve(dnbinom(x, size = r, prob = p), from = 0, to = max(counts), n = max(counts) + 1)
@gatoravi
Copy link
Author

Refer to this link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment