Jump to content

Statistics - Regression

  • PrintPrint

Regression and trend lines

A trend line is actually an equation of a line in the form Y = aX + b, where a is the slope of the line and b is the Y-intercept. Linear regression calculates the equation for this line by minimizing the sum of the squared residuals between the actual data points and the predicted data points using the estimated line’s slope and intercept. Once the slope and intercept have been calculated, it is fairly easy to substitute other values for X and predict a corresponding value for Y, or to substitute a value for Y and predict a value for X. When the X value is a measure of time (months or years, for example), the equation is specifically referred to as a trend line.
Linear regression is also used to estimate the fixed and variable components from a company’s or department’s total costs. In these circumstances, the values for X are usually the cost driver for the organization or department. Examples might include units produced, hours worked, hours of machine time, and others. The values for Y are the total cost for that level of X input. The computed slope of the linear regression line will indicate the variable cost per unit of X, while the computed Y-intercept will indicate the fixed cost. In many or most circumstances, this type of cost analysis will generate slopes and Y-intercepts that make sense in the real world. It is sometimes possible, though, that the fixed cost component in particular may not make any sense. The generated Y-intercept (fixed cost) might be negative, for example, to make the linear regression line fit the observed cost data as closely as possible. Be aware, as well, that it is rarely a good idea to use such an equation to predict too far into the future from the actual data used, since circumstances can change rather quickly.
Other types of regression exist that fit curves to sets of data, rather than a straight line. These all work in a similar manner, by finding an equation for a curve that fits as closely as possible to the provided data points.
When choosing between differing models fit to a set of data points, the choice is often made for the model with the highest correlation, as this measure generally reflects how good a fit a model has to the data points – a model with a correlation of 0.7 is generally not as good a fit to data as a model with a correlation of 0.9. However, this approach should be weighted along with other factors – the model’s usefulness and future expectations for example.

Statistics on the HP 30b

The HP 30b has many built-in statistics functions that apply to finding averages, standard deviations, standard error of the means as well as regression, correlation, and covariance. The HP 30b also accumulates many statistical sums for your use. Many of the HP 30b statistics functions are found in the menu, shown in the menu map on the next page.
The data the statistics functions use for computations must be entered first by pressing . If you enter the stats menu before you have entered any data, you will automatically be placed in the data menu. In this menu, enter a list of x values for one-variable statistics, a list of pairs, (x, y) for two-variable statistics, or a list of pairs, (x, y) for weighted, one-variable statistics, where the y values would be the weights. To enter data, key in a number and press . To enter a list of x values only, press to bypass the entry of y values. To review the data items that are in the data menu, you can press or to scroll through the values. To clear the data menu while in the menu, press , followed by pressing . To simply exit the menu, press .
When you press , your first choice needs to be the type of statistics you will be analyzing: 2 Variable, 1 Variable, or 1 Weight. Press to scroll through the options. When the option you wish to use is displayed, press to enter the second level of the menu, where you will need to choose descriptive, predictions, or sums by pressing to move between the choices and by pressing when the choice you want is displayed.
In this learning module, we will focus on the Predictions sub-menu of the stats menu as shown on the next page.
Figure 1: Statistics Menu – Predictions Regression sub-menu

The Best Fit feature

The table below lists the different regression models built into the HP 30b. Pressing will cycle through the regression model displayed. Press when the model you wish to use is displayed to select that model.
NOTE:When a regression model is displayed, pressing will perform a 'Best Fit' calculation and immediately change the displayed regression model choice to the regression model that best fits the data values, as determined by the model with the correlation whose absolute value is closest to 1. This feature can be very helpful if you are trying to predict values using a regression model.
Statistics Menu – Predictions Regression models
ItemDescription
a*X+bLinear regression
a*ln(X)+bLogarithmic regression
b*e^(aX)Exponential regression using base e
b*X^aPower regression using X as the base.
b*a^XPower regression using the coefficient a as the base.
a/X + bInverse regression.
aX2 +bX+cQuadratic regression.
The table below explains each of the entries in the Statistics – Predictions sub-menu in more detail.
HP 30b Statistics Menu – Predictions Sub-Menu items
ItemDescription
Pred XPredicted X value. Enter an X value to use for predicting a Y value and press , or predict an X value based upon the value found in Pred Y by pressing . Input/Output.
Pred YPredicted Y value. Enter an Y value to use for predicting an X value and press , or predict an Y value based upon the value found in Pred X by pressing . Input/Output.
aThe a coefficient for the selected regression model. Output only.
bThe b coefficient for the selected regression model. Output only.
cThe c coefficient for the quadratic regression model (only shown if the quadratic regression model is chosen). Output only.
CorrelationThe correlation of the X and Y values. Values range from +1 to -1. Output only. Not displayed for the quadratic regression model.
CovarianceThe covariance of the X and Y values. Output only. Not displayed for the quadratic regression model.

