[R] how to calculate Rsquare

Ronaldo Reis Jr. chrysopa at insecta.ufv.br
Mon Jul 21 17:46:46 CEST 2003


Hi,

I have something like this:

> x <- 1:10
> y2 <- 30+5*x+rnorm(x,sd=3)
> y <- c(y1,y2)
> x <- c(x,x)
> plot(x,y)
> x <- 1:10
> y1 <- 1+5*x+rnorm(x,sd=2)
> y2 <- 30+5*x+rnorm(x,sd=5)
> y <- c(y1,y2)
> x <- c(x,x)
> f <- factor(rep(c("a","b"),c(10,10)))
> m <- lm(y~x+f)
> anova(m)
Analysis of Variance Table

Response: y
          Df Sum Sq Mean Sq F value    Pr(>F)    
x          1 4062.9  4062.9  400.04 2.990e-13 ***
f          1 4421.5  4421.5  435.35 1.496e-13 ***
Residuals 17  172.7    10.2                      
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 
> #rsquare of model
> (4062.9+4421.5)/(4062.9+4421.5+172.7)
[1] 0.980051

In this way I calculate the model rsquare, but how to calculate the rsquare of  
each levels "a" and "b"?

This is only an example, the model maybe glm, lme etc.

Thanks
Ronaldo 
-- 
NOWPRINT. NOWPRINT. Clemclone, back to the shadows again.
- The Firesign Theater
--
|>   // | \\   [***********************************]
|   ( õ   õ )  [Ronaldo Reis Júnior                ]
|>      V      [UFV/DBA-Entomologia                ]
|    /     \   [36571-000 Viçosa - MG              ]
|>  /(.''`.)\  [Fone: 31-3899-2532                 ]
|  /(: :'  :)\ [chrysopa at insecta.ufv.br            ]
|>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ]
|    ( `-  )   [***********************************]
|>>  _/   \_Powered by GNU/Debian Woody/Sarge




More information about the R-help mailing list