Package 'robmedExtra'

Title: 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.
Authors: Andreas Alfons [aut, cre] , Aurore Archimbaud [aut] , Vincent Drenth [ctb] (initial prototype of GUI)
Maintainer: Andreas Alfons <[email protected]>
License: GPL (>= 3)
Version: 0.1.1
Built: 2025-02-01 05:29:22 UTC
Source: https://github.com/aalfons/robmedextra

Help Index


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 = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2513-3788")), person("Aurore", "Archimbaud", email = "[email protected]", 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 <[email protected]>
Encoding: UTF-8
RoxygenNote: 7.3.2
Config/pak/sysreqs: libcairo2-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev make libharfbuzz-dev libicu-dev libjpeg-dev libpng-dev libtiff-dev libxml2-dev libssl-dev zlib1g-dev
Repository: https://aalfons.r-universe.dev
RemoteUrl: https://github.com/aalfons/robmedextra
RemoteRef: HEAD
RemoteSha: 31ac239b5c59a17d9f56e48f1ee192b8944e6897

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 <[email protected]>

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 "flextable", or an object containing results from (robust) mediation analysis that can be converted to the subclass "mediation_flextable" via to_flextable().

file

a character string specifying the path an file name for the Microsoft Word file to be generated.

...

for the "flextable" method, additional arguments to be passed down to prop_section() for defining page composition such as page size, page orientation, and margins. For the default method, additional arguments to be passed down to to_flextable() for converting results from (robust) mediation analysis.

size

a character string specifying the page size. Possible values are "A4" for A4 format (297 x 210 mm) or "letter" for US letter format (11 x 8.5 inches).

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

export_pptx()

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 "flextable", or an object containing results from (robust) mediation analysis that can be converted to the subclass "mediation_flextable" via to_flextable().

file

a character string specifying the path an file name for the Microsoft Powerpoint file to be generated.

...

for the "flextable" method, additional arguments to be passed down to prop_section() for defining page composition such as page size, page orientation, and margins. For the default method, additional arguments to be passed down to to_flextable() for converting results from (robust) mediation analysis.

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

export_docx()

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

test_mediation

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

test_mediation

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 "flextable". It is recommend to use this theme only for objects of subclass "mediation_flextable", as returned by to_flextable().

...

additional arguments are currently ignored.

Details

Theme functions for flextables 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 "test_mediation" or "summary_test_mediation" containing results from (robust) mediation analysis, or a list of such objects (typically obtained via different procedures for mediation analysis). In case of a named list, the supplied names are used as labels in the resulting flextable, otherwise default labels are constructed based on how the mediation model was fitted and which type of test was used (e.g., "ROBMED" or "OLS Bootstrap").

...

additional arguments to be passed down, eventually to formatC() for formatting numbers. In particular, argument digits can be used to customize the number of digits after the decimal point (defaults to 3). Also note that argument big.mark is ignored for the numbers in the table; it is only used for formatting the sample size and (if applicable) the number of bootstrap samples in the table note.

type

a character string specifying which estimates and significance tests to report if mediation analysis was done via a bootstrap procedure. If "boot" (the default), the means of the bootstrap replicates are reported as point estimates for all effects, and significance tests for the total and direct effects use the normal approximation of the bootstrap distribution (i.e., the tests assume a normal distribution of the corresponding effect with the standard deviation computed from the bootstrap replicates). If "data", the point estimates on the original data are reported for all effects, and the significance tests for the total and direct effects are based on statistical theory (e.g., t-tests if the coefficients are estimated via regression). Note that for bootstrap procedures, significance of the indirect effect is always reported via a percentile-based confidence interval due to the asymmetry of its distribution.

p_value

a logical indicating whether to include p-values for the indirect effects if mediation analysis was done via a bootstrap procedure. If TRUE (the default), the p-values are obtained via p_value().

orientation

a character string specifying how to arrange the results from different objects (list elements) in the flextable. If "landscape" (the default), results from two objects are arranged next to each other with the results from remaining objects underneath (in groups of two), which is intended for documents in landscape mode. If "portrait", results from different objects are arranged underneath one another, which is intended for documents in portrait mode.

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 "test_mediation" or "summary_test_mediation" containing results from (robust) mediation analysis, or a list of such objects (typically obtained via different procedures for mediation analysis). In case of a named list, the supplied names are used as labels in the resulting LaTeX table, otherwise default labels are constructed based on how the mediation model was fitted and which type of test was used (e.g., "ROBMED" or "OLS Bootstrap").

...

additional arguments to be passed down, eventually to formatC() for formatting numbers. In particular, argument digits can be used to customize the number of digits after the decimal point (defaults to 3). Also note that argument big.mark is ignored for the numbers in the table; it is only used for formatting the sample size and (if applicable) the number of bootstrap samples in the table note.

type

a character string specifying which estimates and significance tests to report if mediation analysis was done via a bootstrap procedure. If "boot" (the default), the means of the bootstrap replicates are reported as point estimates for all effects, and significance tests for the total and direct effects use the normal approximation of the bootstrap distribution (i.e., the tests assume a normal distribution of the corresponding effect with the standard deviation computed from the bootstrap replicates). If "data", the point estimates on the original data are reported for all effects, and the significance tests for the total and direct effects are based on statistical theory (e.g., t-tests if the coefficients are estimated via regression). Note that for bootstrap procedures, significance of the indirect effect is always reported via a percentile-based confidence interval due to the asymmetry of its distribution.

p_value

a logical indicating whether to include p-values for the indirect effects if mediation analysis was done via a bootstrap procedure. If TRUE (the default), the p-values are obtained via p_value().

align

a character vector of length two. The first element is used as the alignment specification in the \begin{tabular}{} statement, while the second element is used for the alignment specification in \multicolumn{}{}{} statements in case of bootstrapped confidence intervals of the indirect effect. For the former, note that if object is a list of objects and orientation is "landscape", two empty columns are inserted in the LaTeX table. It is not recommended to set this argument unless you know what you are doing.

orientation

a character string specifying how to arrange the results from different objects (list elements) in the LaTeX table. If "landscape" (the default), results from two objects are arranged next to each other with the results from remaining objects underneath (in groups of two), which is intended for documents in landscape mode (or LaTeX table environments such as sidewaystable). If "portrait", results from different objects are arranged underneath one another, which is intended for documents in portrait mode.

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 \begin{tabular}{} statement, while the second element gives the alignment specification to be used in \multicolumn{}{}{} statements for any bootstrapped confidence intervals of the indirect effect.

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()

to_flextable()

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)