Get residual standard errors of the mlm object returned by `lm ()`

I used lm() to match multiple regression models, for multiple (~ 1 million) response variables in R. For example.

 allModels <- lm(t(responseVariablesMatrix ~ modelMatrix) 

Returns an object of class "mlm", which looks like a huge object containing all the models. I want to get the Residual Sum of Squares for each model that I can do using:

 summaries <- summary(allModels) rss1s <- sapply(summaries, function(a) return(a$sigma)) 

My problem is that I think that the "summary" function also computes the totality of other things and therefore is pretty slow. I am wondering if there is a faster way to extract only the Residual Sum of Squares for the model?

Thanks!

+6
source share
2 answers

there are residual components in the output of the lm object, so you get the residual sum of squares by sum(output$residuals^2) .

edit: you actually accept the sigma from the summary that sqrt(sum(output$residuals^2)/output$df.residuals)

For all models use

sapply(allModels, function(a) sqrt(sum(a$residuals^2)/a$df.residuals)))

+5
source
 residuals(summary(allModels))) 

will give you a matrix of residues

0
source

All Articles