Sitemap
Katabathina

Katabathina

Hypothesis Testing

6 min readJan 15, 2024

--

In the dynamic world of data analysis, hypothesis testing emerges as a powerful tool, allowing us to make informed decisions and draw conclusions about populations based on sample data. In this blog post, we embark on a journey into the realm of hypothesis testing, demystifying its concepts through practical examples and showcasing how it can be wielded as a statistical sword in the data scientist’s toolkit.

Understanding the Basics of Hypothesis Testing

At its core, hypothesis testing involves two key hypotheses:

  • Null Hypothesis (H0): Assumes no effect or no difference.
  • Alternative Hypothesis (H1): Suggests a significant effect or difference.

The goal is to collect and analyze sample data to determine whether there is enough evidence to reject the null hypothesis in favor of the alternative hypothesis.

Press enter or click to view image in full size

Steps to be fallowed in Hypothesis Testing

  1. Formulation of Null & Alternative Hypothesis
  2. Specifying of Level of Significance
  3. Selection of Test Statistics
  4. Finding the Critical value from the Table, Using the Level of Significance & Degree of freedom
  5. Decision about Null Hypothesis & Alternative Hypothesis, Comparing the significance of test statistics
  6. Writing the conclusion based on the Problem Statement

Level of Significance :

In hypothesis testing, the level of significance is the maximum probability that a researcher is willing to accept for rejecting the null hypothesis, which is the assumption that there is no significant difference between two groups or conditions being compared. If the calculated probability, known as the p-value, is less than or equal to the level of significance, the null hypothesis is rejected in favor of the alternative hypothesis, which states that there is a significant difference between the groups or conditions.

For example, if a researcher sets a level of significance of 0.05 and obtains a p-value of 0.03, they would reject the null hypothesis and conclude that there is strong evidence of a significant difference between the groups being compared. However, if the p-value is greater than the level of significance, the researcher would fail to reject the null hypothesis and conclude that there is not enough evidence to support a significant difference between the groups.

P-Value:

• P-Value is a Probability value, A P-Value measures the probability of obtaining the observed result, By Assuming that the null Hypothesis is True.

Get Katabathina’s stories in your inbox

Join Medium for free to get updates from this writer.

• The Lower the P-Value, The greater the statistical significance of the observed difference

  • P-Value helps you to accept or reject the Null Hypothesis & Alternative Hypothesis
  • In General if the P-Value is <= 0.05 or 5% of Level of Significance, Then we reject the Null Hypothesis. If it is >0.05 or 5% of level of significance then we fail to reject the Null Hypothesis

One-Tailed Tests:

In traditional hypothesis testing, we have the null hypothesis (H0) and the alternative hypothesis (H1). In the context of a one-tailed test, the alternative hypothesis is directional, indicating an effect in one specific direction. This direction could be an increase or a decrease, depending on the research question or hypothesis.

Key Components:

  • Null Hypothesis (H0): Assumes no effect or no difference.
  • Alternative Hypothesis (H1): Suggests a specific directional effect.

Types of One-Tailed Tests:

  1. One-Tailed Test for a Greater Than Effect: H0:μ≤μ0​ vs H1:μ>μ0​
  2. One-Tailed Test for a Less Than Effect: H0:μ≥μ0 ​ vs H1:μ<μ0​
Press enter or click to view image in full size

Practical Examples of One-Tailed Testing

1. Educational Intervention:

  • H0: The new teaching method has no effect on test scores.
  • H1: The new teaching method increases test scores.

2. Productivity Improvement:

  • H0: The new workflow has no impact on productivity.
  • H1: The new workflow decreases the time taken to complete tasks.

3. Marketing Campaign Success:

  • H0: The marketing campaign has no impact on sales.
  • H1: The marketing campaign leads to an increase in sales.

Performing One-Tailed Tests in Python

Python, with its powerful statistical libraries, makes performing one-tailed tests straightforward. Let’s consider a one-tailed t-test as an example:

