Two Way ANOVA. Turkheimer PSYC 771. Page 1 Two-Way ANOVA

Size: px
Start display at page:

Download "Two Way ANOVA. Turkheimer PSYC 771. Page 1 Two-Way ANOVA"

Transcription

1 Page 1 Two Way ANOVA Two way ANOVA is conceptually like multiple regression, in that we are trying to simulateously assess the effects of more than one X variable on Y. But just as in One Way ANOVA, the X variables are group memberships, which are each represented by sets of X variables. It also brings back the concept of interaction to which we were introduced when we were using continuous variables. The example we are going to work with is from neuroscience. Two STRAINs of rats are randomly divided into 3 groups that have different SITEs lesioned in their kidneys. Some kidney product (this is why I didn t turn out to be a neuroscientist) is Y. So there are a total of 6 (2 x 3) groups of rats. It would work perfectly well to completely ignore the two way design, and treat this as a one way ANOVA with 6 groups. You could effect code it as follows. STRAIN -1 1 SITE GROUP This coding, which I'm not actually going to do, would be perfectly OK, in that it would give the correct overall r 2. The individual codes would be interpretable just as they always are, as the difference between the groups getting the 1 and the grand mean. But there is a problem, which is that we have lost the information about SITE and STRAIN. Presumably we conducted the experiment this way because we wanted to chunk the group information into one piece that was about SITE and another piece that was about STRAIN. How can we accomplish this?

2 Page 2 The trick is to conceive the codes separately by factor. So an effect code for STRAIN is -1 in the first strain and 1 in the second, regardless of SITE. And the first effect code for SITE is 1 in the first group, in the second and -1 in the third, regradless of STRAIN. Doing this gives you the first three codes in the table below: STRAIN 1-1 SITE STRAIN SITE SITE INT INT Remember how you create interactions? They are just products of X variables. That's what we have done here. There is one code for STRAIN and two for SITE, so there are 2 x 1 = 2 products we can create. The first is the product of STRAIN and SITE1, and the second is the product of STRAIN and SITE2. We'll have more to say about the interpretation of interactions next time, but for the time being they can be interpreted just as they always interpreted: The first effect code tells you whether the difference between SITE 1 and the grand mean depends on STRAIN; the second tells you whether the magnitude of the difference between SITE 2 and the grand mean depends on STRAIN. Notice that we have five codes, just as before, so the two coding systems will give the same r 2. In the second method we have simply created codes that keep the information about the factors separate. The STRAIN effect code tells you about the difference between the STRAIN means, taken across SITE; the two effect codes for SITE tell you about differences in the SITE means, taken across STRAIN. This is easiest to see if you reorganize the two sets of groups (known as factors ) into a table.

3 Page 3 Strain (1,1) (1,2) 1 SITE 2 (2,1) (2,2) 2 3 (3,1) (3,2) 3 Strain 1 Strain 2 Grand The means at the edges of the tables are known as marginals. The STRAIN codes are about the marginals for STRAIN, and the SITE codes are about the marginals for SITE. These sets of codes are known as the main effectsof SITE and STRAIN. But there is more information in the table than is summarized by the marginals. To see this, suppose I give you data on the marginals, as follows: Strain (1,1) (1,2) SITE 2 (2,1) (2,2) (3,1) (3,2)

4 Page 4 Could you figure out the cell means from this information? If you think about it for a second, you will see that the answer is no. But suppose I filled in two cell means, as follows? Strain (1,2) SITE 2 25 (2,2) (3,1) (3,2) Now you could fill in the rest of the table. So after you know the marginal means (main effects) there are two more pieces of information left to obtain. These are the (in this case) two interactions. This kind of consideration is where the term degrees of freedom comes from. Once you know the marginals, two cell means are free to vary before all the cells in the table are fixed. Now it's time to get to work on analyzing the design in SAS. The master page links to the SAS program we'll be working with, and also to the output. The program creates the codes exactly as before. Notice that as always, the interaction codes are literally the products of the main effect codes. To analyze the data without using CLASS statements, we have to test multiple models. We can summarize the SSE's in these tables as follows:

5 Page 5 Model SSE SSR sr 2 Full No Strain No No No No Interaction No Int No Int And these values produce the following source table: Source SS Df MS pr 2 sr 2 F p Strain Strainx Int Int Error Total Notice that this is a situation where the pr 2 and the sr 2 values are pretty different (I m going to stop including pr 2 values pretty soon). This happends because Strain doesn t reduce SSE by all that much, but it does its work after is in the model, so there isn t all that much left to reduce. Notice also that you can get the sr 2 values simply by subtracting R 2 values in the SAS output. Finally, let's look at the results from PROC GLM, which is at the end of the output we were just

