Multiple Regression

Report 6 Downloads 495 Views
Categorical Predictors

Multiple Regression Categorical Predictors

Categorical Predictors

In This Module In this module, you will learn:  How to dummy code categorical variables so that they can be included in a regression  How to interpret regressions that have: – a predictor with 2 categories – a predictor with k categories, where k > 2 – both a continuous and categorical predictor – both a continuous and categorical predictor and an interaction effect  Analysis of Covariance (ANCOVA)  SAS code for running regressions with categorical predictors

Categorical Predictors

Introduction Our regression examples to this point have all involved continuous predictor variables, but in some circumstances you may have one or more categorical predictors. The purpose of this module is to get you comfortable including categorical predictors in your regression analyses.

Categorical Predictors

Dummy Coding Dummy coding is a process used to represent the category an individual belongs to with zeros and ones.

Categorical Predictors

Dummy Coding: Two-Group Categorical Predictor

As an example suppose we want to include gender (boy or girl) in a regression. The first step would be to dummy code gender. Gender Male Female Male Male Female Female

Dummy Coded Gender 0 1 0 0 1 1

Notice in the Dummy coded version of the variable there are only 0’s and 1’s.

Categorical Predictors

Two-Group Categorical Predictor: Scatter Plot

To continue our example, imagine we run a regression predicting math achievement using gender. We may first want to look at a scatter plot. Math

0                        1

Categorical Predictors

Two-group Categorical Predictor: Regression Line

The scatter plot looks a little odd because there are only 2 values for the x variable, but we can still imagine fitting a regression line to the scatter plot. The regression line should go through the center of each group of points, or put another way, the regression line goes through the mean of each group.

Math

0                        1

Categorical Predictors

Two-group Categorical Predictor: Slope

As with other regressions, the slope can be interpreted as the change in predicted math for a one-unit change in X. In this example, a one unit change in X corresponds to a change from boys to girls. The positive Math slope indicates that we would predict a higher math score for girls. The amount higher corresponds to the value of the slope, which also corresponds to the difference 0                        1 between the means of the two groups. Note the t-value for the test of the regression coefficient is identical to the t-value for the test of the difference in means.

Categorical Predictors

Two-group Categorical Predictor: Regression Equation

Another way to think about the regression is to examine the regression equation. Say weMath find: = 80 + 5(Gender ) Math = 80 + 5(0) = 80 Math = 80 5(1) = 85 Predicted value for a +boy:

Predicted value for a girl:

Thus the mean math score for boys is 80, the mean for girls is 85, and the difference in means is 5.

Categorical Predictors

Dummy Coding: k-Group Categorical Predictor

When there are more than two groups the dummy coding gets a little more complicated, but you still use 0’s and 1’s to represent group membership. To do this we need to make more than 1 dummy coded variable. In fact, we will need to make k-1 dummy coded variables. Consider an example with 3 groups, say Democrats, Republicans, and Independents. We know that we will need 2 dummy coded variables because: k-1 = 3-1 = 2

Categorical Predictors

Dummy Coding: k-Group Categorical Predictor

One way of defining the two dummy variables is that for the first dummy variable (Dummy1) a “1” indicates Democrat and a “0” indicates not Democrat, and that for the second dummy variable (Dummy2) a “1” indicates Republican and a “0” indicates not Republican. If so, we get the illustrated pattern of 0’s and 1’s. Note each group is distinguishable from the others in its pair of values: Democrat 1,0; Republican 0,1; and Independent 0,0.

Categorical Predictors

k-Group Categorical Predictor: Regression

To run a regression, the k-1 dummy variables are used as predictors. As an example, say we are interested in using political party to predict interest in environmental education. Let us say we use the dummy coded variables from the previous slide as the predictors in the regression. Also, we will refer to the first dummy variable as Democrat because it indicates whether or not the participant is Democrat, and we will refer to the second dummy variable as Republican. Suppose we get the following regression equation: Y  70  4 Democrat  3 Republican

Categorical Predictors

k-Group Categorical Predictor: Interpretation

To interpret, it is again useful to think about the predicted value of each group. For an Independent participant Y = 70 + 4(0)+ 3(0)= 70

For a Democrat participant

Y = 70 + 4(1)+ 3(0)= 74 Y = 70 + 4(0)+ 3(1)= 73

For a Republican participant

Categorical Predictors

k-Group Categorical Predictor: Interpretation

Thus the mean for the Independent group is 70, the mean of the Democrat group is 74, and the mean of the Republican group is 73. Note the regression coefficients are again telling us the difference in group means. More specifically the coefficient of 4 for the Democrat dummy variable tells us that Democrat participants have a mean that is 4 points higher than the Independent participants. The coefficient of 3 for the Republican dummy variable tells us that Republican participants have a mean that is 3 points higher than the Independent participants.

