# Hypothesis Testing

Mar 23 · 8 min read

Are you new to hypothesis testing and wonder what it is ? Then this blog is for you as I tried to make it self explanatory with simple examples.

1. Hypothesis and Hypothesis testing
2. Null and Alternative Hypothesis
3. Some important concepts — Significance level, Critical region, Critical Value, P-Value, Types of errors (Type-1 Error, Type-2 Error).
4. Steps to follow for testing a hypothesis
5. Test stastic for single and two normal populations (i) Sample mean (ii) Sample Variance (iii) Sample proportion

## What does hypothesis and hypothesis testing mean ?

We generally encounter lot many problems and they are to be either accepted or rejected and such a problem statement is named as hypothesis and making the process of making decisions for hypothesis is called hypothesis testing.

Examples of Hypothesis : Is drug A is more effective treatment for COVID than drug B? Has the unemployment change in India in last quarter ? Does climatic changes alarming the global warming levels ? Does humans start living in MARS after few decades ? (These are few examples for problem statements that can asked)

If we want to define it more technically , A stastical hypothesis is usually a statement about a set of parameters of a population distribution and A hypothesis test is where we collect a representative sample and examine it to see if our hypothesis is true.

The problem statement is a random sample, if it is deemed to be consistent with hypothesis under considerations, we can either say i) hypothesis is accepted or ii) hypothesis is rejected.

Example of Hypothesis Testing : If a construction firm has just purchased a large supply of cables that have been guranteed to have an average breaking strength of atleast 7000 psi. To verify this claim, the firm has decided to take a random sample of 10 of these cables to determine their breaking strengths. Then the result shows the certainity whether to accept or reject the hypothesis that the population mean is atleast 7000 pounds per square inch.

## What does Null and Alternative Hypothesis mean ?

The null hypothesis ( denoted by H0) is a statement that the value of a population parameter (such as proportion, mean, or standard deviation) is equal to some claimed value. Null hypothesis is measured directly. Null Hypothesis is either reject H0 or fail to reject H0 but not accepted. Null hypothesis contains ‘=’ (equality sign , it can also be ≤ or ≥). It can sometimes be regarded as representing the current state of knowledge or belief about the value of the parameter being tested(the ‘status quo’ hypothesis).

The alternative hypothesis (denoted by H1 or H a or HA ) is the statement that the statistic has a value that somehow differs from the null hypothesis. In HA we use != , <, > .

If a hypothesis completely specifies the distribution, it is called simple hypothesis otherwise it is termed as composite hypothesis.

Here are some examples of formulation of H0, HA :

1.The mean number of years Americans work before retiring is 34. Here mean (mu)= 34, so the null hypothesis H0 : mu = 34 and alternative hypothesis HA : mu != 34. It is a two-tailed sample.

2. At most 60% of Americans vote in presidential elections. Here k =0.6, so the null hypothesis H0 : k ≤ 0.6 and alternative hypothesis HA : k > 0.6. It is a Single-tailed sample (right).

3. The mean starting salary for San Jose State University graduates is at least \$100,000 per year. Here mean (mu) = \$100000 , so the null hypothesis H0 : mu ≥ \$100000 and alternative hypothesis HA : mu < \$100000. It is a Single-tailed sample (left).

4. Twenty-nine percent of high school seniors get drunk each month. Here d= 0.29, so the null hypothesis H0 : d= 0.29 and alternative hypothesis HA : d != 0.29. It is a Two-tailed sample.

One-sided and two-sided tests :

In a test of whether smoking reduces life expectancies, the hypothesis are:

H0 : smoking makes no difference to life expectancy, H1 : smoking reduces life expectancy. This is an example of one-sided test,since we are only considereing the possibility of a reduction in life expectancy i.e. a change in one direction. However we would have specified the hypothesis

H0: smoking makes no difference to life expectancy, H1 : smoking affects life expectancy. This is a two-sided test, since the alternative hypothesis considers the possibility of a change in either direction i.e. increase or decrease.

The tails in a distribution are the extreme regions bounded by critical values.

Single-Tailed sample : (i) Right tailed test : H0 : = , HA : > (ii) Left tailed test : H0 : = , HA :

Two-Tailed sample: Two-tailed test : H0 : = , HA : ≠

## Some important definitions in Hypothesis Testing:

(Just go through these definitions and they will be clear at a later point of time while using)

Significance level : The significance level (denoted by 𝞪) defines how much evidence we require to reject H0 in favor of HA

