Docsity

Lecture Notes #7: Residual Analysis and Multiple Regression ..., Summaries of Statistics

Toggle sidebar
bg1
Lecture Notes #7: Residual Analysis and Multiple Regression 7-1
Richard Gonzalez
Psych 613
Version 3.0 (Nov 2021)
LECTURE NOTES #7: Residual Analysis and Multiple Regression
Reading Assignment
KNNL chapter 6 and chapter 10; CCWA chapters 4, 8, and 10
1. Statistical assumptions
The standard regression model assumes that the residuals, or ϵ’s, are independently, identi-
cally distributed (usually called “iid” for short) as normal with µ= 0 and variance σ2.
(a) Independence
A residual should not be related to another residual. Situations where independence
could be violated include repeated measures and time series because two or more resid-
uals come from the same subject and hence may be correlated. Another violation of
independence comes from nested designs where subjects are clustered (such as in the
same school, same family, same neighborhood). There are regression techniques that
relax the independence assumption, as we saw in the repeated measures section of the
course.
(b) Identically distributed
As stated above, we assume that the residuals are distributed N(0, σ2
ϵ). That is, we
assume that each residual is sampled from the same normal distribution with a mean of
zero and the same variance throughout. This is identical to the normality and equality
of variance assumptions we had in the ANOVA. The terminology applies to regression
in a slightly different manner, i.e., defined as constant variance along the entire range of
the predictor variable, but the idea is the same.
The MSE from the regression source table provides an estimate of the variance σ2
ϵfor
the ϵ’s.
Usually, we don’t have enough data at any given level of X to check whether the Y’s are
normally distributed with constant variance, so how should this assumption be checked?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Lecture Notes #7: Residual Analysis and Multiple Regression ... and more Summaries Statistics in PDF only on Docsity!

Richard Gonzalez

Psych 613

Version 3.0 (Nov 2021)

LECTURE NOTES #7: Residual Analysis and Multiple Regression

Reading Assignment

KNNL chapter 6 and chapter 10; CCWA chapters 4, 8, and 10

1. Statistical assumptions

The standard regression model assumes that the residuals, or ϵ’s, are independently, identi-

cally distributed (usually called “iid” for short) as normal with μ = 0 and variance σ^2.

(a) Independence

A residual should not be related to another residual. Situations where independence

could be violated include repeated measures and time series because two or more resid-

uals come from the same subject and hence may be correlated. Another violation of

independence comes from nested designs where subjects are clustered (such as in the

same school, same family, same neighborhood). There are regression techniques that

relax the independence assumption, as we saw in the repeated measures section of the

course.

(b) Identically distributed

As stated above, we assume that the residuals are distributed N(0, σ^2 ϵ ). That is, we

assume that each residual is sampled from the same normal distribution with a mean of

zero and the same variance throughout. This is identical to the normality and equality

of variance assumptions we had in the ANOVA. The terminology applies to regression

in a slightly different manner, i.e., defined as constant variance along the entire range of

the predictor variable, but the idea is the same.

The MSE from the regression source table provides an estimate of the variance σ^2 ϵ for

the ϵ’s.

Usually, we don’t have enough data at any given level of X to check whether the Y’s are

normally distributed with constant variance, so how should this assumption be checked?

One may plot the residuals against the predicted scores (or instead the predictor vari-

able). There should be no apparent pattern in the residual plot. However, if there is

fanning in (or fanning out), then the equality of variance part of this assumption may be

violated.

To check the normality part of the assumption, look at the histogram of the residuals to

see whether it resembles a symmetric bell-shaped curve. Better still, look at the normal

probability plot of the residuals (recall the discussion of this plot from the ANOVA

lectures).

2. Below I list six problems and discuss how to deal with each of them (see Ch. 3 of KNNL for

more detail)

(a) The association is not linear. You check this by looking at the scatter plot of X and

Y. If you see anything that doesn’t look like a straight line, then you shouldn’t run a

linear regression. You can either transform or use a model that allows curvature such

as polynomial regression or nonlinear regression, which we will discuss later. Plotting

residuals against the predicted scores will also help detect nonlinearity.

