Hi all, This Blog is an English archive of my PhD experience in Imperial College London, mainly logging my research and working process, as well as some visual records.

Saturday, 25 August 2007

Not Yet Another ANOVA (one-way and two-way)

See: http://www.uwsp.edu/psych/stat/12/anova-1w.htm
and http://www.uwsp.edu/psych/stat/13/anova-2w.htm

One-Way ANOVA


1.Logic & Functionality:

The reason this analysis is called ANOVA rather than multi-group means analysis (or something like that) is because it compares group means by analyzing comparisons of variance estimates. Consider:

    Picture (354x381, 19.7Kb)

We draw three samples. Why might these means differ? There are two reasons:

  1. Group Membership (i.e., the treatment effect or IV).
  2. Differences not due to group membership (i.e., chance or sampling error).

The ANOVA is based on the fact that two independent estimates of the population variance can be obtained from the sample data. A ratio is formed for the two estimates, where:

    one is sensitive to ®
    treatment effect & error
    between groups estimate
    and the other to ®
    error
    within groups estimate

Given the null hypothesis (in this case HO: m1=m2=m3), the two variance estimates should be equal. That is, since the null assumes no treatment effect, both variance estimates reflect error and their ratio will equal 1. To the extent that this ratio is larger than 1, it suggests a treatment effect (i.e., differences between the groups).

On the other hand, We could do a bunch of between groups t tests. However, this is not a good idea for three reasons.

  1. The amount of computational labor increases rapidly with the number of groups in the study.

      Number
      Groups
      Number Pairs
      of Means
      33
      46
      510
      615
      721
      828

  2. We are interested in one thing -- is the number of people present related to helping behavior? -- thus it would be nice to be able to do one test that would answer this question.

  3. The type I error rate rises with the number of tests we perform.
2. Implementation

2.1. Partitioning the Variance

As noted above, two independent estimates of the population variance can be obtained. Expressed in terms of the Sum of Squares:

Picture (512x225, 8Kb)

To make this more concrete, consider a data set with 3 groups and 4 subjects in each. Thus, the possible deviations for the score X13 are as follows:

Picture (576x429, 15Kb)

As you can see, there are three deviations and:

Picture (148x66, 1.1Kb)Picture (160x66, 1.2Kb)Picture (116x66, 1009 bytes)
total
within
groups
between
groups
#3
#1
#2

To obtain the Sum of the Squared Deviations about the Mean (the SS), we can square these deviations and sum them over all the scores.

    Picture (488x226, 4.7Kb)

Thus we have:

    Picture (418x330, 6.4Kb)

Note: nj in formula for the SSBetween means do it once for each deviation.



2.2. The F Test

It is simply the ratio of the two variance estimates:

    Picture (218x108, 1.9Kb)

As usual, the critical values are given by a table. Going into the table, one needs to know the degrees of freedom for both the between and within groups variance estimates, as well as the alpha level.


Two way ANOVA

1. Logic


Simply, we considered there is just one observation result for each combination of levels of the multi-factors in previous post about two way ANOVA, see http://dbigbear.blogspot.com/2007/08/analysis-of-variance-anova.html

But here, we are going to think of a little more complex situation that for each combination of the factors' levels value, we have got n observation result, as the table below:

Thus:


Factor BA
Marginals
b1b2bkbq
Factor
A
a1 Xi11Xi12Xi1kXi1qPicture (51x55, 573 bytes)
Xn11Xn12Xn1kXn1q
Picture (56x55, 571 bytes)Picture (58x55, 576 bytes)Picture (60x55, 582 bytes)Picture (60x60, 600 bytes)
a2 Xi21Xi22Xi2kXi2qPicture (53x55, 589 bytes)
Xn21Xn22Xn2kXn2q
Picture (56x55, 577 bytes)Picture (60x55, 585 bytes)Picture (61x55, 582 bytes)Picture (60x60, 611 bytes)
aj Xij1Xij2XijkXijqPicture (48x60, 576 bytes)
Xnj1Xnj2XnjkXnjq
Picture (53x60, 579 bytes)Picture (55x60, 584 bytes)Picture (56x60, 583 bytes)Picture (56x60, 592 bytes)
ap Xip1Xip2XipkXipqPicture (53x60, 602 bytes)
Xnp1Xnp2XnpkXnpq
Picture (58x60, 601 bytes)Picture (60x60, 604 bytes)Picture (61x60, 612 bytes)Picture (61x60, 620 bytes)
B
Marginals
Picture (50x55, 579 bytes)Picture (53x55, 589 bytes)Picture (53x55, 587 bytes)Picture (53x60, 595 bytes)Picture (45x55, 501 bytes)
Grand Mean

