All Questions

Tagged with
Filter by
Sorted by
Tagged with
124 votes
10 answers
316k views

How to calculate probability in a normal distribution given mean & standard deviation?

How to calculate probability in normal distribution given mean, std in Python? I can always explicitly code my own function according to the definition like the OP in this question did: Calculating ...
clwen's user avatar
  • 20.4k
72 votes
10 answers
117k views

Multivariate normal density in Python?

Is there any python package that allows the efficient computation of the PDF (probability density function) of a multivariate normal distribution? It doesn't seem to be included in Numpy/Scipy, and ...
Benno's user avatar
  • 5,376
28 votes
3 answers
76k views

Defining a white noise process in Python

I need to draw samples from a white noise process in order to implement a particular integral numerically. How do I generate this with Python (i.e., numpy, scipy, etc.)?
abcd's user avatar
  • 10.5k
23 votes
2 answers
21k views

Fitting distributions, goodness of fit, p-value. Is it possible to do this with Scipy (Python)?

INTRODUCTION: I'm a bioinformatician. In my analysis which I perform on all human genes (about 20 000) I search for a particular short sequence motif to check how many times this motif occurs in each ...
s_sherly's user avatar
  • 2,347
23 votes
1 answer
3k views

sampling multinomial from small log probability vectors in numpy/scipy

Is there a function in numpy/scipy that lets you sample multinomial from a vector of small log probabilities, without losing precision? example: # sample element randomly from these log probabilities ...
lgd's user avatar
  • 1,472
21 votes
3 answers
30k views

How to compute the probability of a value given a list of samples from a distribution in Python?

Not sure if this belongs in statistics, but I am trying to use Python to achieve this. I essentially just have a list of integers: data = [300,244,543,1011,300,125,300 ... ] And I would like to know ...
qazplok11's user avatar
  • 447
13 votes
2 answers
4k views

multinomial pmf in python scipy/numpy

Is there a built-in function in scipy/numpy for getting the PMF of a Multinomial? I'm not sure if binom generalizes in the correct way, e.g. # Attempt to define multinomial with n = 10, p = [0.1, 0.1,...
user avatar
12 votes
3 answers
13k views

Python: How to get the convolution of two continuous distributions?

Let X, Y be 2 random variables, with probability density functions pdf1 and pdf2. Z = X + Y Then the probability density function of Z is given by the convolution of pdf1 and pdf2. Since we can't ...
Pasindu Tennage's user avatar
8 votes
2 answers
11k views

Generating random numbers with a given probability density function

I want to specify the probability density function of a distribution and then pick up N random numbers from that distribution in Python. How do I go about doing that?
user2445465's user avatar
8 votes
4 answers
6k views

Calculating pdf of Dirichlet distribution in python

I'd like to calculate the pdf for the Dirichlet distribution in python, but haven't been able to find code to do so in any kind of standard library. scipy.stats includes a long list of distributions ...
jpmccoy's user avatar
  • 115
7 votes
4 answers
4k views

Python equivalent for MATLAB's normplot?

Is there a python equivalent function similar to normplot from MATLAB? Perhaps in matplotlib? MATLAB syntax: x = normrnd(10,1,25,1); normplot(x) Gives: I have tried using matplotlib & numpy ...
siva's user avatar
  • 2,135
7 votes
1 answer
7k views

How can I sample a multivariate log-normal distribution in Python?

Using Python, how can I sample data from a multivariate log-normal distribution? For instance, for a multivariate normal, there are two options. Let's assume we have a 3 x 3 covariance matrix and a 3-...
Mack's user avatar
  • 2,654
5 votes
2 answers
26k views

Probability Mass Function of a Binomial Distribution in Python

I am using Python3 to compute the Probability Mass Function (PMF) of this wikipedia example: I tried to follow this scipy documentation: https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/...
user avatar
5 votes
3 answers
699 views

Speeding up normal distribution probability mass allocation

We have N users with P avg. points per user, where each point is a single value between 0 and 1. We need to distribute the mass of each point using a normal distribution with a known density of 0.05 ...
pir's user avatar
  • 5,685
5 votes
1 answer
5k views

Scipy Multivariate Normal: How to draw deterministic samples?

I am using Scipy.stats.multivariate_normal to draw samples from a multivariate normal distribution. Like this: from scipy.stats import multivariate_normal # Assume we have means and covs mn = ...
k88074's user avatar
  • 2,102
5 votes
2 answers
1k views

Drawing cards from a deck in SciPy with scipy.stats.hypergeom

I'm having trouble understanding the documentation for SciPy's scipy.stats.hypergeom functions. In my program, I consider various decks of cards and try to find the probability of various draws. The ...
Brighid McDonnell's user avatar
4 votes
1 answer
6k views

How to run statistics Cumulative Distribution Function and Probability Density Function using SciPy?

I am new to Python and new to SciPy libraries. I wanted to take some ques from the experts here on the list before dive into SciPy world. I was wondering if some one could provide a rough guide about ...
okm's user avatar
  • 293
