1

Plot with residual I have a plot that has residuals vertically dashed to the regression line. I also am using the function resid to derive all residuals. I am not entirely sure what good is finding residuals. Someone please explain and show an example.

library("MASS")     # data
survey              # data

plot(survey$Height ~ survey$Wr.Hnd, xlab = "Writing Handspan (cm)", ylab = "Height (cm)")

survfit <- lm(Height ~ Wr.Hnd, data = survey)
survfit

abline(survfit, lwd = 2)
resid(survfit)    # residuals

obsA <- c(survey$Wr.Hnd[197], survey$Height[197])
obsA

obsB <- c(survey$Wr.Hnd[154], survey$Height[154])
obs

mycoefs <- coef(survfit)
mycoefs

beta0.hat <- mycoefs[1]
beta1.hat <- mycoefs[2]


segments(x0 = c(obsA[1],obsB[1]), 
         y0 = beta0.hat + beta1.hat * c(obsA[1], obsB[1]),
         x1 = c(obsA[1], obsB[1]), y1 = c(obsA[2], obsB[2]), lty = 2)

# residual dashed vertical line
kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
Jacob
  • 11
  • 1
  • 1
    Linear regression makes assumptions about your data, some of which can be tested by analysing the residuals. Search online for "linear regression assumptions residuals". [Here is one useful tutorial](https://towardsdatascience.com/assumptions-of-linear-regression-algorithm-ed9ea32224e1). This is more a statistics than a programming question. – neilfws Oct 08 '19 at 03:13
  • Sometimes the residual plots can highlight problems with the regression model or data. For example, if there is an obvious pattern to the residuals then the model might be incomplete or incorrect - such as fitting data that lies on a curved parabola to a straight line. Or if the errors were tightly grouped on only one part of the plot that indicates heteroskedastic rather than normally distributed errors. – James Phillips Oct 08 '19 at 09:59
  • possible dups: https://stats.stackexchange.com/questions/307221/why-residual-plots-are-used-for-diagnostic-of-glm, https://stats.stackexchange.com/questions/438101/why-we-do-acf-on-residuals, https://stats.stackexchange.com/questions/62306/analyzing-residual-plot-vs-independent-variables-plot, https://stats.stackexchange.com/questions/77591/why-some-people-test-regression-like-model-assumptions-on-their-raw-data-and-oth, https://stats.stackexchange.com/questions/337879/why-do-we-use-residuals-to-test-the-assumptions-on-errors-in-regression – kjetil b halvorsen Feb 07 '20 at 01:21

0 Answers0