# How to test whether changes in x track changes in y over multiple time points for multiple individuals

So I'm wondering how to analyse this data:

I have 30 people. for each person I have 2 normally distributed variables, x and y. I want to see whether x and y are linearly related, but 30 data points isn't that powerful. What might help is that I have x and y for each person over 5 consecutive weeks. So all in all 150 data points. I want to investigate whether changes in x track changes in y over the 5 weeks.

I feel like some sort of multilevel analysis/time series type model would work best, but searching for examples has not been fruitful.

Any advice on how to do this would be greatly appreciated.

• Please expand the question to explain how you collected these data, what the data are, and whether there is expected to be a time effect and if so whether the time effect is expected to vary among subjects – Robert Long Mar 19 '19 at 20:50

I would start by fitting a mixed effects model to these data. I wouldn't really call it multilevel as you don't appear to have grouping factors nested within each other. But this is just semantics and/or a matter of opinion. Clearly measurements are clustered within persons, so you could fit a model such as:

Y ~ X + (1|Subject)


and this will adjust the analysis for observations of one person being more similar to observations of the same person from week to week. i.e. to account for non-independence.

If week is purely a nuisance variable, then you could fit a crossed random effects model:

Y ~ X + (1|Subject) + (1|week)


This is crossed and not nested, since each observation "belongs" to one particular person, but that person does not "belong" to a particular week, and the same applies in vice-versa - an observation also "belongs" to a particular week, but that week does not "belong" to a particular person. More about crossed vs nested random effects can be found here

If the variance at the week level is sufficiently small you could remove it, applying the principle of parsimony, and go back the previous model. A likelihood ratio test could inform this, though clinical/expert domain knowledge should have the last say. This of course does not rule out the possibility of a *systematic' effect of week.

If there is systematic effect of week , then you could also consider either

Y ~ X + week + (1|Subject)


or

Y ~ X + week + (week|Subject)


to allow the "effect" of week to vary across each Subject.

Noting that you have 5 week points, you could code week as a factor, which could potentially uncover non-linearities, though the first of these it would provide 4 coefficient estimates, rather than 1 if you include it as continuous. In the 2nd model including week as a factor would also increase the number of random effects considerably, which could impede model convergence (especially as you have a small dataset) and also impede interpretation. That is, the data may not support that random structure.

There is also the option to allow the effect of X to vary across each Subject, for example:

Y ~ X + week + (X + week|Subject)


Note that in a regression model such as this, X is considered to be fixed, while Y is random - that means there should be no (or negligibly small) measurement error in X. If the situation is reversed then the dependent variable should be X. However if both variables are measured with error then it may be necessary to look at mixed effects model with errors in variables

• Thanks for the detailed response. I wouldn't expect a systematic effect of week on Y, I mainly wanted to include it to increase power of detecting a relationship between X and Y by adding more data points (i.e. including data from all 5 weeks means 5 times more data points than if i only analysed 1 week, which I hope gives me more power). I would expect that X varies with week. Would my power in this case be higher than if I just used ran analyses on a single week? – Richie Mar 19 '19 at 21:49
• Yes, that is correct. However, since you say that X and week are correlated, you should not fit random intercepts for week (see here). The first or third model in my answer would be the way to go. How strong is the correlation, and why are they correlated ? – Robert Long Mar 20 '19 at 20:40
• Thanks for following up, sorry I think I phrased that wrong: X is not correlated with week, but I mean that each value of X for a given person is not the same for each week. Like the values of x for week 1,2,3 etc are different. They do not vary systematically with week, i.e. they are not correlated. Sorry for the confusion. – Richie Mar 22 '19 at 8:47
• @Richie OK, in that case you can go ahead and try fitting random intercepts for week. There may of course, but no variation at the week level, or the data may not support this additional random structure, in which case you can remove it. – Robert Long Mar 22 '19 at 9:27