(b) Error terms do not have constant variance. This can be observed in the residual plots.

You can detect this by plotting the residuals against the predictor variable. The residual

plot should have near constant variance along the levels of the predictor; there should

be no systematic pattern. The plot should look like a horizontal band of points.

(c) The error terms are not independent. We can infer the appropriateness of this assump-

tion from the details of study design, such as if there are repeated measures variables.

You can perform a scatter plot of residuals against time to see if there is a pattern (there

shouldn’t be a correlation). Other sources of independence violations are due to group-

ing such as data from multiple family members or multiple students from the same

classroom; there may be correlations between individuals in the same family or individ-

uals in the same classroom.

(d) Outliers. There are many ways to check for outliers (scatter plot of Y and X, examining

the numerical value of the residuals, plotting residuals against the predictor). We’ll

also cover a more quantitative method of determining the degree to which an outlier

influences the regression line.

(e) Residuals are not normally distributed. This is checked by either looking at the his-

togram of the residuals or the normal-normal plot of the residuals.

(say, making it 2 or 3) or decreasing p (say, making it 0, which leads to the log, or -1, which

is the reciprocal).

With two variables Y and X it is possible to transform either variable. That is, either of these

are possible: Yp = β 0 + β 1 X or Y = β 0 + β 1 Xp. Of course, the two exponents in these

equations will usually not be identical.

The rule of the bulge is a heuristic for determining what exponent to use on either the de-

pendent variable (Y) or the predictor variable (X) to help linearize the relation between two

variables. First, identify the shape of the “one-bend” curve you observe in the scatter plot

with variable Y on the vertical axis and variable X on the horizontal axis (all that matters is

the shape, not the quadrant that your data appear in). Use the figure below to identify one of

the four possible one-bend shapes. The slope is irrelevant, just look at the shape (i.e., is it “J”

shaped, “L” shaped, etc.).

Once you identify a shape (for instance, a J-shape pattern in the far right of the previous

figure), then go to the “rule of the bulge” graph below and identify whether to increase or

decrease the exponent. The graph is a gimmick to help you remember what transformation to

use given a pattern you are trying to deal with. For example, a J-shape data pattern is in the

south-east portion of the plot below. The “rule of the bulge” suggests you can either increase

the exponent on X so you could try squaring or cubing the X variable, or instead you could

decrease the exponent on Y such as with a log or a reciprocal. The action to “increase” or

“decrease” is determined by whether you are in the positive or negative part of the “rule of the

bulge” figure, and which variable to transform (X or Y) is determined by the axis (horizontal

or vertical, respectively).

X

Y

increase p on Y

decrease p on X

decrease p on Y

decrease p on X

increase p on Y

increase p on X

decrease p on Y

increase p on X

If you decide to perform a transformation to eliminate nonlinearity, it makes sense to trans-

form the predictor variable X rather than the criterion variable Y. The reason is that you may

want to eventually test more complicated regressions with multiple predictors. If you tinker

with Y you might inadvertently mess up a linear relation with some other predictor predictor

variable.

An aside with a little calculus. Sometimes transformations follow from theory. For example,

if a theory presupposes that changes in a dependent variable are inversely related to another

variable, as in the differential equation

dY(X)

dX

X

then this differential equation has the solution

Y(X) = α ln X + β (7-2)

Dealing with the equality of variance assumption is tricky. In a few cases it may be possible

to transform a variable to eliminate the equality of variance (as was the case in ANOVA),

but you have to be careful that the transformation does not mess up other assumptions (in

particular, linearity). Conversely, if you perform a transformation to “clean up” a nonlinearity

problem, you need to be careful that the transformation did not inadvertently mess up the

equality of variance assumption.

Another possible remedial measure in this case is to perform a weighted regression. If your

subjects are clustered and the variances depends on the cluster, then you could weight each

data point by the inverse of the variance. See KNNL ch 11 for details on weighted regression.

6. Outliers

By outlier we mean a data point that has the potential to exert a “disproportionate” degree of

influence on the regression line. A simple index of an outlier is the residual (i.e., the observed

score - predicted score). If a residual for a particular subject is large, then that data point is

suspect as a possible outlier.

