3

If I initialize a subclass of scipy.stats.rv_continuous , for example scipy.stats.norm

>>> from scipy.stats import norm
>>> rv = norm()

Can I convert it into a list of probabilities with each element representing the probability of a range of values after providing the number of ranges? Something like - (for the range - [(-inf,-1), (-1,0), (0,1), (1, inf)] )

>>> li
[0.15865525393145707, 0.34134474606854293, 0.34134474606854293, 0.15865525393145707]

( where 0.15865525393145707 is the probability of the variable being less than -1 and 0.34134474606854293 for being in the range -1 to 0 and similarly for others.

Can this be done using scipy? If not which python library can support such conversion operations?

Yashu Seth
  • 935
  • 4
  • 9
  • 24

1 Answers1

3

Based on your comment, you can calculate this using the CDF:

from scipy.stats import norm
import numpy as np

>>> norm().cdf(-1) - norm().cdf(-np.inf), \
    norm().cdf(0) - norm().cdf(-1), \
    norm().cdf(1) - norm().cdf(0), \
    norm().cdf(np.inf) - norm().cdf(1)
(0.15865525393145707,
 0.34134474606854293,
 0.34134474606854293,
 0.15865525393145707)

This follows from the definition of the CDF, basically.


Note that I'm getting numbers that sum to 1, but not the ones you write as the expected output. I don't know your basis for saying that those are the correct ones. My guess is you're implicitly using a Normal variable with non-unit standard deviation.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
  • I mean i want the probabilities for the following ranges [(-inf,-1), (-1,0), (0,1), (1, inf)] and it should give something like [0.01, 0.49, 0.49, 0.01] where 0.01 is the probability of the variable being less than -1 , 0.49 for being in the range -1 to 0 and similarly for others. I want total probability for that range. Will the above method give the total probability? – Yashu Seth Mar 19 '16 at 15:31
  • Thanks. I got it. And I just used the example for illustration. Yes they are not the correct results. – Yashu Seth Mar 19 '16 at 16:27
  • OK. Note that this is extremely misleading for anyone trying to address the question - it slows down answering considerably. – Ami Tavory Mar 19 '16 at 16:28