I have 1000 individuals with measurements of plasmatic HDL levels over the last 15 years. The number of measurements per individual ranges from 1 to 15, and were not taken in the same dates. I would like to compare the HDL levels (quantitative trait) over time in the individuals and make a ranking of those individuals whose HDL levels are consistently the highest over time. I want to adjust for sex and Tanner (categorical variable related to puberty development, it can be 1,2,3,4 or 5).
I have a data.frame (data) with 5 columns: ID (individual ID
), HDL
, Age
(at the time of measurement), Sex
and Tanner
. This is a data frame with a toy example:
ID HDL Age Sex Tanner
1 50 12.3 M 2
1 52.1 15.4 M 4
1 55.3 17.1 M 5
2 45 12.1 M 1
2 46.3 13.1 M 1
3 60 14.3 F 3
3 55 16.2 F 5
... ... ... ... ...
This is the model I figured out:
library(lme4)
model = lmer(HDL ~ Age + Sex + (1|Tanner) + (1|ID), data)
Age
and Sex
are my fixed variables and I expect to adjust for variation between Tanner
. Individuals of the same Tanner
should have more similar HDL
values for reasons other than Age
and Sex
.
After running the regression, I extract the intercept and slope from each individual using coef(data)$ID
. Then, I multiply each intercept by the corresponding slope and get the final value I will use for the ranking.
Is my reasoning correct?