tidymodels / broom

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

Glance.lm gives does not give fstatistic/ f stat based values when used on a 0 intercept model. #1208

Closed jrob95 closed 1 week ago

jrob95 commented 3 months ago

The problem

I have attempted to glance a lm of the form y ~ x + 0. When doing so, statistic, p.value & df are returned as NA.

Examination of the package has led me to believe the issue is in line 213 of stats-lm-tidiers.R where glance checks if the model is fitted to intercept only, but it only checks if the summary of the model has one row, which it also does when a 0 intercept model is estimated.

Reproducible example

library(broom)

data <- mtcars

model <- lm(data, formula = mpg ~ 0 + cyl)

glance(model)
#> # A tibble: 1 × 12
#>   r.squared adj.r.squared sigma statistic p.value    df logLik   AIC   BIC
#>       <dbl>         <dbl> <dbl>     <dbl>   <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1     0.734         0.725  11.0        NA      NA    NA  -122.  247.  250.
#> # ℹ 3 more variables: deviance <dbl>, df.residual <int>, nobs <int>

Created on 2024-07-01 with [reprex v2.1.0](https://reprex.tidyverse.org/)
simonpcouch commented 1 week ago

Closed in #1209. Thank you!