How to plot discrete variables in a linear model interaction using 'fitlm' and 'plotInteraction'?

조회 수: 4 (최근 30일)
Hi, I have a problem plotting the interaction of two variables in a linear model.
One of the variables (Diagnosis) has only 2 unique integer values, e.g. [0,1]. The other variable (Age) has many different values.
I created a model for a third variable, ImagVar, using the 'fitlm' function:
DT=dataset(Age,Diagnosis,ImagVar,'Varnames',VarNames);
mdl = fitlm(DT,'interactions','RobustOpts','on');
Then I plot them as:
plotInteraction(mdl,'Diagnosis','Age','predictions');
The problem is that the resulting plot yields three lines: a red one for the '0' value of diagnosis, a purple one for the '1' value, and a yellow one for a value '0.5'.
I do not have any '0.5' value in my 'Diagnosis' variable, is there any way to plot only two lines (the red and the purple)?
Also, when I do the same but with 'Diagnosis' containing 3 non-sequental unique integer values, e.g. [0 1 4], the resulting plot yields a red line for the '0' value, a purple line for the '4' value and a yellow line for a value of '2', instead of the wanted value of '1'.
Thanks in advance!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by