Reputation: 4608
I want to calculate sum(e-λ λi/i!) where i=197,..., ∞ and λ=421.41
using scipy.
I went through the scipy documentation of scipy.stats.poisson
which can be found in https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html
However, they have multiple methods for scipy.stats.poisson
and bit confused in picking the method that suits me most.
e.g.,
rvs(mu, loc=0, size=1, random_state=None) Random variates.
pmf(k, mu, loc=0) Probability mass function.
logpmf(k, mu, loc=0) Log of the probability mass function.
cdf(k, mu, loc=0) Cumulative distribution function.
logcdf(k, mu, loc=0) Log of the cumulative distribution function.
sf(k, mu, loc=0) Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
logsf(k, mu, loc=0) Log of the survival function.
ppf(q, mu, loc=0) Percent point function (inverse of cdf — percentiles).
isf(q, mu, loc=0) Inverse survival function (inverse of sf).
stats(mu, loc=0, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
entropy(mu, loc=0) (Differential) entropy of the RV.
expect(func, args=(mu,), loc=0, lb=None, ub=None, conditional=False) Expected value of a function (of one argument) with respect to the distribution.
median(mu, loc=0) Median of the distribution.
mean(mu, loc=0) Mean of the distribution.
var(mu, loc=0) Variance of the distribution.
std(mu, loc=0) Standard deviation of the distribution.
interval(alpha, mu, loc=0) Endpoints of the range that contains alpha percent of the distribution
Currently, I am using sf(197, 421.41, loc=0)
. However, I am not very sure if I have picked the right method. Please let me know your thoughts.
I am happy to provide more details if needed.
Upvotes: 0
Views: 1750
Reputation: 4343
The exponential factor (e-λ λi/i!) is the probability density (mass) function of the poisson distribution, while the sum is the cumulative probability (distribution) function. Methods correspond to .pmf
and .cdf
respectively.
Example:
from scipy.stats import poisson
k, mu = 1, 2
print(poisson.pmf(k, mu)) #k, mu
print(np.exp(-mu) * mu**k / np.math.factorial(k))
print(poisson.cdf(k, mu))
print(sum(np.exp(-mu) * mu**j / np.math.factorial(j) for j in range(k + 1)))
>>0.2706705664732254
0.2706705664732254
0.40600584970983794
0.4060058497098381
In your case:
k, mu = 197, 421.41
print(1 - poisson.cdf(k - 1, mu))
Note that it will give 1.0
due to numerical precision
Upvotes: 1