manymome.table

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = ""
)

Introduction

This article is a brief illustration of how convert some results from the package manymome (Cheung & Cheung, 2023) to publication-ready tables using the functions from manymome.table. It assumes readers have used manymome. This guide will focus on converting the results using the as_flextable() method.

Several Indirect Effects

The example from this article will be used, with some modifications.

This is the sample data set from manymome:

library(manymome)
dat <- data_serial
print(head(dat), digits = 3)

Th following model is fitted in lavaan:

library(lavaan)
mod_med <- "
m1 ~ x
m2 ~ m1 + x
y ~ m2 + m1 + x
"
fit_med <- sem(model = mod_med,
               data = dat,
               fixed.x = TRUE)

Use all_indirect_paths() to identify all indirect paths:

all_paths <- all_indirect_paths(fit = fit_med,
                                x = "x",
                                y = "y")
all_paths

Estimate the indirect effects, with bootstrap confidence intervals.

# R set to 100 just for illustration.
# Use 5000 or 10000 and set parallel to TRUE in real research.
out_all <- many_indirect_effects(paths = all_paths,
                                 fit = fit_med,
                                 standardized_x = TRUE,
                                 standardized_y = TRUE,
                                 boot_ci = TRUE,
                                 R = 100,
                                 seed = 12345,
                                 parallel = FALSE,
                                 progress = FALSE)
out_all

The method as_flextable() can then be used to convert the output to a flextable. To use this method, we need to load the package manymome.table first.

library(manymome.table)
ft_all <- as_flextable(out_all)
ft_all

By default, if standardized effects are requested, the unstandardized effects will also be printed when converting to a flextable.

Not demonstrated here due to speed concern, it also supports output with confidence intervals.

See help(as_flextable.indirect_list) for more information on the options available in the conversion.

Conditional Indirect Effects

The example from this article will be used, with some modifications.

This is the sample data set from `manymome:

dat <- data_med_mod_ab
print(head(dat), digits = 3)

For illustration, OLS regression is used instead of structural equation modeling to fit the model:

m ~ x + w1 + w1x + c1 + c2
y ~ m + w2 + w2m + x + c1 + c2
lm_m <- lm(m ~ x*w1, dat)
lm_y <- lm(y ~ m*w2 + x, dat)
lm_out <- lm2list(lm_m, lm_y)

Compute conditional indirect effects:

# R set to 100 just for illustration.
# Use 5000 or 10000 and set parallel to TRUE in real research.
out_cond <- cond_indirect_effects(wlevels =c("w1", "w2"),
                                  x = "x",
                                  y = "y",
                                  m = "m",
                                  fit = lm_out,
                                  standardized_x = TRUE,
                                  standardized_y = TRUE,
                                  boot_ci = TRUE,
                                  R = 100,
                                  seed = 12345,
                                  parallel = FALSE,
                                  progress = FALSE)
out_cond

The method as_flextable() can then be used to convert the output to a flextable.

library(manymome.table)
ft_cond <- as_flextable(out_cond)
ft_cond

By default, if standardized effects are requested, the unstandardized effects will also be printed when converting to a flextable.

Not demonstrated here due to speed concern, it also supports output with confidence intervals.

See help(as_flextable.cond_indirect_effects) for more information on the options available in the conversion.

Other Features

Further Processing by flextable

The output of both methods is a flextable object. Therefore, it can be further modified by functions for flextable. Load the package flextable first to use its functions.

For example:

library(flextable)
ft_cond2 <- ft_cond |>
              bold(part = "header") |>
              bg(i = c(1, 2), bg = "lightblue", part = "body") |>
              bg(i = c(3, 4), bg = "lightgreen", part = "body")
ft_cond2

The export functions from flextable can also be used to export one or more tables to an external file, such as a Word file:

save_as_docx(ft_cond, "conditional_effects.docx")

Please refer to the documentation of flextable for further information.

Other Options

Both as_flextable.indirect_list() and as_flextable.cond_indirect_effects() have options for customize the generation of the table. For example, if the list of indirect paths have different predictors (x-variables) and/or different outcome variables (y-variables), the estimates caN be grouped by x- and/or y-variables. Please refer to the help pages for further details.



Try the manymome.table package in your browser

Any scripts or data that you put into this service are public.

manymome.table documentation built on May 29, 2024, 1:38 a.m.