How to obtain residuals after using 'fitrm'?

5 views (last 30 days)
Maria Garcia Garrido
Maria Garcia Garrido on 23 Sep 2024
Answered: dpb on 23 Sep 2024
Hello,
I have been trying to obtain the residuals after using 'fitrm' with this formula: 'VarLeft-VarRight~Group', so that I can test for normality and outliers, but I haven't found a way of doing this on MATLAB. I was wondering if anybody knows how to do this?
Thanks!

Answers (1)

dpb
dpb on 23 Sep 2024
It doesn't seem as they have implemented it directly; you'll have to compute the residuals as the difference between the resulting model prediction and the input data at the desired data points...
There's an example for the Fisher iris data set that doesn't specifically compute the residuals themselves, but calculates the predicted values and plots them in comparison to the input data...just follow its lead...
load fisheriris
t = table(species,meas(:,1),meas(:,2),meas(:,3),meas(:,4), ...
'VariableNames',{'species','meas1','meas2','meas3','meas4'});
Meas = dataset([1 2 3 4]','VarNames',{'Measurements'});
rm = fitrm(t,'meas1-meas4~species','WithinDesign',Meas);
Yhat=predict(rm,t([1 51 101],:))
Yhat = 3×4
5.0060 3.4280 1.4620 0.2460 5.9360 2.7700 4.2600 1.3260 6.5880 2.9740 5.5520 2.0260
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y=t([1 51 101],[2:end])
Y = 3x4 table
meas1 meas2 meas3 meas4 _____ _____ _____ _____ 5.1 3.5 1.4 0.2 7 3.2 4.7 1.4 6.3 3.3 6 2.5
Res=Y-Yhat
Res = 3x4 table
meas1 meas2 meas3 meas4 ______ _____ ______ ______ 0.094 0.072 -0.062 -0.046 1.064 0.43 0.44 0.074 -0.288 0.326 0.448 0.474
Use your data a results similarly...

Community Treasure Hunt

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

Start Hunting!