Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: glance on a list of models? #561

Closed
billdenney opened this issue Dec 23, 2018 · 5 comments
Closed

Feature Request: glance on a list of models? #561

billdenney opened this issue Dec 23, 2018 · 5 comments

Comments

@billdenney
Copy link
Contributor

I often want to compare many models-- usually collected in a list-- to each other. I've currently implemented this in my PKNCA package with the non-exported AIC.list() function, but as I think of it more, broom (and broom.mixed) seem like a better home for the type of functionality I'm thinking of.

While I can accomplish the same thing with a call like the following (typed directly into GitHub; it may have bugs, but it hopefully indicates the intent):

model_list %>%
  lapply(FUN=glance) %>%
  bind_rows()

For me, the multiple-model comparison need is common and I'd like to have an interface like:

glance_list <- function(x, ...) {
  ret_list <- lapply(X=x, FUN=glance, ...)
  bind_rows(ret_list)
}

To make this work with models that don't converge, I'd also ideally like to have glance() methods for logical NA and NULL:

glance.logical <- function(x, ...) {
  if (length(x) == 1 && is.na(x)) {
    # Choose appropriate "model summaries" for NA, possibly an empty data.frame, perhaps:
    data.frame(convergence=FALSE)
  } else {
    stop("Cannot glance at a logical value other than scalar NA.")
  }
}
glance.NULL <- function(x, ...) {
  # Choose appropriate "model summaries" for NULL, matching NA
  glance.logical(NA, ...)
}

This relates to: billdenney/pknca#71 and billdenney/pknca#90

@alexpghayes
Copy link
Collaborator

I recommend using purrr::map_df(model_list, glance) for this. Does that work for your use case?

@billdenney
Copy link
Contributor Author

@alexpghayes, That works well enough.

@alexpghayes
Copy link
Collaborator

Just realized that glance() currently returns an empty tibble for NULL values, but there isn't a glance() method for NA values, for models that aren't converging. Are there any model types / packages you work with that return NA for models that failed to converge?

@billdenney
Copy link
Contributor Author

Thanks for the quick reply!

My own code does within the PKNCA package, and the empty tibble return is an issue there. I started the discussion of NA in #565. (It seemed out of place to continue that conversation here.)

@github-actions
Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants