[R] lm without intercept, false R-squared

2012-06-27 Thread Christof Kluß
Hi

is there a command that calculates the correct adjusted R-squared, when
I work without intercept? (The R-squared from lm without intercept is
false.)

Greetings
Chrsitof

__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Uwe Ligges



On 27.06.2012 09:33, Christof Kluß wrote:

Hi

is there a command that calculates the correct adjusted R-squared, when
I work without intercept? (The R-squared from lm without intercept is
false.)


Then we need your definition of your version of correct - we know the 
definition of your version of false.


Best,
Uwe Ligges




Greetings
Chrsitof

__
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.



__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Mikko Korpela
On 06/27/2012 10:33 AM, Christof Kluß wrote:
 Hi
 
 is there a command that calculates the correct adjusted R-squared, when
 I work without intercept? (The R-squared from lm without intercept is
 false.)

Hi! This answer in R-FAQ might help you:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f

-- 
Mikko Korpela
Aalto University School of Science
Department of Information and Computer Science

__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread peter dalgaard

On Jun 27, 2012, at 09:33 , Christof Kluß wrote:

 Hi
 
 is there a command that calculates the correct adjusted R-squared, when
 I work without intercept? (The R-squared from lm without intercept is
 false.)

When people say that, they are usually implying that a correct R-squared can 
be negative!

If for some reason you want to use an alternative *definition* of R^2, it 
should be easy enough to calculate it yourself, e.g. (if the proportion 
reduction in variance is wanted):

Y - rnorm(100, 10, 1)
x - 1:100
(var(Y) - summary(lm(Y~x-1))$sigma^2)/var(Y)

(comes out as -31 or so)


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Christof Kluß

for example the same model with intercept R² = 0.6, without intercept R²
= 0.9 and higher. In my definition of R², R² has to be equal or less
without intercept

I do not know what R shows, but in the summary of the model without
intercept it does not show the R² of the regression line.

When I run a regression I like to have the R² of the regression line and
not something else. ;)




Am 27-06-2012 10:25, schrieb Uwe Ligges:
 
 
 On 27.06.2012 09:33, Christof Kluß wrote:
 Hi

 is there a command that calculates the correct adjusted R-squared, when
 I work without intercept? (The R-squared from lm without intercept is
 false.)
 
 Then we need your definition of your version of correct - we know the
 definition of your version of false.
 
 Best,
 Uwe Ligges
 
 

 Greetings
 Chrsitof

 __
 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.

 
 


-- 
Dipl.-Inf. Christof Kluß (Raum 223) | Universität Kiel
Inst. für Pflanzenbau und -züchtung | www.gfo.uni-kiel.de
Grünland u. Futterbau/Ökol. Landbau | ckl...@gfo.uni-kiel.de
Hermann-Rodewald Str. 9, 24118 Kiel | Tel. 0431 880-2197

__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Uwe Ligges



On 27.06.2012 10:36, Christof Kluß wrote:


for example the same model with intercept R² = 0.6, without intercept R²
= 0.9 and higher. In my definition of R², R² has to be equal or less
without intercept

I do not know what R shows, but in the summary of the model without
intercept it does not show the R² of the regression line.

When I run a regression I like to have the R² of the regression line and
not something else. ;)


Ah, now I understand your question, see ?summary.lm:

r.squared: R^2, the ‘fraction of variance explained by the model’,

R^2 = 1 - Sum(R[i]^2) / Sum((y[i]- y*)^2),

  where y* is the mean of y[i] if there is an intercept and
  zero otherwise.


With your definition of  R^2 you can use:

1 - crossprod(residuals(model)) / crossprod(y - mean(y))

while R uses:

1 - crossprod(residuals(model)) / crossprod(y - 0)


Best,
Uwe Ligges










Am 27-06-2012 10:25, schrieb Uwe Ligges:



On 27.06.2012 09:33, Christof Kluß wrote:

Hi

is there a command that calculates the correct adjusted R-squared, when
I work without intercept? (The R-squared from lm without intercept is
false.)


Then we need your definition of your version of correct - we know the
definition of your version of false.

Best,
Uwe Ligges




Greetings
Chrsitof

__
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.









__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread peter dalgaard

On Jun 27, 2012, at 13:15 , Uwe Ligges wrote:

 
 1 - crossprod(residuals(model)) / crossprod(y - mean(y))

And the reason why that is not used in R:

 y- rnorm(100,10,1)
 x - 1:100
 model - lm(y~x-1)
 
 1 - crossprod(residuals(model)) / crossprod(y - mean(y))
  [,1]
[1,] -27.60012


-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Gabor Grothendieck
On Wed, Jun 27, 2012 at 4:36 AM, Christof Kluß ckl...@email.uni-kiel.de wrote:

 for example the same model with intercept R² = 0.6, without intercept R²
 = 0.9 and higher. In my definition of R², R² has to be equal or less
 without intercept

 I do not know what R shows, but in the summary of the model without
 intercept it does not show the R² of the regression line.

 When I run a regression I like to have the R² of the regression line and
 not something else. ;)


If we use a baseline with no intercept in the R^2 definition then
adding the intercept will always improve the R^2 or at least not make
the R^2 worse.  The following r.squared.0 function defines such an
R^2. It will agree with the R^2 produced by R when used with models
having no intercept but will give a different R^2 value for models
with an intercept.

  r.squared.0 - function(fm) c(1 / (1 + crossprod(resid(fm)) /
crossprod(fitted(fm

  fm1 - lm(demand ~ Time, BOD)
  fm0 - lm(demand ~ Time-1, BOD)

  r.squared.0(fm0)
  r.squared.0(fm1) # adding intercept increases r.squared.0

  # for comparison
  # summary(fm0) uses same defn as r.squared.0
  # but summary(fm1) does not

  summary(fm0)$r.squared # does agree with ours
  summary(fm1)$r.squared # does not agree with ours

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
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.


Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Christof Kluß

for example the same model with intercept R² = 0.6, without intercept R²
= 0.9 and higher. In my definition of R², R² has to be equal or less
without intercept

I do not know what R shows, but in the summary of the model without
intercept it does not show the R² of the regression line.

When I run a regression I like to have the R² of the regression line and
not something else. ;)




Am 27-06-2012 10:25, schrieb Uwe Ligges:
 
 
 On 27.06.2012 09:33, Christof Kluß wrote:
 Hi

 is there a command that calculates the correct adjusted R-squared, when
 I work without intercept? (The R-squared from lm without intercept is
 false.)
 
 Then we need your definition of your version of correct - we know the
 definition of your version of false.
 
 Best,
 Uwe Ligges
 
 

 Greetings
 Chrsitof

 __
 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.

 
 


-- 
Dipl.-Inf. Christof Kluß (Raum 223) | Universität Kiel
Inst. für Pflanzenbau und -züchtung | www.gfo.uni-kiel.de
Grünland u. Futterbau/Ökol. Landbau | ckl...@gfo.uni-kiel.de
Hermann-Rodewald Str. 9, 24118 Kiel | Tel. 0431 880-2197

__
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.