[R] Calculation of r squared from a linear regression

From: Sandra Hawthorne <sandra_d_hawthorne_at_yahoo.com.au>
Date: Fri, 11 Jun 2010 01:16:31 -0700 (PDT)


Hi,

I'm trying to verify the calculation of coefficient of determination (r squared) for linear regression. I've done the calculation manually with a simple test case and using the definition of r squared outlined in summary(lm) help. There seems to be a discrepancy between the what R produced and the manual calculation. Does anyone know why this is so? What does the multiple r squared reported in summary(lm) represent?

# The test case:

x <- c(1,2,3,4)
y <- c(1.6,4.4,5.5,8.3)
dummy <- data.frame(x, y)
fm1 <- lm(y ~ x-1, data = dummy)
summary(fm1)
betax <- fm1$coeff[x] * sd(x) / sd(y)
# cd is coefficient of determination

cd <- betax * cor(y, x)

Thanks.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 11 Jun 2010 - 08:19:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Jun 2010 - 10:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive