0% found this document useful (0 votes)
114 views108 pages

STAT - Day 2-2

This document discusses estimation and hypothesis testing in statistics. It covers point estimation using sample statistics to estimate population parameters, sampling error due to using samples rather than entire populations, and interval estimation using confidence intervals to provide a range of plausible values for the population parameter. Hypothesis testing is introduced as a method to test statistical significance and make decisions about claims regarding populations.

Uploaded by

Anand Umarji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views108 pages

STAT - Day 2-2

This document discusses estimation and hypothesis testing in statistics. It covers point estimation using sample statistics to estimate population parameters, sampling error due to using samples rather than entire populations, and interval estimation using confidence intervals to provide a range of plausible values for the population parameter. Hypothesis testing is introduced as a method to test statistical significance and make decisions about claims regarding populations.

Uploaded by

Anand Umarji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 108

Theory of Estimation and

Hypothesis Testing

Introduction to Statistics
Agenda

● Theory of Estimation
○ Point estimation
○ Sampling error
○ Interval estimation

● Hypothesis Testing
○ Terminologies
○ Decision making method
○ Test based on Z statistic
○ Error in hypothesis testing
Estimation
Inferential statistics
Inferential
Statistics

Theory of Testing of
Estimation Hypothesis

Estimating the population parameter Test the statistical


from the sample significance of a claim

Point Interval
Estimation Estimation
Point Estimation
Estimate
Question:

What would be the average income of a 27-year-old in London? How would you
calculate it?
Estimate
Solution:

The trivial way is to collect the income data of every 27-year-old, further compute
its mean.

This mean would be the population mean.


Point estimation

Is this scenario feasible? Is it possible to collect data of every 27-year-old person?

● To do so, draw a sample of size n and compute the mean.

● This sample mean is the point estimate of the population mean


Point estimation

● The sample estimate is considered to be the point estimate of the population


parameter

● If population parameters are not known they are estimated from the sample

● The point estimate of

○ population mean ( ) is sample mean (µ)

○ population variance (σ) is sample variance s 2

○ Population proportion (P) is sample proportion (p)


Point Estimate
Question:

A financial firm has created 50 portfolios. From them a sample of 13 portfolios was
selected, out of which 8 were found to be underperforming. Estimate the number of
underforming portfolios?
Point Estimate
Solution:

A financial firm has created 50 portfolios. Thus N = 50


From them a sample of 13 portfolios was selected. Thus n = 13
The desired category is of underperforming portfolios. 8 of 13 were found to be
underperforming. Thus x = 8

To find: Estimate the number of underperforming portfolios


Point Estimate
Solution:

The estimate of proportion of underperforming portfolios is given by

To estimate the number of underperforming portfolios multiply by the estimate by N.


Point Estimate
Python solution:
Demerits of point estimate

● In most of the scenarios, the point estimate is not accurate

● It is the single value representation of the population that differs with each sample

● The deviation of the point estimate from the population parameter gives rise to
sampling error

Sample means of
different samples m2 m3 m1 m4
Sampling error

● Sampling error is the absolute difference between the population parameter and its
sample statistic (point estimate)

● Since the entire population is not considered as the sample, the values of mean,
median, quantiles, and so on calculated on sample differ from the actual population
values

● In order to reduce sampling error increase the sample size


Sample Error
Question:

The average temperature on a summer morning in Alaska is 55oF. The research student of
climate studies records the temperature for 15 summer mornings in oF.

Data = [49.8, 52.3, 51, 56.9, 54.8, 63, 58.2, 54.1, 50.4, 49.2, 47, 51.3, 43.5, 56, 55]

Find the sampling error for the average temperature.


Interval Estimation
Need of interval estimation

● The point estimate is taken from a particular sample

● For a different sample, we get a different estimate (sampling variability)

● This problem is resolved if we obtained the interval estimate

Point Interval
estimate estimate
Interval Estimation

● Interval estimate is a range or an interval within which the parameter lies for a stated
confidence level

● Based on the central limit theorem

● It is known as the confidence interval


Confidence level

● Confidence level (1-α) is the percentage of all possible point estimates that can be
expected to include the actual population parameter

