[R] Basic regression output question

GRANT Lewis L.Grant at hermes.co.uk
Mon Mar 23 18:04:43 CET 2009


Hi

Probably a very basic question: 

I am regressing a matrix of 50 response variables against a matrix of 10
factors using the lm function. This gives me an object with the output
for 50 regressions, as required. How do I now "use" the data? 

For example, below is some code that generates sample data and shows me
the summary statistics for regression 50. If I want to access the data,
perhaps to extract a particular column or row, how do I do this? Code
such as (coef(summary(lm(t(returns)~factors)))[50])[1,4], which works
when I have only one response variable, returns me an error.

Thanks in advance 

Lewis


EXAMPLE CODE

factors<-matrix(runif(400),nrow=40)
returns1<-matrix(runif(40),nrow=1)
returns2<-matrix(runif(2000),nrow=50)
coef(summary(lm(t(returns1)~factors)))[1,4]

[1] 0.01062590

(coef(summary(lm(t(returns2)~factors)))[50])

Response Y50 :
               Estimate Std. Error     t value  Pr(>|t|)
(Intercept)  0.54829326  0.3230444  1.69726923 0.1003545
factors1     0.08225028  0.1858496  0.44256369 0.6613648
factors2    -0.03084209  0.1968324 -0.15669216 0.8765733
factors3    -0.11287874  0.1845361 -0.61168926 0.5455093
factors4     0.01153631  0.2197322  0.05250168 0.9584889
factors5    -0.21893452  0.2079244 -1.05295235 0.3010575
factors6     0.12978584  0.2164691  0.59955814 0.5534567
factors7     0.09461358  0.1918524  0.49315832 0.6256146
factors8     0.01592064  0.2096206  0.07594975 0.9399806
factors9    -0.06970911  0.2072088 -0.33641968 0.7389767
factors10   -0.04185789  0.1910195 -0.21912894 0.8280846

(coef(summary(lm(t(returns2)~factors)))[50])[1,4]

Error in `[.default`((coef(summary(lm(t(returns2) ~ factors)))[50]), 1,
: 
  incorrect number of dimensions





**********************************************************************
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 




More information about the R-help mailing list