Global Academy of Technology, Bengaluru
Computer Science and Engineering
Course: Computational Data Science
Module 5: Hypothesis Testing
3.1 Testing simple hypotheses
Hypothesis testing is a tool for making statistical inferences about the population data. It is an
analysis tool that tests assumptions and determines how likely something is within a given standard
of accuracy. Hypothesis testing provides a way to verify whether the results of an experiment are
valid.
A null hypothesis and an alternative hypothesis are set up before performing the hypothesis testing.
This helps to arrive at a conclusion regarding the sample obtained from the population.
Hypothesis testing can be defined as a statistical tool that is used to identify if the results of an
experiment are meaningful or not. It involves setting up a null hypothesis and an alternative
hypothesis. These two hypotheses will always be mutually exclusive. This means that if the null
hypothesis is true then the alternative hypothesis is false and vice versa.
What is Hypothesis Testing in Statistics?
Hypothesis testing uses sample data from the population to draw useful conclusions regarding the
population probability distribution. It tests an assumption made about the data using different types
of hypothesis testing methodologies. The hypothesis testing results in either rejecting or not
rejecting the null hypothesis.
Hypothesis testing can be defined as a statistical tool that is used to identify if the results of an
experiment are meaningful or not. It involves setting up a null hypothesis and an alternative
hypothesis. These two hypotheses will always be mutually exclusive. This means that if the null
hypothesis is true then the alternative hypothesis is false and vice versa. An example of hypothesis
testing is setting up a test to check if a new medicine works on a disease in a more efficient manner.
Null Hypothesis
The null hypothesis is a concise mathematical statement that is used to indicate that there is no
difference between two possibilities. In other words, there is no difference between certain
characteristics of data. This hypothesis assumes that the outcomes of an experiment are based on
chance alone. It is denoted as H0. Hypothesis testing is used to conclude if the null hypothesis can
be rejected or not. Suppose an experiment is conducted to check if girls are shorter than boys at the
age of 5. The null hypothesis will say that they are the same height.
Alternative Hypothesis
The alternative hypothesis is an alternative to the null hypothesis. It is used to show that the
observations of an experiment are due to some real effect. It indicates that there is a statistical
significance between two possible outcomes and can be denoted as H1 or Ha. For the above-
mentioned example, the alternative hypothesis would be that girls are shorter than boys at the age of
5
Hypothesis Testing P Value
In hypothesis testing, the p value is used to indicate whether the results obtained after conducting a
test are statistically significant or not. It also indicates the probability of making an error in rejecting
or not rejecting the null hypothesis. This value is always a number between 0 and 1. The p value is
compared to an alpha level, α or significance level. The alpha level can be defined as the acceptable
risk of incorrectly rejecting the null hypothesis. The alpha level is usually chosen between 1% to
5%.
Hypothesis Testing Formula
Depending upon the type of data available and the size, different types of hypothesis testing are
used to determine whether the null hypothesis can be rejected or not. The hypothesis testing formula
for some important test statistics are given below:
Types of Hypothesis Testing
Selecting the correct test for performing hypothesis testing can be confusing. These tests are used to
determine a test statistic on the basis of which the null hypothesis can either be rejected or not
rejected. Some of the important tests used for hypothesis testing are given below.
1. Hypothesis Testing Z Test
A z test is a way of hypothesis testing that is used for a large sample size (n ≥ 30). It is used to
determine whether there is a difference between the population mean and the sample mean when the
population standard deviation is known. It can also be used to compare the mean of two samples. It
is used to compute the z test statistic. The formulas are given as follows:
2. Hypothesis Testing t Test
The t test is another method of hypothesis testing that is used for a small sample size (n < 30). It is
also used to compare the sample mean and population mean. However, the population standard
deviation is not known. Instead, the sample standard deviation is known. The mean of two samples
can also be compared using the t test.
3. Hypothesis Testing Chi Square
The Chi square test is a hypothesis testing method that is used to check whether the variables in a
population are independent or not. It is used when the test statistic is chi-squared distributed.
One Tailed Hypothesis Testing
One tailed hypothesis testing is done when the rejection region is only in one direction. It can also
be known as directional hypothesis testing because the effects can be tested in one direction only.
This type of testing is further classified into the right tailed test and left tailed test.
1. Right Tailed Hypothesis Testing
The right tail test is also known as the upper tail test. This test is used to check whether the
population parameter is greater than some value. The null and alternative hypotheses for this test are
given as follows:
H0: The population parameter is ≤ some value
H1: The population parameter is > some value.
If the test statistic has a greater value than the critical value then the null hypothesis is rejected
2. Left Tailed Hypothesis Testing
The left tail test is also known as the lower tail test. It is used to check whether the population
parameter is less than some value. The hypotheses for this hypothesis testing can be written as
follows:
H0: The population parameter is ≥ some value
H1: The population parameter is < some value.
The null hypothesis is rejected if the test statistic has a value lesser than the critical value.
Two Tailed Hypothesis Testing
In this hypothesis testing method, the critical region lies on both sides of the sampling distribution.
It is also known as a non - directional hypothesis testing method. The two-tailed test is used when it
needs to be determined if the population parameter is assumed to be different than some value. The
hypotheses can be set up as follows:
H0: the population parameter = some value
H1: the population parameter ≠ some value
The null hypothesis is rejected if the test statistic has a value that is not equal to the critical value.
Hypothesis Testing Steps
Hypothesis testing can be easily performed in five simple steps. The most important step is to
correctly set up the hypotheses and identify the right method for hypothesis testing. The basic steps
to perform hypothesis testing are as follows:
Step 1: Set up the null hypothesis by correctly identifying whether it is the left-tailed, right-tailed, or
two-tailed hypothesis testing.
Step 2: Set up the alternative hypothesis.
Step 3: Choose the correct significance level, α, and find the critical value.
Step 4: Calculate the correct test statistic (z, t or χ) and p-value.
Step 5: Compare the test statistic with the critical value or compare the p-value with α to arrive at a
conclusion. In other words, decide if the null hypothesis is to be rejected or not.
What is F Test in Statistics?
F test in statistics is a test that is performed on an f distribution. A two-tailed f test is used to check
whether the variances of the two given samples (or populations) are equal or not. However, if an f
test checks whether one population variance is either greater than or lesser than the other, it
becomes a one-tailed hypothesis f test.
F Test Definition
F test can be defined as a test that uses the f test statistic to check whether the variances of two
samples (or populations) are equal to the same value. To conduct an f test, the population should
follow an f distribution and the samples must be independent events. On conducting the hypothesis
test, if the results of the f test are statistically significant then the null hypothesis can be rejected
otherwise it cannot be rejected.
Define the concept of F-test statistic, with respect to large and small size samples. Also,
list the F-test expression for left tailed, right tailed and two tailed tests.
F Statistic
The f test statistic or simply the f statistic is a value that is compared with the critical value to
check if the null hypothesis should be rejected or not. The f test statistic formula is given
below:
F Test Formula
The f test is used to check the equality of variances using hypothesis testing. The f test formula for
different hypothesis tests is given as follows:
3.4 F-Distribution
The F-distribution, also known Fisher-Snedecor distribution, is extensively used to test for
equality of variances from two normal populations.
Additionally, the f-distribution is the ratio of the X1 random chi-square variable with degrees
of freedom ϑ1 and the X2 random chi-square variable with degrees of freedom ϑ2. In other
words, each Chi-Square random variable has been divided by its degrees of freedom.
F-test is to determine whether the two independent estimates of population variance differ
significantly. In this case, F-ratio is:
or
To find out whether the two samples drawn from the normal population have the same
variance. In this case, F-ratio is:
F Test Critical Value
A critical value is a point that a test statistic is compared to in order to decide whether to
reject or not to reject the null hypothesis. Graphically, the critical value divides a distribution
into the acceptance and rejection regions. If the test statistic falls in the rejection region then
the null hypothesis can be rejected otherwise it cannot be rejected. The steps to find the f test
critical value at a specific alpha level (or significance level), α, are as follows:
Find the degrees of freedom of the first sample. This is done by subtracting 1 from
the first sample size. Thus, x = n1−1.
Determine the degrees of freedom of the second sample by subtracting 1 from the
sample size. This given y = n2−1.
If it is a right-tailed test then α is the significance level. For a left-tailed test 1 – α
is the alpha level. However, if it is a two-tailed test then the significance level is
given by α/ 2.
The F table is used to find the critical value at the required alpha level.
The intersection of the x column and the y row in the f table will give the f test
critical value.
ANOVA F Test
The one-way ANOVA is an example of an f test. ANOVA stands for analysis of variance. It is
used to check the variability of group means and the associated variability in observations
within that group. The F test statistic is used to conduct the ANOVA test. The hypothesis is
given as follows:
H0: The means of all groups are equal.
H1: The means of all groups are not equal.
Test Statistic: F = explained variance / unexplained variance
Decision rule: If F > F critical value then reject the null hypothesis.
To determine the critical value of an ANOVA f test the degrees of freedom are given by df1=
K - 1 and df1 = N - K, where N is the overall sample size and K is the number of groups.
3.5 Bayes Test Procedures
Suppose that we need to decide between two hypotheses H0 and H1. In the Bayesian setting,
we assume that we know prior probabilities of H0 and H1. That is, we know P(H0) =
p0 and P(H1) = p1, where p0+p1=1. We observe the random variable (or the random
vector) Y. We know the distribution of Y under the two hypotheses, i.e, we know
One way to decide between H0 and H1 is to compare P(H0|Y=y) and P(H1|Y=y), and accept
the hypothesis with the higher posterior probability. This is the idea behind the maximum a
posteriori (MAP) test. Here, since we are choosing the hypothesis with the highest probability,
it is relatively easy to show that the error probability is minimized.
To be more specific, according to the MAP test, we choose H0 if and only if
Note that as always, we use the PMF instead of the PDF if Y is a discrete random variable.
We can generalize the MAP test to the case where you have more than two hypotheses. In that
case, again we choose the hypothesis with the highest posterior probability.
3.6 Case studies based on Hypothesis Testing
1. Determine the null hypothesis and the alternative hypothesis.
2. Collect and summarize the data into a test statistic.
3. Use the test statistic to determine the p-value.
4. The result is statistically significant if the p-value is less than or equal to the level of
significance.