Docsity

Notes on Linear Regression Analysis | STA 6167, Study notes of Statistics

Toggle sidebar
bg1
1
1. Linear Regression Analysis
Introduction
A homeowner recorded the amount of electricity in kilowatt-hours (KWH) consumed in his
house on each of 21 days. He also recorded the numbers of hours his air conditioner (AC) was
turned on and the numbers of times his electric clothes dryer (DRYER) was operated. His
objective was to relate the KWH consumption to the AC and DRYER usage. In particular, he
wanted to know how many KWH’s the AC used per hour and the number of KWH’s used in
each run of the DRYER. Statistical regression analysis can serve this purpose.
Following are the data in tabular form:
KWH
AC
(hours) DRYER
(runs)
35 1.5 1
63 4.5 2
66 5.0 2
17 2.0 0
94 8.5 3
79 6.0 3
93 13.5 1
66 8.0 1
94 12.5 1
82 7.5 2
78 6.5 3
65 8.0 1
77 7.5 2
75 8.0 2
62 7.5 1
85 12.0 1
43 6.0 0
57 2.5 3
33 5.0 0
65 7.5 1
33 6.0 0
Figure 1 shows a plot of KWH versus AC.
In regression terminology, KWH is called the dependent variable and AC and DRYER are
called the independent variables. The names “dependent” and “independent” come from the
notion that the amount of KWH consumption depends on the amount of AC hours and DRYER
usage. Usually, dependent variables are denoted “y-variables” and independent variables are
denoted “x-variables.” The prime objective of linear regression analysis is to obtain an
equation of the form
01 2
KWH b b AC b DRYER=+ +
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Notes on Linear Regression Analysis | STA 6167 and more Study notes Statistics in PDF only on Docsity!

1. Linear Regression Analysis

Introduction

A homeowner recorded the amount of electricity in kilowatt-hours (KWH) consumed in his house on each of 21 days. He also recorded the numbers of hours his air conditioner (AC) was turned on and the numbers of times his electric clothes dryer (DRYER) was operated. His objective was to relate the KWH consumption to the AC and DRYER usage. In particular, he wanted to know how many KWH’s the AC used per hour and the number of KWH’s used in each run of the DRYER. Statistical regression analysis can serve this purpose.

Following are the data in tabular form:

KWH AC (hours)

DRYER (runs) 35 1.5 1 63 4.5 2 66 5.0 2 17 2.0 0 94 8.5 3 79 6.0 3 93 13.5 1 66 8.0 1 94 12.5 1 82 7.5 2 78 6.5 3 65 8.0 1 77 7.5 2 75 8.0 2 62 7.5 1 85 12.0 1 43 6.0 0 57 2.5 3 33 5.0 0 65 7.5 1 33 6.0 0

Figure 1 shows a plot of KWH versus AC.

In regression terminology, KWH is called the dependent variable and AC and DRYER are called the independent variables. The names “dependent” and “independent” come from the notion that the amount of KWH consumption depends on the amount of AC hours and DRYER usage. Usually, dependent variables are denoted “ y -variables” and independent variables are denoted “ x -variables.” The prime objective of linear regression analysis is to obtain an equation of the form

KWH = b 0 (^) + b AC 1 + b DRYER 2

that quantifies the dependency of KWH on AC and DRYER.

Simple Linear Regression Regression with a Single Independent Variable: KWH v AC

To get started, we shall investigate the dependency of KWH on AC, alone. Later, we shall explore the dependency of KWH on AC and DRYER simultaneously.

Figure 1. Kilowatt Hours versus AC Hours

Figure 1 shows that KWH increases as AC increase, as you would expect. In this application the rate of increase is more important than the simple fact that there is an increase. We already knew that the air conditioner consumes electricity, and therefore that KWH will increase with AC. What we want to know is how much electricity the AC is using per hour; that is, the rate of consumption.

consumed per day by all other electrical devices in the house.

Some things to think about:

  1. How precise is 5.34 as an estimate of the true rate of KWH consumption by the air conditioner? If we did the experiment over and over again, how much would the slopes vary from one experiment to the next? Can we use 5.34 to construct a confidence interval about the true rate?
  2. How accurate is 5.34 as an estimate of the true rate of KWH consumption by the air conditioner? If we did the experiment over and over again, would the estimates we obtain be clustered about the true rate? In other words, is the expected value of the estimate equal to the true rate?
  3. What other uses can be made of the regression equation? Can we predict the amount of KWH consumption on a certain day if we know the air conditioner usage was, say, AC=8 hours? What can we say about the accuracy and precision of the prediction?
  4. How well does the equation fit the data? Is a linear equation appropriate for this application?

