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

tidy method for anova misses a column name #62

Closed
agoldst opened this issue Jul 23, 2015 · 2 comments
Closed

tidy method for anova misses a column name #62

agoldst opened this issue Jul 23, 2015 · 2 comments

Comments

@agoldst
Copy link

agoldst commented Jul 23, 2015

Applying tidy to the results of anova on more than one model yields a data frame where all the column names are off by one (and the last column has name NA):

m1 <- lm(mpg ~ wt + qsec + disp, mtcars)
m2 <- lm(mpg ~ wt, mtcars)
a <- anova(m1, m2)

Now print(a) gives

Analysis of Variance Table

Model 1: mpg ~ wt + qsec + disp
Model 2: mpg ~ wt
  Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
1     28 195.46                                
2     30 278.32 -2   -82.859 5.9348 0.007099 **

---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

but tidy(a) gives

  df    sumsq meansq statistic  p.value          NA
1 28 195.4626     NA        NA       NA          NA
2 30 278.3219     -2 -82.85933 5.934796 0.007099496

It looks like tidy.anova assumes a has five columns, but it has six; the method misses the third column of a (the Df column). Apologies for not putting together a pull request, and thanks for this fantastic package.

@nutterb
Copy link
Contributor

nutterb commented Jul 24, 2015

This is another type of ANOVA, and is really more of a likelihood ratio test than an analysis of variance.

But this can be resolved as easily as adding another else if{}

else if (identical(colnames(x), c("Res.Df", "RSS", "Df", "Sum of Sq", "F", "Pr(>F)"))){
    # x is anova(m1, m2)
    nn <- c("res.df", "rss", "df", "sumsq", "statistic", "p.value")
  }

@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 15, 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