Hypothesis Test And All About P Value,T test,Chi Square Test, Anova Test and When to Use What?

Hypothesis Test

Kamna Sinha
Data At The Core !
4 min readSep 28, 2023

--

In the simplest of words, Hypothesis testing evaluates 2 mutually exclusive statements on a population using a sample data. And then draw a conclusion if the entire population under consideration is true for a particular statement [Null hypothesis] or untrue for a particular statement.

One of the statements will be true, we reach that conclusion through a series of steps and then test our conclusion by gathering evidence.

Steps of Hypothesis Testing :

  1. Make an initial assumption [ H₀ or Null Hypothesis]
  2. Collect Data [ Evidences ]
  3. Gather Evidence to reject or accept null hypothesis.

Alternate Hypothesis or H₁ is the opposite of H₀.

Hypothesis testing confusion matrix

Explanation of the confusion matrix :

  1. True Positive — H₀ = True , H₀ = Not Rejected / Accepted.
  2. True Negative — H₀ = False, H₁ = True , H₀ is rejected .
  3. False Positive — H₁ = True BUT gets rejected. H₀ = Accepted.
  4. False Negative — H₁ = False BUT gets accepted and H₀ is rejected .

Type 1 Error (False Negative): Is when Null Hypothesis is true but gets rejected due to lack of evidence or other reasons. eg. H₀ = The convict is innocent, and because of lack of evidence to prove it, he gets punishment ,i.e. H₀ got rejected. Although in reality he was innocent.

Type 2 Error (False Positive): Is when Null Hypothesis is not actually true but gets accepted due to lack of evidence or other reasons. eg. H₀ = Market is going to crash. So H₁ = Market is not going to crash. We gained evidence and somehow proved that H₁ is True. But in reality the market is going to crash even though we could gather only enough evidence to prove alternate hypothesis , hence H₁ got accepted.

P Value, T test, Chi Square Test, Anova Test and When to Use What?

A simple Data set :

We shall try to understand which test applies in which scenario by taking some examples out of this dataset :

Eg1. Consider Gender :

Question : Is there a difference in the proportion of males and females.

We proceed with Hypothesis testing :

H₀ = ‘There is no difference’ , H₁ = ‘Yes there is a difference in the proportion’

Create a bar plot :

Bar plot depicting count of Males and Females

The bar plot answers our question very easily BUT keep in mind that the dataset we are seeing is ONLY the SAMPLE dataset and not the entire POPULATION.

Hence we do need to consider the null hypothesis here H₀.

Next, we considering the categorical feature (Gender), we need to apply a test which says that when we have the null hypothesis as True, what is the likelihood/probability that the alternate hypothesis will be true.

This test yields a ‘p’ value or a significance value which is usually less than or equal to 0.05. [Going by Gaussian Distribution p<0.05 says probability is falling in the tail region on either side]. The p value needs to be selected before the test.

If the test falls in the tail region we reject the (null)hypothesis and accept the alternate hypothesis.

Since the test is being considered on a single categorical variable, the kind of test we apply is the ‘One Sample Proportion Test’

Eg2. Considering two category features : Gender and Age Group

Question : Is there a difference between male and female proportion based on the age group ?

Same null and alternate hypothesis as Eg1.

Type of test : Chisquare Test

Eg3. Considering continuous numerical value OR one categorical and one numerical.

Question : Is the mean height same or different than the mean height from the last sample ?

OR Gender and Height comparison.

Test type : T-test

Eg4. Considering two numerical variables

Example : looking at Weight and Height values

Test : Correlation

In this case the Null Hypothesis says there is no relation , Alternate says there is.

Eg5. Considering categorical variable with more than 2 categories

Like the Age group variable in our dataset .

Test : ANOVA test.

We will talk more about each of these tests along with examples and code in my upcoming stories. Watch this space for more.

Reference :

--

--