Is there an easy way of converting an aov.summary into a matrix in which the rows are the factor names and the columns are Df, Sum Sq, Mean Sq, F value and Pr. For example, convert Df Sum Sq Mean Sq F value Pr(>F) block 5 343.29 68.66 4.4467 0.015939 * N 1 189.28 189.28 12.2587 0.004372 ** P 1 8.40 8.40 0.5441 0.474904 K 1 95.20 95.20 6.1657 0.028795 * N:P 1 21.28 21.28 1.3783 0.263165 N:K 1 33.14 33.14 2.1460 0.168648 P:K 1 0.48 0.48 0.0312 0.862752 Residuals 12 185.29 15.44 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 To Factor Df Sum Sq Mean Sq F value Pr block 5 343.29 68.66 4.4467 0.015939 N 1 189.28 189.28 12.2587 0.004372 P 1 8.40 8.40 0.5441 0.474904 K 1 95.20 95.20 6.1657 0.028795 N:P 1 21.28 21.28 1.3783 0.263165 N:K 1 33.14 33.14 2.1460 0.168648 P:K 1 0.48 0.48 0.0312 0.862752 Residuals 12 185.29 15.44 NA NA Thanks, - Moises
On Tue, 17 Aug 2004, Moises Hassan wrote:> Is there an easy way of converting an aov.summary into a matrix in which > the rows are the factor names and the columns are Df, Sum Sq, Mean Sq, F > value and Pr.You are confusing the printed representation with the object (which seems today's favourite misconception). as.matrix(summary(npk.aov)[[1]]) is a matrix (to full precision) as you seek, although I would prefer to work with the data frame which is returned. (Note: your output is from MASS4 & example(aov), unattributed.)> For example, convert > > Df Sum Sq Mean Sq F value Pr(>F) > block 5 343.29 68.66 4.4467 0.015939 * > N 1 189.28 189.28 12.2587 0.004372 ** > P 1 8.40 8.40 0.5441 0.474904 > K 1 95.20 95.20 6.1657 0.028795 * > N:P 1 21.28 21.28 1.3783 0.263165 > N:K 1 33.14 33.14 2.1460 0.168648 > P:K 1 0.48 0.48 0.0312 0.862752 > Residuals 12 185.29 15.44 > --- > Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > > > To > > Factor Df Sum Sq Mean Sq F value Pr > block 5 343.29 68.66 4.4467 0.015939 > N 1 189.28 189.28 12.2587 0.004372 > P 1 8.40 8.40 0.5441 0.474904 > K 1 95.20 95.20 6.1657 0.028795 > N:P 1 21.28 21.28 1.3783 0.263165 > N:K 1 33.14 33.14 2.1460 0.168648 > P:K 1 0.48 0.48 0.0312 0.862752 > Residuals 12 185.29 15.44 NA NA-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Moises Hassan wrote:> Is there an easy way of converting an aov.summary into a matrix in which > the rows are the factor names and the columns are Df, Sum Sq, Mean Sq, F > value and Pr. > > For example, convert > > Df Sum Sq Mean Sq F value Pr(>F) > block 5 343.29 68.66 4.4467 0.015939 * > N 1 189.28 189.28 12.2587 0.004372 ** > P 1 8.40 8.40 0.5441 0.474904 > K 1 95.20 95.20 6.1657 0.028795 * > N:P 1 21.28 21.28 1.3783 0.263165 > N:K 1 33.14 33.14 2.1460 0.168648 > P:K 1 0.48 0.48 0.0312 0.862752 > Residuals 12 185.29 15.44 > --- > Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > > > To > > Factor Df Sum Sq Mean Sq F value Pr > block 5 343.29 68.66 4.4467 0.015939 > N 1 189.28 189.28 12.2587 0.004372 > P 1 8.40 8.40 0.5441 0.474904 > K 1 95.20 95.20 6.1657 0.028795 > N:P 1 21.28 21.28 1.3783 0.263165 > N:K 1 33.14 33.14 2.1460 0.168648 > P:K 1 0.48 0.48 0.0312 0.862752 > Residuals 12 185.29 15.44 NA NA > >Try this: example(aov) as.data.frame.summary.aovlist <- function(x) { if(length(x) == 1) { as.data.frame(x[[1]]) } else { lapply(unlist(x, FALSE), as.data.frame) } } x1 <- summary(npk.aov) x2 <- summary(npk.aovE) as.data.frame(x1) as.data.frame(x2) --sundar