● α is known as the level of significance

● The higher confidence level illustrates the wider confidence interval

● A 95% confidence level implies that 95% of the confidence intervals would include the
actual population parameter
Confidence level

Example:

The average income estimate for a 27-year-old in London is £45,000. After taking
repeated samples, the 99% confidence intervals of the average income include the
actual population parameter for 99% of the times.
Recall - CLT

For random samples of large size n taken from a single population with mean µ and
standard deviation σ, the sampling distribution of mean follows a normal distribution with
mean µ and standard deviation σ/√n
Interval estimate

From the CLT, P(-z α/2 ≤Z ≤z α/2) = 1 - α

Where α is is the level of significance


Interval estimate

From the CLT, P(-z α/2 ≤Z ≤z α/2) = 1 - α

Value of α Zα/2 Value of Zα/2

0.10 z0.05 1.645

0.05 z0.025 1.96

0.01 z0.005 2.575

Note: To obtain these values in python use scipy.stats.norm.isf()


Interval estimate

From the CLT, P(-zα/2 ≤Z ≤ zα/2) = 1 - α and value of Z is

Thus, P(-zα/2 ≤ ≤z α/2) = 1 - α

Rearranging the terms, P( ) =1 - α

This defines a 100(1 - α)% confidence interval


as
Interval estimate

The 100(1 - α)% confidence interval is

Point Margin of error


Estimate
Margin of error
Question:

100 bags of coal were tested and had an average of 35% of ash with a standard deviation
of 15%. Calculate the margin of error for a 90% confidence level.
Margin of error
Solution:

100 bags of coal were tested and had an average of 35% of ash with a standard deviation
of 15%.
Here n =100
σ = 0.15

To find: The margin of error for a 90% confidence level.

Here α = 0.10. Thus z α/2 = 1.64


Margin of error
Solution:

The margin of error for a 90% confidence level is

A 90% CI with 2.46% margin of error implies that the sample mean will be within 2.46%
points of the real population value 90% of the time
Margin of error
Python solution:
● As sample size increases the margin of error decreases

● If margin of error is fixed then the sample size can be obtained


Sample size
Question:

For the previous question, for a margin of error 2.46. Verify whether you get sample size of
100.

Previous Question: 100 bags of coal were tested and had an average of 35% of ash with a
standard deviation of 15%. Calculate the margin of error for a 90% confidence level.
Interval estimate
Question:

From a sample of 250 observations it is found that average income of a 27-year-old


Londoner is £45,000 with a sample standard deviation of £4000. Obtain the 95%
confidence interval to estimate the average income.
Interval estimate
Solution:

A sample of 250 observations of a 27-year-old Londoner has an average income of £45,000


with a sample standard deviation of £4000

Thus, = 45,000, σ = 4000 and n = 250

To find: The 95% confidence interval.

Here α = 0.05. So z 0.025 = 1.96


Interval estimate
Solution:

The 95% confidence interval is


Interval estimate
Python solution:
● It cannot be said that P(44504.155≤ µ ≤45495.845) = 0.95

● The population parameter µ is a constant

● It can be said that from many samples drawn of size 250, construct a 95% CI for each
sample, roughly 95% of the intervals would actually contain the population parameter
µ
Confidence Interval

Question:

For the previous question, obtain the 90% and 99% confidence intervals. Further,
logically explain which one of them is the widest.
Interval estimate

The 100(1 - α)% confidence interval for proportion is

Point Margin of error


Estimate
Interval estimate
Question:

A financial firm has created 50 portfolios. From them a sample of 13 portfolios was
selected, out of which 8 were found to be underperforming. Construct a 99% confidence
interval to estimate the population proportion.
Interval estimate
Solution:

From them a sample of 13 portfolios was selected. Thus n = 13


The desired category is of underperforming portfolios. 8 of 13 were found to be
underperforming. Thus x = 8
Thus the estimate of sample proportion is x/n = 8/13 =0.615

To find: Construct a 99% confidence interval to estimate the population proportion.


Interval estimate
Solution:

Here α = 0.01. So z 0.005 = 2.575

