[R] wrong calculation of R-squared in summary.lm

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 30 15:07:35 CEST 2011


This is user error: that fit has class c("mlm", "lm") and you should 
be calling summary() on it, which will dispatch the mlm method.

For multiple-response linear models, there is also summary.manova.

On Wed, 30 Mar 2011, Stefan Schlager wrote:

> Dear all,
>
> I just stumbled upon the fact, that when I perform a regression on 
> multivariate responses, that are not centred, I get a ricilulously high 
> R-squared value. After reading the code of summary.lm, I found a bug in the 
> function summary.lm:
>
> mss is calculated by:
> mss <-sum((f - mean(f))^2) -  where f are the fitted values.
>
> This works only for a single response variable, because otherwise the matrix 
> containing the fitted values is scaled by a scalar. replacing
> this with:
> mss <- scale(f,scale=FALSE) solved the problem for me.
>
> Example for bug:
> response<-cbind(rnorm(500)+1000,rnorm(500)+300)
> predictor<-rnorm(500)
> fit<-lm(response ~ predictor)
> summary.lm(fit) now reports a R^2 value of 1!!!
>
> Please correct me, if I'm wrong
>
> Stefan
>
> Stefan Schlager M.A.
> Anthropologie
> Medizinische Fakultät der der Albert Ludwigs- Universität Freiburg
> Hebelstr. 29
>
> 79104 Freiburg
>
> Anthropology
> Faculty of Medicine, Albert-Ludwigs-University Freiburg
> Hebelstr. 29
> D- 79104 Freiburg
>
> phone +49 (0)761 203-5522
> fax +49 (0)761 203-6898
>
>
>
> On 30/03/11 13:54, r-help-request at r-project.org wrote:
>> Mailing list subscription confirmation notice for mailing list R-help
>> 
>> We have received a request from 129.132.148.130 for subscription of
>> your email address, "stefan.schlager at uniklinik-freiburg.de", to the
>> r-help at r-project.org mailing list.  To confirm that you want to be
>> added to this mailing list, simply reply to this message, keeping the
>> Subject: header intact.  Or visit this web page:
>>
>>      https://stat.ethz.ch/mailman/confirm/r-help/4aa823dc72684b2ac88f8b630c5669c89da37c7c
>> 
>> 
>> Or include the following line -- and only the following line -- in a
>> message to r-help-request at r-project.org:
>>
>>      confirm 4aa823dc72684b2ac88f8b630c5669c89da37c7c
>> 
>> Note that simply sending a `reply' to this message should work from
>> most mail readers, since that usually leaves the Subject: line in the
>> right form (additional "Re:" text in the Subject: is okay).
>> 
>> If you do not wish to be subscribed to this list, please simply
>> disregard this message.  If you think you are being maliciously
>> subscribed to the list, or have any other questions, send them to
>> r-help-owner at r-project.org.
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list