5.1 Curve Fitting by The Method of Least Squares-Fitting of Straight Lines
5.1 Curve Fitting by The Method of Least Squares-Fitting of Straight Lines
Unit – 5
Applied Statistics
5.1 Curve Fitting by the Method of Least Squares- Fitting Of Straight Lines
In this article we are going to develop an algorithm for fitting curve of type
We have,
Log(y) = log(axb)
Y = A + bX ----- (3),
∑Y = nA+ b ∑X
a = exp(A)
4. Substitute the value of a and b in
Second-order curve
A plane curve whose rectangular Cartesian coordinates fulfil an algebraic calculation of the
second degree:
Equation need not define a real geometrical form, but to reserve generality in such situations one
says that it describes an imaginary second-order curve. Depending on the values of the
coefficients of the equation it can be changed by parallel movement and rotation of the
coordinate system through some angle to one of the 9 canonical forms given under, to each of
which there agrees a definite class of curves. Viz.,
Non-degenerate curves:
, imaginary ellipses;
Degenerate curves:
, pairs of imaginary intersecting lines;
A second-order curve that has a unique centre of symmetry (the centre of the second-order
curve) is named a central curve. The coordinates of the centre of a second-order curve are
determined by the explanation of the system
A second-order curve without a centre of symmetry or with an indefinite centre is named a non-
central curve.
Soundings on the form of a second-order curve can be approved out without reducing the general
equation to canonical form. This is done by seeing the values of the so-called fundamental
invariants of a second-order curve, that is, the resulting expressions in the coefficients of the
equation , the values of which are not changed under a parallel displacement and a rotation of the
coordinate system :
Which is an invariant with respect to rotation of the coordinate system (see the Table below).
Many significantbelongings of second-order curves can be calculated by means of the
characteristic quadratic form
=0 or
The three fundamental invariants , and define a second-order curve (without the case of
parallel lines) up to a motion of the Euclidean plane: If the agreeing invariants , and of two
curves are equal, then these curves can be made to coincide by a motion. In other words, these
curves are corresponding with respect to the group of motions of the plane (metrically
equivalent).
There is a ordering of second-order curves from the point of view of other groups of alterations.
Thus, with respect to the more general (than the group of motions) group of affine alterations any
two curves distinct by equations of the same canonical form are correspondent. For example, two
similar second-order curves are observed as equivalent. The contacts between different affine
classes of second-order curves make it likely to formarrangement from the point of view of
projective geometry, in which elements at infinity do not play a singular role. The real non-
degenerate second-order curves, ellipses, hyperbolas, and parabolas, form one projective class —
the class of real oval curves (ovals, cf. Oval). A real oval curve is an ellipse, hyperbola or
parabola, dependent on how it is placed with respect to the line at infinity; an ellipse intersects
the line at infinity in two imaginary points, a hyperbola intersects it in two real points and a
parabola touches it; there are projective alterations that take these curves into one another. There
are 5 projective equivalence classes of second-order curves. Viz.,
, a real oval;
, an imaginary oval;
Degenerate curves:
Apart from the analytic method of defining second-order curves (specifying the equation) there
are other methods. For example, an ellipse, hyperbola and parabola can be obtained as a section
of a conical surface by a plane (see Conic sections).'
Central curves (
Pairs of intersecting straight lines (a real
Real ellipses point)
)
Imaginary ellipses
Hyperbolas Pairs of real non-intersecting straight lines
Non-central curves
(
Parabolas
Pairs of imaginary parallel lines
)
This lesson describes how to conduct a hypothesis test to define whether the difference between
two proportions is significant.
The test procedure, called the two-proportion z-test, is suitable when the following conditions are
met:
This approach contains of four steps: (1) state the hypotheses, (2) formulate an analysis plan, (3)
analyze sample data, and (4) interpret results.
In this section, two sample difficulties illustrate how to conduct a hypothesis test for the
difference between two sizes. The first problem includes two-tailed test; the second problem, a
one-tailed test.
Suppose Acme Drug Company is making a new medicine designed to prevent colds. The
company claims that the drug is equally effective for men and women. To test this claim, they
chose a simple random sample of 100 women and 200 men from a population of 100,000
volunteers.
At the end of the study, 38% of the women had a cold; and 51% of men caught a cold. Based on
these results, can we rule out the company's claim that the drug is equally effective for men and
women? Use a significance level of 0.05.
Solution: The solution to this problem involves four steps: (1) state the hypotheses, (2) formulate
an analysis plan, (3) analyze the sample data, and (4) interpret the results. We work through the
following steps:
State the hypotheses. The first step is to affirm the null hypothesis and an alternative
hypothesis.
Null hypothesis: P1 = P2
Alternative hypothesis: P1 ≠ P2
Note that these hypotheses constitute a two-tailed test. The null hypothesis will be rejected if the
proportion of population 1 is too large or too small.
Formulate an analysis plan. For this analysis, the significance level is 0.05. The test method is
a two-sided z-test.
Analyze the sample data. Using the sample data, we calculated the proportion of the pooled
sample (p) and the standard error (SE). Using these measures, we compute the z-score (z) test
statistic.
p = 140/300 = 0.467
Suppose Acme Drug Company is making a new medicine designed to prevent colds. The
company claims that the drug is equally effective for men and women. To test this claim, they
chose a simple random sample of 100 women and 200 men from a population of 100,000
volunteers. At the end of the study, 38% of the women had a cold; and 51% of men caught a
cold. Based on these results, can we rule out the company's claim that the drug is equally
effective for men and women? Use a significance level of 0.05. Solution: The solution to this
problem involves four steps: (1) state the hypotheses, (2) formulate an analysis plan, (3) analyze
the sample data, and (4) interpret the results. We work through the following steps:
State the hypotheses. The first step is to affirm the null hypothesis and an alternative
hypothesis. Null hypothesis: P1 = P2 Alternative hypothesis: P1 ≠ P2 Note that these hypotheses
constitute a two-tailed test. The null hypothesis will be rejected if the proportion of population 1
is too large or too small.
Formulate an analysis plan. For this analysis, the significance level is 0.05. The test method is
a two-sided z-test.
Analyze the sample data. Using the sample data, we calculated the proportion of the pooled
sample (p) and the standard error (SE). Using these measures, we compute the z-score (z) test
statistic. The analysis described above is a two-proportion z-test.
Interpretation of results If the sample results are unlikely, given the null hypothesis, the
researcher rejects the null hypothesis. Typically, this involves comparing the P value with the
significance level and rejecting the null hypothesis when the P value is less than the significance
level. Hypothesis test: difference between proportions This lesson explains how to perform a
hypothesis test to determine if the difference between two proportions is significant. The test
procedure, called the two-sided z-test, is appropriate when the following conditions are met:
This approach involves four phases: (1) declaring the hypotheses, (2) formulating an analysis
plan, (3) analyzing the sample data, and (4) interpreting the results. State hypotheses Each
hypothesis test requires the analyst to declare a null hypothesis and an alternative hypothesis.
The following table shows three sets of hypotheses. Each makes a statement about the difference
d between two proportions of the population, P1 and P2. (In the table, the symbol ≠ means "not
equal to").
Set Null hypothesis Alternative hypothesis Number of tails
1 P1 - P2 = 0 P1 - P2 ≠ 0 2
2 P1 - P2 > 0 P1 - P2 < 0 1
3 P1 - P2 < 0 P1 - P2 > 0 1
The first set of hypotheses (Set 1) is an example of a two-tailed test, since an extreme
value on both sides of the sampling distribution would induce an investigator to reject
the null hypothesis. The other two sets of hypotheses (sets 2 and 3) are one-tailed tests,
since an extreme value on one side of the sampling distribution would induce an
investigator to reject the null hypothesis.
When the null hypothesis states that there is no difference between the two proportions of
the population (i.e., d = P1 - P2 = 0), the null and alternative hypothesis for a two-
tailed test is often stated as follows.
I have: P1 = P2
Has: P1 ≠ P2
Formulate an analysis plan.
The analysis plan describes how to use the sample data to accept or reject the null
hypothesis. You must specify the following elements.
Level of significance. Researchers often choose significance levels of 0.01, 0.05, or
0.10; but you can use any value between 0 and 1.
Test method. Use the two aspect ratio z test (described in the next section) to determine
if the assumed difference between population proportions differs significantly from the
observed difference in the sample.
Analyze the sample data.
Using the sample data, complete the following calculations to find the test statistic and
associated P-value.
Proportion of the aggregate sample. Since the null hypothesis states that P1 = P2, we
use an aggregate sample proportion (p) to calculate the standard error of the sampling
distribution.
p = (p1 * n1 + p2 * n2) / (n1 + n2)
Where p1 is the proportion of the sample from population 1, p2 is the proportion of the
sample from population 2, n1 is the size of sample 1 and n2 is the size of sample 2.
Standard error. Calculate the standard error (SE) of the sampling distribution
difference between two proportions.
SE = sqrt {p * (1 - p) * [(1 / n1) + (1 / n2)]}
Where p is the proportion of the pooled sample, n1 is the size of sample 1 and n2 is the
size of sample 2.
Statistical test. The test statistic is a z (z) score defined by the following equation.
z = (p1 - p2) / SE
Where p1 is the proportion of sample 1, p2 is the proportion of sample 2 and SE is the
standard error of the sampling distribution.
p-value The P value is the probability of observing a sample statistic as extreme as the
test statistic. Since the test statistic is a z-score, use the normal distribution calculator
to assess the probability associated with the z-score. (See the example problems at the
end of this lesson for examples of how this is done.)
The analysis described above is a two-way z-test.
Interpretation of results
If the sample results are unlikely, given the null hypothesis, the researcher rejects the null
hypothesis. Typically, this involves comparing the P value with the significance level
and rejecting the null hypothesis when the P value is less than the significance level.
Test your understanding
In this section, two sample problems illustrate how to perform a hypothesis test for the
difference between two proportions. The first problem involves a two-tailed test; The
second problem, a tail test.
Problem 1: two-tailed test
Suppose Acme Drug Company develops a new drug, designed to prevent colds. The
company claims that the drug is equally effective for men and women. To test this
claim, they chose a simple random sample of 100 women and 200 men from a
population of 100,000 volunteers.
At the end of the study, 38% of the women had a cold; and 51% of men caught a cold.
Based on these results, can we rule out the company's claim that the drug is equally
effective for men and women? Use a significance level of 0.05.
Solution: The solution to this problem involves four steps: (1) state the hypotheses, (2)
formulate an analysis plan, (3) analyze the sample data, and (4) interpret the results.
We work through the following steps:
State the hypotheses. The first step is to affirm the null hypothesis and an alternative
hypothesis.
Null hypothesis: P1 = P2
Alternative hypothesis: P1 ≠ P2
Note that these hypotheses constitute a two-tailed test. The null hypothesis will be
rejected if the proportion of population 1 is too large or too small.
Formulate an analysis plan. For this analysis, the significance level is 0.05. The test
method is a two-sided z-test.
Analyze the sample data. Using the sample data, we calculated the proportion of the
pooled sample (p) and the standard error (SE). Using these measures, we compute the
z-score (z) test statistic.
p = (p1 * n1 + p2 * n2) / (n1 + n2)
p = [(0.38 * 100) + (0.51 * 200)] / (100 + 200)
p = 140/300 = 0.467
SE = sqrt {p * (1 - p) * [(1 / n1) + (1 / n2)]}
SE = sqrt [0.467 * 0.533 * (1/100 + 1/200)]
SE = sqrt [0.003733] = 0.061
z = (p1 - p2) / SE = (0.38 - 0.51) /0.061 = -2.13
Where p1 is the proportion of the sample in sample 1, where p2 is the proportion of the
sample in sample 2, n1 is the size of sample 1 and n2 is the size of sample 2.
Since we have a two-tailed test, the P value is the probability that the z-score is less than -
2.13 or greater than 2.13.
We use the normal distribution calculator to find P (z <-2.13) = 0.017 and P (z> 2.13) =
0.017. Therefore, the value P = 0.017 + 0.017 = 0.034.
Interpret the results. Since the P value (0.034) is lower than the significance level
(0.05), we cannot accept the null hypothesis.
Note: If you use this approach during an exam, you can also mention why this approach
is appropriate. In particular, the approach is appropriate because the sampling method
was simple random sampling, the samples were independent, each population was at
least 10 times larger than its sample, and each sample included at least 10 successes
and 10 failures.
Problem 2: testing a queue
Suppose the previous example is declared slightly differently. Suppose Acme Drug
Company develops a new drug, designed to prevent colds. The company claims that
the drug is more effective for women than for men. To test this claim, they chose a
simple random sample of 100 women and 200 men from a population of 100,000
volunteers.
At the end of the study, 38% of the women had a cold; and 51% of men caught a cold.
Based on these results, can we conclude that the medication is more effective for
women than for men? Use a significance level of 0.01.
Solution: The solution to this problem involves four steps: (1) state the hypotheses, (2)
formulate an analysis plan, (3) analyze the sample data, and (4) interpret the results.
We work through the following steps:
State the hypotheses. The first step is to affirm the null hypothesis and an alternative
hypothesis.
Null hypothesis: P1> = P2
Alternative hypothesis: P1 <P2
Note that these hypotheses constitute a one-tailed test. The null hypothesis will be
rejected if the percentage of women who have a cold (p1) is sufficiently lower than the
proportion of men who have a cold (p2).
Formulate an analysis plan. For this analysis, the significance level is 0.01. The test
method is a two-sided z-test.
Analyze the sample data. Using the sample data, we calculated the proportion of the
pooled sample (p) and the standard error (SE). Using these measures, we compute the
z-score (z) test statistic.
p = 140/300 = 0.467
Where p1 is the proportion of the sample in sample 1, where p2 is the proportion of the sample in
sample 2, n1 is the size of sample 1 and n2 is the size of sample 2.
Subsequently we have a one-tailed test, the P significance is the probability that the z-score is
less than -2.13. We practice the normal distribution calculator to discover P (z <-2.13) = 0.017.
Therefore, the P value = 0.017.
Interpret the results. Since the P value (0.017) is greater than the significance level (0.01), we
cannot reject the null hypothesis
To estimate the difference between two population proportions with a confidence interval, you
can use the Central Limit Theorem when the sample sizes are large enough (typically, each at
least 30). When a statistical characteristic, such as opinion on an issue (support/don’t support), of
the two groups being compared is categorical, people want to report on the differences between
the two population proportions — for example, the difference between the proportion of women
and men who support a four-day work week. How do you do this?
You estimate the difference between two population proportions, p1 – p2, by taking a sample
from each population and using the difference of the two sample proportions,
Plus or minus a margin of error. The result is called a confidence interval for the difference of
two population proportions, p1 – p2.
The formula for a confidence interval (CI) for the difference between two population proportions
is
And n1 are the sample proportion and sample size of the first sample, and
And n2 are the sample proportion and sample size of the second sample. The value z* is the
appropriate value from the standard normal distribution for your desired confidence level. (Refer
to the following table for z*-values.)
80% 1.28
95% 1.96
98% 2.33
99% 2.58
To calculate a CI for the difference between two population proportions, do the following:
1. Determine the confidence level and find the appropriate z*-value.
For the first sample by taking the total number from the first sample that are in the category of
interest and dividing by the sample size, n1. Similarly, find for the second sample.
4. Find
And divide that by n2. Add these two results together and take the square root.
6. Take
Plus or minus the margin of error from Step 5 to obtain the CI.
Suppose you work for the Las Vegas Chamber of Commerce, and you want to estimate with
95% confidence the difference between the percentage of all females who have ever gone to see
an Elvis impersonator and the percentage of all males who have ever gone to see an Elvis
impersonator, in order to help determine how you should market your entertainment offerings.
Is 53 divided by 100 = 0.53. Suppose also that your random sample of 110 males includes 37
males who have ever seen an Elvis impersonator, so
3. The difference between these sample proportions (females – males) is 0.53 – 0.34 = 0.19.
4. Take 0.53 ∗ (1 – 0.53) to obtain 0.2941. Then divide that by 100 to get 0.0025. Then take
0.34 ∗ (1 – 0.34) to obtain 0.2244. Then divide that by 110 to get 0.0020. Add these two results
to get 0.0025 + 0.0020 = 0.0045. Then find the square root of 0.0045 which is 0.0671.
5. 1.96 ∗ 0.0671 gives you 0.13, or 13%, which is the margin of error.
6. Your 95% confidence interval for the difference between the percentage of females who have
seen an Elvis impersonator and the percentage of males who have seen an Elvis impersonator is
0.19 or 19% (which you got in Step 3), plus or minus 13%. The lower end of the interval is 0.19
– 0.13 = 0.06 or 6%; the upper end is 0.19 + 0.13 = 0.32 or 32%.
To interpret these results within the context of the problem, you can say with 95% confidence
that a higher percentage of females than males have seen an Elvis impersonator, and the
difference in these percentages is somewhere between 6% and 32%, based on your sample.
The temptation is to say, “Well, I knew a greater proportion of women has seen an Elvis
impersonator because that sample proportion was 0.53 and for men it was only 0.34. Why do I
even need a confidence interval?” All those two numbers tell you is something about those 210
people sampled. You also need to factor in variation using the margin of error to be able to say
something about the entire populations of men and women.
For example, if you had switched the males and females, you would have gotten –0.19 for this
difference. That’s okay, but you can avoid negative differences in the sample proportions by
having the group with the larger sample proportion serve as the first group (here, females).
However, even if the group with the larger sample proportion serves as the first group,
sometimes you will still get negative values in the confidence interval. Suppose in the above
example that only 0.43 of women had seen an Elvis impersonator. Thus, the difference in
proportions is 0.09, and the upper end of the confidence interval is 0.09 + 0.13 = 0.22 while the
lower end is 0.09 – 0.13 = –0.04. This means that the true difference is reasonably anywhere
from 22% more women to 4% more men. It’s too close to tell for sure.
The single mean (or one-sample) t-test is used to compare the mean of a variable in a sample of
data to a (hypothesized) mean in the population from which our sample data are drawn. This is
important because we seldom have access to data for an entire population. The hypothesized
value in the population is specified in the Comparison value box.
We can perform either a one-sided test (i.e., less than or greater than) or a two-sided test (see
the Alternative hypothesis dropdown). We use one-sided tests to evaluate if the available data
provide evidence that the sample mean is larger (or smaller) than the comparison value (i.e., the
population value in the null-hypothesis)
Example :
We have access to data from a random sample of grocery stores in the UK. Management will
consider entering this market if consumer demand for the product category exceeds 100M units,
or, approximately, 1750 units per store. The average demand per store in the sample is equal to
1953. While this number is larger than 1750 we need to determine if the difference could be
attributed to sampling error.
You can find the information on unit sales in each of the sample stores in
the demand_uk.rda data set. The data set contains two variables, store_id and demand_uk. Our
null-hypothesis is that the average store demand in the UK is equal to 1750 unit so we enter that
number into the Comparison value box. We choose the Greater than option from the Alternative
hypothesis drop-down because we want to determine if the available data provides sufficient
evidence to reject the null-hypothesis favor of the alternative that average store demand in the
UK is larger than 1750.
The first two blocks of output show basic information about the test (e.g.,. The null and
alternative hypothesis) and summary statistics (e.g., mean, standard deviation, standard error,
margin or error, etc.). The final row of output shows the following:
Diff is the difference between the sample mean (1953.393) and the comparison value
(1750)
Se is the standard error (i.e., the standard deviation of the sampling distribution of diff)
t.value is the t statistic associated with diff that we can compare to a t-distribution
(i.e., diff / se)
p.value is the probability of finding a value as extreme or more extreme than diff if the
null hypothesis is true
Df is the degrees of freedom associated with the statistical test (i.e., n - 1)
5% 100% show the 95% confidence interval around the sample mean (1897 to Inf.).
These numbers provide a range within which the true population mean is likely to fall
If the calculated value the difference between the sample means is said to be significant
at 5% level of significance.
Cor. If the two samples are of same size and the data are paired, then t is defined by
Example Eleven students were given a test in statistics. They were given a month’s further
tuition and the second test of equal difficulty was held at the end of this. Do the marks give
evidence that the students have benefitted by extra coaching?
Boys 1 2 3 4 5 6 7 8 9 10 11
Marks I test 23 20 19 21 18 20 18 17 23 16 19
Marks II test 24 19 22 18 20 22 20 20 23 20 17
Sol. We compute the mean and the S.D. Of the difference between the marks of the two tests as
under:
Assuming that the students have not been benefitted by extra coaching, it implies that the mean
of the difference between the marks of the two tests is zero i.e.
Students
1 23 24 1 0 0
2 20 19 -1 -2 4
3 19 22 3 2 4
4 21 18 -3 -4 16
5 18 20 2 1 1
6 20 22 2 1 1
7 18 20 2 1 1
8 17 20 3 2 4
9 23 23 - -1 1
10 16 20 4 3 9
11 19 17 -2 -3 9
From table IV, we find that (for v=10) =2.228. As the calculated value of , the value
of t is not significant at 5% level of significance i.e. the test provides no evidence that the
students have benefitted by extra coaching.
Example:
From a random sample of 10 pigs fed on diet A, the increase in weight in certain period were
10,6,16,17,13,12,8,14,15,9 lbs. For another random sample of 12 pigs fed on diet B, the increase
in the same period were 7,13,22,15,12,14,18,8,21,23,10,17 lbs. Test whether diets A and B differ
significantly as regards their effect on increases in weight ?
Sol. We calculate the means and standard derivations of the samples as follows
Diet A Diet B
10 -2 4 7 -8 64
6 -6 36 13 -2 4
16 4 16 22 7 49
17 5 25 15 0 0
13 1 1 12 -3 9
12 0 0 14 -1 1
8 -4 16 18 3 9
14 2 4 8 -7 49
15 3 9 21 6 36
9 -3 9 23 8 64
10 -5 25
17 2 4
Assuming that the samples do not differ in weight so far as the two diets are concerned
i.e.
Hence the difference between the samples means is not significant i.e. thew two diets do not
differ significantly as regards their effects on increase in weight.
References