Skip to contents

Visualizes the output of indirect_effects() (or direct_effects() / total_effects()) as a horizontal point-and-interval (forest) plot, with a reference line at zero. This is the picture the rest of the SEM ecosystem does not draw: piecewiseSEM, dsem, and lavaan plot the path diagram but leave the direct / indirect / total decomposition as a table. drmSEM separates the distribution-mediated contribution (the effect flowing through a mediator's scale, zero-inflation, or shape) from the mean-mediated part, so a path that acts on dispersion rather than the mean is visible.

Usage

# S3 method for class 'drm_effect'
plot(x, style = c("forest", "stacked"), ...)

Arguments

x

A drm_effect data frame from indirect_effects(), direct_effects(), or total_effects().

style

"forest" (default; one point-and-interval row per quantity) or "stacked" (a single bar stacking direct + mean_mediated + distribution_mediated, which sum to the total effect). "stacked" needs the decomposition rows from indirect_effects() and falls back to "forest" if they are absent.

...

Unused.

Value

A ggplot object (invisibly printed by default).

Details

Requires ggplot2 (Suggests); returns a ggplot object you can restyle.

References

Pearl J (2001). “Direct and Indirect Effects.” In Proceedings of the Seventeenth Conference on Uncertainty in Artificial Intelligence (UAI), 411–420.

Imai K, Keele L, Yamamoto T (2010). “Identification, Inference and Sensitivity Analysis for Causal Mediation Effects.” Statistical Science, 25(1), 51–71. doi:10.1214/10-STS321 .

VanderWeele TJ (2015). Explanation in Causal Inference: Methods for Mediation and Interaction. Oxford University Press, New York.

Examples

if (FALSE) { # \dontrun{
sem <- drm_sem(
  size = drm_node(drmTMB::bf(size ~ temp + habitat, sigma ~ temp),
                  family = stats::gaussian()),
  abundance = drm_node(drmTMB::bf(abundance ~ size + temp, zi ~ habitat),
                       family = drmTMB::nbinom2()),
  data = dat)
eff <- indirect_effects(sem, from = "temp", to = "abundance", through = "size")
plot(eff, style = "forest")
} # }