Skip to content

Instantly share code, notes, and snippets.

View battenr's full-sized avatar

Ryan Batten battenr

View GitHub Profile
@battenr
battenr / boot_robust_cis.R
Created July 11, 2024 18:08
Showing Difference Between Bootstrapping and Robust Variance Estimation
# Title: Estimating variance with PS-based methods
# Description: Demonstrating two different ways to estimate variance
# after using PS-based methods.
# Setup ----
library(tidyverse) # ol faithful
library(broom) # tidying the model results
library(sandwich) # for robust variance estimator
@battenr
battenr / diag_logreg.R
Created July 18, 2024 18:37
Diagnostic Plots for Logistic Regression
# Title: Diagnostic Plots for Logistic Regression
# Description: These diagnostic plots are recommended for logistic regression in
# Hosmer & Lemeshow. Creating this code to show how to make them in R.
# Setup ----
#... Libraries ----
library(tidyverse) # ol faithful
@battenr
battenr / g-formula_vs_ipw.R
Created July 25, 2024 19:22
Parametric G-Formula versus IPTW
# Title: Parametric G-Formula vs IPTW
# Description: Comparing results from parametric g-formula to results from IPTW.
# These methods model different things. The parametric g-formula models the outcome
# while IPTW models the treatment. The goal of this code is to show how they differ,
# but are not drastically different (in this example with minimal model misspecification).
# Setup ----
library(tidyverse) # ol faithful
@battenr
battenr / ipcw_curves.R
Created August 1, 2024 17:50
KM Curves using IPCW
# Title: IPCW for KM Curves
# Description: Demonstrating using inverse probability of censoring weighting for
# Kaplan-Meier Curves.
# Setup ----
#... Libraries ----
library(tidyverse) # ol faithful
@battenr
battenr / varsel_pvalue_dag.R
Created August 2, 2024 15:58
Variable Selection - Based on P-Values vs Based on DAGs
# Title: Variable Selection Based on P-Values vs DAGs
# Description: The purpose of this code is to show how variable selection
# based on p-values can lead to more biased results than using DAGs.
# Setup ----
library(tidyverse) # ol faithful
# Simulating Data ----
@battenr
battenr / prophaz_check.R
Created August 5, 2024 15:13
Checking the Proportional Hazards Assumption
# Title: Checking the Proportional Hazards Assumption
# Description: Two ways to test the proportional hazards assumption from a Cox
# PH model. One is the Grambsch-Therneau test, while another is plotting the
# Schoenfeld residuals over time. Other methods will be for future posts
# Setup ----
#... Libraries ----
@battenr
battenr / bootstrap_exs.R
Created August 8, 2024 15:32
Bootstrap Examples
# Title: Bootstrapping
# Description: Showing what bootstrapping is and how it can be useful.
# Setup ----
#... Libraries ----
library(tidyverse) # ol' faithful
library(tidymodels)
@battenr
battenr / stab_nonstab_weights.R
Created August 12, 2024 15:38
Stabilized vs Nonstabilized Weights (Density Plot)
# Title: Stabilized vs Nonstabilized Weights
# Description: Showing stabilized vs nonstabilized weights using a density plot.
# Setup ----
#... Libraries ----
library(tidyverse) # ol' faithful
library(broom) # cleaning model outputs
@battenr
battenr / mi.R
Created August 16, 2024 16:47
Multiple Imputation
# Title: Multiple Imputation
# Description: Showing very, very briefly how multiple imputation works. This was inspired by the
# section on multiple imputation in Flexible Imputation of Missing Data by Stef van Buuren.
# Setup ----
#... Libraries ----
library(tidyverse) # ol' faithful
@battenr
battenr / loglog_ph.R
Created August 23, 2024 15:22
Log-Log Plot for Proportional Hazards Assumption
# Title: Checking the Proportional Hazards Assumption using Log-Log Plot
# Description: Showing how to check the PH assumption using the log-log plot.
# Setup ----
#... Libraries ----
library(tidyverse) # ol' faithful
library(simsurv) # for simulating survival (TTE) data