# How to make a diagnostic plot for the regression?

Context

I am interested in LinearModelFit, and would like to make diagnostic plots using Mathematica. I cannot find them in Mathematica document center. For example, the following R program makes diagnostic plots.

R program

x <- c(5,10,15,20,25,30,35)
y <- c(9.4,18.3,26.2,36.3,37.4,47.3,56.3)
dataset <- data.frame(x, y)
fit <-lm(y ~ x, data = dataset)
par(mfrow=c(2,2))
plot(fit)


Question

Would you give me a suggestion on how to achieve this in mathematica ?

Attempt

data = {{5, 9.4}, {10, 18.3}, {15, 26.2}, {20, 36.3}, {25, 37.4}, {30, 47.3}, {35, 56.3}};
lm = LinearModelFit[data, x, x];
Show[ListPlot[data], Plot[lm[x], {x, 0, 40}], PlotRange -> All, Frame -> True]
ListPlot[lm["FitResiduals"], Filling -> Axis]

• ?LinearModelFit – chris Dec 30 '14 at 15:07
• @user25076, you may find this documentation useful – garej Mar 4 '16 at 20:19

Directly from the documentation of LinearModelFit

X = {5, 10, 15, 20, 25, 30, 35}
Y = {9.4, 18.3, 26.2, 36.3, 37.4, 47.3, 56.3}
fit = LinearModelFit[data = Transpose@{X, Y}, {1, x}, x]


(* FittedModel[1.49929 x+3.04286] *)

Show[ListPlot[data], Plot[fit[x], {x, 0, 35}], Frame -> True]


ListPlot[fit["FitResiduals"], Filling -> Axis]


Note that

fit["Properties"]


returns all the available statistics

so that

{#, fit[#]} & /@ Select[fit["Properties"], # != "Properties" &]


should be an endless source of joy and happiness as far as diagnosis is concerned :-)

• @belisarius well you know: 'lies, damn lies and statistics' – chris Dec 30 '14 at 19:30
• @chris, it more looks like a lot of pain... – garej Mar 4 '16 at 20:25