R/one.lsd.R

Defines functions one.lsd

Documented in one.lsd

#' This is a basic function used in lsd.test.
#'
#' Do not use this function, use \code{lsd.test}.
#'
one.lsd <- function(df, alpha=0.05) {
  y <- df[, 1]  # Response variable
  Factor <- df[, 2]  # Important factor
  mse <- summary(mod)[[1]]["Residuals", "Mean Sq"]
  dof <- summary(mod)[[1]]["Residuals", "Df"]
  ni <- table(Factor)  # Number of observations per cell
  fun1 <- function(a, b) 1/a + 1/b  # Auxiliar function
  LSD <- qt(p=alpha/2, dof, lower.tail=F) * sqrt(mse * outer(ni, ni, fun1))
  means <- sapply(split(y, Factor), mean)
  comparisons <- abs(outer(means, means, "-"))
  abs.dif <- comparisons
  comparisons <- ifelse(comparisons > LSD, 'Diff', 'Equal')
  comparisons[lower.tri(comparisons, diag=T)] <- "----"
  list(LSD=LSD,
       abs.dif=abs.dif[-nrow(comparisons), -1],
       conclusions=comparisons[-nrow(comparisons), -1], 
       means=sort(means))
}
fhernanb/model documentation built on Sept. 16, 2017, 11 a.m.