I am trying to analyze a dataset in which there are three measures on patients within areal units, however I am having trouble in how I am thinking about random/fixed effects and including covariates at different levels of the model.
Dataset
Dependent variable:
- Presence of disease (1=Yes, 0=No)
Independent variables:
- Disease indicator (1=Disease 1, 2=Disease 2, 3=Disease 3)
- Patient age
- Patient race/ethnicity
- Patient sex
- Areal unit exposure
Example of my data:
ArealID | PatientID | DV | DV_Indicator | Patient_Age | Patient_Race | Patient_Sex | ArealExposure
A | 0001 | 1 | 1 | 57 | White | Male | 5
A | 0001 | 0 | 2 | 57 | White | Male | 5
A | 0001 | 0 | 3 | 57 | White | Male | 5
A | 0002 | 1 | 1 | 43 | White | Female | 5
A | 0002 | 1 | 2 | 43 | White | Female | 5
A | 0002 | 0 | 3 | 43 | White | Female | 5
A | 0003 | 0 | 1 | 60 | Black | Male | 5
A | 0003 | 0 | 2 | 60 | Black | Male | 5
A | 0003 | 0 | 3 | 60 | Black | Male | 5
... | ... | ...| ... | ... | ... | ...
Z | 5678 | 1 | 1 | 77 | Black | Female | 12
Z | 5678 | 1 | 2 | 77 | Black | Female | 12
Z | 5678 | 1 | 3 | 77 | Black | Female | 12
Z | 5679 | 1 | 1 | 70 | White | Female | 12
Z | 5679 | 0 | 2 | 70 | White | Female | 12
Z | 5679 | 1 | 3 | 70 | White | Female | 12
Z | 5680 | 0 | 1 | 64 | Hispanic | Male | 12
Z | 5680 | 1 | 2 | 64 | Hispanic | Male | 12
Z | 5680 | 0 | 3 | 64 | Hispanic | Male | 12
Note that the areal exposure is the same within each areal unit and that patient age, race, and sex are the same within each patient.
Model specification
I am trying to specify my model using the glmer
function in the lme4
package in R.
Since I have multiple observations per patient and multiple patients in each areal unit, I am specifying my model as:
m1 <- glmer(DV ~ DV_Indicator + Patient_Age + Patient_Race + Patient_Sex + ArealExposure + (1 | ArealID/PatientID), data=mydata, family=binomial)
If I understand the syntax correctly, this model should have random intercepts for both patients and areal units, but I am not sure that I have included the variables correctly since they all seem to be included at the disease level (rather than patient or areal unit).
The way I thought to indicate which level each variable should be included at was like this:
m2 <- glmer(DV ~ DV_Indicator + (1 + Patient_Age + Patient_Race + Patient_Sex | PatientID) + (1 + Areal_Exposure | ArealID), data=mydata, family=binomial)
but I think this is actually including these terms as random slopes(?). I have had trouble finding clear examples of this since it seems many people mix using other packages with lme4