diff --git a/DESCRIPTION b/DESCRIPTION index 567bd68..7b19aab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: afex Type: Package Title: Analysis of Factorial Experiments Depends: R (>= 3.1.0), lme4 (>= 1.1-8), lsmeans (>= 2.17) -Suggests: ascii, xtable, parallel, plyr, optimx, nloptr, knitr, rmarkdown, lattice, +Suggests: xtable, parallel, plyr, optimx, nloptr, knitr, rmarkdown, lattice, latticeExtra, multcomp, testthat, mlmRev, dplyr, tidyr, dfoptim, Matrix Imports: stringr, coin, pbkrtest (>= 0.4-1), lmerTest, car, reshape2, stats, methods Description: Provides convenience functions for analyzing factorial experiments using @@ -28,6 +28,6 @@ Authors@R: c(person(given="Henrik", family="Singmann", role=c("aut", "cre"), role=c("ctb")), person(given="Michael A.", family="Lawrence", role=c("ctb")), person(given="Ulf", family="Mertens", role=c("ctb")), person(given="Jonathan", family="Love", role=c("ctb")) ) -Version: 0.17-5 -Date: 2017-04-03 +Version: 0.17-6 +Date: 2017-04-06 RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index 3fb31d7..025490f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -69,6 +69,7 @@ importFrom(stats,model.matrix) importFrom(stats,optim) importFrom(stats,p.adjust) importFrom(stats,setNames) +importFrom(stats,symnum) importFrom(stats,t.test) importFrom(stats,terms) importFrom(stats,update) diff --git a/R/afex-package.R b/R/afex-package.R index 8a8f485..78f3661 100644 --- a/R/afex-package.R +++ b/R/afex-package.R @@ -3,8 +3,8 @@ #' \tabular{ll}{ #' Package: \tab afex\cr #' Type: \tab Package\cr -#' Version: \tab 0.17-5\cr -#' Date: \tab 2017-04-03\cr +#' Version: \tab 0.17-6\cr +#' Date: \tab 2017-04-06\cr #' Depends: \tab R (>= 3.1.0), lme4 (>= 1.1-8), lsmeans (>= 2.17)\cr #' Encoding: \tab UTF-8\cr #' License: \tab GPL (>=2)\cr diff --git a/R/helpers.R b/R/helpers.R index ede16c1..8a5f64b 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -13,6 +13,7 @@ #' \item \code{es_aov}: Effect size reported for ANOVAs (see \code{\link{aov_car}}), default is \code{"ges"} (generalized eta-squared). #' \item \code{correction_aov}: Correction used for within-subjects factors with more than two levels for ANOVAs (see \code{\link{aov_car}} or \code{\link{nice}}), default is \code{"GG"} (Greenhouse-Geisser correction). (ANOVA functions only) #' \item \code{factorize}: Should between subject factors be factorized (with note) before running the analysis? Default is \code{TRUE}. (ANOVA functions only) +#' \item \code{sig_symbols}: Default significant symbols used for ANOVA and \code{mixed} printing. Default is\code{c(" +", " *", " **", " ***")}. #' \item \code{lmer_function}: Which \code{lmer} function should \code{mixed} or \code{lmer_alt} use. The default is \code{"lmerTest"} which uses \code{\link[lmerTest]{lmer}}, \code{"lme4"} is also possible which uses \code{\link[lme4]{lmer}}. There should be no difference between the two. The latter could be minimally faster, but does not allow to use \code{lmerTest::anova()}. #' } #' diff --git a/R/methods.afex_aov.R b/R/methods.afex_aov.R index 286da96..622fb5c 100644 --- a/R/methods.afex_aov.R +++ b/R/methods.afex_aov.R @@ -21,7 +21,7 @@ #' \code{p_adjust_method} defaults to the method specified in the call to \code{\link{aov_car}} in \code{anova_table}. If no method was specified and \code{p_adjust_method = NULL} p-values are not adjusted. #' #' @references -#' Cramer, A. O. J., van Ravenzwaaij, D., Matzke, D., Steingroever, H., Wetzels, R., Grasman, R. P. P. P., ... Wagenmakers, E.-J. (2015). Hidden multiplicity in exploratory multiway ANOVA: Prevalence and remedies. \emph{Psychonomic Bulletin & Review}, 1–8. doi:\href{http://doi.org/10.3758/s13423-015-0913-5}{10.3758/s13423-015-0913-5} +#' Cramer, A. O. J., van Ravenzwaaij, D., Matzke, D., Steingroever, H., Wetzels, R., Grasman, R. P. P. P., ... Wagenmakers, E.-J. (2015). Hidden multiplicity in exploratory multiway ANOVA: Prevalence and remedies. \emph{Psychonomic Bulletin & Review}, 1-8. doi:\href{http://doi.org/10.3758/s13423-015-0913-5}{10.3758/s13423-015-0913-5} #' #' @name afex_aov-methods #' @importFrom stats p.adjust @@ -33,7 +33,7 @@ NULL #' @inheritParams nice #' @method anova afex_aov #' @export -anova.afex_aov <- function(object, es = afex_options("es_aov"), observed = NULL, correction = afex_options("correction_aov"), MSE = TRUE, intercept = FALSE, p_adjust_method = NULL, ...) { +anova.afex_aov <- function(object, es = afex_options("es_aov"), observed = NULL, correction = afex_options("correction_aov"), MSE = TRUE, intercept = FALSE, p_adjust_method = NULL, sig_symbols = afex_options("sig_symbols"), ...) { # internal functions: # check arguments dots <- list(...) @@ -113,18 +113,19 @@ anova.afex_aov <- function(object, es = afex_options("es_aov"), observed = NULL, attr(anova_table, "es") <- es attr(anova_table, "correction") <- if(length(attr(object, "within")) > 0 && any(vapply(object$data$long[, attr(object, "within"), drop = FALSE], nlevels, 0) > 2)) correction else "none" attr(anova_table, "observed") <- if(!is.null(observed) & length(observed) > 0) observed else character(0) - attr(anova_table, "sig_symbols") <- if(!is.null(dots$sig_symbols)) dots$sig_symbols else afex_options("sig_symbols") + attr(anova_table, "sig_symbols") <- if(!is.null(sig_symbols)) sig_symbols else afex_options("sig_symbols") anova_table } #' @rdname afex_aov-methods #' @method print afex_aov +#' @importFrom stats symnum #' @export print.afex_aov <- function(x, ...) { out <- nice(x$anova_table, ...) print(out) - - sleg <- paste(paste(c(0, 0.001, 0.01, 0.05, 0.1), rev(paste0("‘", c(" ", gsub(" ", "", attr(x$anova_table, "sig_symbols"))), "’")), collapse = " "), 1) + sleg <- attr(symnum(0, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), + symbols = rev(c(" " ,stringr::str_trim(attr(x$anova_table, "sig_symbols"))))), "legend") width <- getOption("width") if(width < nchar(sleg)) { diff --git a/R/nice.R b/R/nice.R index 9d61019..5dae041 100644 --- a/R/nice.R +++ b/R/nice.R @@ -8,7 +8,7 @@ #' @param observed character vector referring to the observed (i.e., non manipulated) variables/effects in the design. Important for calculation of generalized eta-squared (ignored if \code{es} is not \code{"ges"}), see details. #' @param correction Character. Which sphericity correction of the degrees of freedom should be reported for the within-subject factors. The default is given by \code{afex_options("correction_aov")}, which is initially set to \code{"GG"} corresponding to the Greenhouse-Geisser correction. Possible values are \code{"GG"}, \code{"HF"} (i.e., Hyunh-Feldt correction), and \code{"none"} (i.e., no correction). #' @param p_adjust_method \code{character} indicating if p-values for individual effects should be adjusted for multiple comparisons (see \link[stats]{p.adjust} and details). The default \code{NULL} corresponds to no adjustment. -#' @param sig_symbols Character. What should be the symbols designating significance? When entering an vector with \code{length(sig.symbol) < 4} only those elements of the default (\code{c(" +", " *", " **", " ***")}) will be replaced. \code{sig_symbols = ""} will display the stars but not the \code{+}, \code{sig_symbols = rep("", 4)} will display no symbols. +#' @param sig_symbols Character. What should be the symbols designating significance? When entering an vector with \code{length(sig.symbol) < 4} only those elements of the default (\code{c(" +", " *", " **", " ***")}) will be replaced. \code{sig_symbols = ""} will display the stars but not the \code{+}, \code{sig_symbols = rep("", 4)} will display no symbols. The default is given by \code{afex_options("sig_symbols")}. #' @param MSE logical. Should the column containing the Mean Sqaured Error (MSE) be displayed? Default is \code{TRUE}. #' @param intercept logical. Should intercept (if present) be included in the ANOVA table? Default is \code{FALSE} which hides the intercept. #' @param sig.symbols deprecated argument, only for backwards compatibility, use \code{"sig_symbols"} instead. @@ -140,7 +140,7 @@ is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) #' @rdname nice #' @method nice mixed #' @export -nice.mixed <- function(object, sig_symbols = c(" +", " *", " **", " ***"), ...) { +nice.mixed <- function(object, sig_symbols = afex_options("sig_symbols"), ...) { anova_table <- object$anova_table dots <- list(...) if("sig.symbols" %in% names(dots)) { #(!missing(sig.symbols)) { diff --git a/dev.R b/dev.R index 5aa22c5..ea8fd4a 100644 --- a/dev.R +++ b/dev.R @@ -36,7 +36,7 @@ R.libs <- "./packages/library" closeAllConnections() roxy.package( pck.source.dir = pkg.src.dir, - pck.version = "0.17-5", + pck.version = "0.17-6", pck.description = data.frame( Package = "afex", Type = "Package", @@ -52,7 +52,7 @@ roxy.package( person(given=\"Jonathan\", family=\"Love\", role=c(\"ctb\")) )", Depends = "R (>= 3.1.0), lme4 (>= 1.1-8), lsmeans (>= 2.17)", - Suggests = "ascii, xtable, parallel, plyr, optimx, nloptr, knitr, rmarkdown, lattice, latticeExtra, multcomp, testthat, mlmRev, dplyr, tidyr, dfoptim, Matrix", + Suggests = "xtable, parallel, plyr, optimx, nloptr, knitr, rmarkdown, lattice, latticeExtra, multcomp, testthat, mlmRev, dplyr, tidyr, dfoptim, Matrix", Imports = "stringr, coin, pbkrtest (>= 0.4-1), lmerTest, car, reshape2, stats, methods", Description = "Provides convenience functions for analyzing factorial experiments using ANOVA or mixed models. aov_ez(), aov_car(), and aov_4() allow specification of between, within (i.e., repeated-measures), or mixed between-within (i.e., split-plot) ANOVAs for data in long format (i.e., one observation per row), potentially aggregating multiple observations per individual and cell of the design. mixed() fits mixed models using lme4::lmer() and computes p-values for all fixed effects using either Kenward-Roger or Satterthwaite approximation for degrees of freedom (LMM only), parametric bootstrap (LMMs and GLMMs), or likelihood ratio tests (LMMs and GLMMs). afex uses type 3 sums of squares as default (imitating commercial statistical software).", URL = "http://afex.singmann.science/, https://github.com/singmann/afex", diff --git a/examples/examples.nice.R b/examples/examples.nice.R index be79af4..1b83728 100644 --- a/examples/examples.nice.R +++ b/examples/examples.nice.R @@ -4,7 +4,9 @@ data(md_12.1) # create object of class afex_aov: rmd <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise")) +rmd nice(rmd) +str(nice(rmd)) # use different es: nice(rmd, es = "pes") # noise: .82 nice(rmd, es = "ges") # noise: .39 @@ -23,7 +25,7 @@ tmp.aov <- aov_car(value ~ treatment * gender + Error(id/phase*hour), data = obk nice(tmp.aov, observed = "gender") -nice(tmp.aov, observed = "gender", sig.symbols = rep("", 4)) +nice(tmp.aov, observed = "gender", sig_symbols = rep("", 4)) \dontrun{ # use package ascii or xtable for formatting of tables ready for printing. diff --git a/man/afex-package.Rd b/man/afex-package.Rd index d538f12..07b6a61 100644 --- a/man/afex-package.Rd +++ b/man/afex-package.Rd @@ -11,8 +11,8 @@ Analysis of Factorial Experiments. \tabular{ll}{ Package: \tab afex\cr Type: \tab Package\cr -Version: \tab 0.17-5\cr -Date: \tab 2017-04-03\cr +Version: \tab 0.17-6\cr +Date: \tab 2017-04-06\cr Depends: \tab R (>= 3.1.0), lme4 (>= 1.1-8), lsmeans (>= 2.17)\cr Encoding: \tab UTF-8\cr License: \tab GPL (>=2)\cr diff --git a/man/afex_aov-methods.Rd b/man/afex_aov-methods.Rd index 6876d4d..a9ccb28 100644 --- a/man/afex_aov-methods.Rd +++ b/man/afex_aov-methods.Rd @@ -11,7 +11,8 @@ \usage{ \method{anova}{afex_aov}(object, es = afex_options("es_aov"), observed = NULL, correction = afex_options("correction_aov"), - MSE = TRUE, intercept = FALSE, p_adjust_method = NULL, ...) + MSE = TRUE, intercept = FALSE, p_adjust_method = NULL, + sig_symbols = afex_options("sig_symbols"), ...) \method{print}{afex_aov}(x, ...) @@ -36,6 +37,8 @@ \item{p_adjust_method}{\code{character} indicating if p-values for individual effects should be adjusted for multiple comparisons (see \link[stats]{p.adjust} and details).} +\item{sig_symbols}{Character. What should be the symbols designating significance? When entering an vector with \code{length(sig.symbol) < 4} only those elements of the default (\code{c(" +", " *", " **", " ***")}) will be replaced. \code{sig_symbols = ""} will display the stars but not the \code{+}, \code{sig_symbols = rep("", 4)} will display no symbols. The default is given by \code{afex_options("sig_symbols")}.} + \item{...}{further arguments passed through, see description of return value for details.} \item{trms, xlev, grid}{same as for \code{\link{lsm.basis}}.} @@ -57,5 +60,5 @@ Exploratory ANOVA, for which no detailed hypotheses have been specified a priori \code{p_adjust_method} defaults to the method specified in the call to \code{\link{aov_car}} in \code{anova_table}. If no method was specified and \code{p_adjust_method = NULL} p-values are not adjusted. } \references{ -Cramer, A. O. J., van Ravenzwaaij, D., Matzke, D., Steingroever, H., Wetzels, R., Grasman, R. P. P. P., ... Wagenmakers, E.-J. (2015). Hidden multiplicity in exploratory multiway ANOVA: Prevalence and remedies. \emph{Psychonomic Bulletin & Review}, 1–8. doi:\href{http://doi.org/10.3758/s13423-015-0913-5}{10.3758/s13423-015-0913-5} +Cramer, A. O. J., van Ravenzwaaij, D., Matzke, D., Steingroever, H., Wetzels, R., Grasman, R. P. P. P., ... Wagenmakers, E.-J. (2015). Hidden multiplicity in exploratory multiway ANOVA: Prevalence and remedies. \emph{Psychonomic Bulletin & Review}, 1-8. doi:\href{http://doi.org/10.3758/s13423-015-0913-5}{10.3758/s13423-015-0913-5} } diff --git a/man/afex_options.Rd b/man/afex_options.Rd index e6ffdba..05244b1 100644 --- a/man/afex_options.Rd +++ b/man/afex_options.Rd @@ -25,6 +25,7 @@ The following arguments are currently set: \item \code{es_aov}: Effect size reported for ANOVAs (see \code{\link{aov_car}}), default is \code{"ges"} (generalized eta-squared). \item \code{correction_aov}: Correction used for within-subjects factors with more than two levels for ANOVAs (see \code{\link{aov_car}} or \code{\link{nice}}), default is \code{"GG"} (Greenhouse-Geisser correction). (ANOVA functions only) \item \code{factorize}: Should between subject factors be factorized (with note) before running the analysis? Default is \code{TRUE}. (ANOVA functions only) +\item \code{sig_symbols}: Default significant symbols used for ANOVA and \code{mixed} printing. Default is\code{c(" +", " *", " **", " ***")}. \item \code{lmer_function}: Which \code{lmer} function should \code{mixed} or \code{lmer_alt} use. The default is \code{"lmerTest"} which uses \code{\link[lmerTest]{lmer}}, \code{"lme4"} is also possible which uses \code{\link[lme4]{lmer}}. There should be no difference between the two. The latter could be minimally faster, but does not allow to use \code{lmerTest::anova()}. } } diff --git a/man/nice.Rd b/man/nice.Rd index 4068102..73efdfa 100644 --- a/man/nice.Rd +++ b/man/nice.Rd @@ -15,12 +15,13 @@ nice(object, ...) observed = attr(object$anova_table, "observed"), correction = attr(object$anova_table, "correction"), MSE = NULL, intercept = NULL, p_adjust_method = attr(object$anova_table, - "p_adjust_method"), sig_symbols = c(" +", " *", " **", " ***"), ...) + "p_adjust_method"), sig_symbols = attr(object$anova_table, "sig_symbols"), + ...) \method{nice}{anova}(object, MSE = NULL, intercept = NULL, - sig_symbols = c(" +", " *", " **", " ***"), sig.symbols, ...) + sig_symbols = attr(object, "sig_symbols"), sig.symbols, ...) -\method{nice}{mixed}(object, sig_symbols = c(" +", " *", " **", " ***"), ...) +\method{nice}{mixed}(object, sig_symbols = afex_options("sig_symbols"), ...) \method{print}{nice_table}(x, ...) } @@ -41,7 +42,7 @@ nice(object, ...) \item{p_adjust_method}{\code{character} indicating if p-values for individual effects should be adjusted for multiple comparisons (see \link[stats]{p.adjust} and details). The default \code{NULL} corresponds to no adjustment.} -\item{sig_symbols}{Character. What should be the symbols designating significance? When entering an vector with \code{length(sig.symbol) < 4} only those elements of the default (\code{c(" +", " *", " **", " ***")}) will be replaced. \code{sig_symbols = ""} will display the stars but not the \code{+}, \code{sig_symbols = rep("", 4)} will display no symbols.} +\item{sig_symbols}{Character. What should be the symbols designating significance? When entering an vector with \code{length(sig.symbol) < 4} only those elements of the default (\code{c(" +", " *", " **", " ***")}) will be replaced. \code{sig_symbols = ""} will display the stars but not the \code{+}, \code{sig_symbols = rep("", 4)} will display no symbols. The default is given by \code{afex_options("sig_symbols")}.} \item{sig.symbols}{deprecated argument, only for backwards compatibility, use \code{"sig_symbols"} instead.} } @@ -70,7 +71,9 @@ Exploratory ANOVA, for which no detailed hypotheses have been specified a priori data(md_12.1) # create object of class afex_aov: rmd <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise")) +rmd nice(rmd) +str(nice(rmd)) # use different es: nice(rmd, es = "pes") # noise: .82 nice(rmd, es = "ges") # noise: .39 @@ -89,7 +92,7 @@ tmp.aov <- aov_car(value ~ treatment * gender + Error(id/phase*hour), data = obk nice(tmp.aov, observed = "gender") -nice(tmp.aov, observed = "gender", sig.symbols = rep("", 4)) +nice(tmp.aov, observed = "gender", sig_symbols = rep("", 4)) \dontrun{ # use package ascii or xtable for formatting of tables ready for printing.