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

McNemar's statistical test addition: ard_mcnemartest #51

Merged
merged 18 commits into from
Feb 21, 2024

Conversation

Melkiades
Copy link
Contributor

@Melkiades Melkiades commented Feb 14, 2024

What changes are proposed in this pull request?

  • Added ard_mcnemartest() statistical test function.

Closes #40

  • I am wondering if we need to have ccorrect = TRUE as default, following the default in stats, and if we should make this option more apparent in the case we change this default.

  • Also, I do not know if it would be relevant but I used an utility function to find dichotomies in a data-set that could result useful as a tool if there is not one already doing this:

# Assuming your data.frame is named df
df <- data.frame(
  A = c(1, 0, 1, 0), # dichotomous
  B = c(1, 2, 3, 4), # not dichotomous
  C = c("Yes", "No", "Yes", "No"), # dichotomous
  D = c(TRUE, FALSE, TRUE, FALSE) # dichotomous
)

# Function to find dichotomous columns
find_dichotomous_columns <- function(df) {
  dichotomous_columns <- c()
  for (col_name in names(df)) {
    if (length(unique(df[[col_name]])) == 2) {
      dichotomous_columns <- c(dichotomous_columns, col_name)
    }
  }
  return(dichotomous_columns)
}

# Find and display dichotomous columns
dichotomous_columns <- find_dichotomous_columns(df)
print(dichotomous_columns)
#> [1] "A" "C" "D"
di_cols <- find_dichotomous_columns(cards::ADSL)
print(di_cols)
#>  [1] "SEX"      "ETHNIC"   "EFFFL"    "COMP8FL"  "COMP16FL" "COMP24FL"
#>  [7] "DISCONFL" "DSRAEFL"  "DTHFL"    "DURDSGR1"

Created on 2024-02-14 with reprex v2.1.0

  • .paired_data_pivot_wider is in the Wilcoxon test. Should we have it as a tool in a dedicated file? It looks general to me.

Pre-review Checklist (if item does not apply, mark is as complete)

  • All GitHub Action workflows pass with a ✅
  • PR branch has pulled the most recent updates from master branch: usethis::pr_merge_main()
  • If a bug was fixed, a unit test was added.
  • Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): devtools::test_coverage()
  • Request a reviewer

Reviewer Checklist (if item does not apply, mark is as complete)

  • If a bug was fixed, a unit test was added.
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Code coverage is suitable for any new functions/features: devtools::test_coverage()

When the branch is ready to be merged:

  • Update NEWS.md with the changes from this pull request under the heading "# cards (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • All GitHub Action workflows pass with a ✅
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge" or "Rebase and merge".

@Melkiades Melkiades added enhancement New feature or request sme ARD labels Feb 14, 2024
Copy link
Contributor

github-actions bot commented Feb 14, 2024

Unit Tests Summary

 1 files  14 suites   2s ⏱️
14 tests 10 ✅ 4 💤 0 ❌
30 runs  22 ✅ 8 💤 0 ❌

Results for commit 5781b8d.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Feb 14, 2024

badge

Code Coverage Summary

Filename                 Stmts    Miss  Cover    Missing
---------------------  -------  ------  -------  ------------------------------------
R/ard_chisqtest.R           31       0  100.00%
R/ard_fishertest.R          33       0  100.00%
R/ard_kruskaltest.R         27       0  100.00%
R/ard_mcnemartest.R         41       0  100.00%
R/ard_proportion_ci.R       40       5  87.50%   63-67
R/ard_regression.R          49       0  100.00%
R/ard_ttest.R               78       0  100.00%
R/ard_wilcoxtest.R          83       0  100.00%
R/proportion_ci.R          182      28  84.62%   241, 244, 253-258, 266, 281, 381-404
TOTAL                      564      33  94.15%

Diff against main

Filename               Stmts    Miss  Cover
-------------------  -------  ------  --------
R/ard_mcnemartest.R      +41       0  +100.00%
TOTAL                    +41       0  +0.46%

Results for commit: 5781b8d

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Feb 14, 2024

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
ard_mcnemartest 👶 $+0.17$ $+4$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
ard_mcnemartest 👶 $+0.17$ ard_mcnemartest_works

Results for commit 462ffb7

♻️ This comment has been updated with latest results.

@Melkiades Melkiades requested a review from ddsjoberg February 15, 2024 14:59
R/ard_mcnemartest.R Outdated Show resolved Hide resolved
@ddsjoberg
Copy link
Collaborator

thanks @Melkiades !

I am wondering if we need to have correct = TRUE as default, following the default in stats, and if we should make this option more apparent in the case we change this default.

Let's keep the same defaults as the the R function. To keep the API consistent with the other ard stat functions, we can still use ... with the explanation that these results will be passed to mcnemar.test(...). We can use the @inheritDotParams tag to make it very clear which options the user has.

.paired_data_pivot_wider is in the Wilcoxon test. Should we have it as a tool in a dedicated file? It looks general to me.

Very good point. A separate utils.R file would be great place for this function. Or do you think we make it an exported utility , and if we do that, should it live in cards instead?

Co-authored-by: Abinaya Yogasekaram <[email protected]>
Signed-off-by: Davide Garolini <[email protected]>
@Melkiades
Copy link
Contributor Author

.paired_data_pivot_wider is in the Wilcoxon test. Should we have it as a tool in a dedicated file? It looks general to me.

Very good point. A separate utils.R file would be great place for this function. Or do you think we make it an exported utility , and if we do that, should it live in cards instead?

To me, it seems useful, but I do not know if it is necessarily a missing piece in {cards}' toolbox. I would add it to a group of related utils and export it if you think it would be used. For users, I would make by1 and by2 customizable and the paired values as defaults (also could it make sense to extend it beyond paired data?).

Copy link
Collaborator

@ddsjoberg ddsjoberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Just a few comments to address.

R/ard_mcnemartest.R Outdated Show resolved Hide resolved
R/ard_mcnemartest.R Outdated Show resolved Hide resolved
tests/testthat/test-ard_mcnemartest.R Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@Melkiades
Copy link
Contributor Author

@ddsjoberg thank you for your review! Could you take another look at the changes? ;)

Copy link
Collaborator

@ddsjoberg ddsjoberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Melkiades !! looks great!!

@ddsjoberg ddsjoberg merged commit 39ccf3f into main Feb 21, 2024
28 checks passed
@ddsjoberg ddsjoberg deleted the 40_ard_mcnemar_test@main branch February 21, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARD enhancement New feature or request sme
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ARD for McNemar's Test
4 participants