Categorical Predictors

k-Group Categorical Predictor: Reference Group

Because both the Democrat and Republican groups are being compared to the Independent group, some would call the Independent group the reference group in this analysis. In general the group with all zero values for the dummy variables is the reference group, and the intercept of the regression equation corresponds to the mean of the reference group.

Categorical Predictors

k-Group Categorical Predictor: F-test

The F-test for the R2 of the regression is identical to the one obtained by doing an ANOVA, and the t-tests for the regression coefficients are identical to the independent sample t-tests for comparing means. At this point, you may be wondering why you would ever run a regression with a categorical predictor, when you could get the same results using analyses with which you are already comfortable. The motivation of learning to include categorical predictors is not for situations where you only have categorical predictors, but for situations where you have both continuous and categorical predictors. Let us now turn to an example where we have a mix of continuous and categorical predictors.

Categorical Predictors

Categorical and Continuous Predictors As our next example, suppose we are interested in predicting math achievement using student attitude about math, but we also want to include gender (male=0, female=1) in our regression model. Suppose further that we get the following regression equation: Y  60  3 Attitude  5 Gender

When interpreting the regression coefficient of 5 for Gender we could say: for every 1 point higher in gender the predicted math is 5 points higher, holding attitude constant. Alternatively we could say: given a male and female student with the same attitude about math, we would predict the girl to have a 5 point higher math score than the boy.

Categorical Predictors

Categorical and Continuous Predictors To further our understanding of the equation we could write a simplified version for boys and a simplified version for girls. For boys Y = 60 + 3(Attitude)+ 5(0) Y = 60 + 3(Attitude)

For girls

Y = 60 + 3(Attitude)+ 5(1) Y = 65 + 3(Attitude)

Notice that if we keep attitude the same, the predicted value for girls is always 5 points higher than the predicted value for boys.

Categorical Predictors

Categorical and Continuous Predictors: Graphical Representation

We could also show these regression equations graphically. For both boys and girls the predicted math score goes up with attitude, and for any specific attitude the difference between the predicted values for boys and girls is 5 points. The 5 points can be referred to as the difference in adjusted means, because it is the difference we see in means when we hold attitude constant.

Math

5

girls

boys Attitude

Categorical Predictors

Categorical and Continuous Predictors: With an Interaction

We may think that the difference in math achievement between boys and girls depends on attitude. In which case the lines in our graph would not be parallel. In the diagram, we see that the difference in math between boys and girls is relatively large when attitudes are low, but as attitudes improve the gap between the groups gets smaller. Note that this sort of effect is an interaction effect (just like what we talked about when we were doing factorial ANOVAs).

Math

girls

boys Attitude

Categorical Predictors

Categorical and Continuous Predictors: With an Interaction

In order to account for the interaction the regression equation must get a little more complicated. In particular we must make a product of the gender and attitude variables and include this variable as an additional predictor in the model. Say the regression equation is now: Y  60  3 Attitude  5 Gender

Math

girls

boys Attitude

Categorical Predictors

Categorical and Continuous Predictors: With an Interaction

To interpret the equation it may be helpful to make a simplified equation for each group. For boys Y = 60 + 5(Attitude)+ 15(0)- 3(Attitude * 0) Y = 60 + 5(Attitude)

For girls

Y = 60 + 5(Attitude)+ 15(1)- 3(Attitude * 1) Y = 60 + 15 + (5 - 3)(Attitude) Y = 75 + 2(Attitude)

We can see that for girls the regression equation predicting math from attitude has a greater intercept but lower slope, than in the equation for boys.

Categorical Predictors

Categorical and Continuous Predictors: Attitude Difference

If the Attitude score was 0 the difference in predicted math between girls and boys would be 15.

For boys

Y = 60 + 5(Attitude)

For girls

Y = 60 + 5(0) Y = 60 Y = 75 + 2(Attitude) Y = 75 + 2(0) Y = 75

Math

girls

15

boys 0

2

Attitude

4

Categorical Predictors

Categorical and Continuous Predictors: Attitude Difference

But if Attitude is at the high end of the scale, with a value of 4, the difference in predicted math between girls and boys would only be 3 points.

For boys

Y = 60 + 5(Attitude) Y = 60 + 5(0)

For girls

Y = 60 Y = 75 + 2(Attitude) Y = 75 + 2(0) Y = 75

Math

3

girls

boys 0

2

Attitude

4

Categorical Predictors

Categorical and Continuous Predictors: With an Interaction

