# Regression models with variables from different unit of analyses

This has been a question I have been wondering about for quite some time.

What is the procedure for including variables into a regression that describe different units of analysis?

For example, take the example data below:

Unit1 Unit2         X        Y  C1
1      1     A  8.069306 29.56817  50
2      2     A 57.374125 37.17405  50
3      3     A 28.610334 10.74725  50
4      4     A 11.655329 35.20314  50
5      5     A 55.010888 71.75909  50
6      6     B 86.169210 67.26364 100
7      7     B 96.723271 50.80567 100
8      8     B 80.706313 26.84097 100
9      9     B 91.193207 92.08061 100
10    10     B  3.991037 58.70960 100

X and Y refer to values for Unit1. C1 refers to values for Unit2.

Where, for example, Unit1 refers to individual-level responses and Unit2 are state-level indicators.

This regression equation seems somewhat problematic, given I have repeating values in C1.

Y = a + b(X) + b(C1)

Are repeating values problematic in the regression model? If so, is there a standard approach to dealing with variables describing different units of analyses?

• What are "units"? – Dave Apr 9 '20 at 1:02
• Units refer to unit of analyses. For example, say Unit 1 are individual-level responses and unit 2 are state-level indicators. – Sharif Amlani Apr 9 '20 at 1:17

Welcome to the site, Sharif. This is exactly what multilevel or mixed effects models are used for. You have variables X and Y measured on individual units (Unit1) and variable C1 on group units (Unit2).

The multilevel model partitions the outcome Y into variance that is within Unit2 groups and variance that is between Unit2 groups, and this can be clearly seen in the model equation:

Level 1: $$y_{ij} = \beta_{0j} + \beta1X_{ij} + \epsilon_{ij}$$

Level 2: $$\beta_{0j} = \gamma_{00} + \gamma_{01}C1_j + u_{0j}$$

This model is also called a mixed model, and you can see where this terminology comes from by substituting the level 2 model into the level 1 model:

$$y_{ij} = \gamma_{00} + \gamma_{01}C1_j + \beta1X_{ij} + (\epsilon_{ij} + u_{0j})$$

Note that two error terms are assumed to be normally-distributed with $$\epsilon_{ij}$$ ~ $$N(0, \sigma^2_0)$$ and $$u_{0j}$$ ~ $$N(0, \sigma^2_{u0})$$.

By using the multilevel or mixed effects modeling framework, repeating values of C1 are not a problem and are handled accordingly. Likewise, the random intercept $$\beta_{0j}$$ accounts for correlation in the outcome from getting repeated measures of Y on individual-level units (Unit1) within the same Unit2.

• Awesome! Thank you so much for your helpful response. Do you have an R package you prefer to use when using multilevel or mixed effects? – Sharif Amlani Apr 28 at 4:46
• lme4 is my default. It handles many complicated models and has an ecosystem of packages that work well in conjunction with it. But also worth looking at are nlme, GLMMadaptive, and the glmmTMB packages. If you are interested in running Bayesian version of these models, rstanarm and brms are also great. – Erik Ruzek Apr 28 at 18:15
• Excellent! Your recommendations are extremely helpful! Thank you so much again. – Sharif Amlani Apr 28 at 20:16