I am trying to increase the efficiency of a script where, basically, I run a number of linear regressions and for each fitted model I store the estimated coefficients and standard errors results in a previously created data frame, say results.
Hence the data frame results is already with the required dimensions before storing any regression coefficient.
Also, for each i-th regression I make:
mod.fit <- plm(y ~ x1 + x2, index="group", sample)
and then I run:
results[i,1] <- summary(m.fit)$coefficients[1,1]
results[i,2] <- summary(m.fit)$coefficients[2,1]
results[i,3] <- summary(m.fit)$coefficients[1,2]
results[i,4] <- summary(m.fit)$coefficients[2,2]
Is there a way for making the above storage step faster?
.
summary()4 times per loop is silly. If you had to do this, dosm <- summary(m.fit)and then four calls ofsm$coefficients[x,y]. - Gavin Simpsonm.fitis so... But if it is of class"lm"then you'll need a little more than justcoef(m.fit), but not much more thansqrt(diag(vcov(m.fit))). - Gavin Simpson