With more than one predictor, spotting an outlier is difficult because we need to think about all

the variables (dimensions) concurrently. For instance, with three predictors, an outlier means

that the point “sticks out” in comparison to all the other points within the four dimensional

plot (one dependent variable and three predictors). So simple pairwise scatterplots won’t

always be an option.

Chapter 10 of KNNL discusses various normalizations on the residuals that can be performed.

For instance, is a residual of 3 large or small? In order to tell we can normalize the residuals

into a common scale. Obviously, the magnitude of the residual depends, in part, on the scale

of the dependent variable. There is one normalization that is analogous to a Z score (dividing

the residual by the square root of the MSE). Another set of normalizations involve deleted

residuals (if interested, see chapter 10 KNNL).

Cook’s D One of the best ways to detect an outlier, and whether it is an influential outlier, is through

the use of Cook’s D. This is a measure of the influence on the overall regression of the single

data point in question. Each data point has a Cook’s D. To develop intuition on Cook’s D, I’ll

present an example involving midterm exams. We first look at the scatter plot (Figure 7-2)

and the correlation.

data list free/ test1 test2.

begin data [data go here] end data.

Figure 7-2: SPSS scatter plot

Plot of TEST2 with TEST

TEST

30 40 50 60

TEST

60

50

40

30

20

plot format=regression /plot test2 with test1.

correlation test2 test /print= twotail /statistics=all.

[OUTPUT FROM CORRELATION COMMAND]

Variable Cases Mean Std Dev TEST2 28 39.0357 6. TEST1 28 48.5714 4.

Variables Cases Cross-Prod Dev Variance-Covar TEST2 TEST1 28 465.4286 17.

    • Correlation Coefficients - - TEST2 TEST

TEST2 1.0000.

----------- in ------------

Casewise Plot of Standardized Residual

*:^ Selected^ M:^ Missing

Residuals Statistics:

Figure 7-3: SPSS scatter plot

Plot of RESID with TEST

TEST

30 40 50 60

Residual

8

6

4

2

0

*COOK^ D^ .0002^ .4770^ .0479^ .0987^28

*LEVER^ .0004^ .2295^ .0357^ .0540^28

Total Cases = 28

It appears that subject 23 is an outlier because the residual (-12.71) is much larger in mag-

nitude than any other residual. We’ll omit that subject for now and redo the analysis. That

particular subject was the only one to have a test2 score of 21 so we can conveniently select

that subject out by asking SPSS to not use subjects whose test2 score equals 21. Had the

data file included a subject ID index (e.g., a subject number), then it would have been more

efficient to select directly on subject number.

select if (test2 ne 21). execute.

*LEVER^ .0001^ .2555^ .0370^ .0603^27

Total Cases = 27

In the two regressions the slopes are comparable but the intercepts differ a great deal in ab-

solute terms. Further, the R^2 s are not very across the two regressions suggesting that the

two regressions are comparable. Perhaps that point we suspected to be an outlier is not very

influential because its presence or absence does little to change the resulting regression.

The main things to note in this example are the effects of the outlier on the parameter estimates

and how the residuals, and associated printouts, were used to decipher where the assumptions

were being violated. The way we detected whether this suspected point was an outlier was to

remove it and re-run the regression. We compared the effects of the model with the suspected

outlier included and the model without the suspected outlier. For this example, both cases

yielded comparable results. So, for this example including the outlier will not do too much

damage.

I am not advocating that outliers be dropped in data analysis. Rather, I simply compared

two different regressions (one with the outlier and one without) to see whether the results

differed. The comparison of these two regressions lets me assess how much “influence” the

particular data point has on the overall regression. This time the two regressions were similar

so I feel pretty confident in reporting results with all subjects. In this example the outlier

appears to have little impact on the final result.

This idea of comparing the model with the outlier and the model without the outlier can

be extended. Why not do this for every data point? First, perform one regression with all

the data included. Then perform N different regressions; for each regression a single data

point is removed. This would tell us how “influential” each data point is on the regression

line. Luckily, there is a quick way of doing this computation (if you had 200 subjects, the

technique I just outlined would require 201 separate regressions). The quick way is Cook’s

