mlVAR in R returning 0 (non-NA) cases despite having 419 subjects and longitudinal data

I am trying to estimate a multilevel VAR model in R using the mlVAR package, but the model fails with the error:

Error in lme4::lFormula(formula = formula, data = augData, REML = FALSE, : 0 (non-NA) cases

From what I understand, this error usually occurs when the model ends up with no valid observations after preprocessing, often because rows are removed due to missing data or filtering during model construction.

However, in my case I have a reasonably large dataset.

Dataset structure

  • 419 plants (subjects)
  • 5 variables measured repeatedly
  • 4 visits per plant
  • Each visit separated by 6 months
  • Data are in long format

Columns:

  • id → plant identifier
  • time_num → visit identifier
  • A–E → measured variables

Example of the data:

idtime_numABCDE
305121633119
305131945015
305142294121
3051533107120
305163655220
305231367328
305252486529
30526271412836
3054323139612
30544241010217
30545321314118
30546371714324
30564311712729
305653623111034
30566381913736
30583442415334
30584532013523
30585542115423
3059338156620
30594401410528

The dataset is loaded in R as:

datos_mlvar

Model I am trying to run

fit <- mlVAR( datos_mlvar, vars = c("A","B","C","D","E"), idvar = "id", lags = 1, dayvar = "time_num", estimator = "lmer" )

Output:

'temporal' argument set to 'orthogonal' 'contemporaneous' argument set to 'orthogonal' Estimating temporal and between-subjects effects | 0% Error in lme4::lFormula(formula = formula, data = augData, REML = FALSE, : 0 (non-NA) cases

Things I already checked

  • The dataset contains 419 plants
  • Each plant has multiple time points
  • Variables A–E are numeric
  • The dataset is already in long format
  • There are no obvious missing values in the fragment shown

Possible issue I am wondering about

According to the mlVAR documentation, the dayvar argument should only be used when there are multiple observations per day, since it prevents the first measurement of a day from being regressed on the last measurement of the previous day.

In my case:

  • time_num is not a day
  • it represents visit number every 6 months

So I am wondering if using dayvar here could be causing the function to remove all valid lagged observations.

My questions

  1. Could the problem be related to using dayvar incorrectly?
  2. Should I instead use timevar or remove dayvar entirely?
  3. Could irregular visit numbers (e.g., 2,3,4,5,6) break the lag structure?
  4. Is there a recommended preprocessing step for longitudinal ecological data before fitting mlVAR?

Any suggestions or debugging strategies would be greatly appreciated.

Posted Mar 8, 2026, 8:14 PM UTC

20
Loading comments…