This repository contains an R-based workflow to perform Multilevel Exploratory Factor Analysis (EFA) on Experience Sampling Method (ESM) data collected by the Netherlands Twin Register (NTR).
The goal is to uncover latent affective structures both between individuals and within individuals across days, using multilevel psychometric techniques.
-
Between-Person Analysis
Identify stable individual differences by averaging item responses per person. This analysis reveals how people differ from each other in general affective tendencies. -
Within-Person Analysis (Person-by-Day)
Assess how affect fluctuates within each individual across different days. This allows exploration of whether the factor structure found between individuals also holds within individuals. -
Multilevel EFA
Perform EFA at both levels and compare structures to examine cross-level stability in affective dimensions.
- Import raw ESM CSV data
- Rename item variables for readability
- Convert to long format for flexibility in aggregation
- Kaiser-Meyer-Olkin (KMO) measure of sampling adequacy
- Bartlett's test of sphericity to verify sufficient item intercorrelations
- Estimate eigenvalues and scree plots
- Conduct parallel analysis (optional)
- Extract factors using
psych::fa()(e.g., maximum likelihood)
- Varimax (orthogonal, uncorrelated factors)
- Oblimin (oblique, correlated factors)
- Review factor loadings
- Identify simple structure
- Eliminate weak or cross-loading items (if necessary)
- Translate EFA structure into a CFA model using
lavaan - Evaluate model fit (RMSEA, CFI, TLI, etc.)
This workflow was inspired by data collected in the Netherlands Twin Register (NTR), which maintains a large-scale database of twins and their relatives.
Note: This repository uses simulated or anonymized data. Access to real NTR data requires permission.
Make sure the following R packages are installed:
install.packages(c(
"tidyverse", "readr", "ggplot2", "readxl",
"lubridate", "lavaan", "tcltk", "ggcorrplot",
"corrr", "psych"
))