tidymodels / broom

Convert statistical analysis objects from R into tidy format
https://broom.tidymodels.org
Other
1.43k stars 302 forks source link

re-upping discussion of tobit model tidiers #1167

Closed bbolker closed 12 months ago

bbolker commented 12 months ago

As discussed on Stack Overflow and on this closed issue, there's not currently a tidier for tobit models (from the AER package). (This commit "solved" the problem of an obscure error message by setting tidy.tobit <- tidy.default, which leads to an interpretable rather than an uninterpretable error message). This appears to be solvable by a small workaround:

tidy.tobit <- function(x, ...) {
   class(x) <- "survreg"
   tidy(x, ...)
}

Example:

data("Affairs", package = "AER")
# model
m1 <-
  AER::tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
             data = Affairs)
tidy(m1)

The reason this works is that the tidy.survreg tidier depends on the output of summary() having a $table component. AER::summary.tobit() does not have such a component, but survival::summary.survreg does ...

simonpcouch commented 12 months ago

Thanks for documenting the current state of these tidiers + a workaround! Saw that SO post this morning—I'm glad your effort is findable on the repo now, too.

With an eye for the maintenance guidelines of the package, we won't be merging in support for these model objects. I appreciate you bringing this up, though.

The answer re: your note on the SO post:

(I don't know why it doesn't use standard S3 inheritance rules?)

is in your issue description here. AER::tobit output dispatches to the survreg tidier but still has subclass tobit, resulting in the error on the issue you've linked:

# tidier from 2019 and before
broom::tidy(m1)
#> Error in if (!is.null(newnames) && length(newnames) != ncol(x)) {: missing value where TRUE/FALSE needed

We set that method for the subclass so that users get a more informative error.

bbolker commented 12 months ago

Thanks. I think I realized the answer to my question partway through composing the issue but failed to update the SO post.

Thanks for the pointer to the maintenance guidelines: that makes sense. I guess someone should approach the AER maintainers.

github-actions[bot] commented 11 months ago

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.