Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

norm.ppf vs norm.cdf in python's scipy.stats

so i have pasted my complete code for your reference, i want to know what's the use of ppf and cdf here? can you explain it? i did some research and found out that ppf(percent point function) is an inverse of CDF(comulative distribution function) if they really are, shouldn't this code work if i replaced ppf and cdf as 1/cdf and 1/ppf respectively?

please explain this to me, the difference between the two. and how to and when to use which

this is, btw, hypothesis testing. and sorry for so many comments, just a habit of explaining everything for my future reference.(do point me out if any of my comments is wrong regarding the same)

ball_bearing_radius = [2.99, 2.99, 2.70, 2.92, 2.88, 2.92, 2.82, 2.83, 3.06, 2.85]




import numpy as np

from math import sqrt
from scipy.stats import norm

# h1 : u != U_0
# h0 : u = u_0
#case study : ball bearing example, claim is that radius = 3, do hypothesis testing 
mu_0 = 3
sigma = 0.1

#collect sample
sample = ball_bearing_radius

#compute mean
mean = np.mean(sample)

#compute n
n = len(sample)

#compute test statistic
z = (mean - mu_0) /(sigma/sqrt(n))

#set alpha
a = 0.01

#-------------------------

#calculate the z_a/2, by using percent point function of the norm of scipy
#ppf = percent point function, inverse of CDF(comulative distribution function)
#also, CDF = pr(X<=x), i.e., probability to the left of the distribution

z_critical = norm.ppf(1-a/2)    #this returns a value for which the probab to the left is 0.975

p_value = 2*(1 - norm.cdf(np.abs(z)))

p_value = float("{:.4f}".format(p_value))


print('z : ',z)
print('\nz_critical :', z_critical)
print('\nmean :', mean, "\n\n")

#test the hypothesis

if (np.abs(z) > z_critical):
    print("\nREJECT THE NULL HYPOTHESIS : \n p-value = ", p_value, "\n Alpha = ", a )

else:
    print("CANNOT REJECT THE NULL HYPOTHESIS. NOT ENOUGH EVIDENCE TO REJECT IT: \n p-value = ", p_value, "\n Alpha = ", a )
like image 798
Pushpak Ruhil Avatar asked Dec 27 '20 16:12

Pushpak Ruhil


People also ask

What is the difference between PPF and cdf?

CDF: Cumulative Distribution Function, returns the probability of a value less than or equal to a given outcome. PPF: Percent-Point Function, returns a discrete value that is less than or equal to the given probability.

What is SciPy stats norm PPF?

The method norm. ppf() takes a percentage and returns a standard deviation multiplier for what value that percentage occurs at. It is equivalent to a, 'One-tail test' on the density plot. From scipy. stats.

What does norm cdf do in Python?

A cumulative distribution function (CDF) tells us the probability that a random variable takes on a value less than or equal to some value. This tutorial explains how to calculate and plot values for the normal CDF in Python.

What is PPF function in Python?

ppf() method, we can get the value of percentage point function which is inverse( cdf ) by using stats. halfgennorm. ppf() method. Syntax : stats.halfgennorm.ppf(x, beta) Return : Return the value of percentage point function.

How to calculate normal CDF probabilities in Python?

A cumulative distribution function (CDF) tells us the probability that a random variable takes on a value less than or equal to some value. This tutorial explains how to calculate and plot values for the normal CDF in Python. The easiest way to calculate normal CDF probabilities in Python is to use the norm.cdf () function from the SciPy library.

How to calculate the percent point function of the norm in Python?

The object norm () has a method ppf () that calculate the Percent point function of the norm. In other words, The method norm. ppf () accepts a percentage and returns a standard deviation multiplier for the value that percentage occurs at. The syntax is given below. q: It is a percentage. loc: It is used to specify the mean, by default it is 0.

How to get the Alpha range of a distribution in Python scipy?

The method norm.interval () of Python Scipy computes the endpoints of the distribution’s fractional alpha range, between 0 and 1. The syntax is given below. alpha (float): It is the alpha value. loc: It is used to specify the mean, by default it is 0. scale: It is used to determine the standard deviation, by default it is 1.

What is RVS() method of Python scipy of object norm?

The method rvs () of Python Scipy of object norm is random variates that generate random numbers. loc: It is a mean. scale: The distribution’s matrix of covariance. size (int): It is the sample size. random_state (int): If the seed is None, the NumPy.random method is utilized (or np.random).


1 Answers

The .ppf() function calculates the probability for a given normal distribution value, while the .cdf() function calculates the normal distribution value for which a given probability is the required value. These are inverse of each other in this particular sense.

To illustrate this calculation, check the below sample code.

from scipy.stats import norm
print(norm.ppf(0.95))
print(norm.cdf(1.6448536269514722))

enter image description here

This image with the code above should make it clear for you.

Thanks!

like image 100
srishtigarg Avatar answered Oct 17 '22 03:10

srishtigarg