Linear Mixed Models assistance I’ll try and keep this as concise as possible. I have a dataset, and I am looking at how Fat mass (y) depends upon physical activity. I have data at years 8, 9,12, and 15, and I am looking to fit a linear mixed model to my data.
Firstly, I performed a box cox transformation so that my data meets the assumptions of a linear model, and the Q-Q plots and the histogram both agree with the assumptions. My first question is do I fit 4 different linear models? ( I have 1,000) participants, or is there a way to combine all of them?
My second, is that I know that the physical activity is my fixed effect, however what are my random effects? I should add that there are other explanatory variables, such as affluence which is a factor (1-5).
I should note that I know how to program to a high standard in r, I’m just struggling to get my head around this. I think I am on the right lines when I understand that each participant provides one data point for each four years, so I guess that my random effect must be 1| participant?
Thanks for this, I’ll give it a shot and see what I can come up with
That seems fairly straightforward, I’ll post my results once I have them.
Cheers

So the data was transformed once the plot of the fitted values was shown to be random,
As for this, I therefore fit a model with 1|participant ? And is it four models that I plot or just the one?
Hello again,
I have managed to sort out my data, and have fitted the following model;
newmodel<-lmer((y8_FMI)^0.38~y8_MVPAper + (y8_MVPAper|Child_ID)

FMI is Fat Mass Index, and I have transformed it to the power according to the Box Cox transformation. MVPAper is the physical activity percentage, and of course is for the year 8 participants. The child ID is for the 1,029 that are participating in this study.
I get the following error: Error: number of levels of each grouping factor must be < number of observations
When I run my code, any ideas why?
 A: The distributional assumptions are concerning the residuals, not the variables themselves. There is no condition/assumption that the variables be normally distributed, so Box-Cox transformations are not needed (at least, not for that reason). The residuals should be tested for normality
As to your experiment, you have repeated measures taken on individuals, so you have clustering, therefore the random effect will be the individual. This is known as random intercepts (because each individual has their own intercept). You could also have random effects for other covariates, so that each individual has their own slope too (random slopes).
In R using lme4 this could look something like:
m <- lmer( y ~ t + (t|individual), mydata)

Here you treat time, t as a continuous variable. If the association is linear, this is great, if it is non-linear you can consider either introducing a quadratic term into the model, or coding the variable separately and have a piecewise-linear model. You don't need to run 4 models, one for each time point.
