[R] Regression performance when using summary() twice

Michael Dewey ||@t@ @end|ng |rom dewey@myzen@co@uk
Fri Jun 21 18:04:51 CEST 2024


Dear Christian

Without knowing how big your datset is it is hard to be sure but 
confint() can take some time.

Have you thought of calling summary once
summ <- summary(model)
and then replace all subsequent calls to summary with summ

Michael

On 21/06/2024 15:38, c.buhtz using posteo.jp wrote:
> Hello,
> 
> I am not a regular R user but coming from Python. But I use R for 
> several special task.
> 
> Doing a regression analysis does cost some compute time. But I wonder 
> when this big time consuming algorithm is executed and if it is done 
> twice in my sepcial case.
> 
> It seems that calling "glm()" or similar does not execute the time 
> consuming part of the regression code.
> It seems it is done when calling "summary(model)".
> Am I right so far?
> 
> If this is correct I would say that in my case the regression is down 
> twice with the identical formula and data. Which of course is 
> inefficient. See this code:
> 
> my_function <- function(formula_string, data) {
>              formula <- as.formula(formula_string)
>              model <- glm.nb(formula, data = data)
> 
>              result = cbind(summary(model)$coefficients, confint(model))
>              result = as.data.frame(result)
> 
>              string_result = capture.output(summary(model))
> 
>              return(list(result, string_result))
>          }
> 
> I do call summary() once to get the "$coefficents" and a second time 
> when capturing its output as a string.
> 
> If this really result in computing the regression twice I ask myself if 
> there is a R-way to make this more efficent?
> 
> Best regards,
> Christian Buhtz
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Michael



More information about the R-help mailing list