D (D stands for distance). The formula for Cook’s D involves quite a bit of matrix algebra so

I won’t present it here (see KNNL for a derivation). Cook’s D is basically a measure of the

difference between the regression one gets by including subject i and the regression one gets

by omitting subject i. So, each subject gets his or her own Cook’s D. A subject’s individual

D is an index of how influential that subject’s data are on the regression line. Large values

of Cook’s D indicate that the particular data point (subject) has a big effect on the regression

equation. Cook’s D is influenced both by the residual and the leverage^1 of the predictors.

1 For a definition of leverage see KNNL. It turns out that SPSS has it’s own definition of leverage. SPSS uses a centered

leverage, i.e., ˆhi - 1 n where n is the number of subjects. Most people just use ˆhi. SPSS prints out the leverage values as

part of the casewise plot (labeled LEVER; in most versions of SPSS you have to write “lever” on the casewise line to get

this to print out).

Determining what constitutes a large value of Cook’s D involves calculating the sampling

distribution for F, so we’ll just have to make good guesses as to constitutes high values of

Cook’s D. A rule of thumb is to look for Cook’s D values that are relatively greater than

the majority of the D’s in the sample. Some people propose a simple rule of thumb, such

as any Cook’s D greater than 4/N is a potential influential outlier. in this example with 27

observations 4/27=.148 so two points are potential influential outliers.

Another strategy for determining key values of Cooks D is to use the F table to set up crit-

ical values. Use α = 0. 50 (not 0.05), the numerator degrees of freedom are the number of

parameters in the structural model (including the intercept), and the denominator degrees of

freedom are N minus the number of parameters (the same df associated with MSE). For ex-

ample, with two predictors (so a total of 3 parameters including the intercept), 24 df in the

error, and α =. 50 , we find a tabled value of 0.812.

In the present example, there was one predictor so there were 2 parameters including the

intercept, there were 26 residual degrees of freedom. The F value corresponding to .50 with

2,26 degrees of freedom is .712. This gives a numerical benchmark for Cook’s D in this

particular example: any observed Cook’s D greater than 0.712 is suspect because it might be

an influential outlier.

One could use the built in F function in SPSS (or Excel) to find the necessary value of F. In

SPSS, for example, with the menu system under TRANSFORM-COMPUTE you will find a

list of functions. Select IDF.F. For this example you would type IDF.F(.50,2,26), define the

new variable you want the output to go into, and click on OK. Or, in the syntax window type

this command and you will get a new column of identical numbers that give the F cutoff

(“Fcrit” is an arbitrary name for the new column this command creates).

compute Fcrit = idf.f(.50, 2, 26).

execute.

An alternative but identical approach to finding the critical Cook’s D value would be to use

the inverse F function on the column of Cook D scores to find the cumulative area under the

F. That is, if you save Cook’s D scores in a new column called cook (or any other arbitrary

variable name you like), then you can run this command on that column of saved Cook D

scores:

compute pval = cdf.f(cook, 2, 26).

execute.

This syntax will produce a new column of “pvals”. Look for any “pval” greater than.

the three extra columns. These columns represent three different ways to code the predictor

variable. All are fine as long as you keep track of the values you used (much like interpreting

a contrast value that depends on the particular coefficients). The means for the two groups are

8.56 and 5.06, the grand mean is 6.81, and the treatment effect α is 1.75. Think about what

each of the three scatterplots (the first column on the y-axis and each of the three remaining

columns on separate x-axes) will look like.

data list free / dv dummy contrast group.

REGRESSION USING 0 AND 1 TO CODE FOR GROUPS

regression variables = dv dummy /statistics = r anova coeff ci /dependent = dv /method=enter dummy.

Multiple R .80955 Analysis of Variance R Square .65537 DF Sum of Squares Mean Square Adjusted R Square .63623 Regression 1 61.25000 61. Standard Error 1.33766 Residual 18 32.20800 1.

F = 34.23063 Signif F =.

Variable B SE B 95% Confdnce Intrvl B Beta T Sig T

DUMMY -3.500000 .598220 -4.756813 -2.243187 -.809552 -5.851. (Constant) 8.560000 .423005 7.671299 9.448701 20.236.

