R/MVA.anova.R

Defines functions MVA.anova

Documented in MVA.anova

MVA.anova <- function(object,...) {
  right.all <- attr(terms(object),"term.labels")
  right.in <- right.all[right.all %in% attr(terms(object$terminfo),"term.labels")]
  cond <- if (any(!right.all %in% right.in)) {
    paste0(right.all[!right.all %in% right.in],collapse="+")
  } else {NULL}
  aov.tab <- anova(object,by="terms",...)
  n.terms <- length(right.in)
  Df <- Var <- F <- p <- rep(0,n.terms)
  for (i in 1:n.terms) {
    names.i <- c(right.in[-i],right.in[i])
    right.formula.i <- if (!is.null(cond)) {
	paste(paste0(names.i,collapse="+"),cond,sep="+")
    } else {
	paste0(names.i,collapse="+")
    }
    form.i <- as.formula(paste0(".~",right.formula.i))
    mod.i <- update(object,form.i)
    aov.tab.i <- anova(mod.i,by="terms",...)
    Df[i] <- aov.tab.i[right.in[i],1]
    Var[i] <- aov.tab.i[right.in[i],2]
    F[i] <- aov.tab.i[right.in[i],3]
    p[i] <- aov.tab.i[right.in[i],4]
  }
  result <- aov.tab
  result[1:n.terms,1] <- Df
  result[1:n.terms,2] <- Var
  result[1:n.terms,3] <- F
  result[1:n.terms,4] <- p
  h <- attr(aov.tab,"heading")[1]
  hsplit <- strsplit(h,split="\n")[[1]]
  hsplit[2] <- "Type II tests"
  attr(result,"heading")[1] <- paste0(paste(hsplit,collapse="\n"),"\n")
  return(result)
}

Try the RVAideMemoire package in your browser

Any scripts or data that you put into this service are public.

RVAideMemoire documentation built on Nov. 6, 2023, 5:07 p.m.