Spaghetti plot for linear regression models

14 ビュー (過去 30 日間)
David Obert
David Obert 2023 年 12 月 20 日
回答済み: the cyclist 2023 年 12 月 20 日
I have 6 subjects which got tested 10 times (repeated measure). So in total I have 60 values. I used the fitlme function to fit a quadratic model with random intercept and random slope (Formula: Y ~ 1+ TestNumber + TestNumber^2+ (1 + TestNumber|SubjectID)). Now I want to create a spaghetti plot with all values, the predicted model for each subject und the final model with the 95% CI. I already managed to plot the values and the final model with the 95% CI, but how do I calculate the individual models? Do I have to consider random and fixed effects?

採用された回答

the cyclist
the cyclist 2023 年 12 月 20 日
In the model you describe, you are not interested in this specific subjects, but consider them to be a random draw from a representative population. I would not say that there is a "predicted model for each subject" -- there is one model that has been fit using data from those subjects.
That being said, the model does capture each subject's random deviation from the mean intercept and mean slope. You can get these as follows:
[B,Bnames] = randomEffects(mdl); % where "mdl" is whatever you called your model object
If you wanted to plot the modeled trajectory for these subjects, then you'd add each subject's random effect (different for each subject) to the overall fixed effect (the same for all subjects). Then, using those coefficients, you can plot over the whole range of TestNumber (your independent variable).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConditional Mean Models についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by