6 Page 6 looking at Explore on your own how this output will create the same source table. The one part we need to talk about is the contrast codes for the interactions. The SAS statements were as follows:!" # $ %&'' # $ ('"&' We know how the main effect contrasts work, you simply interpret them like contrasts. These accomplish the same thing as effect codes, because asking whether the mean of the first group is different from the mean of the other two is the same as asking whether it is different from the grand mean. For the interaction contrasts you have to take all six cells into account. Here is what the first interaction code looks like: Strain This interaction is about whether the difference between site 1 and the grand mean is different in the two strains. So we have to write the code as we did for the main effect, but taking the row and colum information into account, ie, 1 Strain 1 / 1 Strain 2 / 2 Strain 1 / 2 Strain 2 / 3 Strain 1 / 3 Strain 2 If you look at the constrast statement you ll see that this is just what it does. It reproduces the effect we got with PROC REG. Interpreting Results of 2-Way ANOVA The basic graphical method for illustrating the results of ANOVA is something called a s Plot, which is just what it sounds like: Here is some SAS code to produce a s Plot for our Ongoing Example:

7 Page 7 Strain has been plotted against Y for each of the three sites (On your own, try doing it the other way around.) the slope of the lines represents the small STRAIN effect, and the distance between them represents the substantial SITE effect. There is a hint of an interaction indicated by the fact that the lines are not parallel: There appears to be something of a STRAIN effect at SITE 1, less at SITE 2, and nothing at all at SITE 3. Remember that with n=4 per cell, our power is abysmal and we have little chance of finding the effect unless is quite large. You should always create a means plot when you do an ANOVA-- once you know how it only takes a second, and it is the best way to understand what is going on in your data. There is more to be said about interpreting effects in ANOVA designs, especially when it comes to interactions. I find it easiest to think of it in terms of means. Let's write out the effect codes that we used in the form of matrices. For example, the effect code for STRAIN had a value of -1 in the first group and 1 in the second, regardless of SITE. It looks like this:

8 Page 8 Strain Here, for reference, is the output from PROC REG for the full model: two-way analysis of kidney data 14:3 Tuesday, November 24, Model: MODEL1 Dependent Variable: Y Analysis of Variance Sum of Source DF Squares Square F Value Prob>F Model Error C Total Root MSE R-square.8886 Dep Adj R-sq.8577 C.V Parameter Estimates Parameter Standard T for H: Variable DF Estimate Error Parameter= Prob > T INTERCEP STRAIN SITE SITE INT INT The b coefficient for STRAIN is Remember what that means for the production of Yhats-- you multiply that b times the subjects' score on the X variable-- the STRAIN effect code, which we illustrated above. This means that the STRAIN code is going to have the effect of subtracting from everyone in strain -1, and adding to everyone in strain 1.:

9 Page 9 Strain We can do exactly the same thing for the two SITE codes. SITE 1 looks like this: Strain So it has this effect: Strain looks like this: Strain And so it has this effect:

10 Page 1 Strain The interactions are just products of the main effects, so we can compute them directly in matrix form. STRAIN x SITE1 looks like this: Strain And has this effect: Strain We need to take an interlude here to think about what this means for the interpretation of the interaction. Think of it as the STRAIN effect at the three different SITEs. The table shows you that when all the main effects have been taken into account, the interaction has the effect of making strain 2 to be greater than strain 1 at site one, while strain 1 tends to be larger than strain2 at site 3. If you go back and look at the means plot you will see that you have to be careful about how you interpret this information. It s not that strain 1 and strain 2 ever differ by exactly six or twelve points, it s that the interaction produces a deviation of six points from the trend defined by the main effects. Another way to do basically the same thing is with simple effects, just like we did with continuous variable interactions. Let s reformulate the regression equation above for the situation where STRAIN=1. We get: Y = [ ] + [ ]SITE1 + [ ]SITE2.

11 Page 11 When STRAIN=-1, we get, Y = [ ] + [ ]SITE1 + [ ]SITE2. So we can see that the interaction has the effect of making the SITE1 effect larger when STRAIN=1 than when STRAIN=-1. Anyway, let s finish completely decomposing the design: STRAIN x SITE 2 looks like this, Strain And has this effect Strain What about the intercept? It gets added into every cell, so its design matrix looks like this: Strain Which has this effect:

12 Page 12 Strain The Yhats for the model are the sum of the 6 design matrices: Strain The sum of each of the cells reproduces the cell means. Unequal N Unequal N is a topic where we get maximum benefit out of the General Linear Model approach. You ll notice that the book has a whole chapter on the topic, with new computational formulas and complex discussions of how to fit the models. Actually, we only need one insight to take care of the whole problem. Consider a simple 2x2 ANOVA, say gender by experimental condition: Male Female Treatment n=5 n=1

13 Page 13 Control n=1 n=5 Now suppose I tell you that a particular subject is male and ask you to guess if he is in the treatment or control group. You would guess control. This means that knowing something about gender tells you something about treatment group, which is to say that gender and group are correlated. Notice that if the cell sizes were equal you wouldn t be able to do this. So unequal N has the consequence of creating correlated X variables. This is too bad, because the whole benefit of experimental design is the nice orthogonality that resulsts from a balanced design, but from a statistical point of view we know exactly what to do. Let s do Problem 2 from the book, not that there is anything to it. The master page has the SAS program and the output. Everything is just the same as always, but now the SSRs for the individual variables don t add up to the SSRs for the full model.