[R] lm output

(Ted Harding) Ted.Harding at manchester.ac.uk
Sat Oct 10 00:00:12 CEST 2009


On 09-Oct-09 21:45:04, Brecknock, Peter wrote:
> Daniel
> Thanks very much for the reply. 
> 
> If the data fails the underlying assumptions of regression wouldn't it
> make sense to suppress all the output and not just the slope
> coefficient?
> 
> Incidently, if I run this simple example in Excel it returns the slope
> as 0.

So much the worse for Excel -- not the first time Excel has been
found to produce nonsense!

> Intuitively, this makes sense to me ... the best estimate of y
> would be its mean for any value of x.

On the contrary -- your data give you no information whatever
about the value of y at any value of x other than x=5. So, given
your data, if you want to "predict" the value of y for some other
value of x, you can choose whatever value you like -- hence the
indeterminate slope. And this is where the statement made by Excel
is grossly misleading: telling you that the slope is 0 would make
you adopt the same value (mean(y) = 13) for any value of x, and
you have no basis whatever for doing so.

Ted.

> 
> Kind regards
> Pete



> -----Original Message-----
> From: Daniel Malter [mailto:daniel at umd.edu] 
> Sent: Friday, October 09, 2009 4:24 PM
> To: Brecknock, Peter; r-help at r-project.org
> Subject: AW: [R] lm output
> 
> That comes out as an NA because X'X is not invertible because it is not
> full
> rank (one row/column is a linear combination of the other(s)). And that
> means there is no unique solution to the system.
> 
> y=c(10,12,17)
> x=c(5,5,5)
> X=cbind(1,x)
> 
> X
> t(X)%*%X
> solve(t(X)%*%X)
> 
> Therefore, nope, there is now way to make this come out as a zero,
> because it fails the very assumptions of regression analysis.
> 
> HTH,
> Daniel
> 
> -------------------------
> cuncta stricte discussurus
> -------------------------
> 
> -----Ursprüngliche Nachricht-----
> Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> Im
> Auftrag von Brecknock, Peter
> Gesendet: Friday, October 09, 2009 5:12 PM
> An: r-help at r-project.org
> Betreff: [R] lm output
> 
> Hi All
> 
> I am running a linear regression using the lm object.
> 
> In the event that my independent variable is the same across all
> observations the regression slope is returned as an NA.
> 
> For example, if I have the following 
> 
> y=c(10,12,17)
> x=c(5,5,5)
> 
> lm = lm(y~x)
> produces the following 
> 
> Coefficients:
> (Intercept)            x  
>       13           NA  
> 
> Other than post-processing the results, is there a way to output the
> slope
> as 0 rather than NA?
> 
> Thanks
> 
> Pete 
> 
> 
> This e-mail may contain confidential or proprietary information
> belonging to
> the BP group and is intended only for the use of the recipients named
> above.
> If you are not the intended recipient, please immediately notify the
> sender
> and either delete this email or return to the sender immediately.  You
> may
> not review, copy or distribute this email.  Within the bounds of law,
> this
> part of BP retains all emails and IMs and may monitor them to ensure
> compliance with BP's internal policies and for other legitimate
> business
> purposes.
> 
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
> 
> ______________________________________________
> 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.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 09-Oct-09                                       Time: 23:00:09
------------------------------ XFMail ------------------------------




More information about the R-help mailing list