Error with random effect: lmer

Hello, I've been trying to run lmer using the code below:

model <- lmer(brain_volume_change ~ blood_leakage_volume + (1 + blood_leakage_volume|SubjectID), data = data_pruned)

I keep getting an error message that says: "Error: number of levels of each grouping factor must be < number of observations (problems: SubjectID)"

Additional info:

  • Data was collected at 2-timepoints: baseline and 1-year.
  • The variable "blood_leakage_volume" is only data at baseline; "brain_volume_change" was calculated by subtracting the brain volume at 1-year from baseline.
  • This study is a repeated-measures design, but I am not sure if the data is structured correctly to use 'lmer'.

I've included a snippet of my dataset below (note: this is my first time trying to place an example of my data in this form. I just followed the instructions in the FAQ. I apologise if this is not how it is supposed to look like!).

I've searched the internet for solutions (and asked ChatGPT), but my problem remains unresolved. Any help would be appreciated.

###---- Sample data

[1] "structure(list(SubjectID = c(23560, 23902, 24189, 24486, 24491, "
[2] "24572, 24623, 24624, 24625, 24677), blood_leakage_volume = c(0.07529, "
[3] "0.00958, NA, 0.03959, 0.04452, 0.07956, 0.0312, 0.02196, 0.07932, "
[4] "0.02943), brain_volume_change = c(-0.370184, 0.3404705, 0.1664023, "
[5] "-0.9712265, NA, -0.933692, -0.970152, -0.8035145, -0.9277315, "
[6] "0.1027567)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "
[7] ""data.frame"))"

I'm not a user of lmer() but it seems you are trying to calculate a global slope vs. blood_leakage_volume and an intercept and a slope of blood_leakage_volume for each SubjectID. There is only one data point per SubjectID. You can't fit a group with only one data point. That's the meaning of "number of levels of each grouping factor must be < number of observations ". You have number of levels = number of observations.

Thank you for replying. I was confused about that as well (i.e. one data point per subject). Information on the internet was mixed but some indicated it is fine (hence the confusion). I wasn't sure if I should use a linear regression model since the data is a repeated measures design which would benefit from having the random effect option in lmer().

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.