The 95% confidence interval is


Interval estimate
Python solution:
Summary

● Sample estimate of a population parameter is considered as a point estimate

● Sample mean, median, standard deviation are the examples of the point estimate

● Point estimate varies significantly for different samples

● Confidence interval returns the interval estimate for the population parameter

● The confidence level describes the uncertainty of the estimate

● Confidence interval is calculated using the point estimate and the margin of error

● The optimal sample size can be obtained by deciding the required margin of error
Inferential statistics

Inferential
Statistics

Theory of Testing of
Estimation Hypothesis

Estimating the population parameter Test the statistical


from the sample significance of a claim

Non-Parametric Parametric
Tests Tests
Testing of Hypothesis
Question:

A manufacturer produces batteries. He claims that the life of his batteries is 25,500 hours.
Can we verify his claim?
Solution:

A trivial solution is to obtain the life of all the batteries produced by the manufacturer by
using them and thereafter verify this claim

However, by doing so all the manufactured products (batteries) will be exhausted and he
will not have any batteries to sell.

To avoid such scenarios, we statistically test the hypothesis


What is a hypothesis?

A hypothesis is a claim about the population parameter

Examples:

● The average diameter of bolts manufactured is 200 cm

● The new drug is more effective


Hypothesis - example

A pharmaceutical has claimed to


have produced a new drug is Hypothesis
effective against cancer treatment.

To test the pharmaceuticals claim,


Null Alternative
first write the test hypotheses - Hypothesis Hypothesis
Null Hypothesis and the
Alternative Hypothesis
Null and alternative hypothesis

Hypothesis

Null Alternative
Hypothesis Hypothesis

● Hypothesis of no change ● It directly contradicts the null hypothesis

● Denoted by H 0 ● Also known as research hypothesis

● Denoted by H a or H1
Hypothesis - example

A pharmaceutical has claimed to have produced a new drug which treats the patients
against cancer.

Hypothesis

Null Alternative
Hypothesis Hypothesis

H0: The new drug is H1: The new drug


not effective is effective
Hypothesis - example

● Now consider the effectiveness of the new drug is determined by the number of days
a patient requires to recover.

● The data for the number of days the patient take to recover are recorded

● Let the random variable X be the number of days required to recover

● Thus µ is the average number of days required to recover


State the hypothesis

Hypothesis
It is claimed that the new drug
reduces the recovery time

µ: the average number of days Null Alternative


required to recover Hypothesis Hypothesis

H 0 : µ ≥ µ0 H 1 : µ < µ0
Here, µ0 is the general recovery
time
Hypothesis testing

● The null and alternative hypothesis are contrasting

● Either the null or the alternative hypothesis can be true

● The decision of the test procedure is one of the following:

○ Reject H 0 implies the null hypothesis is false

○ Fail to reject H 0 implies the null hypothesis is true


“Fail to reject H0”
● The null hypothesis is assumed to be true unless proven to be otherwise

● The null hypothesis gets the benefit of doubt

● The alternative hypothesis has the burden of proof, i.e. from the data it will
have enough evidence to say the null hypothesis is false

● Hence, it is preferred to say ‘fail to reject H0’ instead of accept H0


Question:

Write the null and alternative hypothesis for the following scenarios:

1. A bolt manufacturing company claims that the average number of he manufactures in


a day is 60
2. The new virus testing kit takes 20 hours less time than usual testing kit that takes 34
hours for the results
3. An analyst wants to test whether the Apple Inc. has outperformed in 2019 by 13.5%
1. A bolt manufacturing company claims that the average number of bolts he
manufactures in a day is 60
Solution:

The null and alternative hypothesis for the following scenarios:

Let X: the number of bolts manufactured in a day and

µ: the average number of bolts manufactured in a day

H 0: µ = 60 Against H 1: µ ≠60
Two tailed test

Two-tailed test is a method in which the critical region of a distribution is split in its two tails.
It tests whether a sample is greater than or less than the population parameter.
A critical region is a region in which the null hypothesis is rejected. It is also known as
‘Rejection Region’.

Example

Let X: the number of bolts manufactured in a day and

