R^2 of regressed line fitted through origin


#1

Hi All,

It seems that R is giving the wrong R^2 while regression line fitted through the origin. I have used the attached data.
It is giving R^2=0.98 of the line fitted through the origin but I have verified using excel and other software, it should be 0.72.

R code:

lmfit2 <- lm( y ~ x-1 , data = datafm)
summary(lmfit2)

Thanks
Chandan


#2

Hi there! In order to help you more, we need you to make a Reproducible Example, or reprex for short. You can learn more about making one here:

In particular, to figure out why you're getting different results between R and other software, we need access to the data frame you're working with, datafm. You might also want to check out this post on prepping your data for a reprex:


#4

Roughly when you regress without the constant the lm() model reports something else instead of the R-squared (changes what it reports). I have some notes here http://www.win-vector.com/blog/2017/06/an-easy-way-to-accidentally-inflate-reported-r-squared-in-linear-regression-models/ . The fix is to compute your own correct R-squared outside of the model. (yes one can try an argue what is being computed is or is not whatever, but it isn't the same metric computed in other circumstances)


#5

Hi JohnMount, I think you are right. I have tried lm( y ~ 0 + x , data = datafm), still the R^2 value is same.