I wrote a collection of tips and tricks (guide) for R and RStudio (link). This is a work in progress, and I plan to update this in the fiture.
Staggered difference-in-differences using R
I was interested in learning how to apply the Callaway & Sant'Anna staggered difference-in-differences framework to my work. After reading several papers and watching the video by Sant'Anna, I wrote a short tutorial on how to apply this framework to a simulated data. The tutorial is located on my RPubs site.
This is a unique method that used the R “did” package, which is based on the paper by Callaway & Sant’Anna.
Mediation analysis using R
It’s not uncommon to see covariates in a regression model that should not be there. For example, measurements that occur after the treatment assignment are included into a regression model as baseline covariates. Rather, one should consider a mediation analysis.
I wrote a tutorial on how to perform mediation analysis using R on my RPubs site (link).
I know that I make this mistake at times. This tutorial helped me to carefully consider which covariates to include in a regression model and which ones to consider for mediation analysis.
MEPS tutorial on interrupted time series analysis in R
I wrote a short tutorial on how to perform an interrupted time series analysis in R. I had a challenging time working on this because I wasn’t familiar with all the nuances of the ITSA. More importantly, I wasn’t able to leverage my Stata skills to do this in R. I’m used to the Stata margins command, which is great for creating constrasts. R has its own version of the margins command, but it lacks some of Stata’s features such as the pwcompare, which I use a lot in Stata. However, I found a workaround with linear splines, and I have uploaded this to my RPubs site (link). I hope you find this useful. I also saved my R Markdown code on my GitHub site (link).
MEPS tutorials on linkage files and trend analysis
I create two MEPS tutorials recently. One is on the use of condition-event linkage files to capture the disease-specific costs. I used migraine as a motivating example. In this tutorial, I go through the steps to identify migraine-related costs assocaited with office-based visits and inpatient night stays. In the second tutorial, I review how to perform simple trend analysis with linear regressio models. I pooled MEPS data from 2016 to 2021 and apply the approriate primary sampling units and strata from the pooled file.
The first tutorial is located on my RPubs page (MEPS Tutorial 4 - Using condition-event link (CLNK
) file: A case study with migraine). The R Markdown code to create the tutorial is located in my GitHub repository (link).
The second tutorial is also located on my Rpubs page (MEPS Tutorial 5 - Simple Trend Analysis with Linear Models). The R Markdown code to create the tutorial is located in my GitHub repository (link).
Exact matching using R - MatchIt package
Recently, I was asked to help create a matching algorithm for a retrospective cohort study. The request was to perform an exact match on a single variable using a 2 to 1 ratio (unexposed to exposed). Normally, I would use a propensity score match (PSM) approach, but the data did not have enough variables for each unique subject. With PSM, I tend to build a logit (or probit) model using variables that would be theoretically associated with the treatment assignment. However, this approach requires enough observable variables to construct these PSM models. For this request, there were a few variables for each subjects; the only variable available were the unique identifier, site, and a continuous variable.
This problem led to a tutorial on how to perform an exact match using the MatchIt package in R, which can be viewed here in my RPubs page.
In this tutorial, you will learn how to perform an exact match with a single variable using a hypothetical dataset with 30 subjects.
Building a book using the bookdown package in R - Part 2: Chapters and References
I create a second tutorial on bookdown that provides a high-level overview on how to add chapters and a reference section. It is located on my RPubs site (link).
I plan on creating more tutorials with the bookdown package, so stay tuned.
Building a book using the bookdown package in R - Part 1
I created a tutorial on building an online book using the R bookdown package. The tutorial is available on my RPubs page, which is located here.
I plan on creating more tutorials with the bookdown package, so stay tuned.
Building an HTML Presentation using R Markdown - Part 2
This is the second part of a series on how to create HTML presentations using R Markdown.
I posted it on my Rpubs site and my GitHub site.
I plan on writing more tutorials on this subject, so stay tuned.
Tweedie GLM model in R for Cost Data
I wrote a tutorial on using a Tweedie distribution for a GLM gamma model for cost data in R. Unlike Stata, R is very particular with zeroes when constructing GLM models. Hence, I opted to use the Tweedie distribution to mix and match the link function with the Gamma distribution. I settled on the identity link because it doesn’t involve retransformation and is each to interpret.
My tutorial is available on my RPubs site and GitHub site.