How to implement "broom" package in R

465 views Asked by At

I have an issue that might be silly in some ways, but following this question:

Linear Regression and group by in R

I tried to install the broom package in order to "retrieve the coefficients and Rsquared/p.value".

I know that the previous question is 12 years old but this package is still listed in my RStudio for installation, but then I have this error message and I am lost on what to do to make it work properly:

library(broom) Error in value[3L]: Package 'broom' version 0.7.12 cannot be loaded: Error in unloadNamespace(package): namespace 'broom' is imported by 'modelr', 'tidyverse', 'rstatix' and therefore cannot be unloaded

So my question is straightforward: what does it mean? Did broom become a dependancy of the 3 packages cited? How to make it work?

Thank you very much for your help.

EDIT: screenshot of the output to know why some numbers appear in red.

enter image description here

1

There are 1 answers

7
jpenzer On BEST ANSWER

Given your comments, you should be able to purrr::map broom::tidy over your list column of models.

fitted_models$model %>%
    purrr::map(broom::tidy)

This returns a list of your models with the coefficients, p-values etc. tidied.

You can also mutate a new column into your fitted_models data frame/tibble to keep your data frame/tibble data type. Note that we include model in the map() call because we are piping from fitted_models, not fitted_models$model:

fitted_models %>%
    mutate(tidied_models = purrr::map(model, broom::tidy)