3
$\begingroup$

How do I specify a model based on panel data using the lmer package in a case where (a) my dependent variable is on the group level and the predictors vary across the group and individual level (b) my dependent variable is on the individual level and the predictors vary across group and individual level?

I have created an example data set to illustrate my question:

Let's imagine we observe a doctor working in a clinic and we have both independent variables and dependent variables on the individual level (doctor) and the group level (clinic).

The "1" (individual) and "2" (group) at the end of each variable label indicate at which level the variable was observed.

da1 <- data.frame(doctor_id1 = c(1,1,1,1,2,2,2,2,3,3,3,3), 
          clinic_id2 = c(1,1,1,1,1,1,1,1,2,2,2,2), 
          period = c("sept19", "oct19", "nov19", "dec19", "sept19", 
                     "oct19", "nov19", "dec19", "sept19", "oct19", 
                     "nov19", "dec19"), 
          clinic_income2 = c(120, 40, 300, 220, 120, 40, 300, 220, 40, 
                             60, 50, 76), 
          doctor_income1 = c(4, 3, 6, 5, 11, 14, 13, 12, 6, 7, 7, 8), 
          n_doctors2 = c(10,10,11,9,10,10,11,9,6,6,6,5), 
          n_diagnosis1 = c(6,8,11,4,5,11,9,3,7,2,6,8))

da1
   doctor_id1 clinic_id2 period clinic_income2 doctor_income1 n_doctors2 n_diagnosis1
1           1          1 sept19            120              4         10            6
2           1          1  oct19             40              3         10            8
3           1          1  nov19            300              6         11           11
4           1          1  dec19            220              5          9            4
5           2          1 sept19            120             11         10            5
6           2          1  oct19             40             14         10           11
7           2          1  nov19            300             13         11            9
8           2          1  dec19            220             12          9            3
9           3          2 sept19             40              6          6            7
10          3          2  oct19             60              7          6            2
11          3          2  nov19             50              7          6            6
12          3          2  dec19             76              8          5            8

My intuition would be to specify the model as follows:

Group-level dependent variable:

summary(reg1a <- lmer(clinic_income2 ~ n_doctors2 + 
                      (n_diagnosis1 | doctor_id1) + 
                      (1 | clinic_id2), data = da1))

or

summary(reg1b <- lmer(clinic_income2 ~ n_doctors2 + n_diagnosis1 + 
                      (1 | clinic_id2/doctor_id1), data = da1))

Individual-level dependent variable:

summary(reg2a <- lmer(doctor_income1 ~ n_diagnosis1 + 
                      (n_doctors2 | clinic_id2) + (1 | doctor_id1), 
                        data = da1))

or

summary(reg2b <- lmer(doctor_income1 ~ n_diagnosis1 + n_doctors2 + 
                      (1 | doctor_id1/clinic_id2), data = da1))   
$\endgroup$

1 Answer 1

4
$\begingroup$

You are on the right track, but there are some key things to keep in mind. In multilevel or mixed models the dependent variable has to be at the lowest level of the hierarchy. In the case of your individual-level dependent variable, doctor_income1, this is actually a repeated measure within the group doctor1. Also, random slopes, which are predictor(s) for which you want to allow their association with the outcome to vary across clusters/groups, must come from the lower level of your hierarchy (i.e., variables ending in _1). So the first model you give for an individual-level dependent variable is not completely right. Instead, you could do the following, which given how you've coded your data is equivalent to your second model:

summary(reg2a <- lmer(doctor_income1 ~ n_diagnosis1 + 
                   (1|clinic_id2) + (1|doctor_id1), data = da1))

In the case where you want to model a group-level (clinic) variable, then you have a couple of options.

  1. In mixed models, the dependent variable cannot be at the higher-level, unfortunately. Accordingly, you can model it as an OLS or GLM regression with the key being to calculate the group mean (and perhaps standard deviation) of each of the _1 variables.
require(dplyr)

da1 <- da1 %>% group_by(clinic_id2) %>% 
  mutate(mn_diag=mean(n_diagnosis1), sd_diag=sd(n_diagnosis1)) %>% 
  ungroup()
da2 <- da1 %>%  distinct(clinic_id2, .keep_all = TRUE) 
    # keep 1 row for each clinic_id2
lm1 <- lm(clinic_income2 ~ n_doctors2 + mn_diag + sd_diag, data=da2)
  1. Use a structural equation modeling program that can accomodate multilevel data. In R, lavaan can do this. Outside of R, Mplus can do this, as can Stata's gsem.
$\endgroup$
3
  • $\begingroup$ Thanks for the detailed answer and the code! Is it really sufficient to use the mean values of the individual-level predictors when modeling the group-level outcome? There seems to be literature arguing that the mean needs to be adjusted in this case? $\endgroup$
    – Scijens
    Commented Feb 6, 2020 at 8:55
  • 1
    $\begingroup$ The best case scenario would be using something like latent decomposition (akin to what happens in lmer for the outcome variable), but this is done only in Mplus to my knowledge. . $\endgroup$
    – Erik Ruzek
    Commented Feb 6, 2020 at 12:50
  • $\begingroup$ Thank you, I will take a look. $\endgroup$
    – Scijens
    Commented Feb 7, 2020 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.