# Is the syntax of my mixed-effects model correct?

I am having trouble figuring out the proper syntax for my experiment's mixed effect model.

I used the Cosinor package in R to determine the amplitude value of each participant, based on heart rate per day across a 24 hour period.

• Data was collected for every day for 6 weeks per subject.

My data looks like this:

User.ID    HR       Weekday YearDay  MESOR       amp       acr    Group    TimePoint
39584  71.90667     Sat     300    84.71963  2.021602 -5.172755  Decrease      POST
23490  94.12552     Fri     131    86.28663 12.085945 -1.662759  Decrease      POST
39085  111.63322    Tue     296    112.87266 18.368315 -1.316736 Decrease      POST
24138  68.08333     Tue     156    87.90074  9.807492 -3.470958  Decrease      POST
23490  77.02765     Thu     151    102.51004 12.616990 -3.576744 Decrease      POST

• There are Pre and Post timepoints, and there are either Increase or Decrease per group assignment.

My goal is to determine if amplitude (amp - from the cosinor() function output) is predicted by group, timepoint, and day of the week.

So my simple model is:

simple.model <- lm(amp ~ Group * TimePoint + Weekday, data = DF)


For my mixed model, I added a user random effect, so:

mixed.model <- lmer(amp ~ Group * TimePoint + Weekday + (1 | User.ID), data = DF)


My questions are:

1. How do I control/model for the weekday?
• Is it nested, because each user perceives the same weekday differently, or is it crossed, because Monday to me, is Monday to you?
2. Can I add a random slope, in which case should it be for TimePoint (pre vs postcondition)?
• Although, since Pre/Post is only two levels, it shouldn't be random?

• The simple linear regression model (fitted by lm()) does not account for the correlations in the repeated measurements of each subject.
• The second model is a linear mixed model with a random intercept for subject (variable User.ID). This random-effects structure postulates that the correlations between any two repeated measurements over time of the subject are equal. E.g., the correlation between the amplitude values of Monday and Tuesday is equal to correlation between Monday and Friday.
• If you want to assume that amplitude measurements from the same participants on the same weekday are more correlated than measurements on different weekdays, then you will need to include a random intercept for Weekday grouping factor nested with User.ID.
• If instead, you want to assume that amplitude measurements on the same weekday are correlated even if they come from different participants, then you will need to include Weekday as a crossed random effect.
• So then if I want to incorrporate your third and fourth points into my model, would this be correct (where timeV is the 0-42 day time variable you mention)? Improved.mixed.model <- lmer(amp ~ Group * TimePoint + Weekday + (1 + TimeV|User.ID) + (1 | Weekday/User.ID), data = DF) – Shai Dec 17 '19 at 19:33