0

Is Plot residuals vs predicted response equivalent to Plot residuals vs fitted ?

If so, then would be plotted by plot(lm) and plot(predict(lm)), where lm is the linear model ?

Am I correct?

user9802913
  • 245
  • 4
  • 20
  • Yes to your first question. I don't understand the second question. – Roland Dec 10 '18 at 08:33
  • @Roland I meant an _or_ instead of _and_ in the second question. Can residuals vs predicted be plotted using `plot(lm)` ? – user9802913 Dec 10 '18 at 08:39
  • I still don't understand. Anyway, maybe read `help("plot.lm")` and `plot(lm.SR, which = 1)` gives the desired plot. – Roland Dec 10 '18 at 08:46
  • 2
    `plot(predict(lm))` returns a plot of the predicted values vs their index. To plot fitted vs residuals try `plot(predict(lm),residuals(lm))`. `fitted()` and `predict` give the same value for a linear regression model, but not for a generalized linear model, see: https://stackoverflow.com/questions/12201439/is-there-a-difference-between-the-r-functions-fitted-and-predict – Niek Dec 10 '18 at 09:09

2 Answers2

1

Yes, the fitted values are the predicted responses on the training data, i.e. the data used to fit the model, so plotting residuals vs. predicted response is equivalent to plotting residuals vs. fitted.

As for your second question, the plot would be obtained by plot(lm), but before that you have to run par(mfrow = c(2, 2)). This is because plot(lm) outputs 4 plots, one of which is the one you want, i.e the residuals vs fitted plot. The command above divides the output screen into four facets, so each plot will be shown in one. The plot you are looking for will appear in the top left.

Umair Rafique
  • 108
  • 1
  • 9
1

Maybe little off-topic, but as an addition: package named ggfortify might come handy. Super easy to use, like this:

library(ggfortify)
autoplot(mod3)

Yields an output with the most important things you need to know, if your model violates the lm assumptions or not. An example output here:

enter image description here

massisenergy
  • 1,764
  • 3
  • 14
  • 25
  • The plot that is in the right upper corner, is the normal probability plot of residuals r ? – user9802913 Dec 10 '18 at 18:03
  • Yes, the more closely these points follow the straight line, the better is the `lm` (in general). – massisenergy Dec 10 '18 at 18:09
  • @massisenergy, the normal probability plot does not show you if the model is better, at least not in terms of model fit. It is an indication to see if the model residuals follow a normal distribution, which is an assumption of the linear model but a completely separate issue from how well the model performs (i.e. how well it fits the observed data). – Niek Dec 12 '18 at 07:45
  • Thanks for adding that, @[Niek](https://stackoverflow.com/users/6418297/niek), I agree with you. That is more into the performace of the model, but first someone needs to look at these plots to see whether the data is way off from the underlying assumptions. Sorry for the ambiguity in the comment earlier! – massisenergy Dec 12 '18 at 11:39