easystats / effectsize

:dragon: Compute and work with indices of effect size and standardized parameters
https://easystats.github.io/effectsize/
Other
334 stars 23 forks source link

Weighted effect sizes #388

Open mattansb opened 2 years ago

mattansb commented 2 years ago

Weighting is already implemented in standardize.default() and standardize_parameters() (and eta_squared() via the fit models).

Would be nice to have this also (with weights = arg) in:

Perhaps we can ~steal~ borrow some code from sjstats::weighted_*...

mattansb commented 2 years ago

For all the Xsq stuff, this seems easy - essentially, all suppressWarnings(stats::chisq.test(x, y, ...)) should be replaced with:

chisq.test2 <- function(x, y, w = NULL, ...) {
  if (!is.null(w)) {
    x <- stats::xtabs(w ~ x + y, data = mtcars)
    y <- NULL
  }

  suppressWarnings(stats::chisq.test(x, y, ...))
}

chisq.test2(mtcars$am, mtcars$cyl)
#> 
#>  Pearson's Chi-squared test
#> 
#> data:  x and y
#> X-squared = 8.7407, df = 2, p-value = 0.01265

chisq.test2(mtcars$am, mtcars$cyl, w = mtcars$gear)
#> 
#>  Pearson's Chi-squared test
#> 
#> data:  x
#> X-squared = 26.383, df = 2, p-value = 1.866e-06

Created on 2021-11-30 by the reprex package (v2.0.1)