f_aov | R Documentation |
aov()
functions with optional data transformation, inspection and Post Hoc test.Performs an Analysis of Variance (ANOVA) on a given dataset with options for (Box-Cox) transformations, normality tests, and post-hoc analysis. Several response parameters can be analysed in sequence and the generated output can be in various formats ('Word', 'pdf', 'Excel').
f_aov(
formula,
data = NULL,
norm_plots = TRUE,
ANCOVA = FALSE,
transformation = TRUE,
alpha = 0.05,
adjust = "sidak",
aov_assumptions_text = TRUE,
close_generated_files = FALSE,
open_generated_files = TRUE,
output_type = "off",
output_file = NULL,
output_dir = NULL,
save_in_wdir = FALSE
)
formula |
A formula specifying the model to be fitted. More response variables can be added using |
data |
A data frame containing the variables in the model. |
norm_plots |
Logical. If |
ANCOVA |
Logical. If |
transformation |
Logical or character string. If |
alpha |
Numeric. Significance level for ANOVA, post hoc tests, and Shapiro-Wilk test. Default is |
adjust |
Character string specifying the method used to adjust p-values for multiple comparisons. Available methods include:
Default is |
aov_assumptions_text |
Logical. If |
close_generated_files |
Logical. If |
open_generated_files |
Logical. If |
output_type |
Character string specifying the output format: |
output_file |
Character string specifying the name of the output file. Default is "dataname_aov_output". |
output_dir |
Character string specifying the name of the directory of the output file. Default is |
save_in_wdir |
Logical. If |
The function performs the following steps:
Check if all specified variables are present in the data.
Ensure that the response variable is numeric.
Perform Analysis of Variance (ANOVA) using the specified formula and data.
If shapiro = TRUE
, check for normality of residuals using the Shapiro-Wilk test.
If residuals are not normal and transformation = TRUE
apply a data transformation.
If significant differences are found in ANOVA, proceed with post hoc tests using estimated marginal means from emmeans()
and Sidak adjustment (or another option of adjust =
.
More response variables can be added using -
or +
(e.g., response1 + response2 ~ predictor
) to do a sequential aov()
for each response parameter captured in one output file.
Outputs can be generated in multiple formats ("pdf", "word", "excel" and "rmd") as specified by output_type
. The function also closes any open 'Word' files to avoid conflicts when generating 'Word' documents. If output_type = "rmd"
is used it is adviced to use it in a chunk with {r, echo=FALSE, results='asis'}
This function requires [Pandoc](https://github.com/jgm/pandoc/releases/tag) (version 1.12.3 or higher), a universal document converter.
Windows: Install Pandoc and ensure the installation folder.
(e.g., "C:/Users/your_username/AppData/Local/Pandoc") is added to your system PATH.
macOS: If using Homebrew, Pandoc is typically installed in "/usr/local/bin". Alternatively, download the .pkg installer and verify that the binary’s location is in your PATH.
Linux: Install Pandoc through your distribution’s package manager (commonly installed in "/usr/bin" or "/usr/local/bin") or manually, and ensure the directory containing Pandoc is in your PATH.
If Pandoc is not found, this function may not work as intended.
An object of class 'f_aov' containing results from aov()
, normality tests, transformations, and post hoc tests. Using the option "output_type", it can also generate output in the form of: R Markdown code, 'Word', 'pdf', or 'Excel' files. Includes print and plot methods for 'f_aov' objects.
Sander H. van Delden plantmind@proton.me
# Make a factor of Species.
iris$Species <- factor(iris$Species)
# The left hand side contains two response variables,
# so two aov's will be conducted, i.e. "Sepal.Width"
# and "Sepal.Length" in response to the explanatory variable: "Species".
f_aov_out <- f_aov(Sepal.Width + Sepal.Length ~ Species,
data = iris,
# Save output in MS Word file (Default is console)
output_type = "word",
# Do boxcox transformation for non-normal residual (Default is bestnormalize)
transformation = "boxcox",
# Do not automatically open the file.
open_generated_files = FALSE
)
# Print output to the console.
print(f_aov_out)
# Plot residual plots.
plot(f_aov_out)
#To print rmd output set chunck option to results = 'asis' and use cat().
f_aov_rmd_out <- f_aov(Sepal.Width ~ Species, data = iris, output_type = "rmd")
cat(f_aov_rmd_out$rmd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.