Introduction

A key part of the usualsuspects template is the use of Bayesian modeling for causal inferences. The typical process is to model a dependent variable of interest (E.g. GPA) vs our treatment variable (E.g. participation in some program) while controlling for confounding (e.g. household income and/or race). The brms package is used to set up these models and then several helper functions from the irtools package are used to clean up the results for printing.

Our Data

Again, we have simulated data for use.

ipeds_race gender student_ses treated gpa hrs_earned hrs_attempted ap_hours_earned
Black Female Medium Income 1 3.18 14.15 14.15 17.44
Asian Female High Income 1 3.00 13.43 13.43 17.76
White Female Medium Income 1 3.62 13.12 13.12 19.46
NRA Male Low Income 0 3.55 12.22 12.22 14.33
White Female High Income 0 3.68 11.45 11.45 12.83
White Male High Income 0 3.36 12.18 12.34 14.60

Fitting the Model

Say for example we want to test the effect of the treatment on a student’s gpa. We will also need to try to adjust the effect of our treatment by confounding factors (e.g. race and household income may have an impact on GPA).

We can build the model using the brm function from the brms package which has already been loaded as part of the irverse suite of packages.

First we generate the model that we want to fit. Here we are adjusting for race, gender, and student household income. The default is a normal distribution (i.e. a basic linear model. If this were binary response we would use a “bernouilli” distribution).

We can then fit this model. As this is Bayesian modeling the Stan inference engine which powers the brms function can take some additional arguments to control how many iterations to run, how many chains to run and how to process these are your machine. A ton of great documentation exists for brms and Stan. If you want to learn more see the vignettes here and use the discussion board at the Stan website.

As with any R model we can look at the resulting parameters with the summary function.

We can see from the Rhat diagnostics and Effective Sample sizes that we are achieving good convergences and can trust our results. If we had more information to include in our priors we could include those in the brm model. See ?brm for more details.

Summarising the Results

Now we can use our helper functions from the irtools package to help summarise our results.

summarise_brms_results

We can use the summarise_brms_results function to pull out some summary information from our fitted model including the effect size, our point estimate for the effect as well as our credible interval. Note that brms added a “b_” before our variable.

make_standardized_betas

Note that the values from the summarise_brms_results are on the original scale (e.g. points on a 4.0 GPA scale). However, when we are comparing across several different parameters sometimes we like to include standardized values in order to judge the order of magnitude (e.g. a 1pt GPA jump might be a bigger effect than a 1 hour move in credits earned). The make_standardized_betas function will standardize our coefficients.

Typically we want to look at these two tables together so we could easily combine them with:

Displaying the Outputs

The next step is to combine the results into the appropriate data frame structure. It is important that certain column names exist in order to use the make_regression_results_graph. These include those from the previously joined brms results as well as fields for

  • Pretty_Title
  • significant
  • description

For example see below how I add them. In the usualsuspects template most of this step is completely automated.

Now we can use the make_tie_fighter_plot function to generate our familiar plot.

This graph shows the standardized betas, uses the different criteria for effect size and includes the legend. If the initial table has more values (e.g. GPA, hrs earned, etc, this will automatically display them all together).