f_glm | R Documentation |
glm()
functions with diagnostics, assumption checking, and post-hoc analysisPerforms Generalized Linear Model (GLM) analysis on a given dataset with options for diagnostics, assumption checking, and post-hoc analysis. Several response parameters can be analyzed in sequence and the generated output can be in various formats ('Word', 'pdf', 'Excel').
f_glm(
formula,
family = gaussian(),
data = NULL,
diagnostic_plots = TRUE,
alpha = 0.05,
adjust = "sidak",
type = "response",
show_assumptions_text = TRUE,
dispersion_test = TRUE,
output_type = "off",
output_file = NULL,
output_dir = NULL,
save_in_wdir = FALSE,
close_generated_files = FALSE,
open_generated_files = TRUE,
influence_threshold = 2,
...
)
formula |
A formula specifying the model to be fitted. More response variables can be
added using |
family |
The error distribution and link function to be used in the model (default: gaussian()).
This can be a character string naming a family function, a family function or
the result of a call to a family function. (See |
data |
A data frame containing the variables in the model. |
diagnostic_plots |
Logical. If |
alpha |
Numeric. Significance level for tests. Default is |
adjust |
Character string specifying the method used to adjust p-values for multiple comparisons. Available methods include:
Default is |
type |
specifying the scale on which the emmeans posthoc results are presented, e.g. "link" to show results on the scale for which the variables are linear and "response" when you want to back transform the data to interpret results in the units of your original data (e.g., probabilities, counts, or untransformed measurements). Default is |
show_assumptions_text |
Logical. If |
dispersion_test |
Logical for overdispersion test (default: TRUE). |
output_type |
Character string specifying the output format: |
output_file |
Character string specifying the name of the output file. Default is "dataname_glm_output". |
output_dir |
Character string specifying the name of the directory of the output file. Default is |
save_in_wdir |
Logical. If |
close_generated_files |
Logical. If |
open_generated_files |
Logical. If |
influence_threshold |
Leverage threshold (default: 2). |
... |
Additional arguments passed to |
The function first checks if all specified variables are present in the data and ensures that the response variable is numeric.
It performs Analysis of Variance (ANOVA) using the specified formula and data. If shapiro = TRUE
, it checks for normality of residuals using the Shapiro-Wilk test and optionally (transformation = TRUE
) applies a data transformation if residuals are not normal.
If significant differences are found in ANOVA, it proceeds 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_glm' containing results from glm()
, diagnostics, 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_glm' objects.
Sander H. van Delden plantmind@proton.me
# GLM Binomial example with output to console and MS Word file
mtcars_mod <- mtcars
mtcars_mod$cyl <- as.factor(mtcars_mod$cyl)
glm_bin <- f_glm(vs ~ cyl,
family = binomial,
data = mtcars_mod,
output_type = "word",
# Do not automatically open the 'Word' file (Default is to open the file)
open_generated_files = FALSE)
print(glm_bin)
# GLM Poisson example with output to rmd text
data(warpbreaks)
glm_pos <- f_glm(breaks ~ wool + tension,
data = warpbreaks,
family = poisson(link = "log"),
show_assumptions_text = FALSE,
output_type = "rmd")
cat(cat(glm_pos$rmd))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.