Get the design matrix from a linear mixed model

2 vues (au cours des 30 derniers jours)
Armand Mensen
Armand Mensen le 4 Nov 2016
When running a linear mixed model, using the fitlme function...
formula = 'dependent ~ predictor1 * predictor2';
model_object = fitlme(dataset, formula);
... you can extract the design matrix after you have run the model using the following code:
% get fixed effect design
design_fixed = designMatrix(model_object, 'fixed');
However, I'd rather not have to run the whole model every time I want to just get the design matrix. So I'm looking for a function that will output the design matrix given the dataset table and the formula used in the model. For example:
design_matrix = designFromFormula(formula, dataset, dummyvarcoding);
Precisely such a function already exists buried deep within the 'LinearMixedModels.m' at line 1392; but this function is private so I cannot access it. Nor can I re-engineer exactly what it is doing.
Does someone know how I could use this private function, or have another way to 'extract' the design matrix for a linear mixed model (just the fixed effects to be specific), without having to actually estimate the model?
Thank you!

Réponses (1)

Xue Zhang
Xue Zhang le 7 Mai 2021
Hi I am also looking for a such solution, have you figured out how to implment designFromFormula?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by