Aaron
Aaron

Reputation: 2374

scipy gamma distribution doesn't match formula on wikipedia

According to Wikipedia the expected value of a Gamma distribution is k * theta. However, when I plug that into the CDF for the gamma distribution I don't get 0.5 as expected.

k = 1.5
theta = 2.1
expected_value = k * theta
scipy.stats.gamma.cdf(expected_value, k, scale=theta)

The result of the last line is 0.6083 instead of 0.5 as expected.

Upvotes: -1

Views: 285

Answers (1)

Warren Weckesser
Warren Weckesser

Reputation: 114956

The value of the CDF at the median is 0.5. k*theta gives the mean (i.e. the expected value), not the median.

In [8]: from scipy.stats import gamma

In [9]: k = 1.5

In [10]: theta = 2.1

In [11]: med = gamma.median(k, scale=theta)

In [12]: med
Out[12]: 2.4842725785941049

In [13]: gamma.cdf(med, k, scale=theta)
Out[13]: 0.49999999999999994

Upvotes: 3

Related Questions