I am trying to run multiple regressions in a selected part of a data frame. There are 22 columns. One of them is “DATE”, one is “INDEX” and S1, S2, S3 ... S20.
I run the regression as follows:
Regression <- lm(as.matrix(df[c('S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19', 'S20')]) ~ df$INDEX)
Regression$coefficients
1) How can I make the code shorter? In the same way as using the interval to indicate R: count columns S1-S20 as explanatory variables and start regression on them with the dependent variable INDEX.
2) Regression formula: a + b * INDEX + error Then extract all estimates of "b" from the regression. Assume that the columns have 10 rows, so there should be 10 ratings. Also extract all errors: it should be 10 errors in each column and only 10 * 20 = 200 errors.
Since I have no experience with R, any help is appreciated! Thank!
source
share