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

pairwise_test_bin when method = 'mcnemar' wihle changing order of groups with factors only changes order in some column #102

Open
lemireg opened this issue Jan 14, 2025 · 0 comments

Comments

@lemireg
Copy link

lemireg commented Jan 14, 2025

Below is a reproducible example of the bug in pairwise_test_bin() when method = 'mcnemar' wihle changing order of groups with factors only changes order in some column. In the second output below ResponseStats column order does not match Comparison order once the factor order changes. For example in row 3, 5 and 6 group 1 is listed second in Comparison column but the ResponseStats column lists it first.

library(VISCfunctions)

set.seed(1)
x_example <- c(sample(0:1,20,replace = TRUE, prob = c(.90,.10)), #P_1(0 = 90%)
              sample(0:1,25,replace = TRUE, prob = c(.10,.90)), #P_2(0 = 10%)
              sample(0:1,25,replace = TRUE, prob = c(.5,.5)), #P_3(0 = 50%)
              sample(0:1,25,replace = TRUE, prob = c(.10,.90))) #P_4(0 = 10%)
group_example <- c(rep(1,20),
                   rep(2,25)
                   ,rep(3,25),
                   rep(4,25))
id_example <- c(1:20, rep(1:25, 3))

# mcnemar with factors in order
pairwise_test_bin(x_example,
                  factor(group_example, levels = c("1", "2", "3", "4")),
                  alternative = "two.sided",
                  method = "mcnemar",
                  paired = TRUE,
                  id = id_example,
                  num_needed_for_test = 2)

# mcnemar with order of factors changed
# ResponseStats column order does not match Comparison order once the factor order changes.
# For example in row 3, 5 and 6 group 1 is listed second in Comparison column but the
# ResponseStats column lists it first
pairwise_test_bin(x_example,
                  factor(group_example, levels = c("2", "3", "4", "1")),
                  alternative = "two.sided",
                  method = "mcnemar",
                  paired = TRUE,
                  id = id_example,
                  num_needed_for_test = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant