Question

I'm new to R. We have an assignment that i'm working on. The assignment is on creating R package to mimic Anova table. I have created all the necessary function that is mandated in the assignment. The function calculates the correct values, but I couldn't make it display like ANOVA table that R's built in anova() function can. This is my summary.oneway function

summary.oneway <- function(object, ...){

  #model <- oneway(object)
  fval <- object$FValue
  TAB <- list(t(object$AOV), "Mean Sq."= rbind(object$MSB, object$MSW),
              "F Value" = fval, p.value = object$p.value)

  res <- list(call=object$call, onewayAnova = TAB)
  class(res) <- "summary.oneway"
  res  
}

This is the output:

Analysis of Variance:
oneway.formula(formula = coag ~ diet, data = coagdata)

[[1]]
         Sum of Squares Deg. of Freedom
diet                228               3
Residual            112              20

$`Mean Sq.`
        1
[1,] 76.0
[2,]  5.6

$`F Value`
       1 
13.57143 

$p.value
           1 
4.658471e-05

Actual ANOVA output:

Analysis of Variance Table

Response: coag
          Df Sum Sq Mean Sq F value    Pr(>F)    
diet       3    228    76.0  13.571 4.658e-05 ***
Residuals 20    112     5.6                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

How can I achieve this format? Where and what am I missing?

Thank you so much for your help.

Kuni

Was it helpful?

Solution

The Anova output uses the print method print.anova you may want to take look at methods(print) and specifically stats:::print.anova

You will most likely want to create your own print function

 print.oneway <- function(object, ...) {
     foo
     bar
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top