Critical region : The critical region (or rejection region) is the set of all values of the test statistic that cause us to reject the null hypothesis.

Critical value : A critical value is any value that separates the critical region (where we reject the null hypothesis) from the values of the test statistic that do not lead to rejection of the null hypothesis. The critical values depend on the nature of the null hypothesis, the sampling distribution that applies, and the significance level 𝞪.

Test statistic : The test statistic is a value used in making a decision about the null hypothesis, and is found by converting the sample statistic to a score with the assumption that the null hypothesis is true.

P-value : The P-value (or p-value or probability value) is the probability of getting a value of the test statistic that is at least as extreme as the one representing the sample data, assuming that the null hypothesis is true. The null hypothesis is rejected if the P-value is very small, such as 0.05 or less.

Types of Errors :

(i) Type-1 error : A Type I error is the mistake of rejecting the null hypothesis when it is true. The symbol 𝞪 (alpha) is used to represent the probability of a type I error.

(ii) Type-2 error : A Type II error is the mistake of failing to reject the null hypothesis when it is false. The symbol 𝛽 (beta) is used to represent the probability of a type II error.

## Steps to follow in Hypothesis Testing :

Now its time we take examples and perform hypothesis testing. Here are simple steps that can make the analysis quite structured.

Step-1 : Formulating Null and Alternative hypothesis.

Step-2 : Choose a test statistic

Step-3 : Generate the sampling distribution of the test statistic.

Step-4 : Calculate the p-value

Step-5 : Define extreme values

Step-6 : Check p-value with statistical significants.

## Basic Test Statistics for single samples, two independent samples :

These formula will help in solving the hypothesis testing to calculate p- value

Single Samples :

1. Test stastic for population mean

For large samples N(0,1) can used in place of t distribution here Xbar is the sample mean, n is the sample size.

2. Test stastic for population variance

3. Test statistic for population proportion

Two independent Samples :

1. Test statistic for population means

2. Test statistic for population variance

3. Test statistic for population proportion

Instead of having theta1cap and theta2cap we can also have pooled sampled proportion.

# Example :

Now its the final step to solve the a problem !!

## 1. The annual rainfall in centimeters at a certain weather station over the last ten years has been as : 17.2, 28.1, 25.3, 26.2, 30.7, 19.2, 23.4, 27.5, 29.5, 31.6. Scientists at the weather station wish to test whether the average annual rainfall has increased from its former long-term value of 22cm. Test this hypothesis at the 5% level, stating any assumptions that you make.

1. Formulate null & alternative hypothesis — H0 : mean(mu)= 22 , H1 : mean(mu) > 22

2. Choosing Test statistic — Test statistic for mean

mean= (17.2+28.1+25.3+26.2+30.7+19.2+23.4+27.5+29.5+31.6) /10

S² = 1/9(6895.73–10* 25.87²)

Test statistic = (25.87–22)/(22.57*10)^(1/2) = 2.576

3. Sampling distribution of the test statistic if the null hypothesis was true

4. Calculate the p value

Conclusion — Using probability values P(t9 > 2.576) = 0.0166. This is less than 0.05, so we have sufficient evidence to reject null hypothesis at 5% level and conclude average annual rainfall is greater than 22cm.

Python code :

If p < 0.05 is TRUE then the assumed null hypothesis is rejected else it gets fails to reject.

We also conclude in another way, since the test statistic is greater than 1.833(the upper 5% point of the t9 distribution), so we have sufficient evidence to reject H0 at 5% level. It becomes resonable to conclude that the long-term average annual rainfall has increased from its former level.

NOTE : for single tailed the p value can be taken as it is we get in calculating p in the above code. But if it is two tailed then it should be multiplied by 2 and then significance level is checked.

# Conclusion :

Hypothesis testing is a way to test the claims by conducting simple experiments on samples from population and doing test statistic for the sample ultimately shows the claim is accepted or rejected at a significant level.

## AlmaBetter

AlmaBetter provides risk-free education with rewarding employment opportunities.

## AlmaBetter

Your home for data science. Concepts, ideas, codes and blogs from students of AlmaBetter. We are building the next-gen AI ecosystem https://www.almabetter.com

Written by

## Keerthana

Data science trainee at Almabetter

## AlmaBetter

Your home for data science. Concepts, ideas, codes and blogs from students of AlmaBetter. We are building the next-gen AI ecosystem https://www.almabetter.com

## Study on Review Scores and Comments: Airbnb Istanbul Dataset

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app