How can we create multiple linear models at once and put the coefficients into a new matrix. Is it a good choice?

732    Asked by JakeEdmunds in Data Science , Asked on Feb 1, 2020
Answered by Nitin Solanki

No it’s not a good choice. Suppose we have many columns and we would like to create multiple linear regression models at once secondly extracting the coefficients and put them into a new matrix. This is possible to do but statistically this might not be the best possible approach to analyses temporal data.

Below is the example of same it can be used for achieving the desired result:

Coefs <- matrix(,ncol(Data),2) #Assuming your generic 1:60 column is not in the same object

for(i in 1:ncol(Data)){

Coefs[i,] <- lm(Data[,i]~GenericColumn)$coefficients

}




Your Answer

Interviews

Parent Categories