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

Can't tidy anova for two MASS::polr models #1152

Closed
benwhalley opened this issue Apr 14, 2023 · 3 comments
Closed

Can't tidy anova for two MASS::polr models #1152

benwhalley opened this issue Apr 14, 2023 · 3 comments

Comments

@benwhalley
Copy link

Hi - just came across this:

m.polr <- MASS::polr(ordered(gear)~am, data=mtcars)
m.polr.0 <- MASS::polr(ordered(gear) ~ 1, data=mtcars)
anova(m.polr, m.polr.0) %>% tidy()

Shows this error:

 Error in x - stats::median(x, na.rm = na.rm) : 
non-numeric argument to binary operator

Whereas this works fine:

m <- lm(gear~am, data=mtcars)
m.0 <- lm(gear ~ 1, data=mtcars)
anova(m, m.0) %>% tidy()
@benwhalley
Copy link
Author

Incidentally, this is my workaround which gives what I think would be the expected output:

anova(m.polr, m.polr.0) %>% 
as_tibble() %>% 
set_names(c('model', "res.df",    "res.dev",  'test' ,    "df"  ,      "statistic" ,  "p.value"  )) 

@simonpcouch
Copy link
Collaborator

Thanks for the issue!

A quick reprex with some small edits:

library(broom)
library(MASS)

m.polr <- polr(ordered(gear) ~ am, data = mtcars)
m.polr.0 <- polr(ordered(gear) ~ 1, data = mtcars)

fit <- anova(m.polr, m.polr.0)

class(fit)
#> [1] "Anova"      "data.frame"

tidy(fit)
#> Warning: Data frame tidiers are deprecated and will be removed in an upcoming
#> release of broom.
#> Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
#> returning NA

#> Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
#> returning NA
#> Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm =
#> na.rm): NAs introduced by coercion

#> Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm =
#> na.rm): NAs introduced by coercion
#> Warning in mean.default(sort(x, partial = half + 0L:1L)[half + 0L:1L]):
#> argument is not numeric or logical: returning NA

#> Warning in mean.default(sort(x, partial = half + 0L:1L)[half + 0L:1L]):
#> argument is not numeric or logical: returning NA
#> Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
#> returning NA

#> Warning in mean.default(X[[i]], ...): argument is not numeric or logical:
#> returning NA
#> Warning in mean.default(sort(x, partial = half + 0L:1L)[half + 0L:1L]):
#> argument is not numeric or logical: returning NA
#> Error in x - stats::median(x, na.rm = na.rm): non-numeric argument to binary operator

Created on 2023-05-19 with reprex v2.0.2

We're seeing these failures because broom doesn't have any methods for Anova (note capital A) objects--this thus ends up dispatching to the data.frame tidiers which are now deprecated.

@github-actions
Copy link

github-actions bot commented Jun 8, 2023

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 Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants