grfcausalworkshop provides tools for learning causal inference using machine learning methods, here, causal forests.
# install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
# install causalworkshop from GitHub
devtools::install_github("go-bayes/causalworkshop")
margot# install margot for advanced workflows OPTIONAL
# warning, this package is being refactored: for demonstration purposes in the Workshop
devtools::install_github("go-bayes/margot")
This will install causalworkshop along with all required dependencies for the complete workshop experience.
After installation, verify everything works:
# Load the package
library(causalworkshop)
# Check prerequisites
check_workshop_prerequisites()
# Run a quick test
workshop_results <- run_workshop(n = 30000, verbose = FALSE)
Common Issues and Solutions:
install.packages(c("grf", "dplyr", "ggplot2")) manuallydevtools::install_github("go-bayes/margot")Getting Help:
library(causalworkshop)
# Copy all workshop scripts to your working directory
get_workshop_scripts()
# See what scripts are available
list_workshop_scripts()
# Work through the scripts in order:
# 01-baseline-adjustment.R - Foundation concepts
# 02-causal-forest-analysis.R - Core methodology
# 03-rate-qini-curves.R - Performance evaluation
# 04-policy-trees.R - Decision rules
# 05-margot-workflow.R - Professional analysis
# 06-interpretation.qmd - Results reporting
library(causalworkshop)
# Check prerequisites
check_workshop_prerequisites()
# Run complete educational pipeline
workshop_results <- run_workshop()
# View key results
workshop_results$baseline_results$results_table
workshop_results$causal_forest_results$heterogeneity_stats
# Display educational plots
workshop_results$selection_bias_plot
workshop_results$heterogeneity_plot
workshop_results$targeting_plots$rate_plot
# 1. Simulate realistic data
data <- simulate_religious_data(n = 2000)
# 2. Demonstrate selection bias
baseline_results <- workshop_baseline_adjustment(data)
plot_selection_bias(baseline_results$results_table)
# 3. Estimate heterogeneous treatment effects
cf_results <- workshop_causal_forest(data)
plot_heterogeneity_distribution(cf_results$predictions)
# 4. Evaluate targeting performance
targeting_plots <- plot_rate_qini_curves(cf_results$predictions)
targeting_plots$rate_plot
targeting_plots$qini_plot
Learn why naive comparisons fail in observational studies and how baseline adjustment addresses selection bias.
# Demonstrates selection bias
baseline_results <- workshop_baseline_adjustment()
baseline_results$bias_reduction # Quantifies improvement
Consider how causal forests can estimate conditional average treatment effects while maintaining valid statistical inference.
# Estimates conditional average treatment effects τ(x)
cf_results <- workshop_causal_forest()
cf_results$heterogeneity_stats # Summary of effect variation
cf_results$variable_importance # Drivers of heterogeneity
Explore how treatment effect heterogeneity can inform policy targeting decisions.
# Evaluates targeting performance
plots <- plot_rate_qini_curves(cf_results$predictions)
plots$efficiency_data # Targeting efficiency metrics
Implementations follow the standards established by the Generalized Random Forests development team.
If you use this package in academic work, please cite
citation("causalworkshop")
This R package is licensed under the MIT License. See LICENSE.md for details.
The educational content, tutorials, and documentation are licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0).
Copyright © 2025 Joseph A. Bulbulia
If you use this package in academic work, please cite:
Bulbulia, J.A. (2025). causalworkshop: Educational Package for Causal Inference
with Machine Learning. R package version 0.1.0.
https://github.com/go-bayes/causalworkshop
grf: Core causal forest implementationmargot: Advanced causal inference workflowspolicytree: Policy learning toolsThis package was developed for educational purposes as part of the Epic Lab at Victoria University of Wellington.