This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Posterior Predictive Checks for Bayesian & Frequentist Models | |
| # Description: When fitting a model, we need to check assumptions. In a Bayesian framework, | |
| # one excellent tool is the posterior predictive check. A similar thing can be done with | |
| # frequentist models by simulating data with the model then comparing to the observed data | |
| # This code demonstrates that and how it's useful | |
| # Note: This code was created with the help of Claude Sonnet 4.5 and reviewed by me (R Batten) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Average Treatment Effect in the Overlap | |
| # Description: The average treatment effect in the overlap (ATO) can be a tremendously helpful | |
| # causal estimand. However, it can be tricky to define because it's hard to identify | |
| # before an analysis. | |
| # This code demonstrates what the target population is for the ATO using code | |
| # Note: Claude was used to help with parts of this code, in particular the formatting of the graphic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Bias-corrected and Accelerated Bootstrap Interval for Causal Inference | |
| # Description: Sometimes the confidence interval can be tricky to estimate for | |
| # causal inference. In particular, there may be situations where we can't simply estimate | |
| # it with a formula. | |
| # In these cases, bootstrapping can help. However, when the sampling distribution | |
| # is skewed or biased this can cause problems. The BCa interval can help by accounting | |
| # for this bias and skewness. This code demonstrates how the BCa bootstrap | |
| # interval works with an example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Why Dichotomizing a Continuous Confounder is a Bad Idea | |
| # Description: Dichotomizing a continuous confounder is a bad idea. | |
| # This code demonstrates why it's a bad idea, and how it can lead to | |
| # bias. | |
| # Setup ---- | |
| #... Packages ---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Plotting Causal Estimands using Potential Outcomes | |
| # Description: Understanding different causal estimands is a key part of causal inference. | |
| # Using the potential outcomes framework can help with this! | |
| # This code simulates data under the following conditions: | |
| # Research Question: Does coffee cause happiness? | |
| # Three variables: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Marginal Structural Models for Time-Varying Confounding | |
| # Description: Time-varying confounding can be tricky. If it's not properly accounted | |
| # for the results can be misleading. | |
| # This code demonstrates how to fit a marginal structural model, using | |
| # simulated data and the WeightIt package. It also demonstrates how | |
| # we can get an estimate at each time point but also an overall | |
| # marginal effect. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Entropy Balancing | |
| # Description: Demonstrating how entropy balancing can be useful for causal inference. | |
| # In particular, it can be useful when there is some overlap between the groups. | |
| # For further reading, I highligh recommend the paper by Jans Hainmuller | |
| # "Entropy Balancing for Causal Effects" | |
| # Setup ---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Linear Mixed Effects Models for Causal Inference | |
| # Description: Mixed effects models can be useful for causal inference, in particular | |
| # when there are clusters of groups that we want to account for. If we do not account | |
| # for these clusters, we could get an incorrect result | |
| # (specifically we need to account for the differences within and between clusters) | |
| # Note: This code was created with the help of Gemini | |
| # Setup ---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Clone-Censor-Weight Method | |
| # Description: Immortal time bias can be a problem for causal inference. | |
| # The typical approach is to deal with this through study design. However, sometimes | |
| # that's not possible. In particular when using secondary data. | |
| # One method that can be useful is the clone-censor-weight method. The process of doing that is | |
| # demonstrated below. | |
| # Notes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Title: Coverage Probability | |
| # Description: Demonstrating how coverage probability is useful for causal inference. | |
| # This code uses the example of calculating variance based on three methods: | |
| # a) sandwich estimator, b) M-estimation, c) bootstrapping. | |
| # The coverage probability is calculated for each method then compared. | |
| # Notes: | |
| # 1. The bootstrap step may take a while to run | |
| # 2. This code was generated with the help of Gemini |
NewerOlder