µ: the average number of bolts manufactured in a day

H 0: µ = 60 Against H 1: µ ≠60 α/2 α/2


2. The new virus testing kit takes less time than usual testing kit that takes 34 hours
for
the results

Solution:

The null and alternative hypothesis for the following scenarios:


Let X: the time required for the results by a testing kit

µ: the average time required for the results by a testing kit

H 0: µ ≥34 Against H 1: µ < 34


Left tailed test

A left-tailed test is a statistical hypothesis test set up to show that the sample parameter
would be lower than the population parameter.

Example

Let X: the time required for the results by a testing kit

µ: the average time required for the results by a testing kit

H 0: µ ≥34 Against H 1: µ < 34 α


3. An analyst wants to test whether the Apple Inc. has outperformed in 2019 by
13.5%

Solution:

The null and alternative hypothesis for the following scenarios:


Let X: the performance of Apple Inc. stock

µ: the average performance of Apple Inc. stock

H 0: µ ≤13.5 Against H 1: µ > 13.5


Right tailed test

A right-tailed test is a statistical hypothesis test set up to show that the sample parameter
would be higher than the population parameter.

Example

Let X: the performance of Apple Inc. stock

µ: the average performance of Apple Inc. stock

α
H 0: µ ≤13.5 Against H 1: µ > 13.5
Write the null and alternative hypothesis and identify the type of the test.

● To test the hypothesis that the mean diastolic blood pressure for a group of 85 adults
is less than 90mm

● The tensile strength of an alloy is more than 500 Pa

● The average heart rate of a healthy human is 85 beats per minute

● The yield BT cotton is more than 450 kg lint per hectare


Summary

Example Hypothesis Test Type

The company manager claims that the H0: μ =


average weight of cookies in a gift box Two Tailed Test
235 H1: μ
is 235 gm
≠ 235

The station officer claims that the H0: μ ≥ 2


bullet train takes less than 2 hours Left Tailed Test
from London to Brussels H1: μ < 2

H0: μ ≤
To test whether the average number
Right Tailed Test
of boat rides are more than 10 per day 10 H1: μ
> 10
Errors in Hypothesis Testing
Probability of committing an error

● P(Type I error) is the probability of wrongly rejecting a true null hypothesis

● It is the level of significance (α) set for the hypothesis

● An α of 0.05 suggests that one is willing to accept a 5% chance that you reject a true
null hypothesis

● In order to lower this risk, set a lower α. However, it will be more difficult to reject the
false null hypothesis
Error in hypothesis testing

Test Decision

Reject H 0 Accept H0

Type I error Correct Conclusion


H0 is True
Wrongly reject true H0 Correctly accept true H0
Actual
Situation Correct Conclusion Type II error
H0 is False
Correctly reject false H 0 Wrongly accept false H 0
Probability of committing an error

● P(Type II error) is the probability of wrongly accepting a false null hypothesis

● Denoted by β

● 1 - β is the power of the test, i.e. correctly rejecting a false null hypothesis

● In order to lower the risk of type II error, ensure the power of the test is high

● In python, we calculate the power of a Z test using the ‘power.zt_ind_solve_power()’


from statsmodels library
Controlling the errors

● Both errors cannot be controlled simultaneously

● Fix one error and minimize the other

● Generally α is fixed and β is controlled


Decision Making Methods
Hypothesis Testing Procedure
Decision making methods

● Test statistic, p-value and confidence interval are the three different criterias to test
the acceptance/ rejection of null hypothesis

● Test statistic is a sample statistic that is used to conduct a hypothesis test

● The p-value criteria returns the probability of getting the value greater than or equal to
the test statistic

● The null hypothesis is accepted if the confidence interval contains the specified
population parameter
Test statistic

● The decision whether to accept or reject the null hypothesis is based on the test
statistic value

● Depending upon the problem in hand the test statistic changes

● The test statistic is used to quantify the sample data that distinguishes the null and
alternative hypothesis