4 votes
1 answer
1k views

How is scipy.stats.multivariate_normal.pdf different from the same function written using numpy?

I need to use the multivariate normal distribution in a script. I have noticed that my version of it gives a different answer from scipy's method. I can't really figure out why... Here is my function:...
Fern's user avatar
  • 43
4 votes
1 answer
518 views

Comparing datasets to nonstandard probability distributions in Python

I have a few large sets of data which I have used to create non-standard probability distributions (using numpy.histogram to bin the data, and scipy.interpolate's interp1d function to interpolate the ...
SeaWalk's user avatar
  • 63
4 votes
0 answers
3k views

Using scipy.optimize to fit data to negative binomial

I am trying to fit my data to a negative binomial model. My data is simply an array of numbers all_hits = [0, 4000, 200, ...] If I plot the data as a histogram and plot the negative binomial ...
elsherbini's user avatar
  • 1,606
3 votes
1 answer
1k views

How to use Erlang Distribution Function Scipy

I want to randomly generate numbers that follow a Erlang Distribution for an arrival process. I want to set the number of arrivals k as a parameter of the Erlang Distribution. scipy.stats.erlang.rvs(a,...
Steven Oh's user avatar
  • 392
3 votes
1 answer
714 views

Truncated normal with a given mean

Is it possible in python to generate a truncated normal distribution with a given expected value? I know that scipy.stats.truncnorm can give a truncated normal distribution that takes the mean of the ...
tmldwn's user avatar
  • 465
3 votes
1 answer
2k views

calculate binomial distribution probability matrix with python

Give the N and P, I want to get a 2D binomial distribution probability matrix M, for i in range(1, N+1): for j in range(i+1): M[i,j] = choose(i, j) * p**j * (1-p)**(i-j) other value = 0 I ...
Albert Feng's user avatar
3 votes
1 answer
1k views

Can continuous random variables be converted into discrete using scipy?

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 ...
Yashu Seth's user avatar
3 votes
1 answer
526 views

Loading additional parameters to scipy's rv_continuous

I am planning to do some basic algebra on continuous, non-analytical random variabels. I want to define their probability density functions as arrays x and f(x). Yet, I was surprised to find out that ...
Yann's user avatar
  • 89
3 votes
1 answer
7k views

How to calculate the joint probability distribution of two binomially distributed variables in Python?

Is there an existing formula, perhaps in scipy.stats that allows me to compute the joint probability of two binomial variables as indicated in the picture below? What I would like to do is test ...
finstats's user avatar
  • 1,369
3 votes
1 answer
2k views

Python/SciPy version of Excel FInv function

Hopefully an easy one. Can anyone point me to the SciPy function that will calculate a right-tailed F Probability Distribution? Like Excel's =FINV(0.2, 1, 2) that results in 3.555555556. Thanks, ...
user1505300's user avatar
3 votes
0 answers
428 views

Calculate the likelihood of a function given a Gaussian Process model

I am fitting a Gaussian process regression using scikit-learn. (mine is actually a simple 1 dimensional case) from sklearn.gaussian_process import GaussianProcessRegressor from sklearn....
Gioelelm's user avatar
  • 2,705
2 votes
2 answers
1k views

How to sample from a step function in python/scipy/numpy etc?

If I have bin edges and counts for each bin, is there a nice succinct way to sample from the probability density function this implies? Here is an example of what I mean. bin_edges = [0,2.1,6.3,23.5]...
Simd's user avatar
  • 20.6k
2 votes
2 answers
1k views

How to generate in python a random number in a range but biased toward some specific numbers?

I would like to choose a range, for example, 60 to 80, and generate a random number from it. However, between 65-72 I'd like a higher probability, while the other ranges aside from this (60-64 and 73 ...
Emerson Oliveira's user avatar
2 votes
1 answer
1k views

Theoretical normal distribution function in scipy

I need to plot normal cumulative distribution for given edges of bins: bin_edges = np.array([1.02, 4.98, 8.93, 12.89, 16.84, 20.79, 24.75, 28.7]) mean = 15.425 standard_deviation = 6....
George Zorikov's user avatar
2 votes
1 answer
3k views

scipy: How do I use weibull_min.pdf?

I'm finding scipy's weibull_min pdf function unintuitive and hard to use. I want to generate a weibull PDF with scale=30 and shape=2.5. This is what that is supposed to look like: Here's what I've ...
kilojoules's user avatar
  • 10.2k
2 votes
1 answer
2k views

Fitting a distribution given the histogram using scipy

I would like to fit a distribution using scipy (in my case, using weibull_min) to my data. Is it possible to do this given the Histogram, and not the data points? In my case, because the histogram has ...
Alberto A's user avatar
  • 1,230
2 votes
1 answer
3k views

Fitting Gaussian KDE in numpy/scipy in Python

I am fitting a Gaussian kernel density estimator to a variable that is the difference of two vectors, called "diff", as follows: gaussian_kde_covfact(diff, smoothing_param) -- where ...
user avatar
2 votes
2 answers
414 views

How to calculate the combination of matrix of probabilities (win rate ranking in game)

Let imagine we have a game with 4 players. And after playing game, we will get ranking of 4 players based on their score, rank 1 is the best, rank 4 is the worst. I have created a model for predicting ...
voxter's user avatar
  • 875
2 votes
1 answer
877 views

Fast sampling from a user-defined distribution

A simulation I'm running requires me to draw values from a probability distribution. I'm doing this as follows: import numpy as np import scipy.special as sp from scipy.stats import rv_continuous ...
abcd's user avatar
  • 10.5k
2 votes
0 answers
116 views

Function that can create any type of probability distribution function

I would like to receive the distribution name and parameters from the user as input and generate a probability distribution from which I can choose a random number proportional to their probability. I ...
John's user avatar
  • 99
2 votes
0 answers
248 views

How to plot a 3_d representation of the probability density function in the bloch sphere?

I have a model which gives me datasets in a specific form. Lets say its a radius + 2 angles (r,phi,theta). I would like to plot this data in the bloch sphere with two volumes indicating the regions ...
toktok's user avatar
  • 21
2 votes
0 answers
3k views

Plotting fit of lognormal distribution after fit by scipy using seaborn

I have fit a distribution to my data using scipy.stats.lognormal, and now I am trying to plot the distribution. I have generated the fit to my data with seaborn: ax = sns.distplot(1 - ...
Ian Fiddes's user avatar
  • 2,891
2 votes
0 answers
544 views

Strange behaviour from scipy.stats.multivariate_normal

I fit a 3 component bivariate Gaussian Mixture Model using scikit-learn and obtained the following means/covariances Component 1 Mean=[ 2.01878147e+03 1.09863146e-01] Cov=[[ 6.56549549e+06 7....
A.R.Ferguson's user avatar
1 vote
1 answer
2k views

Equivalent for "qt" R function in Python

I have the following code in R: n <- 112 # Observations p <- 4 # Variables alpha <- 0.05 # Alpha is alpha quant = qt(1-alpha/2, n-p-1) # which is 1.982383 From my research, the qt ...
Carlos Carvalho's user avatar
1 vote
2 answers
2k views

Numpy/Scipy: Singular Matrix Calculating probability of multivariate observation

I'm trying to calculate probabilities for observations in matrices where my rows are observations and my columns are features using python. I always get singular matrix errors, even when using random ...
rumdrums's user avatar
  • 1,352
1 vote
1 answer
748 views

Estimating parameters of Von Mises Distribution Scipy - Inconsistent Answers

I am computing the parameters of a Von Mises distribution by hand and wanted to compare to the Scipy Von Mises fit function. I am getting inconsistent results from the fit function. My two datasets ...
Sacha Gunaratne's user avatar
1 vote
1 answer
510 views

In Scipy why does custom.rvs() having uniform probability return the values in the begining region only?

If I generate a array custom=np.ones(800, dtype=np.float32) Then create a Custom Probability distribution out of it using custom=normalize(custom)[0] customPDF = stats.rv_discrete(name='pdfX', ...
Alexander's user avatar
1 vote
1 answer
911 views

Fitting a probability distribution to the data and finding cumulative distribution function for it

I want to fit an asymmetric probability distribution to my data and I thought an exponentially modified Gaussian distribution can be a good representative for my data. I m=array([ 16.25, 16.75, ...
Dalek's user avatar
  • 4,268
1 vote
1 answer
34 views

Why does integrating scipy.multivariate_normal give incorrect probability?

I'm trying to integrate an independent bivariate normal distribution over a square region. The numerical integration does not match a Monte Carlo simulation. What's going wrong here? import numpy as ...
feetwet's user avatar
  • 3,360
1 vote
2 answers
492 views

Difference between scipy.stats.binom and np.random.binomial

I am learning about probability distribution with python and I'm currently looking at binomial distribution and have seen both the scipy way and numpy method, what I'm trying to understand is that why ...
Amazing-Grace Umoren's user avatar
1 vote
1 answer
238 views

SciPy - 'Object too deep for desired array' when subclassing rv_continuous

I'm trying to generate a 2D uniform distribution by subclassing rv_continuous. from scipy import stats class uniform_2d(stats.rv_continuous): def _pdf(self, x, y): X, Y = np.meshgrid(x,...
Nick Sweet's user avatar
  • 2,109
1 vote
1 answer
1k views

How to properly plot the pdf of a beta function in scipy.stats

I am trying to fit a beta distribution to some data, and then plot how well the beta distribution fits the data. But the output looks really weird and incorrect. import scipy.stats as stats import ...
statsman's user avatar
1 vote
1 answer
1k views

scipy.stats.chi2 returns Nan probability [duplicate]

I need to calculate the Chi^2 probability of a dataset that is expected to follow a Poisson distribution. I have my observed frequencies and theoretical frequencies. My degrees of freedom is 7. ...
Gordon J. Köhn's user avatar