[R] Output of Anova (CAR package) in Sweave

Maria Wolters mwolters at staffmail.ed.ac.uk
Tue Jun 16 16:21:57 CEST 2009


Many thanks to John Fox, who replied on-list,
and to David Hajage, who replied to me
off list. David suggested this quick hack of the
print.anova.mlm function, which I am sharing with his
permission

# From print.Anova.mlm
xtable.Anova.mlm <- function (x, ...) {
     test <- x$test
     repeated <- x$repeated
     ntests <- length(x$terms)
     tests <- matrix(NA, ntests, 4)
     if (!repeated)
         SSPE.qr <- qr(x$SSPE)
     for (term in 1:ntests) {
         eigs <- Re(eigen(qr.coef(if (repeated) qr(x$SSPE[[term]]) else
SSPE.qr,
             x$SSP[[term]]), symmetric = FALSE)$values)
         tests[term, 1:4] <- switch(test, Pillai = stats:::Pillai(eigs,
             x$df[term], x$error.df), Wilks = stats:::Wilks(eigs,
             x$df[term], x$error.df), `Hotelling-Lawley` = stats:::HL(eigs,
             x$df[term], x$error.df), Roy = stats:::Roy(eigs,
             x$df[term], x$error.df))
     }
     ok <- tests[, 2] >= 0 & tests[, 3] > 0 & tests[, 4] > 0
     ok <- !is.na(ok) & ok
     tests <- cbind(x$df, tests, pf(tests[ok, 2], tests[ok, 3],
         tests[ok, 4], lower.tail = FALSE))
     rownames(tests) <- x$terms
     colnames(tests) <- c("Df", "test stat", "approx F", "num Df",
         "den Df", "Pr(>F)")
     tests <- structure(as.data.frame(tests), heading = paste("\nType ",
         x$type, if (repeated)
             " Repeated Measures", " MANOVA Tests: ", test, " test
statistic",
         sep = ""), class = c("anova", "data.frame"))
#    print(tests)
#    invisible(x)
       xtable(test)
}

John provided extremely useful additional information; the link to  
Peter Dalgaard's article is also much appreciated.

Maria, a "happy customer" ;)

-- 
Dr Maria Wolters
    CSTR / HCRC, School of Informatics
    MATCH Research Fellow
    EdSST Project Manager
mwolters AT staffmail.ed.ac.uk

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.




More information about the R-help mailing list