From 5f18d9fd66c1e6f495e4ed2a5a1c7d3f7e338639 Mon Sep 17 00:00:00 2001 From: SERDAR BALCI Date: Sun, 10 May 2020 17:12:40 +0300 Subject: [PATCH] pairwise chi-square formulas must be controlled --- .github/workflows/main.yml | 366 ++++---- .../workflows/r-lib-actions-R-CMD-check.yml | 28 +- .github/workflows/r-lib-actions-readme.yml | 46 +- .travis.yml | 54 -- AAA.travis.yml | 54 ++ AAAappveyor.yml | 29 + AAAcodecov.yml | 12 + NAMESPACE | 2 +- R/pairchi.h.R | 60 +- R/{pairchi.b.R => pairchi2.b.R} | 78 +- R/pairchi2.h.R | 778 ++++++++++++++++++ appveyor.yml | 29 - codecov.yml | 12 - jamovi/0000.yaml | 2 +- jamovi/{pairchi.a.yaml => pairchi2.a.yaml} | 2 +- jamovi/{pairchi.r.yaml => pairchi2.r.yaml} | 32 +- jamovi/{pairchi.u.yaml => pairchi2.u.yaml} | 2 +- man/crosstable.Rd | 2 +- man/{pairchi.Rd => pairchi2.Rd} | 98 ++- man/{pairchiClass.Rd => pairchi2Class.Rd} | 14 +- tododata/todo.Rmd | 70 +- 21 files changed, 1382 insertions(+), 388 deletions(-) delete mode 100644 .travis.yml create mode 100644 AAA.travis.yml create mode 100644 AAAappveyor.yml create mode 100644 AAAcodecov.yml rename R/{pairchi.b.R => pairchi2.b.R} (93%) create mode 100644 R/pairchi2.h.R delete mode 100644 appveyor.yml delete mode 100644 codecov.yml rename jamovi/{pairchi.a.yaml => pairchi2.a.yaml} (99%) rename jamovi/{pairchi.r.yaml => pairchi2.r.yaml} (90%) rename jamovi/{pairchi.u.yaml => pairchi2.u.yaml} (99%) rename man/{pairchi.Rd => pairchi2.Rd} (63%) rename man/{pairchiClass.Rd => pairchi2Class.Rd} (92%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 73f6cbd1..f2b3b7c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,183 +1,183 @@ -on: - push: - pull_request: - # for now, CRON jobs only run on the default branch of the repo (i.e. usually on master) - schedule: - # * is a special character in YAML so you have to quote this string - - cron: "0 4 * * *" - -name: R CMD Check via {tic} - -jobs: - R-CMD-check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - # comment out lines if you do not want to build on certain platforms - - { os: windows-latest, r: "release" } - - { os: macOS-latest, r: "release", pkgdown: "true" } - - { os: macOS-latest, r: "devel" } - - { os: ubuntu-latest, r: "release" } - - env: - # otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - CRAN: ${{ matrix.config.cran }} - # we are not allowed to write to ~/.ccache on GH Actions - # setting some ccache options - CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }} - CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache - CCACHE_NOHASHDIR: true - CCACHE_SLOPPINESS: include_file_ctime - # make sure to run `tic::use_ghactions_deploy()` to set up deployment - TIC_DEPLOY_KEY: ${{ secrets.TIC_DEPLOY_KEY }} - # prevent rgl issues because no X11 display is available - RGL_USE_NULL: true - # if you use bookdown or blogdown, replace "PKGDOWN" by the respective - # capitalized term. This also might need to be done in tic.R - BUILD_PKGDOWN: ${{ matrix.config.pkgdown }} - # macOS >= 10.15.4 linking - SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@master - with: - r-version: ${{ matrix.config.r }} - Ncpus: 4 - - # LaTeX. Installation time: - # Linux: ~ 1 min - # macOS: ~ 1 min 30s - # Windows: never finishes - - uses: r-lib/actions/setup-tinytex@v1 - if: runner.os != 'Windows' - - - uses: r-lib/actions/setup-pandoc@master - - # set date/week for use in cache creation - # https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970 - # - cache R packages daily - # - cache ccache weekly -> 'ccache' helps rebuilding the package cache faster - - name: "[Cache] Prepare daily timestamp for cache" - if: runner.os != 'Windows' - id: date - run: echo "::set-output name=date::$(date '+%d-%m')" - - - name: "[Cache] Prepare weekly timestamp for cache" - if: runner.os != 'Windows' - id: datew - run: echo "::set-output name=datew::$(date '+%Y-%V')" - - - name: "[Cache] Cache R packages" - if: runner.os != 'Windows' - uses: pat-s/always-upload-cache@v1.1.4 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}} - restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}} - - - name: "[Cache] Cache ccache" - if: runner.os != 'Windows' - uses: pat-s/always-upload-cache@v1.1.4 - with: - path: ${{ env.CCACHE_DIR}} - key: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}} - restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}} - - # install ccache and write config file - - name: "[Linux] ccache" - if: runner.os == 'Linux' - run: | - sudo apt install ccache libcurl4-openssl-dev - mkdir -p ~/.R && echo -e 'CC=ccache gcc -std=gnu99\nCXX=ccache g++\nFC=ccache gfortran\nF77=ccache gfortran' > $HOME/.R/Makevars - - # install ccache and write config file - # mirror the setup described in https://github.com/rmacoslib/r-macos-rtools - - name: "[macOS] ccache" - if: runner.os == 'macOS' && matrix.config.r != 'devel' - run: | - brew install ccache - wget https://cran.r-project.org/bin/macosx/tools/clang-7.0.0.pkg - sudo installer -package clang-7.0.0.pkg -target / - mkdir -p ~/.R && echo -e 'CC=ccache clang\nCPP=ccache clang\nCXX=ccache clang++\nCXX11=ccache clang++\nCXX14=ccache clang++\nCXX17=ccache clang++\nCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\nCCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\nCXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\nCPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include\nF77=ccache /usr/local/gfortran/bin/gfortran\nFC=ccache /usr/local/gfortran/bin/gfortran' > $HOME/.R/Makevars - - # install ccache and write config file - # mirror the setup described in https://github.com/rmacoslib/r-macos-rtools - - name: "[macOS-devel] ccache" - if: runner.os == 'macOS' && matrix.config.r == 'devel' - run: | - brew install ccache - # install SDK 10.13 (High Sierra, used by CRAN) - wget -nv https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.13.sdk.tar.xz - tar fxz MacOSX10.13.sdk.tar.xz - sudo mv MacOSX10.13.sdk /Library/Developer/CommandLineTools/SDKs/ - rm -rf MacOSX10.13* - # install gfortran 8.2 (used by CRAN) - wget -nv https://github.com/fxcoudert/gfortran-for-macOS/releases/download/8.2/gfortran-8.2-Mojave.dmg - sudo hdiutil attach gfortran*.dmg - sudo installer -package /Volumes/gfortran*/gfortran*/gfortran*.pkg -target / - sudo hdiutil detach /Volumes/gfortran-8.2-Mojave - rm gfortran-8* - # set compiler flags - mkdir -p ~/.R && echo -e 'CC=ccache clang\nCPP=ccache clang\nCXX=ccache clang++\nCXX11=ccache clang++\nCXX14=ccache clang++\nCXX17=ccache clang++\nCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk\nCCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk\nCXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk\nCPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk -I/usr/local/include\nF77=ccache /usr/local/gfortran/bin/gfortran\nFC=ccache /usr/local/gfortran/bin/gfortran' > $HOME/.R/Makevars - - # for some strange Windows reason this step and the next one need to be decoupled - - name: "[Stage] Prepare" - run: | - Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')" - Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')" - - - name: "[Stage] Install" - if: matrix.config.os != 'macOS-latest' || matrix.config.r != 'devel' - run: Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" - - # macOS devel needs its own stage because we need to work with an options to suppress the usage of binaries - - name: "[Stage] Prepare & Install (macOS-devel)" - if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'devel' - run: | - echo -e 'options(Ncpus = 4, pkgType = "source", repos = structure(c(CRAN = "https://cloud.r-project.org/")))' > $HOME/.Rprofile - Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" - - - - - name: "Install non-default packages" - run: | - Rscript -e "if (!requireNamespace('jmvtools')) install.packages('jmvtools', repos=c('https://repo.jamovi.org', 'https://cran.r-project.org'))" - Rscript -e "if (!requireNamespace('finalfit')) install.packages('finalfit', type = 'source')" - Rscript -e "if (!requireNamespace('ggstatsplot')) install.packages('ggstatsplot', type = 'source')" - Rscript -e "if (!requireNamespace('tableone')) install.packages('tableone', type = 'source')" - Rscript -e "if (!requireNamespace('kableExtra')) install.packages('kableExtra', type = 'source')" - Rscript -e "if (!requireNamespace('caret')) install.packages('caret', type = 'source')" - Rscript -e "if (!requireNamespace('vtree')) install.packages('vtree', type = 'source')" - Rscript -e "if (!requireNamespace('correlation')) install.packages('correlation', type = 'source')" - - - name: "[Stage] Script" - run: Rscript -e 'tic::script()' - - - name: "[Stage] After Success" - if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release' - run: Rscript -e "tic::after_success()" - - - name: "[Stage] Upload R CMD check artifacts" - if: failure() - uses: actions/upload-artifact@master - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check - - name: "[Stage] Before Deploy" - run: | - Rscript -e "tic::before_deploy()" - - - name: "[Stage] Deploy" - run: Rscript -e "tic::deploy()" - - - name: "[Stage] After Deploy" - run: Rscript -e "tic::after_deploy()" - +# on: +# push: +# pull_request: +# # for now, CRON jobs only run on the default branch of the repo (i.e. usually on master) +# schedule: +# # * is a special character in YAML so you have to quote this string +# - cron: "0 4 * * *" +# +# name: R CMD Check via {tic} +# +# jobs: +# R-CMD-check: +# runs-on: ${{ matrix.config.os }} +# +# name: ${{ matrix.config.os }} (${{ matrix.config.r }}) +# +# strategy: +# fail-fast: false +# matrix: +# config: +# # comment out lines if you do not want to build on certain platforms +# - { os: windows-latest, r: "release" } +# - { os: macOS-latest, r: "release", pkgdown: "true" } +# - { os: macOS-latest, r: "devel" } +# - { os: ubuntu-latest, r: "release" } +# +# env: +# # otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries +# R_REMOTES_NO_ERRORS_FROM_WARNINGS: true +# CRAN: ${{ matrix.config.cran }} +# # we are not allowed to write to ~/.ccache on GH Actions +# # setting some ccache options +# CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }} +# CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache +# CCACHE_NOHASHDIR: true +# CCACHE_SLOPPINESS: include_file_ctime +# # make sure to run `tic::use_ghactions_deploy()` to set up deployment +# TIC_DEPLOY_KEY: ${{ secrets.TIC_DEPLOY_KEY }} +# # prevent rgl issues because no X11 display is available +# RGL_USE_NULL: true +# # if you use bookdown or blogdown, replace "PKGDOWN" by the respective +# # capitalized term. This also might need to be done in tic.R +# BUILD_PKGDOWN: ${{ matrix.config.pkgdown }} +# # macOS >= 10.15.4 linking +# SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk +# +# steps: +# - uses: actions/checkout@v2 +# +# - uses: r-lib/actions/setup-r@master +# with: +# r-version: ${{ matrix.config.r }} +# Ncpus: 4 +# +# # LaTeX. Installation time: +# # Linux: ~ 1 min +# # macOS: ~ 1 min 30s +# # Windows: never finishes +# - uses: r-lib/actions/setup-tinytex@v1 +# if: runner.os != 'Windows' +# +# - uses: r-lib/actions/setup-pandoc@master +# +# # set date/week for use in cache creation +# # https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970 +# # - cache R packages daily +# # - cache ccache weekly -> 'ccache' helps rebuilding the package cache faster +# - name: "[Cache] Prepare daily timestamp for cache" +# if: runner.os != 'Windows' +# id: date +# run: echo "::set-output name=date::$(date '+%d-%m')" +# +# - name: "[Cache] Prepare weekly timestamp for cache" +# if: runner.os != 'Windows' +# id: datew +# run: echo "::set-output name=datew::$(date '+%Y-%V')" +# +# - name: "[Cache] Cache R packages" +# if: runner.os != 'Windows' +# uses: pat-s/always-upload-cache@v1.1.4 +# with: +# path: ${{ env.R_LIBS_USER }} +# key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}} +# restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}} +# +# - name: "[Cache] Cache ccache" +# if: runner.os != 'Windows' +# uses: pat-s/always-upload-cache@v1.1.4 +# with: +# path: ${{ env.CCACHE_DIR}} +# key: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}} +# restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-ccache-${{steps.datew.outputs.datew}} +# +# # install ccache and write config file +# - name: "[Linux] ccache" +# if: runner.os == 'Linux' +# run: | +# sudo apt install ccache libcurl4-openssl-dev +# mkdir -p ~/.R && echo -e 'CC=ccache gcc -std=gnu99\nCXX=ccache g++\nFC=ccache gfortran\nF77=ccache gfortran' > $HOME/.R/Makevars +# +# # install ccache and write config file +# # mirror the setup described in https://github.com/rmacoslib/r-macos-rtools +# - name: "[macOS] ccache" +# if: runner.os == 'macOS' && matrix.config.r != 'devel' +# run: | +# brew install ccache +# wget https://cran.r-project.org/bin/macosx/tools/clang-7.0.0.pkg +# sudo installer -package clang-7.0.0.pkg -target / +# mkdir -p ~/.R && echo -e 'CC=ccache clang\nCPP=ccache clang\nCXX=ccache clang++\nCXX11=ccache clang++\nCXX14=ccache clang++\nCXX17=ccache clang++\nCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\nCCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\nCXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\nCPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include\nF77=ccache /usr/local/gfortran/bin/gfortran\nFC=ccache /usr/local/gfortran/bin/gfortran' > $HOME/.R/Makevars +# +# # install ccache and write config file +# # mirror the setup described in https://github.com/rmacoslib/r-macos-rtools +# - name: "[macOS-devel] ccache" +# if: runner.os == 'macOS' && matrix.config.r == 'devel' +# run: | +# brew install ccache +# # install SDK 10.13 (High Sierra, used by CRAN) +# wget -nv https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.13.sdk.tar.xz +# tar fxz MacOSX10.13.sdk.tar.xz +# sudo mv MacOSX10.13.sdk /Library/Developer/CommandLineTools/SDKs/ +# rm -rf MacOSX10.13* +# # install gfortran 8.2 (used by CRAN) +# wget -nv https://github.com/fxcoudert/gfortran-for-macOS/releases/download/8.2/gfortran-8.2-Mojave.dmg +# sudo hdiutil attach gfortran*.dmg +# sudo installer -package /Volumes/gfortran*/gfortran*/gfortran*.pkg -target / +# sudo hdiutil detach /Volumes/gfortran-8.2-Mojave +# rm gfortran-8* +# # set compiler flags +# mkdir -p ~/.R && echo -e 'CC=ccache clang\nCPP=ccache clang\nCXX=ccache clang++\nCXX11=ccache clang++\nCXX14=ccache clang++\nCXX17=ccache clang++\nCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk\nCCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk\nCXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk\nCPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk -I/usr/local/include\nF77=ccache /usr/local/gfortran/bin/gfortran\nFC=ccache /usr/local/gfortran/bin/gfortran' > $HOME/.R/Makevars +# +# # for some strange Windows reason this step and the next one need to be decoupled +# - name: "[Stage] Prepare" +# run: | +# Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')" +# Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')" +# +# - name: "[Stage] Install" +# if: matrix.config.os != 'macOS-latest' || matrix.config.r != 'devel' +# run: Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" +# +# # macOS devel needs its own stage because we need to work with an options to suppress the usage of binaries +# - name: "[Stage] Prepare & Install (macOS-devel)" +# if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'devel' +# run: | +# echo -e 'options(Ncpus = 4, pkgType = "source", repos = structure(c(CRAN = "https://cloud.r-project.org/")))' > $HOME/.Rprofile +# Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" +# +# +# +# - name: "Install non-default packages" +# run: | +# Rscript -e "if (!requireNamespace('jmvtools')) install.packages('jmvtools', repos=c('https://repo.jamovi.org', 'https://cran.r-project.org'))" +# Rscript -e "if (!requireNamespace('finalfit')) install.packages('finalfit', type = 'source')" +# Rscript -e "if (!requireNamespace('ggstatsplot')) install.packages('ggstatsplot', type = 'source')" +# Rscript -e "if (!requireNamespace('tableone')) install.packages('tableone', type = 'source')" +# Rscript -e "if (!requireNamespace('kableExtra')) install.packages('kableExtra', type = 'source')" +# Rscript -e "if (!requireNamespace('caret')) install.packages('caret', type = 'source')" +# Rscript -e "if (!requireNamespace('vtree')) install.packages('vtree', type = 'source')" +# Rscript -e "if (!requireNamespace('correlation')) install.packages('correlation', type = 'source')" +# +# - name: "[Stage] Script" +# run: Rscript -e 'tic::script()' +# +# - name: "[Stage] After Success" +# if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release' +# run: Rscript -e "tic::after_success()" +# +# - name: "[Stage] Upload R CMD check artifacts" +# if: failure() +# uses: actions/upload-artifact@master +# with: +# name: ${{ runner.os }}-r${{ matrix.config.r }}-results +# path: check +# - name: "[Stage] Before Deploy" +# run: | +# Rscript -e "tic::before_deploy()" +# +# - name: "[Stage] Deploy" +# run: Rscript -e "tic::deploy()" +# +# - name: "[Stage] After Deploy" +# run: Rscript -e "tic::after_deploy()" +# diff --git a/.github/workflows/r-lib-actions-R-CMD-check.yml b/.github/workflows/r-lib-actions-R-CMD-check.yml index ea5d3b87..641dea7b 100644 --- a/.github/workflows/r-lib-actions-R-CMD-check.yml +++ b/.github/workflows/r-lib-actions-R-CMD-check.yml @@ -1,14 +1,14 @@ -on: [push, pull_request] - -name: R-CMD-check - -jobs: - R-CMD-check: - runs-on: macOS-latest - steps: - - uses: actions/checkout@v1 - - uses: r-lib/actions/setup-r@master - - name: Install dependencies - run: Rscript -e "install.packages(c('remotes', 'rcmdcheck'))" -e "remotes::install_deps(dependencies = TRUE)" - - name: Check - run: Rscript -e "rcmdcheck::rcmdcheck(args = '--no-manual', error_on = 'error')" +# on: [push, pull_request] +# +# name: R-CMD-check +# +# jobs: +# R-CMD-check: +# runs-on: macOS-latest +# steps: +# - uses: actions/checkout@v1 +# - uses: r-lib/actions/setup-r@master +# - name: Install dependencies +# run: Rscript -e "install.packages(c('remotes', 'rcmdcheck'))" -e "remotes::install_deps(dependencies = TRUE)" +# - name: Check +# run: Rscript -e "rcmdcheck::rcmdcheck(args = '--no-manual', error_on = 'error')" diff --git a/.github/workflows/r-lib-actions-readme.yml b/.github/workflows/r-lib-actions-readme.yml index b72b1afa..d554b96b 100644 --- a/.github/workflows/r-lib-actions-readme.yml +++ b/.github/workflows/r-lib-actions-readme.yml @@ -1,23 +1,23 @@ -on: - push: - paths: - - README.Rmd - -name: Render README - -jobs: - render: - name: Render README - runs-on: macos-latest - steps: - - uses: actions/checkout@v1 - - uses: r-lib/actions/setup-r@v1 - - uses: r-lib/actions/setup-pandoc@v1 - - name: Install rmarkdown - run: Rscript -e "install.packages('rmarkdown')" - - name: Render README - run: Rscript -e "rmarkdown::render('README.Rmd')" - - name: Commit results - run: | - git commit examples/README.md -m 'Re-build README.Rmd' || echo "No changes to commit" - git push https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:${{ github.ref }} || echo "No changes to commit" +# on: +# push: +# paths: +# - README.Rmd +# +# name: Render README +# +# jobs: +# render: +# name: Render README +# runs-on: macos-latest +# steps: +# - uses: actions/checkout@v1 +# - uses: r-lib/actions/setup-r@v1 +# - uses: r-lib/actions/setup-pandoc@v1 +# - name: Install rmarkdown +# run: Rscript -e "install.packages('rmarkdown')" +# - name: Render README +# run: Rscript -e "rmarkdown::render('README.Rmd')" +# - name: Commit results +# run: | +# git commit examples/README.md -m 'Re-build README.Rmd' || echo "No changes to commit" +# git push https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:${{ github.ref }} || echo "No changes to commit" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f889a4e9..00000000 --- a/.travis.yml +++ /dev/null @@ -1,54 +0,0 @@ -# OS: Linux + macOS ------------------------------------------------------------ -# tic documentation: https://docs.ropensci.org/tic/dev/ - -matrix: - include: - - os: osx - r: release - - os: linux - r: release - env: - - BUILD_PKGDOWN=true - -# meta ------------------------------------------------------------------------- -language: r -cache: - - packages - - $HOME/.ccache - - $HOME/Library/Caches/Homebrew -latex: false - -# environment variables -------------------------------------------------------- - -env: - global: - - MAKEFLAGS="-j 2" - -# Stages ----------------------------------------------------------------------- - -before_install: - - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then brew install ccache; fi - - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi - - echo -e "options(Ncpus = 8, repos = structure(c(CRAN = 'https://cloud.r-project.org/')))" > $HOME/.Rprofile - - mkdir -p $HOME/.R && echo -e 'CXX_STD = CXX14\n\nCC=ccache gcc -std=gnu99\nCXX=ccache g++\nCXX11=ccache g++ -std=gnu99\nCXX14=ccache g++ -std=gnu99\nC11=ccache g++\nC14=ccache g++\nFC=ccache gfortran\nF77=ccache gfortran' > $HOME/.R/Makevars - - mkdir -p $HOME/.ccache && echo -e 'max_size = 5.0G\nsloppiness = include_file_ctime\nhash_dir=false' > $HOME/.ccache/ccache.conf - - R -q -e 'if (!requireNamespace("remotes")) install.packages("remotes")' - - R -q -e 'if (getRversion() < "3.2" && !requireNamespace("curl")) install.packages("curl")' - - R -q -e 'remotes::install_github("ropensci/tic", upgrade = "always"); print(tic::dsl_load()); tic::prepare_all_stages()' - - R -q -e 'tic::before_install()' -install: - - R -q -e 'tic::install()' -before_script: R -q -e 'tic::before_script()' -script: R -q -e 'tic::script()' -after_success: R -q -e 'tic::after_success()' -after_failure: R -q -e 'tic::after_failure()' -before_deploy: R -q -e 'tic::before_deploy()' -deploy: - provider: script - script: R -q -e 'tic::deploy()' - on: - all_branches: true -after_deploy: R -q -e 'tic::after_deploy()' -after_script: R -q -e 'tic::after_script()' - -# Custom user code ------------------------------------------------------------- diff --git a/AAA.travis.yml b/AAA.travis.yml new file mode 100644 index 00000000..c16506ff --- /dev/null +++ b/AAA.travis.yml @@ -0,0 +1,54 @@ +# # OS: Linux + macOS ------------------------------------------------------------ +# # tic documentation: https://docs.ropensci.org/tic/dev/ +# +# matrix: +# include: +# - os: osx +# r: release +# - os: linux +# r: release +# env: +# - BUILD_PKGDOWN=true +# +# # meta ------------------------------------------------------------------------- +# language: r +# cache: +# - packages +# - $HOME/.ccache +# - $HOME/Library/Caches/Homebrew +# latex: false +# +# # environment variables -------------------------------------------------------- +# +# env: +# global: +# - MAKEFLAGS="-j 2" +# +# # Stages ----------------------------------------------------------------------- +# +# before_install: +# - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then brew install ccache; fi +# - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi +# - echo -e "options(Ncpus = 8, repos = structure(c(CRAN = 'https://cloud.r-project.org/')))" > $HOME/.Rprofile +# - mkdir -p $HOME/.R && echo -e 'CXX_STD = CXX14\n\nCC=ccache gcc -std=gnu99\nCXX=ccache g++\nCXX11=ccache g++ -std=gnu99\nCXX14=ccache g++ -std=gnu99\nC11=ccache g++\nC14=ccache g++\nFC=ccache gfortran\nF77=ccache gfortran' > $HOME/.R/Makevars +# - mkdir -p $HOME/.ccache && echo -e 'max_size = 5.0G\nsloppiness = include_file_ctime\nhash_dir=false' > $HOME/.ccache/ccache.conf +# - R -q -e 'if (!requireNamespace("remotes")) install.packages("remotes")' +# - R -q -e 'if (getRversion() < "3.2" && !requireNamespace("curl")) install.packages("curl")' +# - R -q -e 'remotes::install_github("ropensci/tic", upgrade = "always"); print(tic::dsl_load()); tic::prepare_all_stages()' +# - R -q -e 'tic::before_install()' +# install: +# - R -q -e 'tic::install()' +# before_script: R -q -e 'tic::before_script()' +# script: R -q -e 'tic::script()' +# after_success: R -q -e 'tic::after_success()' +# after_failure: R -q -e 'tic::after_failure()' +# before_deploy: R -q -e 'tic::before_deploy()' +# deploy: +# provider: script +# script: R -q -e 'tic::deploy()' +# on: +# all_branches: true +# after_deploy: R -q -e 'tic::after_deploy()' +# after_script: R -q -e 'tic::after_script()' +# +# # Custom user code ------------------------------------------------------------- diff --git a/AAAappveyor.yml b/AAAappveyor.yml new file mode 100644 index 00000000..c1848a83 --- /dev/null +++ b/AAAappveyor.yml @@ -0,0 +1,29 @@ +# # tic documentation: https://docs.ropensci.org/tic/dev/ +# +# # Download script file from GitHub +# init: +# ps: | +# $ErrorActionPreference = "Stop" +# Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" +# Import-Module '..\appveyor-tool.ps1' +# +# install: +# - ps: Bootstrap +# - cmd: Rscript -e "writeLines('options(repos = \'https://cloud.r-project.org\')', '~/.Rprofile')" +# - cmd: Rscript -e "getOption('repos')" +# - cmd: Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'binary')" +# - cmd: Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'binary')" +# - cmd: Rscript -e "options(pkgType = 'binary'); remotes::install_github('ropensci/tic', upgrade = 'always'); print(tic::dsl_load()); tic::prepare_all_stages()" +# +# before_build: Rscript -e "tic::before_install()" +# build_script: Rscript -e "tic::install()" +# after_build: Rscript -e "tic::after_install()" +# before_test: Rscript -e "tic::before_script()" +# test_script: Rscript -e "tic::script()" +# on_success: Rscript -e "try(tic::after_success(), silent = TRUE)" +# on_failure: Rscript -e "tic::after_failure()" +# before_deploy: Rscript -e "tic::before_deploy()" +# deploy_script: Rscript -e "tic::deploy()" +# after_deploy: Rscript -e "tic::after_deploy()" +# on_finish: Rscript -e "tic::after_script()" +# # Custom user code ------------------------------------------------------------- diff --git a/AAAcodecov.yml b/AAAcodecov.yml new file mode 100644 index 00000000..82958cbe --- /dev/null +++ b/AAAcodecov.yml @@ -0,0 +1,12 @@ +# comment: false +# +# coverage: +# status: +# project: +# default: +# target: auto +# threshold: 1% +# patch: +# default: +# target: auto +# threshold: 1% diff --git a/NAMESPACE b/NAMESPACE index 7be2ef0c..c755a32c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,7 +13,7 @@ export(gtsummaryClass) export(icccoeff) export(multisurvival) export(oddsratio) -export(pairchi) +export(pairchi2) export(reportcat) export(roc) export(statsplot2) diff --git a/R/pairchi.h.R b/R/pairchi.h.R index a3846c7b..c07ba9dc 100644 --- a/R/pairchi.h.R +++ b/R/pairchi.h.R @@ -1,8 +1,8 @@ # This file is automatically generated, you probably don't want to edit this -pairchiOptions <- if (requireNamespace('jmvcore')) R6::R6Class( - "pairchiOptions", +pairchi2Options <- if (requireNamespace('jmvcore')) R6::R6Class( + "pairchi2Options", inherit = jmvcore::Options, public = list( initialize = function( @@ -32,7 +32,7 @@ pairchiOptions <- if (requireNamespace('jmvcore')) R6::R6Class( super$initialize( package='ClinicoPath', - name='pairchi', + name='pairchi2', requiresData=TRUE, ...) @@ -219,7 +219,7 @@ pairchiOptions <- if (requireNamespace('jmvcore')) R6::R6Class( ..pairw = NA) ) -pairchiResults <- if (requireNamespace('jmvcore')) R6::R6Class( +pairchi2Results <- if (requireNamespace('jmvcore')) R6::R6Class( inherit = jmvcore::Group, active = list( freqs = function() private$.items[["freqs"]], @@ -228,7 +228,8 @@ pairchiResults <- if (requireNamespace('jmvcore')) R6::R6Class( nom = function() private$.items[["nom"]], gamma = function() private$.items[["gamma"]], taub = function() private$.items[["taub"]], - pw = function() private$.items[["pw"]]), + pw = function() private$.items[["pw"]], + tablepw = function() private$.items[["tablepw"]]), private = list(), public=list( initialize=function(options) { @@ -508,19 +509,49 @@ pairchiResults <- if (requireNamespace('jmvcore')) R6::R6Class( self$add(jmvcore::Preformatted$new( options=options, name="pw", - title="Pairwise Chi-Square Comparison"))})) + title="Pairwise Chi-Square Comparison")) + self$add(jmvcore::Table$new( + options=options, + name="tablepw", + title="Pairwise Chi-Square Comparison", + visible="(pairw)", + rows=1, + columns=list( + list( + `name`="method", + `title`="Method", + `type`="text"), + list( + `name`="v1", + `title`="Variable 1", + `type`="text"), + list( + `name`="v2", + `title`="Variable 2", + `type`="text"), + list( + `name`="pv", + `title`="p-value", + `type`="number", + `format`="zto,pvalue")), + clearWith=list( + "rows", + "cols", + "counts", + "layers", + "pairw")))})) -pairchiBase <- if (requireNamespace('jmvcore')) R6::R6Class( - "pairchiBase", +pairchi2Base <- if (requireNamespace('jmvcore')) R6::R6Class( + "pairchi2Base", inherit = jmvcore::Analysis, public = list( initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) { super$initialize( package = 'ClinicoPath', - name = 'pairchi', + name = 'pairchi2', version = c(1,0,0), options = options, - results = pairchiResults$new(options=options), + results = pairchi2Results$new(options=options), data = data, datasetId = datasetId, analysisId = analysisId, @@ -625,6 +656,7 @@ pairchiBase <- if (requireNamespace('jmvcore')) R6::R6Class( #' \code{results$gamma} \tab \tab \tab \tab \tab a table of the gamma test results \cr #' \code{results$taub} \tab \tab \tab \tab \tab a table of the Kendall's tau-b test results \cr #' \code{results$pw} \tab \tab \tab \tab \tab a preformatted \cr +#' \code{results$tablepw} \tab \tab \tab \tab \tab a table \cr #' } #' #' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example: @@ -634,7 +666,7 @@ pairchiBase <- if (requireNamespace('jmvcore')) R6::R6Class( #' \code{as.data.frame(results$freqs)} #' #' @export -pairchi <- function( +pairchi2 <- function( data, rows, cols, @@ -662,7 +694,7 @@ pairchi <- function( formula) { if ( ! requireNamespace('jmvcore')) - stop('pairchi requires jmvcore to be installed (restart may be required)') + stop('pairchi2 requires jmvcore to be installed (restart may be required)') if ( ! missing(formula)) { if (missing(counts)) @@ -711,7 +743,7 @@ pairchi <- function( for (v in cols) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]]) for (v in layers) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]]) - options <- pairchiOptions$new( + options <- pairchi2Options$new( rows = rows, cols = cols, counts = counts, @@ -736,7 +768,7 @@ pairchi <- function( pcTot = pcTot, pairw = pairw) - analysis <- pairchiClass$new( + analysis <- pairchi2Class$new( options = options, data = data) diff --git a/R/pairchi.b.R b/R/pairchi2.b.R similarity index 93% rename from R/pairchi.b.R rename to R/pairchi2.b.R index f324c73b..157fd47b 100644 --- a/R/pairchi.b.R +++ b/R/pairchi2.b.R @@ -6,9 +6,9 @@ #' @import rmngb -pairchiClass <- - if (requireNamespace("jmvcore")) R6::R6Class("pairchiClass", -inherit = pairchiBase, private = list( +pairchi2Class <- + if (requireNamespace("jmvcore")) R6::R6Class("pairchi2Class", +inherit = pairchi2Base, private = list( # TODO ---- @@ -320,6 +320,22 @@ inherit = pairchiBase, private = list( + # tablepw <- self$results$tablepw + # tablepw$setRow(rowNo = 1, + # values = list( + # method = "Pairwise Chi-Square", + # v1 = pwrow + # # v1 = pw[["rowname"]], + # # v2 = pw[["name"]], + # # vp = pw[["value"]] + # ) + # ) + + + + + + }) # suppressWarnings total <- sum(mat) @@ -638,43 +654,29 @@ inherit = pairchiBase, private = list( .pairwise = function(mat) { - - pairwiseRVAideMemoire <- RVAideMemoire::chisq.multcomp(mat) + # pairwiseRVAideMemoire <- RVAideMemoire::chisq.multcomp(mat) + # pairwisermngb <- rmngb::pairwise.chisq.test(as.table(mat)) + # pairwise <- list("RVAideMemoire" = pairwiseRVAideMemoire, + # "rmngb" = pairwisermngb) + # return(pairwise) + + # pairwiseRVAideMemoire <- RVAideMemoire::chisq.multcomp(mat) + # pairwiseRVAideMemoire <- pairwiseRVAideMemoire[["p.value"]] + # pairwiseRVAideMemoire <- as.data.frame(pairwiseRVAideMemoire) %>% + # tibble::rownames_to_column() + # pairwiseRVAideMemoire <- pairwiseRVAideMemoire %>% + # tidyr::pivot_longer(cols = -rowname) %>% + # dplyr::filter(complete.cases(.)) + # return(pairwiseRVAideMemoire) pairwisermngb <- rmngb::pairwise.chisq.test(as.table(mat)) - - - pairwise <- list("RVAideMemoire" = pairwiseRVAideMemoire, - "rmngb" = pairwisermngb) - - return(pairwise) - - - # dims <- dim(mat) - - # if (dims[1] > 2 || dims[2] > 2) - # return(NULL) - - # ciWidth <- self$options$ciWidth - # tail <- (100 - ciWidth) / 200 - # z <- qnorm(tail, lower.tail = FALSE) - - # a <- mat[1,1] - # b <- mat[1,2] - # c <- mat[2,1] - # d <- mat[2,2] - - # p1 <- a / (a + b) - # p2 <- c / (c + d) - - # m <- log(p1 / p2) - # s <- sqrt((b / (a*(a+b))) + (d / (c*(c+d)))) - # lower <- exp(m - z*s) - # upper <- exp(m + z*s) - - # rr <- p1 / p2 - - # return(list(rr=rr, lower=lower, upper=upper)) + pairwisermngb <- pairwisermngb[["p.value"]] + pairwisermngb <- as.data.frame(pairwisermngb) %>% + tibble::rownames_to_column() + pairwisermngb <- pairwisermngb %>% + tidyr::pivot_longer(cols = -rowname) %>% + dplyr::filter(complete.cases(.)) + return(pairwisermngb) }, diff --git a/R/pairchi2.h.R b/R/pairchi2.h.R new file mode 100644 index 00000000..c07ba9dc --- /dev/null +++ b/R/pairchi2.h.R @@ -0,0 +1,778 @@ + +# This file is automatically generated, you probably don't want to edit this + +pairchi2Options <- if (requireNamespace('jmvcore')) R6::R6Class( + "pairchi2Options", + inherit = jmvcore::Options, + public = list( + initialize = function( + rows = NULL, + cols = NULL, + counts = NULL, + layers = NULL, + chiSq = TRUE, + chiSqCorr = FALSE, + likeRat = FALSE, + fisher = FALSE, + contCoef = FALSE, + phiCra = FALSE, + logOdds = FALSE, + odds = FALSE, + relRisk = FALSE, + ci = TRUE, + ciWidth = 95, + gamma = FALSE, + taub = FALSE, + obs = TRUE, + exp = FALSE, + pcRow = FALSE, + pcCol = FALSE, + pcTot = FALSE, + pairw = FALSE, ...) { + + super$initialize( + package='ClinicoPath', + name='pairchi2', + requiresData=TRUE, + ...) + + private$..rows <- jmvcore::OptionVariable$new( + "rows", + rows, + suggested=list( + "nominal", + "ordinal"), + permitted=list( + "factor")) + private$..cols <- jmvcore::OptionVariable$new( + "cols", + cols, + suggested=list( + "nominal", + "ordinal"), + permitted=list( + "factor")) + private$..counts <- jmvcore::OptionVariable$new( + "counts", + counts, + suggested=list( + "continuous"), + permitted=list( + "numeric"), + default=NULL) + private$..layers <- jmvcore::OptionVariables$new( + "layers", + layers, + default=NULL, + permitted=list( + "factor")) + private$..chiSq <- jmvcore::OptionBool$new( + "chiSq", + chiSq, + default=TRUE) + private$..chiSqCorr <- jmvcore::OptionBool$new( + "chiSqCorr", + chiSqCorr, + default=FALSE) + private$..likeRat <- jmvcore::OptionBool$new( + "likeRat", + likeRat, + default=FALSE) + private$..fisher <- jmvcore::OptionBool$new( + "fisher", + fisher, + default=FALSE) + private$..contCoef <- jmvcore::OptionBool$new( + "contCoef", + contCoef, + default=FALSE) + private$..phiCra <- jmvcore::OptionBool$new( + "phiCra", + phiCra, + default=FALSE) + private$..logOdds <- jmvcore::OptionBool$new( + "logOdds", + logOdds, + default=FALSE) + private$..odds <- jmvcore::OptionBool$new( + "odds", + odds, + default=FALSE) + private$..relRisk <- jmvcore::OptionBool$new( + "relRisk", + relRisk, + default=FALSE) + private$..ci <- jmvcore::OptionBool$new( + "ci", + ci, + default=TRUE) + private$..ciWidth <- jmvcore::OptionNumber$new( + "ciWidth", + ciWidth, + min=50, + max=99.9, + default=95) + private$..gamma <- jmvcore::OptionBool$new( + "gamma", + gamma, + default=FALSE) + private$..taub <- jmvcore::OptionBool$new( + "taub", + taub, + default=FALSE) + private$..obs <- jmvcore::OptionBool$new( + "obs", + obs, + default=TRUE) + private$..exp <- jmvcore::OptionBool$new( + "exp", + exp, + default=FALSE) + private$..pcRow <- jmvcore::OptionBool$new( + "pcRow", + pcRow, + default=FALSE) + private$..pcCol <- jmvcore::OptionBool$new( + "pcCol", + pcCol, + default=FALSE) + private$..pcTot <- jmvcore::OptionBool$new( + "pcTot", + pcTot, + default=FALSE) + private$..pairw <- jmvcore::OptionBool$new( + "pairw", + pairw, + default=FALSE) + + self$.addOption(private$..rows) + self$.addOption(private$..cols) + self$.addOption(private$..counts) + self$.addOption(private$..layers) + self$.addOption(private$..chiSq) + self$.addOption(private$..chiSqCorr) + self$.addOption(private$..likeRat) + self$.addOption(private$..fisher) + self$.addOption(private$..contCoef) + self$.addOption(private$..phiCra) + self$.addOption(private$..logOdds) + self$.addOption(private$..odds) + self$.addOption(private$..relRisk) + self$.addOption(private$..ci) + self$.addOption(private$..ciWidth) + self$.addOption(private$..gamma) + self$.addOption(private$..taub) + self$.addOption(private$..obs) + self$.addOption(private$..exp) + self$.addOption(private$..pcRow) + self$.addOption(private$..pcCol) + self$.addOption(private$..pcTot) + self$.addOption(private$..pairw) + }), + active = list( + rows = function() private$..rows$value, + cols = function() private$..cols$value, + counts = function() private$..counts$value, + layers = function() private$..layers$value, + chiSq = function() private$..chiSq$value, + chiSqCorr = function() private$..chiSqCorr$value, + likeRat = function() private$..likeRat$value, + fisher = function() private$..fisher$value, + contCoef = function() private$..contCoef$value, + phiCra = function() private$..phiCra$value, + logOdds = function() private$..logOdds$value, + odds = function() private$..odds$value, + relRisk = function() private$..relRisk$value, + ci = function() private$..ci$value, + ciWidth = function() private$..ciWidth$value, + gamma = function() private$..gamma$value, + taub = function() private$..taub$value, + obs = function() private$..obs$value, + exp = function() private$..exp$value, + pcRow = function() private$..pcRow$value, + pcCol = function() private$..pcCol$value, + pcTot = function() private$..pcTot$value, + pairw = function() private$..pairw$value), + private = list( + ..rows = NA, + ..cols = NA, + ..counts = NA, + ..layers = NA, + ..chiSq = NA, + ..chiSqCorr = NA, + ..likeRat = NA, + ..fisher = NA, + ..contCoef = NA, + ..phiCra = NA, + ..logOdds = NA, + ..odds = NA, + ..relRisk = NA, + ..ci = NA, + ..ciWidth = NA, + ..gamma = NA, + ..taub = NA, + ..obs = NA, + ..exp = NA, + ..pcRow = NA, + ..pcCol = NA, + ..pcTot = NA, + ..pairw = NA) +) + +pairchi2Results <- if (requireNamespace('jmvcore')) R6::R6Class( + inherit = jmvcore::Group, + active = list( + freqs = function() private$.items[["freqs"]], + chiSq = function() private$.items[["chiSq"]], + odds = function() private$.items[["odds"]], + nom = function() private$.items[["nom"]], + gamma = function() private$.items[["gamma"]], + taub = function() private$.items[["taub"]], + pw = function() private$.items[["pw"]], + tablepw = function() private$.items[["tablepw"]]), + private = list(), + public=list( + initialize=function(options) { + super$initialize( + options=options, + name="", + title="Pairwise Chi-Square Test", + refs=list( + "rmngb", + "RVAideMemoire")) + self$add(jmvcore::Table$new( + options=options, + name="freqs", + title="Contingency Tables", + columns=list(), + clearWith=list( + "rows", + "cols", + "counts", + "layers"))) + self$add(jmvcore::Table$new( + options=options, + name="chiSq", + title="\u03C7\u00B2 Tests", + clearWith=list( + "rows", + "cols", + "counts", + "layers"), + columns=list( + list( + `name`="test[chiSq]", + `title`="", + `type`="text", + `content`="\u03C7\u00B2", + `visible`="(chiSq)"), + list( + `name`="value[chiSq]", + `title`="Value", + `visible`="(chiSq)"), + list( + `name`="df[chiSq]", + `title`="df", + `type`="integer", + `visible`="(chiSq)"), + list( + `name`="p[chiSq]", + `title`="p", + `type`="number", + `format`="zto,pvalue", + `visible`="(chiSq)"), + list( + `name`="test[chiSqCorr]", + `title`="", + `type`="text", + `content`="\u03C7\u00B2 continuity correction", + `visible`="(chiSqCorr)"), + list( + `name`="value[chiSqCorr]", + `title`="Value", + `visible`="(chiSqCorr)"), + list( + `name`="df[chiSqCorr]", + `title`="df", + `type`="integer", + `visible`="(chiSqCorr)"), + list( + `name`="p[chiSqCorr]", + `title`="p", + `type`="number", + `format`="zto,pvalue", + `visible`="(chiSqCorr)"), + list( + `name`="test[likeRat]", + `title`="", + `type`="text", + `content`="Likelihood ratio", + `visible`="(likeRat)", + `refs`="vcd"), + list( + `name`="value[likeRat]", + `title`="Value", + `visible`="(likeRat)"), + list( + `name`="df[likeRat]", + `title`="df", + `type`="integer", + `visible`="(likeRat)"), + list( + `name`="p[likeRat]", + `title`="p", + `type`="number", + `format`="zto,pvalue", + `visible`="(likeRat)"), + list( + `name`="test[fisher]", + `title`="", + `type`="text", + `content`="Fisher's exact test", + `visible`="(fisher)"), + list( + `name`="value[fisher]", + `title`="Value", + `visible`="(fisher)"), + list( + `name`="p[fisher]", + `title`="p", + `type`="number", + `format`="zto,pvalue", + `visible`="(fisher)"), + list( + `name`="test[N]", + `title`="", + `type`="text", + `content`="N"), + list( + `name`="value[N]", + `title`="Value", + `type`="integer")))) + self$add(jmvcore::Table$new( + options=options, + name="odds", + title="Comparative Measures", + visible="(logOdds || odds || relRisk)", + clearWith=list( + "rows", + "cols", + "counts", + "layers", + "ciWidth"), + columns=list( + list( + `name`="t[lo]", + `title`="", + `type`="text", + `content`="Log odds ratio", + `visible`="(logOdds)", + `refs`="vcd"), + list( + `name`="v[lo]", + `title`="Value", + `visible`="(logOdds)"), + list( + `name`="cil[lo]", + `title`="Lower", + `superTitle`="Confidence Intervals", + `visible`="(logOdds && ci)"), + list( + `name`="ciu[lo]", + `title`="Upper", + `superTitle`="Confidence Intervals", + `visible`="(logOdds && ci)"), + list( + `name`="t[o]", + `title`="", + `type`="text", + `content`="Odds ratio", + `visible`="(odds)"), + list( + `name`="v[o]", + `title`="Value", + `visible`="(odds)"), + list( + `name`="cil[o]", + `title`="Lower", + `superTitle`="Confidence Intervals", + `visible`="(odds && ci)"), + list( + `name`="ciu[o]", + `title`="Upper", + `superTitle`="Confidence Intervals", + `visible`="(odds && ci)"), + list( + `name`="t[rr]", + `title`="", + `type`="text", + `content`="Relative risk", + `visible`="(relRisk)"), + list( + `name`="v[rr]", + `title`="Value", + `visible`="(relRisk)"), + list( + `name`="cil[rr]", + `title`="Lower", + `superTitle`="Confidence Intervals", + `visible`="(relRisk && ci)"), + list( + `name`="ciu[rr]", + `title`="Upper", + `superTitle`="Confidence Intervals", + `visible`="(relRisk && ci)")))) + self$add(jmvcore::Table$new( + options=options, + name="nom", + title="Nominal", + visible="(contCoef || phiCra)", + columns=list( + list( + `name`="t[cont]", + `title`="", + `type`="text", + `content`="Contingency coefficient", + `visible`="(contCoef)"), + list( + `name`="v[cont]", + `title`="Value", + `visible`="(contCoef)"), + list( + `name`="t[phi]", + `title`="", + `type`="text", + `content`="Phi-coefficient", + `visible`="(phiCra)"), + list( + `name`="v[phi]", + `title`="Value", + `visible`="(phiCra)"), + list( + `name`="t[cra]", + `title`="", + `type`="text", + `content`="Cramer's V", + `visible`="(phiCra)"), + list( + `name`="v[cra]", + `title`="Value", + `visible`="(phiCra)")))) + self$add(jmvcore::Table$new( + options=options, + name="gamma", + title="Gamma", + visible="(gamma)", + refs="vcdExtra", + clearWith=list( + "rows", + "cols", + "counts", + "layers"), + columns=list( + list( + `name`="gamma", + `title`="Gamma"), + list( + `name`="se", + `title`="Standard Error"), + list( + `name`="cil", + `title`="Lower", + `superTitle`="Confidence Intervals"), + list( + `name`="ciu", + `title`="Upper", + `superTitle`="Confidence Intervals")))) + self$add(jmvcore::Table$new( + options=options, + name="taub", + title="Kendall's Tau-b", + visible="(taub)", + clearWith=list( + "rows", + "cols", + "counts", + "layers"), + columns=list( + list( + `name`="taub", + `title`="Kendall's Tau-B"), + list( + `name`="t", + `title`="t"), + list( + `name`="p", + `title`="p", + `type`="number", + `format`="zto,pvalue")))) + self$add(jmvcore::Preformatted$new( + options=options, + name="pw", + title="Pairwise Chi-Square Comparison")) + self$add(jmvcore::Table$new( + options=options, + name="tablepw", + title="Pairwise Chi-Square Comparison", + visible="(pairw)", + rows=1, + columns=list( + list( + `name`="method", + `title`="Method", + `type`="text"), + list( + `name`="v1", + `title`="Variable 1", + `type`="text"), + list( + `name`="v2", + `title`="Variable 2", + `type`="text"), + list( + `name`="pv", + `title`="p-value", + `type`="number", + `format`="zto,pvalue")), + clearWith=list( + "rows", + "cols", + "counts", + "layers", + "pairw")))})) + +pairchi2Base <- if (requireNamespace('jmvcore')) R6::R6Class( + "pairchi2Base", + inherit = jmvcore::Analysis, + public = list( + initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) { + super$initialize( + package = 'ClinicoPath', + name = 'pairchi2', + version = c(1,0,0), + options = options, + results = pairchi2Results$new(options=options), + data = data, + datasetId = datasetId, + analysisId = analysisId, + revision = revision, + pause = NULL, + completeWhenFilled = TRUE, + requiresMissings = FALSE) + })) + +#' Pairwise Chi-Square Test +#' +#' The X² test of association (not to be confused with the X² goodness of fit) +#' is used to test whether two categorical variables are independent or +#' associated. If the p-value is low, it suggests the variables are not +#' independent, and that there is a relationship between the two variables. +#' +#' +#' @examples +#' data('HairEyeColor') +#' dat <- as.data.frame(HairEyeColor) +#' +#' contTables(formula = Freq ~ Hair:Eye, dat) +#' +#' # +#' # CONTINGENCY TABLES +#' # +#' # Contingency Tables +#' # ----------------------------------------------------- +#' # Hair Brown Blue Hazel Green Total +#' # ----------------------------------------------------- +#' # Black 68 20 15 5 108 +#' # Brown 119 84 54 29 286 +#' # Red 26 17 14 14 71 +#' # Blond 7 94 10 16 127 +#' # Total 220 215 93 64 592 +#' # ----------------------------------------------------- +#' # +#' # +#' # X² Tests +#' # ------------------------------- +#' # Value df p +#' # ------------------------------- +#' # X² 138 9 < .001 +#' # N 592 +#' # ------------------------------- +#' # +#' +#' # Alternatively, omit the left of the formula (`Freq`) if each row +#' # represents a single observation: +#' +#' contTables(formula = ~ Hair:Eye, dat) +#' +#' @param data the data as a data frame +#' @param rows the variable to use as the rows in the contingency table (not +#' necessary when providing a formula, see the examples) +#' @param cols the variable to use as the columns in the contingency table +#' (not necessary when providing a formula, see the examples) +#' @param counts the variable to use as the counts in the contingency table +#' (not necessary when providing a formula, see the examples) +#' @param layers the variables to use to split the contingency table (not +#' necessary when providing a formula, see the examples) +#' @param chiSq \code{TRUE} (default) or \code{FALSE}, provide X² +#' @param chiSqCorr \code{TRUE} or \code{FALSE} (default), provide X² with +#' continuity correction +#' @param likeRat \code{TRUE} or \code{FALSE} (default), provide the +#' likelihood ratio +#' @param fisher \code{TRUE} or \code{FALSE} (default), provide Fisher's exact +#' test +#' @param contCoef \code{TRUE} or \code{FALSE} (default), provide the +#' contingency coefficient +#' @param phiCra \code{TRUE} or \code{FALSE} (default), provide Phi and +#' Cramer's V +#' @param logOdds \code{TRUE} or \code{FALSE} (default), provide the log odds +#' ratio (only available for 2x2 tables) +#' @param odds \code{TRUE} or \code{FALSE} (default), provide the odds ratio +#' (only available for 2x2 tables) +#' @param relRisk \code{TRUE} or \code{FALSE} (default), provide the relative +#' risk (only available for 2x2 tables) +#' @param ci \code{TRUE} or \code{FALSE} (default), provide confidence +#' intervals for the comparative measures +#' @param ciWidth a number between 50 and 99.9 (default: 95), width of the +#' confidence intervals to provide +#' @param gamma \code{TRUE} or \code{FALSE} (default), provide gamma +#' @param taub \code{TRUE} or \code{FALSE} (default), provide Kendall's tau-b +#' @param obs \code{TRUE} or \code{FALSE} (default), provide the observed +#' counts +#' @param exp \code{TRUE} or \code{FALSE} (default), provide the expected +#' counts +#' @param pcRow \code{TRUE} or \code{FALSE} (default), provide row percentages +#' @param pcCol \code{TRUE} or \code{FALSE} (default), provide column +#' percentages +#' @param pcTot \code{TRUE} or \code{FALSE} (default), provide total +#' percentages +#' @param pairw . +#' @param formula (optional) the formula to use, see the examples +#' @return A results object containing: +#' \tabular{llllll}{ +#' \code{results$freqs} \tab \tab \tab \tab \tab a table of proportions \cr +#' \code{results$chiSq} \tab \tab \tab \tab \tab a table of X² test results \cr +#' \code{results$odds} \tab \tab \tab \tab \tab a table of comparative measures \cr +#' \code{results$nom} \tab \tab \tab \tab \tab a table of the 'nominal' test results \cr +#' \code{results$gamma} \tab \tab \tab \tab \tab a table of the gamma test results \cr +#' \code{results$taub} \tab \tab \tab \tab \tab a table of the Kendall's tau-b test results \cr +#' \code{results$pw} \tab \tab \tab \tab \tab a preformatted \cr +#' \code{results$tablepw} \tab \tab \tab \tab \tab a table \cr +#' } +#' +#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example: +#' +#' \code{results$freqs$asDF} +#' +#' \code{as.data.frame(results$freqs)} +#' +#' @export +pairchi2 <- function( + data, + rows, + cols, + counts = NULL, + layers = NULL, + chiSq = TRUE, + chiSqCorr = FALSE, + likeRat = FALSE, + fisher = FALSE, + contCoef = FALSE, + phiCra = FALSE, + logOdds = FALSE, + odds = FALSE, + relRisk = FALSE, + ci = TRUE, + ciWidth = 95, + gamma = FALSE, + taub = FALSE, + obs = TRUE, + exp = FALSE, + pcRow = FALSE, + pcCol = FALSE, + pcTot = FALSE, + pairw = FALSE, + formula) { + + if ( ! requireNamespace('jmvcore')) + stop('pairchi2 requires jmvcore to be installed (restart may be required)') + + if ( ! missing(formula)) { + if (missing(counts)) + counts <- jmvcore::marshalFormula( + formula=formula, + data=`if`( ! missing(data), data, NULL), + from='lhs', + type='vars', + subset='1') + if (missing(rows)) + rows <- jmvcore::marshalFormula( + formula=formula, + data=`if`( ! missing(data), data, NULL), + from='rhs', + type='vars', + subset='1') + if (missing(cols)) + cols <- jmvcore::marshalFormula( + formula=formula, + data=`if`( ! missing(data), data, NULL), + from='rhs', + type='vars', + subset='2') + if (missing(layers)) + layers <- jmvcore::marshalFormula( + formula=formula, + data=`if`( ! missing(data), data, NULL), + from='rhs', + type='vars', + subset='3:') + } + + if ( ! missing(rows)) rows <- jmvcore::resolveQuo(jmvcore::enquo(rows)) + if ( ! missing(cols)) cols <- jmvcore::resolveQuo(jmvcore::enquo(cols)) + if ( ! missing(counts)) counts <- jmvcore::resolveQuo(jmvcore::enquo(counts)) + if ( ! missing(layers)) layers <- jmvcore::resolveQuo(jmvcore::enquo(layers)) + if (missing(data)) + data <- jmvcore::marshalData( + parent.frame(), + `if`( ! missing(rows), rows, NULL), + `if`( ! missing(cols), cols, NULL), + `if`( ! missing(counts), counts, NULL), + `if`( ! missing(layers), layers, NULL)) + + for (v in rows) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]]) + for (v in cols) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]]) + for (v in layers) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]]) + + options <- pairchi2Options$new( + rows = rows, + cols = cols, + counts = counts, + layers = layers, + chiSq = chiSq, + chiSqCorr = chiSqCorr, + likeRat = likeRat, + fisher = fisher, + contCoef = contCoef, + phiCra = phiCra, + logOdds = logOdds, + odds = odds, + relRisk = relRisk, + ci = ci, + ciWidth = ciWidth, + gamma = gamma, + taub = taub, + obs = obs, + exp = exp, + pcRow = pcRow, + pcCol = pcCol, + pcTot = pcTot, + pairw = pairw) + + analysis <- pairchi2Class$new( + options = options, + data = data) + + analysis$run() + + analysis$results +} diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index a06f4339..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,29 +0,0 @@ -# tic documentation: https://docs.ropensci.org/tic/dev/ - -# Download script file from GitHub -init: - ps: | - $ErrorActionPreference = "Stop" - Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" - Import-Module '..\appveyor-tool.ps1' - -install: - - ps: Bootstrap - - cmd: Rscript -e "writeLines('options(repos = \'https://cloud.r-project.org\')', '~/.Rprofile')" - - cmd: Rscript -e "getOption('repos')" - - cmd: Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'binary')" - - cmd: Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'binary')" - - cmd: Rscript -e "options(pkgType = 'binary'); remotes::install_github('ropensci/tic', upgrade = 'always'); print(tic::dsl_load()); tic::prepare_all_stages()" - -before_build: Rscript -e "tic::before_install()" -build_script: Rscript -e "tic::install()" -after_build: Rscript -e "tic::after_install()" -before_test: Rscript -e "tic::before_script()" -test_script: Rscript -e "tic::script()" -on_success: Rscript -e "try(tic::after_success(), silent = TRUE)" -on_failure: Rscript -e "tic::after_failure()" -before_deploy: Rscript -e "tic::before_deploy()" -deploy_script: Rscript -e "tic::deploy()" -after_deploy: Rscript -e "tic::after_deploy()" -on_finish: Rscript -e "tic::after_script()" -# Custom user code ------------------------------------------------------------- diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index 8f36b6cc..00000000 --- a/codecov.yml +++ /dev/null @@ -1,12 +0,0 @@ -comment: false - -coverage: - status: - project: - default: - target: auto - threshold: 1% - patch: - default: - target: auto - threshold: 1% diff --git a/jamovi/0000.yaml b/jamovi/0000.yaml index 5e8b8c5c..d45e8293 100644 --- a/jamovi/0000.yaml +++ b/jamovi/0000.yaml @@ -114,7 +114,7 @@ analyses: menuTitle: Decision Tree description: Function for making Decision Trees. - title: Pairwise Chi-Square Test - name: pairchi + name: pairchi2 ns: ClinicoPath menuGroup: ClinicoPath2 menuTitle: Pairwise Chi-Square Test diff --git a/jamovi/pairchi.a.yaml b/jamovi/pairchi2.a.yaml similarity index 99% rename from jamovi/pairchi.a.yaml rename to jamovi/pairchi2.a.yaml index 2d9beb8a..1379be78 100644 --- a/jamovi/pairchi.a.yaml +++ b/jamovi/pairchi2.a.yaml @@ -1,5 +1,5 @@ --- -name: pairchi +name: pairchi2 title: Pairwise Chi-Square Test menuGroup: ClinicoPath2 menuSubgroup: Comparisons diff --git a/jamovi/pairchi.r.yaml b/jamovi/pairchi2.r.yaml similarity index 90% rename from jamovi/pairchi.r.yaml rename to jamovi/pairchi2.r.yaml index b6b63616..d996004d 100644 --- a/jamovi/pairchi.r.yaml +++ b/jamovi/pairchi2.r.yaml @@ -1,5 +1,5 @@ --- -name: pairchi +name: pairchi2 title: Pairwise Chi-Square Test jrs: '1.0' @@ -284,6 +284,36 @@ items: title: Pairwise Chi-Square Comparison type: Preformatted + + - name: tablepw + title: 'Pairwise Chi-Square Comparison' + type: Table + # swapRowsColumns: true + visible: (pairw) + rows: 1 + columns: + - name: method + title: 'Method' + type: text + - name: v1 + title: 'Variable 1' + type: text + - name: v2 + title: 'Variable 2' + type: text + - name: pv + title: 'p-value' + type: number + format: zto,pvalue + clearWith: + - rows + - cols + - counts + - layers + - pairw + + + refs: - rmngb - RVAideMemoire diff --git a/jamovi/pairchi.u.yaml b/jamovi/pairchi2.u.yaml similarity index 99% rename from jamovi/pairchi.u.yaml rename to jamovi/pairchi2.u.yaml index 9a89c2c2..2763d477 100644 --- a/jamovi/pairchi.u.yaml +++ b/jamovi/pairchi2.u.yaml @@ -1,4 +1,4 @@ -name: pairchi +name: pairchi2 title: Pairwise Chi-Square Test jus: '2.0' compilerMode: tame diff --git a/man/crosstable.Rd b/man/crosstable.Rd index 5279b22c..77f21f50 100644 --- a/man/crosstable.Rd +++ b/man/crosstable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/crosstable.h.R \name{crosstable} \alias{crosstable} -\title{CrossTables} +\title{Cross Tables} \usage{ crosstable(data, vars, group, sty = "nejm") } diff --git a/man/pairchi.Rd b/man/pairchi2.Rd similarity index 63% rename from man/pairchi.Rd rename to man/pairchi2.Rd index ac9626f7..fda47d05 100644 --- a/man/pairchi.Rd +++ b/man/pairchi2.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pairchi.h.R -\name{pairchi} -\alias{pairchi} +% Please edit documentation in R/pairchi.h.R, R/pairchi2.h.R +\name{pairchi2} +\alias{pairchi2} \title{Pairwise Chi-Square Test} \usage{ -pairchi( +pairchi2( data, rows, cols, @@ -28,6 +28,35 @@ pairchi( pcRow = FALSE, pcCol = FALSE, pcTot = FALSE, + pairw = FALSE, + formula +) + +pairchi2( + data, + rows, + cols, + counts = NULL, + layers = NULL, + chiSq = TRUE, + chiSqCorr = FALSE, + likeRat = FALSE, + fisher = FALSE, + contCoef = FALSE, + phiCra = FALSE, + logOdds = FALSE, + odds = FALSE, + relRisk = FALSE, + ci = TRUE, + ciWidth = 95, + gamma = FALSE, + taub = FALSE, + obs = TRUE, + exp = FALSE, + pcRow = FALSE, + pcCol = FALSE, + pcTot = FALSE, + pairw = FALSE, formula ) } @@ -96,6 +125,8 @@ percentages} \item{pcTot}{\code{TRUE} or \code{FALSE} (default), provide total percentages} +\item{pairw}{.} + \item{formula}{(optional) the formula to use, see the examples} } \value{ @@ -107,6 +138,26 @@ A results object containing: \code{results$nom} \tab \tab \tab \tab \tab a table of the 'nominal' test results \cr \code{results$gamma} \tab \tab \tab \tab \tab a table of the gamma test results \cr \code{results$taub} \tab \tab \tab \tab \tab a table of the Kendall's tau-b test results \cr +\code{results$pw} \tab \tab \tab \tab \tab a preformatted \cr +\code{results$tablepw} \tab \tab \tab \tab \tab a table \cr +} + +Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example: + +\code{results$freqs$asDF} + +\code{as.data.frame(results$freqs)} + +A results object containing: +\tabular{llllll}{ +\code{results$freqs} \tab \tab \tab \tab \tab a table of proportions \cr +\code{results$chiSq} \tab \tab \tab \tab \tab a table of X² test results \cr +\code{results$odds} \tab \tab \tab \tab \tab a table of comparative measures \cr +\code{results$nom} \tab \tab \tab \tab \tab a table of the 'nominal' test results \cr +\code{results$gamma} \tab \tab \tab \tab \tab a table of the gamma test results \cr +\code{results$taub} \tab \tab \tab \tab \tab a table of the Kendall's tau-b test results \cr +\code{results$pw} \tab \tab \tab \tab \tab a preformatted \cr +\code{results$tablepw} \tab \tab \tab \tab \tab a table \cr } Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example: @@ -116,6 +167,11 @@ Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.f \code{as.data.frame(results$freqs)} } \description{ +The X² test of association (not to be confused with the X² goodness of fit) +is used to test whether two categorical variables are independent or +associated. If the p-value is low, it suggests the variables are not +independent, and that there is a relationship between the two variables. + The X² test of association (not to be confused with the X² goodness of fit) is used to test whether two categorical variables are independent or associated. If the p-value is low, it suggests the variables are not @@ -156,4 +212,38 @@ contTables(formula = Freq ~ Hair:Eye, dat) contTables(formula = ~ Hair:Eye, dat) +data('HairEyeColor') +dat <- as.data.frame(HairEyeColor) + +contTables(formula = Freq ~ Hair:Eye, dat) + +# +# CONTINGENCY TABLES +# +# Contingency Tables +# ----------------------------------------------------- +# Hair Brown Blue Hazel Green Total +# ----------------------------------------------------- +# Black 68 20 15 5 108 +# Brown 119 84 54 29 286 +# Red 26 17 14 14 71 +# Blond 7 94 10 16 127 +# Total 220 215 93 64 592 +# ----------------------------------------------------- +# +# +# X² Tests +# ------------------------------- +# Value df p +# ------------------------------- +# X² 138 9 < .001 +# N 592 +# ------------------------------- +# + +# Alternatively, omit the left of the formula (`Freq`) if each row +# represents a single observation: + +contTables(formula = ~ Hair:Eye, dat) + } diff --git a/man/pairchiClass.Rd b/man/pairchi2Class.Rd similarity index 92% rename from man/pairchiClass.Rd rename to man/pairchi2Class.Rd index 1aab150c..ed74e412 100644 --- a/man/pairchiClass.Rd +++ b/man/pairchi2Class.Rd @@ -1,7 +1,7 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pairchi.b.R -\name{pairchiClass} -\alias{pairchiClass} +% Please edit documentation in R/pairchi2.b.R +\name{pairchi2Class} +\alias{pairchi2Class} \title{Pairwise Chi-Square Test} \description{ Pairwise Chi-Square Test @@ -9,12 +9,12 @@ Pairwise Chi-Square Test Pairwise Chi-Square Test } \section{Super classes}{ -\code{\link[jmvcore:Analysis]{jmvcore::Analysis}} -> \code{\link[ClinicoPath:pairchiBase]{ClinicoPath::pairchiBase}} -> \code{pairchiClass} +\code{\link[jmvcore:Analysis]{jmvcore::Analysis}} -> \code{\link[ClinicoPath:pairchi2Base]{ClinicoPath::pairchi2Base}} -> \code{pairchi2Class} } \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-clone}{\code{pairchiClass$clone()}} +\item \href{#method-clone}{\code{pairchi2Class$clone()}} } } \if{html}{ @@ -46,7 +46,7 @@ Pairwise Chi-Square Test \item \out{}\href{../../jmvcore/html/Analysis.html#method-serialize}{\code{jmvcore::Analysis$serialize()}}\out{} \item \out{}\href{../../jmvcore/html/Analysis.html#method-setError}{\code{jmvcore::Analysis$setError()}}\out{} \item \out{}\href{../../jmvcore/html/Analysis.html#method-setStatus}{\code{jmvcore::Analysis$setStatus()}}\out{} -\item \out{}\href{../../ClinicoPath/html/pairchiBase.html#method-initialize}{\code{ClinicoPath::pairchiBase$initialize()}}\out{} +\item \out{}\href{../../ClinicoPath/html/pairchi2Base.html#method-initialize}{\code{ClinicoPath::pairchi2Base$initialize()}}\out{} } \out{} } @@ -56,7 +56,7 @@ Pairwise Chi-Square Test \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{pairchiClass$clone(deep = FALSE)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{pairchi2Class$clone(deep = FALSE)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/tododata/todo.Rmd b/tododata/todo.Rmd index 9546644d..2844499c 100644 --- a/tododata/todo.Rmd +++ b/tododata/todo.Rmd @@ -2146,7 +2146,7 @@ readyfunctions <- c( # "^icccoeff", "^multisurvival", "^oddsratio", - # "^pairchi", + # "^pairchi2", "^reportcat", # "^roc", "^statsplot2", @@ -2209,7 +2209,65 @@ table3 <- matrix(c(80L, 20L, 25L, 30L, 70L, 75L), nrow = 2, ncol = 3, byrow = TR # RVAideMemoire::chisq.multcomp() RVAideMemoire::fisher.multcomp() -RVAideMemoire::chisq.multcomp(table3) +result1 <- RVAideMemoire::chisq.multcomp(table3) + +result1 <- result1[["p.value"]] + + +result1 <- as.data.frame(result1) %>% + tibble::rownames_to_column() + +result1 <- result1 %>% + tidyr::pivot_longer(cols = -rowname) %>% + dplyr::filter(complete.cases(.)) + + + + +myfun <- function(i,j) { + if(!is.na(result1[i,j])){ + paste0( +dimnames(result1)[[1]][i], +" vs ", +dimnames(result1)[[2]][j], +" p= ", +result1[i,j]) + } +} + +for (i in 1:dim(result1)[1]) { +for (j in 1:dim(result1)[2]) { + des <- myfun(i,j) + if(!is.null(des)) print(des) +} +} + + +myfun1 <- function(i,j) { + if(!is.na(result1[i,j])){ +dimnames(result1)[[1]][i] + } +} + + +for (i in 1:dim(result1)[1]) { +for (j in 1:dim(result1)[2]) { + des <- myfun1(i,j) + if(!is.null(des)) print(des) +} +} + + + + + +myfun(3,3) + +myfun(1,2) + + +dimnames(result1)[[1]][2] + RVAideMemoire::fisher.multcomp(table3) @@ -2220,9 +2278,13 @@ RVAideMemoire::fisher.multcomp(table3) library(rmngb) x <- sample(1:2, 1e3, TRUE) g <- sample(1:4, 1e3, TRUE) -rmngb::pairwise.chisq.test(x, g) +result2 <- rmngb::pairwise.chisq.test(x, g) tab <- table(g, x) -rmngb::pairwise.fisher.test(tab, p.adj = "bonf") + +resultrmngb <- rmngb::pairwise.fisher.test(tab, p.adj = "bonf") + +result2[["p.value"]] +resultrmngb[["p.value"]] rmngb::pairwise.chisq.test(tab)