08.Two Way Anova

Embed Size (px)

Citation preview

  • 8/13/2019 08.Two Way Anova

    1/41

    Two-way ANOVA

  • 8/13/2019 08.Two Way Anova

    2/41

    Two-Way ANOVA Data Layout

    Xijk

    Level iFactor

    A

    Level jFactor

    B

    Observation k

    in each cell

    Factor Factor B

    A 1 2 ... b

    1 X111 X121 ... X1b1X11n X12n ... X1bn

    2 X211 X221 ... X2b1

    X21n X22n ... X2bn

    : : : : :

    a Xa11 Xa21 ... Xab1

    Xa1n Xa2n ... Xabni = 1,,a

    j = 1,,b

    k = 1,,nThere are a X b treatment combinations

  • 8/13/2019 08.Two Way Anova

    3/41

    Motivating Example:

    Capsule Dissolve Time

    Suppose are looking at two capsule types

    (C or V) & two digestive fluids (Gastric or Duodenal)

    Randomly assign 5

    capsules of each type toeach of type of digestive

    juice and observe

    dissolve time.

    Xijk = measured dissolve

    time for capsule kin

    digestive juice i and

    capsule type j.

    i = 1 or 2 (i.e. G and D)

    j = 1 or 2 (i.e. C and V)

    k = 1,2,3,4,5

  • 8/13/2019 08.Two Way Anova

    4/41

  • 8/13/2019 08.Two Way Anova

    5/41

    Plotting the Results ~ Capsule Effect

    seconds42.85dissolvetocapsulesVfor typemean timeseconds05.43dissolvetocapsulesCfor typemean time

    2

    1

    XX

    TimeUntilBubbles(second

    s)

    Capsule Type

    There appears to be very little difference between the capsule

    types in terms of the time it takes them to dissolve.

  • 8/13/2019 08.Two Way Anova

    6/41

    Plotting the Results ~ Fluid Effect

    seconds40.2juiceduodenalindissolvetocapsulesformean timeseconds7.45juicegastricindissolvetocapsulesformean time

    2

    1

    XX

    Fluid Type

    Capsules take 5.5 seconds longer on average to dissolve in

    gastric juice compared to duodenal juice.

  • 8/13/2019 08.Two Way Anova

    7/41

    Preliminary Conclusion

    There is very little difference between the capsule

    types in terms of the length it time it takes them to

    dissolve.

    Capsules take about 5 seconds longer on average to

    dissolve in gastric juice than in duodenal juice.

    THESE CONCLUSIONS ARE

    COMPLETELY WRONG!! WHY ?!?

  • 8/13/2019 08.Two Way Anova

    8/41

    Plotting the Results ~ Capsule Effect Separately

    seconds44.1juiceduodenalindissolvetocapsulesVformean time

    seconds36.3juiceduodenalindissolvetocapsulesCformean timeseconds41.6juicegastricindissolvetocapsulesVformean time

    seconds8.49juicegastricindissolvetocapsulesCformean time

    22

    21

    12

    11

    X

    XX

    X

    Clearly the time to dissolve depends on what capsule is being

    used and which juice it is being dissolved in.

    Type C capsules dissolve faster in duodenal

    juice than do type V capsules where for gastric

    juice the opposite is true.

  • 8/13/2019 08.Two Way Anova

    9/41

    Interactions

    The capsule study is an example of situation wherethere is an interaction between the two factors

    being studied in terms of their effect on the

    numeric response.

    An interaction occurs when the effect of one

    factor depends on the level of another factor.Here the effect of capsule depends on the type

    of digestive juice used to dissolve it and vise

    versa.

    Type C capsules dissolvefaster than Type V in

    duodenal juice, where

    opposite is true when

    gastric juice is used todissolve the capsules.

  • 8/13/2019 08.Two Way Anova

    10/41

    Interactions can mask main effects

    The apparent lack of

    a capsule effect is

    caused by theinteraction of capsule

    type and fluid type.We say the interaction masks

    the main effect of capsule

    type.

  • 8/13/2019 08.Two Way Anova

    11/41

    Types of Interactions and Interpreting

    Interaction Plots

    Here the meanresponse is the same

    for both levels of both

    factors.

    Here both effects are masked

    by the interaction. This type

    of interaction is called a

    difference in direction of the

    effects.

  • 8/13/2019 08.Two Way Anova

    12/41

    Types of Interactions and Interpreting

    Interaction Plots

    Here the meanresponse differs

    depending on the level

    of B but not A.

    Here the A main effect is

    masked by the interaction. The

    B main effect is significant,

    although cannot be talked about

    independently of the level of A.

  • 8/13/2019 08.Two Way Anova

    13/41

    Types of Interactions and Interpreting

    Interaction Plots

    Here the effect of A is the

    same for both levels of B.There is minimal separation

    between the two profiles for

    the levels of B, thus B is not

    significant

    Here the A main effect is differs

    depending on the level of B. The

    B main effect is masked by the

    interaction as the means for B1

    and B2 are the same.

  • 8/13/2019 08.Two Way Anova

    14/41

    Types of Interactions and Interpreting

    Interaction Plots

    Here the effect of A is the same

    for both levels of B and viseversa. The response differs

    across the level of both factors

    and both differences suggest

    significant A & B effects.

    Here the A main effect is

    differs depending on the levelof B. Neither the A or B

    main effects are masked by

    the interaction.

    This type of interaction is adifference in magnitude the

    effect. The direction of A main

    effect is the same for both levels

    of B, however the A effect is

    larger when B is at the 1st level.

  • 8/13/2019 08.Two Way Anova

    15/41

    Types of Interactions

    In summary there are types of interactions:

    Differences in Direction Differences in Magnitude

    Always construct an interaction plot to

    visualize the interaction or lack thereof !

  • 8/13/2019 08.Two Way Anova

    16/41

    Questions of Interest

    Generally, the questions of interest here

    (i.e. hypotheses to be tested) concern three

    questions regarding the potential effects of

    the factors on the response variable.

    Question 1: Do the effects that factorsA and

    B have on the response variable interact, i.e.is there a significant interactionbetween

    factorsA and B ?

  • 8/13/2019 08.Two Way Anova

    17/41

    Questions of Interest

    If we conclude there is a significant interaction

    then we conclude the effects of both factors

    A and B are significant!

    When we have an interaction we cannot consider

    the effect of either factor independently of the

    other, therefore both factors matter.

  • 8/13/2019 08.Two Way Anova

    18/41

    Questions of Interest

    If there is not a significant interactioneffect then we can consider the maineffects separately, i.e. we ask the

    following:

    Question 2: Does factorA alone have asignificant effect?

    Question 3: Does factor B alone have asignificant effect?

  • 8/13/2019 08.Two Way Anova

    19/41

    Tests of Hypotheses

    Just as we had Sums of Squares and Mean Squaresin One-way ANOVA, we have the same in Two-

    way ANOVA:

    Recall, Mean Squares are measures of variabilityacross the levels of the relevant factor of interest.

    In balanced Two-way ANOVA, we measure the

    overall variability in the data by:1)(

    1 1 1

    2

    NdfXXSS

    a

    i

    b

    j

    n

    k

    ijkT

  • 8/13/2019 08.Two Way Anova

    20/41

    Tests of Hypotheses

    1)()(1

    2

    1 1 1

    2

    adfXXbnXXSS

    a

    i

    i

    a

    i

    b

    j

    n

    k

    iA

    a

    i

    b

    j

    n

    k

    b

    j

    jjB bdfXXanXXSS1 1 1 1

    22 1)()(

    Sum of Squares for factor A

    Sum of Squares fo r factor B

    Measures variation in the response due to the factthat different levels of factor A were used.

    Measures variation in the response due to the fact

    that different levels of factor B were used.

  • 8/13/2019 08.Two Way Anova

    21/41

    Test of Hypotheses

    Interact ion Sum of Squares

    a

    i

    b

    j

    n

    k

    jiijAB badfXXXXSS1 1 1

    2 )1)(1()(

    Error or Residual Sum of Squares

    a

    i

    b

    j

    n

    k

    ijijkE nabdfXXSS1 1 1

    2 )1()(

    Measures the variation in the response due to the

    interaction between factors A and B. If the interactionplot is perfectly parallel this will be 0!

    Measures the variation in the responsewithin the a x b

    factor combinations.

  • 8/13/2019 08.Two Way Anova

    22/41

    Tests of Hypotheses

    So the Two-wayANOVA Identityis:

    This partitions the Total Sum of Squares

    into four pieces of interest for our

    hypotheses to be tested.

    EABBAT SSSSSSSSSS

  • 8/13/2019 08.Two Way Anova

    23/41

    Tests of Hypotheses

    As in One-wayANOVA, we obtain mean squares

    for the different effects by dividing the sums ofsquares by their respective degrees of freedom

    i.e.

    These are our measures of variance for the analysis.

    If an effect is not significant we expect

    and if it is we expect

    effect

    effect

    effect

    df

    SSMS

    Eeffect MSMS

    Eeffect MSMS

  • 8/13/2019 08.Two Way Anova

    24/41

    Test of Hypotheses

    F-Statistic for Testing an Effect

    ondistributiFMS

    MSF

    E

    effect

    o ~Numerator df = dfeffect

    Denominator df = dferror

    If the F-statistic is large we reject that the effect is zero in

    favor of the alternative that the effect of the factor is non-zero.

  • 8/13/2019 08.Two Way Anova

    25/41

    Two-way ANOVA Table

    Source of

    Variation

    Degrees of

    Freedom

    Sum of

    Squares

    Mean

    Square F-ratio

    P-value

    FactorA a 1 SSA MSA FA =MSA /MSE Tail area

    FactorB b 1 SSB

    MSB

    FB

    =MSB

    /MSE

    Tail area

    Interaction (a1)(b1) SSAB MSAB FAB =MSAB /MSE Tail area

    Error ab(n1) SSE MSE

    Total abn 1 SST

    This is our initial focus

    which is the p-value for

    Question 1: Is there an

    interaction effect?

    T f H h

  • 8/13/2019 08.Two Way Anova

    26/41

    Tests of Hypotheses

    If the interaction is notstatistically significant

    (i.e.p-value> 0.05) then we conclude the maineffects (if present) are independent of one another.

    We can then test for significance of the main effectsseparately, again using an F-test.

    If a main effect is significant we can then usemultiple comparison procedures as usual tocompare the mean response for different levels ofthe factor while holding the other factor fixed.

    T f H h

  • 8/13/2019 08.Two Way Anova

    27/41

    Tests of Hypotheses

    If an interaction is significant (p-value < .05) we

    conclude the main effects are not independent ofone another and that both effects are important!

    In this case (i.e. the interaction is significant) thetests for main effects in the Two-way ANOVA

    table are MEANINGLESS!

    We must compare levels of factorA within

    each levelof factor B (and vise versa).

  • 8/13/2019 08.Two Way Anova

    28/41

    Example 1: Capsule Dissolve Time

    Enter the n = 5

    replicates for eachtreatment combination:Gastric, C

    Gastric, V

    Duodenal, C

    Duodenal, V

  • 8/13/2019 08.Two Way Anova

    29/41

    Example 1: Capsule Dissolve Time

    1st Highlight both

    factors in this

    list.

    Next highlight

    Full Factorial

    from the Macros

    pull-down menu.

    Then click Run Modelleaving everything else

    unchanged.

  • 8/13/2019 08.Two Way Anova

    30/41

    Example 1: Capsule Dissolve Time

    Lots of extra CRAP we dont need. Turn

    off the plots as they are unnecessary when

    considering two-way ANOVA. Also we

    really only need to consider the Effect

    Tests portion of the numeric output

    initially.

  • 8/13/2019 08.Two Way Anova

    31/41

  • 8/13/2019 08.Two Way Anova

    32/41

    Capsulex Fluid Type Interaction

    Treatment combination

    means.

    Interaction Plot

    Because the interaction is statistically significant

    we are interested in comparing fluid types for a

    given capsule type or comparing capsules for a

    given fluid type.

    The table on the right contains the results of all

    pair-wise treatment mean comparisons,

    however we are only interested in those as

    described above.

    Here we find that there is a significant

    difference in the fluid types for the type C

    capsules however there are no significant

    differences between the capsules themselves for

    given fluid type, nor is there a fluid effect whendissolving type V capsules.

    We estimate that the mean time to dissolve type

    C capsules in gastric fluid is between 3.57 and

    23.43 minutes larger than the mean for

    duodenal.

  • 8/13/2019 08.Two Way Anova

    33/41

    Checking Assumptions

    To check the assumptions of normality of the

    response and equality of variance for the

    difference treatment combinations we can

    examine the residuals. For a two-wayANOVA the residuals are the deviations of the

    observations from their respective treatment

    combination sample means, i.e.

    ijijkijk xxe

  • 8/13/2019 08.Two Way Anova

    34/41

    Checking Assumptions

    To check the assumption of normality, assess the

    normality of the residuals ijijkijk xxe

    The residuals from thecapsule experiment

    look approximately

    normal with the

    exception of twooutliers, but neither are

    extreme enough to

    warrant any concerns.

  • 8/13/2019 08.Two Way Anova

    35/41

    Checking Assumptions

    To check the equality of variance for the

    difference treatment combinations we can

    examine the residuals plotted vs. the different

    treatment combination means ijijkijk xxe

    There appears to be more variation for the

    dissolve times for type C capsules being

    dissolved in gastric fluid. These

    combination produced the two mildoutliers seen in the normal quantile plot.

    Generally we worry when the variation

    increases with the treatment combination

    mean.

  • 8/13/2019 08.Two Way Anova

    36/41

    Example 2: Comparing the Effectiveness of Three Forms ofPsychotherapy for Alleviating Depression

    Suppose that a clinical psychologist is interested incomparing the relative effectiveness of three forms ofpsychotherapy for alleviating depression. Fifteenindividuals are randomly assigned to each of three

    treatment groups: cognitive-behavioral, Rogerian, andassertiveness training. The Depression Scale of MMPIserves as the response. The psychologist also wished toincorporate information about the patients severity ofdepression, so all subjects in the study were classified ashaving mild, moderate, or severe depression. Thus wehave two factor of interest in this study: the treatmentthey received and the initial severity of their depression.

  • 8/13/2019 08.Two Way Anova

    37/41

    Example 2: Comparing the Effectiveness of Three Forms ofPsychotherapy for Alleviating Depression

    Interaction Plot

    Therapy Effect Plot

    Degree of Severity Effect Plot

  • 8/13/2019 08.Two Way Anova

    38/41

    Example 2: Comparing the Effectiveness of Three Forms ofPsychotherapy for Alleviating Depression

    Is there a significant interaction effect ? NO, p = .9717

    Is there a significant therapy effect ?

    Is there a significant degree of severity of effect ?

    YES, p = .0356

    YES, p < .0001

    Now we can conduct multiple comparisons on each factor separately.

  • 8/13/2019 08.Two Way Anova

    39/41

    Example 2: Comparing the Effectiveness of Three Forms ofPsychotherapy for Alleviating Depression

    We see that Rogerian

    therapy differs significantly

    from Cognitive-Behavioral

    therapy, with Rogerian

    having larger mean by

    between .8 and 9.87 units.

    We see that the initial severity of depression

    levels significantly differ from each other in

    terms of mean depression score. In particular

    we see that those with a severe classificationhave a mean depression score exceeding that for

    those with mild depression by between 8 and 18

    points and those with moderate depression by

    between 2 and 11.5 points.

  • 8/13/2019 08.Two Way Anova

    40/41

  • 8/13/2019 08.Two Way Anova

    41/41