Multilevel/Split-plot model: Documentation error in covariancePattern.m?
Mostrar comentarios más antiguos
Hello,
I try to understand the implementation of nested effects and split plot designs in Matlab.
Is there a mistake in the official description of the fertilizer examples?
I compared
vs
I noticed that the equations derived from the Wilkinson notations are not consistent. For fitlme it seems correct, but for covarianceParameters the term for (1|Soil) is missing, isn't it? I expected it would also be represented by a term b_0k in the equation for the dependent variable y_ijk.
Furthermore, what does the Term b_0k*S_k mean in this case? I thought the term b_0k represents the intercept variance (for the random soil effect) and is a random number drawn from its corresponding normal distribution N(0,sigma_S^2). But it seems to be multiplied with another factor S_k which represents soil type and is a categorical?
Best regards
1 comentario
AI confirms that you have spotted two real documentation errors (typos) in the MathWorks covarianceParameters page, and your intuition about the mathematical notation is spot on.
You should report it to
to get confirmation from "human" TMW employees.
Here is a breakdown of both issues in the documentation.
1. The Missing Term (and Mismatched Fixed Effects) in covarianceParameters
In the covarianceParameters example, the code runs the following formula:
matlab
lme = fitlme(tbl,"Yield ~ Fertilizer + (1|Soil) + (1|Soil:Tomato)");
However, the mathematical equation written right above it is:
There are two typos in this documentation equation compared to the MATLAB code:
- Missing (1|Soil) term: Just as you expected, the random intercept for soil
is missing from the formula, even though the text right below it explicitly defines its prior distribution
and the code includes (1|Soil). - Wrong fixed effect variable: The code specifies Fertilizer as the fixed effect, yet the equation sums over
instead of Fertilizer
.
A corrected equation matching the code on that page should look like:
2. What Does
Mean in the fitlme Example?
In the fitlme documentation, the equation is written as:
Your understanding is completely right:
is already a scalar random realization drawn from
for the k-th soil type. You do not multiply a random effect by a categorical label.
Here is why MathWorks wrote it that way (and why it is slightly abused notation):
- What it actually means: In matrix notation (
), the random-effects design matrix Z consists of dummy/indicator variables (0s and 1s) that "turn on" the specific random effect
belonging to soil k. - Why it's confusing: In the fitlme text, MathWorks states: "
represents the k th soil type". Strictly speaking,
should either be defined as a dummy indicator variable 1 if observation i is in soil k, 0 otherwise, summed over
, or if k is already fixed as the index of the observation's soil type (as in
), you simply write
without
. Multiplying
by a categorical factor makes no mathematical sense—MathWorks informally wrote
next to
just as a label to remind the reader which grouping factor
belongs to.
Summary of How MATLAB Actually Evaluates It
When you run fitlme(tbl, "Yield ~ Fertilizer + (1|Soil) + (1|Soil:Tomato)"), MATLAB constructs:
- Fixed effects (\(X\)): Intercept + 3 dummy columns for Fertilizer (4 levels total).
- Random effects (\(Z\)):
- 3 dummy columns for Soil (corresponding to
). - 15 dummy columns for the Soil:Tomato combinations (3 soils × 5 tomatoes, corresponding to
).
Respuestas (0)
Categorías
Más información sobre Agriculture en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!