Two-way Anova Using SPSS

Embed Size (px)

Citation preview

  • 8/12/2019 Two-way Anova Using SPSS

    1/13

    1

    Conducting Two-Way ANOVA using SPSS

    Psychology 304b

    This handout will review how to do 2-way ANOVA, comparisons of marginal means, interaction

    contrasts, and simple effects analyses using SPSS. In addition, I will discuss how to perform

    non-orthogonal ANOVAs using SPSS.

    Two general approaches will be used depending on the analysis. One involves the pull-down

    menus you see when you first enter SPSS. The second involves syntax files, in which the user

    enters commands similar to those that we have used for SAS. The former approach is best for

    relatively simple analyses but the latter offers the maximal number of options. Most of the

    analyses will be done using the Generalized Linear Model program in SPSS with the univariate

    option. However, at some points we will use the multivariate (MANOVA) option within the

    GLM program.

    The Data

    I will assume that you know how to create a SPSS .sav file and to read it in using a GET

    statement if youre using the syntax editor. The data file used for this example is on the web site

    and named twoway.sav. It contains data from the biofeedback X drug group example used for

    the SAS two-way ANOVA programs. I should note that the particular data set used here is the

    one with 6 subjects per cell (36 in all) that was used for the SAS program demonstrating

    interaction contrasts and simple effects analysis. Part of the data file looks like this:

  • 8/12/2019 Two-way Anova Using SPSS

    2/13

    2

    Two-way ANOVA

    To do the omnibus two-way ANOVA, it is probably easiest to just use the pull-down menu

    option. Click on Analyze >>> General Linear Model >> Univariate:

    Then, indicate the dependent variable and the factors in the appropriate boxes.

  • 8/12/2019 Two-way Anova Using SPSS

    3/13

    3

    I would also use the Options to generate marginal and cell means:

    Then hit Continue and then OK and you will initiate the analysis. As youll see from the output,

    these steps also generate the following Syntax code (that you could use if you did this using the

    Syntax editor):

    UNIANOVA bp BY bio_gp drug_gp/METHOD=SSTYPE(3)/INTERCEPT=INCLUDE/EMMEANS=TABLES(bio_gp)/EMMEANS=TABLES(drug_gp)/EMMEANS=TABLES(bio_gp*drug_gp)/CRITERIA=ALPHA(.05)/DESIGN=bio_gp drug_gp bio_gp*drug_gp.

    In fact, not all these statements are necessary if you wanted to reproduce the pull-down menu.

    You could get away with just:

    UNIANOVA bp BY bio_gp drug_gp/EMMEANS=TABLES(bio_gp)

    /EMMEANS=TABLES(drug_gp)/EMMEANS=TABLES(bio_gp*drug_gp)

    The output is as follows:

  • 8/12/2019 Two-way Anova Using SPSS

    4/13

    4

    Univariate Analysis of Variance

    Tests of Between-Subjects Effects

    Dependent Variable:bp

    SourceType III Sum of

    Squares Df Mean Square F Sig.

    Corrected Model 6552.000a 5 1310.400 9.593 .000

    Intercept 1340964.000 1 1340964.000 9816.720 .000

    bio_gp 1296.000 1 1296.000 9.488 .004

    drug_gp 4104.000 2 2052.000 15.022 .000

    bio_gp * drug_gp 1152.000 2 576.000 4.217 .024

    Error 4098.000 30 136.600

    Total 1351614.000 36

    Corrected Total 10650.000 35

    a. R Squared = .615 (Adjusted R Squared = .551)

    You will note that the ANOVA output and means are identical to the omnibus SAS output in the

    program demonstrating simple effects analyses and interaction contrasts. You can disregard the

    intercept source above (representing modeling of the effect of grand mean). The key effectshere are the two main effects for bio_gp and drug_gp and the bio_gp*drug_gp interaction term.

    Estimated Marginal Means

    1. bio_gp

    Dependent Variable:bp

    bio_gp Mean Std. Error

    95% Confidence Interval

    Lower Bound Upper Bound

    1 187.000 2.755 181.374 192.626

    2 199.000 2.755 193.374 204.626

  • 8/12/2019 Two-way Anova Using SPSS

    5/13

    5

    2. drug_gp

    Dependent Variable:bp

    drug_gp Mean Std. Error

    95% Confidence Interval

    Lower Bound Upper Bound

    1 178.000 3.374 171.110 184.890

    2 202.000 3.374 195.110 208.890

    3 199.000 3.374 192.110 205.890

    3. bio_gp * drug_gp

    Dependent Variable:bp

    bio_gp drug_gp Mean Std. Error

    95% Confidence Interval

    Lower Bound Upper Bound

    1 1 168.000 4.771 158.255 177.745

    2 204.000 4.771 194.255 213.745

    3 189.000 4.771 179.255 198.745

    2 1 188.000 4.771 178.255 197.745

    2 200.000 4.771 190.255 209.745

    3 209.000 4.771 199.255 218.745

    Main Effect Comparisons: Pairwise Comparisons

    There are several different ways to do main effect comparisons in SPSS, some of which can be

    surprisingly tedious and complex. Pairwise comparisons, though, are pretty simple.

    Individual Pairwise Comparisons (Unadjusted for Multiplicity)

    Lets start with comparisons un-adjusted for multiplicity (e.g., if you were just doing one

    contrast). One good way for you to go is to use the syntax editor. Specify the contrast as part ofthe EMMEANS option. For example, lets say we want to do all pairwise comparisons among

    the 3 drug groups. Your code would look like this:

    GLM bp by bio_gp drug_gp/EMMEANS TABLES (drug_gp) COMPARE(drug_gp).

  • 8/12/2019 Two-way Anova Using SPSS

    6/13

    6

    Youll see in the output the results of pairwise comparisons among the three drug groups:

    Pairwise Comparisons

    Dependent Variable:bp

    (I)drug_gp

    (J)drug_gp

    MeanDifference (I-

    J) Std. Error Sig.a

    95% Confidence Interval forDifference

    a

    Lower Bound Upper Bound

    1 2 -24.000 4.771 .000 -33.745 -14.255

    3 -21.000 4.771 .000 -30.745 -11.255

    2 1 24.000 4.771 .000 14.255 33.745

    3 3.000 4.771 .534 -6.745 12.745

    3 1 21.000 4.771 .000 11.255 30.745

    2 -3.000 4.771 .534 -12.745 6.745

    Based on estimated marginal means

    *. The mean difference is significant at the .050 level.

    a. Adjustment for multiple comparisons: Least Significant Difference (equivalent tono adjustments).

    You can see that drug group 1 (i.e., drug X) differs significantly from group 2(Y) and 3 (Z) butthat groups 2 and 3 dont differ.

    Theres another way to do this too. You could just use the pull-down menu, go to post-hoc

    contrasts (I know this sounds weird), specify LSD contrasts but just ignore the results of the

    overall ANOVA. The idea here is to just get out the results of individual contrasts with anindividual per comparison type 1 error rate of .05. The key strokes are Analyze >> General

    Linear Models >> Univariate >> Enter DV and Fixed Factors if you havent done so >> Post

    Hoc >> LSD >>Continue >> Continue

    Multiple Pairwise ComparisonsPairwise comparisons corrected for multiplicity are easy. Just use the pull-down menu.

    The key strokes are Analyze >> General Linear Models >> Univariate >> Enter DV and FixedFactors if you havent done so >> Post Hoc. Then you will see this menu:

  • 8/12/2019 Two-way Anova Using SPSS

    7/13

    7

    Click on the factor of interest (here drug_gp) and indicate the post-hoc tests you want (e.g.,Bonferroni, Tukey, Scheffe). Then hit Continue, and then OK and you will get the MC results in

    addition to the results of the ANOVA. You should be able to interpret the output clearly. For

    example, below is the output of the Tukey test for these data:

    Multiple Comparisons

    bp

    Tukey HSD

    (I)drug_gp

    (J)drug_gp

    Mean Difference(I-J) Std. Error Sig.

    95% Confidence Interval

    Lower Bound Upper Bound

    1 2 -24.0000 4.77144 .000 -35.7629 -12.2371

    3 -21.0000 4.77144 .000 -32.7629 -9.2371

    2 1 24.0000 4.77144 .000 12.2371 35.7629

    3 3.0000 4.77144 .806 -8.7629 14.7629

  • 8/12/2019 Two-way Anova Using SPSS

    8/13

    8

    3 1 21.0000 4.77144 .000 9.2371 32.7629

    2 -3.0000 4.77144 .806 -14.7629 8.7629

    Based on observed means.

    The error term is Mean Square(Error) = 136.600.

    *. The mean difference is significant at the 0.05 level.

    Homogeneous Subsets

    bp

    Tukey HSD

    drug_gp N

    Subset

    1 2

    1 12 178.0000

    3 12 199.0000

    2 12 202.0000

    Sig. 1.000 .806

    Means for groups in homogeneous subsets aredisplayed.

    Based on observed means.

    The error term is Mean Square(Error) = 136.600.

    As you can see group 1 differs from groups 2 and 3 but the latter two dont differ from each

    other.

    Main Effect Comparisons: Complex Comparisons

    Individual Complex Comparisons

    Specifying complex comparisons with SPSS is harder than you might expect. There are

    two main ways to do this and theyre both pretty tricky. Let me show you the method I think willbe easiest for you. Im not going to explain why this works this is simply a how-to, cookbook

    approach (though I certainly DO assume you know comparisons at well more than a cookbook

    level). Really understanding why this works probably requires a class in linear models and/ormultivariate analysis.

    Lets say we wanted to do the complex contrast comparing the mean of drug groups 1 and 2 todrug group 3. Our contrast coefficients could be 1 1 -2. I would do this using the MANOVA

    command in the syntax editor. The key thing is to use the CONTRAST option and to specify

  • 8/12/2019 Two-way Anova Using SPSS

    9/13

    9

    what SPSS calls a SPECIAL contrast because its not one of their standard defaults. The key

    thing here is that you have to create a square matrix of coefficients with the numbers of rows andcolumns equal to the number of marginal means associated with the factor of interest. Here that

    number = 3. So you need a 3 X 3 matrix. The first row of this matrix must be all 1s (NOT the

    contrast youre interested in). Make the second row the coefficients of the contrast youre

    interested in. Make the third row the coefficients of an additional contrast (often the best choicehere is a contrast thats orthogonal to the first but that need not be the case). Obviously if you

    have a second contrast of interest then use it for row 3. If you have 4 groups you need to enter a

    4 X 4 matrix with all rows being 1s, then put three contrasts in rows 2-4 and make sure one ofthem is the contrast youre interested in.

    The overall syntax here is this:

    MANOVA bp by bio_gp (1,2) drug_gp (1,3)

    /ERROR = W/Contrast(drug_gp) = SPECIAL (1 1 1

    1 1 -21 -2 1).

    As you can see, were using the MANOVA command that denotes the dv and the two factors

    (including information about the levels of each factor (i.e., from 1 to 2 and from 1 to 3). Put

    ERROR=W to make sure the MSW is used as the error term. Then put in the Contrast statement.Note how row 2 is our contrast of interest (1 1 -2). I put in a second complex contrast in the third

    row as well. If you run this you get the following output:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - -

    * * * * * * * * * * * * * * * * * A n a l y s i s o f V a r i a n c e * * * * * ** * * * * * * * * * *

    36 cases accepted.0 cases rejected because of out-of-range factor values.0 cases rejected because of missing data.6 non-empty cells.

    1 design will be processed.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - -

    * * * * * * * * * * * * * * * * * A n a l y s i s o f V a r i a n c e -- Design1 * * * * * * * * * * * * * * * * *

    Tests of Significance for bp using UNIQUE sums of squaresSource of Variation SS DF MS F Sig of F

    WITHIN CELLS 4098.00 30 136.60bio_gp 1296.00 1 1296.00 9.49 .004drug_gp 4104.00 2 2052.00 15.02 .000bio_gp BY drug_gp 1152.00 2 576.00 4.22 .024

  • 8/12/2019 Two-way Anova Using SPSS

    10/13

    10

    (Model) 6552.00 5 1310.40 9.59 .000(Total) 10650.00 35 304.29

    R-Squared = .615Adjusted R-Squared = .551

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    - - - - - - - - - - - - - - - - -Estimates for bp--- Individual univariate .9500 confidence intervals

    bio_gp

    Parameter Coeff. Std. Err. t-Value Sig. t Lower -95% CL- Upper

    2 -6.0000000000 1.94793 -3.08019 .00440 -9.97821 -2.02179

    drug_gp

    Parameter Coeff. Std. Err. t-Value Sig. t Lower -95% CL- Upper

    3 -18.0000000000 8.26438 -2.17802 .03740 -34.87812 -1.12188

    4 -27.0000000000 8.26438 -3.26703 .00272 -43.87812 -10.12188

    bio_gp BY drug_gp

    Parameter Coeff. Std. Err. t-Value Sig. t Lower -95% CL- Upper

    5 12.0000000000 8.26438 1.45201 .15688 -4.87812 28.878126 -24.0000000000 8.26438 -2.90403 .00685 -40.87812 -7.12188

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Here its kind of hard to find what you want. However, the key thing here are the parameters for

    drug_gp. The first one shown (# 3 in bold) is the one for our contrast of interest. In fact, if youuse the contrast coefficients of 1, 1, and -2 and the marginal means, you will find that the value

    of the contrast is -18. You will see the associated t statistic and p value.

    Multiple Complex Comparisons.

    You can use the general approach noted above when you have multiple complex

    comparisons or a combination of complex and pairwise comparisons. Note here that your typicalalternatives will be Bonferroni or Scheffe. If its Bonferroni, just use the general approach

    described above (you might have to run more than one MANOVA to get all the contrasts in) and

    note the critical per comparison t and alpha levels youre shooting for. If youre doing Scheffes,

    take the t value shown in the SPSS output and square it to get your observed F. Then compare itto the Scheffe critical value = (df for the main effect of interest) X critical F for that effect for the

    overall ANOVA at alpha = .05.

    Simple Effects Analyses

    Its fairly easy to run simple effects analyses using SPSS. Again use the syntax editor. Lets say

    we want to estimate the simple effects of drug at biofeedback. That is, we want to compare thethree drug groups at biofeedback present and absent. To do this, use the following code:

    GLM bp by bio_gp drug_gp

    /EMMEANS Tables (bio_gp*drug_gp) Compare(drug_gp).

  • 8/12/2019 Two-way Anova Using SPSS

    11/13

    11

    At the bottom of the output, youll see the simple effects F tests:

    Univariate Tests

    Dependent Variable:bp

    bio_gp Sum of Squares Df Mean Square F Sig.

    1 Contrast 3924.000 2 1962.000 14.363 .000

    Error 4098.000 30 136.600

    2 Contrast 1332.000 2 666.000 4.876 .015

    Error 4098.000 30 136.600

    Each F tests the simple effects of drug_gp within each level combination of the other effects shown.These tests are based on the linearly independent pairwise comparisons among the estimatedmarginal means.

    This result is identical to what we computed by hand and via SAS.

    Interaction Contrasts

    To do interaction contrasts in SPSS, I would again use the syntax editor and use a specification

    thats similar to what you would use with SAS. Below is the syntax for specifying the

    interaction contrast between drugs x and y and biofeedback. The key thing here is to notesomething similar that I noted for SAS. Note how in the GLM statement bio_gp appears first.

    This means that it moves more slowly. So that the six cells in order in the LMATRIX portion

    are bio present/X, bio present/Y, bio-present Z, bio_absent/X, bio_absent Y, bio_absent Z.

    GLM bp by bio_gp drug_gp

    /LMATRIX = 'x vs y by biofeedback interaction contrast' bio_gp*drug_gp 1 -1 0 -1 1 0.

    The key thing here is to note something similar that I noted for SAS. Note how in the GLM

    statement bio_gp appears first. This means that it moves more slowly. So that the six cells in

    order in the LMATRIX portion are bio present/X, bio present/Y, bio-present Z, bio_absent/X,bio_absent Y, bio_absent Z. Another way to think of this that might be easier because it retains

    the 2-dimensional row X column format is that biofeedback conditions constitute the rows

    (because they come first in the by statement and drug_gp constitutes the columns. For example,

    we could rewrite the LMATRIX statement above in the following manner:

    GLM bp by bio_gp drug_gp

    /LMATRIX = 'x vs y by biofeedback interaction contrast' bio_gp*drug_gp 1 -1 0-1 1 0.

    Either way will work. The output is as follows:

  • 8/12/2019 Two-way Anova Using SPSS

    12/13

    12

    Contrast Results (K Matrix)a

    Contrast

    DependentVariable

    bp

    L1 Contrast Estimate -24.000

    Hypothesized Value 0

    Difference (Estimate - Hypothesized) -24.000

    Std. Error 9.543

    Sig. .017

    95% Confidence Interval for

    Difference

    Lower Bound -43.489

    Upper Bound -4.511

    a. Based on the user-specified contrast coefficients (L') matrix: x vs y by biofeedbackinteraction contrast

    Test Results

    Dependent Variable:bp

    SourceSum ofSquares df

    MeanSquare F Sig.

    Contrast 864.000 1 864.000 6.325 .017

    Error 4098.000 30 136.600

    The results for this contrast are identical to what we observed for SAS.

    Non-orthogonal ANOVA

    Remember that for non-orthogonal ANOVAs you will have the choice of Type 1 or Type 3 SS

    approaches. The default in SPSS will be Type 3 SS. If you want to use Type 1, just use the pull-

  • 8/12/2019 Two-way Anova Using SPSS

    13/13

    13

    down menu. The key strokes are Analyze >> General Linear Models >> Univariate Enter DV

    and Fixed Factors if you havent done so >> Model. You will see the following menu:

    Just enter Type 1 in the SS box. Then hit Continue and OK. This would be equivalent to thefollowing statements in the syntax editor:

    UNIANOVA bp BY bio_gp drug_gp

    /METHOD=SSTYPE(1).