strengejacke / sjstats

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

`etasq` function doesn't work with `aovlist` class objects #34

Closed IndrajeetPatil closed 6 years ago

IndrajeetPatil commented 6 years ago

The sjstats::etasq function doesn't seem to work with repeated measures ANOVA designs:

# loading the needed libraries
library(tidyverse)
library(magrittr)
library(sjstats)

# converting the iris dataset to long format
iris_long <- datasets::iris %>%
  dplyr::mutate(.data = ., id = dplyr::row_number(x = Species)) %>%
  tidyr::gather(
    data = .,
    key = "condition",
    value = "value",
    Sepal.Length:Petal.Width,
    convert = TRUE,
    factor_key = TRUE
  ) %>%
  tidyr::separate(
    col = "condition",
    into = c("attribute", "measure"),
    sep = "\\.",
    convert = TRUE
  ) %>%
  tibble::as_data_frame(x = .)

# specifying the model
iris.mod <-
  stats::aov(formula = value ~ attribute * measure + Error(id / (attribute * measure)),
             data = iris_long)

# getting tidy output from broom (works only with >= broom 0.4.5)
broom::tidy(iris.mod)
#> # A tibble: 8 x 7
#>   stratum              term        df   sumsq  meansq statistic    p.value
#>   <chr>                <chr>    <dbl>   <dbl>   <dbl>     <dbl>      <dbl>
#> 1 id                   Residua~     1 2.64e+2 2.64e+2     NA    NA        
#> 2 id:attribute         attribu~     1 2.37e+2 2.37e+2     NA    NA        
#> 3 id:measure           measure      1 1.11e+3 1.11e+3     NA    NA        
#> 4 id:attribute:measure attribu~     1 7.99e-1 7.99e-1     NA    NA        
#> 5 Within               attribu~     1 4.70e+2 4.70e+2   1446.    4.71e-161
#> 6 Within               measure      1 5.77e+1 5.77e+1    177.    1.34e- 35
#> 7 Within               attribu~     1 1.54e+0 1.54e+0      4.72  3.01e-  2
#> 8 Within               Residua~   592 1.92e+2 3.25e-1     NA    NA

# getting effect sizes and their confidence intervals 
sjstats::eta_sq(model = iris.mod, partial = TRUE, ci.lvl = 0.95)
#> Error in UseMethod("anova"): no applicable method for 'anova' applied to an object of class "c('aovlist', 'listof')"

Created on 2018-07-02 by the reprex package (v0.2.0).

strengejacke commented 6 years ago

Yes, this is a duplicate of #20 I have no solution yet.

strengejacke commented 6 years ago

Just saw:

getting tidy output from broom (works only with >= broom 0.4.5) broom::tidy(iris.mod)

So it might be working with broom >= 0.4.5.

strengejacke commented 6 years ago

Should be working now, but requires broom >= 0.4.5

IndrajeetPatil commented 6 years ago

@strengejacke Thanks! It's working indeed.

Is it also possible to have the same functionality with omega-squared as well? I usually like to present both effect sizes for my models.

> sjstats::omega_sq(model = iris.mod, partial = TRUE, ci.lvl = 0.95)
Error in formula.default(model) : invalid formula
strengejacke commented 6 years ago

For omega-sq only of partial = FALSE. For bootstrapping, I need to extract the formula (see https://github.com/strengejacke/sjstats/blob/13353e18cb7e352091606500b40fd44675b9fc2e/R/eta_sq.R#L423), which currently fails for Anova with error term. If you have any ideas, let me know!

strengejacke commented 6 years ago

or better, I use lm() for bootstrapping, which allows no error term in the formula: https://github.com/strengejacke/sjstats/blob/13353e18cb7e352091606500b40fd44675b9fc2e/R/eta_sq.R#L436

I'm not sure how to fix this yet, must think about it. Probably an own bootstrapping-function for Anova with error term.

strengejacke commented 6 years ago

Ok, fixed this issue, omega_sq and CI or eta_sq and CI should now also work. Will commit later.