I was trying to understand how the calculations are done behind lm() function in R using mtcars dataset. I understand that lm() function minimizes the sum of the squared residuals to get the best fit line. Now the summary() done on that fit gives coefficient which includes: the intercept, slope, standard error, t-statistic, and P-value.

Suppose I fit a regression line with the mtcars dataset using 2 different approaches:

  • when I don't shift the x=wt axis

    g <- ggplot(data=mtcars, aes(x=wt,y=mpg))
    g <- g+geom_point(size=2, color="blue", alpha=0.4)
    g <- g+geom_smooth(method = "lm")
    g <- g+ggtitle("Normal")
    g <- g+labs(x ="wt", y = "mpg")

    enter image description here

  • when I center the x=wt axis first:

    g <- ggplot(data=mtcars, aes(x=c(wt-mean(wt)), y=mpg))
    g <- g+geom_point(size=2, color="red", alpha=0.4)
    g <- g+geom_smooth(method="lm")
    g <- g+ggtitle("Shifted")
    g <- g+labs(x="wt", y="mpg")

    enter image description here

So it is evident from the plots that the:

  • Slopes are same (I understand that)
  • intercepts change due to shifting of x-axis (I understand that)
  • But the intercept's standard error in summary(fit) changes (I don't understand this)

Does it mean, the standard error outputted by the summary() function is the standard error in the response only at that x-value? and that this standard deviation will be different at different predictor values?

[1]: https://i.stack.imgur.com/KW

enter image description here

  • 1
    $\begingroup$ I think you will find the information you need in the linked thread. Please read it. If it isn't what you want / you still have a question afterwards, come back here & edit your question to state what you learned & what you still need to know. Then we can provide the information you need without just duplicating material elsewhere that already didn't help you. $\endgroup$ – gung - Reinstate Monica May 6 '17 at 16:43
  • $\begingroup$ Thank you gung. It clears all my doubt now. Much appreciated. $\endgroup$ – Piyush Verma May 6 '17 at 17:02
  • $\begingroup$ You're welcome, @PiyushVerma. +1, although this is a duplicate, it is a good & clear question. $\endgroup$ – gung - Reinstate Monica May 6 '17 at 17:06