import scipy.stats as stats
# Sample data
sample_data = [78, 82, 75, 88, 85, 80, 83, 79, 81, 84]
# Null hypothesis: The average score is 80 or less
# Alternative hypothesis: The average score is greater than 80
# Perform one-tailed t-test
t_statistic, p_value = stats.ttest_1samp(sample_data, 80)
# Set significance level
alpha = 0.05
# Compare p-value to alpha
if p_value < alpha:
print("Reject the null hypothesis in favor of the alternative hypothesis.")
else:
print("Fail to reject the null hypothesis.")

Two-Tailed Hypothesis Testing

In the realm of hypothesis testing, we often encounter situations where the nature of the effect is uncertain, or there is no strong expectation about the direction of the effect. This is where a two-tailed test comes into play. In this scenario, the alternative hypothesis (H1) suggests the presence of an effect, but without specifying whether it’s an increase or a decrease.

Key Components:

  • Null Hypothesis (H0): Assumes no effect or no difference.
  • Alternative Hypothesis (H1): Suggests the presence of an effect, without specifying the direction.

Two-Tailed Test Hypotheses:

Two-Tailed Test for a Not Equal To Effect: H0:μ=μ0 ​ vs H1:μ≠μ0​

Practical Examples of Two-Tailed Testing

1. Drug Efficacy Study:

  • H0: The new drug has no effect on blood pressure.
  • H1: The new drug has an effect on blood pressure, but the direction is not specified.

2. Employee Productivity Analysis:

  • H0: The new work schedule has no impact on productivity.
  • H1: The new work schedule has an impact on productivity, but the direction is not specified.

3. Customer Satisfaction Survey:

  • H0: The recent changes in service have not affected customer satisfaction.
  • H1: The recent changes in service have affected customer satisfaction, but the direction is not specified.

Performing Two-Tailed Tests in Python

Python, with its robust statistical libraries, makes performing two-tailed tests seamless. Let’s consider a two-tailed t-test as an example:

import scipy.stats as stats
# Sample data
sample_data = [68, 72, 65, 78, 70, 74, 68, 76, 71, 75]
# Null hypothesis: The average score is 70
# Alternative hypothesis: The average score is different from 70
# Perform two-tailed t-test
t_statistic, p_value = stats.ttest_1samp(sample_data, 70)
# Set significance level
alpha = 0.05
# Compare p-value to alpha
if p_value < alpha:
print("Reject the null hypothesis in favor of the alternative hypothesis.")
else:
print("Fail to reject the null hypothesis.")

Types of Errors:

In hypothesis testing, there are two types of errors that can occur: Type I error and Type II error. These errors are associated with the decision to either reject or fail to reject the null hypothesis.

Press enter or click to view image in full size

1. Type I Error (False Positive):

  • Definition: Occurs when the null hypothesis is incorrectly rejected when it is actually true.
  • Symbolically: α
  • Significance Level: The probability of making a Type I error is denoted by the significance level (α). Common choices for α include 0.05, 0.01, etc.
  • Consequence: Falsely concluding that there is an effect or difference when there isn’t one.

2. Type II Error (False Negative):

  • Definition: Occurs when the null hypothesis is not rejected when it is actually false.
  • Symbolically: β
  • Consequence: Failing to detect a real effect or difference that exists.

Relationship Between Type I and Type II Errors:

  • There is an inherent trade-off between Type I and Type II errors. As you decrease the probability of one type of error, the probability of the other type of error tends to increase.

Example: Medical Testing:

  • Type I Error: Concluding a patient has a disease when they do not (false positive).
  • Type II Error: Failing to diagnose a patient who actually has the disease (false negative).

Example: Legal System:

  • Type I Error: Wrongfully convicting an innocent person (false positive).
  • Type II Error: Wrongfully acquitting a guilty person (false negative).

Understanding and managing these types of errors are crucial in hypothesis testing, as they impact the reliability and validity of the conclusions drawn from statistical analyses. Researchers and practitioners often aim to strike a balance between Type I and Type II errors based on the context and consequences of the decision.

--

--