Specifying a mixed model with cross correlations and hierarchies in Lme4 syntax My aim is to predict the quality $y$ of a food product based on measurements $x_a$ and $x_b$ on the main ingredient.
I have several batches of a food product that are evaluated for quality by measurement of $y$. The food product mainly consists of one type of processed ingredient. The properties of the ingredient are evaluated by two measurements $x_a$ and $x_b$ for each batch of ingredient.
Each batch of food product consists of one or more batches of the main ingredient, mixed with known ratios. Each batch of the main ingredient can also be split up into one or more batches of the food product. In addition, the ingredient is sourced from a number of different known suppliers.
How do I formulate the model I need in lme4 syntax?
My own best effort so far is:
lmer(y ~  x_a +  x_b + (x_a|ingredient batch/supplier)  + (x_b|ingredient batch/supplier))

However, I'm unsure about how to include the information from mixing ratios?

The model:
y ~  x_a +  x_b + (x_a|ingredient_batch/supplier)  + (x_b|ingredient_batch/supplier)

has the following features:

*

*fixed effects for x_a and x_b

*random intercepts for ingredient_batch and random intercepts for supplier varying within levels of ingredient_batch`

*random slopes for x_a within both ingredient_batch and supplier

*random intercepts for ingredient_batch and random intercepts for supplier varying within levels of ingredient_batch` (for the 2nd time)

*random slopes for x_b within both ingredient_batch and supplier
This random structure is almost surely not what you want.
For one thing it fits the random intercepts twice which will likely lead to convergence issues.
If the intention is that the random slopes for x_a and x_b are uncorrelated, then a simple change may suffice:
y ~  x_a +  x_b + (x_a|ingredient_batch/supplier)  + (0 + x_b|ingredient_batch/supplier)

where we use 0 +  on the right side of the second | in order to suppress the second set of random intercepts.
On the other hand if you intend the the random slopes for x_a and x_b are correlated, then a simple change may suffice:
y ~  x_a +  x_b + (x_a + x_b|ingredient_batch/supplier)

I would, however, think carefully about whether this is justified (provided that it is supported by the data).
As for the mixing ratios, I would assume that these should be included as further fixed effects.
