├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── test-coverage.yaml │ └── rhub.yaml ├── src ├── .gitignore ├── tvar.cpp ├── nsign.cpp ├── init.c └── RcppExports.cpp ├── LICENSE ├── docs ├── LICENSE ├── google02e424888b5e2def.html ├── inferr.jpg ├── hex_inferr.png ├── reference │ ├── ttest.html │ ├── Rplot001.png │ ├── owanova.html │ ├── binom_calc.html │ ├── binom_test.html │ ├── chisq_gof.html │ ├── chisq_test.html │ ├── ind_ttest.html │ ├── os_vartest.html │ ├── prop_test.html │ ├── runs_test.html │ ├── var_test.html │ ├── cochran_test.html │ ├── levene_test.html │ ├── mcnemar_test.html │ ├── os_chisqgof.html │ ├── paired_ttest.html │ ├── ts_prop_test.html │ ├── launch_inferr.html │ ├── two_sample_test.html │ ├── var_test_shiny.html │ ├── inferr-package.html │ ├── ifr_binom_test.html │ ├── infer_os_t_test.html │ ├── infer_runs_test.html │ ├── infer_binom_calc.html │ ├── infer_binom_test.html │ ├── infer_levene_test.html │ ├── infer_os_var_test.html │ ├── infer_ts_var_test.html │ ├── ifr_ts_prop_calc.html │ ├── ifr_ts_prop_group.html │ ├── infer_mcnemar_test.html │ ├── infer_oneway_anova.html │ ├── infer_os_prop_test.html │ ├── infer_ts_ind_ttest.html │ ├── infer_ts_prop_calc.html │ ├── infer_ts_prop_grp.html │ ├── infer_ts_prop_test.html │ ├── ifr_levene_test.default.html │ ├── ifr_os_prop_test.default.html │ ├── infer_chisq_gof_test.html │ ├── infer_cochran_qtest.html │ ├── infer_chisq_assoc_test.html │ ├── infer_launch_shiny_app.html │ └── infer_ts_paired_ttest.html ├── _headers ├── deps │ ├── font-awesome-6.4.2 │ │ └── webfonts │ │ │ ├── fa-brands-400.ttf │ │ │ ├── fa-solid-900.ttf │ │ │ ├── fa-brands-400.woff2 │ │ │ ├── fa-regular-400.ttf │ │ │ ├── fa-solid-900.woff2 │ │ │ ├── fa-regular-400.woff2 │ │ │ ├── fa-v4compatibility.ttf │ │ │ └── fa-v4compatibility.woff2 │ ├── headroom-0.11.0 │ │ ├── jQuery.headroom.min.js │ │ └── headroom.min.js │ ├── data-deps.txt │ └── bootstrap-toc-1.0.1 │ │ └── bootstrap-toc.min.js ├── pkgdown.yml ├── articles │ ├── intro_files │ │ ├── header-attrs-2.6 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.8 │ │ │ └── header-attrs.js │ ├── index.html │ └── reference-media.html ├── katex-auto.js ├── link.svg ├── bootstrap-toc.css ├── docsearch.js ├── docsearch.json ├── jquery.sticky-kit.min.js ├── lightswitch.js ├── LICENSE-text.html ├── LICENSE.html ├── 404.html └── sitemap.xml ├── .gitattributes ├── .gitignore ├── cran-comments.md ├── data ├── hsb.rda ├── exam.rda ├── treatment.rda └── treatment2.rda ├── hex_inferr.png ├── codecov.yml ├── .Rbuildignore ├── R ├── RcppExports.R ├── ifr-data-treatment.R ├── ifr-data-treatment2.R ├── ifr-data-exam.R ├── inferr.R ├── ifr-data-hsb.R ├── ifr-launch-shiny-app.R ├── ifr-zzz.R ├── ifr-utils.R ├── ifr-cochran-q-test.R ├── ifr-chisq-gof-test.R ├── ifr-os-prop-test.R └── ifr-anova.R ├── tests ├── testthat │ ├── _snaps │ │ ├── cochran.md │ │ ├── runs.md │ │ ├── chisqgof.md │ │ ├── levene.md │ │ ├── mcnemar.md │ │ ├── anova.md │ │ ├── chisq.md │ │ ├── two-prop-test.md │ │ ├── binom.md │ │ ├── two-var-test.md │ │ └── os-vartest.md │ ├── test-cochran.R │ ├── test-anova.R │ ├── test-mcnemar.R │ ├── test-levene.R │ ├── test-prop-test.R │ ├── test-chisq.R │ ├── test-os-vartest.R │ ├── test-paired-test.R │ ├── test-ttest.R │ ├── test-two-var-test.R │ ├── test-binom.R │ ├── test-indttest.R │ ├── test-chisqgof.R │ ├── test-runs.R │ └── test-two-prop-test.R ├── testthat.R └── _covrpage.Rmd ├── inferr.Rproj ├── man ├── treatment.Rd ├── ifr_launch_shiny_app.Rd ├── treatment2.Rd ├── exam.Rd ├── inferr.Rd ├── hsb.Rd ├── ifr_cochran_qtest.Rd ├── ifr_oneway_anova.Rd ├── ifr_binom_calc.Rd ├── ifr_chisq_gof_test.Rd ├── ifr_chisq_assoc_test.Rd ├── ifr_mcnemar_test.Rd ├── ifr_os_prop_test.Rd ├── ifr_ts_var_test.Rd ├── ifr_os_var_test.Rd ├── ifr_os_t_test.Rd ├── ifr_ts_paired_ttest.Rd ├── ifr_runs_test.Rd ├── ifr_levene_test.Rd ├── ifr_ts_prop_test.Rd └── ifr_ts_ind_ttest.Rd ├── DESCRIPTION ├── CONDUCT.md ├── NEWS.md ├── _pkgdown.yml ├── NAMESPACE └── README.Rmd /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2016-2017 2 | COPYRIGHT HOLDER: Aravind Hebbali 3 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2016 2 | COPYRIGHT HOLDER: Aravind Hebbali 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-vendored 2 | *.R linguist-vendored=false 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 0 note 4 | -------------------------------------------------------------------------------- /data/hsb.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/data/hsb.rda -------------------------------------------------------------------------------- /data/exam.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/data/exam.rda -------------------------------------------------------------------------------- /docs/google02e424888b5e2def.html: -------------------------------------------------------------------------------- 1 | google-site-verification: google02e424888b5e2def.html -------------------------------------------------------------------------------- /docs/inferr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/inferr.jpg -------------------------------------------------------------------------------- /hex_inferr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/hex_inferr.png -------------------------------------------------------------------------------- /data/treatment.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/data/treatment.rda -------------------------------------------------------------------------------- /data/treatment2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/data/treatment2.rda -------------------------------------------------------------------------------- /docs/hex_inferr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/hex_inferr.png -------------------------------------------------------------------------------- /docs/reference/ttest.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/ttest.html -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/owanova.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/owanova.html -------------------------------------------------------------------------------- /docs/reference/binom_calc.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/binom_calc.html -------------------------------------------------------------------------------- /docs/reference/binom_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/binom_test.html -------------------------------------------------------------------------------- /docs/reference/chisq_gof.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/chisq_gof.html -------------------------------------------------------------------------------- /docs/reference/chisq_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/chisq_test.html -------------------------------------------------------------------------------- /docs/reference/ind_ttest.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/ind_ttest.html -------------------------------------------------------------------------------- /docs/reference/os_vartest.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/os_vartest.html -------------------------------------------------------------------------------- /docs/reference/prop_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/prop_test.html -------------------------------------------------------------------------------- /docs/reference/runs_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/runs_test.html -------------------------------------------------------------------------------- /docs/reference/var_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/var_test.html -------------------------------------------------------------------------------- /docs/_headers: -------------------------------------------------------------------------------- 1 | /* 2 | X-Frame-Options: DENY 3 | X-XSS-Protection: 1; mode=block 4 | X-Content-Type-Options: nosniff -------------------------------------------------------------------------------- /docs/reference/cochran_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/cochran_test.html -------------------------------------------------------------------------------- /docs/reference/levene_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/levene_test.html -------------------------------------------------------------------------------- /docs/reference/mcnemar_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/mcnemar_test.html -------------------------------------------------------------------------------- /docs/reference/os_chisqgof.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/os_chisqgof.html -------------------------------------------------------------------------------- /docs/reference/paired_ttest.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/paired_ttest.html -------------------------------------------------------------------------------- /docs/reference/ts_prop_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/ts_prop_test.html -------------------------------------------------------------------------------- /docs/reference/launch_inferr.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/launch_inferr.html -------------------------------------------------------------------------------- /docs/reference/two_sample_test.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/two_sample_test.html -------------------------------------------------------------------------------- /docs/reference/var_test_shiny.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/reference/var_test_shiny.html -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsquaredacademy/inferr/HEAD/docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.woff2 -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '3.2' 2 | pkgdown: 2.1.0 3 | pkgdown_sha: ~ 4 | articles: 5 | intro: intro.html 6 | last_built: 2024-11-11T12:38Z 7 | urls: 8 | reference: https://inferr.rsquaredacademy.com/reference 9 | article: https://inferr.rsquaredacademy.com/articles 10 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^appveyor\.yml$ 4 | ^README\.Rmd$ 5 | ^README-.*\.png$ 6 | ^\.travis\.yml$ 7 | ^codecov\.yml$ 8 | ^cran-comments\.md$ 9 | ^_pkgdown\.yml$ 10 | ^docs$ 11 | ^NEWS$ 12 | ^CONDUCT\.md$ 13 | ^.*\.jpg$ 14 | ^hex_inferr\.png$ 15 | ^\.github$ 16 | ^CODE_OF_CONDUCT\.md$ 17 | -------------------------------------------------------------------------------- /docs/reference/inferr-package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/tvar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::export]] 5 | List gvar(NumericVector ln, NumericVector ly) { 6 | 7 | int n = ly.size(); 8 | List out(n); 9 | 10 | for(int i = 0; i < n; i++) { 11 | out[i] = rep(i, ln[i]); 12 | } 13 | 14 | return out; 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /docs/reference/ifr_binom_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_os_t_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_runs_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | nsignC <- function(x) { 5 | .Call('_inferr_nsignC', PACKAGE = 'inferr', x) 6 | } 7 | 8 | gvar <- function(ln, ly) { 9 | .Call('_inferr_gvar', PACKAGE = 'inferr', ln, ly) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /docs/reference/infer_binom_calc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_binom_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_levene_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_os_var_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_ts_var_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/ifr_ts_prop_calc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/ifr_ts_prop_group.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_mcnemar_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_oneway_anova.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_os_prop_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_ts_ind_ttest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_ts_prop_calc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_ts_prop_grp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_ts_prop_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/ifr_levene_test.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/ifr_os_prop_test.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_chisq_gof_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_cochran_qtest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /R/ifr-data-treatment.R: -------------------------------------------------------------------------------- 1 | #' Dummy data set for 2 Sample Proportion test 2 | #' 3 | #' A dataset containing information about two treatments 4 | #' 5 | #' @format A data frame with 50 rows and 2 variables: 6 | #' \describe{ 7 | #' \item{treatment1}{result of treatment type 1} 8 | #' \item{treatment2}{result of treatment type 2} 9 | #' } 10 | #' 11 | "treatment" 12 | -------------------------------------------------------------------------------- /docs/reference/infer_chisq_assoc_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_launch_shiny_app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/infer_ts_paired_ttest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /R/ifr-data-treatment2.R: -------------------------------------------------------------------------------- 1 | #' Dummy data set for 2 Sample Proportion test 2 | #' 3 | #' A dataset containing information about treatment outcomes 4 | #' 5 | #' @format A data frame with 200 rows and 2 variables: 6 | #' \describe{ 7 | #' \item{outcome}{outcome of treatment} 8 | #' \item{female}{gender of patient, 0 for male and 1 for female} 9 | #' } 10 | #' 11 | "treatment2" 12 | -------------------------------------------------------------------------------- /src/nsign.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::export]] 5 | double nsignC(NumericVector x) { 6 | 7 | int n = x.size(); 8 | int count = 1; 9 | 10 | for(int i = 1; i < n; i++) { 11 | int l = i - 1; 12 | if(x[i] != x[l]) { 13 | count++; 14 | } 15 | } 16 | 17 | return count; 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/cochran.md: -------------------------------------------------------------------------------- 1 | # output from cochran test is as expected 2 | 3 | Code 4 | ifr_cochran_qtest(exam, exam1, exam2, exam3) 5 | Output 6 | Test Statistics 7 | ---------------------- 8 | N 15 9 | Cochran's Q 4.75 10 | df 2 11 | p value 0.093 12 | ---------------------- 13 | 14 | -------------------------------------------------------------------------------- /R/ifr-data-exam.R: -------------------------------------------------------------------------------- 1 | #' Dummy data set for Cochran's Q test 2 | #' 3 | #' A dataset containing information about results of three exams. 4 | #' 5 | #' @format A data frame with 15 rows and 3 variables: 6 | #' \describe{ 7 | #' \item{exam1}{result of exam1} 8 | #' \item{exam2}{result of exam2} 9 | #' \item{exam3}{result of exam3} 10 | #' } 11 | #' 12 | #' @source \url{https://www.spss-tutorials.com/spss-cochran-q-test/} 13 | "exam" 14 | -------------------------------------------------------------------------------- /inferr.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(inferr) 11 | 12 | test_check("inferr") 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/runs.md: -------------------------------------------------------------------------------- 1 | # output from runs test is as expected 2 | 3 | Code 4 | ifr_runs_test(resid, residual) 5 | Output 6 | Runs Test 7 | Total Cases: 32 8 | Test Value : -0.9630856 9 | Cases < Test Value: 16 10 | Cases > Test Value: 16 11 | Number of Runs: 11 12 | Expected Runs: 17 13 | Variance (Runs): 7.741935 14 | z Statistic: -2.156386 15 | p-value: 0.03105355 16 | 17 | -------------------------------------------------------------------------------- /R/inferr.R: -------------------------------------------------------------------------------- 1 | #' \code{inferr} package 2 | #' 3 | #' Parametric and non parametric statistical tests 4 | #' 5 | #' See the README on 6 | #' \href{https://github.com/rsquaredacademy/inferr}{GitHub} 7 | #' 8 | #' @docType package 9 | #' @keywords internal 10 | #' @name inferr 11 | #' @aliases inferr-package 12 | "_PACKAGE" 13 | NULL 14 | 15 | ## quiets concerns of R CMD check re: the .'s that appear in pipelines 16 | if (getRversion() >= "2.15.1") utils::globalVariables(c(".", "sse", "sst", "var", "sd")) 17 | -------------------------------------------------------------------------------- /man/treatment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-data-treatment.R 3 | \docType{data} 4 | \name{treatment} 5 | \alias{treatment} 6 | \title{Dummy data set for 2 Sample Proportion test} 7 | \format{ 8 | A data frame with 50 rows and 2 variables: 9 | \describe{ 10 | \item{treatment1}{result of treatment type 1} 11 | \item{treatment2}{result of treatment type 2} 12 | } 13 | } 14 | \usage{ 15 | treatment 16 | } 17 | \description{ 18 | A dataset containing information about two treatments 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/ifr_launch_shiny_app.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-launch-shiny-app.R 3 | \name{ifr_launch_shiny_app} 4 | \alias{ifr_launch_shiny_app} 5 | \alias{infer_launch_shiny_app} 6 | \title{Launch Shiny App} 7 | \usage{ 8 | ifr_launch_shiny_app() 9 | } 10 | \description{ 11 | Launches shiny app 12 | } 13 | \section{Deprecated Function}{ 14 | 15 | \code{infer_launch_shiny_app()} has been deprecated. Instead use \code{ifr_launch_shiny_app()}. 16 | } 17 | 18 | \examples{ 19 | \dontrun{ 20 | ifr_launch_shiny_app() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /man/treatment2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-data-treatment2.R 3 | \docType{data} 4 | \name{treatment2} 5 | \alias{treatment2} 6 | \title{Dummy data set for 2 Sample Proportion test} 7 | \format{ 8 | A data frame with 200 rows and 2 variables: 9 | \describe{ 10 | \item{outcome}{outcome of treatment} 11 | \item{female}{gender of patient, 0 for male and 1 for female} 12 | } 13 | } 14 | \usage{ 15 | treatment2 16 | } 17 | \description{ 18 | A dataset containing information about treatment outcomes 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /docs/articles/intro_files/header-attrs-2.6/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/intro_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /man/exam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-data-exam.R 3 | \docType{data} 4 | \name{exam} 5 | \alias{exam} 6 | \title{Dummy data set for Cochran's Q test} 7 | \format{ 8 | A data frame with 15 rows and 3 variables: 9 | \describe{ 10 | \item{exam1}{result of exam1} 11 | \item{exam2}{result of exam2} 12 | \item{exam3}{result of exam3} 13 | } 14 | } 15 | \source{ 16 | \url{https://www.spss-tutorials.com/spss-cochran-q-test/} 17 | } 18 | \usage{ 19 | exam 20 | } 21 | \description{ 22 | A dataset containing information about results of three exams. 23 | } 24 | \keyword{datasets} 25 | -------------------------------------------------------------------------------- /docs/deps/headroom-0.11.0/jQuery.headroom.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it 3 | * Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js 4 | * License: MIT 5 | */ 6 | 7 | !function(a){a&&(a.fn.headroom=function(b){return this.each(function(){var c=a(this),d=c.data("headroom"),e="object"==typeof b&&b;e=a.extend(!0,{},Headroom.options,e),d||(d=new Headroom(this,e),d.init(),c.data("headroom",d)),"string"==typeof b&&(d[b](),"destroy"===b&&c.removeData("headroom"))})},a("[data-headroom]").each(function(){var b=a(this);b.headroom(b.data())}))}(window.Zepto||window.jQuery); -------------------------------------------------------------------------------- /docs/katex-auto.js: -------------------------------------------------------------------------------- 1 | // https://github.com/jgm/pandoc/blob/29fa97ab96b8e2d62d48326e1b949a71dc41f47a/src/Text/Pandoc/Writers/HTML.hs#L332-L345 2 | document.addEventListener("DOMContentLoaded", function () { 3 | var mathElements = document.getElementsByClassName("math"); 4 | var macros = []; 5 | for (var i = 0; i < mathElements.length; i++) { 6 | var texText = mathElements[i].firstChild; 7 | if (mathElements[i].tagName == "SPAN") { 8 | katex.render(texText.data, mathElements[i], { 9 | displayMode: mathElements[i].classList.contains("display"), 10 | throwOnError: false, 11 | macros: macros, 12 | fleqn: false 13 | }); 14 | }}}); 15 | -------------------------------------------------------------------------------- /src/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // for NULL 4 | #include 5 | 6 | /* FIXME: 7 | Check these declarations against the C/Fortran source code. 8 | */ 9 | 10 | /* .Call calls */ 11 | extern SEXP _inferr_gvar(SEXP, SEXP); 12 | extern SEXP _inferr_nsignC(SEXP); 13 | 14 | static const R_CallMethodDef CallEntries[] = { 15 | {"_inferr_gvar", (DL_FUNC) &_inferr_gvar, 2}, 16 | {"_inferr_nsignC", (DL_FUNC) &_inferr_nsignC, 1}, 17 | {NULL, NULL, 0} 18 | }; 19 | 20 | void R_init_inferr(DllInfo *dll) 21 | { 22 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 23 | R_useDynamicSymbols(dll, FALSE); 24 | } -------------------------------------------------------------------------------- /tests/testthat/test-cochran.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_cochran_qtest matches the expected result", { 2 | k <- ifr_cochran_qtest(exam, exam1, exam2, exam3) 3 | expect_equal(k$n, 15) 4 | expect_equal(k$df, 2) 5 | expect_equal(k$q, 4.75) 6 | expect_equal(k$pvalue, 0.093) 7 | }) 8 | 9 | 10 | test_that("ifr_cochran_qtest throws appropriate errors", { 11 | expect_error( 12 | ifr_cochran_qtest(exam, exam1, exam2), 13 | "Please specify at least 3 variables." 14 | ) 15 | expect_error( 16 | ifr_cochran_qtest(hsb, female, schtyp, race), 17 | "Please specify dichotomous/binary variables only." 18 | ) 19 | }) 20 | 21 | test_that("output from cochran test is as expected", { 22 | expect_snapshot(ifr_cochran_qtest(exam, exam1, exam2, exam3)) 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-anova.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_oneway_anova matches the expected output", { 2 | k <- ifr_oneway_anova(mtcars, mpg, cyl) 3 | expect_equal(k$ss_between, 824.785) 4 | expect_equal(k$ss_within, 301.263) 5 | expect_equal(k$ss_total, 1126.048) 6 | expect_equal(k$df_btw, 2) 7 | expect_equal(k$df_within, 29) 8 | expect_equal(k$df_total, 31) 9 | expect_equal(k$ms_btw, 412.392) 10 | expect_equal(k$ms_within, 10.388) 11 | expect_equal(k$fstat, 39.699) 12 | expect_equal(k$pval, 0) 13 | expect_equal(k$r2, 0.7325) 14 | expect_equal(k$adjusted_r2, 0.714) 15 | expect_equal(k$rmse, 3.2231) 16 | expect_equal(k$obs, 32) 17 | }) 18 | 19 | test_that("output from one way anova is as expected", { 20 | expect_snapshot(ifr_oneway_anova(mtcars, mpg, cyl)) 21 | }) 22 | -------------------------------------------------------------------------------- /man/inferr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inferr.R 3 | \docType{package} 4 | \name{inferr} 5 | \alias{inferr} 6 | \alias{inferr-package} 7 | \title{\code{inferr} package} 8 | \description{ 9 | Parametric and non parametric statistical tests 10 | } 11 | \details{ 12 | See the README on 13 | \href{https://github.com/rsquaredacademy/inferr}{GitHub} 14 | } 15 | \seealso{ 16 | Useful links: 17 | \itemize{ 18 | \item \url{https://rsquaredacademy.github.io/inferr/} 19 | \item \url{https://github.com/rsquaredacademy/inferr} 20 | \item Report bugs at \url{https://github.com/rsquaredacademy/inferr/issues} 21 | } 22 | 23 | } 24 | \author{ 25 | \strong{Maintainer}: Aravind Hebbali \email{hebbali.aravind@gmail.com} (\href{https://orcid.org/0000-0001-9220-9669}{ORCID}) 26 | 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /R/ifr-data-hsb.R: -------------------------------------------------------------------------------- 1 | #' High School and Beyond Data Set 2 | #' 3 | #' A dataset containing demographic information and standardized test 4 | #' scores of high school students. 5 | #' 6 | #' @format A data frame with 200 rows and 10 variables: 7 | #' \describe{ 8 | #' \item{id}{id of the student} 9 | #' \item{female}{gender of the student} 10 | #' \item{race}{ethnic background of the student} 11 | #' \item{ses}{socio-economic status of the student} 12 | #' \item{schtyp}{school type} 13 | #' \item{prog}{program type} 14 | #' \item{read}{scores from test of reading} 15 | #' \item{write}{scores from test of writing} 16 | #' \item{math}{scores from test of math} 17 | #' \item{science}{scores from test of science} 18 | #' \item{socst}{scores from test of social studies} 19 | #' } 20 | #' 21 | #' @source \url{https://nces.ed.gov/surveys/hsb/} 22 | "hsb" 23 | -------------------------------------------------------------------------------- /docs/deps/data-deps.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /man/hsb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-data-hsb.R 3 | \docType{data} 4 | \name{hsb} 5 | \alias{hsb} 6 | \title{High School and Beyond Data Set} 7 | \format{ 8 | A data frame with 200 rows and 10 variables: 9 | \describe{ 10 | \item{id}{id of the student} 11 | \item{female}{gender of the student} 12 | \item{race}{ethnic background of the student} 13 | \item{ses}{socio-economic status of the student} 14 | \item{schtyp}{school type} 15 | \item{prog}{program type} 16 | \item{read}{scores from test of reading} 17 | \item{write}{scores from test of writing} 18 | \item{math}{scores from test of math} 19 | \item{science}{scores from test of science} 20 | \item{socst}{scores from test of social studies} 21 | } 22 | } 23 | \source{ 24 | \url{https://nces.ed.gov/surveys/hsb/} 25 | } 26 | \usage{ 27 | hsb 28 | } 29 | \description{ 30 | A dataset containing demographic information and standardized test 31 | scores of high school students. 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/chisqgof.md: -------------------------------------------------------------------------------- 1 | # output from ifr_chisq_gof_test is as expected 2 | 3 | Code 4 | ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140)) 5 | Output 6 | Test Statistics 7 | ----------------------- 8 | Chi-Square 5.0286 9 | DF 3 10 | Pr > Chi Sq 0.1697 11 | Sample Size 200 12 | 13 | Variable: race 14 | ----------------------------------------------------------------- 15 | Category Observed Expected % Deviation Std. Residuals 16 | ----------------------------------------------------------------- 17 | 1 24 20 20.00 0.89 18 | 2 11 20 -45.00 -2.01 19 | 3 20 20 0.00 0.00 20 | 4 145 140 3.57 0.42 21 | ----------------------------------------------------------------- 22 | 23 | -------------------------------------------------------------------------------- /R/ifr-launch-shiny-app.R: -------------------------------------------------------------------------------- 1 | #' @title Launch Shiny App 2 | #' @description Launches shiny app 3 | #' @section Deprecated Function: 4 | #' \code{infer_launch_shiny_app()} has been deprecated. Instead use \code{ifr_launch_shiny_app()}. 5 | #' @examples 6 | #' \dontrun{ 7 | #' ifr_launch_shiny_app() 8 | #' } 9 | #' @export 10 | #' 11 | ifr_launch_shiny_app <- function() { 12 | 13 | message("`ifr_launch_shiny_app()` has been soft-deprecated and will be removed in the next release. In future, to launch the app, run the below code:\n 14 | - install.packages('xplorerr')\n - xplorerr::app_inference()\n") 15 | 16 | check_suggests('descriptr') 17 | check_suggests('jsonlite') 18 | check_suggests('haven') 19 | check_suggests('lubridate') 20 | check_suggests('readr') 21 | check_suggests('readxl') 22 | check_suggests('shinyBS') 23 | check_suggests('shinycssloaders') 24 | check_suggests('shinythemes') 25 | check_suggests('stringr') 26 | check_suggests('xplorerr') 27 | 28 | xplorerr::app_inference() 29 | 30 | } 31 | 32 | #' @export 33 | #' @rdname ifr_launch_shiny_app 34 | #' @usage NULL 35 | #' 36 | infer_launch_shiny_app <- function(data, x, y) { 37 | .Deprecated("ifr_launch_shiny_app()") 38 | } -------------------------------------------------------------------------------- /R/ifr-zzz.R: -------------------------------------------------------------------------------- 1 | .onAttach <- function(...) { 2 | 3 | if (!interactive() || stats::runif(1) > 0.1) return() 4 | 5 | pkgs <- utils::available.packages() 6 | cran_version <- package_version(pkgs["inferr", "Version"]) 7 | local_version <- utils::packageVersion("inferr") 8 | behind_cran <- cran_version > local_version 9 | 10 | tips <- c( 11 | "Learn more about inferr at https://github.com/rsquaredacademy/inferr/.", 12 | "Use suppressPackageStartupMessages() to eliminate package startup messages.", 13 | "Need help getting started with regression models? Visit: https://www.rsquaredacademy.com", 14 | "Check out our interactive app for quick data exploration. Visit: https://apps.rsquaredacademy.com/." 15 | ) 16 | 17 | tip <- sample(tips, 1) 18 | 19 | if (interactive()) { 20 | if (behind_cran) { 21 | msg <- c("A new version of inferr is available with bug fixes and new features.") 22 | packageStartupMessage(msg, "\nWould you like to install it?") 23 | if (utils::menu(c("Yes", "No")) == 1) { 24 | utils::update.packages("inferr") 25 | } 26 | } else { 27 | packageStartupMessage(paste(strwrap(tip), collapse = "\n")) 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | 6 | using namespace Rcpp; 7 | 8 | #ifdef RCPP_USE_GLOBAL_ROSTREAM 9 | Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); 10 | Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); 11 | #endif 12 | 13 | // nsignC 14 | double nsignC(NumericVector x); 15 | RcppExport SEXP _inferr_nsignC(SEXP xSEXP) { 16 | BEGIN_RCPP 17 | Rcpp::RObject rcpp_result_gen; 18 | Rcpp::RNGScope rcpp_rngScope_gen; 19 | Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP); 20 | rcpp_result_gen = Rcpp::wrap(nsignC(x)); 21 | return rcpp_result_gen; 22 | END_RCPP 23 | } 24 | // gvar 25 | List gvar(NumericVector ln, NumericVector ly); 26 | RcppExport SEXP _inferr_gvar(SEXP lnSEXP, SEXP lySEXP) { 27 | BEGIN_RCPP 28 | Rcpp::RObject rcpp_result_gen; 29 | Rcpp::RNGScope rcpp_rngScope_gen; 30 | Rcpp::traits::input_parameter< NumericVector >::type ln(lnSEXP); 31 | Rcpp::traits::input_parameter< NumericVector >::type ly(lySEXP); 32 | rcpp_result_gen = Rcpp::wrap(gvar(ln, ly)); 33 | return rcpp_result_gen; 34 | END_RCPP 35 | } 36 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: inferr 2 | Type: Package 3 | Title: Inferential Statistics 4 | Version: 0.3.2.9000 5 | Authors@R: person("Aravind", "Hebbali", email = "hebbali.aravind@gmail.com", role = c("aut", "cre"), 6 | comment = c(ORCID = "0000-0001-9220-9669")) 7 | Description: Select set of parametric and non-parametric statistical tests. 'inferr' builds upon the solid set of 8 | statistical tests provided in 'stats' package by including additional data types as inputs, expanding and 9 | restructuring the test results. The tests included are t tests, variance tests, proportion tests, chi square tests, Levene's test, McNemar Test, Cochran's Q test and Runs test. 10 | Depends: 11 | R(>= 3.2) 12 | License: MIT + file LICENSE 13 | URL: https://rsquaredacademy.github.io/inferr/, https://github.com/rsquaredacademy/inferr 14 | BugReports: https://github.com/rsquaredacademy/inferr/issues 15 | Imports: 16 | data.table, 17 | magrittr, 18 | Rcpp, 19 | stats, 20 | utils 21 | Suggests: 22 | covr, 23 | knitr, 24 | rmarkdown, 25 | testthat (>= 3.0.0), 26 | xplorerr 27 | Encoding: UTF-8 28 | LazyData: true 29 | VignetteBuilder: knitr 30 | RoxygenNote: 7.3.2 31 | LinkingTo: Rcpp 32 | Config/testthat/edition: 3 33 | -------------------------------------------------------------------------------- /man/ifr_cochran_qtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-cochran-q-test.R 3 | \name{ifr_cochran_qtest} 4 | \alias{ifr_cochran_qtest} 5 | \alias{infer_cochran_qtest} 6 | \title{Cochran Q Test} 7 | \usage{ 8 | ifr_cochran_qtest(data, ...) 9 | } 10 | \arguments{ 11 | \item{data}{a \code{data.frame} or \code{tibble}} 12 | 13 | \item{...}{columns in \code{data}} 14 | } 15 | \value{ 16 | \code{ifr_cochran_qtest} returns an object of class 17 | \code{"ifr_cochran_qtest"}. An object of class \code{"ifr_cochran_qtest"} 18 | is a list containing the following components: 19 | 20 | \item{df}{degrees of freedom} 21 | \item{n}{number of observations} 22 | \item{pvalue}{p value} 23 | \item{q}{cochran's q statistic} 24 | } 25 | \description{ 26 | Test if the proportions of 3 or more dichotomous variables are 27 | equal in the same population. 28 | } 29 | \section{Deprecated Function}{ 30 | 31 | \code{infer_cochran_test()} has been deprecated. Instead use 32 | \code{ifr_cochran_qtest()}. 33 | } 34 | 35 | \examples{ 36 | ifr_cochran_qtest(exam, exam1, exam2, exam3) 37 | 38 | } 39 | \references{ 40 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 41 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 42 | } 43 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/levene.md: -------------------------------------------------------------------------------- 1 | # output from levene test is as expected 2 | 3 | Code 4 | ifr_levene_test(hsb, read, group_var = race) 5 | Output 6 | Summary Statistics 7 | Levels Frequency Mean Std. Dev 8 | ----------------------------------------- 9 | 1 24 46.67 10.24 10 | 2 11 51.91 7.66 11 | 3 20 46.8 7.12 12 | 4 145 53.92 10.28 13 | ----------------------------------------- 14 | Total 200 52.23 10.25 15 | ----------------------------------------- 16 | 17 | Test Statistics 18 | ------------------------------------------------------------------------- 19 | Statistic Num DF Den DF F Pr > F 20 | ------------------------------------------------------------------------- 21 | Brown and Forsythe 3 196 3.44 0.0179 22 | Levene 3 196 3.4792 0.017 23 | Brown and Forsythe (Trimmed Mean) 3 196 3.3936 0.019 24 | ------------------------------------------------------------------------- 25 | 26 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/mcnemar.md: -------------------------------------------------------------------------------- 1 | # output from mcnemar test is as expected 2 | 3 | Code 4 | ifr_mcnemar_test(table(himath, hiread)) 5 | Output 6 | Controls 7 | --------------------------------- 8 | Cases 0 1 Total 9 | --------------------------------- 10 | 0 135 21 156 11 | 1 18 26 44 12 | --------------------------------- 13 | Total 153 47 200 14 | --------------------------------- 15 | 16 | McNemar's Test 17 | ---------------------------- 18 | McNemar's chi2 0.2308 19 | DF 1 20 | Pr > chi2 0.631 21 | Exact Pr >= chi2 0.7493 22 | ---------------------------- 23 | 24 | Kappa Coefficient 25 | -------------------------------- 26 | Kappa 0.4454 27 | ASE 0.075 28 | 95% Lower Conf Limit 0.2984 29 | 95% Upper Conf Limit 0.5923 30 | -------------------------------- 31 | 32 | Proportion With Factor 33 | ---------------------- 34 | cases 0.78 35 | controls 0.765 36 | ratio 1.0196 37 | odds ratio 1.1667 38 | ---------------------- 39 | 40 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/anova.md: -------------------------------------------------------------------------------- 1 | # output from one way anova is as expected 2 | 3 | Code 4 | ifr_oneway_anova(mtcars, mpg, cyl) 5 | Output 6 | ANOVA 7 | -------------------------------------------------------------------- 8 | Sum of 9 | Squares DF Mean Square F Sig. 10 | -------------------------------------------------------------------- 11 | Between Groups 824.785 2 412.392 39.699 0 12 | Within Groups 301.263 29 10.388 13 | Total 1126.048 31 14 | -------------------------------------------------------------------- 15 | 16 | Report 17 | ---------------------------------------- 18 | Category N Mean Std. Dev. 19 | ---------------------------------------- 20 | 4 11 26.664 4.510 21 | 6 7 19.743 1.454 22 | 8 14 15.100 2.560 23 | ---------------------------------------- 24 | 25 | Number of obs = 32 R-squared = 0.7325 26 | Root MSE = 3.2231 Adj R-squared = 0.714 27 | 28 | 29 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /tests/testthat/test-mcnemar.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_mcnemar_test matches the expected result", { 2 | k <- ifr_mcnemar_test(matrix(c(172, 7, 6, 15), nrow = 2)) 3 | expect_equal(k$statistic, 0.0769) 4 | expect_equal(k$df, 1.000) 5 | expect_equal(k$pvalue, 0.7815) 6 | expect_equal(k$exactp, 1.0000) 7 | expect_equal(k$kappa, 0.6613) 8 | expect_equal(k$std_err, 0.0873) 9 | expect_equal(k$kappa_cil, 0.4901) 10 | expect_equal(k$kappa_ciu, 0.8324) 11 | expect_equal(k$cases, 0.8900) 12 | expect_equal(k$controls, 0.8950) 13 | expect_equal(k$ratio, 0.9944) 14 | expect_equal(k$odratio, 0.8571) 15 | }) 16 | 17 | 18 | test_that("output from ifr_mcnemar_test matches the expected result", { 19 | k <- ifr_mcnemar_test(table(hsb$female, hsb$schtyp)) 20 | expect_equal(k$statistic, 56.4667) 21 | expect_equal(k$df, 1) 22 | expect_equal(k$pvalue, 0) 23 | expect_equal(k$exactp, 0) 24 | expect_equal(k$kappa, 0.0106) 25 | expect_equal(unname(k$std_err), 0.0485) 26 | expect_equal(unname(k$kappa_cil), -0.0846) 27 | expect_equal(unname(k$kappa_ciu), 0.1057) 28 | expect_equal(unname(k$cases), 0.455) 29 | expect_equal(unname(k$controls), 0.84) 30 | expect_equal(unname(k$ratio), 0.5417) 31 | expect_equal(k$odratio, 0.1538) 32 | }) 33 | 34 | 35 | test_that("output from mcnemar test is as expected", { 36 | himath <- ifelse(hsb$math > 60, 1, 0) 37 | hiread <- ifelse(hsb$read > 60, 1, 0) 38 | expect_snapshot(ifr_mcnemar_test(table(himath, hiread))) 39 | }) 40 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # inferr 0.3.2.9000 2 | 3 | # inferr 0.3.2 4 | 5 | This is a patch release to fix minor issues. 6 | 7 | # inferr 0.3.1 8 | 9 | This is a patch release to fix error on R-devel on Debian and Fedora. 10 | 11 | # inferr 0.3.0 12 | 13 | This is a minor release for bug fixes and API changes. We have completely revamped the API. All the functions now take a `data.frame` or `tibble` as the first argument followed by the variable names. The variable names need not be surrounded by single/double quotes anymore. Please view the guide for more details. 14 | 15 | ### Bug Fixes 16 | 17 | - using if/while statement is used with a condition of lenght greater than 1 will result in a runtime error and not warning ([#9](https://github.com/rsquaredacademy/inferr/issues/9)) 18 | 19 | - error in binomial test ([#11](https://github.com/rsquaredacademy/inferr/issues/11)) 20 | 21 | THe shiny app has been updated to reflect the changes in the API. 22 | 23 | # inferr 0.2.0 24 | 25 | ### New Features 26 | 27 | - shiny app for interactive analysis 28 | 29 | # inferr 0.1.1 30 | 31 | ### Bug Fixes 32 | 33 | * `binom_test()` accepts non-binary variables (#1). 34 | * `ind_ttest()` should throw an error when the grouping variable has more than 2 levels (#2). 35 | * `ts_prop_test()` should accept only binary variables (#3). 36 | * `var_test()` should accept only binary variables for the `group_var` input. The number of continuous variables must also not exceed two. (#4). 37 | 38 | # inferr 0.1.0 39 | 40 | * First release 41 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/chisq.md: -------------------------------------------------------------------------------- 1 | # ouput from ifr_chisq_assoc_test is as expected 2 | 3 | Code 4 | ifr_chisq_assoc_test(hsb, female, schtyp) 5 | Output 6 | Chi Square Statistics 7 | 8 | Statistics DF Value Prob 9 | ---------------------------------------------------- 10 | Chi-Square 1 0.0470 0.8284 11 | Likelihood Ratio Chi-Square 1 0.0471 0.8282 12 | Continuity Adj. Chi-Square 1 0.0005 0.9822 13 | Mantel-Haenszel Chi-Square 1 0.0468 0.8287 14 | Phi Coefficient 0.0153 15 | Contingency Coefficient 0.0153 16 | Cramer's V 0.0153 17 | ---------------------------------------------------- 18 | 19 | # ouput from ifr_chisq_assoc_test 2 is as expected 20 | 21 | Code 22 | ifr_chisq_assoc_test(hsb, female, ses) 23 | Output 24 | Chi Square Statistics 25 | 26 | Statistics DF Value Prob 27 | ---------------------------------------------------- 28 | Chi-Square 2 4.5765 0.1014 29 | Likelihood Ratio Chi-Square 2 4.6789 0.0964 30 | Phi Coefficient 0.1513 31 | Contingency Coefficient 0.1496 32 | Cramer's V 0.1513 33 | ---------------------------------------------------- 34 | 35 | -------------------------------------------------------------------------------- /tests/testthat/test-levene.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_levene_test matches the expected result", { 2 | mt <- mtcars 3 | mt$cyl <- as.factor(mt$cyl) 4 | 5 | k <- ifr_levene_test(mt, mpg, group_var = cyl) 6 | expect_equal(k$bf, 6.4843) 7 | expect_equal(k$p_bf, 0.0047) 8 | expect_equal(k$lev, 5.5071) 9 | expect_equal(k$p_lev, 0.0094) 10 | expect_equal(k$bft, 6.2047) 11 | expect_equal(k$p_bft, 0.0057) 12 | expect_equal(as.vector(k$avgs), c(26.66, 19.74, 15.10)) 13 | expect_equal(as.vector(k$sds), c(4.51, 1.45, 2.56)) 14 | expect_equal(k$avg, 20.09) 15 | expect_equal(k$sd, 6.03) 16 | expect_equal(k$n, 32) 17 | expect_equal(k$levs, c("4", "6", "8")) 18 | expect_equal(k$n_df, 2) 19 | expect_equal(k$d_df, 29) 20 | expect_equal(as.vector(k$lens), c(11, 7, 14)) 21 | }) 22 | 23 | 24 | 25 | test_that("output from ifr_levene_test matches the expected result", { 26 | k <- ifr_levene_test(mtcars, mpg, qsec) 27 | expect_equal(k$bf, 24.3932) 28 | expect_equal(k$p_bf, 0) 29 | expect_equal(k$lev, 20.9464) 30 | expect_equal(k$p_lev, 0) 31 | expect_equal(k$bft, 22.7064) 32 | expect_equal(k$p_bft, 0) 33 | expect_equal(as.vector(k$avgs), c(20.09, 17.85)) 34 | expect_equal(as.vector(k$sds), c(6.03, 1.79)) 35 | expect_equal(k$avg, 18.97) 36 | expect_equal(k$sd, 4.55) 37 | expect_equal(k$n, 64) 38 | expect_equal(k$levs, c("0", "1")) 39 | expect_equal(k$n_df, 1) 40 | expect_equal(k$d_df, 62) 41 | expect_equal(as.vector(k$lens), c(32, 32)) 42 | }) 43 | 44 | 45 | test_that("output from levene test is as expected", { 46 | expect_snapshot(ifr_levene_test(hsb, read, group_var = race)) 47 | }) 48 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [master, develop] 6 | pull_request: 7 | branches: [master, develop] 8 | 9 | name: R-CMD-check.yaml 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | R-CMD-check: 15 | runs-on: ${{ matrix.config.os }} 16 | 17 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | config: 23 | - {os: macos-latest, r: 'release'} 24 | - {os: windows-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 26 | - {os: ubuntu-latest, r: 'release'} 27 | - {os: ubuntu-latest, r: 'oldrel-1'} 28 | 29 | env: 30 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 31 | R_KEEP_PKG_SOURCE: yes 32 | 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - uses: r-lib/actions/setup-pandoc@v2 37 | 38 | - uses: r-lib/actions/setup-r@v2 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | http-user-agent: ${{ matrix.config.http-user-agent }} 42 | use-public-rspm: true 43 | 44 | - uses: r-lib/actions/setup-r-dependencies@v2 45 | with: 46 | extra-packages: any::rcmdcheck 47 | needs: check 48 | 49 | - uses: r-lib/actions/check-r-package@v2 50 | with: 51 | upload-snapshots: true 52 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 53 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/two-prop-test.md: -------------------------------------------------------------------------------- 1 | # output from 2 sample proportion test is as expected when alternative is less 2 | 3 | Code 4 | ifr_ts_prop_group(treatment2, outcome, female, alternative = "less") 5 | Output 6 | Test Statistics 7 | ----------------------------- 8 | Total Observations 200 9 | z 0.351 10 | Pr(Z < z) 0.637 11 | 12 | 13 | # output from 2 sample proportion test is as expected when alternative is greater 14 | 15 | Code 16 | ifr_ts_prop_group(treatment2, outcome, female, alternative = "greater") 17 | Output 18 | Test Statistics 19 | ----------------------------- 20 | Total Observations 200 21 | z 0.351 22 | Pr(Z > z) 0.363 23 | 24 | 25 | # output from 2 sample proportion test is as expected when alternative is both 26 | 27 | Code 28 | ifr_ts_prop_group(treatment2, outcome, female, alternative = "both") 29 | Output 30 | Test Statistics 31 | ----------------------------- 32 | Total Observations 200 33 | z 0.351 34 | Pr(|Z| < |z|) 0.726 35 | 36 | 37 | # output from 2 sample proportion test is as expected when alternative is all 38 | 39 | Code 40 | ifr_ts_prop_group(treatment2, outcome, female, alternative = "all") 41 | Output 42 | Test Statistics 43 | ----------------------------- 44 | Total Observations 200 45 | z 0.351 46 | Pr(|Z| < |z|) 0.726 47 | Pr(Z < z) 0.637 48 | Pr(Z > z) 0.363 49 | 50 | 51 | -------------------------------------------------------------------------------- /tests/testthat/test-prop-test.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_os_prop_test matches expected result", { 2 | k <- ifr_os_prop_test(200, phat = 0.3, prob = 0.5, alternative = "both") 3 | expect_equal(k$n, 200) 4 | expect_equal(k$phat, 0.3) 5 | expect_equal(k$p, 0.5) 6 | expect_equal(k$z, -5.6569) 7 | expect_equal(k$sig, 0) 8 | expect_equal(k$alt, "both") 9 | expect_equal(k$obs, c(140, 60)) 10 | expect_equal(k$exp, c(100, 100)) 11 | expect_equal(k$deviation, c(" 40.00", "-40.00")) 12 | expect_equal(k$std, c(" 4.00", "-4.00")) 13 | }) 14 | 15 | test_that("output from ifr_os_prop_test matches expected result when using factor variables", { 16 | k <- ifr_os_prop_test(hsb, female, prob = 0.5) 17 | expect_equal(k$n, 200) 18 | expect_equal(k$phat, 0.545) 19 | expect_equal(k$p, 0.5) 20 | expect_equal(k$z, 1.2728) 21 | expect_equal(k$sig, 0.2031) 22 | expect_equal(k$alt, "both") 23 | expect_equal(k$obs, c(91, 109)) 24 | expect_equal(k$exp, c(100, 100)) 25 | expect_equal(k$deviation, c("-9.00", " 9.00")) 26 | expect_equal(k$std, c("-0.90", " 0.90")) 27 | }) 28 | 29 | test_that("output from ifr_os_prop_test matches expected result", { 30 | k <- ifr_os_prop_test(200, phat = 0.3, prob = 0.5, alternative = "less") 31 | expect_equal(k$sig, 0) 32 | expect_equal(k$alt, "less") 33 | }) 34 | 35 | test_that("output from ifr_os_prop_test matches expected result", { 36 | k <- ifr_os_prop_test(200, phat = 0.3, prob = 0.5, alternative = "greater") 37 | expect_equal(k$sig, 1) 38 | expect_equal(k$alt, "greater") 39 | }) 40 | 41 | 42 | test_that("output from ifr_os_prop_test matches expected result", { 43 | k <- ifr_os_prop_test(200, phat = 0.3, prob = 0.5, alternative = "all") 44 | expect_equal(unname(k$sig), c(0, 0, 1)) 45 | expect_equal(k$alt, "all") 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-chisq.R: -------------------------------------------------------------------------------- 1 | test_that("ouput from ifr_chisq_assoc_test matches the expected result", { 2 | k <- ifr_chisq_assoc_test(hsb, female, schtyp) 3 | expect_equal(k$df, 1) 4 | expect_equal(k$chisquare, 0.047) 5 | expect_equal(k$chisquare_lr, 0.0471) 6 | expect_equal(k$chisquare_mantel_haenszel, 0.0468) 7 | expect_equal(k$chisquare_adjusted, 0.0005) 8 | expect_equal(k$pval_chisquare, 0.8284) 9 | expect_equal(k$pval_chisquare_lr, 0.8282) 10 | expect_equal(k$pval_chisquare_mantel_haenszel, 0.8287) 11 | expect_equal(k$pval_chisquare_adjusted, 0.9822) 12 | expect_equal(k$phi_coefficient, 0.0153) 13 | expect_equal(k$contingency_coefficient, 0.0153) 14 | expect_equal(k$cramers_v, 0.0153) 15 | expect_equal(k$ds, 4) 16 | }) 17 | 18 | test_that("ouput from ifr_chisq_assoc_test matches the expected result", { 19 | k <- ifr_chisq_assoc_test(hsb, female, ses) 20 | expect_equal(k$df, 2) 21 | expect_equal(k$chisquare, 4.5765) 22 | expect_equal(k$chisquare_lr, 4.6789) 23 | expect_equal(k$pval_chisquare, 0.1014) 24 | expect_equal(k$pval_chisquare_lr, 0.0964) 25 | expect_equal(k$phi_coefficient, 0.1513) 26 | expect_equal(k$contingency_coefficient, 0.1496) 27 | expect_equal(k$cramers_v, 0.1513) 28 | expect_equal(k$ds, 6) 29 | }) 30 | 31 | test_that("ifr_chisq_assoc_test throws the appropriate error", { 32 | expect_error(ifr_chisq_assoc_test(hsb, female, read), "y must be a categorical variable") 33 | expect_error(ifr_chisq_assoc_test(hsb, read, ses), "x must be a categorical variable") 34 | }) 35 | 36 | test_that("ouput from ifr_chisq_assoc_test is as expected", { 37 | expect_snapshot(ifr_chisq_assoc_test(hsb, female, schtyp)) 38 | }) 39 | 40 | test_that("ouput from ifr_chisq_assoc_test 2 is as expected", { 41 | expect_snapshot(ifr_chisq_assoc_test(hsb, female, ses)) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-os-vartest.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_os_var_test matches the expected result", { 2 | k <- ifr_os_var_test(mtcars, mpg, 0.3) 3 | expect_equal(k$n, 32) 4 | expect_equal(k$sd, 0.3) 5 | expect_equal(k$sigma, 6.0269) 6 | expect_equal(k$se, 1.0654) 7 | expect_equal(round(k$chi, 2), 12511.64) 8 | expect_equal(k$df, 31) 9 | expect_equal(k$p_lower, 1) 10 | expect_equal(k$p_upper, 0) 11 | expect_equal(k$p_two, 0) 12 | expect_equal(k$xbar, 20.0906) 13 | expect_equal(k$c_lwr, 3.8737) 14 | expect_equal(k$c_upr, 10.6527) 15 | expect_equal(k$conf, 0.95) 16 | expect_equal(k$var_name, "mpg") 17 | expect_equal(k$type, "both") 18 | }) 19 | 20 | 21 | test_that("ifr_os_var_test returns appropriate errors", { 22 | expect_error( 23 | ifr_os_var_test(hsb, race, 0.3), 24 | "x must be numeric" 25 | ) 26 | expect_error( 27 | ifr_os_var_test(mtcars, mpg, "0.3"), 28 | "sd must be numeric" 29 | ) 30 | expect_error( 31 | ifr_os_var_test(mtcars, mpg, 0.3, "0.95"), 32 | "confint must be numeric" 33 | ) 34 | }) 35 | 36 | 37 | test_that("output from one sample variance test is as expected when alternative is less", { 38 | expect_snapshot(ifr_os_var_test(mtcars, mpg, 5, alternative = "less")) 39 | }) 40 | 41 | test_that("output from one sample variance test is as expected when alternative is greater", { 42 | expect_snapshot(ifr_os_var_test(mtcars, mpg, 5, alternative = "greater")) 43 | }) 44 | 45 | test_that("output from one sample variance test is as expected when alternative is both", { 46 | expect_snapshot(ifr_os_var_test(mtcars, mpg, 5, alternative = "both")) 47 | }) 48 | 49 | test_that("output from one sample variance test is as expected when alternative is all", { 50 | expect_snapshot(ifr_os_var_test(mtcars, mpg, 5, alternative = "all")) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/binom.md: -------------------------------------------------------------------------------- 1 | # output from ifr_binom_calc is as expected when k < exp_k 2 | 3 | Code 4 | ifr_binom_calc(32, 8) 5 | Output 6 | Binomial Test 7 | -------------------------------------- 8 | Group N Obs. Prop Exp. Prop 9 | -------------------------------------- 10 | 0 24 0.75 0.500 11 | 1 8 0.25 0.500 12 | -------------------------------------- 13 | 14 | 15 | Test Summary 16 | ------------------------------------------ 17 | Tail Prob p-value 18 | ------------------------------------------ 19 | Lower Pr(k <= 8) 0.0035 20 | Upper Pr(k >= 8) 0.998949 21 | ------------------------------------------ 22 | 23 | # output from ifr_binom_calc is as expected when k > exp_k 24 | 25 | Code 26 | ifr_binom_calc(32, 20) 27 | Output 28 | Binomial Test 29 | -------------------------------------- 30 | Group N Obs. Prop Exp. Prop 31 | -------------------------------------- 32 | 0 12 0.375 0.500 33 | 1 20 0.625 0.500 34 | -------------------------------------- 35 | 36 | 37 | Test Summary 38 | -------------------------------------------- 39 | Tail Prob p-value 40 | -------------------------------------------- 41 | Lower Pr(k <= 20) 0.944908 42 | Upper Pr(k >= 20) 0.107664 43 | -------------------------------------------- 44 | 45 | -------------------------------------------------------------------------------- /man/ifr_oneway_anova.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-anova.R 3 | \name{ifr_oneway_anova} 4 | \alias{ifr_oneway_anova} 5 | \alias{infer_oneway_anova} 6 | \title{One Way ANOVA} 7 | \usage{ 8 | ifr_oneway_anova(data, x, y, ...) 9 | } 10 | \arguments{ 11 | \item{data}{a \code{data.frame} or a \code{tibble}} 12 | 13 | \item{x}{numeric; column in \code{data}} 14 | 15 | \item{y}{factor; column in \code{data}} 16 | 17 | \item{...}{additional arguments passed to or from other methods} 18 | } 19 | \value{ 20 | \code{ifr_oneway_anova} returns an object of class \code{"ifr_oneway_anova"}. 21 | An object of class \code{"ifr_oneway_anova"} is a list containing the 22 | following components: 23 | 24 | \item{adjusted_r2}{adjusted r squared value} 25 | \item{df_btw}{between groups degress of freedom} 26 | \item{df_within}{within groups degress of freedom} 27 | \item{df_total}{total degress of freedom} 28 | \item{fstat}{f value} 29 | \item{group_stats}{group statistics} 30 | \item{ms_btw}{between groups mean square} 31 | \item{ms_within}{within groups mean square} 32 | \item{obs}{number of observations} 33 | \item{pval}{p value} 34 | \item{r2}{r squared value} 35 | \item{rmse}{root mean squared error} 36 | \item{ss_between}{between group sum of squares} 37 | \item{ss_within}{within group sum of squares} 38 | \item{ss_total}{total sum of squares} 39 | } 40 | \description{ 41 | One way analysis of variance 42 | } 43 | \section{Deprecated Function}{ 44 | 45 | \code{infer_oneway_anova()} has been deprecated. Instead use 46 | \code{ifr_oneway_anova()} 47 | } 48 | 49 | \examples{ 50 | ifr_oneway_anova(mtcars, mpg, cyl) 51 | ifr_oneway_anova(hsb, write, prog) 52 | 53 | } 54 | \references{ 55 | Kutner, M. H., Nachtsheim, C., Neter, J., & Li, W. (2005). 56 | Applied linear statistical models. Boston: McGraw-Hill Irwin. 57 | } 58 | \seealso{ 59 | \code{\link[stats]{anova}} 60 | } 61 | -------------------------------------------------------------------------------- /tests/testthat/test-paired-test.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_ts_paired_ttest matches expected output", { 2 | 3 | k <- ifr_ts_paired_ttest(mtcars, mpg, qsec) 4 | expect_equal(k$Obs, 32) 5 | expect_equal(round(unname(k$b[[1]]), 2), c(20.09, 17.85, 2.24)) 6 | expect_equal(round(unname(k$b[[2]]), 2), c(6.03, 1.79, 5.52)) 7 | expect_equal(round(unname(k$b[[3]]), 2), c(1.07, 0.32, 0.98)) 8 | expect_equal(unlist(k$conf_int1), c(17.92, 22.26)) 9 | expect_equal(unlist(k$conf_int2), c(17.2, 18.49)) 10 | expect_equal(unlist(k$conf_int_diff), c(0.25, 4.23)) 11 | expect_equal(k$corr, 0.42) 12 | expect_equal(k$corsig, 0.02) 13 | expect_equal(unname(k$tstat), 2.2964) 14 | expect_equal(round(unname(k$p_lower), 3), 0.986) 15 | expect_equal(round(unname(k$p_upper), 3), 0.014) 16 | expect_equal(round(unname(k$p_two_tail), 3), 0.029) 17 | expect_equal(k$var_names, c("mpg", "qsec")) 18 | expect_equal(k$xy, c("mpg - qsec")) 19 | expect_equal(k$alternative, c("both")) 20 | expect_equal(k$df, 31) 21 | expect_equal(k$confint, 0.95) 22 | }) 23 | 24 | 25 | test_that("output from paired sample t test is as expected when alternative is less", { 26 | expect_snapshot(ifr_ts_paired_ttest( 27 | hsb, read, write, 28 | alternative = "less" 29 | )) 30 | }) 31 | 32 | test_that("output from paired sample t test is as expected when alternative is greater", { 33 | expect_snapshot(ifr_ts_paired_ttest( 34 | hsb, read, write, 35 | alternative = "greater" 36 | )) 37 | }) 38 | 39 | test_that("output from paired sample t test is as expected when alternative is both", { 40 | expect_snapshot(ifr_ts_paired_ttest( 41 | hsb, read, write, 42 | alternative = "both" 43 | )) 44 | }) 45 | 46 | test_that("output from paired sample t test is as expected when alternative is all", { 47 | expect_snapshot(ifr_ts_paired_ttest( 48 | hsb, read, write, 49 | alternative = "all" 50 | )) 51 | }) 52 | -------------------------------------------------------------------------------- /man/ifr_binom_calc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-binom-test.R 3 | \name{ifr_binom_calc} 4 | \alias{ifr_binom_calc} 5 | \alias{infer_binom_calc} 6 | \alias{ifr_binom_test} 7 | \alias{infer_binom_test} 8 | \title{Binomial Test} 9 | \usage{ 10 | ifr_binom_calc(n, success, prob = 0.5, ...) 11 | 12 | ifr_binom_test(data, variable, prob = 0.5) 13 | } 14 | \arguments{ 15 | \item{n}{number of observations} 16 | 17 | \item{success}{number of successes} 18 | 19 | \item{prob}{assumed probability of success on a trial} 20 | 21 | \item{...}{additional arguments passed to or from other methods} 22 | 23 | \item{data}{a \code{data.frame} or a \code{tibble}} 24 | 25 | \item{variable}{factor; column in \code{data}} 26 | } 27 | \value{ 28 | \code{ifr_binom_test} returns an object of class \code{"ifr_binom_test"}. 29 | An object of class \code{"ifr_binom_test"} is a list containing the 30 | following components: 31 | 32 | \item{exp_k}{expected number of successes} 33 | \item{exp_p}{expected probability of success} 34 | \item{k}{number of successes} 35 | \item{n}{number of observations} 36 | \item{obs_p}{assumed probability of success} 37 | \item{pval_lower}{lower one sided p value} 38 | \item{pval_upper}{upper one sided p value} 39 | } 40 | \description{ 41 | Test whether the proportion of successes on a two-level 42 | categorical dependent variable significantly differs from a hypothesized value. 43 | } 44 | \section{Deprecated Functions}{ 45 | 46 | \code{infer_binom_calc()} and \code{infer_binom_test()} have been deprecated. Instead use 47 | \code{ifr_binom_cal()} and \code{ifr_binom_test()}. 48 | } 49 | 50 | \examples{ 51 | # using calculator 52 | ifr_binom_calc(32, 13, prob = 0.5) 53 | 54 | # using data set 55 | ifr_binom_test(hsb, female, prob = 0.5) 56 | 57 | } 58 | \references{ 59 | Hoel, P. G. 1984. Introduction to Mathematical Statistics. 60 | 5th ed. New York: Wiley. 61 | } 62 | \seealso{ 63 | \code{\link[stats]{binom.test}} 64 | } 65 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://inferr.rsquaredacademy.com 2 | template: 3 | bootstrap: 5 4 | 5 | authors: 6 | Aravind Hebbali: 7 | href: https://www.aravindhebbali.com 8 | 9 | templates: 10 | params: 11 | bootswatch: cerulean 12 | 13 | navbar: 14 | title: "inferr" 15 | type: inverse 16 | left: 17 | - text: "Home" 18 | href: index.html 19 | - text: "Guides" 20 | menu: 21 | - text: "Intro" 22 | href: articles/intro.html 23 | - text: "Reference" 24 | menu: 25 | - text: "Functions" 26 | href: reference/index.html 27 | - text: "News" 28 | href: news/index.html 29 | right: 30 | - icon: fa-github 31 | href: https://github.com/rsquaredacademy/inferr 32 | 33 | home: 34 | links: 35 | - text: Our R packages 36 | href: https://pkgs.rsquaredacademy.com 37 | - text: Read our blog 38 | href: https://blog.rsquaredacademy.com 39 | - text: Our ebooks 40 | href: https://ebooks.rsquaredacademy.com 41 | - text: Online courses 42 | href: https://www.rsquaredacademy.com 43 | 44 | reference: 45 | - title: Shiny App 46 | 47 | contents: 48 | - ifr_launch_shiny_app 49 | 50 | - title: Parametric Tests 51 | 52 | contents: 53 | - ifr_binom_calc 54 | - ifr_binom_test 55 | - ifr_levene_test 56 | - ifr_os_prop_test 57 | - ifr_os_t_test 58 | - ifr_os_var_test 59 | - ifr_ts_ind_ttest 60 | - ifr_ts_paired_ttest 61 | - ifr_ts_prop_test 62 | - ifr_ts_var_test 63 | 64 | 65 | - title: Non-parametric Tests 66 | 67 | contents: 68 | - ifr_chisq_assoc_test 69 | - ifr_chisq_gof_test 70 | - ifr_cochran_qtest 71 | - ifr_mcnemar_test 72 | - ifr_runs_test 73 | 74 | - title: ANOVA 75 | 76 | contents: 77 | - ifr_oneway_anova 78 | 79 | - title: Data 80 | desc: > 81 | inferr comes with a built-in datasets which are used to 82 | illustrate the functions as well as for running tests. 83 | contents: 84 | - hsb 85 | - exam 86 | - treatment 87 | - treatment2 88 | -------------------------------------------------------------------------------- /man/ifr_chisq_gof_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-chisq-gof-test.R 3 | \name{ifr_chisq_gof_test} 4 | \alias{ifr_chisq_gof_test} 5 | \alias{infer_chisq_gof_test} 6 | \title{Chi Square Goodness of Fit Test} 7 | \usage{ 8 | ifr_chisq_gof_test(data, x, y, correct = FALSE) 9 | } 10 | \arguments{ 11 | \item{data}{a \code{data.frame} or \code{tibble}} 12 | 13 | \item{x}{factor; column in \code{data}} 14 | 15 | \item{y}{expected proportions} 16 | 17 | \item{correct}{logical; if TRUE continuity correction is applied} 18 | } 19 | \value{ 20 | \code{ifr_chisq_gof_test} returns an object of class 21 | \code{"ifr_chisq_gof_test"}. An object of class \code{"ifr_chisq_gof_test"} 22 | is a list containing the following components: 23 | 24 | \item{categories}{levels of \code{x}} 25 | \item{chisquare}{chi square statistic} 26 | \item{deviation}{deviation of observed from frequency} 27 | \item{degrees_of_freedom}{chi square degrees of freedom} 28 | \item{expected_frequency}{expected frequency/proportion} 29 | \item{n_levels}{number of levels of \code{x}} 30 | \item{observed_frequency}{observed frequency/proportion} 31 | \item{pvalue}{p-value} 32 | \item{sample_size}{number of observations} 33 | \item{std_residuals}{standardized residuals} 34 | \item{varname}{name of categorical variable} 35 | } 36 | \description{ 37 | Test whether the observed proportions for a categorical variable 38 | differ from hypothesized proportions 39 | } 40 | \section{Deprecated Function}{ 41 | 42 | \code{infer_chisq_gof_test()} has been deprecated. Instead use 43 | \code{ifr_chisq_gof_test()} 44 | } 45 | 46 | \examples{ 47 | ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140)) 48 | 49 | # apply continuity correction 50 | ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140), correct = TRUE) 51 | 52 | } 53 | \references{ 54 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 55 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 56 | } 57 | \seealso{ 58 | \code{\link[stats]{chisq.test}} 59 | } 60 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [master, develop] 6 | pull_request: 7 | branches: [master, develop] 8 | 9 | name: test-coverage.yaml 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | test-coverage: 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | 19 | steps: 20 | - uses: actions/checkout@v4 21 | 22 | - uses: r-lib/actions/setup-r@v2 23 | with: 24 | use-public-rspm: true 25 | 26 | - uses: r-lib/actions/setup-r-dependencies@v2 27 | with: 28 | extra-packages: any::covr, any::xml2 29 | needs: coverage 30 | 31 | - name: Test coverage 32 | run: | 33 | cov <- covr::package_coverage( 34 | quiet = FALSE, 35 | clean = FALSE, 36 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 37 | ) 38 | covr::to_cobertura(cov) 39 | shell: Rscript {0} 40 | 41 | - uses: codecov/codecov-action@v4 42 | with: 43 | fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} 44 | file: ./cobertura.xml 45 | plugin: noop 46 | disable_search: true 47 | token: ${{ secrets.CODECOV_TOKEN }} 48 | 49 | - name: Show testthat output 50 | if: always() 51 | run: | 52 | ## -------------------------------------------------------------------- 53 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 54 | shell: bash 55 | 56 | - name: Upload test results 57 | if: failure() 58 | uses: actions/upload-artifact@v4 59 | with: 60 | name: coverage-test-failures 61 | path: ${{ runner.temp }}/package 62 | -------------------------------------------------------------------------------- /man/ifr_chisq_assoc_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-chisq-assoc-test.R 3 | \name{ifr_chisq_assoc_test} 4 | \alias{ifr_chisq_assoc_test} 5 | \alias{infer_chisq_assoc_test} 6 | \title{Chi Square Test of Association} 7 | \usage{ 8 | ifr_chisq_assoc_test(data, x, y) 9 | } 10 | \arguments{ 11 | \item{data}{a \code{data.frame} or \code{tibble}} 12 | 13 | \item{x}{factor; column in \code{data}} 14 | 15 | \item{y}{factor; column in \code{data}} 16 | } 17 | \value{ 18 | \code{ifr_chisq_assoc_test} returns an object of class 19 | \code{"ifr_chisq_assoc_test"}. An object of class 20 | \code{"ifr_chisq_assoc_test"} is a list containing the 21 | following components: 22 | 23 | \item{chisquare}{chi square} 24 | \item{chisquare_lr}{likelihood ratio chi square} 25 | \item{chisquare_mantel_haenszel}{mantel haenszel chi square} 26 | \item{chisquare_adjusted}{continuity adjusted chi square} 27 | \item{contingency_coefficient}{contingency coefficient} 28 | \item{cramers_v}{cramer's v} 29 | \item{df}{degrees of freedom} 30 | \item{ds}{product of dimensions of the table of \code{x} and \code{y}} 31 | \item{phi_coefficient}{phi coefficient} 32 | \item{pval_chisquare}{p-value of chi square} 33 | \item{pval_chisquare_adjusted}{p-value of continuity adjusted chi square} 34 | \item{pval_chisquare_lr}{p-value of likelihood ratio chi square} 35 | \item{pval_chisquare_mantel_haenszel}{p-value of mantel haenszel chi square} 36 | } 37 | \description{ 38 | Chi Square test of association to examine if there is a 39 | relationship between two categorical variables. 40 | } 41 | \section{Deprecated Function}{ 42 | 43 | \code{infer_chisq_assoc_test()} has been deprecated. Instead use 44 | \code{ifr_chisq_assoc_test()}. 45 | } 46 | 47 | \examples{ 48 | ifr_chisq_assoc_test(hsb, female, schtyp) 49 | 50 | ifr_chisq_assoc_test(hsb, female, ses) 51 | 52 | } 53 | \references{ 54 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 55 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 56 | } 57 | \seealso{ 58 | \code{\link[stats]{chisq.test}} 59 | } 60 | -------------------------------------------------------------------------------- /tests/testthat/test-ttest.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_os_t_test matches the expected output", { 2 | k <- ifr_os_t_test(mtcars, mpg, mu = 50, alternative = "less") 3 | expect_equal(k$mu, 50) 4 | expect_equal(k$n, 32) 5 | expect_equal(k$df, 31) 6 | expect_equal(k$Mean, 20.0906) 7 | expect_equal(k$stddev, 6.0269) 8 | expect_equal(k$std_err, 1.0654) 9 | expect_equal(k$test_stat, -28.073) 10 | expect_equal(k$confint, c(-Inf, 21.8974)) 11 | expect_equal(k$mean_diff_l, -Inf) 12 | expect_equal(k$mean_diff_u, -28.1026) 13 | expect_equal(k$mean_diff, -29.9094) 14 | expect_equal(k$p_l, 6.592161e-24) 15 | expect_equal(k$p_u, 1) 16 | expect_equal(k$p, 1.31843219487798e-23) 17 | expect_equal(k$conf, 0.95) 18 | expect_equal(k$type, "less") 19 | expect_equal(k$var_name, "mpg") 20 | 21 | k <- ifr_os_t_test(mtcars, mpg, mu = 50, alternative = "greater") 22 | expect_equal(k$confint, c(18.2846, Inf)) 23 | 24 | k <- ifr_os_t_test(mtcars, mpg, mu = 50, alternative = "both") 25 | expect_equal(k$confint, c(17.9181, 22.2639)) 26 | }) 27 | 28 | test_that("ifr_os_t_test throws the appropriate error", { 29 | expect_error(ifr_os_t_test(hsb, race, mu = 50), "x must be numeric") 30 | expect_error(ifr_os_t_test(mtcars, mpg, mu = "50"), "mu must be numeric") 31 | expect_error(ifr_os_t_test(mtcars, mpg, mu = 50, alpha = "0.05"), "alpha must be numeric") 32 | }) 33 | 34 | test_that("output from one sample t test is as expected when alternative is less", { 35 | expect_snapshot(ifr_os_t_test(hsb, write, mu = 50, alternative = "less")) 36 | }) 37 | 38 | test_that("output from one sample t test is as expected when alternative is greater", { 39 | expect_snapshot(ifr_os_t_test(hsb, write, mu = 50, alternative = "greater")) 40 | }) 41 | 42 | test_that("output from one sample t test is as expected when alternative is both", { 43 | expect_snapshot(ifr_os_t_test(hsb, write, mu = 50, alternative = "both")) 44 | }) 45 | 46 | test_that("output from one sample t test is as expected when alternative is all", { 47 | expect_snapshot(ifr_os_t_test(hsb, write, mu = 50, alternative = "all")) 48 | }) 49 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v1.0.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | !function(a){"use strict";window.Toc={helpers:{findOrFilter:function(e,t){var n=e.find(t);return e.filter(t).add(n).filter(":not([data-toc-skip])")},generateUniqueIdBase:function(e){return a(e).text().trim().replace(/\'/gi,"").replace(/[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\\n\t\b\v]/g,"-").replace(/-{2,}/g,"-").substring(0,64).replace(/^-+|-+$/gm,"").toLowerCase()||e.tagName.toLowerCase()},generateUniqueId:function(e){for(var t=this.generateUniqueIdBase(e),n=0;;n++){var r=t;if(0')},createChildNavList:function(e){var t=this.createNavList();return e.append(t),t},generateNavEl:function(e,t){var n=a('');n.attr("href","#"+e),n.text(t);var r=a("
  • ");return r.append(n),r},generateNavItem:function(e){var t=this.generateAnchor(e),n=a(e),r=n.data("toc-text")||n.text();return this.generateNavEl(t,r)},getTopLevel:function(e){for(var t=1;t<=6;t++){if(1% 3 | as.character() %>% 4 | format(width = w, justify = "centre") 5 | } 6 | 7 | fk <- function(x, w) { 8 | format(x, width = w, justify = "centre", nsmall = 3) 9 | } 10 | 11 | 12 | fs <- function() { 13 | rep(" ") 14 | } 15 | 16 | fl <- function(x, w) { 17 | x %>% 18 | as.character() %>% 19 | format(width = w, justify = "left") 20 | } 21 | 22 | fc <- function(x, w) { 23 | x %>% 24 | as.character() %>% 25 | format(width = w, justify = "centre") 26 | } 27 | 28 | formatter_t <- function(x, w) { 29 | x %>% 30 | as.character() %>% 31 | format(width = w, justify = "centre") 32 | } 33 | 34 | format_cil <- function(x, w) { 35 | x %>% 36 | as.character() %>% 37 | format(width = w, justify = "centre") 38 | } 39 | 40 | format_ciu <- function(x, w) { 41 | x %>% 42 | as.character() %>% 43 | format(width = w, justify = "centre") 44 | } 45 | 46 | formats_t <- function() { 47 | rep(" ") 48 | } 49 | 50 | formatter_pair <- function(x, w) { 51 | x1 <- format(x, nsmall = 2) 52 | x2 <- as.character(x1) 53 | ret <- format(x2, width = w, justify = "centre") 54 | return(ret) 55 | } 56 | 57 | fw <- function(x, w) { 58 | x %>% 59 | as.character() %>% 60 | format(width = w, justify = "centre") 61 | } 62 | 63 | fn <- function(x, w) { 64 | x %>% 65 | as.character() %>% 66 | format(width = w, justify = "centre") 67 | } 68 | 69 | formats <- function() { 70 | rep(" ") 71 | } 72 | 73 | #' @importFrom utils packageVersion menu install.packages 74 | check_suggests <- function(pkg) { 75 | 76 | pkg_flag <- tryCatch(utils::packageVersion(pkg), error = function(e) NA) 77 | 78 | if (is.na(pkg_flag)) { 79 | 80 | msg <- message(paste0('\n', pkg, ' must be installed for this functionality.')) 81 | 82 | if (interactive()) { 83 | message(msg, "\nWould you like to install it?") 84 | if (utils::menu(c("Yes", "No")) == 1) { 85 | utils::install.packages(pkg) 86 | } else { 87 | stop(msg, call. = FALSE) 88 | } 89 | } else { 90 | stop(msg, call. = FALSE) 91 | } 92 | } 93 | 94 | } -------------------------------------------------------------------------------- /tests/testthat/test-two-var-test.R: -------------------------------------------------------------------------------- 1 | mtcarz <- mtcars 2 | mtcarz$vs <- as.factor(mtcarz$vs) 3 | 4 | test_that("output from ifr_ts_var_test matches expected result", { 5 | k <- ifr_ts_var_test(mtcarz, mpg, group_var = vs) 6 | expect_equal(k$f, 0.5151) 7 | expect_equal(k$lower, 0.0999) 8 | expect_equal(k$upper, 0.9001) 9 | expect_equal(as.vector(k$vars), c(14.90, 28.93)) 10 | expect_equal(as.vector(k$avgs), c(16.62, 24.56)) 11 | expect_equal(as.vector(k$sds), c(3.86, 5.38)) 12 | expect_equal(as.vector(k$ses), c(0.91, 1.44)) 13 | expect_equal(k$avg, 20.09) 14 | expect_equal(k$sd, 6.03) 15 | expect_equal(k$se, 1.07) 16 | expect_equal(k$len, 32) 17 | expect_equal(as.vector(k$lens), c(18, 14)) 18 | expect_equal(as.vector(k$n1), 17) 19 | expect_equal(as.vector(k$n2), 13) 20 | expect_equal(k$type, "less") 21 | expect_equal(k$lev, c("0", "1")) 22 | }) 23 | 24 | test_that("output from ifr_ts_var_test matches expected result", { 25 | k <- ifr_ts_var_test(mtcarz, mpg, qsec) 26 | expect_equal(k$f, 11.3756) 27 | expect_equal(k$lower, 1) 28 | expect_equal(k$upper, 0) 29 | expect_equal(as.vector(k$vars), c(36.32, 3.19)) 30 | expect_equal(as.vector(k$avgs), c(20.09, 17.85)) 31 | expect_equal(as.vector(k$sds), c(6.03, 1.79)) 32 | expect_equal(as.vector(k$ses), c(1.07, 0.32)) 33 | expect_equal(k$avg, 18.97) 34 | expect_equal(k$sd, 4.55) 35 | expect_equal(k$se, 0.57) 36 | expect_equal(k$len, 64) 37 | expect_equal(as.vector(k$lens), c(32, 32)) 38 | expect_equal(unname(k$n1), 31) 39 | expect_equal(unname(k$n2), 31) 40 | expect_equal(k$type, "less") 41 | expect_equal(k$lev, c("mpg", "qsec")) 42 | }) 43 | 44 | 45 | test_that("output from 2 sample variance test is as expected when alternative is less", { 46 | expect_snapshot(ifr_ts_var_test(hsb, read, write, alternative = "less")) 47 | }) 48 | 49 | test_that("output from 2 sample variance test is as expected when alternative is greater", { 50 | expect_snapshot(ifr_ts_var_test(hsb, read, write, alternative = "greater")) 51 | }) 52 | 53 | test_that("output from 2 sample variance test is as expected when alternative is all", { 54 | expect_snapshot(ifr_ts_var_test(hsb, read, write, alternative = "all")) 55 | }) 56 | -------------------------------------------------------------------------------- /tests/testthat/test-binom.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_binom_calc matches the expected output", { 2 | k <- ifr_binom_calc(32, 8) 3 | expect_equal(k$n, 32) 4 | expect_equal(k$k, 8) 5 | expect_equal(k$exp_k, 16) 6 | expect_equal(k$obs_p, 0.25) 7 | expect_equal(k$exp_p, 0.5) 8 | expect_equal(k$pval_lower, 0.0035) 9 | expect_equal(k$pval_upper, 0.998949) 10 | 11 | 12 | k <- ifr_binom_calc(32, 20) 13 | expect_equal(k$n, 32) 14 | expect_equal(k$k, 20) 15 | expect_equal(k$exp_k, 16) 16 | expect_equal(k$obs_p, 0.625) 17 | expect_equal(k$exp_p, 0.5) 18 | expect_equal(k$pval_lower, 0.944908) 19 | expect_equal(k$pval_upper, 0.107664) 20 | }) 21 | 22 | test_that("ifr_binom_calc throws the appropriate error", { 23 | expect_error(ifr_binom_calc("32", 20), "n must be an integer") 24 | expect_error(ifr_binom_calc(32, "20"), "success must be an integer") 25 | expect_error(ifr_binom_calc(32, 20, "0.5"), "prob must be numeric") 26 | expect_error(ifr_binom_calc(32, 20, 1.5), "prob must be between 0 and 1") 27 | expect_error(ifr_binom_calc(32, 20, -1.5), "prob must be between 0 and 1") 28 | }) 29 | 30 | 31 | mt <- mtcars 32 | mt$vs <- as.factor(mt$vs) 33 | mt$am <- as.factor(mt$am) 34 | 35 | test_that("output from ifr_binom_test matches the expected output", { 36 | k <- ifr_binom_test(mt, vs) 37 | expect_equal(k$n, 32) 38 | expect_equal(k$k, 14) 39 | expect_equal(k$exp_k, 16) 40 | expect_equal(k$obs_p, 0.4375) 41 | expect_equal(k$exp_p, 0.5) 42 | expect_equal(k$pval_lower, 0.298307) 43 | expect_equal(k$pval_upper, 0.811457) 44 | }) 45 | 46 | test_that("ifr_binom_test throws the appropriate error", { 47 | expect_error(ifr_binom_test(mtcars, mpg), "variable must be of type factor") 48 | expect_error(ifr_binom_test(mt, am, "0.5"), "prob must be numeric") 49 | expect_error(ifr_binom_test(mt, am, 1.5), "prob must be between 0 and 1") 50 | expect_error(ifr_binom_test(mt, am, -1.5), "prob must be between 0 and 1") 51 | }) 52 | 53 | 54 | test_that("output from ifr_binom_calc is as expected when k < exp_k", { 55 | expect_snapshot(ifr_binom_calc(32, 8)) 56 | }) 57 | 58 | test_that("output from ifr_binom_calc is as expected when k > exp_k", { 59 | expect_snapshot(ifr_binom_calc(32, 20)) 60 | }) 61 | -------------------------------------------------------------------------------- /man/ifr_mcnemar_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-mcnemar-test.R 3 | \name{ifr_mcnemar_test} 4 | \alias{ifr_mcnemar_test} 5 | \alias{infer_mcnemar_test} 6 | \title{McNemar Test} 7 | \usage{ 8 | ifr_mcnemar_test(data, x = NULL, y = NULL) 9 | } 10 | \arguments{ 11 | \item{data}{a \code{data.frame} or \code{tibble}} 12 | 13 | \item{x}{factor; column in \code{data}} 14 | 15 | \item{y}{factor; column in \code{data}} 16 | } 17 | \value{ 18 | \code{ifr_mcnemar_test} returns an object of class \code{"ifr_mcnemar_test"}. 19 | An object of class \code{"ifr_mcnemar_test"} is a list containing the 20 | following components: 21 | 22 | \item{statistic}{chi square statistic} 23 | \item{df}{degrees of freedom} 24 | \item{pvalue}{p-value} 25 | \item{exactp}{exact p-value} 26 | \item{cstat}{continuity correction chi square statistic} 27 | \item{cpvalue}{continuity correction p-value} 28 | \item{kappa}{kappa coefficient; measure of interrater agreement} 29 | \item{std_err}{asymptotic standard error} 30 | \item{kappa_cil}{95\% kappa lower confidence limit} 31 | \item{kappa_ciu}{95\% kappa upper confidence limit} 32 | \item{cases}{cases} 33 | \item{controls}{controls} 34 | \item{ratio}{ratio of proportion with factor} 35 | \item{odratio}{odds ratio} 36 | \item{tbl}{two way table} 37 | } 38 | \description{ 39 | Test if the proportions of two dichotomous variables are 40 | equal in the same population. 41 | } 42 | \section{Deprecated Function}{ 43 | 44 | \code{infer_mcnermar_test()} has been deprecated. Instead use 45 | \code{ifr_mcnemar_test()}. 46 | } 47 | 48 | \examples{ 49 | # using variables from data 50 | hb <- hsb 51 | hb$himath <- ifelse(hsb$math > 60, 1, 0) 52 | hb$hiread <- ifelse(hsb$read > 60, 1, 0) 53 | ifr_mcnemar_test(hb, himath, hiread) 54 | 55 | # test if the proportion of students in himath and hiread group is same 56 | himath <- ifelse(hsb$math > 60, 1, 0) 57 | hiread <- ifelse(hsb$read > 60, 1, 0) 58 | ifr_mcnemar_test(table(himath, hiread)) 59 | 60 | # using matrix 61 | ifr_mcnemar_test(matrix(c(135, 18, 21, 26), nrow = 2)) 62 | 63 | } 64 | \references{ 65 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 66 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 67 | } 68 | \seealso{ 69 | \code{\link[stats]{mcnemar.test}} 70 | } 71 | -------------------------------------------------------------------------------- /tests/testthat/test-indttest.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_ts_ind_ttest matches expected result", { 2 | k <- ifr_ts_ind_ttest(hsb, female, write) 3 | expect_equal(k$levels, c("0", "1")) 4 | expect_equal(as.numeric(k$obs), c(91, 109)) 5 | expect_equal(k$n, 200) 6 | expect_equal(as.numeric(k$mean), c(50.121, 54.991)) 7 | expect_equal(as.numeric(k$sd), c(10.305, 8.134)) 8 | expect_equal(as.numeric(k$se), c(1.080, 0.779)) 9 | expect_equal(round(as.numeric(k$lower), 3), c(47.975, 53.447)) 10 | expect_equal(round(as.numeric(k$upper), 3), c(52.267, 56.535)) 11 | expect_equal(round(unlist(k$combined), 3), c( 12 | 200.000, 52.775, 9.479, 0.670, 13 | 199.000, 1.972, 51.454, 54.096 14 | )) 15 | expect_equal(k$mean_diff, -4.87) 16 | expect_equal(k$sd_dif, 9.231) 17 | expect_equal(k$se_dif, 1.304) 18 | expect_equal(round(k$conf_diff, 3), c(-7.426, -2.314)) 19 | expect_equal(k$df_pooled, 198) 20 | expect_equal(k$df_satterthwaite, 170) 21 | expect_equal(round(k$t_pooled, 2), -3.73) 22 | expect_equal(round(k$t_satterthwaite, 2), -3.66) 23 | expect_equal(k$sig_pooled_l, 1e-04) 24 | expect_equal(k$sig_pooled_u, 0.9999) 25 | expect_equal(k$sig_pooled, 2e-04) 26 | expect_equal(k$sig, 3e-04) 27 | expect_equal(k$sig_l, 2e-04) 28 | expect_equal(k$sig_u, 0.9998) 29 | expect_equal(k$num_df, 90) 30 | expect_equal(k$den_df, 108) 31 | expect_equal(k$f, 1.605) 32 | expect_equal(k$f_sig, 0.0188) 33 | expect_equal(k$confint, 0.95) 34 | expect_equal(k$var_y, "write") 35 | expect_equal(k$alternative, "both") 36 | }) 37 | 38 | 39 | test_that("output from independent sample t test is as expected when alternative is less", { 40 | expect_snapshot(ifr_ts_ind_ttest(hsb, female, write, alternative = "less")) 41 | }) 42 | 43 | test_that("output from independent sample t test is as expected when alternative is greater", { 44 | expect_snapshot(ifr_ts_ind_ttest(hsb, female, write, alternative = "greater")) 45 | }) 46 | 47 | test_that("output from independent sample t test is as expected when alternative is both", { 48 | expect_snapshot(ifr_ts_ind_ttest(hsb, female, write, alternative = "both")) 49 | }) 50 | 51 | test_that("output from independent sample t test is as expected when alternative is all", { 52 | expect_snapshot(ifr_ts_ind_ttest(hsb, female, write, alternative = "all")) 53 | }) 54 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /man/ifr_os_prop_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-os-prop-test.R 3 | \name{ifr_os_prop_test} 4 | \alias{ifr_os_prop_test} 5 | \alias{ifr_os_prop_test.default} 6 | \alias{infer_os_prop_test} 7 | \title{One Sample Test of Proportion} 8 | \usage{ 9 | ifr_os_prop_test( 10 | data, 11 | variable = NULL, 12 | prob = 0.5, 13 | phat = 0.5, 14 | alternative = c("both", "less", "greater", "all") 15 | ) 16 | 17 | \method{ifr_os_prop_test}{default}( 18 | data, 19 | variable = NULL, 20 | prob = 0.5, 21 | phat = 0.5, 22 | alternative = c("both", "less", "greater", "all") 23 | ) 24 | } 25 | \arguments{ 26 | \item{data}{numeric vector of length 1 or a \code{data.frame} or \code{tibble}} 27 | 28 | \item{variable}{factor; column in \code{data}} 29 | 30 | \item{prob}{hypothesised proportion} 31 | 32 | \item{phat}{observed proportion} 33 | 34 | \item{alternative}{a character string specifying the alternative hypothesis, 35 | must be one of "both" (default), "greater", "less" or "all". You can specify 36 | just the initial letter.} 37 | } 38 | \value{ 39 | \code{ifr_os_prop_test} returns an object of class \code{"ifr_os_prop_test"}. 40 | An object of class \code{"ifr_os_prop_test"} is a list containing the 41 | following components: 42 | 43 | \item{n}{number of observations} 44 | \item{phat}{proportion of 1's} 45 | \item{p}{assumed probability of success} 46 | \item{z}{z statistic} 47 | \item{sig}{p-value for z statistic} 48 | \item{alt}{alternative hypothesis} 49 | \item{obs}{observed number of 0's and 1's} 50 | \item{exp}{expected number of 0's and 1's} 51 | \item{deviation}{deviation of observed from expected} 52 | \item{std}{standardized resiudals} 53 | } 54 | \description{ 55 | \code{ifr_os_prop_test} compares proportion in one group to a 56 | specified population proportion. 57 | } 58 | \section{Deprecated Function}{ 59 | 60 | \code{infer_os_prop_test()} has been deprecated. Instead use \code{ifr_os_prop_test()}. 61 | } 62 | 63 | \examples{ 64 | # use as a calculator 65 | ifr_os_prop_test(200, prob = 0.5, phat = 0.3) 66 | 67 | # using data set 68 | ifr_os_prop_test(hsb, female, prob = 0.5) 69 | 70 | } 71 | \references{ 72 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 73 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 74 | } 75 | \seealso{ 76 | \code{\link[stats]{prop.test}} \code{\link[stats]{binom.test}} 77 | } 78 | -------------------------------------------------------------------------------- /docs/docsearch.json: -------------------------------------------------------------------------------- 1 | { 2 | "index_name": "inferr", 3 | "start_urls": [ 4 | { 5 | "url": "https://inferr.rsquaredacademy.com/index.html", 6 | "selectors_key": "homepage", 7 | "tags": [ 8 | "homepage" 9 | ] 10 | }, 11 | { 12 | "url": "https://inferr.rsquaredacademy.com/reference", 13 | "selectors_key": "reference", 14 | "tags": [ 15 | "reference" 16 | ] 17 | }, 18 | { 19 | "url": "https://inferr.rsquaredacademy.com/articles", 20 | "selectors_key": "articles", 21 | "tags": [ 22 | "articles" 23 | ] 24 | } 25 | ], 26 | "stop_urls": [ 27 | "/reference/$", 28 | "/reference/index.html", 29 | "/articles/$", 30 | "/articles/index.html" 31 | ], 32 | "sitemap_urls": [ 33 | "https://inferr.rsquaredacademy.com/sitemap.xml" 34 | ], 35 | "selectors": { 36 | "homepage": { 37 | "lvl0": { 38 | "selector": ".contents h1", 39 | "default_value": "inferr Home page" 40 | }, 41 | "lvl1": { 42 | "selector": ".contents h2" 43 | }, 44 | "lvl2": { 45 | "selector": ".contents h3", 46 | "default_value": "Context" 47 | }, 48 | "lvl3": ".ref-arguments td, .ref-description", 49 | "text": ".contents p, .contents li, .contents .pre" 50 | }, 51 | "reference": { 52 | "lvl0": { 53 | "selector": ".contents h1" 54 | }, 55 | "lvl1": { 56 | "selector": ".contents .name", 57 | "default_value": "Argument" 58 | }, 59 | "lvl2": { 60 | "selector": ".ref-arguments th", 61 | "default_value": "Description" 62 | }, 63 | "lvl3": ".ref-arguments td, .ref-description", 64 | "text": ".contents p, .contents li" 65 | }, 66 | "articles": { 67 | "lvl0": { 68 | "selector": ".contents h1" 69 | }, 70 | "lvl1": { 71 | "selector": ".contents .name" 72 | }, 73 | "lvl2": { 74 | "selector": ".contents h2, .contents h3", 75 | "default_value": "Context" 76 | }, 77 | "text": ".contents p, .contents li" 78 | } 79 | }, 80 | "selectors_exclude": [ 81 | ".dont-index" 82 | ], 83 | "min_indexed_level": 2, 84 | "custom_settings": { 85 | "separatorsToIndex": "_", 86 | "attributesToRetrieve": [ 87 | "hierarchy", 88 | "content", 89 | "anchor", 90 | "url", 91 | "url_without_anchor" 92 | ] 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /man/ifr_ts_var_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-ts-var-test.R 3 | \name{ifr_ts_var_test} 4 | \alias{ifr_ts_var_test} 5 | \alias{infer_ts_var_test} 6 | \title{Two Sample Variance Comparison Test} 7 | \usage{ 8 | ifr_ts_var_test( 9 | data, 10 | ..., 11 | group_var = NULL, 12 | alternative = c("less", "greater", "all") 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a \code{data.frame} or \code{tibble}} 17 | 18 | \item{...}{numeric; column(s) in \code{data}} 19 | 20 | \item{group_var}{factor; column in \code{data}} 21 | 22 | \item{alternative}{a character string specifying the alternative hypothesis, 23 | must be one of "both" (default), "greater", "less" or "all". You can specify 24 | just the initial letter.} 25 | } 26 | \value{ 27 | \code{ifr_ts_var_test} returns an object of class \code{"ifr_ts_var_test"}. 28 | An object of class \code{"ifr_ts_var_test"} is a list containing the 29 | following components: 30 | 31 | \item{f}{f statistic} 32 | \item{lower}{lower one-sided p-value} 33 | \item{upper}{upper one-sided p-value} 34 | \item{two_tail}{two-sided p-value} 35 | \item{vars}{variances for each level of the grouping variable} 36 | \item{avgs}{means for each level of the grouping variable} 37 | \item{sds}{standard deviations for each level of the grouping variable} 38 | \item{ses}{standard errors for each level of the grouping variable} 39 | \item{avg}{combined mean} 40 | \item{sd}{combined standard deviation} 41 | \item{se}{estimated combined standard error} 42 | \item{n1}{numerator degrees of freedom} 43 | \item{n2}{denominator degrees of freedom} 44 | \item{lens}{number of observations for each level of grouping variable} 45 | \item{len}{number of observations} 46 | \item{lev}{levels of the grouping variable} 47 | \item{type}{alternative hypothesis} 48 | } 49 | \description{ 50 | \code{ifr_ts_var_test} performs tests on the equality of standard 51 | deviations (variances). 52 | } 53 | \section{Deprecated Function}{ 54 | 55 | \code{infer_ts_var_test()} has been deprecated. Instead use \code{ifr_ts_var_test()}. 56 | } 57 | 58 | \examples{ 59 | # using grouping variable 60 | ifr_ts_var_test(hsb, read, group_var = female, alternative = 'less') 61 | 62 | # using two variables 63 | ifr_ts_var_test(hsb, read, write, alternative = 'less') 64 | 65 | } 66 | \references{ 67 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 68 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 69 | } 70 | \seealso{ 71 | \code{\link[stats]{var.test}} 72 | } 73 | -------------------------------------------------------------------------------- /man/ifr_os_var_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-os-var-test.R 3 | \name{ifr_os_var_test} 4 | \alias{ifr_os_var_test} 5 | \alias{infer_os_var_test} 6 | \title{One Sample Variance Comparison Test} 7 | \usage{ 8 | ifr_os_var_test( 9 | data, 10 | x, 11 | sd, 12 | confint = 0.95, 13 | alternative = c("both", "less", "greater", "all"), 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{a \code{data.frame} or \code{tibble}} 19 | 20 | \item{x}{numeric; column in \code{data}} 21 | 22 | \item{sd}{hypothesised standard deviation} 23 | 24 | \item{confint}{confidence level} 25 | 26 | \item{alternative}{a character string specifying the alternative hypothesis, 27 | must be one of "both" (default), "greater", "less" or "all". You can specify 28 | just the initial letter} 29 | 30 | \item{...}{additional arguments passed to or from other methods} 31 | } 32 | \value{ 33 | \code{ifr_os_var_test} returns an object of class \code{"ifr_os_var_test"}. 34 | An object of class \code{"ifr_os_var_test"} is a list containing the 35 | following components: 36 | 37 | \item{n}{number of observations} 38 | \item{sd}{hypothesised standard deviation of \code{x}} 39 | \item{sigma}{observed standard deviation} 40 | \item{se}{estimated standard error} 41 | \item{chi}{chi-square statistic} 42 | \item{df}{degrees of freedom} 43 | \item{p_lower}{lower one-sided p-value} 44 | \item{p_upper}{upper one-sided p-value} 45 | \item{p_two}{two-sided p-value} 46 | \item{xbar}{mean of \code{x}} 47 | \item{c_lwr}{lower confidence limit of standard deviation} 48 | \item{c_upr}{upper confidence limit of standard deviation} 49 | \item{var_name}{name of \code{x}} 50 | \item{conf}{confidence level} 51 | \item{type}{alternative hypothesis} 52 | } 53 | \description{ 54 | \code{ifr_os_var_test} performs tests on the equality of standard 55 | deviations (variances).It tests that the standard deviation of a sample is 56 | equal to a hypothesized value. 57 | } 58 | \section{Deprecated Function}{ 59 | 60 | \code{infer_os_var_test()} has been deprecated. Instead use \code{ifr_os_var_test()}. 61 | } 62 | 63 | \examples{ 64 | # lower tail 65 | ifr_os_var_test(mtcars, mpg, 5, alternative = 'less') 66 | 67 | # upper tail 68 | ifr_os_var_test(mtcars, mpg, 5, alternative = 'greater') 69 | 70 | # both tails 71 | ifr_os_var_test(mtcars, mpg, 5, alternative = 'both') 72 | 73 | # all tails 74 | ifr_os_var_test(mtcars, mpg, 5, alternative = 'all') 75 | 76 | } 77 | \references{ 78 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 79 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 80 | } 81 | \seealso{ 82 | \code{\link[stats]{var.test}} 83 | } 84 | -------------------------------------------------------------------------------- /man/ifr_os_t_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-os-t-test.R 3 | \name{ifr_os_t_test} 4 | \alias{ifr_os_t_test} 5 | \alias{infer_os_t_test} 6 | \title{One Sample t Test} 7 | \usage{ 8 | ifr_os_t_test( 9 | data, 10 | x, 11 | mu = 0, 12 | alpha = 0.05, 13 | alternative = c("both", "less", "greater", "all"), 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{a \code{data.frame} or \code{tibble}} 19 | 20 | \item{x}{numeric; column in \code{data}} 21 | 22 | \item{mu}{a number indicating the true value of the mean} 23 | 24 | \item{alpha}{acceptable tolerance for type I error} 25 | 26 | \item{alternative}{a character string specifying the alternative hypothesis, must be 27 | one of "both" (default), "greater", "less" or "all". You can specify just the 28 | initial letter} 29 | 30 | \item{...}{additional arguments passed to or from other methods} 31 | } 32 | \value{ 33 | \code{ifr_os_t_test} returns an object of class \code{"ifr_os_t_test"}. 34 | An object of class \code{"ifr_os_t_test"} is a list containing the 35 | following components: 36 | 37 | \item{mu}{a number indicating the true value of the mean} 38 | \item{n}{number of observations} 39 | \item{df}{degrees of freedom} 40 | \item{Mean}{observed mean of \code{x}} 41 | \item{stddev}{standard deviation of \code{x}} 42 | \item{std_err}{estimate of standard error} 43 | \item{test_stat}{t statistic} 44 | \item{confint}{confidence interval for the mean} 45 | \item{mean_diff}{mean difference} 46 | \item{mean_diff_l}{lower confidence limit for mean difference} 47 | \item{mean_diff_u}{upper confidence limit for mean difference} 48 | \item{p_l}{lower one-sided p-value} 49 | \item{p_u}{upper one-sided p-value} 50 | \item{p}{two sided p-value} 51 | \item{conf}{confidence level} 52 | \item{type}{alternative hypothesis} 53 | \item{var_name}{name of \code{x}} 54 | } 55 | \description{ 56 | \code{ifr_os_t_test} performs t tests on the equality of means. It tests the 57 | hypothesis that a sample has a mean equal to a hypothesized value. 58 | } 59 | \section{Deprecated Function}{ 60 | 61 | \code{infer_os_t_test()} has been deprecated. Instead use \code{ifr_os_t_test()}. 62 | } 63 | 64 | \examples{ 65 | # lower tail 66 | ifr_os_t_test(hsb, write, mu = 50, alternative = 'less') 67 | 68 | # upper tail 69 | ifr_os_t_test(hsb, write, mu = 50, alternative = 'greater') 70 | 71 | # both tails 72 | ifr_os_t_test(hsb, write, mu = 50, alternative = 'both') 73 | 74 | # all tails 75 | ifr_os_t_test(hsb, write, mu = 50, alternative = 'all') 76 | 77 | } 78 | \references{ 79 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 80 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 81 | } 82 | \seealso{ 83 | \code{\link[stats]{t.test}} 84 | } 85 | -------------------------------------------------------------------------------- /man/ifr_ts_paired_ttest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-ts-paired-ttest.R 3 | \name{ifr_ts_paired_ttest} 4 | \alias{ifr_ts_paired_ttest} 5 | \alias{infer_ts_paired_ttest} 6 | \title{Paired t test} 7 | \usage{ 8 | ifr_ts_paired_ttest( 9 | data, 10 | x, 11 | y, 12 | confint = 0.95, 13 | alternative = c("both", "less", "greater", "all") 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{a \code{data.frame} or \code{tibble}} 18 | 19 | \item{x}{numeric; column in \code{data}} 20 | 21 | \item{y}{numeric; column in \code{data}} 22 | 23 | \item{confint}{confidence level} 24 | 25 | \item{alternative}{a character string specifying the alternative hypothesis, must be 26 | one of "both" (default), "greater", "less" or "all". You can specify just the 27 | initial letter.} 28 | } 29 | \value{ 30 | \code{ifr_ts_paired_ttest} returns an object of class \code{"ifr_ts_paired_ttest"}. 31 | An object of class \code{"ifr_ts_paired_ttest"} is a list containing the 32 | following components: 33 | 34 | \item{Obs}{number of observations} 35 | \item{b}{mean, standard deviation and standard error of \code{x}, \code{y} 36 | and their difference} 37 | \item{tstat}{t statistic} 38 | \item{p_lower}{lower one-sided p-value} 39 | \item{p_upper}{upper one-sided p-value} 40 | \item{p_two_tail}{two sided p-value} 41 | \item{corr}{Correlation of \code{x} and \code{y}} 42 | \item{corsig}{p-value of correlation test} 43 | \item{conf_int1}{confidence interval for mean of \code{x}} 44 | \item{conf_int2}{confidence interval for mean of \code{y}} 45 | \item{conf_int_diff}{confidence interval for mean of difference of \code{x} 46 | and \code{y}} 47 | \item{df}{degrees of freedom} 48 | \item{confint}{confidence level} 49 | \item{alternative}{alternative hypothesis} 50 | \item{var_names}{names of \code{x} and \code{y}} 51 | \item{xy}{string used in printing results of the test} 52 | } 53 | \description{ 54 | \code{ifr_ts_paired_ttest} tests that two samples have the 55 | same mean, assuming paired data. 56 | } 57 | \section{Deprecated Function}{ 58 | 59 | \code{infer_ts_paired_ttest()} has been deprecated. Instead use 60 | \code{ifr_ts_paired_ttest()}. 61 | } 62 | 63 | \examples{ 64 | # lower tail 65 | ifr_ts_paired_ttest(hsb, read, write, alternative = 'less') 66 | 67 | # upper tail 68 | ifr_ts_paired_ttest(hsb, read, write, alternative = 'greater') 69 | 70 | # both tails 71 | ifr_ts_paired_ttest(hsb, read, write, alternative = 'both') 72 | 73 | # all tails 74 | ifr_ts_paired_ttest(hsb, read, write, alternative = 'all') 75 | 76 | } 77 | \references{ 78 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 79 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 80 | } 81 | \seealso{ 82 | \code{\link[stats]{t.test}} 83 | } 84 | -------------------------------------------------------------------------------- /man/ifr_runs_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-runs-test.R 3 | \name{ifr_runs_test} 4 | \alias{ifr_runs_test} 5 | \alias{infer_runs_test} 6 | \title{Test for Random Order} 7 | \usage{ 8 | ifr_runs_test( 9 | data, 10 | x, 11 | drop = FALSE, 12 | split = FALSE, 13 | mean = FALSE, 14 | threshold = NA 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{a \code{data.frame} or \code{tibble}} 19 | 20 | \item{x}{numeric; column in \code{data}} 21 | 22 | \item{drop}{logical; if TRUE, values equal to the threshold will be dropped 23 | from \code{x}} 24 | 25 | \item{split}{logical; if TRUE, data will be recoded in binary format} 26 | 27 | \item{mean}{logical; if TRUE, mean will be used as threshold} 28 | 29 | \item{threshold}{threshold to be used for counting runs, specify 0 if data 30 | is coded as a binary.} 31 | } 32 | \value{ 33 | \code{infer_runs_test} returns an object of class \code{"ifr_runs_test"}. 34 | An object of class \code{"ifr_runs_test"} is a list containing the 35 | following components: 36 | 37 | \item{n}{number of observations} 38 | \item{threshold}{within group sum of squares} 39 | \item{n_below}{number below the threshold} 40 | \item{n_above}{number above the threshold} 41 | \item{mean}{expected number of runs} 42 | \item{var}{variance of the number of runs} 43 | \item{n_runs}{number of runs} 44 | \item{z}{z statistic} 45 | \item{p}{p-value of \code{z}} 46 | } 47 | \description{ 48 | runtest tests whether the observations of \code{x} are serially 49 | independent i.e. whether they occur in a random order, by counting 50 | how many runs there are above and below a threshold. By default, the median 51 | is used as the threshold. A small number of runs indicates positive serial 52 | correlation; a large number indicates negative serial correlation. 53 | } 54 | \section{Deprecated Function}{ 55 | 56 | \code{runs_test()} has been deprecated. Instead use \code{ifr_runs_test()}. 57 | } 58 | 59 | \examples{ 60 | ifr_runs_test(hsb, read) 61 | 62 | ifr_runs_test(hsb, read, drop = TRUE) 63 | 64 | ifr_runs_test(hsb, read, split = TRUE) 65 | 66 | ifr_runs_test(hsb, read, mean = TRUE) 67 | 68 | ifr_runs_test(hsb, read, threshold = 0) 69 | 70 | } 71 | \references{ 72 | {Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric Statistical Procedures, 4th edition. : Chapman & Hall/CRC.} 73 | 74 | {Edgington, E. S. 1961. Probability table for number of runs of signs of first differences in ordered series. Journal of the American Statistical Association 56: 156–159.} 75 | 76 | {Madansky, A. 1988. Prescriptions for Working Statisticians. New York: Springer.} 77 | 78 | {Swed, F. S., and C. Eisenhart. 1943. Tables for testing randomness of grouping in a sequence of alternatives. Annals of Mathematical Statistics 14: 66–87.} 79 | } 80 | -------------------------------------------------------------------------------- /docs/jquery.sticky-kit.min.js: -------------------------------------------------------------------------------- 1 | /* Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | */ 2 | /* 3 | Source: https://github.com/leafo/sticky-kit 4 | License: MIT 5 | */ 6 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); 7 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
    "))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, 8 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), 10 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", 11 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n localStorage.getItem('theme') 10 | const setStoredTheme = theme => localStorage.setItem('theme', theme) 11 | 12 | const getPreferredTheme = () => { 13 | const storedTheme = getStoredTheme() 14 | if (storedTheme) { 15 | return storedTheme 16 | } 17 | 18 | return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' 19 | } 20 | 21 | const setTheme = theme => { 22 | if (theme === 'auto') { 23 | document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) 24 | } else { 25 | document.documentElement.setAttribute('data-bs-theme', theme) 26 | } 27 | } 28 | 29 | function bsSetupThemeToggle () { 30 | 'use strict' 31 | 32 | const showActiveTheme = (theme, focus = false) => { 33 | var activeLabel, activeIcon; 34 | 35 | document.querySelectorAll('[data-bs-theme-value]').forEach(element => { 36 | const buttonTheme = element.getAttribute('data-bs-theme-value') 37 | const isActive = buttonTheme == theme 38 | 39 | element.classList.toggle('active', isActive) 40 | element.setAttribute('aria-pressed', isActive) 41 | 42 | if (isActive) { 43 | activeLabel = element.textContent; 44 | activeIcon = element.querySelector('span').classList.value; 45 | } 46 | }) 47 | 48 | const themeSwitcher = document.querySelector('#dropdown-lightswitch') 49 | if (!themeSwitcher) { 50 | return 51 | } 52 | 53 | themeSwitcher.setAttribute('aria-label', activeLabel) 54 | themeSwitcher.querySelector('span').classList.value = activeIcon; 55 | 56 | if (focus) { 57 | themeSwitcher.focus() 58 | } 59 | } 60 | 61 | window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { 62 | const storedTheme = getStoredTheme() 63 | if (storedTheme !== 'light' && storedTheme !== 'dark') { 64 | setTheme(getPreferredTheme()) 65 | } 66 | }) 67 | 68 | window.addEventListener('DOMContentLoaded', () => { 69 | showActiveTheme(getPreferredTheme()) 70 | 71 | document 72 | .querySelectorAll('[data-bs-theme-value]') 73 | .forEach(toggle => { 74 | toggle.addEventListener('click', () => { 75 | const theme = toggle.getAttribute('data-bs-theme-value') 76 | setTheme(theme) 77 | setStoredTheme(theme) 78 | showActiveTheme(theme, true) 79 | }) 80 | }) 81 | }) 82 | } 83 | 84 | setTheme(getPreferredTheme()); 85 | bsSetupThemeToggle(); 86 | -------------------------------------------------------------------------------- /tests/testthat/test-chisqgof.R: -------------------------------------------------------------------------------- 1 | test_that("output from ifr_chisq_gof_test matches the expected output", { 2 | k <- ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140)) 3 | expect_equal(k$chisquare, 5.0286) 4 | expect_equal(k$pvalue, 0.1697) 5 | expect_equal(k$degrees_of_freedom, 3) 6 | expect_equal(k$sample_size, 200) 7 | expect_equal(k$categories, c("1", "2", "3", "4")) 8 | expect_equal(k$n_levels, 4) 9 | expect_equal(k$observed_frequency, c(24, 11, 20, 145)) 10 | expect_equal(k$expected_frequency, c(20, 20, 20, 140)) 11 | expect_equal(k$deviation, c(" 20.00", "-45.00", " 0.00", " 3.57")) 12 | expect_equal(k$std_residuals, c(" 0.89", "-2.01", " 0.00", " 0.42")) 13 | expect_equal(k$varname, "race") 14 | }) 15 | 16 | 17 | test_that("output from ifr_chisq_gof_test matches the expected output", { 18 | k <- ifr_chisq_gof_test(hsb, race, c(0.1, 0.1, 0.1, 0.7)) 19 | expect_equal(k$chisquare, 5.0286) 20 | expect_equal(k$pvalue, 0.1697) 21 | expect_equal(k$degrees_of_freedom, 3) 22 | expect_equal(k$sample_size, 200) 23 | expect_equal(k$categories, c("1", "2", "3", "4")) 24 | expect_equal(k$n_levels, 4) 25 | expect_equal(k$observed_frequency, c(24, 11, 20, 145)) 26 | expect_equal(k$expected_frequency, c(20, 20, 20, 140)) 27 | expect_equal(k$deviation, c(" 20.00", "-45.00", " 0.00", " 3.57")) 28 | expect_equal(k$std_residuals, c(" 0.89", "-2.01", " 0.00", " 0.42")) 29 | expect_equal(k$varname, "race") 30 | }) 31 | 32 | test_that("output from ifr_chisq_gof_test matches the expected output", { 33 | k <- ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140), correct = TRUE) 34 | expect_equal(k$chisquare, 4.3821) 35 | expect_equal(k$pvalue, 0.2231) 36 | expect_equal(k$degrees_of_freedom, 3) 37 | expect_equal(k$sample_size, 200) 38 | expect_equal(k$categories, c("1", "2", "3", "4")) 39 | expect_equal(k$n_levels, 4) 40 | expect_equal(k$observed_frequency, c(24, 11, 20, 145)) 41 | expect_equal(k$expected_frequency, c(20, 20, 20, 140)) 42 | expect_equal(k$deviation, c(" 17.50", "-47.50", " -2.50", " 3.21")) 43 | expect_equal(k$std_residuals, c(" 0.78", "-2.12", "-0.11", " 0.38")) 44 | expect_equal(k$varname, "race") 45 | }) 46 | 47 | 48 | test_that("ifr_chisq_gof_test throws appropriate errors", { 49 | expect_error( 50 | ifr_chisq_gof_test( 51 | hsb, race, c(20, 20, 20, 140), 52 | correct = "FALSE" 53 | ), 54 | "correct must be either TRUE or FALSE" 55 | ) 56 | expect_error( 57 | ifr_chisq_gof_test( 58 | hsb, race, 59 | c("20", "20", "20", "140") 60 | ), 61 | "y must be numeric" 62 | ) 63 | expect_error( 64 | ifr_chisq_gof_test(hsb, race, c(20, 20, 20)), 65 | "Length of y must be equal to the number of categories in x" 66 | ) 67 | }) 68 | 69 | 70 | test_that("output from ifr_chisq_gof_test is as expected", { 71 | expect_snapshot(ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140))) 72 | }) 73 | -------------------------------------------------------------------------------- /tests/_covrpage.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Tests and Coverage" 3 | date: "`r format(Sys.time(), '%d %B, %Y %H:%M:%S')`" 4 | --- 5 | 6 | This output is created by [covrpage](https://github.com/yonicd/covrpage). 7 | 8 | ```{r load,include=FALSE} 9 | library(covr , warn.conflicts = FALSE , quietly = TRUE) 10 | library(knitr , warn.conflicts = FALSE , quietly = TRUE) 11 | library(magrittr , warn.conflicts = FALSE , quietly = TRUE) 12 | 13 | ``` 14 | 15 | ```{r tests, include=FALSE} 16 | #test_x <- testthat::test_dir('testthat') 17 | this_pkg <- basename(normalizePath('..')) 18 | test_x <- testthat::test_check(this_pkg,reporter = testthat::default_reporter(),stop_on_failure = FALSE,stop_on_warning = FALSE) 19 | 20 | skip <- length(test_x)>0 21 | ``` 22 | 23 | ```{r maps, include=FALSE} 24 | test_m <- covrpage::map_testthat('testthat') 25 | ``` 26 | 27 | 28 | ```{r, include=FALSE} 29 | test_x_short <- test_x%>% 30 | covrpage::testthat_summary(type='short') 31 | 32 | test_x_long <- test_x%>% 33 | covrpage::testthat_summary(type='long') 34 | 35 | ``` 36 | 37 | ```{r, include=FALSE,eval=skip} 38 | test_skip <- test_x_long[test_x_long$status!='PASS',c('file','test')] 39 | 40 | test_skip$file <- gsub('#(.*?)$','',basename(test_skip$file)) 41 | 42 | test_skip <- merge(test_skip,test_m) 43 | 44 | ``` 45 | 46 | ```{r, include=FALSE,eval=!skip} 47 | 48 | test_skip <- test_m 49 | 50 | ``` 51 | 52 | ## Coverage 53 | 54 | Coverage summary is created using the [covr](https://github.com/r-lib/covr) package. 55 | 56 | ```{r,echo=FALSE} 57 | covrpage::coverage_skip(test_path = '../tests/testthat', test_skip = test_skip)%>% 58 | covrpage::covr_summary()%>% 59 | knitr::kable(digits = 2, 60 | col.names = c('Object','Coverage (%)'),align = c('l','c')) 61 | 62 | ``` 63 | 64 | 65 |
    66 | 67 | ## Unit Tests 68 | 69 | Unit Test summary is created using the [testthat](https://github.com/r-lib/testthat) package. 70 | 71 | ```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=!skip} 72 | cat('All tests were skipped') 73 | ``` 74 | 75 | ```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=skip} 76 | 77 | test_x_short%>% 78 | knitr::kable() 79 | 80 | ``` 81 | 82 |
    83 | Show Detailed Test Results 84 | 85 | ```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=!skip} 86 | cat('All tests were skipped') 87 | ``` 88 | 89 | ```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=skip} 90 | 91 | test_x_long%>% 92 | knitr::kable() 93 | 94 | ``` 95 | 96 |
    97 | 98 |
    99 | Session Info 100 | 101 | ```{r,echo=FALSE,warning=FALSE,message=FALSE} 102 | 103 | x <- covrpage:::sinfo() 104 | 105 | x$info%>% 106 | knitr::kable() 107 | 108 | x$pkgs%>% 109 | knitr::kable() 110 | 111 | ``` 112 | 113 |
    114 | 115 | 116 | `r sprintf('', test_to_badge(test_x_short))` 117 | -------------------------------------------------------------------------------- /tests/testthat/test-runs.R: -------------------------------------------------------------------------------- 1 | test_that("output from runs test matches the expected result", { 2 | reg <- lm(mpg ~ disp, data = mtcars) 3 | resid <- data.frame(residual = residuals(reg)) 4 | k <- ifr_runs_test(resid, residual) 5 | expect_equal(k$n, 32) 6 | expect_equal(round(k$threshold, 3), -0.963) 7 | expect_equal(k$n_above, 16) 8 | expect_equal(k$n_below, 16) 9 | expect_equal(k$mean, 17) 10 | expect_equal(round(k$var, 3), 7.742) 11 | expect_equal(k$n_runs, 11) 12 | expect_equal(round(k$z, 3), -2.156) 13 | expect_equal(round(k$p, 3), 0.031) 14 | }) 15 | 16 | test_that("output from runs test matches the expected result", { 17 | reg <- lm(mpg ~ disp, data = mtcars) 18 | resid <- data.frame(residual = residuals(reg)) 19 | k <- ifr_runs_test(resid, residual, drop = TRUE) 20 | expect_equal(k$n, 32) 21 | expect_equal(round(k$threshold, 3), -0.963) 22 | expect_equal(k$n_above, 16) 23 | expect_equal(k$n_below, 16) 24 | expect_equal(k$mean, 17) 25 | expect_equal(round(k$var, 3), 7.742) 26 | expect_equal(k$n_runs, 11) 27 | expect_equal(round(k$z, 3), -2.156) 28 | expect_equal(round(k$p, 3), 0.031) 29 | }) 30 | 31 | test_that("output from runs test matches the expected result", { 32 | reg <- lm(mpg ~ disp, data = mtcars) 33 | resid <- data.frame(residual = residuals(reg)) 34 | k <- ifr_runs_test(resid, residual, split = TRUE) 35 | expect_equal(k$n, 32) 36 | expect_equal(round(k$threshold, 3), -0.963) 37 | expect_equal(k$n_above, 16) 38 | expect_equal(k$n_below, 16) 39 | expect_equal(k$mean, 17) 40 | expect_equal(round(k$var, 3), 7.742) 41 | expect_equal(k$n_runs, 11) 42 | expect_equal(round(k$z, 3), -2.156) 43 | expect_equal(round(k$p, 3), 0.031) 44 | }) 45 | 46 | test_that("output from runs test matches the expected result", { 47 | reg <- lm(mpg ~ disp, data = mtcars) 48 | resid <- data.frame(residual = residuals(reg)) 49 | k <- ifr_runs_test(resid, residual, mean = TRUE) 50 | expect_equal(k$n, 32) 51 | expect_equal(k$threshold, -1.127570e-16) 52 | expect_equal(k$n_above, 13) 53 | expect_equal(k$n_below, 19) 54 | expect_equal(k$mean, 1.643750e+01) 55 | expect_equal(round(k$var, 2), 7.19) 56 | expect_equal(k$n_runs, 11) 57 | expect_equal(round(k$z, 2), -2.03) 58 | expect_equal(round(k$p, 2), 0.04) 59 | }) 60 | 61 | test_that("output from runs test matches the expected result", { 62 | reg <- lm(mpg ~ disp, data = mtcars) 63 | resid <- data.frame(residual = residuals(reg)) 64 | k <- ifr_runs_test(resid, residual, threshold = 0) 65 | expect_equal(k$n, 32) 66 | expect_equal(round(k$threshold, 3), 0) 67 | expect_equal(k$n_above, 13) 68 | expect_equal(k$n_below, 19) 69 | expect_equal(k$mean, 16.4375) 70 | expect_equal(round(k$var, 3), 7.19) 71 | expect_equal(k$n_runs, 11) 72 | expect_equal(round(k$z, 3), -2.028) 73 | expect_equal(round(k$p, 3), 0.043) 74 | }) 75 | 76 | test_that("output from runs test is as expected", { 77 | reg <- lm(mpg ~ disp, data = mtcars) 78 | resid <- data.frame(residual = residuals(reg)) 79 | expect_snapshot(ifr_runs_test(resid, residual)) 80 | }) 81 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(ifr_binom_calc,default) 4 | S3method(ifr_chisq_assoc_test,default) 5 | S3method(ifr_chisq_gof_test,default) 6 | S3method(ifr_cochran_qtest,default) 7 | S3method(ifr_levene_test,default) 8 | S3method(ifr_mcnemar_test,default) 9 | S3method(ifr_oneway_anova,default) 10 | S3method(ifr_os_prop_test,default) 11 | S3method(ifr_os_t_test,default) 12 | S3method(ifr_os_var_test,default) 13 | S3method(ifr_runs_test,default) 14 | S3method(ifr_ts_ind_ttest,default) 15 | S3method(ifr_ts_paired_ttest,default) 16 | S3method(ifr_ts_prop_test,default) 17 | S3method(ifr_ts_var_test,default) 18 | S3method(print,ifr_binom_calc) 19 | S3method(print,ifr_chisq_assoc_test) 20 | S3method(print,ifr_chisq_gof_test) 21 | S3method(print,ifr_cochran_qtest) 22 | S3method(print,ifr_levene_test) 23 | S3method(print,ifr_mcnemar_test) 24 | S3method(print,ifr_oneway_anova) 25 | S3method(print,ifr_os_prop_test) 26 | S3method(print,ifr_os_t_test) 27 | S3method(print,ifr_os_var_test) 28 | S3method(print,ifr_runs_test) 29 | S3method(print,ifr_ts_ind_ttest) 30 | S3method(print,ifr_ts_paired_ttest) 31 | S3method(print,ifr_ts_prop_test) 32 | S3method(print,ifr_ts_var_test) 33 | export(ifr_binom_calc) 34 | export(ifr_binom_test) 35 | export(ifr_chisq_assoc_test) 36 | export(ifr_chisq_gof_test) 37 | export(ifr_cochran_qtest) 38 | export(ifr_launch_shiny_app) 39 | export(ifr_levene_test) 40 | export(ifr_mcnemar_test) 41 | export(ifr_oneway_anova) 42 | export(ifr_os_prop_test) 43 | export(ifr_os_t_test) 44 | export(ifr_os_var_test) 45 | export(ifr_runs_test) 46 | export(ifr_ts_ind_ttest) 47 | export(ifr_ts_paired_ttest) 48 | export(ifr_ts_prop_calc) 49 | export(ifr_ts_prop_group) 50 | export(ifr_ts_prop_test) 51 | export(ifr_ts_var_test) 52 | export(infer_binom_calc) 53 | export(infer_binom_test) 54 | export(infer_chisq_assoc_test) 55 | export(infer_chisq_gof_test) 56 | export(infer_cochran_qtest) 57 | export(infer_launch_shiny_app) 58 | export(infer_levene_test) 59 | export(infer_mcnemar_test) 60 | export(infer_oneway_anova) 61 | export(infer_os_prop_test) 62 | export(infer_os_t_test) 63 | export(infer_os_var_test) 64 | export(infer_runs_test) 65 | export(infer_ts_ind_ttest) 66 | export(infer_ts_paired_ttest) 67 | export(infer_ts_prop_calc) 68 | export(infer_ts_prop_grp) 69 | export(infer_ts_prop_test) 70 | export(infer_ts_var_test) 71 | import(magrittr) 72 | importFrom(Rcpp,sourceCpp) 73 | importFrom(data.table,":=") 74 | importFrom(data.table,data.table) 75 | importFrom(data.table,setDF) 76 | importFrom(magrittr,"%>%") 77 | importFrom(stats,anova) 78 | importFrom(stats,as.formula) 79 | importFrom(stats,complete.cases) 80 | importFrom(stats,cor) 81 | importFrom(stats,dbinom) 82 | importFrom(stats,lm) 83 | importFrom(stats,median) 84 | importFrom(stats,pbinom) 85 | importFrom(stats,pchisq) 86 | importFrom(stats,pf) 87 | importFrom(stats,pnorm) 88 | importFrom(stats,pt) 89 | importFrom(stats,qchisq) 90 | importFrom(stats,qnorm) 91 | importFrom(stats,qt) 92 | importFrom(stats,sd) 93 | importFrom(stats,var) 94 | importFrom(utils,install.packages) 95 | importFrom(utils,menu) 96 | importFrom(utils,packageVersion) 97 | useDynLib(inferr) 98 | -------------------------------------------------------------------------------- /man/ifr_ts_prop_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-ts-prop-test.R 3 | \name{ifr_ts_prop_test} 4 | \alias{ifr_ts_prop_test} 5 | \alias{infer_ts_prop_test} 6 | \alias{infer_ts_prop_grp} 7 | \alias{infer_ts_prop_calc} 8 | \alias{ifr_ts_prop_group} 9 | \alias{ifr_ts_prop_calc} 10 | \title{Two Sample Test of Proportion} 11 | \usage{ 12 | ifr_ts_prop_test( 13 | data, 14 | var1, 15 | var2, 16 | alternative = c("both", "less", "greater", "all"), 17 | ... 18 | ) 19 | 20 | ifr_ts_prop_group( 21 | data, 22 | var, 23 | group, 24 | alternative = c("both", "less", "greater", "all") 25 | ) 26 | 27 | ifr_ts_prop_calc( 28 | n1, 29 | n2, 30 | p1, 31 | p2, 32 | alternative = c("both", "less", "greater", "all"), 33 | ... 34 | ) 35 | } 36 | \arguments{ 37 | \item{data}{a \code{data.frame} or \code{tibble}} 38 | 39 | \item{var1}{factor; column in \code{data}} 40 | 41 | \item{var2}{factor; column in \code{data}} 42 | 43 | \item{alternative}{a character string specifying the alternative hypothesis, 44 | must be one of "both" (default), "greater", "less" or "all". You can specify 45 | just the initial letter} 46 | 47 | \item{...}{additional arguments passed to or from other methods} 48 | 49 | \item{var}{factor; column in \code{data}} 50 | 51 | \item{group}{factor; column in \code{data}} 52 | 53 | \item{n1}{sample 1 size} 54 | 55 | \item{n2}{sample 2 size} 56 | 57 | \item{p1}{sample 1 proportion} 58 | 59 | \item{p2}{sample 2 proportion} 60 | } 61 | \value{ 62 | an object of class \code{"ifr_ts_prop_test"}. 63 | An object of class \code{"ifr_ts_prop_test"} is a list containing the 64 | following components: 65 | 66 | \item{n1}{sample 1 size} 67 | \item{n2}{sample 2 size} 68 | \item{phat1}{sample 1 proportion} 69 | \item{phat2}{sample 2 proportion} 70 | \item{z}{z statistic} 71 | \item{sig}{p-value for z statistic} 72 | \item{alt}{alternative hypothesis} 73 | } 74 | \description{ 75 | Tests on the equality of proportions using 76 | large-sample statistics. It tests that a sample has the same proportion 77 | within two independent groups or two samples have the same proportion. 78 | } 79 | \section{Deprecated Functions}{ 80 | 81 | \code{infer_ts_prop_test()}, \code{infer_ts_prop_grp()} and \code{infer_ts_prop_calc()} have 82 | been deprecated. Instead use \code{ifr_ts_prop_test()}, 83 | \code{ifr_ts_prop_group()} and \code{ifr_ts_prop_calc()}. 84 | } 85 | 86 | \examples{ 87 | # using variables 88 | # lower tail 89 | ifr_ts_prop_test(treatment, treatment1, treatment2, 90 | alternative = 'less') 91 | 92 | # using groups 93 | # lower tail 94 | ifr_ts_prop_group(treatment2, outcome, female, 95 | alternative = 'less') 96 | 97 | # using sample size and proportions 98 | # lower tail 99 | ifr_ts_prop_calc(n1 = 30, n2 = 25, p1 = 0.3, p2 = 0.5, alternative = 'less') 100 | 101 | } 102 | \references{ 103 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 104 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 105 | } 106 | \seealso{ 107 | \code{\link[stats]{prop.test}} 108 | } 109 | -------------------------------------------------------------------------------- /.github/workflows/rhub.yaml: -------------------------------------------------------------------------------- 1 | # R-hub's generic GitHub Actions workflow file. It's canonical location is at 2 | # https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml 3 | # You can update this file to a newer version using the rhub2 package: 4 | # 5 | # rhub::rhub_setup() 6 | # 7 | # It is unlikely that you need to modify this file manually. 8 | 9 | name: R-hub 10 | run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" 11 | 12 | on: 13 | workflow_dispatch: 14 | inputs: 15 | config: 16 | description: 'A comma separated list of R-hub platforms to use.' 17 | type: string 18 | default: 'linux,windows,macos' 19 | name: 20 | description: 'Run name. You can leave this empty now.' 21 | type: string 22 | id: 23 | description: 'Unique ID. You can leave this empty now.' 24 | type: string 25 | 26 | jobs: 27 | 28 | setup: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | containers: ${{ steps.rhub-setup.outputs.containers }} 32 | platforms: ${{ steps.rhub-setup.outputs.platforms }} 33 | 34 | steps: 35 | # NO NEED TO CHECKOUT HERE 36 | - uses: r-hub/actions/setup@v1 37 | with: 38 | config: ${{ github.event.inputs.config }} 39 | id: rhub-setup 40 | 41 | linux-containers: 42 | needs: setup 43 | if: ${{ needs.setup.outputs.containers != '[]' }} 44 | runs-on: ubuntu-latest 45 | name: ${{ matrix.config.label }} 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | config: ${{ fromJson(needs.setup.outputs.containers) }} 50 | container: 51 | image: ${{ matrix.config.container }} 52 | 53 | steps: 54 | - uses: r-hub/actions/checkout@v1 55 | - uses: r-hub/actions/platform-info@v1 56 | with: 57 | token: ${{ secrets.RHUB_TOKEN }} 58 | job-config: ${{ matrix.config.job-config }} 59 | - uses: r-hub/actions/setup-deps@v1 60 | with: 61 | token: ${{ secrets.RHUB_TOKEN }} 62 | job-config: ${{ matrix.config.job-config }} 63 | - uses: r-hub/actions/run-check@v1 64 | with: 65 | token: ${{ secrets.RHUB_TOKEN }} 66 | job-config: ${{ matrix.config.job-config }} 67 | 68 | other-platforms: 69 | needs: setup 70 | if: ${{ needs.setup.outputs.platforms != '[]' }} 71 | runs-on: ${{ matrix.config.os }} 72 | name: ${{ matrix.config.label }} 73 | strategy: 74 | fail-fast: false 75 | matrix: 76 | config: ${{ fromJson(needs.setup.outputs.platforms) }} 77 | 78 | steps: 79 | - uses: r-hub/actions/checkout@v1 80 | - uses: r-hub/actions/setup-r@v1 81 | with: 82 | job-config: ${{ matrix.config.job-config }} 83 | token: ${{ secrets.RHUB_TOKEN }} 84 | - uses: r-hub/actions/platform-info@v1 85 | with: 86 | token: ${{ secrets.RHUB_TOKEN }} 87 | job-config: ${{ matrix.config.job-config }} 88 | - uses: r-hub/actions/setup-deps@v1 89 | with: 90 | job-config: ${{ matrix.config.job-config }} 91 | token: ${{ secrets.RHUB_TOKEN }} 92 | - uses: r-hub/actions/run-check@v1 93 | with: 94 | job-config: ${{ matrix.config.job-config }} 95 | token: ${{ secrets.RHUB_TOKEN }} 96 | -------------------------------------------------------------------------------- /R/ifr-cochran-q-test.R: -------------------------------------------------------------------------------- 1 | #' @title Cochran Q Test 2 | #' @description Test if the proportions of 3 or more dichotomous variables are 3 | #' equal in the same population. 4 | #' @param data a \code{data.frame} or \code{tibble} 5 | #' @param ... columns in \code{data} 6 | #' 7 | #' @return \code{ifr_cochran_qtest} returns an object of class 8 | #' \code{"ifr_cochran_qtest"}. An object of class \code{"ifr_cochran_qtest"} 9 | #' is a list containing the following components: 10 | #' 11 | #' \item{df}{degrees of freedom} 12 | #' \item{n}{number of observations} 13 | #' \item{pvalue}{p value} 14 | #' \item{q}{cochran's q statistic} 15 | #' 16 | #' @section Deprecated Function: 17 | #' \code{infer_cochran_test()} has been deprecated. Instead use 18 | #' \code{ifr_cochran_qtest()}. 19 | #' 20 | #' @references Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 21 | #' Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 22 | #' 23 | #' @examples 24 | #' ifr_cochran_qtest(exam, exam1, exam2, exam3) 25 | #' 26 | #' @export 27 | #' 28 | ifr_cochran_qtest <- function(data, ...) UseMethod("ifr_cochran_qtest") 29 | 30 | #' @export 31 | ifr_cochran_qtest.default <- function(data, ...) { 32 | 33 | vars <- vapply(substitute(...()), deparse, NA_character_) 34 | fdata <- data[vars] 35 | 36 | if (ncol(fdata) < 3) { 37 | stop("Please specify at least 3 variables.", call. = FALSE) 38 | } 39 | 40 | if (any(sapply(lapply(fdata, as.factor), nlevels) > 2)) { 41 | stop("Please specify dichotomous/binary variables only.", call. = FALSE) 42 | } 43 | 44 | k <- cochran_comp(fdata) 45 | 46 | result <- 47 | list( 48 | df = k$df, 49 | n = k$n, 50 | pvalue = k$pvalue, 51 | q = k$q) 52 | 53 | class(result) <- "ifr_cochran_qtest" 54 | return(result) 55 | } 56 | 57 | #' @export 58 | #' @rdname ifr_cochran_qtest 59 | #' @usage NULL 60 | #' 61 | infer_cochran_qtest <- function(data, ...) { 62 | .Deprecated("ifr_cochran_qtest()") 63 | } 64 | 65 | #' @export 66 | #' 67 | print.ifr_cochran_qtest <- function(x, ...) { 68 | print_cochran_test(x) 69 | } 70 | 71 | coch_data <- function(x, ...) { 72 | 73 | if (is.data.frame(x)) { 74 | data <- x %>% 75 | lapply(as.numeric) %>% 76 | as.data.frame() %>% 77 | `-`(1) 78 | } else { 79 | data <- cbind(x, ...) %>% 80 | apply(2, as.numeric) %>% 81 | `-`(1) %>% 82 | as.data.frame() 83 | } 84 | 85 | return(data) 86 | } 87 | 88 | cochran_comp <- function(data) { 89 | 90 | n <- nrow(data) 91 | k <- ncol(data) 92 | df <- k - 1 93 | 94 | cs <- 95 | data %>% 96 | lapply(as.numeric) %>% 97 | as.data.frame() %>% 98 | subtract(1) %>% 99 | sums() 100 | 101 | q <- coch(k, cs$cls_sum, cs$cl, cs$g, cs$gs_sum) 102 | 103 | pvalue <- 1 - pchisq(q, df) 104 | 105 | list(df = df, 106 | n = n, 107 | pvalue = round(pvalue, 4), 108 | q = q) 109 | 110 | } 111 | 112 | sums <- function(data) { 113 | 114 | cl <- colSums(data) 115 | cls_sum <- sum(cl ^ 2) 116 | g <- rowSums(data) 117 | gs_sum <- sum(g ^ 2) 118 | 119 | list(cl = cl, 120 | cls_sum = cls_sum, 121 | g = g, 122 | gs_sum = gs_sum) 123 | 124 | } 125 | 126 | coch <- function(k, cls_sum, cl, g, gs_sum) { 127 | ((k - 1) * ((k * cls_sum) - (sum(cl) ^ 2))) / ((k * sum(g)) - gs_sum) 128 | } -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, echo = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "README-" 12 | ) 13 | ``` 14 | 15 | # inferr 16 | 17 | > Tools for Statistical Inference 18 | 19 | 20 | [![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/inferr)](https://cran.r-project.org/package=inferr) [![R-CMD-check](https://github.com/rsquaredacademy/inferr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rsquaredacademy/inferr/actions/workflows/R-CMD-check.yaml) 21 | [![Coverage status](https://app.codecov.io/gh/rsquaredacademy/inferr/branch/master/graph/badge.svg)](https://app.codecov.io/github/rsquaredacademy/inferr?branch=master) 22 | 23 | 24 | ## Overview 25 | 26 | inferr builds upon the statistical tests provided in **stats**, provides additional and flexible input options and more detailed and structured test results. As of version 0.3, **inferr** includes a select set of parametric and non-parametric statistical tests which are listed below: 27 | 28 | - One Sample t Test 29 | - Paired Sample t Test 30 | - Independent Sample t Test 31 | - One Sample Proportion Test 32 | - Two Sample Proportion Test 33 | - One Sample Variance Test 34 | - Two Sample Variance Test 35 | - Binomial Test 36 | - ANOVA 37 | - Chi Square Goodness of Fit Test 38 | - Chi Square Independence Test 39 | - Levene's Test 40 | - Cochran's Q Test 41 | - McNemar Test 42 | - Runs Test for Randomness 43 | 44 | 45 | ## Installation 46 | 47 | ```{r cran-installation, eval = FALSE} 48 | # install inferr from CRAN 49 | install.packages("inferr") 50 | 51 | # the development version from github 52 | # install.packages("devtools") 53 | devtools::install_github("rsquaredacademy/inferr") 54 | ``` 55 | 56 | ## Articles 57 | 58 | - [Introduction to inferr](https://inferr.rsquaredacademy.com/articles/intro.html) 59 | 60 | ## Usage 61 | 62 | #### One Sample t Test 63 | 64 | ```{r load, echo=FALSE, message=FALSE} 65 | library(inferr) 66 | ``` 67 | 68 | ```{r infer1} 69 | ifr_os_t_test(hsb, write, mu = 50, type = 'all') 70 | ``` 71 | 72 | #### ANOVA 73 | 74 | ```{r anova} 75 | ifr_oneway_anova(hsb, write, prog) 76 | ``` 77 | 78 | #### Chi Square Test of Independence 79 | 80 | ```{r chi1} 81 | ifr_chisq_assoc_test(hsb, female, schtyp) 82 | ``` 83 | 84 | #### Levene's Test 85 | 86 | ```{r lev1} 87 | ifr_levene_test(hsb, read, group_var = race) 88 | ``` 89 | 90 | #### Cochran's Q Test 91 | 92 | ```{r cochran} 93 | ifr_cochran_qtest(exam, exam1, exam2, exam3) 94 | ``` 95 | 96 | #### McNemar Test 97 | 98 | ```{r mc1} 99 | hb <- hsb 100 | hb$himath <- ifelse(hsb$math > 60, 1, 0) 101 | hb$hiread <- ifelse(hsb$read > 60, 1, 0) 102 | ifr_mcnemar_test(hb, himath, hiread) 103 | ``` 104 | 105 | ## Getting Help 106 | 107 | If you encounter a bug, please file a minimal reproducible example using 108 | [reprex](https://reprex.tidyverse.org/index.html) on github. For questions and 109 | clarifications, use [StackOverflow](https://stackoverflow.com/). 110 | 111 | ## Code of Conduct 112 | 113 | Please note that the inferr project is released with a [Contributor Code of Conduct](https://inferr.rsquaredacademy.com/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. 114 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • inferr 3 | Skip to contents 4 | 5 | 6 |
    34 |
    35 |
    40 | 41 |
    YEAR: 2016-2017
    42 | COPYRIGHT HOLDER: Aravind Hebbali
    43 | 
    44 | 45 |
    46 | 47 | 48 |
    57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /man/ifr_ts_ind_ttest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ifr-ts-ind-ttest.R 3 | \name{ifr_ts_ind_ttest} 4 | \alias{ifr_ts_ind_ttest} 5 | \alias{infer_ts_ind_ttest} 6 | \title{Two Independent Sample t Test} 7 | \usage{ 8 | ifr_ts_ind_ttest( 9 | data, 10 | x, 11 | y, 12 | confint = 0.95, 13 | alternative = c("both", "less", "greater", "all"), 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{a data frame} 19 | 20 | \item{x}{factor; a column in \code{data}} 21 | 22 | \item{y}{numeric; a column in \code{data}} 23 | 24 | \item{confint}{confidence level} 25 | 26 | \item{alternative}{a character string specifying the alternative hypothesis, 27 | must be one of "both" (default), "greater", "less" or "all". You can specify 28 | just the initial letter} 29 | 30 | \item{...}{additional arguments passed to or from other methods} 31 | } 32 | \value{ 33 | \code{ifr_ts_ind_ttest} returns an object of class \code{"ifr_ts_ind_ttest"}. 34 | An object of class \code{"ifr_ts_ind_ttest"} is a list containing the 35 | following components: 36 | 37 | \item{levels}{levels of \code{x}} 38 | \item{obs}{number of observations of \code{y} for each level of \code{x}} 39 | \item{n}{total number of observations} 40 | \item{mean}{mean of \code{y} for each level of \code{x}} 41 | \item{sd}{standard deviation of \code{y} for each level of \code{x}} 42 | \item{se}{estimate of standard error of \code{y} for each level of \code{x}} 43 | \item{lower}{lower limit for the mean of \code{y} for each level of \code{x}} 44 | \item{upper}{upper limit for the mean of \code{y} for each level of \code{x}} 45 | \item{combined}{a data frame; mean, standard deviation, standard error and 46 | confidence limit of mean of \code{y}} 47 | \item{mean_diff}{difference in mean of \code{y} for the two groups of \code{x}} 48 | \item{se_dif}{estimate of the standard error for difference in mean of 49 | \code{y} for the two groups of \code{x}} \item{sd_dif}{degrees of freedom} 50 | \item{conf_diff}{confidence interval for \code{mean_diff}} 51 | \item{df_pooled}{degrees of freedom for the pooled method} 52 | \item{df_satterthwaite}{degrees of freedom for the Satterthwaite method} 53 | \item{t_pooled}{t statistic for the pooled method} 54 | \item{t_satterthwaite}{t statistic for the Satterthwaite method} 55 | \item{sig_pooled}{two-sided p-value for the pooled method} 56 | \item{sig_pooled_l}{lower one-sided p-value for the pooled method} 57 | \item{sig_pooled_u}{upper one-sided p-value for the pooled method} 58 | \item{sig}{two-sided p-value for the Satterthwaite method} 59 | \item{sig_l}{lower one-sided p-value for the Satterthwaite method} 60 | \item{sig_u}{upper one-sided p-value for the Satterthwaite method} 61 | \item{num_df}{numerator degrees of freedom for folded f test} 62 | \item{den_df}{denominator degrees of freedom for folded f test} 63 | \item{f}{f value for the equality of variances test} 64 | \item{f_sig}{p-value for the folded f test} 65 | \item{var_y}{name of \code{y}} 66 | \item{confint}{confidence level} 67 | \item{alternative}{alternative hypothesis} 68 | } 69 | \description{ 70 | \code{ifr_ts_ind_ttest} compares the means of two independent groups in order to determine whether 71 | there is statistical evidence that the associated population means are significantly different. 72 | } 73 | \section{Deprecated Function}{ 74 | 75 | \code{infer_ts_ind_ttest()} has been deprecated. Instead use \code{ifr_ts_ind_ttest()}. 76 | } 77 | 78 | \examples{ 79 | # lower tail 80 | ifr_ts_ind_ttest(hsb, female, write, alternative = 'less') 81 | 82 | # upper tail 83 | ifr_ts_ind_ttest(hsb, female, write, alternative = 'greater') 84 | 85 | # both tails 86 | ifr_ts_ind_ttest(hsb, female, write, alternative = 'both') 87 | 88 | # all tails 89 | ifr_ts_ind_ttest(hsb, female, write, alternative = 'all') 90 | 91 | } 92 | \references{ 93 | Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 94 | Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 95 | } 96 | \seealso{ 97 | \code{\link[stats]{t.test}} 98 | } 99 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/two-var-test.md: -------------------------------------------------------------------------------- 1 | # output from 2 sample variance test is as expected when alternative is less 2 | 3 | Code 4 | ifr_ts_var_test(hsb, read, write, alternative = "less") 5 | Output 6 | Variance Ratio Test 7 | -------------------------------------------------- 8 | Group Obs Mean Std. Err. Std. Dev. 9 | -------------------------------------------------- 10 | read 200 52.23 0.72 10.25 11 | write 200 52.77 0.67 9.48 12 | -------------------------------------------------- 13 | combined 400 52.5 0.49 9.86 14 | -------------------------------------------------- 15 | 16 | Lower Tail Test 17 | --------------- 18 | ratio = sd(read) / (write) 19 | Ho: ratio = 1 20 | Ha: ratio < 1 21 | 22 | Variance Ratio Test 23 | ------------------------------------ 24 | F Num DF Den DF p 25 | ------------------------------------ 26 | 1.1701 199 199 0.8656 27 | ------------------------------------ 28 | 29 | # output from 2 sample variance test is as expected when alternative is greater 30 | 31 | Code 32 | ifr_ts_var_test(hsb, read, write, alternative = "greater") 33 | Output 34 | Variance Ratio Test 35 | -------------------------------------------------- 36 | Group Obs Mean Std. Err. Std. Dev. 37 | -------------------------------------------------- 38 | read 200 52.23 0.72 10.25 39 | write 200 52.77 0.67 9.48 40 | -------------------------------------------------- 41 | combined 400 52.5 0.49 9.86 42 | -------------------------------------------------- 43 | 44 | Upper Tail Test 45 | --------------- 46 | Ho: ratio = 1 47 | Ha: ratio > 1 48 | 49 | Variance Ratio Test 50 | ------------------------------------ 51 | F Num DF Den DF p 52 | ------------------------------------ 53 | 1.1701 199 199 0.1344 54 | ------------------------------------ 55 | 56 | # output from 2 sample variance test is as expected when alternative is all 57 | 58 | Code 59 | ifr_ts_var_test(hsb, read, write, alternative = "all") 60 | Output 61 | Variance Ratio Test 62 | -------------------------------------------------- 63 | Group Obs Mean Std. Err. Std. Dev. 64 | -------------------------------------------------- 65 | read 200 52.23 0.72 10.25 66 | write 200 52.77 0.67 9.48 67 | -------------------------------------------------- 68 | combined 400 52.5 0.49 9.86 69 | -------------------------------------------------- 70 | 71 | Variance Ratio Test 72 | -------------------------------------------------- 73 | F Num DF Den DF 74 | -------------------------------------------------- 75 | 1.1701 199 199 76 | -------------------------------------------------- 77 | 78 | Null & Alternate Hypothesis 79 | ---------------------------------------- 80 | ratio = sd(read) / (write) 81 | Ho: ratio = 1 82 | 83 | Ha: ratio < 1 Ha: ratio > 1 84 | Pr(F < f) = 0.8656 Pr(F > f) = 0.1344 85 | ---------------------------------------- 86 | 87 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • inferr 3 | Skip to contents 4 | 5 | 6 |
    34 |
    35 |
    39 | 40 |
    41 |

    All vignettes

    42 |
    43 | 44 |
    Introduction to inferr
    45 |
    46 |
    47 |
    48 | 49 | 50 |
    59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • inferr 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 97 | 98 | 99 |
    100 | 101 |
    102 |
    103 | 106 | 107 |
    YEAR: 2016-2017
    108 | COPYRIGHT HOLDER: Aravind Hebbali
    109 | 
    110 | 111 |
    112 | 113 |
    114 | 115 | 116 |
    117 | 120 | 121 |
    122 |

    Site built with pkgdown.

    123 |
    124 | 125 |
    126 |
    127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/deps/headroom-0.11.0/headroom.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * headroom.js v0.11.0 - Give your page some headroom. Hide your header until you need it 3 | * Copyright (c) 2020 Nick Williams - http://wicky.nillia.ms/headroom.js 4 | * License: MIT 5 | */ 6 | 7 | !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).Headroom=n()}(this,function(){"use strict";function t(){return"undefined"!=typeof window}function d(t){return function(t){return t&&t.document&&function(t){return 9===t.nodeType}(t.document)}(t)?function(t){var n=t.document,o=n.body,s=n.documentElement;return{scrollHeight:function(){return Math.max(o.scrollHeight,s.scrollHeight,o.offsetHeight,s.offsetHeight,o.clientHeight,s.clientHeight)},height:function(){return t.innerHeight||s.clientHeight||o.clientHeight},scrollY:function(){return void 0!==t.pageYOffset?t.pageYOffset:(s||o.parentNode||o).scrollTop}}}(t):function(t){return{scrollHeight:function(){return Math.max(t.scrollHeight,t.offsetHeight,t.clientHeight)},height:function(){return Math.max(t.offsetHeight,t.clientHeight)},scrollY:function(){return t.scrollTop}}}(t)}function n(t,s,e){var n,o=function(){var n=!1;try{var t={get passive(){n=!0}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){n=!1}return n}(),i=!1,r=d(t),l=r.scrollY(),a={};function c(){var t=Math.round(r.scrollY()),n=r.height(),o=r.scrollHeight();a.scrollY=t,a.lastScrollY=l,a.direction=ls.tolerance[a.direction],e(a),l=t,i=!1}function h(){i||(i=!0,n=requestAnimationFrame(c))}var u=!!o&&{passive:!0,capture:!1};return t.addEventListener("scroll",h,u),c(),{destroy:function(){cancelAnimationFrame(n),t.removeEventListener("scroll",h,u)}}}function o(t,n){n=n||{},Object.assign(this,o.options,n),this.classes=Object.assign({},o.options.classes,n.classes),this.elem=t,this.tolerance=function(t){return t===Object(t)?t:{down:t,up:t}}(this.tolerance),this.initialised=!1,this.frozen=!1}return o.prototype={constructor:o,init:function(){return o.cutsTheMustard&&!this.initialised&&(this.addClass("initial"),this.initialised=!0,setTimeout(function(t){t.scrollTracker=n(t.scroller,{offset:t.offset,tolerance:t.tolerance},t.update.bind(t))},100,this)),this},destroy:function(){this.initialised=!1,Object.keys(this.classes).forEach(this.removeClass,this),this.scrollTracker.destroy()},unpin:function(){!this.hasClass("pinned")&&this.hasClass("unpinned")||(this.addClass("unpinned"),this.removeClass("pinned"),this.onUnpin&&this.onUnpin.call(this))},pin:function(){this.hasClass("unpinned")&&(this.addClass("pinned"),this.removeClass("unpinned"),this.onPin&&this.onPin.call(this))},freeze:function(){this.frozen=!0,this.addClass("frozen")},unfreeze:function(){this.frozen=!1,this.removeClass("frozen")},top:function(){this.hasClass("top")||(this.addClass("top"),this.removeClass("notTop"),this.onTop&&this.onTop.call(this))},notTop:function(){this.hasClass("notTop")||(this.addClass("notTop"),this.removeClass("top"),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){this.hasClass("bottom")||(this.addClass("bottom"),this.removeClass("notBottom"),this.onBottom&&this.onBottom.call(this))},notBottom:function(){this.hasClass("notBottom")||(this.addClass("notBottom"),this.removeClass("bottom"),this.onNotBottom&&this.onNotBottom.call(this))},shouldUnpin:function(t){return"down"===t.direction&&!t.top&&t.toleranceExceeded},shouldPin:function(t){return"up"===t.direction&&t.toleranceExceeded||t.top},addClass:function(t){this.elem.classList.add.apply(this.elem.classList,this.classes[t].split(" "))},removeClass:function(t){this.elem.classList.remove.apply(this.elem.classList,this.classes[t].split(" "))},hasClass:function(t){return this.classes[t].split(" ").every(function(t){return this.classList.contains(t)},this.elem)},update:function(t){t.isOutOfBounds||!0!==this.frozen&&(t.top?this.top():this.notTop(),t.bottom?this.bottom():this.notBottom(),this.shouldUnpin(t)?this.unpin():this.shouldPin(t)&&this.pin())}},o.options={tolerance:{up:0,down:0},offset:0,scroller:t()?window:null,classes:{frozen:"headroom--frozen",pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},o.cutsTheMustard=!!(t()&&function(){}.bind&&"classList"in document.documentElement&&Object.assign&&Object.keys&&requestAnimationFrame),o}); -------------------------------------------------------------------------------- /R/ifr-chisq-gof-test.R: -------------------------------------------------------------------------------- 1 | #' @title Chi Square Goodness of Fit Test 2 | #' @description Test whether the observed proportions for a categorical variable 3 | #' differ from hypothesized proportions 4 | #' @param data a \code{data.frame} or \code{tibble} 5 | #' @param x factor; column in \code{data} 6 | #' @param y expected proportions 7 | #' @param correct logical; if TRUE continuity correction is applied 8 | #' @return \code{ifr_chisq_gof_test} returns an object of class 9 | #' \code{"ifr_chisq_gof_test"}. An object of class \code{"ifr_chisq_gof_test"} 10 | #' is a list containing the following components: 11 | #' 12 | #' \item{categories}{levels of \code{x}} 13 | #' \item{chisquare}{chi square statistic} 14 | #' \item{deviation}{deviation of observed from frequency} 15 | #' \item{degrees_of_freedom}{chi square degrees of freedom} 16 | #' \item{expected_frequency}{expected frequency/proportion} 17 | #' \item{n_levels}{number of levels of \code{x}} 18 | #' \item{observed_frequency}{observed frequency/proportion} 19 | #' \item{pvalue}{p-value} 20 | #' \item{sample_size}{number of observations} 21 | #' \item{std_residuals}{standardized residuals} 22 | #' \item{varname}{name of categorical variable} 23 | #' 24 | #' @section Deprecated Function: 25 | #' \code{infer_chisq_gof_test()} has been deprecated. Instead use 26 | #' \code{ifr_chisq_gof_test()} 27 | #' 28 | #' @references Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 29 | #' Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 30 | #' 31 | #' @examples 32 | #' ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140)) 33 | #' 34 | #' # apply continuity correction 35 | #' ifr_chisq_gof_test(hsb, race, c(20, 20, 20, 140), correct = TRUE) 36 | #' 37 | #' @seealso \code{\link[stats]{chisq.test}} 38 | #' 39 | #' @export 40 | #' 41 | ifr_chisq_gof_test <- function(data, x, y, correct = FALSE) UseMethod("ifr_chisq_gof_test") 42 | 43 | #' @export 44 | ifr_chisq_gof_test.default <- function(data, x, y, correct = FALSE) { 45 | 46 | x1 <- deparse(substitute(x)) 47 | xcheck <- data[[x1]] 48 | xlen <- length(data[[x1]]) 49 | xone <- as.vector(table(data[[x1]])) 50 | 51 | if (!is.factor(xcheck)) { 52 | stop("x must be an object of class factor", call. = FALSE) 53 | } 54 | 55 | if (!is.numeric(y)) { 56 | stop("y must be numeric", call. = FALSE) 57 | } 58 | 59 | if (!is.logical(correct)) { 60 | stop("correct must be either TRUE or FALSE", call. = FALSE) 61 | } 62 | 63 | varname <- names(data[x1]) 64 | n <- length(xone) 65 | df <- n - 1 66 | 67 | if (length(y) != n) { 68 | stop("Length of y must be equal to the number of categories in x", 69 | call. = FALSE) 70 | } 71 | 72 | if (sum(y) == 1) { 73 | y <- xlen * y 74 | } 75 | 76 | if ((df == 1) || (correct == TRUE)) { 77 | k <- chi_cort(xone, y) 78 | } else { 79 | k <- chigof(xone, y) 80 | } 81 | 82 | sig <- round(pchisq(k$chi, df, lower.tail = FALSE), 4) 83 | 84 | result <- 85 | list( 86 | categories = levels(xcheck), 87 | chisquare = k$chi, 88 | deviation = format(k$dev, nsmall = 2), 89 | degrees_of_freedom = df, 90 | expected_frequency = y, 91 | n_levels = nlevels(xcheck), 92 | observed_frequency = xone, 93 | pvalue = sig, 94 | sample_size = length(xcheck), 95 | std_residuals = format(k$std, nsmall = 2), 96 | varname = varname 97 | ) 98 | 99 | class(result) <- "ifr_chisq_gof_test" 100 | return(result) 101 | } 102 | 103 | #' @export 104 | #' @rdname ifr_chisq_gof_test 105 | #' @usage NULL 106 | #' 107 | infer_chisq_gof_test <- function(data, x, y, correct = FALSE) { 108 | .Deprecated("ifr_chisq_gof_test()") 109 | } 110 | 111 | #' @export 112 | print.ifr_chisq_gof_test <- function(x, ...) { 113 | print_chisq_gof(x) 114 | } 115 | 116 | chi_cort <- function(x, y) { 117 | 118 | diff <- x - y - 0.5 119 | dif <- abs(x - y) - 0.5 120 | dif2 <- dif ^ 2 121 | dev <- round((diff / y) * 100, 2) 122 | std <- round(diff / sqrt(y), 2) 123 | chi <- round(sum(dif2 / y), 4) 124 | 125 | list(dev = dev, 126 | std = std, 127 | chi = chi) 128 | } 129 | 130 | chigof <- function(x, y) { 131 | 132 | dif <- x - y 133 | dif2 <- dif ^ 2 134 | dev <- round((dif / y) * 100, 2) 135 | std <- round(dif / sqrt(y), 2) 136 | chi <- round(sum(dif2 / y), 4) 137 | 138 | list(dev = dev, 139 | std = std, 140 | chi = chi) 141 | } 142 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • inferr 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Skip to contents 17 | 18 | 19 |
    55 |
    56 |
    61 | 62 | Content not found. Please use links in the navbar. 63 | 64 |
    65 |
    66 | 67 | 68 | 77 |
    78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/os-vartest.md: -------------------------------------------------------------------------------- 1 | # output from one sample variance test is as expected when alternative is less 2 | 3 | Code 4 | ifr_os_var_test(mtcars, mpg, 5, alternative = "less") 5 | Output 6 | One-Sample Statistics 7 | ----------------------------------------------------------------------------- 8 | Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] 9 | ----------------------------------------------------------------------------- 10 | mpg 32 20.0906 1.0654 6.0269 3.8737 10.6527 11 | ----------------------------------------------------------------------------- 12 | 13 | Lower Tail Test 14 | --------------- 15 | Ho: sd(mpg) >= 5 16 | Ha: sd(mpg) < 5 17 | 18 | Chi-Square Test for Variance 19 | ------------------------------------- 20 | Variable c DF Sig 21 | ------------------------------------- 22 | mpg 45.042 31 0.9506 23 | ------------------------------------- 24 | 25 | # output from one sample variance test is as expected when alternative is greater 26 | 27 | Code 28 | ifr_os_var_test(mtcars, mpg, 5, alternative = "greater") 29 | Output 30 | One-Sample Statistics 31 | ----------------------------------------------------------------------------- 32 | Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] 33 | ----------------------------------------------------------------------------- 34 | mpg 32 20.0906 1.0654 6.0269 3.8737 10.6527 35 | ----------------------------------------------------------------------------- 36 | 37 | Upper Tail Test 38 | --------------- 39 | Ho: sd(mpg) <= 5 40 | Ha: sd(mpg) > 5 41 | 42 | Chi-Square Test for Variance 43 | ------------------------------------- 44 | Variable c DF Sig 45 | ------------------------------------- 46 | mpg 45.042 31 0.0494 47 | ------------------------------------- 48 | 49 | # output from one sample variance test is as expected when alternative is both 50 | 51 | Code 52 | ifr_os_var_test(mtcars, mpg, 5, alternative = "both") 53 | Output 54 | One-Sample Statistics 55 | ----------------------------------------------------------------------------- 56 | Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] 57 | ----------------------------------------------------------------------------- 58 | mpg 32 20.0906 1.0654 6.0269 3.8737 10.6527 59 | ----------------------------------------------------------------------------- 60 | 61 | Two Tail Test 62 | --------------- 63 | Ho: sd(mpg) = 5 64 | Ha: sd(mpg) != 5 65 | 66 | Chi-Square Test for Variance 67 | ------------------------------------- 68 | Variable c DF Sig 69 | ------------------------------------- 70 | mpg 45.042 31 0.0988 71 | ------------------------------------- 72 | 73 | # output from one sample variance test is as expected when alternative is all 74 | 75 | Code 76 | ifr_os_var_test(mtcars, mpg, 5, alternative = "all") 77 | Output 78 | One-Sample Statistics 79 | ----------------------------------------------------------------------------- 80 | Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] 81 | ----------------------------------------------------------------------------- 82 | mpg 32 20.0906 1.0654 6.0269 3.8737 10.6527 83 | ----------------------------------------------------------------------------- 84 | 85 | Ho: sd(mpg) = 5 86 | 87 | Ha: sd < 5 Ha: sd != 5 Ha: sd > 5 88 | c = 45.0419 c = 45.0419 c = 45.0419 89 | Pr(C < c) = 0.9506 2 * Pr(C > c) = 0.0988 Pr(C > c) = 0.0494 90 | 91 | -------------------------------------------------------------------------------- /tests/testthat/test-two-prop-test.R: -------------------------------------------------------------------------------- 1 | mtcarz <- mtcars 2 | mtcarz$vs <- as.factor(mtcarz$vs) 3 | mtcarz$am <- as.factor(mtcarz$am) 4 | 5 | test_that("output from ifr_ts_prop_test matches the expected result", { 6 | k <- ifr_ts_prop_test(mtcarz, am, vs, alternative = "less") 7 | expect_equal(k$n1, 32) 8 | expect_equal(k$n2, 32) 9 | expect_equal(k$phat1, 0.4062) 10 | expect_equal(k$phat2, 0.4375) 11 | expect_equal(round(k$z, 3), -0.254) 12 | expect_equal(round(k$sig, 3), 0.4) 13 | expect_equal(k$alt, "less") 14 | }) 15 | 16 | 17 | test_that("output from ifr_ts_prop_test matches the expected result", { 18 | k <- ifr_ts_prop_test( 19 | mtcarz, am, vs, 20 | alternative = "greater" 21 | ) 22 | expect_equal(round(k$sig, 3), 0.6) 23 | expect_equal(k$alt, "greater") 24 | }) 25 | 26 | 27 | test_that("output from ifr_ts_prop_test matches the expected result", { 28 | k <- ifr_ts_prop_test( 29 | mtcarz, am, vs, 30 | alternative = "both" 31 | ) 32 | expect_equal(round(k$sig, 3), 0.8) 33 | expect_equal(k$alt, "both") 34 | }) 35 | 36 | test_that("output from ifr_ts_prop_test matches the expected result", { 37 | k <- ifr_ts_prop_test( 38 | mtcarz, am, vs, 39 | alternative = "all" 40 | ) 41 | expect_equal(unname(round(k$sig, 3)), c(0.8, 0.4, 0.6)) 42 | expect_equal(k$alt, "all") 43 | }) 44 | 45 | 46 | test_that("output from ifr_ts_prop_test matches the expected result", { 47 | k <- ifr_ts_prop_group(mtcarz, am, vs, alternative = "less") 48 | expect_equal(k$n1, 18) 49 | expect_equal(k$n2, 14) 50 | expect_equal(round(k$phat1, 3), 0.333) 51 | expect_equal(k$phat2, 0.5) 52 | expect_equal(round(k$z, 3), -0.952) 53 | expect_equal(round(k$sig, 3), 0.17) 54 | expect_equal(k$alt, "less") 55 | }) 56 | 57 | test_that("output from ifr_ts_prop_test matches the expected result", { 58 | k <- ifr_ts_prop_group( 59 | mtcarz, am, vs, 60 | alternative = "greater" 61 | ) 62 | expect_equal(round(k$sig, 3), 0.83) 63 | expect_equal(k$alt, "greater") 64 | }) 65 | 66 | test_that("output from ifr_ts_prop_test matches the expected result", { 67 | k <- ifr_ts_prop_group( 68 | mtcarz, am, vs, 69 | alternative = "both" 70 | ) 71 | expect_equal(round(k$sig, 3), 0.341) 72 | expect_equal(k$alt, "both") 73 | }) 74 | 75 | test_that("output from ifr_ts_prop_test matches the expected result", { 76 | k <- ifr_ts_prop_group( 77 | mtcarz, am, vs, 78 | alternative = "all" 79 | ) 80 | expect_equal(unname(round(k$sig, 3)), c(0.341, 0.17, 0.83)) 81 | expect_equal(k$alt, "all") 82 | }) 83 | 84 | test_that("output from ifr_ts_prop_test matches the expected result", { 85 | k <- ifr_ts_prop_calc( 86 | n1 = 30, n2 = 25, p1 = 0.3, p2 = 0.5, 87 | alternative = "less" 88 | ) 89 | expect_equal(k$n1, 30) 90 | expect_equal(k$n2, 25) 91 | expect_equal(round(k$phat1, 3), 0.3) 92 | expect_equal(k$phat2, 0.5) 93 | expect_equal(round(k$z, 3), -1.514) 94 | expect_equal(round(k$sig, 3), 0.065) 95 | expect_equal(k$alt, "less") 96 | }) 97 | 98 | test_that("output from ifr_ts_prop_test matches the expected result", { 99 | k <- ifr_ts_prop_calc( 100 | n1 = 30, n2 = 25, p1 = 0.3, p2 = 0.5, 101 | alternative = "greater" 102 | ) 103 | expect_equal(round(k$sig, 3), 0.935) 104 | expect_equal(k$alt, "greater") 105 | }) 106 | 107 | test_that("output from ifr_ts_prop_test matches the expected result", { 108 | k <- ifr_ts_prop_calc( 109 | n1 = 30, n2 = 25, p1 = 0.3, p2 = 0.5, 110 | alternative = "both" 111 | ) 112 | expect_equal(round(k$sig, 3), 0.13) 113 | expect_equal(k$alt, "both") 114 | }) 115 | 116 | 117 | test_that("output from ifr_ts_prop_test matches the expected result", { 118 | k <- ifr_ts_prop_calc( 119 | n1 = 30, n2 = 25, p1 = 0.3, p2 = 0.5, 120 | alternative = "all" 121 | ) 122 | expect_equal(unname(round(k$sig, 3)), c(0.13, 0.065, 0.935)) 123 | expect_equal(k$alt, "all") 124 | }) 125 | 126 | test_that("output from 2 sample proportion test is as expected when alternative is less", { 127 | expect_snapshot(ifr_ts_prop_group(treatment2, outcome, female, alternative = "less")) 128 | }) 129 | 130 | test_that("output from 2 sample proportion test is as expected when alternative is greater", { 131 | expect_snapshot(ifr_ts_prop_group(treatment2, outcome, female, alternative = "greater")) 132 | }) 133 | 134 | test_that("output from 2 sample proportion test is as expected when alternative is both", { 135 | expect_snapshot(ifr_ts_prop_group(treatment2, outcome, female, alternative = "both")) 136 | }) 137 | 138 | test_that("output from 2 sample proportion test is as expected when alternative is all", { 139 | expect_snapshot(ifr_ts_prop_group(treatment2, outcome, female, alternative = "all")) 140 | }) 141 | -------------------------------------------------------------------------------- /docs/articles/reference-media.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Media • inferr 9 | 10 | 11 | 12 | 16 | 17 | 18 |
    19 |
    78 | 79 | 80 | 81 |
    82 |
    83 | 87 | 88 | 89 | 90 |
    91 |
    92 |

    93 | Shiny App Demo

    94 | 97 |
    98 |
    99 |
    100 | 101 | 109 | 110 |
    111 | 112 | 113 |
    116 | 117 |
    118 |

    Site built with pkgdown.

    119 |
    120 | 121 |
    122 |
    123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | https://inferr.rsquaredacademy.com/404.html 3 | https://inferr.rsquaredacademy.com/articles/index.html 4 | https://inferr.rsquaredacademy.com/articles/intro.html 5 | https://inferr.rsquaredacademy.com/articles/reference-media.html 6 | https://inferr.rsquaredacademy.com/articles/shiny-demo.html 7 | https://inferr.rsquaredacademy.com/authors.html 8 | https://inferr.rsquaredacademy.com/CODE_OF_CONDUCT.html 9 | https://inferr.rsquaredacademy.com/CONDUCT.html 10 | https://inferr.rsquaredacademy.com/google02e424888b5e2def.html 11 | https://inferr.rsquaredacademy.com/index.html 12 | https://inferr.rsquaredacademy.com/ISSUE_TEMPLATE.html 13 | https://inferr.rsquaredacademy.com/LICENSE-text.html 14 | https://inferr.rsquaredacademy.com/LICENSE.html 15 | https://inferr.rsquaredacademy.com/news/index.html 16 | https://inferr.rsquaredacademy.com/reference/binom_calc.html 17 | https://inferr.rsquaredacademy.com/reference/binom_test.html 18 | https://inferr.rsquaredacademy.com/reference/chisq_gof.html 19 | https://inferr.rsquaredacademy.com/reference/chisq_test.html 20 | https://inferr.rsquaredacademy.com/reference/cochran_test.html 21 | https://inferr.rsquaredacademy.com/reference/exam.html 22 | https://inferr.rsquaredacademy.com/reference/hsb.html 23 | https://inferr.rsquaredacademy.com/reference/ifr_binom_calc.html 24 | https://inferr.rsquaredacademy.com/reference/ifr_chisq_assoc_test.html 25 | https://inferr.rsquaredacademy.com/reference/ifr_chisq_gof_test.html 26 | https://inferr.rsquaredacademy.com/reference/ifr_cochran_qtest.html 27 | https://inferr.rsquaredacademy.com/reference/ifr_launch_shiny_app.html 28 | https://inferr.rsquaredacademy.com/reference/ifr_levene_test.html 29 | https://inferr.rsquaredacademy.com/reference/ifr_mcnemar_test.html 30 | https://inferr.rsquaredacademy.com/reference/ifr_oneway_anova.html 31 | https://inferr.rsquaredacademy.com/reference/ifr_os_prop_test.html 32 | https://inferr.rsquaredacademy.com/reference/ifr_os_t_test.html 33 | https://inferr.rsquaredacademy.com/reference/ifr_os_var_test.html 34 | https://inferr.rsquaredacademy.com/reference/ifr_runs_test.html 35 | https://inferr.rsquaredacademy.com/reference/ifr_ts_ind_ttest.html 36 | https://inferr.rsquaredacademy.com/reference/ifr_ts_paired_ttest.html 37 | https://inferr.rsquaredacademy.com/reference/ifr_ts_prop_test.html 38 | https://inferr.rsquaredacademy.com/reference/ifr_ts_var_test.html 39 | https://inferr.rsquaredacademy.com/reference/index.html 40 | https://inferr.rsquaredacademy.com/reference/ind_ttest.html 41 | https://inferr.rsquaredacademy.com/reference/inferr.html 42 | https://inferr.rsquaredacademy.com/reference/launch_inferr.html 43 | https://inferr.rsquaredacademy.com/reference/levene_test.html 44 | https://inferr.rsquaredacademy.com/reference/mcnemar_test.html 45 | https://inferr.rsquaredacademy.com/reference/os_chisqgof.html 46 | https://inferr.rsquaredacademy.com/reference/os_vartest.html 47 | https://inferr.rsquaredacademy.com/reference/owanova.html 48 | https://inferr.rsquaredacademy.com/reference/paired_ttest.html 49 | https://inferr.rsquaredacademy.com/reference/prop_test.html 50 | https://inferr.rsquaredacademy.com/reference/runs_test.html 51 | https://inferr.rsquaredacademy.com/reference/treatment.html 52 | https://inferr.rsquaredacademy.com/reference/treatment2.html 53 | https://inferr.rsquaredacademy.com/reference/ts_prop_test.html 54 | https://inferr.rsquaredacademy.com/reference/ttest.html 55 | https://inferr.rsquaredacademy.com/reference/two_sample_test.html 56 | https://inferr.rsquaredacademy.com/reference/var_test.html 57 | https://inferr.rsquaredacademy.com/reference/var_test_shiny.html 58 | https://inferr.rsquaredacademy.com/SUPPORT.html 59 | 60 | 61 | -------------------------------------------------------------------------------- /R/ifr-os-prop-test.R: -------------------------------------------------------------------------------- 1 | #' @title One Sample Test of Proportion 2 | #' @description \code{ifr_os_prop_test} compares proportion in one group to a 3 | #' specified population proportion. 4 | #' @param data numeric vector of length 1 or a \code{data.frame} or \code{tibble} 5 | #' @param variable factor; column in \code{data} 6 | #' @param prob hypothesised proportion 7 | #' @param phat observed proportion 8 | #' @param alternative a character string specifying the alternative hypothesis, 9 | #' must be one of "both" (default), "greater", "less" or "all". You can specify 10 | #' just the initial letter. 11 | #' 12 | #' @return \code{ifr_os_prop_test} returns an object of class \code{"ifr_os_prop_test"}. 13 | #' An object of class \code{"ifr_os_prop_test"} is a list containing the 14 | #' following components: 15 | #' 16 | #' \item{n}{number of observations} 17 | #' \item{phat}{proportion of 1's} 18 | #' \item{p}{assumed probability of success} 19 | #' \item{z}{z statistic} 20 | #' \item{sig}{p-value for z statistic} 21 | #' \item{alt}{alternative hypothesis} 22 | #' \item{obs}{observed number of 0's and 1's} 23 | #' \item{exp}{expected number of 0's and 1's} 24 | #' \item{deviation}{deviation of observed from expected} 25 | #' \item{std}{standardized resiudals} 26 | #' 27 | #' @section Deprecated Function: 28 | #' \code{infer_os_prop_test()} has been deprecated. Instead use \code{ifr_os_prop_test()}. 29 | #' 30 | #' @references Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric 31 | #' Statistical Procedures, 4th edition. : Chapman & Hall/CRC. 32 | #' 33 | #' @examples 34 | #' # use as a calculator 35 | #' ifr_os_prop_test(200, prob = 0.5, phat = 0.3) 36 | #' 37 | #' # using data set 38 | #' ifr_os_prop_test(hsb, female, prob = 0.5) 39 | #' 40 | #' @seealso \code{\link[stats]{prop.test}} \code{\link[stats]{binom.test}} 41 | #' 42 | #' @export 43 | #' 44 | ifr_os_prop_test <- function(data, variable = NULL, prob = 0.5, phat = 0.5, 45 | alternative = c("both", "less", "greater", "all")) 46 | UseMethod("ifr_os_prop_test") 47 | 48 | #' @export 49 | #' @rdname ifr_os_prop_test 50 | #' 51 | ifr_os_prop_test.default <- function(data, variable = NULL, prob = 0.5, phat = 0.5, 52 | alternative = c("both", "less", "greater", "all")) { 53 | if (is.numeric(data)) { 54 | 55 | method <- match.arg(alternative) 56 | k <- prop_comp(data, prob = prob, phat = phat, alternative = method) 57 | 58 | } else { 59 | 60 | varyables <- deparse(substitute(variable)) 61 | fdata <- data[[varyables]] 62 | n1 <- length(fdata) 63 | n2 <- table(fdata)[[2]] 64 | phat <- round(n2 / n1, 4) 65 | prob <- prob 66 | method <- match.arg(alternative) 67 | k <- prop_comp(n1, prob = prob, phat = phat, alternative = method) 68 | } 69 | 70 | result <- 71 | list(alt = k$alt, 72 | deviation = k$deviation, 73 | exp = k$exp, 74 | n = k$n, 75 | obs = k$obs, 76 | p = k$p, 77 | phat = k$phat, 78 | sig = k$sig, 79 | std = k$std, 80 | z = k$z) 81 | 82 | class(result) <- "ifr_os_prop_test" 83 | return(result) 84 | } 85 | 86 | #' @export 87 | #' @rdname ifr_os_prop_test 88 | #' @usage NULL 89 | #' 90 | infer_os_prop_test <- function(data, variable = NULL, prob = 0.5, phat = 0.5, 91 | alternative = c("both", "less", "greater", "all")) { 92 | .Deprecated("ifr_os_prop_test()") 93 | } 94 | 95 | #' @export 96 | #' 97 | print.ifr_os_prop_test <- function(x, ...) { 98 | print_prop_test(x) 99 | } 100 | 101 | #' @importFrom stats pnorm 102 | prop_comp <- function(n, prob, alternative, phat) { 103 | 104 | n <- n 105 | phat <- phat 106 | p <- prob 107 | q <- 1 - p 108 | obs <- c(n * (1 - phat), n * phat) 109 | exp <- n * c(q, p) 110 | dif <- obs - exp 111 | dev <- round((dif / exp) * 100, 2) 112 | std <- round(dif / sqrt(exp), 2) 113 | num <- phat - prob 114 | den <- sqrt((p * q) / n) 115 | z <- round(num / den, 4) 116 | lt <- round(pnorm(z), 4) 117 | ut <- round(1 - pnorm(z), 4) 118 | tt <- round((1 - pnorm(abs(z))) * 2, 4) 119 | alt <- alternative 120 | 121 | if (alt == "all") { 122 | sig <- c("two-both" = tt, "less" = lt, "greater" = ut) 123 | } else if (alt == "greater") { 124 | sig <- ut 125 | } else if (alt == "less") { 126 | sig <- lt 127 | } else { 128 | sig <- tt 129 | } 130 | 131 | out <- 132 | list(alt = alt, 133 | deviation = format(dev, nsmall = 2), 134 | exp = exp, 135 | n = n, 136 | obs = obs, 137 | p = prob, 138 | phat = phat, 139 | sig = sig, 140 | std = format(std, nsmall = 2), 141 | z = z) 142 | 143 | return(out) 144 | } 145 | -------------------------------------------------------------------------------- /R/ifr-anova.R: -------------------------------------------------------------------------------- 1 | #' @title One Way ANOVA 2 | #' @description One way analysis of variance 3 | #' @param data a \code{data.frame} or a \code{tibble} 4 | #' @param x numeric; column in \code{data} 5 | #' @param y factor; column in \code{data} 6 | #' @param ... additional arguments passed to or from other methods 7 | #' @return \code{ifr_oneway_anova} returns an object of class \code{"ifr_oneway_anova"}. 8 | #' An object of class \code{"ifr_oneway_anova"} is a list containing the 9 | #' following components: 10 | #' 11 | #' \item{adjusted_r2}{adjusted r squared value} 12 | #' \item{df_btw}{between groups degress of freedom} 13 | #' \item{df_within}{within groups degress of freedom} 14 | #' \item{df_total}{total degress of freedom} 15 | #' \item{fstat}{f value} 16 | #' \item{group_stats}{group statistics} 17 | #' \item{ms_btw}{between groups mean square} 18 | #' \item{ms_within}{within groups mean square} 19 | #' \item{obs}{number of observations} 20 | #' \item{pval}{p value} 21 | #' \item{r2}{r squared value} 22 | #' \item{rmse}{root mean squared error} 23 | #' \item{ss_between}{between group sum of squares} 24 | #' \item{ss_within}{within group sum of squares} 25 | #' \item{ss_total}{total sum of squares} 26 | #' 27 | #' @section Deprecated Function: 28 | #' \code{infer_oneway_anova()} has been deprecated. Instead use 29 | #' \code{ifr_oneway_anova()} 30 | #' 31 | #' @references Kutner, M. H., Nachtsheim, C., Neter, J., & Li, W. (2005). 32 | #' Applied linear statistical models. Boston: McGraw-Hill Irwin. 33 | #' 34 | #' @examples 35 | #' ifr_oneway_anova(mtcars, mpg, cyl) 36 | #' ifr_oneway_anova(hsb, write, prog) 37 | #' 38 | #' @seealso \code{\link[stats]{anova}} 39 | #' 40 | #' @export 41 | #' 42 | ifr_oneway_anova <- function(data, x, y, ...) UseMethod("ifr_oneway_anova") 43 | 44 | #' @export 45 | ifr_oneway_anova.default <- function(data, x, y, ...) { 46 | 47 | x1 <- deparse(substitute(x)) 48 | y1 <- deparse(substitute(y)) 49 | 50 | fdata <- data[c(x1, y1)] 51 | sample_mean <- anova_avg(fdata, x1) 52 | sample_stats <- anova_split(fdata, x1, y1, sample_mean) 53 | k <- anova_calc(fdata, sample_stats, x1, y1) 54 | 55 | result <- 56 | list( 57 | adjusted_r2 = round(k$reg$adj.r.squared, 4), 58 | df_btw = k$df_sstr, 59 | df_total = k$df_sst, 60 | df_within = k$df_sse, 61 | fstat = k$f, 62 | group_stats = sample_stats[, c(1, 2, 3, 5)], 63 | ms_btw = k$mstr, 64 | ms_within = k$mse, 65 | obs = k$obs, 66 | pval = k$sig, 67 | r2 = round(k$reg$r.squared, 4), 68 | rmse = round(k$reg$sigma, 4), 69 | ss_between = k$sstr, 70 | ss_total = k$total, 71 | ss_within = k$ssee) 72 | 73 | class(result) <- "ifr_oneway_anova" 74 | return(result) 75 | } 76 | 77 | #' @export 78 | #' @rdname ifr_oneway_anova 79 | #' @usage NULL 80 | #' 81 | infer_oneway_anova <- function(data, x, y, ...) { 82 | .Deprecated("ifr_oneway_anova()") 83 | } 84 | 85 | #' @export 86 | print.ifr_oneway_anova <- function(x, ...) { 87 | print_owanova(x) 88 | } 89 | 90 | #' @import magrittr 91 | #' @importFrom stats var sd 92 | #' @importFrom data.table data.table := setDF 93 | anova_split <- function(data, x, y, sample_mean) { 94 | 95 | dat <- data[c(y, x)] 96 | dm <- data.table(dat) 97 | 98 | by_factor <- dm[, .(length = length(get(x)), 99 | mean = mean(get(x)), 100 | var = var(get(x)), 101 | sd = sd(get(x))), 102 | by = y] 103 | 104 | by_factor[, ':='(sst = length * ((mean - sample_mean) ^ 2), 105 | sse = (length - 1) * var)] 106 | 107 | setDF(by_factor) 108 | by_factor <- by_factor[order(by_factor[, 1]),] 109 | 110 | return(by_factor) 111 | } 112 | 113 | anova_avg <- function(data, y) { 114 | 115 | mean(data[[y]]) 116 | 117 | } 118 | 119 | #' @importFrom stats pf as.formula lm 120 | anova_calc <- function(data, sample_stats, x, y) { 121 | 122 | var_names <- names(data[c(x, y)]) 123 | 124 | sample_stats %>% 125 | use_series(sst) %>% 126 | sum() %>% 127 | round(3) -> sstr 128 | 129 | sample_stats %>% 130 | use_series(sse) %>% 131 | sum() %>% 132 | round(3) -> ssee 133 | 134 | total <- round(sstr + ssee, 3) 135 | df_sstr <- nrow(sample_stats) - 1 136 | df_sse <- nrow(data) - nrow(sample_stats) 137 | df_sst <- nrow(data) - 1 138 | mstr <- round(sstr / df_sstr, 3) 139 | mse <- round(ssee / df_sse, 3) 140 | f <- round(mstr / mse, 3) 141 | sig <- round(1 - pf(f, df_sstr, df_sse), 3) 142 | obs <- nrow(data) 143 | regs <- paste(var_names[1], "~ as.factor(", var_names[2], ")") 144 | model <- lm(as.formula(regs), data = data) 145 | reg <- summary(model) 146 | 147 | out <- list( 148 | sstr = sstr, ssee = ssee, total = total, df_sstr = df_sstr, 149 | df_sse = df_sse, df_sst = df_sst, mstr = mstr, mse = mse, f = f, 150 | sig = sig, obs = obs, model = model, reg = reg 151 | ) 152 | 153 | return(out) 154 | } 155 | --------------------------------------------------------------------------------