Creates graphs that visiualize the mechanisms behind each sufficient cause using the DiagrammeR
package.
new_mechanism()
and validate_mechanism()
define the epicmodel_mechanism
S3 class, which is created by mechanism()
.
plot()
renders the graphs in the RStudio Viewer.
print()
prints the legend for node labels in the console.
Arguments
- scc
For
mechanism()
, an object of classepicmodel_scc
.- modules
For
mechanism()
, TRUE (default) or FALSE, indicating if nodes in the same module should be colored equally (TRUE) or if all nodes have white background (FALSE). Colors are only applied, if modules have actually been specified in theepicmodel_steplist
. If modules are considered bymechanism()
, the module keywords are added to the legend (accessable viaprint()
).- module_colors
For
mechanism()
, if nodes are colored by module, colors can be provided via this argument. Colors must be provided as a character vector. Both named colors and hexadecimal color codes are allowed. The function has 8 colors stored internally. Ifmodule_colors
= NULL (default), these colors are used. If the model has more than 8 modules,module_colors
must be specified. If more colors than necessary are specified, the function takes as many as necessary from the start of the vector.- x
x
is used in several functions:new_mechanism()
: A list to be converted to classepicmodel_mechanism
.validate_mechanism()
: An object of classepicmodel_mechanism
to be validated.plot.epicmodel_mechanism()
: An object of classepicmodel_mechanism
.print.epicmodel_mechanism()
: An object of classepicmodel_mechanism
.
- reverse
For
plot.epicmodel_mechanism()
, TRUE or FALSE indicating if the output should be displayed in reverse order. Since graphs rendered later show up first in the viewer pane, reverse = T leads to SC1 being the last rendered and the one displayed on top.- ...
Value
mechanism()
: An object of classepicmodel_mechanism
. Useplot()
to plot the graphs in the RStudio Viewer. Useprint()
to print the legend in the console. Useexport_mechanism()
to save the graphs as PNG, PDF, SVG, or PostScript.new_mechanism()
: An object of classepicmodel_mechanism
.validate_mechanism()
: An object of classepicmodel_mechanism
that has been checked to have the correct structure.plot.epicmodel_mechanism()
: Renders the graphs in the RStudio Viewer.print.epicmodel_mechanism()
: Prints the legend of theepicmodel_mechanism
object in the console.
Details
The graphs
One graph per sufficient cause is created. The graphs display steps as nodes and IF/IFNOT relations as edges. Nodes will not be
labeled with their IDs or descriptions due to limited space, but with newly created labels. These labels are based on the type of node and are
listed together with the step description in the legend
(accessed by print()
). Step descriptions are also accessible via tooltips in the
graph. Just put your cursor on the node labels.
There are 4 different types of nodes:
Component causes
: Labeled"CC"
, squares, gray borderInterventions
: Labeled"I"
, triangles, gray borderEnd steps
: Labeled"E"
, circles, black borderOther steps
: Labeled"S"
, circles, gray border
There are 2 types of edges:
IF conditions
: gray arrowsIFNOT conditions
: red and T-shaped
epicmodel_mechanism
objects
epicmodel_mechanism
objects are created by mechanism()
. They are lists containing 2 elements:
legend
A data.frame with up to 3 variables:
Label
: Contains the labels used in the graphs.Module
: Contains the name of the module to which this step belongs. Only available ifmodules = TRUE
inmechanism()
and if the SCC model actually uses modules (specified in elementsc_use_modules
ofepicmodel_scc
objects).Step
: A description of the corresponding step.
graph
A list of length equal to the number of sufficient causes. Each element contains another list with 2 elements:
ndf
: A data.frame containing information about nodes in the graph (seeDiagrammeR::node_aes()
).edf
: A data.frame containing information about edges in the graph (seeDiagrammeR::edge_aes()
).
ndf
Data.frames containing the following variables:
id
: Node ID used internally byDiagrammeR
to define edges (from
andto
inedf
data.frames).type
: Type of node as defined byepicmodel
. Possible options are:cc
(component cause),int
(intervention),end
(step that is part of an outcome definition),other
(all other steps).label
: The label displayed in the graph and listed in variableLabel
oflegend
.tooltip
: The text displayed when putting the cursor on top of the node label. Corresponds to the step descriptions in variableStep
oflegend
.shape
: The shape of the node.square
for typecc
,triangle
for typeint
, andcircle
for typesend
andother
.color
: Color of the node border. Gray for typescc
,int
, andother
, and black for typeend
.fillcolor
: Color of the background, which is similar for all steps in the same module. If modules are not considered,fillcolor
is white for all nodes.fontcolor
: Color of the node label. Always black.
edf
Data.frames containing the following variables:
id
: Edge ID used internally byDiagrammeR
.from
: Node ID of the node from which the edge starts.to
: Node ID of the node at which the edge ends.rel
: Type of edge as defined byepicmodel
. Possible options are:if
(from
node is in IF condition ofto
node),ifnot
(from
node is in IFNOT condition ofto
node).arrowhead
: Type of arrow.normal
for relif
andtee
for relifnot
.arrowsize
: Size of arrow. 1 for relif
and 1.2 for relifnot
.color
: Color of arrow. Gray for relif
and#A65141
for relifnot
.
See also
export_mechanism()
for saving the plotsDiagrammeR::node_aes()
for a list of node-related variables inDiagrammeR
DiagrammeR::edge_aes()
for a list of edge-related variables inDiagrammeR
Examples
# Create some SCC model
steplist_checked <- check_steplist(steplist_rain)
#>
#> ── Checking epicmodel_steplist steplist_rain ───────────────────────────────────
#> ✔ Checking WHAT IDs was successful.
#> ✔ Checking DOES IDs was successful.
#> ✔ Checking WHERE IDs was successful.
#> ✔ Checking Module IDs was successful.
#> ✔ Checking ICC IDs was successful.
#> ✔ Checking WHAT keywords was successful.
#> ✔ Checking DOES keywords was successful.
#> ✔ Checking WHERE keywords was successful.
#> ✔ Checking Module keywords was successful.
#> ✔ Checking Modules was successful.
#> ✔ Checking ICC entries was successful.
#> ✔ Checking WHAT segments was successful.
#> ✔ Checking DOES segments was successful.
#> ✔ Checking WHERE segments was successful.
#> ✔ Checking references was successful.
#> ✔ Checking start/end steps was successful.
#> ✔ Checking THEN statements was successful.
#> ✔ Checking THEN/IF/IFNOT equality was successful.
#> ✔ Checking outcome definitions was successful.
#> ── Summary ─────────────────────────────────────────────────────────────────────
#> ✔ Checking successful!
scc_model <- create_scc(steplist_checked)
#>
#> ── Create SCC Model ──
#>
#> ✔ 15/15 | Check if set of component causes is sufficient
#> ✔ 5/5 | Check if sufficiency dependends on IFNOT conditions
#> ✔ 5/5 | Check if sufficient cause is minimal
#> ℹ 2/5 sufficient causes are minimal
# Derive mechanisms
mech <- mechanism(scc_model)
# new_mechanism() and validate_mechanism() are used inside mechanism()
# nonetheless, you can check its structure using validate_mechanism()
validate_mechanism(mech)
#> Label Module Step
#> CC1 activity no vacation
#> CC2 fate weekday
#> CC3 weather rain
#> CC4 activity get groceries
#> I1 activity take vacation
#> I2 activity take umbrella
#> I3 activity work from home
#> S1 activity walk to work
#> S2 activity go outside
#> E1 weather you get wet
# Plot the mechanisms
plot(mech)
#> $SC2
#>
#> $SC1
#>
# Print the legend
print(mech)
#> Label Module Step
#> CC1 activity no vacation
#> CC2 fate weekday
#> CC3 weather rain
#> CC4 activity get groceries
#> I1 activity take vacation
#> I2 activity take umbrella
#> I3 activity work from home
#> S1 activity walk to work
#> S2 activity go outside
#> E1 weather you get wet
mech
#> Label Module Step
#> CC1 activity no vacation
#> CC2 fate weekday
#> CC3 weather rain
#> CC4 activity get groceries
#> I1 activity take vacation
#> I2 activity take umbrella
#> I3 activity work from home
#> S1 activity walk to work
#> S2 activity go outside
#> E1 weather you get wet