Get the design matrix from a linear mixed model
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
Xue Zhang
2021-5-7
Hi I am also looking for a such solution, have you figured out how to implment designFromFormula?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!