strengejacke / sjstats

Effect size measures and significance tests
https://strengejacke.github.io/sjstats
189 stars 21 forks source link

eta_sq and `omega_sq` don't work when white adjustment is applied #43

Closed IndrajeetPatil closed 6 years ago

IndrajeetPatil commented 6 years ago

# for reproducibility
set.seed(123)

# needed libraries
library(car)
#> Loading required package: carData
library(sjstats)

# model
mod <- stats::lm(
  formula = conformity ~ fcategory * partner.status,
  data = Moore,
  contrasts = list(fcategory = contr.sum, partner.status = contr.sum)
)

# works
sjstats::eta_sq(stats::aov(mod))
#>                       term etasq
#> 1                fcategory 0.003
#> 2           partner.status 0.175
#> 3 fcategory:partner.status 0.145

# works
sjstats::eta_sq(car::Anova(mod, type = "III"))
#>                       term etasq
#> 1              (Intercept) 0.819
#> 2                fcategory 0.005
#> 3           partner.status 0.034
#> 4 fcategory:partner.status 0.025

# doesn't work
sjstats::eta_sq(car::Anova(mod, type = "III", white.adjust = TRUE))
#> Coefficient covariances computed by hccm()
#> Error in if (.after < 1) {: argument is of length zero

I am guessing this is because when white.adjust = TRUE, there is no column corresponding to sum of squares:

# tidy outputs from broom
broom::tidy(car::Anova(mod, type = "III"))
#> # A tibble: 5 x 5
#>   term                      sumsq    df statistic   p.value
#>   <chr>                     <dbl> <dbl>     <dbl>     <dbl>
#> 1 (Intercept)              5753.      1   274.     3.05e-19
#> 2 fcategory                  36.0     2     0.859  4.31e- 1
#> 3 partner.status            240.      1    11.4    1.66e- 3
#> 4 fcategory:partner.status  175.      2     4.18   2.26e- 2
#> 5 Residuals                 818.     39    NA     NA

broom::tidy(car::Anova(mod, type = "III", white.adjust = TRUE))
#> Coefficient covariances computed by hccm()
#> # A tibble: 5 x 4
#>   term                        df statistic   p.value
#>   <chr>                    <dbl>     <dbl>     <dbl>
#> 1 (Intercept)                  1   228.     6.84e-18
#> 2 fcategory                    2     0.911  4.10e- 1
#> 3 partner.status               1     9.51   3.75e- 3
#> 4 fcategory:partner.status     2     2.83   7.12e- 2
#> 5 Residuals                   39    NA     NA

Created on 2018-09-24 by the reprex package (v0.2.1)

strengejacke commented 6 years ago

So it would be best to exclude adjusted ANOVA and give a warning? Effect sizes depend on the sums of squares values...

IndrajeetPatil commented 6 years ago

Yes, it will be good to have a helpful message that informs the user why the function didn't work. Right now, it produces a rather cryptic and unhelpful error message.