The process of obtaining the equation of the line and making inference about the coefficients is called Linear Regression Analysis. At the heart of linear regression analysis is a statistical model.

Simple Linear Regression Model

The expression “Simple Linear Regression” refers to regression applications in which there is only one independent and one dependent variable. A simple linear regression model is given by the equation

y = β 0 + β 1 x + ε, (1)

where β 0 and β 1 are unknown parameters and ε is a random variable, usually considered

normally distributed.

The model equation (1) states that a value of y is equal to a linear function of x plus a random

quantity ε. The parameters β 0 and β 1 are the intercept and slope of the regression line. In the

electricity consumption example, y =KWH and x =AC would yield a simple linear regression

model for relating KWH to AC. The parameter β 1 is the expected KWH consumed per hour use

of the AC, and the parameter β 0 is the expected combined KWH used by all other electrical

devices in the house per day. These parameters are population quantities and cannot be known exactly, but can be estimated from the data. The quantity ε is a random quantity that accounts for random deviation from expected KWH consumption. For example, suppose the AC is turned on

for x = eight hours on a particular day. What is the value of y = KWH consumption? The expected consumption, that is, the mean consumption in the conceptual sub-population of all

similar days that the AC would be turned on for eight hours, is E y ( ) = β 0 + β 1 (8). The actual

KWH consumption for the particular day in question is the mean for that population plus the random quantity ε to account for deviation from the mean for that particular day. That is to say,

y = E ( y )+ ε = β 0 + β 1 x + ε. (2)

The mean, i.e. expected, KWH consumption for a day with known AC usage cannot be

calculated because it involves the unknown parameters β 0 and β 1. If the random ε values are

distributed independently with mean 0 and variance σ 2 , then the sub-population of KWH values

also has variance σ 2. These conditions can be summarized in the assumptions:

  1. The sub-population means are linear functions of the independent variable.
  2. The sub-population variances are equal for all values of the independent variable.
  3. The observations are independent.

A subscript can be inserted on x and y when it is necessary to write the model equation in reference to a particular observation. Generically, the subscript “ j ” could be used to indicate the “ j th” observation, and the model equation would be

yj = β 0 + β 1 xj + ε j , (3)

Fitting the Simple Linear Regression Model

In applications, the model is fitted to data using the method of least squares, giving the “prediction” equation

y ˆ = βˆ 0 + βˆ 1 x (4)

where βˆ 0 and βˆ 1 are estimates of β 0 and β 1 and y ˆ^ is a “predicted value” of y obtained by

inserting a value of x into the prediction equation. The prediction equation is also useful to

estimate the mean E ( y )= β 0 + β 1 x of the sub-population of y values corresponding to a given

value of x.

The caret above the parameters is called “hat” and is used to distinguish the actual parameters

from their estimates. Thus, βˆ 1 is called “beta-one hat.” Likewise, the estimate σˆ 2 of σ 2 is called

“sigma-squared hat.” All these parameter estimates can be computed from five summary statistics shown in Table 1, where n is the total number of data points.

Accounting for Variation in Simple Linear Regression

Another aspect of regression analysis is accounting for the variation in the dependent variable as it relates to variation in the independent variable. A fundamental equation is

y − y =( y − y ˆ)+( y ˆ− y ). (7)

Equation (7) states that a deviation of a value of the dependent variable from the overall mean, y − y , is equal to the sum of a deviation of the dependent variable from the predicted value, ( y − y ˆ), plus the deviation of the predicted value from the overall mean, y ˆ^ − y. It can be shown

that y ˆ^ − y =0 when x = x. Also, y ˆ^ − y changes by an amount βˆ 1 for each unit of change in x.

Thus, the deviation ( y ˆ − y )depends directly on the independent variable x. But the

deviation ( y − y ˆ)can be large or small, and positive or negative, for any value of x. So the

deviation ( y − y ˆ)does not depend directly on x. (The ( y − ˆ y )deviations are called “residuals.”)

It turns out that the sums of squares of the deviations in equation (7) obey a similar equation,

Σ( y − y )^2 =Σ( y − y ˆ)^2 +Σ( y ˆ− y )^2. (8)

The sums of squared deviations have names. The left side of the equation is call the total sum of

