The causalcakes package creates visual representations of causal mechanisms using "causal cake" diagrams. These diagrams are rarely employed in the social sciences, but can provide an alternative to directed-acyclic graphs (DAGs) and are useful for making explicit a variety of external validity dimensions. They excel at modeling structural mechanisms, such as INUS causation—conditions that are central to external validity inference.
What is a Causal Cake?
Core Factor
The central causal force (center circle)
Necessary Conditions
Moderators that must be present (outer ring)
Outcome
The effect produced when conditions align
Think of it like baking: you need flour AND eggs AND heat to make a cake. Each ingredient is necessary (you can't skip any), but insufficient on its own. Together, they're sufficient. Often there are multiple recipes (pathways) that can produce the same outcome.
Installation
# Install from GitHub
devtools::install_github("externalvalidity/causalcakes")
# Load the package
library(causalcakes)
Quick Start
Single Causal Pathway
library(causalcakes)
# Example TBA
This creates a diagram with a core causal factor at the center, surrounded by necessary conditions, with an arrow pointing to the outcome.
Multiple Pathways (INUS Structure)
library(causalcakes)
# Example TBA
This shows multiple alternative pathways to the same outcome—each sufficient on its own, but neither necessary.
Example Applications
🗳️ Voter Turnout
Two pathways: performance information vs. malfeasance information, each with different necessary conditions.
Coming Soon
🏢 Technology Adoption
Three mechanisms: economic pressure, competitive pressure, and regulatory requirements.
Coming Soon
📋 Policy Compliance
Normative pathway (2 conditions) vs. instrumental pathway (5 conditions) with asymmetric complexity.
Coming Soon
🎓 Academic Success
Four pathways: academic preparation, financial resources, social support, and institutional fit.
Coming Soon
Customization Options
Causal cake diagrams can be customized in several ways:
- Size adjustments — Control the size of core circles, outer rings, and outcome nodes
- Spacing — Adjust whitespace between diagram elements
- Layout — Choose horizontal or vertical arrangements for two-pathway diagrams; circular arrangement for three or more pathways
- Text scaling — Adjust font sizes for core labels, segment labels, and outcome text
- Arrow styling — Customize arrow thickness and appearance
- Relationship types — Label arrows as Sufficient (S), Probabilistic (P), or Necessary (N) to indicate the nature of causal relationships
Integration with EVinference
Causal cakes integrate with the broader EVinference ecosystem. Mechanisms declared using EVinference's declare_mechanism() function can be automatically converted to causal cake visualizations. This allows researchers to move seamlessly between formal mechanism specification and visual representation, making it easier to communicate theoretical models and identify which necessary conditions might differ across target contexts.