Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can normal distribution prob density be greater than 1?... based on python code checkup

I have a question: Given mean and variance I want to calculate the probability of a sample using a normal distribution as probability basis. The numbers are:

mean = -0.546369
var = 0.006443
curr_sample = -0.466102

prob = 1/(np.sqrt(2*np.pi*var))*np.exp( -( ((curr_sample - mean)**2)/(2*var) ) )

I get a probability which is larger than 1! I get prob = 3.014558...

What is causing this? The fact that the variance is too small messes something up? It's a totally legal input to the formula and should give something small not greater than 1! Any suggestions?

like image 446
user3861925 Avatar asked Apr 20 '26 12:04

user3861925


2 Answers

Ok, what you compute is not a probability, but a probability density (which may be larger than one). In order to get 1 you have to integrate over the normal distribution like so:

import numpy as np
mean = -0.546369
var = 0.006443
curr_sample = np.linspace(-10,10,10000)

prob = np.sum( 1/(np.sqrt(2*np.pi*var))*np.exp( -( ((curr_sample - mean)**2)/(2*var) ) ) * (curr_sample[1]-curr_sample[0]) )
print prob

witch results in

0.99999999999961509

The formula you give is a probability density, not a probability. The density formula is such that when you integrate it between two values of x, you get the probability of being in that interval. However, this means that the probability of getting any particular sample is, in fact, 0 (it's the density times the infinitesimally small dx).

So what are you actually trying to calculate? You probably want something like the probability of getting your value or larger, the so-called tail probability, which is often used in statistics (it so happens that this is given by the error function when you're talking about a normal distribution, although you need to be careful of exactly how it's defined).

like image 22
Andrew Jaffe Avatar answered Apr 22 '26 08:04

Andrew Jaffe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!