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

FR: Add group medians for Wilcoxon rank sum test in model_parameters #492

Open
iagogv3 opened this issue May 13, 2021 · 3 comments
Open
Labels
Feature idea 🔥 New feature or request Low priority 😴 This issue does not impact package functionality much

Comments

@iagogv3
Copy link

iagogv3 commented May 13, 2021

As model_parameters shows group means for Welch two-sample test, it could also show group medians for Wilcoxon rank sum test.

@IndrajeetPatil IndrajeetPatil added Enhancement 💥 Implemented features can be improved or revised Consistency 🍏 🍎 Expected output across functions could be more similar labels May 13, 2021
@IndrajeetPatil
Copy link
Member

Note that parameters only returns details contained in the underlying object.

It returns group means for Welch two-sample test because the underlying object contains them.

library(parameters)

x <- c(1.83,  0.50,  1.62,  2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)

mod1 <- t.test(x, y, paired = TRUE)

mod1
#> 
#>  Paired t-test
#> 
#> data:  x and y
#> t = 3.0354, df = 8, p-value = 0.01618
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  0.1037787 0.7599991
#> sample estimates:
#> mean of the differences 
#>               0.4318889
parameters(mod1)
#> Paired t-test
#> 
#> Parameter | Group | Difference | t(8) |     p |       95% CI
#> ------------------------------------------------------------
#> x         |     y |       0.43 | 3.04 | 0.016 | [0.10, 0.76]

But it doesn't do so for Wilcoxon rank sum test because the object doesn't contain them:

mod2 <- wilcox.test(x, y, paired = TRUE)

mod2
#> 
#>  Wilcoxon signed rank exact test
#> 
#> data:  x and y
#> V = 40, p-value = 0.03906
#> alternative hypothesis: true location shift is not equal to 0
parameters(mod2)
#> Wilcoxon signed rank exact test
#> 
#> Parameter1 | Parameter2 |     W |     p
#> ---------------------------------------
#> x          |          y | 40.00 | 0.039

You can always add effect size information for these object though:

parameters(mod1, hedges_g = TRUE)
#> Paired t-test
#> 
#> Parameter | Group | Difference |       95% CI | t(8) | Hedges_g |     g 95% CI |     p
#> --------------------------------------------------------------------------------------
#> x         |     y |       0.43 | [0.10, 0.76] | 3.04 |     0.91 | [0.17, 1.73] | 0.016
parameters(mod2, rank_biserial = TRUE)
#> Wilcoxon signed rank exact test
#> 
#> Parameter1 | Parameter2 |     W | r_rank_biserial | rank_biserial 95% CI |     p
#> --------------------------------------------------------------------------------
#> x          |          y | 40.00 |            0.78 |         [0.33, 1.00] | 0.039

Created on 2021-05-13 by the reprex package (v2.0.0)

@IndrajeetPatil IndrajeetPatil added Won't fix 🚫 This will not be worked on and removed Consistency 🍏 🍎 Expected output across functions could be more similar Enhancement 💥 Implemented features can be improved or revised labels May 13, 2021
@IndrajeetPatil
Copy link
Member

Reopening in light of easystats/report#189

This will depend on whether we can recover data from the htest object, which is not always guaranteed.

@IndrajeetPatil IndrajeetPatil added Feature idea 🔥 New feature or request Low priority 😴 This issue does not impact package functionality much and removed Won't fix 🚫 This will not be worked on labels Jun 17, 2021
@mattansb
Copy link
Member

Something along these lines:

x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46)
y <- c(1.15, 0.88, 0.90, 0.74, 1.21)

## wilcox.test ----

model <- wilcox.test(x, y)

data <- insight::get_data(model)
desc <- NULL
if (!is.null(data)) {
  desc <- as.data.frame(t(sapply(data, function(d) {
    data.frame(Median = median(d, na.rm = TRUE),
               MAD = mad(d, na.rm = TRUE))
  })))
}
desc
#>   Median      MAD
#> x  1.415 0.630105
#> y    0.9 0.237216



## wilcox.test ----

model <- t.test(x, y)

data <- insight::get_data(model)
desc <- NULL
if (!is.null(data)) {
  desc <- as.data.frame(t(sapply(data, function(d) {
    data.frame(Mean = mean(d, na.rm = TRUE),
               SD = sd(d, na.rm = TRUE))
  })))
}
desc
#>    Mean        SD
#> x 1.313 0.4412117
#> y 0.976 0.1973069

Created on 2021-06-17 by the reprex package (v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature idea 🔥 New feature or request Low priority 😴 This issue does not impact package functionality much
Projects
None yet
Development

No branches or pull requests

3 participants