Note: the grand N=npq. Also note that since the calculations become much more difficult with unequal ns, we will only cover the situation of equal ns.

1.2 Advantages of the Factorial Design

There are three important advantages to the factorial design:

  1. Economy

    The design provides more information from the same amount of work. Consider the effects of marijuana on memory. We have an experimental group that receives the drug and a control group that receives a placebo.

  2. Two Group Design
    Control
    Experimental
    n=10
    n=10

    Factorial Design

    Control
    Experimental
    naive
    n=5
    n=5
    experienced
    n=5
    n=5

    n=10
    n=10

Although the number of subjects is the same in both designs, with the factorial design, we obtain the additional information about the relationship of previous experience with the drug to memory performance.

  1. Experimental Control & Increased Generality of the Results

    Suppose we are interested in the effects of teaching method on student performance. A potential extraneous variable in this case is the IQ of the students. The EV inflates the error term (i.e., the within group variability). One way to deal with this problem is to employ subjects with a homogeneous IQ. A more elegant solution is to include IQ as a factor in the design and thus remove this added source of variability from the error term.


  2. Teaching Method
    A
    B
    C
    IQLow


    Medium


    High


An additional potential advantage of this approach is that the results have more generality (they apply to folks of varying IQs).

  1. The Interaction

    The factorial design is the only way that we can investigate the interactions among IVs. This is particularly important because the effect of an IV rarely occurs in isolation. In the real world, many variables operate simultaneously. Thus, the factorial design allows us to investigate these more realistic situations.

    In the two way factorial design, there is one possible interaction. We have discussed the notion of the interaction in detail above. In a three way factorial design, there are four possible interactions, that is: A x B, A x C, B x C, and the triple interaction, A x B x C. Triple interactions are beyond the scope of this course and thus will not be discussed further.


there will be a source of variance for each effect as well as the error term. In terms of the Sum of Squares:

Picture (511x217, 9.4Kb)


2. Implementation

Thus, there are five deviations involved:

For SSA, we are interested in the deviations of the A marginals about the grand mean. In symbols:

Picture (140x66, 1Kb)

For the actual formula, we need to square and sum these deviations over all subjects.

Picture (351x111, 2.3Kb)

For SSB, we are interested in the deviations of the B marginals about the grand mean. In symbols:

Picture (145x66, 1.1Kb)

For the actual formula, we need to square and sum these deviations over all subjects.

Picture (356x106, 2.3Kb)

For SSwithin, we are interested in the deviations of the individual scores from their cell means. In symbols:

Picture (161x66, 1.2Kb)

For the actual formula, we need to square and sum these deviations over all subjects.

Picture (451x111, 3.1Kb)

For SSAxB, we are interested in the deviations of the cell means from the grand mean minus the effects of factors A and B. In symbols:

Picture (470x66, 2.5Kb)

This reduces to:

Picture (373x158, 3.3Kb)

For the actual formula, we need to square and sum these deviations over all subjects.

Picture (550x100, 5.6Kb)

For SST, we are interested in the deviations of the individual scores from the grand mean. In symbols:

Picture (151x66, 1.1Kb)

For the actual formula, we need to square and sum these deviations over all subjects.

Picture (428x111, 2.9Kb)

And for the degrees of freedom, we have:

dfA=p-1
dfB=q-1
dfAxB=(p-1)(q-1)
=pq-p-q+1
dfwithin=pq(n-1)
=pqn-pq
=N-pq
dfT=npq-1
=N-1

3. Example

Here is the data (i.e., the number of trials to learn PA):

    Age ->
    Young
    b1
    Older
    b2

    Maternal Diet ->
    0%
    a1
    35%
    a2
    0%
    a1
    35%
    a2
    Data
    51866
    41979
    31455
    41289
    21543
    Picture (136x60, 809 bytes)
    18783032
    n=njk
    5555
    Picture (106x60, 779 bytes)
    3.615.666.4

The relevant descriptive statistic is the means, and, in the case of an ANOVA, it is probably best to plot them:

Picture (520x428, 8.5Kb)

Let's expand on the data grid for the calculations.

Age ->b1b2