Just like with factorial ANOVAs we need to use great care when thinking about the main effects. We wouldn’t want to say the average difference between girls and boys is 15 because the regression coefficient for gender was 15. Rather we would want to indicate that the difference between predicted math for girls and boys depends on attitude with larger differences predicted when Math attitude is low and smaller differences predicted when 3 attitude is high. We could also girls point out that lower attitudes are associated with lower math scores, 15 boys and that this is especially evident for boys. 0 2 4 Attitude

Categorical Predictors

ANCOVA Sometimes people use the term Analysis of Covariance (ANCOVA) when running a regression that includes both a continuous and categorical predictor. Note that by definition ANCOVA has NO interaction term, thus if the data suggest an interaction, ANCOVA is inappropriate. Math

Math

3

girls

15

5

girls boys

Attitude

ANCOVA inappropriate

5

boys Attitude

ANCOVA appropriate

Categorical Predictors

Case 1: The Effectiveness of Coded Elaborative Outlines

Much of college learning is gained from textbooks. Consequently it is reasonable to explore strategies designed to enhance this type of learning. One such strategy involves coded elaborative outlines. Outlining helps the student select the most critical information from the text. During the coding process the selected information is categorized. Finally, elaboration is used to enhance meaning. Each of these processes is thought to be valuable, and the synthesis of the three is expected to increase learning from text. The objective of the study was to compare the achievement of students using coded elaborative outlines to the achievement of students using ordinary outlines.

Categorical Predictors

Case 1: Method for Study

Eighty-eight students from an undergraduate course in educational psychology agreed to participate in the study. Prior to the treatment all students took a verbal comprehension test, the 36 item vocabulary test from the Kit of Reference Tests for Cognitive Factors. The researcher anticipated that by controlling for verbal comprehension, the variability in achievement could be reduced. This in turn would increase the chances of finding a significant difference between treatment groups.

Categorical Predictors

Case 1: Method for Study

The students were then randomly assigned to one of two conditions. Students in the first condition were required to turn in a coded elaborative outline of the information in the chapters on learning theories. Students in the other condition were required to turn in an ordinary outline. All students then took an achievement test over the covered material.

Categorical Predictors

Case 1: Data for Study

The data from the study shows the treatment group is in column 1. Students using coded elaborative outlines are coded as 1’s and students using ordinary outlines are coded as 0’s. The scores on the verbal comprehension test range from 0 to 36 in column 2 The scores on the achievement test range from 0 to 100 in column 3. Part of the data is shown in this slide. the data set is available for download from the Attachments tab

Categorical Predictors

Case 1: Analysis Plan

In this case we have both a categorical predictor (outline type) and a continuous predictor (verbal comprehension). To proceed with the regression we need to make sure the categorical variable is dummy coded, which it is. We also note the researcher seems to be interested in an overall statement about the difference in the outline types, but it would be prudent to at least look for an interaction initially. If we find an interaction we will need to indicate how the difference in outline types depends on verbal comprehension. If the interaction is not significant, however, we can drop it from the regression model, run the simpler ANCOVA model, and make a more general statement about the difference in outline types.

Categorical Predictors

SAS Code for Multiple Regression data j1; input group verbal score 6-8; interaction=group*verbal; cards; 0 11 59 0 10 54 0 11 73 0 13 66 …………. ; proc reg; model score=group verbal interaction; run;

Note we created the interaction term by making the product of the group and verbal variables.

Also note we have included the interaction as a predictor in the regression model.

We can include group, which is a categorical variable, in the regression because it is a dummy coded variable (i.e., it only has values of 0 and 1).

the SAS code is available for download from the Attachments tab

Categorical Predictors

SAS Output

Note the interaction is NOT statistically significant, so we can run the simpler ANCOVA model

Categorical Predictors

SAS Code for ANCOVA data j1; input group 1 verbal 3-4 score 6-8; interaction=group*verbal; cards; 0 11 59 0 10 54 0 11 73 0 13 66 0 18 91 0 15 77 ; proc reg; model score=group verbal / p r stb scorr2; plot residual.*predicted.; output out=j2 residual=resid1; proc univariate plot; var resid1;

Note we have NOT included the interaction as a predictor in the regression model. We can include group, which is a categorical variable, in the regression because it is a dummy coded variable (i.e., it only has values of 0 and 1). We also added in the syntax from previous regression models to examine the residuals.

We also added in the syntax from previous regression models to examine the residuals. the SAS code is available for download from the Attachments tab

Categorical Predictors

SAS Output for ANCOVA The coefficient for group can be interpreted to mean that if we have students of equal verbal ability, those using the coded elaborative outline would be predicted to score 5.8 higher than those using an ordinary outline, which is a statistically significant difference (t(85)=3.04, p=.0032). Put another way, the difference in adjusted means is 5.8, favoring the coded elaborative outline group.

Categorical Predictors

Online Testing Your next step is to apply your knowledge of the topics in this module to the practice activities.