On Mon, 3 Nov 2008, J. Sebastian Tello wrote:

Does anyone know of a literature reference, or a piece of code that can help me calculate the amount of variation explained (R2 value), in a regression constrained to have a slope of 1 and an intercept of 0?


Sebastien,

In the future, please follow the posting guide or use help.request() to craft a better posting to this list.

Something like this is what you are after?

x <- rnorm(100)
y <- rnorm(100,x)
# unexplained
sum(residuals(lm(y~0+offset(x)))^2)/sum(y^2)
[1] 0.500178
(sum(y^2) - sum( residuals( lm(y~0+offset(x)) )^2))/sum(y^2)
[1] 0.499822


Of course, I could have finessed the use of lm(), but why pass up an opportunity to show how the formula language handles this?

---

Be advised that this (fixing values of coefficients in tow models and then comparing them) is a tricky business.

You can get 'explained' values that are not in [0,1], which is a source of confusion to many. You can use

        RSiteSearch("R2 intercept")

to find threads on this.

The usual distribution theory for nested linear models does not apply. (Read: do not try to compute a p-value unless you have the assistance of a statistician who can explain this sentence.)


HTH,

Chuck



Thanks!

Sebastian

J. Sebasti?n Tello


Department of Biological Sciences
285 Life Sciences Building
Louisiana State University
Baton Rouge, LA, 70803
(225) 578-4284 (office and lab.)




        [[alternative HTML version deleted]]



Charles C. Berry                            (858) 534-2098
                                            Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]                  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

______________________________________________
R-help@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.

Reply via email to