● The sampling distribution of a test statistic under the null hypothesis is used to
calculate the p-value
Procedure - using test statistic
P -value
● P-value is the probability associated with the test statistic
● P-value or ‘Calculated probability’ is the probability of finding the observed, or
more extreme, results when the null hypothesis (H0) of a study is true
● If the test statistic is available, the p-value is the probability of getting
observations equal to the test statistic as well as more extreme than the test
statistic given the distribution of observations
○ If p-value is less than 0.05 as obtained from the test statistic, it means that
there is less than 5 percent chance of getting the value of the test statistic
value as computed from the sample if the null hypothesis is true
○ In case of p-value is less than 0.05 (or less than the chosen significance
level), the null hypothesis is rejected and if it is more, then the null
hypothesis is accepted
The p-value

● The p-value is the mostly used criteria while performing the hypothesis test

● It is the probability of getting a value greater than or equal to the test statistic

● If T is the test statistic and T0 is calculated value then observed level of significance or
p-value is P(T>T0| H 0 is true)

● The test is significant if the p-value is less than or equal to the level of significance (α)
The p-value

● The smaller p-value supports the alternative hypothesis, as it exhibits the difference
between the observed data and the null hypothesis
Procedure - using p-value
Procedure - using confidence interval
Tests based on Z statistic
Tests based on Z statistic

Assumptions:

● The data is continuous in nature

● The sample is assumed to be drawn from a population following the normal


distribution

● The sample is a simple random sample (each observation is equally likely to be


drawn)
Test for normality
● The hypothesis to test whether the population is normally distributed

H0: The data is normal against H1: The data is not normal

● Failing to reject H0, implies that the data is normally distributed

● The Shapiro-Wilk test is used

Note: The python code for Shapiro test is scipy.stats.shapiro(Sample)


Two tailed test

● The hypothesis to test whether the population mean is equal to a specified value

H 0 : µ = µ0 against H 1 : µ ≠µ0

● It implies

H0: The population mean is equal to µ0

against H1: The population mean is not equal to µ0

● Failing to reject H 0 implies that population mean is equal to µ0


Left tailed test

● The hypothesis to test whether the population mean is equal to a specified value

H 0 : µ ≥µ0 against H 1 : µ < µ0

● It implies

H0: The population mean is equal to µ0

against H1: The population mean is less than µ0

● Failing to reject H 0 implies that population mean is equal to µ0


Right tailed test

● The hypothesis to test whether the population mean is equal to a specified value

H 0 : µ ≤µ0 against H 1 : µ > µ0

● It implies

H0: The population mean is equal to µ0

against H1: The population mean is more than µ0

● Failing to reject H 0 implies that population mean is equal to µ0


Tests based on Z statistic

● The test statistic Z is given by


S ample mean S pecified mean

Population standard deviation S ample size

● Under H0, the test statistic follows normal distribution


The python code to conduct a Z test for population mean is

statsmodels.stats.weightstats.ztest(sample, value, alternative)


Decision rule

Based on
H1 Based on critical region Based on p-value
confidence interval

For two tailed test µ ≠ µ0 Reject H0 if |Z|> Zα/2


Reject H 0 if p-value
Reject H 0 if µ0
is less than or
For left tailed test µ < µ0 Reject H0 if Z < -Zα does not lie in the
equal to the level
confidence interval
of significance
For right tailed test µ > µ0 Reject H0 if Z > Zα
Two tailed test
Question:

A car manufacturing company claims that the mileage of their new car is 25 kmph with a
standard deviation of 2.5 kmph. A random sample of 45 cars was drawn and recorded their
mileage as per the standard procedure. From the sample, the mean mileage was seen to
be 24 kmph. Is this evidence to claim that the mean mileage is different from 25kmph?
(assume normality of data)

Test the claim using critical region technique, p-value technique and confidence interval
technique. [Use α = 0.01].
Two tailed test
Solution:

A car manufacturing company claims that the mileage of a car is 25 kmph with a standard
deviation of 2.5 kmph.
Thus µ = 25 kmph and σ = 2.5 kmph

A random sample of 45 cars was drawn and recorded their mileage as per the standard
procedure. From the sample, the mean mileage was seen to be 24 kmph.
Thus = 24 kmph and n = 45

