Spaghetti plot for linear regression models

19 visualizaciones (últimos 30 días)
David Obert
David Obert el 20 de Dic. de 2023
Respondida: the cyclist el 20 de Dic. de 2023
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?

Respuesta aceptada

the cyclist
the cyclist el 20 de Dic. de 2023
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).

Más respuestas (0)

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by