AlmaBetter Blogs > Hypothesis Testing

# Hypothesis Testing

Data Science

The types of test that we conduct is based on the alternate hypothesis (Ha) If Ha : parameter < value, then we conduct left-tailed test, where critical region lies on the left tail of the distribution.

If Ha : parameter >value, then we conduct right-tailed test, where critical region lies on the right tail of the distribution.

If Ha : parameter ≠ value, then we conduct a two-tailed test, where critical regions lie on both the left and right tails of distribution.

Test Statistic A Test statistic is a mathematical formula that allows researchers to determine the likelihood of obtaining sample outcomes if null hypothesis were true. The value of test statistic is used to make a decision regarding the null hypothesis. The larger the test statistic, the further the distance, or the number of standard deviations, a sample mean is from the population mean stated in null hypothesis. Examples of test statistics that are used in hypothesis testing are : Test statistic for proportions :

Test statistic for mean :

If standard deviation σ of population is not known, but however the sample variance is known, we use a t-statistic with (n-1) degrees of freedom, instead of z-statistic.

When we want to test the measure deviation of sample variance (S²) from the population variance (σ²), we use χ² statistic with (n-1) degrees of freedom.

P-value Approach After we are done calculating the statistic of a parameter for a given sample, We need to calculate the P-value of the given statistic. P-value is nothing but the probability of observing a sample parameter that is as or more extreme than the observed and is given by the area under the tails with limits defined according to the type of test we conduct. Lets take the example of the z-statistic that is calculated assuming that our sample parameter follows a normal distribution, which also follows from the Central Limit Theorem.

Now, we use significance levels during hypothesis testing to help us determine which hypothesis the data support. We compare your p-value to our significance level. If the p-value is less than our significance level, we can reject the null hypothesis and conclude that the effect is statistically significant. In other words, the evidence in our sample is strong enough to be able to reject the null hypothesis at the population level. Example 1: A principal at a certain school claims that the students in his school are above average intelligence. A random sample of thirty students IQ scores have a mean score of 112.5. Is there sufficient evidence to support the principal’s claim? The mean population IQ is 100 with a standard deviation of 15. Step 1: State the Null Hypothesis. The accepted fact is that the population mean is 100, so: H0: μ=100. Step 2: State the Alternate Hypothesis. The claim is that the students have above average IQ scores, so: H1: μ > 100. The fact that we are looking for scores “greater than” a certain point means that this is a right-tailed test. Step 3: State the α level. If you aren’t given an α level, use 5% (0.05). Step 4: Find the test statistic using this formula:

For this set of data: z= (112.5–100) / (15/√30) = 4.56. Step 5: Considering we are doing a right-tailed test, calculate the P-value for z statistic using the z table P-value ∼ 0.00001. Step 6: Compare the P-value to significance level α. If p < α, results are significant and null hypothesis is rejected. Else, we fail to reject the Null hypothesis. Since p < α = 0.05, we reject the null hypothesis, in favor of alternate hypothesis and effectively conclude that principal’s claim is True based on the statistical test conducted. Example 2 The average height of students in a batch is 100 cm and the standard deviation is 15. However, the teacher believes that this has changed, so he decides to test the height of 75 random students in the batch. The average height of the sample comes out to be 105. Is there enough evidence to suggest that the average height has changed? Step 1: State the Null Hypothesis. In our case it will be the average height of students in the batch is 100. H0 : μ = 100 Step 2: State the Alternate Hypothesis. In our case, the teacher claims that the actual value has changed. He doesn’t know whether the average has gone up or down, but he believes that it has changed and is not 100 anymore. Ha : μ ≠100 So if the alternate hypothesis is written with a ≠ sign that means that we are going to perform a 2-tailed test because chances are it could be more than 100 or less than 100 which makes it 2-tailed. Step 3: State the α level. If you aren’t given an α level, use 5% (0.05). Step 4: Find the test statistic using this formula:

For this set of data: z= (105–100)/(15/√7.5) = 2.89 Step 5: Considering we are doing a two-tailed test, calculate the P-value for z statistic using the z table P-value = 0.003852 Step 6: Compare the P-value to significance level α. If p < α, results are significant and null hypothesis is rejected. Else, we fail to reject the Null hypothesis. Since p < α = 0.05, we reject the null hypothesis, in favor of alternate hypothesis and effectively conclude that teacher’s claim is True that the average height of students in the batch has changed. Statistical errors We often come across terms like statistical errors as a result of conducting hypothesis tests. If the result of the test corresponds with reality, then a correct decision has been made. However, if the result of the test does not correspond with reality, then an error has occurred. There are two situations in which the decision is wrong. The null hypothesis may be true, whereas we reject H0. On the other hand, the alternative hypothesis Ha may be true, whereas we do not reject H0. Two types of error are distinguished: Type I error and type II error.

Type I error The first kind of error is the rejection of a true null hypothesis as the result of a test procedure. This kind of error is called a type I error (false positive) and is sometimes called an error of the first kind. Type II error The second kind of error is the failure to reject a false null hypothesis as the result of a test procedure. This sort of error is called a type II error (false negative) and is also referred to as an error of the second kind. Power of Hypothesis Test The power of a hypothesis test is the probability that the test rejects the null hypothesis (H0) when a specific alternate hypothesis (Ha) is true i.e., it indicates the probability of avoiding a Type-II error. The statistical power ranges from 0 to 1, and as statistical power increases, the probability of making a type II error (wrongly failing to reject the null hypothesis) decreases. If probability of making Type II error is β, power of hypothesis test is given by 1-β.