ANOVA: One-way and Two-way ANOVA

View source: R/ANOVA.R

ANOVAR Documentation

One-way and Two-way ANOVA

Description

Perform one-way or two-way ANOVA on variables of a data set. The output is printed as a LaTeX table that mimics the look of SPSS output, and a profile plot of the results mimics the look of SPSS graphs.

Usage

ANOVA(data, variable, group, conf.level = 0.95)

## S3 method for class 'ANOVA_SPSS'
to_SPSS(
  object,
  statistics = c("test", "variance", "descriptives"),
  version = r2spss_options$get("version"),
  digits = 3,
  ...
)

## S3 method for class 'ANOVA_SPSS'
print(
  x,
  statistics = c("descriptives", "variance", "test"),
  version = r2spss_options$get("version"),
  ...
)

## S3 method for class 'ANOVA_SPSS'
plot(x, y, which = 1, version = r2spss_options$get("version"), ...)

Arguments

data

a data frame containing the variables.

variable

a character string specifying the numeric variable of interest.

group

a character vector specifying one or two grouping variables.

conf.level

a number between 0 and 1 giving the confidence level of the confidence interval.

object, x

an object of class "ANOVA_SPSS" as returned by function ANOVA.

statistics

a character string or vector specifying which SPSS tables to produce. Available options are "descriptives" for descriptive statistics, "variance" for Levene's test on homogeneity of the variances, and "test" for ANOVA results. For the to_SPSS method, only one option is allowed (the default is the table of ANOVA results), but the print method allows several options (the default is to print all tables).

version

a character string specifying whether the table or plot should mimic the content and look of recent SPSS versions ("modern") or older versions (<24; "legacy"). For the table, the main differences in terms of content are that recent versions include different variations of Levene's test, and that small p-values are displayed differently.

digits

an integer giving the number of digits after the comma to be printed in the SPSS tables.

...

for the to_SPSS and print methods, additional arguments to be passed down to format_SPSS. For the plot method, additional arguments to be passed down to linesSPSS, in particular graphical parameters.

y

ignored (only included because it is defined for the generic function plot).

which

for two-way ANOVA, an integer with possible values 1 or 2 indicating whether the first or the second factor should be used on the x-axis. The other factor will then be used for drawing separate lines. For one-way ANOVA, this is not meaningful and ignored.

Details

The print method first calls the to_SPSS method followed by to_latex. Further customization can be done by calling those two functions separately, and modifying the object returned by to_SPSS.

Value

ANOVA returns an object of class "ANOVA_SPSS" with the following components:

descriptives

a data frame containing per-group descriptive statistics.

levene

an object as returned by leveneTest (if version = "legacy"); or a list of such objects containing different variations of Levene's test (if version = "modern").

test

a data frame containing the ANOVA table.

variable

a character string containing the name of the numeric variable of interest.

group

a character vector containing the name(s) of the grouping variable(s).

i

an integer giving the number of groups in the (first) grouping variable.

j

an integer giving the number of groups in the second grouping variable (only two-way ANOVA).

conf.level

numeric; the confidence level used.

type

a character string giving the type of ANOVA performed ("one-way" or "two-way").

The to_SPSS method returns an object of class "SPSS_table" which contains all relevant information in the required format to produce the LaTeX table. See to_latex for possible components and how to further customize the LaTeX table based on the returned object.

The print method produces a LaTeX table that mimics the look of SPSS output.

The plot method returns an object of class "ggplot", which produces a profile plot of the ANOVA results when printed.

Note

The test statistic and p-value for Levene's test based on the trimmed mean (only returned for version = "modern") differ slightly from those returned by SPSS. Function trimmed_mean rounds the number of observations to be trimmed in a different manner than the base R function mean, which brings the results closer to those of SPSS, but they are still not identical.

LaTeX tables that mimic recent versions of SPSS (version = "modern") may require several LaTeX compilations to be displayed correctly.

Author(s)

Andreas Alfons

Examples

# load data
data("Eredivisie")
# log-transform market values
Eredivisie$logMarketValue <- log(Eredivisie$MarketValue)

# one-way ANOVA
oneway <- ANOVA(Eredivisie, "logMarketValue",
                group = "Position")
oneway        # print LaTeX table
plot(oneway)  # create profile plot

# two-way ANOVA
twoway <- ANOVA(Eredivisie, "logMarketValue",
                group = c("Position", "Foreign"))
twoway        # print LaTeX table
plot(twoway)  # create profile plot


r2spss documentation built on May 25, 2022, 5:05 p.m.