squares, and is denoted SS(Total)= Σ ( y − y )^2. The terms on the right side are the error and

regression sums of squares, SS(Regression) = Σ ( y ˆ − y )^2 and SS(Error)= Σ( y − y ˆ)^2. For brevity,

we write SSR=SS(Regression), SSE=SS(Error), and SST=SS(Total), and equation (8) takes the form

SST=SSR+SSE. (9)

The total sum of squares, SST, is a measure of the total variation in the values of the dependent variable y. The regression sum of squares, SSR, is a measure of the variation in y that is attributable to variation in the independent variable x. Finally, the error sum of squares measures the variation in y that is not attributable to changes in x. Thus equation (9) shows the fundamental partitioning of the total variation into the portion attributable to x and the portion not attributable to x. The coefficient of determination , usually denoted R^2 , is SSR divided by SST, and thus measures the proportion of total variation in y that is attributable to variation in x ,

R^2 = SSR/SST. (10)

Analysis of Variance for Simple Linear Regression

The generic analysis of variance associated with the regression is shown in Table 2.

Source of Variation

Degrees of Freedom DF

Sum of Squares SS

Mean Square MS

Regression 1

SS for Regression SSR

MS for Regression MSR Error n-2 SSE MSE Total n-1 SST

Table 2. Generic ANOVA Table for Regression Analysis

The column headed DF contains degrees of freedom for the sums of squares. The column headed MS contains mean squares , which are the corresponding sums of squares divided by the

degrees of freedom. The error mean square, MSE, is an estimate of σ 2 , the variance of the

errors, σˆ 2 =MSE.

Analysis of Variance Computations for Simple Linear Regression

The sums of squares in the ANOVA table can be calculated from the summary statistics as SSR= S (^) xy^2 / S (^) xx , SST = S (^) yy , and SSE = S (^) yy - S (^) xy^2 / S (^) xx. These computations for the KWH data are

SSR = 1050.3^2 /196.64 = 1,103,130/196.64 = 5609.7,

SST = 9578.6,

and SSE = 9578.8 – 5609.7 = 3968.9.

For the KWH data, the analysis of variance (ANOVA) is

Source of Variation DF SS MS Regression 1 5609.7 5609. Error 19 3968.9 208. Total 20 9578.

This gives R^2 = 5609.7/9578.6 = .5856.

The estimate of σ 2 is σˆ 2 = MSE = 208.9, and the estimate of the error standard deviation

is σˆ =(208.9) .5=14.45.

Prediction and Estimation of Sub-population Means

It is often useful to make inference about the mean of a sub-population corresponding to a given value of x , say x 0. The estimate of the subpopulation mean is obtained by inserting x 0 into the

prediction equation. That is, the estimate of E ( y )= β 0 + β 1 x 0 is ˆ y = βˆ 0 + βˆ 1 x 0. The standard

error of y ˆ = βˆ 0 + βˆ 1 x is needed to make statistical inference about E ( y )= β 0 + β 1 x 0. The

variance of the sampling distribution is

V( y ˆ^ ) = σ 2 (1/n + ( x 0 − x )^2 / S xx ). (16)

Therefore the standard error is

s.e.( y ˆ ) = (MSE(1/n + ( x (^) 0 − x )^2 / S (^) xx )) .5^. (16)

A 95% confidence interval for the mean of the sub-population of y values corresponding to x = x 0 is

βˆ^0 + βˆ 1 x 0 ± t. 025 (MSE(1/n + ( x 0 − x )^2 / S xx )) .5^. (17)

Consider the conceivable days when the AC could be turned on for 10 hours. A 95% confidence interval for the mean KWH consumption on those days is

81.25 ± 2.1(208.9(1/21 + (10 – 6.93) 2 /196.64)) .5^ , or 81.25 ± 9.38 = (71.87,90.63).

When used to predict a value of y , the relevant variance is the prediction variance

V( y ˆ^ − y ) = σ 2 (1 + 1/n + ( x 0 − x )^2 / S xx ). (18)

The relevant standard error is

s.e.( y ˆ^ − y ) = (MSE(1 + 1/n + ( x 0 (^) − x )^2 / S (^) xx )) .5^. (19)

A 95% prediction interval for the y value corresponding to x = x 0 is

βˆ^0 + βˆ 1 x 0 ± t. 025 (MSE(1 + 1/n + ( x 0 − x )^2 / S xx )) .5^. (20)

