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

3 views (last 30 days)
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!

Answers (0)

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!