Usually R snippets, with explanation
Much of the code for these posts can also be found in this github repo.
The RI-CLPM in OpenMx
September 26, 2018
Lavaan is great. I love lavaan. But a lot of folks prefer OpenMx, and given its long and widespread usage, especially in fields outside psychology, it might be a bit better road tested. So this is a brief addendum to my previous post, showing you how to implement a RI-CLPM in OpenMx.
A better cross-lagged panel model, from Hamaker et al. (2015)
October 20, 2017
Update, 2019-11-11: There are a couple of new bits of code online that could be helpful if you are interested in these models.
- I wrote an R package called
lavaangenerate syntax for multivariate RI-CLPMs (and also provides the proper call to
lavaanfor estimating it).
- Christoph Nhuyen (@cgnguyen_online) wrote a function to generate graphs (path diagrams) for displaying the results from these models.
This walk-through explains, briefly, why and how to run a RI-CLPM in R.
All code and data are available in the github repository
Critique of cross-lagged pannel models
This post summarizes critiques of the traditional cross-lagged panel model (CLPM), and an improved model by Hamaker, Kuiper, and Grasman (2015).
The primary point Hamaker and colleagues make regarding the CLPM is that it assumes that there are “no trait-like individual differences that endure.” That is, looking at the structure of a CLPM it is clear that individual-level stability must be accounted for entirely by the auto-regressive path between waves. As they put it, it imposes an assumption that there is no between-subject variance of time-invariant, trait-like stability, but only temporal stability, wave to wave, of subjects around the mean score for any particular wave.
- I wrote an R package called
Brief MLM tutorial
September 20, 2016
Updated: plotting estimates from real data using
This is a brief description of how to think about multi-level models, especially the link between the formal expression of these models and how that looks in
lme4. The data set consists of 4 observations per day over 2 days of cortisol in a developmental sample. The relevant theoretical questions are: what individual-level predictors are related to cortisol intercepts and slopes.
Plotting using `predict`
September 12, 2016
One of my favorite functions in R is
predict, and so in response to this recent question on SlackRs#plots (“Anyone know how to plot an interaction at a moderators mean, +1SD, and -1SD?”) I thought I’d write up a quick demo of it’s usefulness.
Power to detect mediation and other problems
September 2, 2016
I was reminded of this old R Club post recently by Rose, and decided to flesh it out a bit. The first part is about power to detect mediation in the standard 3 variable model people use. The second part examines how model misspecification gives rise to significant statistical tests of mediation when there is actually no mediation going on. Since publishing a paper (in press now, but written in ~2013) in which longitudinal data was subjected to a test of mediation, I’ve become increasingly skeptical of these kinds of analyses (including my own).
Intro to Bootstrapping
November 14, 2014
“It just works”
All of the information you have about the population is in your sample – you can learn something about the ‘empirical sampling distribution’ of your parameters by estimating them in new samples drawn, with replacement, from your sample. Replacement is crucial – your bootstrap samples will be the same size as your observed sample, but will be comprised of observations from your sample at a rate proportional to the frequency in the sample. Note: There are several different methods for producing replicates.
November 12, 2014
The motivation for this example has to do with different ways one can calculate individual differences with regard to the effect of some manipulation that pushes around cortisol levels.
As a general resource for simulation in R, I highly recommend Hadley Wickham’s simulation presntation. Also, the
psychpackage has some great tools for generating data (with great support in this helpful guide by William Revelle).
Using fMRI to study child and adolescent development
September 11, 2014
Every other year, The Society for Research in Child Development hosts a series of smaller, special topic conferences. This year I was lucky to go to the Developmental Methodology conference. I was blown away by what I saw there, and left very inspired.
My contribution was to present the DSN lab’s guide to best practices both for our fellow imagers, as well as for those reading the literature without much background. Here it is:
Flournoy, J. C., Moore III, W. E., & Pfeifer, J. H. (2014, September 11). Using fMRI to study child and adolescent development: Thoughts from the trenches. Presented at Developmental Methodology, San Diego, CA.