Maternal Diet ->a1a2a1a2
Data XX2XX2XX2XX2
52518324636636
41619361749981
3914196525525
41612144864981
241522541639
Picture (136x60, 809 bytes)
18
78
30
32
158
T
n=njk
5555
20
N
Picture (106x60, 779 bytes)
3.615.666.4


Picture (226x105, 1.6Kb)
701250190232
1742
II

The following table helps with computing marginal totals.


b1
b2

a1
18
30
48
Tj.s
a2
78
32
110

96
62
158

T.ks

T..

Now we will need five quantities. Note, in the interest of saving some space, all intermediate quantities are not shown.

      I.
      Picture (323x101, 2Kb)
      II.
      Picture (365x111, 2.6Kb)
      III.
      Picture (470x165, 3Kb)
      IV.
      Picture (451x160, 3Kb)
      V.
      Picture (478x290, 4Kb)

And:

      SSA=III-I=1440.4-1248.2=192.2
      SSB=IV-I=1306.0-1248.2=57.8
      SSAxB=V+I-III-IV=1666.4+1248.2-
      1440.4-1306.0
      =168.2
      SSW=II-V=1742.0-1666.4=75.6
      SST=II-I=1742.0-1248.2=493.8

We check that the Sum of Squares add up to the total and they do. Thus, remembering that:

Picture (150x95, 1.2Kb) and Picture (201x108, 1.7Kb)

we can fill in the ANOVA Summary Table.

      SourceSSdfMSFp
      A
      192.2
      1
      192.2
      40.68.05
      B
      57.8
      1
      57.8
      12.23.05
      AxB
      168.2
      1
      168.2
      35.60.05
      Within
      75.6
      16
      4.725

      Total
      493.8
      19

  1. Decision
    Since we have three research questions, we also have three decisions to make. Since all three Fobs values are greater than the Fcrit (i.e., 4.49), we reject Ho in each case.
    1. There is a main effect of prenatal alcohol which says that animals receiving alcohol in utero showed impaired passive avoidance learning when compared to controls.
    2. There is a main effect of age which says that mature animals learned the task more quickly.
    3. There is an interaction which says that prenatal alcohol produces a deficit in the ability to withhold responding which dissipates as the animal matures.

    Note that given this pattern of data (which are fictitious but based upon fact), we would not pay attention to the main effects. The main effect of age is not true for the 0%EDC animals. The main effect of alcohol is not true for the adult animals. Thus, the interaction is what is worth paying attention too in this study.

Comparisons Revisited

In the example we have given of the 2x2 ANOVA, the outcome is clear. However, what if we had employed a 3x3 factorial design? That is, we include another control group that receives a normal, Lab Chow (LC) diet and we test the animals at either 30, 80, or 130 days of age. There are two types of analysis that should be mentioned here. I should note that in an effort to keep things simple, I will not ask you to actually perform these analyses. However, they follow logically from what we have been doing and it is certainly worth your while to be aware of their existence.

  1. Further Analysis of Main Effects

    If there was no interaction and a significant main effect, we could do an analysis similar to what we did when using the protected t test with the one way ANOVA. Below is a formula to determine the Least Significant Difference (LSD) between means that is worthy of our attention. The procedure is essentially the same as for the protected t, however, in this case, the main effect is reflected in the marginal means which changes the formula slightly, and we are computing an LSD rather than an F ratio which also shifts things around a bit.

    Picture (433x125, 2.9Kb)

    Consider the hypothetical example below:

    Picture (500x404, 14.5Kb)

    In this case, the analysis would reveal that the significant main effect of maternal diet is due to the fact that the animals receiving alcohol in utero took longer to learn PA that did controls (which did not differ among themselves).

  2. Simple Main Effects of the Interaction

    If, however, the interaction was significant, we might want to look at the simple main effects of the interaction. This analysis looks at the difference between the cell means for one factor at each of the levels of the other. The least significant difference between the means is computed with a slight modification to the formula we used above, that is:

    Picture (406x120, 2.8Kb)

    The hypothetical data presented below (which, in this case, is based on the actual data obtained in the experiment) shows a significant interaction.

    Picture (500x401, 13.1Kb)

    Computing the simple main effects of the interaction would show that the animals receiving alcohol in utero took significantly longer to learn PA at 30 days of age. At 80 days, the effect was marginal and at 130 days there was no effect. Furthermore, the analysis would show that the two control groups were not significantly different at any age.

No comments: