I have a longitudinal dataset with 5 repeated measures, where individuals are nested within counties and may have moved to a new county during the study period, e.g.,
> df
# A tibble: 15 × 4
ID wave county Y
<dbl> <dbl> <chr> <dbl>
1 1 1 A 0
2 1 2 A 0
3 1 3 A 0
4 1 4 B 0
5 1 5 B 1
6 2 1 B 1
7 2 2 B 1
8 2 3 B 0
9 2 4 B 1
10 2 5 B 1
11 3 1 B 0
12 3 2 B 0
13 3 3 C 0
14 3 4 C 0
15 3 5 C 0
As such, I understand this to be multiple membership data with repeated measures, with a structure like:
Similar to this question here (longitudinal cross membership multilevel model), I am struggling with the best way to organize the data for analysis. I am planning on using the brms package in R to fit a multilevel model that accounts for the clustering of observations within individuals, and individuals within (multiple) counties. However, all documentation that I have found for multiple membership multilevel models using brms (e.g., https://cran.r-project.org/web/packages/brms/vignettes/brms_multilevel.pdf) require the data to be in wide format, like this:
> df
# A tibble: 3 × 7
ID county1 county2 county3 county4 county5 Y
<dbl> <chr> <chr> <chr> <chr> <chr> <chr>
1 1 A A A B B ?
2 2 B B B B B ?
3 3 B B C C C ?
.. where county1 is the first county an individual lived in, county 2 is the second, etc., which allows you to fit the model with code like:
model <- brm(Y ~ 1 + (1 | mm(county1, county2, county3, county4, county5)), data = df)
However, I am confused about how to incorporate the repeated measures within such data format (and model code). I've thought about simplifying the model, and simply including random effects for county and for individual (i.e., ignoring the multiple membership piece), but I'm worried this would lead to biased estimates. Any help would be appreciated!