1

I am trying to work with some hypergeometric and binomial random variables, and so I am looking at the scipy.stats functionality. But I'm confused what scipy.stats.binom() and script.stats.hypergeom() functions actually do. Do they implicitly create a PMF for with given parameters, which we then access with the stats.pmf() function, or do they define a function from the sample space to the numerical quantities we define? The last is what a random variable actually does, but I haven't passed a sample space to the binom or hypergeom functions, so I'm confused about what they are actually doing. The reference manual doesn't clear things up.

Thank you for any help.

Dan Öz
  • 319
  • 1
  • 8

1 Answers1

0

According to the documentation:

A binomial discrete random variable.

As an instance of the rv_discrete class, binom object inherits from it a collection of generic methods (see below for the full list), and completes them with details specific for this particular distribution.

Some of these methods are pmf(k, n, p, loc=0), median(n, p, loc=0), and std(n, p, loc=0).

Alternatively, the distribution object can be called (as a function) to fix the shape and location. This returns a “frozen” RV object holding the given parameters fixed.

So that

from scipy.stats import binom

n,p = 5, 0.4
rv = binom(n, p)
rv.rvs(size=1000)

binom.rvs(n, p, size=1000)

do the same thing, because you froze the parameters at n,p when you called the constructor function binom.

Vons
  • 3,277
  • 2
  • 16
  • 19