Now consider the particular day when the homeowner had the AC turned on for 10 hours. A 95% prediction interval is

81.25 ± 2.1(208.9(1 + 1/21 + (10 – 6.93) 2 /196.64)).5^ , or 81.25 ± 31.77 = (49.48,113.02).

Figures 3 shows 95% confidence intervals for subpopulation means at each possible value of value of AC, ranging from AC=0 to AC=15. Constructed in this manner, the set intervals form a “band” about the regression line. You can see that several individual data points are outside the interval. This illustrates the important distinction between a confidence interval and a prediction interval. The 95% for a confidence interval at a given value of AD refers to the probability that

the interval contains the subpopulation mean, E ( y )= β 0 + β 1 x 0 , whereas the 95% for a prediction

interval refers to the probability that the interval contains an individual value, y = β 0 + β 1 x 0 + ε.

Figure 3. 95% Confidence Band for KWH Means

Graphical Diagnostics for Goodness of Fit

Residual values, y − y ˆ, should be approximately normally distributed and independent.

Therefore, if the residuals are plotted versus values of AC, the resulting plot should show a random scattering of points. Such a plot is called a “residual plot” and can be used to visually assess whether the assumptions for the regression analysis are valid.

There are primarily three patterns to look for. One is for points that fall distinctly outside the general pattern of other points. Such points are called “outliers.” Another is a “bend” in the pattern, which indicated the relationship between the dependent variable and independent variable is not linear. The last is a “funnel” shaped pattern, that indicates the variance is not constant across all values of the independent variable.

Figure 5 shows a plot of KWH residuals plotted versus AC values. This plot indicates no obvious violation of model assumptions.

Figure 5. KWH Residuals versus AC

Regression with a Single Independent Variable: KWH v DRYER

Now we investigate the dependency of KWH on DRYER. Figure 6 shows the linear regression results.

Figure 6. Regression of KWH versus DRYER

The regression equation is

KWH = 46.66 + 12.74(DRYER).

The analysis of variance table is

Source of Variation DF SS MS Regression 1 3429.7 3429. Error 19 6148.8 323. Total 20 9578.

This gives R^2 = 3429.7/9578.6 = .3581, compared with R^2 = .5856 in the regression on AC. Thus, more variation is attributable to AC than to DRYER.

Figure 8 shows confidence limits for expected KWH consumption for all values of DRYER. The bands is generally wider than the band in Figure 3 because of the larger value of MS(Error).

Figure 8. Confidence Limits for Expected KWH versus DRYER

Figure 9 shows prediction limits for individual values of KWH for all values of DRYER.

Figure 9. Predictions Limits for Individual KWH versus DRYER

end; run ;

proc print data=acplot; run ;

Title2 'Regression of KWH vs AC'; run ;

data acplot; merge acplot kilowatt; by ac; run ;

proc reg data=acplot; id ac; model kwh=ac/p; plot kwh*ac; output out=acplot1 p=acpred r=acresid1; run ;

proc gplot data=acplot1; plot acresid1ac; plot acresid1acpred; run ;

proc reg data=acplot; id ac; model kwh=ac/p clm cli; plot kwh*ac; output out=acplot2 p=acpred lclm=lcl uclm=ucl lcl=lpl ucl=upl; run ;

proc print data=acplot2; run ;

proc gplot data=acplot2; plot kwhac acpredac lclac uclac / overlay; plot kwhac acpredac lplac uplac / overlay; run ;

Title2 'Regression of KWH vs DRYER'; run ;

proc sort data=kilowatt; by dryer; run ;

data dryplot;

do dryer= 0 to 3 by .1 ; kwh=. ; output; end; run ;

proc print data=dryplot; run ;

data dryplot; merge dryplot kilowatt; by dryer; run ;

proc reg data=dryplot; id ac; model kwh=dryer/p; plot kwh*dryer; output out=dryplot1 p=drypred r=dryresid1; run ;

proc gplot data=dryplot1; plot dryresid1dryer; plot dryresid1drypred; run ;

proc reg data=dryplot; id ac; model kwh=dryer/p clm cli; plot kwh*dryer; output out=dryplot2 p=drypred lclm=lcl uclm=ucl lcl=lpl ucl=upl; run ;

proc print data=dryplot2; run ;

proc gplot data=dryplot2; plot kwhdryer drypreddryer lcldryer ucldryer / overlay; plot kwhdryer drypreddryer lpldryer upldryer / overlay; run ;