ANOVA | R Documentation |
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.
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"), ...)
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 |
statistics |
a character string or vector specifying which SPSS tables
to produce. Available options are |
version |
a character string specifying whether the table or plot
should mimic the content and look of recent SPSS versions ( |
digits |
an integer giving the number of digits after the comma to be printed in the SPSS tables. |
... |
for the |
y |
ignored (only included because it is defined for the generic
function |
which |
for two-way ANOVA, an integer with possible values |
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
.
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.
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.
Andreas Alfons
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.