Hướng dẫn multivariate poisson distribution python

I would like to draw N times from a bivariate Possion distribution. Is there a Python module similar to the package bivpois in R?

In Python, I only know the libraries scipy.stats.poisson and numpy.random.possion which allow me to make draws from a univariate Poisson distribution depending on a single parameter lambda, but not from a bivariate or multivariate.

asked Mar 2, 2021 at 16:07

You can do it by yourself pretty easily since I don't see any built-in method:

//en.wikipedia.org/wiki/Poisson_distribution#Bivariate_Poisson_distribution

Steps:

  1. Generate 3 independent Poisson variables Z_i with parameters lambda_i
  2. Generate two P_i = Z_i + Z_3 for i = 1, 2 which follows Poi[lambda_i + lambda_3]

Code:

import numpy
lam1 = 1
lam2 = 2
lam3 = 3
#wrap next part in a loop to generate more than 1 sample
a = np.random.poisson[lam1]
b = np.random.poisson[lam2]
c = np.random.poisson[lam3]
bivariate1 = a + c #follows Poi[lam1+lam3]
bivariate2 = b + c #follows Poi[lam2+lam3]

answered Mar 2, 2021 at 16:13

user15270287user15270287

1,0933 silver badges11 bronze badges

0

Not the answer you're looking for? Browse other questions tagged python numpy scipy poisson or ask your own question.

The Poisson distribution describes the probability of obtaining k successes during a given time interval.

If a random variable X follows a Poisson distribution, then the probability that X = k successes can be found by the following formula:

P[X=k] = λk * e– λ / k!

where:

  • λ: mean number of successes that occur during a specific interval
  • k: number of successes
  • e: a constant equal to approximately 2.71828

This tutorial explains how to use the Poisson distribution in Python.

How to Generate a Poisson Distribution

You can use the poisson.rvs[mu, size] function to generate random values from a Poisson distribution with a specific mean value and sample size:

from scipy.stats import poisson

#generate random values from Poisson distribution with mean=3 and sample size=10
poisson.rvs[mu=3, size=10]

array[[2, 2, 2, 0, 7, 2, 1, 2, 5, 5]]

How to Calculate Probabilities Using a Poisson Distribution

You can use the poisson.pmf[k, mu] and poisson.cdf[k, mu] functions to calculate probabilities related to the Poisson distribution.

Example 1: Probability Equal to Some Value

A store sells 3 apples per day on average. What is the probability that they will sell 5 apples on a given day? 

from scipy.stats import poisson

#calculate probability
poisson.pmf[k=5, mu=3]

0.100819

The probability that the store sells 5 apples in a given day is 0.100819.

Example 2: Probability Less than Some Value

A certain store sells seven footballs per day on average. What is the probability that this store sells four or less footballs in a given day?

from scipy.stats import poisson

#calculate probability
poisson.cdf[k=4, mu=7]

0.172992

The probability that the store sells four or less footballs in a given day is 0.172992.

Example 3: Probability Greater than Some Value

A certain store sells 15 cans of tuna per day on average. What is the probability that this store sells more than 20 cans of tuna in a given day?

from scipy.stats import poisson

#calculate probability
1-poisson.cdf[k=20, mu=15]

0.082971

The probability that the store sells more than 20 cans of tuna in a given day is 0.082971.

How to Plot a Poisson Distribution

You can use the following syntax to plot a Poisson distribution with a given mean:

from scipy.stats import poisson
import matplotlib.pyplot as plt

#generate Poisson distribution with sample size 10000
x = poisson.rvs[mu=3, size=10000]

#create plot of Poisson distribution
plt.hist[x, density=True, edgecolor='black']

Additional Resources

An Introduction to the Poisson Distribution
5 Real-Life Examples of the Poisson Distribution
Online Poisson Distribution Calculator

Chủ Đề