CowboyBear (10-10-2016), spunky (07-24-2012)
Following the discussion in this recent thread (Getting F statistic from multiple t-statistics?) and spunky's request therein, here is a neat trick one can use to test arbitrary contrasts for ANOVA models, and even multiple degree of freedom tests, using only some basic summary statistics of the kind that would be reported in a manuscript -- without needing access to the raw data.
Setup
We need the following three pieces of information to do these tricks:
- the cell means
- the sample sizes per cell
- at least one F-ratio corresponding to any of the possible contrasts from the ANOVA model
So let's say we have a manuscript on our desk in which the authors conducted a 2*2 factorial ANOVA, with factors (having levels and ) and (having levels and ). They give a table of means and sample sizes by cell, but for whatever reason only report the test of the interaction. So we have the following information:
Case 1: single degree of freedom testsCode:> # cell means > round(tapply(dat$y, list(A = dat$A,B = dat$B), mean), 2) B A -1 1 -1 103.54 99.28 1 99.59 102.61 > > # cell sample sizes > table(A = dat$A,B = dat$B) B A -1 1 -1 18 23 1 23 16 > > # t statistic for interaction contrast > summary(lm(y ~ A + B + AB, data=dat))$coef["AB",] Estimate Std. Error t value Pr(>|t|) 1.819051097 0.570385136 3.189162871 0.002073302
Perhaps as curious readers we are interested in knowing whether the cell differs from the other three cells. In other words we want to test the contrast below labeled "new":
Following the formula here, the F-ratio can be computed asCode:> cbind(contr, new = c(3,-1,-1,-1)) A B AB new [1,] 1 1 1 3 [2,] 1 -1 -1 -1 [3,] -1 1 -1 -1 [4,] -1 -1 1 -1
where and are the numbers of parameters in the full model and the nested model, respectively; and is the total sample size.
So the only two missing quantities here are SSR and SSE. If we can get those we can compute the desired F-ratio.
Given a particular contrast ,
SSR for =
where is the contrast weight for group , is the mean for group , is the number of groups, and is the number of observations in group .
So in this data we have
.
Now we need to get SSE. To do this, we can use the same formula to compute SSR for a contrast for which we already know F, and then rearrange the F-ratio formula to solve for SSE.
So for the known interaction contrast we have
.
Solving the F formula for SSE gives
Since , we can now just plug in the numbers to get
So that finally we have
And we can check our work by running anova() on the dataset after recoding the contrasts:
Aside from some minimal rounding error, we have it.Code:> anova(lm(y ~ other1 + other2 + new, data=dat)) Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) other1 1 38.06 38.056 1.4988 0.224639 other2 1 191.60 191.604 7.5462 0.007505 ** new 1 41.50 41.496 1.6343 0.205002 Residuals 76 1929.70 25.391 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Case 2: multiple degree of freedom tests
Given the same data as above, suppose now that for some reason we wish to see the 2 degree of freedom test comparing the full ANOVA model (factors A, B, and their interaction) to a model that only includes factor A.
We already saw above how to solve for SSE (and in fact we already computed it--we are using the same Full model so SSE will be the same). However, here we will get SSR in a slightly different way, using
where is the predicted value for observation under the smaller or reduced model, is the predicted value for observation under the larger or full model, and is the number of observations. Essentially, we are treating the predicted values from the more complex model as the data to be predicted and then computing the sum of squared errors in the normal fashion.
In the ANOVA case, this formula can be written more simply as
where is the number of observations in group , is the predicted value for group under the smaller or reduced model, is the predicted value for group under the larger or full model, and is the number of groups.
The predicted values from the Large model are straightforward: they are the group means. For the Small model, we have two sets of predicted values, those for and , and in both cases these predicted values are weighted averages of the two cell means at each level (i.e., collapsing across the factor), weighted by cell size.
For :
For :
So using the simplified SSR formula, we have
Which makes our F-ratio
Checking our work:
And again we have it, save for minimal rounding error.Code:> anova(lm(y ~ A, data=dat), + lm(y ~ A + B + AB, data=dat)) Analysis of Variance Table Model 1: y ~ A Model 2: y ~ A + B + AB Res.Df RSS Df Sum of Sq F Pr(>F) 1 78 2198.8 2 76 1929.7 2 269.06 5.2983 0.007013 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
In God we trust. All others must bring data.
~W. Edwards Deming
CowboyBear (10-10-2016), spunky (07-24-2012)
oh w-o-w!!! thanks Jake!!! instant subscription to this thread for future references now. i'm gonna have to start adding your posts in my reference sections, heh...
for all your psychometric needs! https://psychometroscar.wordpress.com/about/
I'm not sure how useful this stuff is when you have the actual dataset in hand, but with these procedures now you can really be the Reviewer From Hell...
In God we trust. All others must bring data.
~W. Edwards Deming
Tweet |