I am learning to use the
nlme package to fit a multilevel model in R, and I want to be sure that I am specifying the model correctly.
My response variable is cortisol levels measured over several years for many individuals (sample collection was opportunistic, so the time intervals between samples are variable). These are my predictors:
- Gender (binary, individual level predictor)
- Age (in years, varies within individuals)
- Disease (binary, varies within individuals)
- Pregnancy (binary, varies within females but always 0 for males)
- Temperature (continuous, varies within individuals)
- Rainfall (continuous, varies within individuals)
I also know from past work that interactions between Gender:Age and Temperature:Rainfall should be included. I want to allow random intercepts among individuals, and I want to account for the temporal autocorrelation of samples within individuals. I am specifying my model like this:
lme(cortisol ~ sex + age + sex:age + disease + pregnancy + temperature + rainfall + temperature:rainfall, random=~1|ID, correlation=corCAR1(form=~Date|ID))
Is my specification of this model correct?
Also, is it a problem that one of my variables (pregnancy) only applies to a subset of my data (females)?