Below are some example R scripts I compiled for analyses and plotting.
More R code is available on my Github page.


Interaction Effects from Regression Models: Plotting & Simple Slopes

This demo shows how to fit a regression model with interaction effects, plot the results, and run tests on the simple slopes.


Testing for Differences between Two Coefficients

This demo shows how to test whether two regression coefficients are significantly different from each other using both Frequentist and Bayesian approaches (with the brms package).


Within- and Between-Subject Centering

This demo walks through three different approaches to computing within- and between-subject centered variables in R in preparation for a multilevel analysis.


Plotting Fixed Effects from Multilevel Models

This demo shows how to plot fixed (average) effects from a multilevel model, including how to do so while accounting for a covariate. The demo includes how to plot results from both Frequentist models (using the lme4 package) and Bayesian models (using the brms package).


Visualizing Subject-Specific Effects and Posterior Draws

This demo shows how to generate panel plots to visualize between-subject heterogeneity in psychological effects, including subject-specific model predictions, raw data points, and draws from the posterior distribution using a Bayesian mixed effects (multilevel) model.


Spaghetti Plot of Multilevel Logistic Regression

This demo shows how to create a spaghetti plot of predicted values from a Bayesian multilevel logistic model.


Aggregating Physiological Data from Mindware Files

This demo shows how to use R to aggregate data from individual Excel files from Mindware, a popular physio scoring software, into one aggregated file that contains data for all participants in long form.


Bayesian Dyadic Multilevel Modeling

This demo walks through setting up a dyadic multilevel model with Bayesian estimation using the brms package for R. Here, I highlight the advantages of brms for this kind of model and provide code for formatting the data, fitting the model, and comparing the results to those returned by the nlme package.




Back to top

footer.knit