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 ANOVA_SPSS
to_SPSS(
object,
statistics = c("test", "variance", "descriptives"),
version = r2spss_options$get("version"),
digits = 3,
...
)
# S3 method for ANOVA_SPSS
print(
x,
statistics = c("descriptives", "variance", "test"),
version = r2spss_options$get("version"),
...
)
# S3 method for ANOVA_SPSS
plot(x, y, which = 1, version = r2spss_options$get("version"), ...)
a data frame containing the variables.
a character string specifying the numeric variable of interest.
a character vector specifying one or two grouping variables.
a number between 0 and 1 giving the confidence level of the confidence interval.
an object of class "ANOVA_SPSS"
as returned by
function ANOVA
.
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).
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.
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.
ignored (only included because it is defined for the generic
function plot
).
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.
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 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
.
# NOT RUN {
# 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
# }
Run the code above in your browser using DataLab