Asking for help on lme4 package

I'm trying to run a lmer package using these codes:

summary (lmer(elabe_data$DMN_vs_DMN_z ~ elabe_data$HRLR + elabe_data$child_sex + elabe_data$mri_test_scan_day_un + elabe_data$mat_med_risk_sum + elabe_data$maternal_age_birth + elabe_data$bmi_pre_pregnancy + (1|modid), data = elabe_data))

However, I got an error message: Error: number of levels of each grouping factor must be < number of observations (problems: modid).

Does anyone know what the problem here is? I'm trying to have the identifier number (modid) as the random variable. Thanks!

That's the error.

By the way, you don't need to have elabe_data$ in there because you have used data = elabe_data.

It would be good to have a reproducible example of your dataset:

Hi Thank you so much for your help. I have put together a reproducible dataset. It would be very helpful if anyone can help how to dissolve the error. Thanks!

elabe_data <- data.frame(
DMN_vs_DMN_z = c(-1.5537227756,1.2685453317,0.5076225730,0.1588330048,0.4783086631),
HRLR = c(0, 0, 0, 0, 0),
child_sex = c(1,2,1,2,1),
mri_test_scan_day_un = c(3,1,6,6,3),
mat_med_risk_sum = c(3,1,4,3,1),
maternal_age_birth = c(25.24624, 35.86932, 26.72197, 25.94714, 27.18194),
bmi_pre_pregnancy = c(37.4,38.9,28,25.5,27.5),
modid = c('MOD1022', 'MOD1025', 'MOD1039',' MOD1054', 'MOD1058')
)

A <- lmer(elabe_data$DMN_vs_DMN_z ~ elabe_data$HRLR + elabe_data$child_sex + elabe_data$mri_test_scan_day_un + elabe_data$mat_med_risk_sum + elabe_data$maternal_age_birth + elabe_data$bmi_pre_pregnancy + (1|modid), data = elabe_data)

summary(A)

The error message is Error: number of levels of each grouping factor must be < number of observations (problems: modid).

Your modid column isn't a grouping variable. It is a unique ID.

That is what is causing your error:

Error: number of levels of each grouping factor must be < number of observations

You could probably drop that column, but also choose an actual grouping variable.

More info:

Thank you. This is very helpful!

This topic was automatically closed 21 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.