2
$\begingroup$

stats/stackexchange novice here i'm afraid. I've got a data set which I believe a multilevel linear model will suit nicely but i'm struggling with a) whether this is the right technique and b) how to approach formulating the model in R.

The data consist of: Id of individual, for each individual there's 2 time points ('Period': day vs night), x and y variables (which are linearly related) and a group (1 vs 0).

I want to test whether the relationship between x and y is different during the day vs night, and whether the group has any effect on the day-night changes (interaction?).

Here's what i've tried so far (ignoring group for now):

a<-lme(y~x*Period, data=d, random= ~x|Individual, method="REML")

How far off is this? Am I right in thinking that x and Individual are random effects with x nested in Individual? or have I misunderstood this?

Apologies for the messy post - hopefully enough information is here!

Any help appreciated. Thanks!

$\endgroup$
  • $\begingroup$ In $\texttt{lme}$ the random part should be specified like $\texttt{variable | group}$, so for a random effect of $x$ per individual you should write $\texttt{random=~x|Individual}$. However, this model does not fit an interaction between $x$ and period. $\endgroup$ – Sanderr Apr 6 '18 at 12:21
  • $\begingroup$ Thanks Sanderr, edited now. I am a little confused at what should be random effects now - should Period also be a random effect? $\endgroup$ – EdH Apr 6 '18 at 13:23
  • $\begingroup$ I am not too sure what to suggest, I think this depends on the way you want to model things. You use a random effect for a variable when you assume that the effect of your variable differs over clusters (individuals, in this case). It helps in correctly estimating a parameter's variance when dealing with correlated data. So I believe you should ask yourself how you want to model this. For your second question, you should look into adding a $\texttt{group*period}$ term. $\endgroup$ – Sanderr Apr 6 '18 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.