Practice solving regression problems

Example 1

John’s store has had sales for the last 5 months of $150, $165, $160, $175, and $170. Use a trend line to predict sales for months 6 and 7 and also predict when estimated sales would reach $200. What are the a and b coefficients (for a linear model, these would be the slope and intercept), and what are the correlation and covariance?

Solution

KeysDisplay
Figure 2: Calculating the predicted sales
Figure 3: Calculating the sales
Figure 4: Calculating the slope
Figure 5: Calculating the y-intercept
Figure 6: Calculating the correlation
Figure 7: Calculating the covariance
Figure 8: Calculating the sales in 6th month
Figure 9: Calculating the sales in 7th month
Figure 10: Calculating the prediction of sales

Answer

The slope is 5 and the y-intercept is 149. The linear regression equation is therefore Y = 5X + 149. Sales in month 6 are predicted to be $179 and in month 7 are expected to be $184. Sales are predicted to reach $200 between months 10 and 11 (actual answer is 10.2). The correlation is 0.82 and the covariance is 12.50.

Example 2

Assuming you have just finished example 1 and that the data is still in the calculator, which model is the best fit, giving the highest correlation? What is that correlation?

Solution

Re-enter the stats menu and navigate to the sub-menu item showing the regression model choice.
Figure 11: Using the regression model
Now, press to have the HP 30b choose the Best Fit model – the model with the correlation whose value is closest to -1 or +1.
KeysDisplay
Figure 12: Inverse regression - Best fit model
Figure 13: Calculating the correlation

Answer

The best fitting model is the inverse regression, with a correlation of -0.87, compared to 0.82 for the linear model. This may be worth considering as an alternative.

Example 3

Johnson’s Chair Company has experienced the following costs for the first 6 months of the year:
# Chairs MadeTotal Costs
5,000$120,000
5,500$122,100
4,800$118,540
5,300$122,400
4,950$119,100
5,150$124,200
What estimate would a linear regression equation produce for Johnson’s fixed and variable cost? What are the total costs predicted if 5,400 chairs were to be made? If the total costs were $125,000, how many chairs would you estimate had been produced? Is a linear regression line the best model? If not, what is?

Solution

The X values will be the number of chairs produced. The Y values will be the total costs.
KeysDisplay
Figure 14: Calculating the total cost
Figure 15: Calculating the number of chairs produced
Figure 16: Calculating the slope
Figure 17: Calculating the Y-intercept
Figure 18: Calculating the correlation using linear regression
Figure 19: Inverse Regression - Best fit model
Figure 20: Calculating the correlation

Answer

The linear regression equation generated is of the form: Y = 6.18X + 89449.38. The slope of 6.18 is the estimate for the variable cost and the Y-intercept of 89,449.38 is the estimate for the fixed cost. The total cost estimate if 5,400 chairs were made is $122,806. The estimated number of chairs made if the total costs were $125,000 is 5,755 chairs. The correlation of the linear regression line is 0.72. The HP 30b computes the best fitting line as the inverse regression with a correlation of -0.73. Since this is barely 'better' than the 0.72 of the linear model, there may be no compelling reason to switch from the linear model, particularly since the linear model provides a clearer meaning for fixed and variable costs.

HP Support forums

Find solutions and collaborate with others on the HP Support Forum
HP.comHP on FacebookHP on TwitterHP on YouTubeHP on Linked InHP on FlickrHP on Google+