Hypothesis Testing in Statistics
Hypothesis Testing in Statistics
Engineers
• Represented by H0
• The Null Hypothesis says that the effect indicated by the sample is due
only to random variation between the sample and the population.
• In scientific research, the null hypothesis is the claim that the effect
being studied does not exist.
Mathematics for Computer Science Engineers
Alternate Hypothesis
• Represented by H1
• The Alternate Hypothesis says that the effect indicated by the sample is
real, in that it accurately represents the whole population.
Hypothesis Testing
Example:
A coin was flipped 50 times, resulting in 40 Heads and 10 Tails.
Example:
A new type of battery will be installed in heart pacemakers if it can be shown to
have a mean lifetime is greater than eight years.
Mathematics for Computer Science Engineers
Introduction
• If sample data are not consistent with the statistical hypothesis, the
hypothesis is rejected.
Mathematics for Computer Science Engineers
Note:
In any hypothesis test, we are calculating conditional probabilities based on the
assumption that the null hypothesis is true.
P-value: measures the plausibility of H0. The smaller the P-value, the stronger the
evidence is against H0.
Note:
It is natural to ask how small the P-value should be in order to reject H0.
Some people use the “5% rule”; they reject H0 if P ≤ 0.05.
Mathematics for Computer Science Engineers
Conclusions from hypothesis
Note:
Hypothesis Test Population S.D. Population
known S.D.
unknown
𝑛 < 30 Small sample Use z- test Use t-test
drawn from Normal
population
𝑛 ≥ 30 Large sample Use z- test Use z- test
Or t- test
Mathematics for Computer Science Engineers
Topics Covered
Solution continued:
• We got 𝑷 − 𝒗alue is 𝟎. 𝟐𝟎𝟗 .
Solution:
𝑯𝟎 ∶ 𝝁 = 𝟏𝟎𝟎𝟎 𝒗𝒆𝒓𝒔𝒖𝒔 𝑯𝟏 ∶ 𝝁 ≠ 𝟏𝟎𝟎𝟎.
We assume 𝑯𝟎 is true
𝒛 𝟏𝟎𝟎𝟎. 𝟔−1000
𝟎. 𝟐𝟓𝟖
= 𝟐. 𝟑𝟐
Solution continued:
• The P-value is the sum of the areas in both of these tails, which is 0.0204.
Example:
• A coin was tossed 400 times and the head turned up 216 times. Test
the hypothesis that the coin is unbiased?
Mathematics for Computer Science Engineers
Large-Sample Tests for a Population Mean
Example:
• A coin was tossed 400 times and the head turned up 216 times. Test
the hypothesis that the coin is unbiased?
Solution:
𝟏
𝑯𝟎: 𝒑 = 𝟐
𝟏
𝑯𝟏 ∶ 𝒑 ≠ 𝟐
𝒙 − 𝒏𝒑
𝒛= = 𝟏. 𝟔
𝒏𝒑𝒒
Mathematics for Computer Science Engineers
Large-Sample Tests for a Population Mean
Example:
• A trucking firm is suspicious of the claim that the average lifetime of certain
tires is at least 28,000 miles.
• To check the claim, the firm puts 40 of these tires on its trucks and gets a
mean lifetime of 27,463 with a standard deviation 1,348 miles.
Solution:
𝑯𝟎: 𝝁 ≥ 𝟐𝟖, 𝟎𝟎𝟎 𝒎𝒊𝒍𝒆𝒔
P – Value is 0.0059
Since P- Value is a very small probability we need to reject 𝑯𝟎
Mathematics for Computer Science Engineers
Large-Sample Tests for a Population Mean
• [Link]
• [Link]
• “Statistics for Engineers and Scientists”, William Navidi, McGraw Hill Education, India, 4th Edition, 2015.
Dr. Deepa Nair
Department of Science and Humanities
PES University, Bangalore
Mathematics for Computer
Science Engineers
❖Statistical significance.
p-value Approach
• The region on the side of the critical point that leads to rejection is
called the rejection region.
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
The null hypothesis, on the other hand, either is true or is not true.
The truth or falsehood of H0 cannot be changed by repeating the
experiment.
It is therefore not correct to discuss the “probability” that H0 is true.
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
Statistical Significance Is Not the Same as Practical Significance:
Textbook: Page
Mathematics for Computer Science Engineers
Drawing Conclusions from the Results of Hypothesis Tests
• What it does measure is the degree of confidence we can have that the true
value is really different from the value specified by the null hypothesis.
• When the P-value is small, then we can be confident that the true value is
really different.
• This does not necessarily imply that the difference is large enough to be of
practical importance.
Mathematics for Computer Science Engineers
MCQS/true or false
True or false:
If P = 0.02, then
Ans:
(a) True. The result is statistically significant at any level greater than or equal to2%.
(b) False. P > 0.01, so the result is not statistically significant at the 1% level.
(c) True. The null hypothesis is rejected at any level greater than or equal to 2%.
(d) False. P > 0.01, so the null hypothesis is not rejected at the 1% level.
Mathematics for Computer Science Engineers
MCQS/true or false
2) George performed a hypothesis test. Luis checked George’s work by redoing the
calculations. Both George and Luis agree that the result was statistically significant
the 5% level, but they got different P-values. George got a P-value of 0.20 and Luis
got a P-value of 0.02.
a) Is it possible that George’s work is correct? Explain.
b. Is it possible that Luis’s work is correct? Explain.
Ans:
(a) No. If the P-value is 0.20, then the result is not statistically significant at the 5% level.
(b) Yes. If the P-value is 0.02, then the result is statistically significant at the 5% level.
Mathematics for Computer Science Engineers
References
• “Statistics for Engineers and Scientists”, William Navidi, McGraw Hill Education, India, 4th
Edition, 2015.
Dr. Deepa Nair
Department of Science and Humanities
PES University, Bangalore
Mathematics for Computer Science Engineers
Found 75 attended
P value
Alternate Hypothesis
H_1: p =p_0 Sum of the areas in the tails cut off by z and -z
Mathematics for Computer Science Engineers
Tests for a Population Proportion
Example:
• The article “Refinement of Gravimetric Geoid Using GPS and Leveling Data” (W.
Thurston, Journal of Surveying Engineering, 2000:27–56) presents a method for
measuring orthometric heights above sea level.
• For a sample of 1225 baselines, 926 gave results that were within the class C spirit
leveling tolerance limits.
• Can we conclude that this method produces results within the tolerance limits more
than 75% of the time?
Textbook: Page
Mathematics for Computer Science Engineers
Tests for a Population Proportion
Textbook: Page
Mathematics for Computer Science Engineers
Tests for a Population Proportion
Example:
A commonly prescribed drug for relieving nervous tension is believed to be only 60%
effective. Experimental results with a new drug administered to a random sample of
100 adults who were suffering from nervous tension show that 70 received relief.
Is this sufficient evidence to conclude that the new drug is superior to the one
commonly prescribed? Use a 0.05 level of significance.
Mathematics for Computer Science Engineers
Tests for a Population Proportion
Mathematics for Computer Science Engineers
Tests for a Population Proportion
Mathematics for Computer Science Engineers
Tests for a Population Proportion
Textbook: Page
Mathematics for Computer Science Engineers
MCQS
A company claims that 60% of its customers are satisfied. You take a sample of 200
customers and find that 120 are satisfied. Which hypothesis test setup is correct for
testing the claim?
Answer) a
Mathematics for Computer Science Engineers
References
• “Statistics for Engineers and Scientists”, William Navidi, McGraw Hill Education, India, 4th Edition,
2015.
• [Link]
Dr. Deepa Nair
Department of Science and Humanities
PES University, Bangalore
Mathematics for Computer Science Engineers
A small sample test for the population mean is typically conducted when the
sample size ≤30, and the population standard deviation is unknown. In such
cases, a t-test is used instead of a z-test
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Examples
1. Spacer collars for a transmission countershaft have a thickness specification of
38.98–39.02 mm. The process that manufactures the collars is supposed to be
calibrated so that the mean thickness is 39.00 mm, which is in the center of the
specification window.
A sample of six collars is drawn and measured for thickness. The six thicknesses are
39.030, 38.997, 39.012, 39.008, 39.019, and 39.002. Assume that the population of
thicknesses of the collars is approximately normal. Can we conclude that the process
needs recalibration?
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Solution
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Example Solution:
1. Before a substance can be deemed safe for landfilling, its chemical properties must
be characterized. The article “Landfilling Ash/Sludge Mixtures” (J. Benoit, T. Eighmy,
and B. Crannell, Journal of Geotechnical and Geoenvironmental Engineering, 1999:
877–888) reports that in a sample of six replicates of sludge from a New Hampshire
wastewater treatment plant, the mean pH was 6.68 with a standard deviation of
0.20. Can we conclude that the mean pH is less than 7.0?
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
More Example
2. A certain manufactured product is supposed to contain 23% potassium by weight. A
sample of 10 specimens of this product had an average percentage of 23.2 with a
standard deviation of 0.2. If the mean percentage is found to differ from 23, the
manufacturing process will be recalibrated.
a. State the appropriate null and alternate hypotheses.
b. Compute the P-value.
c. Should the process be recalibrated? Explain.
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Solution:
Mathematics for Computer Science Engineers
Small-Sample Tests for a Population Mean
Mathematics for Computer Science Engineers
MCQS
You sample 12 items from a population with unknown standard deviation. Which test should
you use to test the population mean?
a) Z-test
b) T-test for mean (small sample, σ unknown)
c) Chi-square test
d) F-test
Answer b)
Mathematics for Computer Science Engineers
References
• “Statistics for Engineers and Scientists”, William Navidi, McGraw Hill Education, India, 4th Edition,
2015.
Dr. Deepa Nair
Department of Science and Humanities
PES University, Bangalore
Mathematics for Computer Science
Engineers
HYPOTHESIS and INFERENCE
Nonparametric methods :
▪ rank-based methods are used when we have no idea about the population
distribution from which the data is sampled.
▪ Used for small sample sizes.
▪ Used when the data are measured on an ordinal scale and only their ranks are
meaningful.
▪ Data are skewed or heavily tailed, or you detect outliers.
▪ Variances between groups are not equal and transformation either not possible
or undesirable.
Mathematics for Computer Science Engineers
Non-Parametric test procedure
• The samples are not required to come from any specific distribution.
• While distribution free tests do require assumptions for their validity, these
assumptions are somewhat less restrictive than the assumptions needed for the t
test.
Advantages Disadvantages
• Used with all scales • May waste information
• Easier to compute — If data permit using parametric procedures
— Developed originally before wide computer — Example: converting data from
use ratio to ordinal scale
• Make fewer assumptions • Difficult to compute by hand for
large samples
• Need not involve population parameters
• Tables not widely available
• Results may be as exact as parametric procedures
Mathematics for Computer Science Engineers
Distribution Free Tests: Wilcoxon Signed-Rank Test
The nickel content (in parts per thousand by weight) is measured for six welds, giving the
following results:
9.3, 0.9, 9.0, 21.7, 11.5, and 13.9.
Let 𝜇represent the mean nickel content for this type of weld.
It is desired to test whether the average nickel content is less than 12.
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
Distribution Free Tests
• The difference next closest to 0, again ignoring sign, is assigned a rank of 2, and so on.
• Finally, the ranks corresponding to negative differences are given negative signs. The
following table shows the results.
• Denote the sum of the positive ranks S+ and the sum of the absolute values of the
negative ranks S−.
• Either S+ or S− may be used as a test statistic;
• we shall use S+
Mathematics for Computer Science Engineers
Distribution Free Tests
X X-12 Rank
11.5 -0.5 -1
13.9 1.9 2
9.3 -2.7 -3
9.0 -3.0 -4
21.7 9.7 5
0.9 -11.1 -6
Mathematics for Computer Science Engineers
Distribution Free Tests
In this example
S+ = 2+5 = 7, and S− = 1+3+4+6 = 14.
In some cases, where there are many more positive ranks than negative ranks, it is
easiest to first compute S− by summing the negative ranks and then computing
S+ = n(n + 1)/2 − (S−).
Mathematics for Computer Science Engineers
Distribution Free Tests
In Figure 6.17, μ > 12. For this distribution, positive differences are more probable than negative
differences and tend to be larger in magnitude as well.
Therefore it is likely that the positive ranks will be greater both in number and in magnitude than
the negative ranks, so S+ is likely to be large.
Mathematics for Computer Science Engineers
Distribution Free Tests
In general,
large values of S+ will provide evidence against a null hypothesis of the form H0 :μ ≤ μ0,
while small values of S+ will provide evidence against a null hypothesis of the form H0 :μ ≥
μ0.
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
Distribution Free Tests
Ties:
• Sometimes two or more of the quantities to be ranked have exactly the same
value. Such quantities are said to be tied. The standard method for dealing with
ties is to assign to each tied observation the average of the ranks they would
have received if they had differed slightly.
• For example, the quantities 3, 4, 4, 5, 7 would receive the ranks 1, 2.5, 2.5, 4, 5
• The quantities 12, 15, 16, 16, 16, 20 would receive the ranks 1, 2, 4, 4, 4, 6.
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
Distribution Free Tests
The nickel content for six welds was measured to be 9.3, 0.9, 9.0,
21.7, 11.5, and 13.9. Use these data to test H0 :μ ≤ 5 versus H1
:μ > 5.
Mathematics for Computer Science Engineers
Distribution Free Tests
Solution
The nickel content for six welds was measured to be 9.3, 0.9, 9.0, 21.7, 11.5, and 13.9.
Use these data to test H0 :μ = 16 versus H1 :μ ≠ 16.
Mathematics for Computer Science Engineers
Distribution Free Tests
Solution
Solution
Large-Sample Approximation
When the sample size n is large, the test statistic S+ is approximately normally distributed.
A rule of thumb is that the normal approximation is good if n > 20.
It can be shown by advanced methods that under H0, S+ has
X X X
79.26 22.39 10.08
Given data
80.79 118.39 7.28
82.07 118.46 6.87
82.14 20.32 6.23
57.19 16.69 4.57
55.86 16.50 4.09
42.08 15.95 140.09
41.78 15.16 140.77
100.01 14.22
100.36 11.64
30.46 11.48
30.27 11.28
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
MCQS
Which of the following is a key assumption of the Wilcoxon Signed-Rank
Test?
a) Data must be normally distributed
b) Data must be paired and at least ordinal
c) Samples must be independent
d) Population variance must be known
Answer b)
In the Wilcoxon Signed-Rank Test, what do you do with zero differences (ties)?
a) Count them as positive differences
b) Count them as negative differences
c) Exclude them from ranking
d) Add them to the smallest rank
b) Answer C)
Mathematics for Computer Science Engineers
References
• “Statistics for Engineers and Scientists”, William Navidi, McGraw Hill Education, India, 4th Edition,
2015.
Dr. Deepa Nair
Department of Science and Humanities
PES University, Bangalore
Mathematics for Computer Science
Engineers
HYPOTHESIS and INFERENCE
• We adopt the notational convention that when the sample sizes are
unequal, the smaller sample will be denoted 𝑋1 , . . . , 𝑋𝑚 .
• Since the populations are identical with the possible exception of location,
it follows that if 𝜇𝑋 < 𝜇𝑌 , the values in the 𝑋 sample will tend to be
smaller than those in the 𝑌 sample.
• Resistances, in m, are measured for five wires of one type and six wires of
another type. The results are as follows:
𝑿: 𝟑𝟔 𝟐𝟖 𝟐𝟗 𝟐𝟎 𝟑𝟖
𝒀: 𝟑𝟒 𝟒𝟏 𝟑𝟓 𝟒𝟕 𝟒𝟗 𝟒𝟔
𝑊 = 1 + 2 + 3 + 6 + 7 = 19.
Large-Sample Approximation:
• When both sample sizes 𝑚 and 𝑛 are greater than 8, it can be shown by advanced
methods that the null distribution of the test statistic 𝑊 is approximately normal
with mean 𝑚(𝑚 + 𝑛 + 1)/2 and variance 𝑚𝑛(𝑚 + 𝑛 + 1)/12.
• 𝑧 − 𝑠𝑐𝑜𝑟𝑒 𝑖𝑠
𝑊 − 𝑚(𝑚 + 𝑛 + 1)/2
𝑧 =
𝑚𝑛(𝑚 + 𝑛 + 1)/12
Mathematics for Computer Science Engineers
Distribution Free Tests
The article “Cost Analysis Between SABER and Design Bid Build Contracting Methods”
(E. Henry and H. Brothers, Journal of Construction Engineering and Management,
2001:359–366) presents data on construction costs for 10 jobs bid by the traditional
method (denoted X) and 19 jobs bid by an experimental system (denoted Y ). The data,
in units of dollars per square meter, and their ranks, are presented in . Test H0 :μX ≤ μY
versus H1 :μX > μY .
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
Distribution Free Tests
Mathematics for Computer Science Engineers
MCQS
deepanair@[Link]
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
• For example, your model expected women winning lottery is 0.05 more
than male, but is that really the case. Does the real data really match up
with your prediction?
• Chi square is used when data is categorical (i.e can be classified into
groups (yes/no)(red/blue/green) )
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
Tender for collecting toll for a newly You want to know if the day of
opened bridge week affects
The number of people sending
Day Mon Tues Wedn Thur Frid Saturd Sun tenders for the bridge?
day day esday sday ay ay day
You accordingly set up your H0
No 50 20 90 130 200 170 220 and H1
Day Mon Tues Wedn Thur Frid Saturd Sun Ex:H0 probability of all day
same
day day esday sday ay ay day
If H0 rejected then the day
No 50 50 100 130 200 150 200 affects number of tenders else
not
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test for best fit of model
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
Example:
Consider a die is thrown 600 times with following results.
Number 1 2 3 4 5 6
turned up
Frequency 115 97 91 101 110 86
Example:
Expected value=600/6=100 (unbiased die means equal outcome
of all)
Hypothesis
H0: Die is unbiased Catogory Observed Expected
H1: Die is biased 1 115 100
2 97 100
3 91 100
4 101 100
5 110 100
6 86 100
Tot 600 600
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
The Chi-Square test is used to:
a) Compare means of two groups
b) Compare medians of two groups
c) Test the association between categorical variables or goodness-of-fit
d) Test correlation between two quantitative variables
Answer b)
In a Chi-Square test, what happens to the test statistic if the difference between observed
and expected frequencies increases?
a) It decreases
b) Remains the same
c) It increases
d) Becomes negative
Answer C)
Dr. Deepa Nair
deepanair@[Link]
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
• In some cases, both row and column totals are random. In either case,
we can test the null hypothesis that the probabilities of the column
outcomes are the same for each row outcome, and the test is exactly
the same in both cases.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
• Then calculate overall chi-square (applying formula over all cells observed
and expected)
Example:
• Use the following data to test the null hypothesis that the proportions of
pins that are too thin, OK, or too thick are the same for all the machines.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
T00 OK Too
thin thick
Machine 1 10 102 8
Machine 2 34 161 5
Machine 3 12 79 9
Machine 4 10 60 10
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
Null Hypothesis (H₀): The proportions of pins that are too thin, OK, or
too thick are the same across all machines.
Alternative Hypothesis (H₁): The proportions of pins that are too thin,
OK, or too thick differ for at least one machine.
Note: calculate the expected values for each cell. The apply in chi square
formula
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
Observed values
T00 OK Too
thin thick
Machine 1 10 102 8
Machine 2 34 161 5
Machine 3 12 79 9
Machine 4 10 60 10
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
The Chi-Square Test for Independence:
Example:
The cylindrical steel pins in Example 6.21 are subject to a length specification as well as a diameter
specification. With respect to the length, a pin may meet the specification, or it may be too short or too
long. A total of 1021 pins are sampled and categorized with respect to both length and diameter
specification. The results are presented in the following table. Test the null hypothesis that the
proportions of pins that are too thin, OK, or too thick with respect to the diameter specification do not
depend on the classification with respect to the length specification.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
Example:
Formulate the Hypotheses:
• Null Hypothesis (H₀): The proportions of pins that are too thin, OK, or too thick with respect to the
diameter specification do not depend on the length specification.
• Alternative Hypothesis (H₁): The proportions of pins that are too thin, OK, or too thick with respect to
the diameter specification depend on the length specification.
Calculate the expected values
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
Chi-squared Test
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
Chi-squared Test-Practice Problems (independence test)
deepanair@[Link]
MATHEMATICS FOR COMPUTER
SCIENCE ENGINEERS
Type II error (False Negative): Sick person diagnosed as healthy (missed detection).
The test says the person does NOT have COVID-19, but they actually do.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
Example:
• A new concrete mix is being evaluated. 100 concrete blocks made
with the new mix are sampled, the sample mean compressive
strength is X, it is tested on the following hypothesis
• H0 :μ ≤ 1350 Mpa
• H1 :μ > 1350 Mpa
• If population standard deviation is 70 Mpa. Find critical point and
rejection region if significance level of the test is 5%.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
Example:
In a hypothesis test to determine whether a scale is in calibration, the
null hypothesis is
H0 :μ = 1000
and the null distribution of X is N(1000, 0.262).
Find the rejection region if the test will be conducted at a significance
level of 5%.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
0.262=sample variance=s2/n
=0.26
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Fixed Level Testing
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Type I and Type II Errors
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Type I and Type II Errors
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Type I and Type II Errors
H0 True H0 False
H0 True H0 False
Correct Decision
Reject H0 Type I error Correct
Type II error α
(β)
(1 – 𝛼) Decision
1-𝛽
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
•
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
Effect of bio-fertilizer ‘x’ on plant growth
• A high-powered test reduces the risk of a Type II error (a false negative), preventing
researchers from mistakenly concluding there is no effect when one actually exists.
• This ensures that research is more likely to find significant results that are actually
there, avoiding wasted resources and the failure to identify important findings.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
How large the power must be for a test ?
SIVASANKARI V
Department of Science & Humanities
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test(Computation)
Factor Affecting the power of the test)
SIVASANKARI V
Department of Science & Humanities
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
2. Compute the probability that the test statistic falls in the rejection region
if the alternate hypothesis is true.
This is the power.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example of a power calculation
Assume that a new chemical process has been developed that may increase the
yield over that of the current process. The current process is known to have a
mean yield of 80 and a standard deviation of 5, where the units are the
percentage of a theoretical maximum. If the mean yield of the new process is
shown to be greater than 80, the new process will be put into production.
Let μ denote the mean yield of the new process. It is proposed to run the new
process 50 times and then to test the hypothesis
𝐻0 : μ ≤ 80 versus 𝐻1 : μ > 80 at a significance level of 5%.
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
Calculation of Power
Problem 1 :
Find the power of the 5% level test of
𝑯𝟎 : μ ≤ 80 versus 𝑯𝟏 : μ > 80
for the mean yield of the new process under the
alternative μ = 81, assuming n = 50 and σ = 5.
Solution:
Null distribution of 𝑋ത :
2 𝜎
ത
𝑋~𝑁 𝜇, 𝜎𝑋ത 𝑤ℎ𝑒𝑟𝑒 𝜎𝑋ത =
𝑛
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
ഥ:
Null distribution of 𝑿
ത
𝑋~𝑁 80, 0.7072
The critical point has a z-score of 1.645, so its value is
𝑋ത = 80 + (1.645)(0.707) = 81.16.
The rejection region consists of all values of 𝑋ത ⩾ 81.16
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
Alternate distribution of ഥ 𝑿:
ത
𝑋~𝑁 81, 0.7072
(The alternate distribution is obtained by shifting the null
distribution to chosen value of μ.)
Power is the probability that 𝑋ത will fall into the
rejection region if the alternate hypothesis μ = 81 is true.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Computing the power
𝑧 -Score under 𝑯𝟏 for the critical point 81.16 is
𝑋ത − 𝜇 81.16 − 81
𝑧= = = 0.23
𝜎 0.707
The area to the right of 𝑧 = 0.23 is 0.4090.
This is the power of the test.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
Conclusion:
Problem 2 :
Find the power of the 5% level test of
𝑯𝟎 : μ ≤ 80 versus 𝑯𝟏 : μ > 80
for the mean yield of the new process under the alternative μ = 82, assuming
n = 50 and σ = 5.
Solution:
Null distribution of 𝑋ത :
2 𝜎
ത
𝑋~𝑁 𝜇, 𝜎𝑋ത 𝑤ℎ𝑒𝑟𝑒 𝜎𝑋ത =
𝑛
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
ഥ:
Null distribution of 𝑿
ത
𝑋~𝑁 80, 0.7072
The critical point has a z-score of 1.645, so its value is
𝑋ത = 80 + (1.645)(0.707) = 81.16.
The rejection region consists of all values of 𝑋ത ⩾ 81.16
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
Alternate distribution of ഥ 𝑿:
ത
𝑋~𝑁 82, 0.7072
(The alternate distribution is obtained by shifting the null
distribution to chosen value of μ.)
Power is the probability that 𝑋ത will fall into the
rejection region if the alternate hypothesis μ = 82 is true.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Computing the power
𝑧 -Score under 𝑯𝟏 for the critical point 81.16 is
𝑋ത − 𝜇 81.16 − 82
𝑧= = = −1.19
𝜎 0.707
The area to the right of 𝑧 = −1.19 is 0.8830.
This is the power of the test.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
Conclusion
A power of 0.8830 is high.
➢It means that if the mean yield of new process is actually equal to 82, there
is a 88.30% chance that the proposed experiment will detect the
improvement over the old process and allow the new process to be put into
production.
➢ It would be a wise decision to invest time and money to run this
experiment, since it has a large chance to succeed.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Computing Power
Problem 3 :
In testing the hypothesis 𝑯𝟎 : μ ≤ 80 versus 𝑯𝟏 : μ > 80
regarding the mean yield of the new process, how many times must the new
process be run so that a test conducted at a significance level of 5% will have
power 0.90 against the alternative μ = 81, if it is assumed that σ = 5?
Solution:
Let n represent the necessary sample size.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
ഥ:
Null distribution of 𝑿
𝜎
ത
𝑋~𝑁 𝜇, 𝜎𝑋2ത 𝑤ℎ𝑒𝑟𝑒 𝜎𝑋ത =
𝑛
𝟓
Critical point : 𝟖𝟎 + 𝟏. 𝟔𝟒𝟓
𝒏
ഥ.
Consider the alternate distribution of 𝑿
Given Power is 0.90. The power of the test is the area of the rejection
region under the alternate curve. This area must be 0.90.
Therefore, Z-score is -1.28.
𝟓
Critical point : 𝟖𝟏 − 𝟏. 𝟐𝟖
𝒏
We now have two different expression for the critical point. Since
there is only one critical point, these two expressions are equal.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power of test
Set them equal and solve for n
𝟓 𝟓
𝟖𝟎 + 𝟏. 𝟔𝟒𝟓 = 𝟖𝟏 − 𝟏. 𝟐𝟖
𝒏 𝒏
→ 𝒏 ≈ 𝟐𝟏𝟒.
Sample
size(n)
Significance
Type of level(𝛼)
Statistical
test
Power
Standard
Effect size
deviation(𝜎)
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Factors affecting Statistical Power of test – Sample size
Example:
A random sample of n people’s weight whose mean and standard
deviation are 168 lbs and 7.2 lbs. Can we conclude that the mean
of the population is 165lb?
𝐻0 : 𝜇 = 165
𝐻1 : 𝜇 ≠ 165
The larger
Sample the sample
Power size, the
size(n) higher the
power.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Factors affecting Statistical Power of test – Sample size
The above figure shows that the larger the sample size, the higher
the power. Since sample size is typically under an experimenter's
control, increasing sample size is one way to increase power.
However, it is sometimes difficult and/or expensive to use a large
sample size.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Factors affecting Statistical Power of test – Significance level
𝐻0 : 𝜇 = 165
𝐻1 : 𝜇 ≠ 165
168 − 165
168 − 165 200
𝑧= =
𝜎/ 200 𝜎
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Factors affecting Statistical Power of test- Standard deviation
2) If the sample size remains the same, and the level α increases, then the power will
______________
a) Increase b) decrease c) remains constant d) both increase and decreases
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
True or False/ Mcqs
1) A test has power 0.90 when μ = 15.
True or false:
2) If the sample size remains the same, and the level α increases, then the power will
______________
a) Increase b) decrease c) remains constant d) both increase and decreases
SIVASANKARI V
Department of Science & Humanities
sivasankariv@[Link]
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
Simple Linear Regression
Dr. Karthiyayini
Department of Science and Humanities
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Dr. Karthiyayini
Department of Science & Humanities
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Introduction
❖ Classification of Data
❖ What is Correlation ?
Multivariate Univariate
Data Data
Bivariate Data
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Univariate & Bi - Variate Data
The analysis of Univariate data can be done using : The analysis of Bivariate data can be done using :
Temperature Resistance
55 5
45 4.94
35 4.84
65 5.11
75 5.19
70 5.14
60 5.09
The resistance decreases with increase in
50 4.99 temperature in a Semiconductor whereas
40 4.92 in a Conductor, the resistance increases
30 4.82 with an increase in the temperature.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Correlation
❖ Does height have an impact on the
performance of a player in a Basket ball
match?
σ𝑛 ҧ
𝑖=1(𝑥𝑖 −𝑥)(𝑦𝑖 −𝑦) Pearson’s Correlation Coefficient
⇒𝑟=
σ𝑛 ҧ 2
𝑖=1 (𝑥𝑖 −𝑥) σ𝑛
𝑖=1 (𝑦𝑖 −𝑦)
2
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example Problem :
𝑥ҧ =99 𝑦ത = 98
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Scatter Plot
104
102
100
ER
98
96
94
92
90
90 92 94 96 98 100 102 104 106
IR
Positive
Correlation
Correlation
No
Correlation Negative
/ Poor Correlation
Correlation
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Interpretation of Correlation Coefficient
𝑟 = ±1 ⟹
Perfect Positive
𝑟 =0⟹
/
No Correlation
Interpretation
Perfect Negative
Correlation of
Correlation
0 < 𝑟 < 1Coefficient
⟹ −1 < 𝑟 < 0 ⟹
Positive Negative
Correlation Correlation
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Examples of various levels of correlation
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
How the Correlation coefficient works!!
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
More about Correlation Coefficient
Correlation Coefficient
Note that Sample Correlation is not only used to measure the strength of a relationship
but is also used to construct Confidence intervals and perform Hypothesis testing on the
population correlation.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Some more properties of the Correlation Coefficient
1 𝑛 𝑥𝑖 −𝑥ҧ 𝑦𝑖 −𝑦ത
𝑟= σ𝑖=1
𝑛−1 𝑆𝑥 𝑆𝑦
𝑟 = 0.80
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
The Correlation Coefficient Is Unit less
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Correlation Coefficient measures only Linear Association
Identical statistics
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Visual representation of the Anscombe’s Quartet
X causes Y
Correlation between X & Y
Y causes X
Crimes
been found.
❖ But there is no evidence to suggest
that tweets are causing more crime
and tweets about crime do not Tweets
necessarily reflect the crime rate.
Reference : The Relationship Between Social Media Data and Crime Rates in the United States Yan
Wang1 , Wenchao Yu1 , Sam Liu2 , and Sean D. Y Social Media + Society January-March 2019: 1–9
©
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Correlation is not causation!!
Crimes
❖Confounding variables can cause two major problems:
▪ Increase variance
▪ Introduce bias.
❖ A confounding variables are like extra independent
Tweets variables
that are having a hidden effect on your dependent variables.
❖A confounding variable can be what the actual cause of a
correlation is, hence any studies must take these into
account and find ways of dealing with them.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Confounding Variable!!
❖ Correlation , 𝑟 = 0.987
❖ Correlation , 𝑟 = 0.988
❖ Positive Correlation ❖ Positive Correlation
❖ Increasing the time that the skin is in
❖ Increasing the volume causes
the percentage absorbed to contact with chemical causes the
increase. percentage absorbed to increase.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example Problem
No! The conclusions are not justified!
Suggested Solution :
❖ The correlation between time & volume has to be explored.
❖ The Scatter plot :
2.00 10 68.7
2.00 24 87.2
5.00 2 47.7
5.00 10 65.1
5.00 24 88.4
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example Problem 2.
Correlation between Volume & Correlation between Time & Percent
Percent Absorbed Absorbed
❖ Scatter Plot : ❖ Scatter Plot :
❖ Correlation , 𝑟 = 0.952
❖ Correlation, 𝑟 = 0.121 ❖ Strong Positive Correlation
❖ Weak Positive Correlation ❖ Increasing the time that the
❖ Hence increase of volume has skin is in contact with the
little or no effect on the chemical will cause the
percentage absorbed. percentage absorbed to increase.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example Problem 2.
Correlation between Volume & Time
❖ Scatter Plot :
Independent Dependent
variable Spurious Correlation variable
Solution A
THANK YOU
Dr. Karthiyayini
Department of Science & Humanities
[Link]@[Link]
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
Simple Linear Regression
[Link] H R
Department of Computer Science and Engineering
Dr. Karthiyayini
Department of Science and Humanities
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Simple Linear Regression: Correlation &
Regression Analysis
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Regression Analysis
▪ Regression analysis can help you to quantify that and can help you to
predict how much you will weigh in 10 years time if you continue to put
on weight at the same rate.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Prediction of Floods / Droughts
Urbanisation
Floods
Other Deforestation
Human
Factors
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Regression Analysis
❖It is a way of mathematically sorting out which of those variables indeed have
an impact
❖And most importantly, how certain are we about all these factors?
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Regression Analysis – A Broad Classification
0 + 𝛽
𝑦𝑖 = 𝛽 1 𝑥𝑖
where,
σ𝑛 ҧ
𝑖=1(𝑥𝑖 −𝑥)(𝑦 ത
𝑖 −𝑦)
1 =
▪ 𝛽 σ𝑛 ҧ 2
𝑖=1(𝑥𝑖 −𝑥)
0 = 𝑦ത − 𝛽
▪ 𝛽 1 𝑥ҧ
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example :
❖The details pertaining to the no. of SL No. No. of hours Marks
hours spent by students in preparing spent Scored
for an entrance exam and the marks 1 6 82
scored (on a scale of (0 – 100) is 2 10 88
provided in the following table. 3 2 56
Using these values, 4 4 64
i. Estimate the marks scored by a 5 6 77
student who has spent 2.35 6 7 92
hours. 7 0 23
ii. Predict the marks that a student 8 1 41
can score if he/she invests 20 hours. 9 8 80
10 5 59
11 3 47
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Computing the least squares line
❖We need to first obtain the least square line which is given by,
𝟎 + 𝜷
𝒚=𝜷 𝟏 𝒙
σ𝒏
𝒊=𝟏(𝒙𝒊 −ഥ
𝒙)(𝒚𝒊 −ഥ𝒚)
▪ 𝟏 =
𝜷 σ𝒏 𝒙 )𝟐
𝒊=𝟏(𝒙𝒊 −ഥ
▪ 𝟎 = 𝒚
𝜷 𝟏 𝒙
ഥ−𝜷 ഥ
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example :
SL No. No. of hours Marks
spent (𝑥) Scored(𝑦)
𝑥 − 𝑥ҧ (𝑥 − 𝑥)ҧ 2 𝑦 − 𝑦ത (𝑥 − 𝑥)(𝑦
ҧ − 𝑦)
ത
1 6 82 1.27 1.6129 17.55 22.33
2 10 88 5.27 27.7729 23.55 124.15
3 2 56 -2.73 7.4529 -8.45 23.06
4 4 64 -0.73 0.5329 -0.45 0.33
5 6 77 1.27 1.6129 12.55 15.97
6 7 92 2.27 5.1529 27.55 62.60
7 0 23 -4.73 22.3729 -41.45 195.97
8 1 41 -3.73 13.9129 -23.45 87.42
9 8 80 3.37 11.3569 15.55 50.88
10 5 59 0.27 0.0729 -5.45 -1.49
11 3 47 -1.73 2.9929 -17.45 30.15
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example :
SL No. No. of hours Marks
spent (𝑥) Scored(𝑦)
𝑥 − 𝑥ҧ (𝑥 − 𝑥)ҧ 2 𝑦 − 𝑦ത (𝑥 − 𝑥)(𝑦
ҧ − 𝑦)
ത
1 6 82 1.27 1.6129 17.55 22.33
2 10 88 5.27 27.7729 23.55 124.15
3 2 56 -2.73 7.4529 -8.45 23.06
4 4 64 -0.73 0.5329 -0.45 0.33
5 6 77 1.27 1.6129 12.55 15.97
6 7 92 2.27 5.1529 27.55 62.60
7 0 23 -4.73 22.3729 -41.45 195.97
8 1 41 -3.73 13.9129 -23.45 87.42
9 8 80 3.37 11.3569 15.55 50.88
10 5 59 0.27 0.0729 -5.45 -1.49
11 3 47 -1.73 2.9929 -17.45 30.15
4.73 64.45 94.8459 611.37
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Example :
From the table we have,
𝑥ҧ = 4.73 ; 𝑦ത =64.45
▪ σ𝑛𝑖=1 𝑥𝑖 − 𝑥ҧ 𝑦𝑖 − 𝑦ത =611.37
σ𝑛 ҧ
𝑖=1(𝑥𝑖 −𝑥)(𝑦 ത
𝑖 −𝑦)
▪
𝛽1 = σ𝑛 ҧ 2
=611.37/94.8459=6.49
𝑖=1(𝑥𝑖 −𝑥)
0 = 𝑦ത − 𝛽
▪ 𝛽 1 𝑥ҧ =64.45-[6.49x4.73]=33.7523
i. To estimate the marks scored by a student who has spent 2.35 hours.
Y=33.7523+[6.35x2.35]=48.6748
ii. To predict the marks that a student can score if he/she invests 20
hours.
Y=33.7523+[6.35x20]=163.5523
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
𝒍𝟏
𝒍𝟐
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
How to compute the Least – Squares Line ???
𝒍𝟏 • 𝑙𝑖 → true length
𝒍𝟐
Linear Model
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Scenario # 1 : No Errors!!
(𝑥) (𝑦)
0.0 5.02
5.2
0.2 5.04
0.4 5.06
0.6 5.08 5.15
0.8 5.10
1.0 5.12 5.1
1.2 5.14
1.4 5.16
5.05
1.6 5.18
1.8 5.20
5
2.0 5.22 0 0.5 1 1.5 2 2.5
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Scenario #2 : Measurement has Errors!!
5.8
5.7
5.6
5.5
5.4
5.3
5.2
5.1
4.9
0 0.5 1 1.5 2 2.5 3 3.5 4
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Least Square Line :
WEight (lb) (x)/Length (in.) (y)
5.9
NOTE : The least square line is defined to be the line
5.8
for which the sum of squared residuals is minimum.
5.5
5.4
❖Using some Mathematical computations it can be shown
5.3
that,
5.2
5.1
4.9
0 0.5 1 1.5 2 2.5 3 3.5 4
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Least Squares Line : Summary
Scenario #1 : If there is no measurement error then the data points lie on the straight line
𝑦 = 𝛽0 + 𝛽1 𝑥 and values of 𝛽0 and 𝛽1 can be obtained easily by calculating the slope and the
intercept.
Scenario #2 : If there is a measurement error 𝜀𝑖 , then
❖ the exact value of 𝛽0 and 𝛽1 cannot be determined
❖ the values of 𝛽0 and 𝛽1 are computed by calculating the least square line.
0 + 𝛽
❖ The least square line is given by 𝑦ෝ𝑖 = 𝛽 1 𝑥𝑖
where
0 → the 𝑦 − intercept of the least square line
▪ 𝛽
→ gives an estimate of 𝛽0 , the initial length of the spring.
1 →the slope of the least square line
▪ 𝛽
→ gives an estimate of the actual value of the spring constant 𝛽 .
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Computing formulas
Remark :
❖ σ𝑛𝑖=1(𝑦𝑖 − 𝑦)
ത 2 = σ𝑛𝑖=1 𝑦𝑖 2 − 𝑛𝑦ത 2
❖ Don’t use the Least Squares line when the data aren’t linear.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
The Estimates are not the same as true values
Length(y)
5.25
y = 0.1 + 5.02x
0.8 5.10 5.14 5.2 → 𝐓𝐫𝐮𝐞 Line
1.0 5.12 5.16 5.15
Length(y)
5.25
y = 0.1x + 5.02
0.8 5.10 5.14 5.2
→ 𝐓𝐫𝐮𝐞 Line
1.0 5.12 5.16 5.15
163.5523 10 5 59
11 3 47
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Don’t Extrapolate outside the range of the data!!
𝐄𝐠. 𝟐:
Weight (𝑙𝑏) Length (𝑖𝑛. ) Weight (𝑙𝑏) Length (𝑖𝑛. )
(𝑥) (𝑦) (𝑥) (𝑦) Least square line: y=0.2046x+4.997
0.0 5.06 2.0 5.40
0.2 5.01 2.2 5.57
0.4 5.12 2.4 5.47
For weight, x=100lb
0.6 5.13 2.6 5.53 Length y=0.2046x100+4.997
0.8 5.14 2.8 5.61 =25.46in
1.0 5.16 3.0 5.59
1.2 5.25 3.2 5.61
1.4 5.19 3.4 5.75
1.6 5.24 3.6 5.68
1.8 5.46 3.8 5.80
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Don’t use the Least Squares Line when the data aren’t linear
60
50
40
30
20
10
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Note : In some cases the Least – Squares line can be used for non linear data, but only after
variable transformation is applied.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Measuring goodness of fit
❖ A goodness of fit statistic is a quantity that measures how well a
model explains a given set of data.
❖ A linear model fits well if there is a strong relationship between the
variables involved.
❖ The strength of a linear relationship can be measured by
considering,
σ𝑛𝑖=1(𝑦𝑖 − 𝑦)
ത 2 − σ𝑛𝑖=1(𝑦𝑖 − 𝑦ෝ𝑖 )2 .
❖ The above relation is also referred to as a goodness-of-fit statistic.
❖ The draw back of this statistic relation is that it cannot be used to
compare the goodness-of-fit of two models which have different
data set. (That is, data sets having different units)
σ𝑛 ത 2 − σ𝑛
𝑖=1(𝑦𝑖 −𝑦) 𝑦𝑖 )2
𝑖=1(𝑦𝑖 −ෞ
❖ Hence we use the relation, 𝑟 2 = σ𝑛 ത 2
𝑖=1(𝑦𝑖 −𝑦)
which is obtained by using the correlation coefficient.
❖ This is also referred to as the co-efficient of determination.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Visualisation of 𝒓𝟐
t
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Some special terminologies!
σ𝑛 (𝑦 − ത
𝑦) 2 − σ𝑛 (𝑦 −ෞ𝑦 ) 2
❖𝑟 2 = 𝑖=1 𝑖
σ𝑛
𝑖=1
ത 2
𝑖 𝑖
𝑖=1(𝑦𝑖 −𝑦)
❖ σ𝑛𝑖=1(𝑦𝑖 − 𝑦)
ത 2 − σ𝑛𝑖=1(𝑦𝑖 − 𝑦ෝ𝑖 )2 : Regression sum of
squares
Dr. Mamatha H R
Department of Computer Science and Engineering
MATHEMATICS FOR COMPUTER SCIENCE
ENGINEERS
Checking Assumptions and Transforming Data
[Link] H R
Department of Computer Science and Engineering
Dr. Karthiyayini
Department of Science and Humanities
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Simple Linear Regression: Correlation &
Regression Analysis
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Uncertainties in the Least-Squares Coefficients
• Assume we have n data points (x1, y1), . . . , (xn, yn), and we plan
to fit the least squares line.
3. The errors 1,…,n all have the same variance, which we denote by 2.
• The spread of the points around the line can be measured by the sum of the
squared residuals
• The estimate of the error variance σ2 is the quantity s2 given by
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Distribution
y2 = 2
i
The slope represents the change in the mean of y associated with an increase in
one unit in the value of x.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
More Distributions
Under assumptions 1 – 4:
• The quantitiesˆ0 and ˆ1 are normally distributed random variables.
• The means of ˆ 0
and ˆ1 are the true values 0 and 1, respectively.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
More Distributions (cont.)
• The standard deviations of ˆ0 and ˆ1 are estimated with
s
1 x 2
sˆ =
sˆ = s + and 1 n
i
n
0
n
(x − x) 2 ( x − x ) 2
i
i =1
i =1
n
(1 − r ) 2
(y i
− y ) 2
where s = i =1
is an estimate of the
n−2
2. Use caution: if the range of x values extends beyond the range where
the linear model holds, the results will not be valid.
3. The quantities ( ˆ0 − 0 ) / sˆ and
0
( ˆ1 − 1 ) / sˆ
1
have Student’s t
distribution with n – 2 degrees of freedom.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Checking Assumptions and Transforming Data
• We stated some assumptions for the errors. Here we want to see if any of
those assumptions are violated.
• When the linear model is valid, and assumptions 1 – 4 are satisfied, the
plot will show no substantial pattern. There should be no curve to the
plot, and the vertical spread of the points should not vary too much over
the horizontal range of the data.
• A good-looking residual plot does not by itself prove that the linear
model is appropriate. However, a residual plot with a serious defect does
clearly indicate that the linear model is inappropriate.
• When the vertical spread in a scatterplot doesn’t vary too much, the
scatterplot is said to be homoscedastic. The opposite of homoscedastic is
heteroscedastic.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Residual Plots
A: No noticeable pattern
B: Heteroscedastic
C: Trend
D: Outlier
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Checking Assumptions to form a Linear Model
• Example of a residual plot: On the left is the plot of x versus the values
of y, on the right the residual with the fitted values of y
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Checking Assumptions to form a Linear Model
• Below on the left the plot is homoscedastic, while on the
right the spread increases with the fitted value and is thus
heteroscedastic.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Homoscedasticity or Heteroscedasticity? The way forward...
x y x y
1 2.2 11 31.5
2 9 12 32.7
3 13.5 13 34.9
4 17 14 36.3
5 20.5 15 37.7
6 23.3 16 38.7
7 25.2 17 40
8 26.4 18 41.3
9 27.6 19 42.5
10 30.2 20 43.7
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Power Transformations – Positive Powers
Plot y2 vs x and its homoscedastic
residual plot which exhibits no
discernible pattern.
Linear model is OK.
x y2 x y2
1 4.84 11 992.25
2 81 12 1069.29
3 182.25 13 1218.01
4 289 14 1317.69
5 420.25 15 1421.29
6 542.89 16 1497.69
7 635.04 17 1600
8 696.96 18 1705.69
9 761.76 19 1806.25
10 912.04 20 1909.69
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Transformations – Do they always work?
• Multiple Regression
➔ We add more independent variables in order to explain the
When there are too few points on the residual plot, then…
You can start by fitting a linear model but declare your result
tentative; wait for more data and then a reliable decision can be
made.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
How Many Points Make a Reliable Residual Plot?
NOT all residual plots with few points turn out to be hard to interpret.
Some of these show a pattern which cannot be changed by relocating just one
or two points.
• Outliers are points that are detached from the bulk of the data.
• Both the scatter plot and the residual plot should be examined for
outliers.
• If there are outliers that cannot be removed from the data set,
then the best thing to do is fit the whole data set and then
remove the outlier and fit a line to the data set.
• If the plot of residuals versus fitted values looks good, then further
diagnostics may be used to further check the fit of the linear model.
• If there are trends in this plot, then x and y may be varying with time.
In this case, adding a time term to the model as an additional
independent variable.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
Normality Assumption
• If the plot looks like it follows a rough straight line, then we can
conclude that the residuals are approximately normally distributed.
MATHEMATICS FOR COMPUTER SCIENCE ENGINEERS
MCQ
Solution D
THANK YOU