A SECOND REGRESSION USING 1 AND -1 TO CODE FOR GROUPS

regression variables = dv contrast /statistics = r anova coeff ci /dependent = dv /method=enter contrast.

Multiple R .80955 Analysis of Variance

R Square .65537 DF Sum of Squares Mean Square Adjusted R Square .63623 Regression 1 61.25000 61. Standard Error 1.33766 Residual 18 32.20800 1.

F = 34.23063 Signif F =.

Variable B SE B 95% Confdnce Intrvl B Beta T Sig T

CONTRAST -1.750000 .299110 -2.378406 -1.121594 -.809552 -5.851.

(Constant) 6.810000 .299110 6.181594 7.438406 22.768.

The test of significance for these two regressions are identical. The slope is reduced by 1/2 as

compared to the first regression. This is because the coding on the predictor variable is two

units apart (1 and -1) rather than one unit (1 and 0). The intercept also changes because of

two reasons: the line has shifted over to the left and the slope has changed.

Below is yet another predictor variable (1 and 2) as well as the usual two-sample t test and

the output from a oneway ANOVA so that you can compare regression and ANOVA.

t-test groups= group /variables dv.

Number Variable of Cases Mean SD SE of Mean


DV

GROUP 1 10 5.0600 1.189.

GROUP 2 10 8.5600 1.471.

Mean Difference = -3.

t-test for Equality of Means 95% Variances t-value df 2-Tail Sig SE of Diff CI for Diff


Equal -5.85 18 .000 .598 (-4.757, -2.243) Unequal -5.85 17.24 .000 .598 (-4.761, -2.239)

oneway dv by group(1,2) ANALYSIS OF VARIANCE

SUM OF MEAN F F

SOURCE D.F. SQUARES SQUARES RATIO PROB.

BETWEEN GROUPS 1 61.2500 61.2500 34.2306.

WITHIN GROUPS 18 32.2080 1.

TOTAL 19 93.

with the other predictors because this creates multicollinearity problems–the standard error

of the slope will be larger than it should be. More on this “multicollinearity problem” later.

With two predictors there is a three dimensional scatterplot that corresponds to the regression

problem. Figure 7-4 shows a scatterplot in three dimensions. The three dimensions refer to

the predictors and the two dependent variable, with the points in the plot representing subjects.

For two predictors, the regression is finding the plane that minimizes the residuals. Figure 7-

5 shows the same scatter plot but with a plane of best fit. The analog with the pegboard

demonstration should be obvious–rather than fitting a line there is now a plane.

Three or more predictor variables are difficult to display in a plot because we need more than

three dimensions but the idea and intuition scales to any number of dimensions.

Variance decomposition is also extended to the case of multiple regression. The degrees

of freedom in the numerator take into account the number of predictors. The F ratio from

the source table is interpreted as whether all the variables as a set account for a significant

proportion of the variability in the dependent variable. That is, the F ratio is comparing “the

model” as a whole (MSregression) to “what’s left over” (MSresiduals). This corresponds

to the simple ANOVA design that decomposed sums of squares into between and within

components. The form of the multiple regression source table is

SS df MS F SSR=

P ( ˆYi − Y)^2 number of parameters - 1 SSR/df MSR/MSE SSE=

P (Yi − Yˆi)^2 N - number of parameters SSE/df

The value R^2 is simply

SS

regression

SS

total

. This value is interpreted as the percentage of the

variance in Y that can be accounted for by the set of X variables. Recall the pie chart we

played with earlier in the term with ANOVA. The square root of R^2 , sometimes denoted ryˆy,

is the correlation between the observed data and the fitted values. Both are indices of how

well a linear model fits the data.

The F given by MSR/MSE is an omnibus test that shows how well the model as a whole (all

predictors as an aggregate) fit the data. This F tests whether R^2 is significantly different from

zero. As with all omnibus tests, this particular F is not very useful. We usually care more

about how specific predictors are performing, especially in relation to other predictors. Thus,

we are usually interested in each slope. This is analogous to the “I hats” from contrasts in

ANOVA.

Figure 7-4: Scatterplot with two predictor variables

X

Y

Z