R/oneway.R

Defines functions oneway

Documented in oneway

#' @title One Way Analysis of Variance
#' @description \code{oneway} computes a one-way analysis of variance and includes
#' group level summary statistics
#' @param formula an object of class formula, relation the dependent variable
#' to the grouping variable
#' @param data a data frame containing the variables in the model
#' @return a list with 2 elements
#' \item{oneway}{a list with the lm results}
#' \item{summarystats}{a data frame with the summary statistics}
#' @details
#' This function computes a standard one-way ANOVA, means, and standard
#' deviations. Missing values are handled listwise deletion
#' @examples
#' mileage <- oneway(hwy ~ class, cars)
#'  summary(mileage)
#'  print(mileage)
#'  plot(mileage)
#'
#' @rdname oneway
#' @export

oneway <- function(formula, data) {

  # listwise deletion of missing values
  data_complete <- na.omit(data)

  # anova
  fit <- lm(formula, data_complete)

  stats <-  aggregate(formula,
                      data,
                      function(x) c(n = length(x), mean = mean(x), sd = sd(x)))


  result <- list(anova = fit, summarystats = stats)
  class(result) <- c("oneway", "list")
  return(result)

}






#### TODO
# 1. coerce response variable to a factor
# 2. improve print function (e.g. leve out call and residuals. give better formatting)
# 3. make the plot use ggplot2 for continued editing
# 4. give plot options (e.g. boxplot, density plot, mean/se plot)
# 5. add sorting option for plot (low-high or reversed)
# 6. add better default labels and titles for plot
# 7. add mean line for plot
# 8. have summary function provide results as a paragraph in APA format
# 9. add pairwise comparisons function or option with adjusted p values
# 10. add a assumputions function to test statistical assumptions (e.g. normality, homoscedasticity)
# 11. add a robust option for non normal data or data with outliers
# 12. add attractive Rmarkdown output option?
# 13. what else?
fredcorpuz06/onewayAnova documentation built on Nov. 4, 2019, 12:57 p.m.