Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posthocTGH function accepts formula. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 55 additions & 16 deletions R/posthocTGH.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gjalt-jorn@@userfriendlyscience.com>
#' @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.
Expand Down Expand Up @@ -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 <gjalt-jorn@@userfriendlyscience.com>
#' @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) {
Expand Down Expand Up @@ -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');
Expand Down