[R] Regression and data types
Gavin Simpson
gavin.simpson at ucl.ac.uk
Sat Sep 27 17:18:32 CEST 2008
On Fri, 2008-09-26 at 13:17 +0100, GRANT Lewis wrote:
> Dear All
> I have three data sets, X1, X2 and Y. X1 is data, X2 and Y were
> generated in (different) R programs. All three vectors have one column
> of 60 data points.
> I am using the code lm(Y~X1)$coef and lm(Y~X2)$coef.
Others have replied with an answer to your question. I just wanted to
suggest you don't rummage around in R model objects taking what you like
using '$'. 9 times out of 10 you'll get what you want, but that last
remaining time will have you rubbing your head in confusion at best, at
worst, answers may be just plain wrong.
Use extractor functions, such as coef() instead:
coef(lm(Y ~ X1))
G
> The first returns
> two values, an intercept and a slope, but the second returns 60 values.
> I suspect there is something in the "type" of X2 such that it forces the
> regression to do something different, but I can't work this out.
> Please help!
> Lewis
>
>
> **********************************************************************
> Hermes Fund Managers Limited
> Registered in England No. 1661776, Lloyds Chambers, 1 Portsoken Street, London E1 8HZ
>
> *** Please read the Hermes email disclaimer at http://www.hermes.co.uk/email_terms.htm before acting on this email or opening any attachment ***
>
> The contents of this email are confidential. If you have received this message in error, please delete it immediately and contact the sender directly or the Hermes IT Helpdesk on +44(0)20 7680 2117. Any reliance on, use, disclosure, dissemination, distribution or copying of this email is unauthorised and strictly prohibited.
>
> This message has been checked for viruses but the recipient is strongly advised to rescan the message before opening any attachments or attached executable files. Hermes do not accept any liability for any damage sustained as a result of a virus introduced by this email or any attachment.
>
>
> **********************************************************************
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>
> ______________________________________________
> 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.
More information about the R-help
mailing list