Description
Tidy Intensive Longitudinal Data Analysis.
Description
A reproducible, tidyverse-style framework for intensive longitudinal data analysis in R, with built-in methodological safeguards, provenance tracking, and reporting tools. Encodes time structure, enforces within-between decomposition, provides spacing-aware lags, and integrates diagnostics and visualization. Use ild_prepare(), ild_center(), ild_lag(), and related functions for a unified pipeline from raw EMA/diary data to interpretable models.
README.md
tidyILD
A reproducible, tidyverse-style framework for intensive longitudinal data (ILD) analysis in R, with built-in methodological safeguards, provenance tracking, and reporting tools.
Author: Alex Litovchenko.
Install
remotes::install_github("alitovchenko/tidyILD")
Quick start
library(tidyILD)
# Prepare: validate time structure, add .ild_* columns and metadata
d <- data.frame(
id = rep(1:3, each = 5),
time = rep(as.POSIXct(0:4 * 3600, origin = "1970-01-01"), 3),
mood = rnorm(15)
)
x <- ild_prepare(d, id = "id", time = "time", gap_threshold = 7200)
# Inspect (summary tibble + list)
ild_summary(x)
# Within-between decomposition
x <- ild_center(x, mood)
# Spacing-aware lags (max_gap from metadata if omitted)
x <- ild_lag(x, mood, mode = "gap_aware", max_gap = 7200)
# Missingness (summary tibble + plot + by_id)
ild_missing_pattern(x, vars = "mood")
# Fit and report: tidy fixed effects, fitted vs observed, residual ACF + QQ
fit <- ild_lme(mood ~ 1 + (1 | id), data = x, ar1 = FALSE, warn_no_ar1 = FALSE)
tidy_ild_model(fit)
ild_plot(fit, type = "fitted")
diag <- ild_diagnostics(fit); diag; plot_ild_diagnostics(diag)
Pipeline
ild_prepare()— encode longitudinal structure, spacing, gapsild_summary()— one-shot summaryild_center()— person-mean centering (WP/BP)ild_lag()— index, gap-aware, or time-window lags (supportslubridate::hours(2)etc.)ild_decomposition()— WP/BP variance and ratio; optional WP vs BP density plotild_check_lags()— lag validity (valid/invalid, pct_invalid, lag order)ild_crosslag()— one-call cross-lag: lag predictor, check lags, fit outcome ~ lagild_acf()— ACF on a variable or on residuals (pre-model check for AR1)ild_spacing_class()— regular-ish vs irregular-ishild_spacing()— spacing diagnostics (median/IQR, large gaps %, CV) and AR1/CAR1 recommendationild_design_check()— aggregate spacing, WP/BP, missingness, and recommendationsild_center_plot()— standalone WP vs BP density plotild_missing_pattern()— missingness by person/variableild_missing_bias()— test if missingness is associated with a predictor (informative missingness)ild_align()— align secondary stream (e.g. wearables) to primary ILD within a time windowild_lme()— mixed-effects model (lmer or nlme with AR1/CAR1)ild_robust_se()— cluster-robust variance (clubSandwich);tidy_ild_model(fit, se = "robust")for robust SE/CI/pild_missing_model()— model missingness from covariates;ild_ipw_weights()andild_ipw_refit()for IPW sensitivityild_tvem()— time-varying effects (GAM);ild_tvem_plot()for the coefficient curveild_person_model()— fit model per person (N-of-1);ild_person_distribution()— plot distribution of estimatesild_diagnostics()— residual ACF, residuals vs fitted/time (useprint()for summary)plot_ild_diagnostics()— build diagnostic plots from anild_diagnosticsobjectild_plot()— trajectory, heatmap, gaps, fitted vs observed, residual ACFild_heatmap(),ild_spaghetti()— aliases for heatmap and trajectory plotsild_circadian()— variable by hour of day (when time is POSIXct)augment_ild_model()— tibble with .ild_id, .ild_time, outcome, .fitted, .residtidy_ild_model()— fixed-effect table (estimate, SE, CI, p); usese = "robust"for cluster-robust inferenceild_simulate()— simulated ILD (n_id, n_time/n_obs_per, ar1, wp_effect, bp_effect, irregular)ild_power()— simulation-based power for a fixed effect (ild_simulate → ild_lme → effect recovery)ema_example— built-in dataset (data(ema_example))- broom: Load
broom.mixedfortidy(fit)andaugment(fit)onild_lmefits.
Vignettes
- From raw data to model: full pipeline with
ild_prepare()throughild_lme()andild_plot(). - Short analysis report: fit, tidy fixed effects, fitted vs observed, residual ACF and Q-Q.
- Within-between decomposition and irregular spacing: centering and gap-aware lags.
- Glossary and quick-start: function glossary and checklist.
pkgdown site
Documentation and vignettes are built with pkgdown. From the package root: pkgdown::build_site(). Config: _pkgdown.yml.
License
MIT.