[R] Regression Column names instead of numbers

TMiller thomas.mueller at student.unisg.ch
Fri Aug 2 17:16:55 CEST 2013


Hi guys
I am new to R and I am currently trying to do a regression:
I have two matrices with 200 time series each.
In order to achieve a loop, I used the following command:

sapply(1:200, function(x) summary(lm(formula=matrix1[,x]~matrix2[,x])))

Each column/time series has a unique name, in case of Matrix 1 I have 200
cities, in case of Matrix 2 I have 200 stocks.
However, if I run the command I get the following result:

[[1]]

Call:
lm(formula = matrix1[, x] ~ matrix2[, x])

Residuals:
   Min     1Q Median     3Q    Max 
-134.9  -68.6  -32.8   33.2  261.2 

Coefficients:
                     Estimate Std. Error t value Pr(>|t|)    
(Intercept)          525.2356    69.8059    7.52  9.1e-10 ***
matrix2[, x]             0.0640     0.0161    3.98  0.00023 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 113 on 50 degrees of freedom
  (41 observations deleted due to missingness)
Multiple R-squared: 0.24,	Adjusted R-squared: 0.225 
F-statistic: 15.8 on 1 and 50 DF,  p-value: 0.000226 


[[2]]

Call:
lm(formula = matrix1[, x] ~ matrix2[, x])

Residuals:
   Min     1Q Median     3Q    Max 
-914.9 -393.3  -76.9  243.3 1304.7 

Coefficients:
                     Estimate Std. Error t value Pr(>|t|)    
(Intercept)          3.33e+03   1.88e+02   17.70  < 2e-16 ***
matrix2[, x]            4.10e-01   7.87e-02    5.21  3.4e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 531 on 51 degrees of freedom
  (40 observations deleted due to missingness)
Multiple R-squared: 0.348,	Adjusted R-squared: 0.335 
F-statistic: 27.2 on 1 and 51 DF,  p-value: 3.4e-06 


Instead of the X's in the call response, I'd like to have the column name
(city and stock).
Is this by any means possible?
Thanks in advance for your help.
Best
Tom



--
View this message in context: http://r.789695.n4.nabble.com/Regression-Column-names-instead-of-numbers-tp4672904.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list