Skip to content

Instantly share code, notes, and snippets.

@aodin aodin/gamma.jl
Created Apr 26, 2016

What would you like to do?
Plotting the Gamma distribution sampling from it as a normalized histogram
# Plotting the Gamma distribution and sample as a normalize histogram
using Distributions
using Gadfly
pdf(d::Gamma, x) = (x ^ (d.α - 1) * e ^ (-x / d.α)) / (d.θ ^ d.α * gamma(d.α))
n = 500
g = Gamma(2., 2.)
r = rand(g, n)
bins, counts = hist(r, 100)
# normalize on area of the histogram
counts_norm = counts / sum(counts * step(bins))
layer(x=bins, y=[pdf(g, l + step(bins) / 2.) for l in bins], Geom.line, Theme(default_color=colorant"black")),
layer(x=bins[1:end-1], y=counts_norm,,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.