To find: Evidence to claim that the mean mileage is different from 25kmph
Two tailed test
Solution:

Here X: the mileage of the new car


X~N(µ,σ2)

To test, H 0 : µ = 25 against H 1 : µ ≠ 25

Obtain the solution using critical region technique.

The test statistics:


Two tailed test
Solution:

The test statistics:

Here α = 0.01, so z 0.005 = 2.575


-2.575 2.575

Decision: Reject H0, if |Zcalc| > Zα/2. Here |-2.68| > 2.575.

Thus reject H0.


Thus there is enough evidence to conclude that the mean mileage is different from 25 kmph.
Two tailed test
Solution:

Let us obtain the decision using the p-value method.

The p-value = 2 .P(|Z| > |Z calc |, under H 0)


= 2 .P(|Z| > 2.68, µ = 25) … (due to symmetricity)
= 0.0074 2.68

Since p-value < 0.01, we reject H 0.


Thus there is enough evidence to conclude that the mean mileage is different from 25 kmph.
Two tailed test
Solution:

Solution using confidence interval method.

The confidence interval is given by

The CI = ( ) =( )
=

Since µ0 = 25, does not lie in (23.05, 24.95), we reject H0.


Thus there is enough evidence to conclude that the mean mileage is different from 25 kmph.
Two tailed test
Python solution: Calculate Zcalc

Reject H 0, as |Z calc| > Z α/2. Here |-2.68| > 2.575


Two tailed test
Python solution: Calculate p-value

Since p-value < 0.01, we reject H 0.


Two tailed test
Python solution: Calculate 99% confidence interval

Since µ0 = 25, does not lie in the confidence interval, we reject H0.
Left tailed test
Question:

A sample of 900 PVC pipes is found to have an average thickness of 12.5 mm. Can we
assume that the sample is coming from a normal population with mean 13mm against that
it is less than 13 mm. The population standard deviation is 1 mm. Test the hypothesis using
the p-value method at 5% level of significance.
Left tailed test
Solution:

Here X: the thickness of PVC pipes


X~N(µ,σ2)

Here, µ = 13mm , σ = 1 mm, = 12.5, n = 900

To test, H 0 : µ ≥13 against H 1 : µ < 13

Obtain the solution using p-value technique.


Left tailed test
Solution:

The test statistics:

The p-value = P(Z < Zcalc, under H0) = P(Z < -15, µ = 13) = 0.00

Since p-value < 0.05, we reject H 0.


Thus there is enough evidence to conclude that the sample may not be regarded as coming
from population with mean 13
Left tailed test
Python solution: Calculate p-value

Since p-value < 0.05, we reject H 0.


Right tailed test
Question:

An e-commerce company claims that the mean delivery time of food items on their website
in NYC is 60 minutes with a standard deviation of 30 minutes. A random sample of 45
customers ordered from the website, and the mean time for delivery was found to be 75
minutes. Is this enough evidence to claim that the mean time to get items delivered is more
than 60 minutes. (assume normality of data)

Test the claim using p-value technique. [Use α = 0.05].


Right tailed test
Solution:

Here X: Time (in minutes) to receive the delivery


X~N(µ,σ2)

Here, µ = 60 , σ = 30, = 75, n = 45

To test, H 0 : µ ≤60 against H 1 : µ > 60

Obtain the solution using p-value technique.


Right tailed test
Solution:

The test statistics:

The p-value = P(Z > Zcalc, under H0) = P(Z > 3.35, µ = 60) = 0.0004

3.35

Since p-value < 0.05, we reject H 0.


Thus there is enough evidence to conclude that the mean delivery time is more than 60 min
Right tailed test
Python solution: Calculate p-value

Since p-value < 0.05, we reject H 0.


Summary

● The Z test can be used if the sample data is drawn from a normally distributed
population

● The normality of the dataset can be checked using Shapiro-Wilk test

● Two tailed as well as one tailed (left/ right) Z test can be performed

● The test statistic for the Z test follows normal distribution under the null hypothesis

● The test statistic, p-value and confidence interval can be used to analyze the
significance of the test
Thank You

You might also like