[R] Combining two ANOVA outputs of different lengths
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Aug 10 12:01:25 CEST 2007
Christoph Scherber wrote:
> Dear R users,
>
> I have been trying to combine two anova outputs into one single table
> (for later publication). The outputs are of different length, and share
> only some common explanatory variables.
>
> Using merge() or melt() (from the reshape package) did not work out.
>
> Here are the model outputs and what I would like to have:
>
> anova(model1)
> numDF denDF F-value p-value
> (Intercept) 1 74 0.063446 0.8018
> days 1 74 6.613997 0.0121
> logdiv 1 74 1.587983 0.2116
> leg 1 74 4.425843 0.0388
>
> anova(model2)
> numDF denDF F-value p-value
> (Intercept) 1 73 165.94569 <.0001
> funcgr 1 73 7.91999 0.0063
> grass 1 73 42.16909 <.0001
> leg 1 73 4.72108 0.0330
> funcgr:grass 1 73 8.49068 0.0047
>
> #"merge(anova(model1),anova(model2),...)"
>
> F-value 1 p-val1 F-value 2 p-value 2
> (Intercept) 0.063446 0.8018 165.94569 <.0001
> days 6.613997 0.0121 NA NA
> logdiv 1.587983 0.2116 NA NA
> leg 4.425843 0.0388 4.72108 0.033
> funcgr NA NA 7.91999 0.0063
> grass NA NA 42.16909 <.0001
> funcgr:grass NA NA 8.49068 0.0047
>
>
> I would be glad if someone would have an idea of how to do this in
> principle.
>
The main problems are that the merge key is the rownames and that you
want to keep entries that are missing in one of the analysis. There are
ways to deal with that:
> example(anova.lm)
.....
> merge(anova(fit2), anova(fit4), by=0, all=T)
Row.names Df.x Sum Sq.x Mean Sq.x F value.x Pr(>F).x Df.y Sum Sq.y
1 ddpi NA NA NA NA NA 1 63.05403
2 dpi NA NA NA NA NA 1 12.40095
3 pop15 1 204.11757 204.11757 13.211166 0.000687868 1 204.11757
4 pop75 1 53.34271 53.34271 3.452517 0.069425385 1 53.34271
5 Residuals 47 726.16797 15.45038 NA NA 45 650.71300
Mean Sq.y F value.y Pr(>F).y
1 63.05403 4.3604959 0.0424711387
2 12.40095 0.8575863 0.3593550848
3 204.11757 14.1157322 0.0004921955
4 53.34271 3.6889104 0.0611254598
5 14.46029 NA NA
Presumably, you can take it from here.
More information about the R-help
mailing list