DEV Community

Cover image for Statistical Hypothesis Test in Python
D VAMSIDHAR
D VAMSIDHAR

Posted on

2

Statistical Hypothesis Test in Python

What is Statistical Hypothesis Test?

In statistics, hypothesis test is used to test the quality of an assumption. By this test we can interpret whether the assumption made is true to factual data and situation or violates the facts.
This test is called STATISTICAL HYPOTHESIS TESTING.

Currently there are hundreds of statistical hypothesis testing but in this post we are going to see few of them which are most used.

Following is the flowchart that describes the types which we will discuss in this post :

Image description

1. NORMALITY TEST

This statistical test helps you check whether your data has Gaussian Distribution or not.

This test again has 3 different types in it :

Image description

1.1 Shapiro-Wilk Test

Python code for this test :

# Example of the Shapiro-Wilk Normality Test
from scipy.stats import shapiro
data = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637, -1.869]
stat, p = shapiro(data)
print('stat=%.3f, p=%.3f' % (stat, p))
if p > 0.05:
    print('Probably Gaussian')
else:
    print('Probably not Gaussian')
Enter fullscreen mode Exit fullscreen mode

1.2 D Agostino's K^2 Test

Python code for this test :

# Example of the D'Agostino's K^2 Normality Test
from scipy.stats import normaltest
data = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637, -1.869]
stat, p = normaltest(data)
print('stat=%.3f, p=%.3f' % (stat, p))
if p > 0.05:
    print('Probably Gaussian')
else:
    print('Probably not Gaussian')
Enter fullscreen mode Exit fullscreen mode

1.3 Anderson-Darling Test

Python code for the test :

# Example of the Anderson-Darling Normality Test
from scipy.stats import anderson
data = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637, -1.869]
result = anderson(data)
print('stat=%.3f' % (result.statistic))
for i in range(len(result.critical_values)):
    sl, cv = result.significance_level[i], result.critical_values[i]
    if result.statistic < cv:
        print('Probably Gaussian at the %.1f%% level' % (sl))
    else:
        print('Probably not Gaussian at the %.1f%% level' % (sl))
Enter fullscreen mode Exit fullscreen mode

Python codes about other tests shall be discussed in upcoming posts.

To be continued ....

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay