Type: | Package |
Title: | Extra Functionality for (Robust) Mediation Analysis |
Version: | 0.1.1 |
Date: | 2024-11-03 |
Depends: | robmed (≥ 0.10.0) |
Imports: | shiny (≥ 1.1.0), DT, flextable (≥ 0.8.3), ggplot2 (≥ 3.3.0), graphics, grDevices, officer, stats, utils |
Description: | This companion package extends the package 'robmed' (Alfons, Ates & Groenen, 2022b; <doi:10.18637/jss.v103.i13>) in various ways. Most notably, it provides a graphical user interface for the robust bootstrap test ROBMED (Alfons, Ates & Groenen, 2022a; <doi:10.1177/1094428121999096>) to make the method more accessible to less proficient 'R' users, as well as functions to export the results as a table in a 'Microsoft Word' or 'Microsoft Powerpoint' document, or as a 'LaTeX' table. Furthermore, the package contains a 'shiny' app to compare various bootstrap procedures for mediation analysis on simulated data. |
License: | GPL (≥ 3) |
URL: | https://github.com/aalfons/robmedExtra |
BugReports: | https://github.com/aalfons/robmedExtra/issues |
Author: | Andreas Alfons |
Maintainer: | Andreas Alfons <alfons@ese.eur.nl> |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2024-11-03 10:53:50 UTC; alfons |
Repository: | CRAN |
Date/Publication: | 2024-11-03 12:10:01 UTC |
Extra Functionality for (Robust) Mediation Analysis
Description
This companion package extends the package 'robmed' (Alfons, Ates & Groenen, 2022b; <doi:10.18637/jss.v103.i13>) in various ways. Most notably, it provides a graphical user interface for the robust bootstrap test ROBMED (Alfons, Ates & Groenen, 2022a; <doi:10.1177/1094428121999096>) to make the method more accessible to less proficient 'R' users, as well as functions to export the results as a table in a 'Microsoft Word' or 'Microsoft Powerpoint' document, or as a 'LaTeX' table. Furthermore, the package contains a 'shiny' app to compare various bootstrap procedures for mediation analysis on simulated data.
Details
The DESCRIPTION file:
Package: | robmedExtra |
Type: | Package |
Title: | Extra Functionality for (Robust) Mediation Analysis |
Version: | 0.1.1 |
Date: | 2024-11-03 |
Depends: | robmed (>= 0.10.0) |
Imports: | shiny (>= 1.1.0), DT, flextable (>= 0.8.3), ggplot2 (>= 3.3.0), graphics, grDevices, officer, stats, utils |
Description: | This companion package extends the package 'robmed' (Alfons, Ates & Groenen, 2022b; <doi:10.18637/jss.v103.i13>) in various ways. Most notably, it provides a graphical user interface for the robust bootstrap test ROBMED (Alfons, Ates & Groenen, 2022a; <doi:10.1177/1094428121999096>) to make the method more accessible to less proficient 'R' users, as well as functions to export the results as a table in a 'Microsoft Word' or 'Microsoft Powerpoint' document, or as a 'LaTeX' table. Furthermore, the package contains a 'shiny' app to compare various bootstrap procedures for mediation analysis on simulated data. |
License: | GPL (>= 3) |
URL: | https://github.com/aalfons/robmedExtra |
BugReports: | https://github.com/aalfons/robmedExtra/issues |
LazyData: | yes |
Authors@R: | c(person("Andreas", "Alfons", email = "alfons@ese.eur.nl", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2513-3788")), person("Aurore", "Archimbaud", email = "archimbaud@ese.eur.nl", role = "aut", comment = c(ORCID = "0000-0002-6511-9091")), person("Vincent", "Drenth", role = "ctb", comment = "initial prototype of GUI")) |
Author: | Andreas Alfons [aut, cre] (<https://orcid.org/0000-0002-2513-3788>), Aurore Archimbaud [aut] (<https://orcid.org/0000-0002-6511-9091>), Vincent Drenth [ctb] (initial prototype of GUI) |
Maintainer: | Andreas Alfons <alfons@ese.eur.nl> |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Index of help topics:
export_docx Export a flextable of results from (robust) mediation analysis to 'Microsoft Word' export_pptx Export a flextable of results from (robust) mediation analysis to 'Microsoft Powerpoint' robmedExtra-package Extra Functionality for (Robust) Mediation Analysis robmed_GUI Graphical user interface for (robust) mediation analysis simulation_app Open a 'shiny' app for exploring mediation analysis on simulated data theme_mediation Theme for formatting a flextable of results from (robust) mediation analysis to_flextable Tabular summary of results from (robust) mediation analysis to_latex 'LaTeX' table of results from (robust) mediation analysis
Author(s)
Andreas Alfons [aut, cre] (<https://orcid.org/0000-0002-2513-3788>), Aurore Archimbaud [aut] (<https://orcid.org/0000-0002-6511-9091>), Vincent Drenth [ctb] (initial prototype of GUI)
Maintainer: Andreas Alfons <alfons@ese.eur.nl>
References
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022a) A Robust Bootstrap Test for Mediation Analysis. Organizational Research Methods, 25(3), 591–617. doi:10.1177/1094428121999096.
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022b) Robust mediation analysis: The R package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.
See Also
Useful links:
Export a flextable of results from (robust) mediation analysis to 'Microsoft Word'
Description
Export a flextable
object to Microsoft
Word. This function is intended for tables of results from (robust)
mediation analysis. It is essentially a wrapper for
save_as_docx()
with a more convenient argument
for page size, and it uses additional information from subclass
"mediation_flextable"
to determine the page
orientation.
Usage
export_docx(object, file, ...)
## S3 method for class 'flextable'
export_docx(object, file, size = c("A4", "letter"), ...)
## Default S3 method:
export_docx(object, file, ...)
Arguments
object |
an object of class |
file |
a character string specifying the path an file name for the Microsoft Word file to be generated. |
... |
for the |
size |
a character string specifying the page size. Possible values
are |
Value
The function is called for its side effect of creating a Microsoft Word file. It returns the path to the file invisibly.
Author(s)
Andreas Alfons
See Also
flextable()
, to_flextable()
Examples
data("BSG2014")
# perform mediation analysis via robust bootstrap test ROBMED
set.seed(20241101)
boot <- test_mediation(BSG2014,
x = "SharedLeadership",
y = "TeamPerformance",
m = c("ProceduralJustice",
"InteractionalJustice"),
covariates = c("AgeDiversity",
"GenderDiversity"))
# construct flextable of results
ft <- to_flextable(boot)
# export to Microsoft Word
file_name <- tempfile(fileext = ".docx")
export_docx(ft, file = file_name)
Export a flextable of results from (robust) mediation analysis to 'Microsoft Powerpoint'
Description
Export a flextable
object to Microsoft
Powerpoint. This function is intended for tables of results from (robust)
mediation analysis. It is essentially a wrapper for
save_as_pptx()
.
Usage
export_pptx(object, file, ...)
## S3 method for class 'flextable'
export_pptx(object, file, ...)
## Default S3 method:
export_pptx(object, file, ...)
Arguments
object |
an object of class |
file |
a character string specifying the path an file name for the Microsoft Powerpoint file to be generated. |
... |
for the |
Value
The function is called for its side effect of creating a Microsoft Powerpoint file. It returns the path to the file invisibly.
Author(s)
Andreas Alfons
See Also
flextable()
, to_flextable()
Examples
data("BSG2014")
# perform mediation analysis via robust bootstrap test ROBMED
set.seed(20241101)
boot <- test_mediation(BSG2014,
x = "SharedLeadership",
y = "TeamPerformance",
m = c("ProceduralJustice",
"InteractionalJustice"),
covariates = c("AgeDiversity",
"GenderDiversity"))
# construct flextable of results
ft <- to_flextable(boot)
# export to Microsoft Powerpoint
file_name <- tempfile(fileext = ".pptx")
export_pptx(ft, file = file_name)
Graphical user interface for (robust) mediation analysis
Description
Open a shiny app that provides a graphical user interface for (robust) mediation analysis via package robmed.
Usage
robmed_GUI(data = NULL)
Arguments
data |
optional; a data frame to be selected by default in the graphical user interface. Note that if the supplied object is not a data frame or does not exist in the global environment, the graphical user interface is opened as if the argument were not supplied. |
Details
The graphical user interface allows to select or import a data set, to perform the robust bootstrap test ROBMED (Alfons et al., 2022a) or the OLS bootstrap test (e.g., Preacher & Hayes, 2004, 2008), and to easily export results for reporting (including a replication file in the form of an R script).
Value
No return value, the function is called for its side effect of starting a shiny app.
Note
The graphical user interface is still experimental. It may change in future versions based on user feedback.
Author(s)
Andreas Alfons and Aurore Archimbaud, based on an initial prototype by Vincent Drenth.
References
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022a) A Robust Bootstrap Test for Mediation Analysis. Organizational Research Methods, 25(3), 591–617. doi:10.1177/1094428121999096.
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022b) Robust Mediation Analysis: The R Package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.
Preacher, K.J. and Hayes, A.F. (2004) SPSS and SAS Procedures for Estimating Indirect Effects in Simple Mediation Models. Behavior Research Methods, Instruments, & Computers, 36(4), 717–731. doi:10.3758/bf03206553.
Preacher, K.J. and Hayes, A.F. (2008) Asymptotic and Resampling Strategies for Assessing and Comparing Indirect Effects in Multiple Mediator Models. Behavior Research Methods, 40(3), 879–891. doi:10.3758/brm.40.3.879.
See Also
Examples
# run example only from an interactive R session
if (interactive()) {
# start graphical user interface
robmed_GUI()
}
Open a 'shiny' app for exploring mediation analysis on simulated data
Description
Open a shiny app for exploring the behavior of various bootstrap procedures for mediation analysis on simulated data.
Usage
simulation_app()
Details
The default settings are similar to one of the simulation designs of Alfons, Ates & Groenen (2022a). You can adjust the total number of observations, the values of the coefficients in the (simple) mediation model, the number of outliers, as well as outlier scaling factors and shifts in the individual variables.
For each selected method, the bootstrap distribution of the indirect effect is shown together with a shaded area representing the 95% confidence interval. If the app does not update quickly enough, try to reduce the number of bootstrap samples.
Value
No return value, the function is called for its side effect of starting a shiny app.
Author(s)
Andreas Alfons
References
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022a) A Robust Bootstrap Test for Mediation Analysis. Organizational Research Methods, 25(3), 591–617. doi:10.1177/1094428121999096.
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022b) Robust Mediation Analysis: The R Package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.
Preacher, K.J. and Hayes, A.F. (2004) SPSS and SAS Procedures for Estimating Indirect Effects in Simple Mediation Models. Behavior Research Methods, Instruments, & Computers, 36(4), 717–731. doi:10.3758/bf03206553.
Preacher, K.J. and Hayes, A.F. (2008) Asymptotic and Resampling Strategies for Assessing and Comparing Indirect Effects in Multiple Mediator Models. Behavior Research Methods, 40(3), 879–891. doi:10.3758/brm.40.3.879.
Yuan, Y. and MacKinnon, D.P. (2014) Robust Mediation Analysis Based on Median Regression. Psychological Methods, 19(1), 1–20. doi:10.1037/a0033820.
Zu, J. and Yuan, K.-H. (2010) Local Influence and Robust Procedures for Mediation Analysis. Multivariate Behavioral Research, 45(1), 1–44. doi:10.1080/00273170903504695.
See Also
Examples
# run example only from an interactive R session
if (interactive()) {
# start graphical user interface
simulation_app()
}
Theme for formatting a flextable of results from (robust) mediation analysis
Description
Apply a theme to a flextable
intended to format
results from (robust) mediation analysis. The theme uses additional
information from subclass "mediation_flextable"
,
and it formats the table according to APA style.
Usage
theme_mediation(x, ...)
Arguments
x |
an object of class |
... |
additional arguments are currently ignored. |
Details
Theme functions for flextable
s are not like
ggplot2 themes, as they are applied to the existing table immediately.
For example, if you add a row in the footer after setting the theme, the new
row is not formatted with the theme. The theme is applied only to existing
elements when the function is called.
That is, if you modify the table returned by to_flextable()
,
it may be necessary to apply the theme function again after all elements of
the table have been added (e.g., additional header or footer rows).
Value
An object inheriting from class "flextable"
.
Author(s)
Andreas Alfons
See Also
flextable()
, to_flextable()
Examples
data("BSG2014")
# perform mediation analysis via robust bootstrap test ROBMED
set.seed(20150601)
boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict")
# construct flextable of results
ft <- to_flextable(boot)
# add additional row to the footer
footer_line <- flextable::as_paragraph(
"Depending on the seed of the random number generator, the ",
flextable::as_i("p"), " value of the indirect effect may ",
"fall below or above the arbitrary 5% threshold."
)
ft <- flextable::add_footer_lines(ft, values = footer_line)
ft <- theme_mediation(ft)
ft
Tabular summary of results from (robust) mediation analysis
Description
Convert results from (robust) mediation analysis to a tabular summary in
the form of a flextable
. This flextable
can easily be exported to Microsoft Word or Microsoft
Powerpoint, or integrated into a dynamic Markdown document.
This eliminates the risk of mistakes in reporting that stem from
copying-and-pasting results.
Usage
to_flextable(object, ...)
## S3 method for class 'test_mediation'
to_flextable(object, type = c("boot", "data"), ...)
## S3 method for class 'summary_test_mediation'
to_flextable(object, p_value = TRUE, ...)
## S3 method for class 'list'
to_flextable(
object,
type = c("boot", "data"),
p_value = TRUE,
orientation = c("landscape", "portrait"),
...
)
Arguments
object |
an object inheriting from class
|
... |
additional arguments to be passed down, eventually to
|
type |
a character string specifying which estimates and significance
tests to report if mediation analysis was done via a bootstrap procedure.
If |
p_value |
a logical indicating whether to include p-values for the
indirect effects if mediation analysis was done via a bootstrap procedure.
If |
orientation |
a character string specifying how to arrange the results
from different objects (list elements) in the |
Value
An object of class "mediation_flextable"
, which inherits
from class "flextable"
.
Note
Numbers are not formatted via flextable
defaults (see
set_flextable_defaults()
), but instead via
formatC()
. This is done to ensure consistency in
number formatting between functions to_flextable()
and
to_latex()
.
Author(s)
Andreas Alfons, based on code by Vincent Drenth
References
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022a) A Robust Bootstrap Test for Mediation Analysis. Organizational Research Methods, 25(3), 591–617. doi:10.1177/1094428121999096.
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022b) Robust Mediation Analysis: The R Package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.
See Also
test_mediation()
,
summary()
export_docx()
, export_pptx()
to_latex()
Examples
data("BSG2014")
# seed to be used for the random number generator
seed <- 20150601
# perform mediation analysis via robust bootstrap test ROBMED
set.seed(seed)
robust_boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict",
robust = TRUE)
# note that depending on the seed of the random number
# generator, the p value of the indirect effect may fall
# below or above the arbitrary 5% threshold
# construct flextable of results
to_flextable(robust_boot)
# perform mediation analysis via the OLS bootstrap
set.seed(seed)
ols_boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict",
robust = FALSE)
# construct flextable of results from both procedures
boot_list <- list(ols_boot, robust_boot)
to_flextable(boot_list)
# customize labels for procedures and number of digits
boot_list_named <- list("Non-robust" = ols_boot,
"Robust" = robust_boot)
to_flextable(boot_list_named, digits = 4)
'LaTeX' table of results from (robust) mediation analysis
Description
Generate LaTeX code for a tabular summary of results from
(robust) mediation analysis in the form of a tabular
environment.
This tabular
environment can easily be integrated into a dynamic
LaTeX document with tools such as package knitr, which
eliminates the risk of mistakes in reporting that stem from
copying-and-pasting results. Note that to_latex()
itself does not
actually produce any LaTeX code, it is the print()
method
of the resulting object that prints the code for the tabular
environment.
Usage
to_latex(object, ...)
## S3 method for class 'test_mediation'
to_latex(object, type = c("boot", "data"), ...)
## S3 method for class 'summary_test_mediation'
to_latex(object, p_value = TRUE, align = c("lrrrr", "c"), ...)
## S3 method for class 'list'
to_latex(
object,
type = c("boot", "data"),
p_value = TRUE,
orientation = c("landscape", "portrait"),
align = NULL,
...
)
Arguments
object |
an object inheriting from class
|
... |
additional arguments to be passed down, eventually to
|
type |
a character string specifying which estimates and significance
tests to report if mediation analysis was done via a bootstrap procedure.
If |
p_value |
a logical indicating whether to include p-values for the
indirect effects if mediation analysis was done via a bootstrap procedure.
If |
align |
a character vector of length two. The first element is used
as the alignment specification in the |
orientation |
a character string specifying how to arrange the results
from different objects (list elements) in the LaTeX table. If
|
Value
An object of class "mediation_latex_tables"
with the following
components:
labels |
a character string giving the labels to be used in the LaTeX table (only returned if a list of objects is supplied). |
total |
a data frame containing a tabular summary of the total effects, or a list of such data frames. |
direct |
a data frame containing a tabular summary of the direct effects, or a list of such data frames. |
indirect |
a data frame containing a tabular summary of the indirect effects, or a list of such data frames. |
x , m , y , covariates |
character vectors specifying the respective variables used. |
n |
a character string containing the (formatted) sample size. |
R |
a character string containing the (formatted) number of bootstrap samples (only returned if applicable). |
orientation |
a character string specifying how to arrange the results from different objects in the LaTeX table (only returned if a list of objects is supplied). |
align |
a character vector of length two. The first element gives the
alignment specification to be used in the |
Note
The print()
method for class "mediation_latex_tables"
prints
the LaTeX code for the tabular
environment. It ignores
any additional arguments, and it returns the supplied object invisibly.
Author(s)
Andreas Alfons
References
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022a) A Robust Bootstrap Test for Mediation Analysis. Organizational Research Methods, 25(3), 591–617. doi:10.1177/1094428121999096.
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022b) Robust Mediation Analysis: The R Package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.
See Also
test_mediation()
,
summary()
Examples
data("BSG2014")
# seed to be used for the random number generator
seed <- 20150601
# perform mediation analysis via robust bootstrap test ROBMED
set.seed(seed)
robust_boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict",
robust = TRUE)
# note that depending on the seed of the random number
# generator, the p value of the indirect effect may fall
# below or above the arbitrary 5% threshold
# construct LaTeX table of results
to_latex(robust_boot)
# perform mediation analysis via the OLS bootstrap
set.seed(seed)
ols_boot <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict",
robust = FALSE)
# construct LaTeX table of results from both procedures
boot_list <- list(ols_boot, robust_boot)
to_latex(boot_list)
# customize labels for procedures and number of digits
boot_list_named <- list("Non-robust" = ols_boot,
"Robust" = robust_boot)
to_latex(boot_list_named, digits = 4)