2.5 Among- and within-group effects
We may want to simulate the case where a predictor variable varies both within and among groups - in other words it is repeatable at the group level. For example, if we are simulating body mass, we might expect that body mass is a function of an environmental variable, rainfall, and that differs systematically among individuals, as well as within, for example due to spatial variation in where individual lives.
The simplest way of simulating this is as two rainfall variables, one at the level of the individual and one at the level of the observation, something like:
<- simulate_population(
squid_data data_structure=make_structure("individual(100)", repeat_obs=5),
parameters = list(
individual=list(
names=c("between_rainfall"),
...
),observation=list(
names=c("within_rainfall"),
...
),residual=list(
...
)
) )
We can then specify the variation in rainfall within and between individuals, for example, if the repeatability of rainfall amongst individuals is 0.5, and the total variance in rainfall is 0.8, we would make the variance in rainfall 0.4 at each level:
<- simulate_population(
squid_data data_structure=make_structure("individual(100)", repeat_obs=5),
parameters = list(
individual=list(
names=c("between_rainfall"),
vcov=0.4,
...
),observation=list(
names=c("within_rainfall"),
vcov=0.4,
...
),residual=list(
0.8
)
) )
If we want the rainfall variable to have a mean that is not 0, we should specify this in only one place, as otherwise they will add up weirdly!
<- simulate_population(
squid_data data_structure=make_structure("individual(100)", repeat_obs=5),
parameters = list(
individual=list(
names=c("between_rainfall"),
vcov=0.4,
...
),observation=list(
names=c("within_rainfall"),
vcov=0.4,
mean=10
),residual=list(
0.8
)
) )
Now we want to add in some betas. If the effect of rainfall on body mass is causal, we would expect the beta to be the same at both levels - this results as a simple reorganisation of the model equation. We start with an effect of rainfall on body size \[ y_i = \beta_0 + \beta_1 (x_{ij}) + \epsilon_i \] where \(x_{ij}\) is rainfall varying at levels \(i\) (observation) and \(j\) (individual).
We can split rainfall up into within (\(x_{1i}\)) and between (\(u_{1i}\)) individual components:
\[ y_i = \beta_0 + \beta_1 (u_{j} + x_{i}) + \epsilon_i \]
\[ y_i = \beta_0 + \beta_1u_{j} + \beta_{1}x_{i} + \epsilon_i \]
you see that the coefficients should be the same.
<- simulate_population(
squid_data data_structure=make_structure("individual(100)", repeat_obs=5),
parameters = list(
individual=list(
names=c("between_env", "ind_int"),
vcov=c(0.5,1),
beta=c(-2,1)
),observation=list(
names=c("within_env"),
vcov=c(0.5),
beta=c(2)
),residual=list(
vcov=1
)
)
)
<- get_population_data(squid_data)
data $environment <- data$between_env + data$within_env data