Cross-posting from stackoverflow

I am working with a dataset having the following structure (download data here).

enter image description here

The variable resp is a physiological response measured once for every subject during the study. In the study, each subject was observed for 5 days at 10 time points. The variables vala, valb, valc, vald are the observed values that indicate the percentage of time a subject spent performing a particular activity (I am not using the activity variables directly but a transformed-version of the variables. The transformation is performed using the R package compositions). Grp (5 groups), sbjt (10 subjects), dy (5 days), tm (10 time points) are factors.

library(compositions) # for the function ilr()
sim[10:12] <- ilr(sim[6:9]) # transforming the activity variables

I am interested in fitting a mixed-effects model with grp as fixed effect (because I am specifically interested in the groups that I have selected for the participants) and sbjt, dy, tm as random effects (because I am not specifically interested in the subjects that I have chosen and wish to generalize to the study population; day and time are random because different subjects were observed at different days and different times). The times are nested within days, which in turn, are nested within subjects (tm within dy within sbjt). I believe the model is appropriate for understanding the amount of variance my activity variables and random effect variables are contributing to my resp variable.

In nlme::lme(), I have specified my model as follows with subject autocorrelation:

library(nlme) # for the function lme()
model <- lme(resp ~ V1 + V2 + V3 + grp, random = ~ 1 | Sbjt/dy/tm, correlation = corAR1(), method = "REML", data = sim) # V1, V2, V3 are the transformed activity variables
# Error in solve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop = FALSE]) : 
  system is computationally singular: reciprocal condition number = 1.24056e-17

I have the following questions about my model:

  1. Is it possible to fit a mixed-effects model with only 10 response values (another post seemed to suggest that running a mixed-model is not appropriate in such situations)? If possible, how do I get the above model to run? If not, what other models should I use instead?
  2. Could someone explain what the above error is telling me and how to correct it?
  3. If the 3-level nesting in my model is too complex, how do I simplify it so that my model runs?

I am also open to any other suggestions about the best way to model my data in nlme::lme() since I would like to specify subject autocorrelation. Thank you for your time and help! I greatly appreciate it!

  • $\begingroup$ Can you explain what you mean by "resp (that's your outcome variable Y) was measured once per participant during the study" but "each subject was observed for 5 days at 10 time points"? If you have K participants and one outcome measurements for each participant then you have K data points to model (ie K rows of data). $\endgroup$
    – dipetkov
    Commented Apr 4, 2023 at 22:03
  • $\begingroup$ @dipetkov Thank you for sharing your feedback. In the study, I observed the physical activity of the subjects in free living and each observation is a breakdown of their physical activity in an hour (the time in minutes the different activities were performed). My dataset contains physical activity recorded on 5 different days at 10 different time points and response/outcome recorded once at the end of the study. $\endgroup$ Commented Apr 4, 2023 at 22:29
  • $\begingroup$ So you have 5 * 10 * 4 = days * times * vals = 200 explanatory variables per subject but only 10 data points. It seems your data is in a wide format with 5 * 10 = days * times = 50 observations per subject, but you actually have just one observation per subject since you measured what you are trying to model (resp) only once. $\endgroup$
    – dipetkov
    Commented Apr 4, 2023 at 22:33
  • $\begingroup$ @dipetkov Yes, that would be the case with my dataset. Would you have any recommendations for me? $\endgroup$ Commented Apr 4, 2023 at 22:39
  • $\begingroup$ Well, you can convert your data into an appropriate format, with 10 rows and 200 columns for the X variables and 1 column for the outcome variable. Obviously the dataset is very small and any model would overfit to this data. Perhaps you can do some exploratory data analysis (aka plots)? $\endgroup$
    – dipetkov
    Commented Apr 4, 2023 at 22:43

1 Answer 1


This is more of a a comment, but why do you think you need random effects of day and time? Was there something special about the particular days (and/or times of day) on which each participant was tested? Without knowing anything about the subject matter, I'd be inclined to only put participant in as random effect. 10 observations per cluster is definitely enough for a mixed model as such (typically), but you are splitting your cluster-specific observations by putting in the nested day and time and you don't have enough level 1 observations for that. I'm not very familiar with nlme but I think this causes the error.

Edited to add: looking at the data, your resp variable only has 1 value per participant; thus, you don't have multilevel data. This is most likely what causes the error. You can't have a random effect of participant if you don't have varying observations for each participant.

Also, even if you had varying observations for each participant, it seems to me that day and time would be crossed random effects (not nested), and participant and day would probably also be crossed. So you wouldn't need to use the nested random effect formula but you could (probably) enter all three as separate random effects (if you had enough data & actual multilevel data).

  • $\begingroup$ Thank you for providing your feedback. The reason I chose day and time as random effects is because each subject was observed on a random selection of days. E.g., Subject A was recorded on Sun-Thurs, Subject B was recorded Wed-Sun, Subject C was recorded Thurs, Sat-Tue, etc. Similarly, times selected for different subjects were a random sample. Assuming I had multilevel data, would you recommend using the day and time variables as nested or crossed random effects? $\endgroup$ Commented Apr 4, 2023 at 22:45
  • 1
    $\begingroup$ Ah, now I see! But a random effect in a mixed model does not refer to a variable chosen at random. It refers to a variable that causes some kind of clustering in the data with regards to the outcome variable, such as when your outcome variable is a variable that has been measured several times per participant. In your case, it's not (though you seem to have other variables that have been measured several times per participant, such as the vala etc.). (cont.) $\endgroup$
    – Sointu
    Commented Apr 5, 2023 at 6:29
  • $\begingroup$ cont. Anyways, But if you had measured "resp" 10 times per participant in a design you specified, you probably wouldn't need to put in day and time as random effects, and even if you did (which might be the case if each day and/or time would be somehow "special" in terms of resp values), they would probably be crossed random effects, not nested. Maybe peruse some of the resources for mixed models $\endgroup$
    – Sointu
    Commented Apr 5, 2023 at 6:32
  • $\begingroup$ To clarify the first comment (I kind of jumped over the following point I wanted to make): a random effect in a mixed model refers to a variable that causes some kind of clustering in the data with regards to the outcome variable, and it does not seem your "day" and "time" variables represent such variables, even if you had multilevel data. $\endgroup$
    – Sointu
    Commented Apr 5, 2023 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.