Likelihood ratio test for random intercept (MATLAB) I need to program a likelihood ratio test for testing the significance of a random effect in a linear mixed model in MATLAB. But I am having some trouble finding out how to correctly specify the null model.
Here is the code for the full model:
model_h1 = fitlmematrix(X, y, Z, G);

where X is the fixed effect design matrix, y is the response vector, Z is a column vector of ones with length equal to the number of rows in X, and G is a grouping variable for the random effect. Here is the model formula written in fitlme syntax:
model_h1 = fitlme(data, y ~ x1 + x2 + x3 + x4 + x5 + (1|G))

My goal is to test the significance of the random intercept term (1|G), for example using the compare method (e.g. compare(model_h0, model_h1)). But what would be the correct syntax for the null model here? Intuitively I would guess the null model should be a model with the fixed effects included, without the random intercept (a general linear model). But I don't think this would be supported by the compare function. Is there a way of generating a LinearMixedModel object which does not include any random effects?


Is there a way of generating a LinearMixedModel object which does not include any random effects?

I am not a MATLAB expert, and programming questions are off-topic here anyway (so you might try asking that on a MATLAB programming site), but a model without random effects is not a mixed effects model, so from that point of view it may not be possible.
The standard approach with a platform such as R is simply to fit the the linear model and compare that to the mixed model directly with a likelihood ratio test (since these are nested models)
model1 <- lmer(Y ~ X + (1|G), mydata)
model2 <- lm(Y ~ X, mydata)
anova(model1, model2)

However, the LRT of a variance parameter equalling zero is conservative (larger p-value). This is due to the test being on a boundary condition, since a variance cannot be negative). In linear mixed models with a single random intercept term, this p-value is approximately twice as large as it should be.
Other options for testing the significance of a random effect are profiled confidence intervals, the exact LRT test and the parametric bootstrap.
