HP HP 30S User manual

hp calculators
HP 30S Statistics – Linear Regression
Linear Regression
Practice Solving Linear Regression Problems

hp calculators
HP 30S Statistics – Linear Regression
Linear regression
A regression of yon xis a way of predicting values of ywhen values of xare given. If the regression is based on a
straight line graph, it is called a linear regression, and the straight line is called the regression line.
The regression line (sometimes referred to as the line of best fit) of yon xis then the line that gives the best prediction of
values of yfrom those of x, and is:
where nxby
aii
∑
∑−
=and
n)x(
x
nyx
yx
bi
i
ii
ii
2
2∑
∑
∑
∑
∑
−
−
=
bxay
+
=
nbeing the number of data pairs. (Note that the regression line of xon y, which is usually different from the regression
line of yon x, can be found by interchanging xand yin the above expressions). aand bare known as the linear
regression coefficients. The independent variable is the regressor, and the dependent variables is called regressand.
The coefficients are found by minimizing the sum of the squares of the vertical distances of the points from the line (i.e.
the sum of the squares of the residuals). This method is known as least squares.
The correlation coefficient is a measure of the amount of agreement between the xand yvariables, and is given by:
⎟
⎟
⎠
⎞
⎜
⎜
⎝
⎛−
⎟
⎟
⎠
⎞
⎜
⎜
⎝
⎛−
−
=∑
∑
∑
∑
∑
∑
∑
n)y(
y
n)x(
x
nyx
yx
r
i
i
i
i
ii
ii
2
2
2
2
When r is positive, the correlation is positive, which means that high values of one variable correspond to high values of
the other. Conversely, if r is negative then the correlation is negative: low values of one variable correspond to high
values of the other. An important property of r is that 11
≤
≤
−
r. The ±1 values correspond to a perfect correlation:
real values and estimates are exactly the same. If r = 0 thenthere’s no correlation: x and y are uncorrelated.
On the HP 30S, linear regressions are calculated in 2-VAR STAT operating mode. First of all, let’s clear any previous
data. To do so, press –1to display the STAT menu, and then select CLR-DATA using the <and @keys, finally
press yto confirm. Next, press –1again, select 2-VAR, and press y. You’re now ready to carry out
regression calculations on your calculator, which are illustrated by the following examples.
Practice solving linear regression problems
Example 1: A quality control engineer notes a relationship between the amount of chemical added to a batch, and the
final concentration of the chemical in the final product. The following table shows the weight in grams
added (x) and the weight in the final product (y):
hp calculators - 2 - HP 30S Statistics – Linear Regression - Version 1.0

hp calculators
HP 30S Statistics – Linear Regression
x 2 1 6 3 7 6 9
y 3 1 5 5 7 8 8.5
Find the linear regression line and the correlation coefficient for this data.
Solution: First of all, we have to enter the given data, which is really easy on the HP 30S. Simply pressing a
makes your calculator prompt you for the first value displaying “x1=” in the entry line. Let’s now enter the
data by pressing:
2?3?1?1?6?5?3?5?7?7?6?8?9?8.5
?
Data pairs are entered in order, the x values first. Notice that values are actually entered by pressing the ?
key, not the ykey. This is because you may wish to calculate a value first (e.g. A y+ B % ANS y)
– keep in mind that the history stack (i.e. a log of past calculations) is not available in STAT mode, but the
ANS variable can be used, and the most recent calculation can be retrieved to be edited. Correcting data is
as easy as using the &and ?keys to display the wrong value and change it. The new value replaces the
old one: you need not press oto clear the entry line.
Once all the values have been entered, results can be displayed by pressing b. This displays a menu
with seventeen variables. Select the desired result using the <and the @keys. Values appear in the
result line. Pressing yputs the selected variable (its name, not its value) into the entry line for further
calculations. This menu works much likethe CONST menu.
Answer: Expressed to two decimal digits, a = 1.22 and b = 0.85, therefore the regression line is:
. The correlation coefficient, is 0.91, which means that the correlation is positive and
that it is quite a good fit since r is close to 1. However, exactly how far away from this value the correlation
can be and the equation still be considered a good predictor is certainly a matter of debate.
x..y 850221 +=
Example 2: If the engineer adds 4 grams of the chemical, what will be the concentration in the final product?
Solution: Predicted values can be easily calculated using the regression line, but the quickest way is to use the
STATVAR menu again. Press b, select and press y. The entry line now reads with the
blinking cursor placed on the right parenthesis. returns a predicted y value given an x value, that is,
returns (remember that these numbers are shown to two decimal digits in this document,
but not on your calculator). Enter the given x value: 4and press yto calculate the predicted
concentration.
'y )('y
'y
x.. 850221 +
Answer: 4.63. In many textbooks is written as . It is important to understand that the actual
concentration may well be different.: the regression line is just a mathematical model of the reality.
=)('y 4'y y
ˆ
Example 3: In order to obtain a concentration of 10.5, how much chemical should she add?
Solution: Once again press bbut select this time, and press yto put this function into the entry line.'x
returns'x bay −. Enter the given y value: 10.5 and press yto calculate the estimated
amount of chemical.
hp calculators - 3 - HP 30S Statistics – Linear Regression - Version 1.0

hp calculators
HP 30S Statistics – Linear Regression
Answer: 10.89 grams.=).('x 510 =).(x
ˆ510
Example 4: The previous examples are based on the regression of the final concentration (y) on the amount of
chemical added (x). Would the last result obtained be equal to if we were studying the regression
of xon y? ).('y 510
Solution: The most likely answer is no. yis the dependent variable and x is the independent variable. Their roles
cannot be interchanged. If we interchange x and y, we change our experiment, the results of which may
well be meaningless. Let’s see what happens, by swapping the given data, and then we’ll find .
Press aand reenter the data in the following order: ).('y 510
3?2???5?6?5?3???8?6?8.5?9?
To find
press:).('y 510
b@@@@@@@@ (to select ) y10.5y'y
Answer: According to the new regression, the predicted value is 9.88 grams. The regression line is now
(where x is still the amount of chemical added and y is the concentration), whichy..x 980380 +−=
is not the same as before ( y..x 181441
+
−= )
Example 5: By polling fifty people, a survey taker obtained the following data:
, , , and
3333=
∑i
x9459.yi=
∑231933
2=
∑i
x574308
2.yi=
∑7530549.yx ii =
∑
Judging by the correlation coefficient , is there a linear relation between xand y?
Solution: rcan be calculated using the formula given on page 2:
⎟
⎟
⎠
⎞
⎜
⎜
⎝
⎛−
⎟
⎟
⎠
⎞
⎜
⎜
⎝
⎛−
⋅
−
=
509459
574308
50
3333
231933
50 94593333
7530549
22 .
.
.
.
r
Let’s enter it into the entry line by pressing:
r30549.75-333*459.9/50s
/pr231933-3333q/50sr43
08.57-459.9q/50and finally y.
Answer: r = –0.12, so we can assume there’s no linear relation at all.
hp calculators - 4 - HP 30S Statistics – Linear Regression - Version 1.0

hp calculators
HP 30S Statistics – Linear Regression
Example 6: An experimenter obtained the following data:
x 300 420 450 500 610 780 800
y 11.1 12.2 12.5 13 15.6 15.8 16.1
Determine whether there is a linear relation between xand y.
Solution: First of all, let’s clear any previous data: –1, select CLR-DATA and press y. This is not required
in this example: since the number of data items did not change, new data would overwrite the old ones.
But, it’s a good habit to clear previous data before starting a new regression calculation. 2-VAR mode was
already set, so we can now enter the data as follows:
a300?11.1?420?12.2?450?12
.5?500?13?610?15.6?780?15.
8?800?16.1?
Let’s now find the linear correlation coefficient: b<<<<<<.
Rounded to four decimal places, r = 0.9624. Even though it is quite close
to one, the experimenter expected a more conclusive result. By plotting a
scatter graph (figure 1), she notices that point (610, 15.6) is anomalous,
and is consequently removed from the data set. To do so, press: Figure 1
a& seven times, and e(NB: not o).
The new correlation coefficient is displayed as above. i.e. by pressing band then the left arrow key six
times.
Answer: r = 0.9997, so there’s strong evidence that the relation is linear. The regression line is
x..y 010038
+
=
Example 7: Find the power curve that best fits the following data:
n
xmy ⋅=
x 0.50 0.75 1.00 1.25 1.50 2.00
y 0.47 1.43 3.15 5.75 9.45 20.68
Solution: This problem can be solved on your HP 30S by making the substitutions y’ = ln y, and x’ = ln x. The model
becomes: , which is a linear form. Clear the statistical data ( –1, select CLR-DATA
and press y) and enter the new data as follows:
'xnmln'y ⋅+=
ah.5?h.47?h.75?h1.43?h1?
h3.15?h1.25?h5.75?h1.5?h
9.45?h2?h20.68?
In the STATVAR menu ( b), we find that a = 1.140696782 and b = 2.728608754. Since b = n and
, then n = 2.728608754, and , which can be calculated as follows:
mlna =a
em =
o—Hb<(eight times) yy
Answer: Rounding to two decimal digits,
732
133 .
x.y ⋅=
hp calculators - 5 - HP 30S Statistics – Linear Regression - Version 1.0
Table of contents
Other HP Calculator manuals