diff --git a/R/posthocTGH.R b/R/posthocTGH.R index ec860b4..9c196ce 100644 --- a/R/posthocTGH.R +++ b/R/posthocTGH.R @@ -3,8 +3,28 @@ #' This function is used by the 'oneway' function for oneway analysis of #' variance in case a user requests post-hoc tests using the Tukey or #' Games-Howell methods. +#' +#' @author Gjalt-Jorn Peters (Open University of the Netherlands) & Jeff Bagget +#' (University of Wisconsin - La Crosse) #' +#' Maintainer: Gjalt-Jorn Peters +#' @keywords utilities +#' @examples #' +#' ### Compute post-hoc statistics using the tukey method +#' posthocTGH(y=ChickWeight$weight, x=ChickWeight$Diet, method="tukey"); +#' posthocTGH(weight ~ Diet, data = ChickWeight, method="tukey"); +#' ### Compute post-hoc statistics using the games-howell method +#' posthocTGH(y=ChickWeight$weight, x=ChickWeight$Diet); +#' posthocTGH(weight ~ Diet, data = ChickWeight); +#' +#' @export posthocTGH +posthocTGH <- function(...) { + UseMethod("posthocTGH") +} + +#' @rdname posthocTGH +#' #' @param y y has to be a numeric vector. #' @param x x has to be vector that either is a factor or can be converted into #' one. @@ -37,22 +57,10 @@ #' \code{userfriendlyscience} version 0.6-2, the default of this setting #' changed from \code{"holm"} to \code{"none"} (also see #' https://stats.stackexchange.com/questions/83941/games-howell-post-hoc-test-in-r). -#' @author Gjalt-Jorn Peters (Open University of the Netherlands) & Jeff Bagget -#' (University of Wisconsin - La Crosse) -#' -#' Maintainer: Gjalt-Jorn Peters -#' @keywords utilities -#' @examples -#' -#' ### Compute post-hoc statistics using the tukey method -#' posthocTGH(y=ChickWeight$weight, x=ChickWeight$Diet, method="tukey"); -#' ### Compute post-hoc statistics using the games-howell method -#' posthocTGH(y=ChickWeight$weight, x=ChickWeight$Diet); -#' -#' @export posthocTGH -posthocTGH <- function(y, x, method=c("games-howell", "tukey"), - conf.level = 0.95, digits=2, - p.adjust="none", formatPvalue = TRUE) { +#' +posthocTGH.default <- function(y, x, method=c("games-howell", "tukey"), + conf.level = 0.95, digits=2, + p.adjust="none", formatPvalue = TRUE) { ### Based on http://www.psych.yorku.ca/cribbie/6130/games_howell.R method <- tolower(method); tryCatch(method <- match.arg(method), error=function(err) { @@ -167,6 +175,37 @@ posthocTGH <- function(y, x, method=c("games-howell", "tukey"), } +#' @rdname posthocTGH +#' +#' @param formula A formula specifying the model. +#' @param data an optional matrix or data frame (or similar: see +#' \code{\link{model.frame}}) containing the variables in the formula +#' \code{formula}. By default the variables are taken from +#' \code{environment(formula)}. +#' @param subset an optional vector specifying a subset of observations +#' to be used. +#' @param na.action a function which indicates what should happen when the data +#' contain \code{NA}s. Defaults to \code{getOption("na.action")}. +#' @param \dots further arguments to be passed to or from methods. +#' +posthocTGH.formula <- function(formula, data, subset, na.action, ...) +{ + if(missing(formula) + || (length(formula) != 3L) + || (length(attr(terms(formula[-2L]), "term.labels")) != 1L)) + stop("'formula' missing or incorrect") + m <- match.call(expand.dots = FALSE) + if(is.matrix(eval(m$data, parent.frame()))) + m$data <- as.data.frame(data) + ## need stats:: for non-standard evaluation + m[[1L]] <- quote(stats::model.frame) + m$... <- NULL + mf <- eval(m, parent.frame()) + DATA <- list(mf[,1], mf[,2]) + y <- do.call("posthocTGH", c(DATA, list(...))) + y +} + print.posthocTGH <- function(x, digits=x$input$digits, ...) { print(x$intermediate$descriptives, digits=digits); cat('\n');