1
$\begingroup$

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
$\endgroup$
3

0

Browse other questions tagged or ask your own question.