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: Overlap Weighting | |
| # Description: A demonstration of overlap weighting using the propensity score | |
| # Setup ---- | |
| #... Libraries ---- | |
| library(tidyverse) # ol' faithful | |
| library(WeightIt) # for weighting |
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: Parametric vs Nonparametric Statistics | |
| # Description: An example of what is actually meant by parametric with parametric statistics. | |
| # Setup ---- | |
| #... Libraries ---- | |
| library(tidyverse) # ol faithful | |
| library(glue) # for easy string formatting |
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: A collider and a confounder - To adjust or not adjust? | |
| # Description: Should we adjust for a variable if it's both a collider and a confounder? | |
| # The idea for this came from an article I recently read - Liu et al.(2012) | |
| # https://academic.oup.com/aje/article/176/10/938/92975#246684420 | |
| # The idea for this code was to keep the situation simple to start. It can be built upon | |
| # rather easily. A few things to try altering would be the strength of the causal relationships, | |
| # continuous vs binary vs TTE variables, more/less variables, etc. |
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: Variable Selection - Model Misspecification | |
| # Subtitle: Two Variables Included That Shouldn't Be | |
| # Description: The idea for this came from trying to show what happens | |
| # if the wrong variables are selected. Basically, when we use variable selection methods | |
| # based on the p-value the results can be biased due to model misspecification. Furthermore, | |
| # how would that look if it wasn't just one variable that was wrong...but two! | |
| # 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: Plotting Propensity Scores and Weights | |
| # Description: Plotting propensity scores and weights is helpful for checking the | |
| # entire distribution and assumptions. This code gives an example of doing that. | |
| # Setup ---- | |
| library(tidyverse) # ol' faithful | |
| library(WeightIt) # for using IPTW | |
| library(patchwork) # for combining plots |
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: Understanding Distributions and Parameters | |
| # Description: The below plots show which parameters are needed for four different | |
| # distributions: normal, exponential, binomial and poisson distributions. | |
| # Setup ---- | |
| #... Libraries ---- | |
| library(tidyverse) # ol faithful |
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: Conditioning on Descendant of a Collider Causes Bias | |
| # Description: This script is intended to show that conditioning/adjusting | |
| # for a descendant of a collider can induce bias. | |
| # Setup ---- | |
| library(tidyverse) # ol' faithful | |
| library(ggdag) # for creating and showing DAG | |
| library(broom) # for tidying result of the model |
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: Adjusting for Sunshine | |
| # Description: Assessing whether adjusting for sunshine improves precision based on a question from David Okunlola on a LinkedIn Post | |
| # Replicate 1000 times ---- | |
| # We could use one run as an example, however that is a single run. We need to do it many more times than that. | |
| # Let's run it 1000 times. (Note: there are ways to calculate the number of runs required. For simplicity, we'll pick 1000 for now) | |
| #... No Adjustment ---- |
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: Always Plot Your Data | |
| # Description: A piece of advice I got from my supervisor was to always | |
| # plot your data first. This is invaluable. The code below is meant to show | |
| # one reason why | |
| # Setup ---- | |
| #... Libraries ---- |
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: Showing what the probability of the null is given our data | |
| # Description: Often the p-value is misinterpreted as the probability of the null. | |
| # The goal of this post is to show what the probability of the null actually is. | |
| # We can do this using Bayesian statistics. | |
| # Note: the p-value is the probability of a test-statistic at least as extreme assuming | |
| # the null distribution | |
| # Setup ---- |