├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── AUCTest.R ├── BinomTest.R ├── ChiSqTest.R ├── CohenD.R ├── CorTest.R ├── DifferenceDistribution.R ├── DifferenceDistribution2.R ├── EmpiricalFns.R ├── FTest.R ├── FisherTest.R ├── ROC.R ├── TInterval.R ├── TTest.R ├── fns.R ├── model_utility.R ├── pwr.R ├── rexport.R ├── sigr.R ├── toPresentation.R └── wrapr_exports.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── cran-comments.md ├── docs ├── 404.html ├── LICENSE-text.html ├── _config.yml ├── articles │ ├── index.html │ ├── lmExample.html │ ├── lmExample_files │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ ├── sigrFormatting.html │ └── sigrFormatting_files │ │ └── accessible-code-block-0.0.1 │ │ └── empty-anchor.js ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── Bernoulli_diff_stat.html │ ├── Rplot001.png │ ├── TInterval.data.frame.html │ ├── TInterval.html │ ├── TInterval.numeric.html │ ├── TIntervalS.html │ ├── add_ROC_derived_columns.html │ ├── as.character.sigr_statistic.html │ ├── build_ROC_curve.html │ ├── calcAUC.html │ ├── calcDeviance.html │ ├── calcSSE.html │ ├── check_utility_calc.html │ ├── estimateDifferenceZeroCrossing.html │ ├── find_AUC_q.html │ ├── find_ROC_matching_ab.html │ ├── find_ROC_matching_ab1.html │ ├── find_area_q.html │ ├── find_matching_a1_1b.html │ ├── find_matching_conditional_betas.html │ ├── fit_beta_shapes.html │ ├── format.sigr_statistic.html │ ├── getRenderingFormat.html │ ├── index.html │ ├── model_utility-1.png │ ├── model_utility.html │ ├── permTestAUC.html │ ├── permutationScoreModel.html │ ├── print.sigr_statistic.html │ ├── reexports.html │ ├── render.html │ ├── render.sigr_Bernoulli_diff_test.html │ ├── render.sigr_aucpairtest.html │ ├── render.sigr_aucpermtest.html │ ├── render.sigr_aucresamptest.html │ ├── render.sigr_binomtest.html │ ├── render.sigr_chisqtest.html │ ├── render.sigr_cohend.html │ ├── render.sigr_cortest.html │ ├── render.sigr_emptest.html │ ├── render.sigr_fishertest.html │ ├── render.sigr_ftest.html │ ├── render.sigr_permtest.html │ ├── render.sigr_pwr_htest.html │ ├── render.sigr_significance.html │ ├── render.sigr_tinterval.html │ ├── render.sigr_ttest.html │ ├── resampleScoreModel.html │ ├── resampleScoreModelPair.html │ ├── resampleTestAUC.html │ ├── run_sigr_tests.html │ ├── sensitivity_and_specificity_s12p12n.html │ ├── sensitivity_from_specificity_q.html │ ├── sigr-package.html │ ├── sigr.html │ ├── testAUCpair.html │ ├── wrapBinomTest.data.frame.html │ ├── wrapBinomTest.htest.html │ ├── wrapBinomTest.html │ ├── wrapBinomTest.logical.html │ ├── wrapBinomTest.numeric.html │ ├── wrapBinomTestS.html │ ├── wrapChiSqTest.anova.html │ ├── wrapChiSqTest.data.frame.html │ ├── wrapChiSqTest.glm.html │ ├── wrapChiSqTest.html │ ├── wrapChiSqTest.summary.glm.html │ ├── wrapChiSqTestImpl.html │ ├── wrapCohenD.data.frame.html │ ├── wrapCohenD.html │ ├── wrapCohenD.numeric.html │ ├── wrapCorTest.data.frame.html │ ├── wrapCorTest.htest.html │ ├── wrapCorTest.html │ ├── wrapFTest.anova.html │ ├── wrapFTest.data.frame.html │ ├── wrapFTest.htest.html │ ├── wrapFTest.html │ ├── wrapFTest.lm.html │ ├── wrapFTest.summary.lm.html │ ├── wrapFTestImpl.html │ ├── wrapFTestezANOVA.html │ ├── wrapFisherTest.data.frame.html │ ├── wrapFisherTest.htest.html │ ├── wrapFisherTest.html │ ├── wrapFisherTest.table.html │ ├── wrapPWR.html │ ├── wrapPWR.power.htest.html │ ├── wrapSignificance.html │ ├── wrapTTest.data.frame.html │ ├── wrapTTest.htest.html │ ├── wrapTTest.html │ └── wrapTTest.numeric.html └── sitemap.xml ├── extras ├── BiasEsts.Rmd ├── BiasEsts.md ├── BiasEstsNormal.Rmd ├── BiasEstsNormal.md ├── BiasEstsNormal_files │ └── figure-markdown_github │ │ ├── unnamed-chunk-1-1.png │ │ └── unnamed-chunk-1-2.png ├── BiasEsts_files │ └── figure-markdown_github │ │ ├── run-1.png │ │ ├── run-10.png │ │ ├── run-11.png │ │ ├── run-12.png │ │ ├── run-13.png │ │ ├── run-14.png │ │ ├── run-15.png │ │ ├── run-16.png │ │ ├── run-17.png │ │ ├── run-18.png │ │ ├── run-19.png │ │ ├── run-2.png │ │ ├── run-20.png │ │ ├── run-21.png │ │ ├── run-22.png │ │ ├── run-23.png │ │ ├── run-24.png │ │ ├── run-3.png │ │ ├── run-4.png │ │ ├── run-5.png │ │ ├── run-6.png │ │ ├── run-7.png │ │ ├── run-8.png │ │ └── run-9.png ├── RateDiffs.Rmd ├── RateDiffs.md ├── UtilityExample.Rmd ├── UtilityExample.md ├── UtilityExample_files │ └── figure-gfm │ │ ├── unnamed-chunk-10-1.png │ │ ├── unnamed-chunk-2-1.png │ │ ├── unnamed-chunk-3-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-7-1.png │ │ └── unnamed-chunk-9-1.png ├── check_reverse_dependencies.Rmd ├── check_reverse_dependencies.md ├── nina_check │ ├── nina_check.Rmd │ └── nina_check.html └── utility_modeling │ ├── ROC_optimization.Rmd │ ├── ROC_optimization.md │ ├── ROC_optimization_files │ └── figure-gfm │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-5-1.png │ │ ├── unnamed-chunk-8-1.png │ │ └── unnamed-chunk-9-1.png │ ├── ROC_utility.ipynb │ ├── Utility_Sampling_Distribution.Rmd │ ├── Utility_Sampling_Distribution.md │ ├── Utility_Sampling_Distribution_files │ └── figure-gfm │ │ ├── unnamed-chunk-1-1.png │ │ ├── unnamed-chunk-1-2.png │ │ ├── unnamed-chunk-10-1.png │ │ ├── unnamed-chunk-11-1.png │ │ ├── unnamed-chunk-4-1.png │ │ └── unnamed-chunk-5-1.png │ └── calculate_utility_graph.R ├── inst └── tinytest │ ├── test_BD.R │ ├── test_T1.R │ └── test_utility_calc.R ├── man ├── Bernoulli_diff_stat.Rd ├── TInterval.Rd ├── TInterval.data.frame.Rd ├── TInterval.numeric.Rd ├── TIntervalS.Rd ├── add_ROC_derived_columns.Rd ├── as.character.sigr_statistic.Rd ├── build_ROC_curve.Rd ├── calcAUC.Rd ├── calcDeviance.Rd ├── calcSSE.Rd ├── check_utility_calc.Rd ├── estimateDifferenceZeroCrossing.Rd ├── find_AUC_q.Rd ├── find_area_q.Rd ├── find_matching_a1_1b.Rd ├── find_matching_conditional_betas.Rd ├── fit_beta_shapes.Rd ├── format.sigr_statistic.Rd ├── getRenderingFormat.Rd ├── model_utility.Rd ├── permTestAUC.Rd ├── permutationScoreModel.Rd ├── print.sigr_statistic.Rd ├── reexports.Rd ├── render.Rd ├── render.sigr_Bernoulli_diff_test.Rd ├── render.sigr_aucpairtest.Rd ├── render.sigr_aucpermtest.Rd ├── render.sigr_aucresamptest.Rd ├── render.sigr_binomtest.Rd ├── render.sigr_chisqtest.Rd ├── render.sigr_cohend.Rd ├── render.sigr_cortest.Rd ├── render.sigr_emptest.Rd ├── render.sigr_fishertest.Rd ├── render.sigr_ftest.Rd ├── render.sigr_permtest.Rd ├── render.sigr_pwr_htest.Rd ├── render.sigr_significance.Rd ├── render.sigr_tinterval.Rd ├── render.sigr_ttest.Rd ├── resampleScoreModel.Rd ├── resampleScoreModelPair.Rd ├── resampleTestAUC.Rd ├── sensitivity_and_specificity_s12p12n.Rd ├── sensitivity_from_specificity_q.Rd ├── sigr-package.Rd ├── testAUCpair.Rd ├── wrapBinomTest.Rd ├── wrapBinomTest.data.frame.Rd ├── wrapBinomTest.htest.Rd ├── wrapBinomTest.logical.Rd ├── wrapBinomTest.numeric.Rd ├── wrapBinomTestS.Rd ├── wrapChiSqTest.Rd ├── wrapChiSqTest.anova.Rd ├── wrapChiSqTest.data.frame.Rd ├── wrapChiSqTest.glm.Rd ├── wrapChiSqTest.summary.glm.Rd ├── wrapChiSqTestImpl.Rd ├── wrapCohenD.Rd ├── wrapCohenD.data.frame.Rd ├── wrapCohenD.numeric.Rd ├── wrapCorTest.Rd ├── wrapCorTest.data.frame.Rd ├── wrapCorTest.htest.Rd ├── wrapFTest.Rd ├── wrapFTest.anova.Rd ├── wrapFTest.data.frame.Rd ├── wrapFTest.htest.Rd ├── wrapFTest.lm.Rd ├── wrapFTest.summary.lm.Rd ├── wrapFTestImpl.Rd ├── wrapFTestezANOVA.Rd ├── wrapFisherTest.Rd ├── wrapFisherTest.data.frame.Rd ├── wrapFisherTest.htest.Rd ├── wrapFisherTest.table.Rd ├── wrapPWR.Rd ├── wrapPWR.power.htest.Rd ├── wrapSignificance.Rd ├── wrapTTest.Rd ├── wrapTTest.data.frame.Rd ├── wrapTTest.htest.Rd └── wrapTTest.numeric.Rd ├── sigr.Rproj ├── tests └── tinytest.R ├── tools └── sigr.png └── vignettes ├── lmExample.Rmd └── sigrFormatting.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^README.Rmd$ 5 | ^cran-comments.md$ 6 | ^sigr.png$ 7 | ^docs$ 8 | ^_pkgdown\.yml$ 9 | ^extras$ 10 | ^revdep$ 11 | ^LICENSE$ 12 | ^CRAN-SUBMISSION$ 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | *~ 7 | .DS_Store 8 | revdep 9 | CRAN-RELEASE 10 | .ipynb_checkpoints 11 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: sigr 2 | Type: Package 3 | Title: Succinct and Correct Statistical Summaries for Reports 4 | Version: 1.1.5 5 | Date: 2023-08-19 6 | Authors@R: c( 7 | person("John", "Mount", email = "jmount@win-vector.com", role = c("aut", "cre")), 8 | person("Nina", "Zumel", email = "nzumel@win-vector.com", role = c("aut")), 9 | person(family = "Win-Vector LLC", role = c("cph")) 10 | ) 11 | URL: https://github.com/WinVector/sigr/, https://winvector.github.io/sigr/ 12 | Maintainer: John Mount 13 | BugReports: https://github.com/WinVector/sigr/issues 14 | Description: Succinctly and correctly format statistical summaries of 15 | various models and tests (F-test, Chi-Sq-test, Fisher-test, T-test, and rank-significance). 16 | This package also includes empirical tests, such as Monte Carlo and bootstrap distribution estimates. 17 | License: GPL-2 | GPL-3 18 | RoxygenNote: 7.2.3 19 | Depends: 20 | R (>= 3.2.1) 21 | Imports: 22 | wrapr (>= 2.0.9), 23 | stats 24 | Suggests: 25 | pwr, 26 | parallel, 27 | knitr, 28 | rmarkdown, 29 | tinytest 30 | VignetteBuilder: knitr 31 | ByteCompile: true 32 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(TInterval,data.frame) 4 | S3method(TInterval,numeric) 5 | S3method(as.character,sigr_statistic) 6 | S3method(format,sigr_statistic) 7 | S3method(print,sigr_statistic) 8 | S3method(render,sigr_Bernoulli_diff_test) 9 | S3method(render,sigr_aucpairtest) 10 | S3method(render,sigr_aucpermtest) 11 | S3method(render,sigr_aucresamptest) 12 | S3method(render,sigr_binomtest) 13 | S3method(render,sigr_chisqtest) 14 | S3method(render,sigr_cohend) 15 | S3method(render,sigr_cortest) 16 | S3method(render,sigr_emptest) 17 | S3method(render,sigr_fishertest) 18 | S3method(render,sigr_ftest) 19 | S3method(render,sigr_permtest) 20 | S3method(render,sigr_pwr_htest) 21 | S3method(render,sigr_significance) 22 | S3method(render,sigr_tinterval) 23 | S3method(render,sigr_ttest) 24 | S3method(wrapBinomTest,data.frame) 25 | S3method(wrapBinomTest,htest) 26 | S3method(wrapBinomTest,logical) 27 | S3method(wrapBinomTest,numeric) 28 | S3method(wrapChiSqTest,anova) 29 | S3method(wrapChiSqTest,data.frame) 30 | S3method(wrapChiSqTest,glm) 31 | S3method(wrapChiSqTest,summary.glm) 32 | S3method(wrapCohenD,data.frame) 33 | S3method(wrapCohenD,numeric) 34 | S3method(wrapCorTest,data.frame) 35 | S3method(wrapCorTest,htest) 36 | S3method(wrapFTest,anova) 37 | S3method(wrapFTest,data.frame) 38 | S3method(wrapFTest,htest) 39 | S3method(wrapFTest,lm) 40 | S3method(wrapFTest,summary.lm) 41 | S3method(wrapFisherTest,data.frame) 42 | S3method(wrapFisherTest,htest) 43 | S3method(wrapFisherTest,table) 44 | S3method(wrapPWR,power.htest) 45 | S3method(wrapTTest,data.frame) 46 | S3method(wrapTTest,htest) 47 | S3method(wrapTTest,numeric) 48 | export("%.>%") 49 | export("%:=%") 50 | export(Bernoulli_diff_stat) 51 | export(TInterval) 52 | export(TIntervalS) 53 | export(add_ROC_derived_columns) 54 | export(apply_left) 55 | export(apply_right) 56 | export(build_ROC_curve) 57 | export(build_frame) 58 | export(calcAUC) 59 | export(calcDeviance) 60 | export(calcSSE) 61 | export(check_utility_calc) 62 | export(draw_frame) 63 | export(estimateDifferenceZeroCrossing) 64 | export(find_AUC_q) 65 | export(find_ROC_matching_ab) 66 | export(find_ROC_matching_ab1) 67 | export(find_area_q) 68 | export(find_matching_a1_1b) 69 | export(find_matching_conditional_betas) 70 | export(fit_beta_shapes) 71 | export(getRenderingFormat) 72 | export(let) 73 | export(map_to_char) 74 | export(mk_tmp_name_source) 75 | export(model_utility) 76 | export(permTestAUC) 77 | export(permutationScoreModel) 78 | export(qae) 79 | export(qc) 80 | export(qchar_frame) 81 | export(qe) 82 | export(render) 83 | export(resampleScoreModel) 84 | export(resampleScoreModelPair) 85 | export(resampleTestAUC) 86 | export(sensitivity_and_specificity_s12p12n) 87 | export(sensitivity_from_specificity_q) 88 | export(testAUCpair) 89 | export(wrapBinomTest) 90 | export(wrapBinomTestS) 91 | export(wrapChiSqTest) 92 | export(wrapChiSqTestImpl) 93 | export(wrapCohenD) 94 | export(wrapCorTest) 95 | export(wrapFTest) 96 | export(wrapFTestImpl) 97 | export(wrapFTestezANOVA) 98 | export(wrapFisherTest) 99 | export(wrapPWR) 100 | export(wrapSignificance) 101 | export(wrapTTest) 102 | importFrom(parallel,parLapplyLB) 103 | importFrom(stats,approxfun) 104 | importFrom(stats,binom.test) 105 | importFrom(stats,convolve) 106 | importFrom(stats,cor.test) 107 | importFrom(stats,dbinom) 108 | importFrom(stats,fisher.test) 109 | importFrom(stats,pbeta) 110 | importFrom(stats,pchisq) 111 | importFrom(stats,pf) 112 | importFrom(stats,pnorm) 113 | importFrom(stats,pt) 114 | importFrom(stats,sd) 115 | importFrom(stats,t.test) 116 | importFrom(stats,var) 117 | importFrom(wrapr,"%.>%") 118 | importFrom(wrapr,"%:=%") 119 | importFrom(wrapr,apply_left) 120 | importFrom(wrapr,apply_right) 121 | importFrom(wrapr,build_frame) 122 | importFrom(wrapr,draw_frame) 123 | importFrom(wrapr,let) 124 | importFrom(wrapr,map_to_char) 125 | importFrom(wrapr,mk_tmp_name_source) 126 | importFrom(wrapr,qae) 127 | importFrom(wrapr,qc) 128 | importFrom(wrapr,qchar_frame) 129 | importFrom(wrapr,qe) 130 | importFrom(wrapr,stop_if_dot_args) 131 | importFrom(wrapr,unpack) 132 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | 2 | # sigr 1.1.5 2023-08-19 3 | 4 | * Work around https://github.com/r-lib/roxygen2/issues/1491 5 | 6 | # sigr 1.1.4 2021-06-11 7 | 8 | * Remove LazyData decl. 9 | 10 | # sigr 1.1.3 2020-10-16 11 | 12 | * Better fitting function names. 13 | * Improve package description. 14 | * Move to tinytest. 15 | 16 | # sigr 1.1.2 2020-10-01 17 | 18 | * Add model_utility. 19 | * Remove unused params from ftest-wrapper. 20 | * Add htest adatper for ftest-wrapper. 21 | 22 | # sigr 1.1.1 2020-09-22 23 | 24 | * Fix parens in AUC area matching formula! 25 | * Asymmetric ROC case. 26 | * Add in more ROC parameters inference functions. 27 | 28 | # sigr 1.1.0 2020-09-14 29 | 30 | * More on ROC 31 | 32 | # sigr 1.0.9 2020-08-11 33 | 34 | * Change http to https where practical 35 | * Badges 36 | 37 | # sigr 1.0.6 2019-07-24 38 | 39 | * Adjust license. 40 | 41 | # sigr 1.0.5 2019-02-20 42 | 43 | * Move to RUnit. 44 | 45 | # sigr 1.0.4 2019-01-26 46 | 47 | * Unify signatures a bit. 48 | 49 | # sigr 1.0.3 2018-11-03 50 | 51 | * Polish Binomial work a bit. 52 | 53 | # sigr 1.0.2 2018-10-04 54 | 55 | * Fix end conditons of differnce of binomials. 56 | * More interfaces to Binomial test. 57 | * Student-T summary. 58 | 59 | # sigr 1.0.1 2018-09-28 60 | 61 | * Binomial test. 62 | * Difference of binomials test. 63 | * Increase default sig-figs. 64 | 65 | # sigr 1.0.0 2018-09-17 66 | 67 | * Bump versions. 68 | 69 | # sigr 0.2.8 2018-07-19 70 | 71 | * Documentation fixes. 72 | 73 | # sigr 0.2.7 2018-07-03 74 | 75 | * Re-ogranize wrapr export. 76 | 77 | # sigr 0.2.6 2018-05-25 78 | 79 | * Adjust dependencies. 80 | * Fix some documentation. 81 | * Add as.character() override. 82 | * Improve error messages. 83 | * More flexible formatting. 84 | * Fix pre-formatting on FTest (though this may not be not the pattern we want to user later). 85 | 86 | # sigr 0.2.5 2018-04-24 87 | 88 | * Allow more formats. 89 | 90 | # sigr 0.2.4 2018-03-13 91 | 92 | * Minor formatting improvements. 93 | * Add format S3 method. 94 | 95 | # sigr 0.2.3 2018-01-28 96 | 97 | * Improve import declarations. 98 | 99 | # sigr 0.2.2 2017-10-22 100 | 101 | * Add table Fisher test. 102 | * Fix "not connected" options on TTest and others. 103 | 104 | # sigr 0.2.1 2017-10-14 105 | 106 | * Pass more arguments to tests. 107 | * Switch to own Cohen-d estimate. 108 | * Add vector signatures. 109 | 110 | # sigr 0.2.0 2017-10-07 111 | 112 | * Make sigfig a bit more flexible. 113 | * Add Cohen's d. 114 | * Add lm() anova wrapper wrapFTest.anova(). 115 | * Add glm(family=binomial) anova wrapper wrapChiSqTest.anova(). 116 | * Add ez::ezANOVA linear adapter. 117 | * Some statistic presentation sigfig fixes. 118 | 119 | # sigr 0.1.7 2017-07-04 120 | 121 | * Fix NA warning bug in wrapChiSqTest.data.frame. 122 | 123 | # sigr 0.1.6 2017-05-05 124 | 125 | * Enforce more types in calculations. 126 | * Add na.rm options. 127 | 128 | # sigr 0.1.5 2017-03-24 129 | 130 | * Enforce more types in calculations. 131 | 132 | # sigr 0.1.4 2017-03-13 133 | 134 | * More standard (data.frame plus column names) interfaces. 135 | * Default to independent samples in resampleScoreModelPair. 136 | 137 | # sigr 0.1.3 2017-01-15 138 | 139 | * First CRAN submission. 140 | -------------------------------------------------------------------------------- /R/CohenD.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #' Format Cohen-D (effect size between groups) 7 | #' 8 | #' @param statistic CohenD-approximation 9 | #' @param ... not used, force use of named binding for later arguments 10 | #' @param format if set the format to return ("html", "latex", "markdown", "ascii") 11 | #' @param statDigits integer number of digits to show in summaries. 12 | #' @param sigDigits integer number of digits to show in significances. 13 | #' @param pLargeCutoff value to declare non-significance at or above. 14 | #' @param pSmallCutoff smallest value to print 15 | #' @return formatted string 16 | #' 17 | #' 18 | #' @export 19 | render.sigr_cohend <- function(statistic, 20 | ..., 21 | format, 22 | statDigits=4, 23 | sigDigits=4, 24 | pLargeCutoff=1, 25 | pSmallCutoff=0) { 26 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::render.sigr_cohend") 27 | if (missing(format) || is.null(format)) { 28 | format <- getRenderingFormat() 29 | } 30 | if(!isTRUE(format %in% formats)) { 31 | format <- "ascii" 32 | } 33 | fsyms <- syms[format,] 34 | stat_format_str <- paste0('%.',statDigits,'g') 35 | formatStr <- paste0(fsyms['startB'],statistic$test,fsyms['endB'], 36 | ': ', sprintf(stat_format_str,statistic$cohen_d)) 37 | formatStr 38 | } 39 | 40 | #' Wrap Cohen's D (effect size between groups). 41 | #' 42 | #' @param x numeric, data.frame or test. 43 | #' @param ... extra arguments 44 | #' 45 | #' @seealso \code{\link{wrapCohenD.data.frame}} 46 | #' @export 47 | wrapCohenD <- function(x,...) { 48 | UseMethod('wrapCohenD') 49 | } 50 | 51 | 52 | # NOT following strict definition, ad-hoc sensible calculation. 53 | calcCohenD <- function(pop1, pop2) { 54 | pooledSD <- sd(c(pop1 - mean(pop1), pop2 - mean(pop2))) 55 | popDiff <- mean(pop2) - mean(pop1) 56 | CohenD <- popDiff/pooledSD 57 | CohenD 58 | } 59 | 60 | 61 | #' Wrap Cohen's D (effect size between groups). 62 | #' 63 | #' @param x data.frame 64 | #' @param Column1Name character column 1 name 65 | #' @param Column2Name character column 2 name 66 | #' @param ... extra arguments (not used) 67 | #' @param na.rm if TRUE remove NAs 68 | #' @return formatted string and fields 69 | #' 70 | #' @examples 71 | #' 72 | #' d <- data.frame(x = c(1,1,2,2,3,3,4,4), 73 | #' y = c(1,2,3,4,5,6,7,7)) 74 | #' render(wrapCohenD(d,'x','y')) 75 | #' 76 | #' @export 77 | wrapCohenD.data.frame <- function(x, 78 | Column1Name, 79 | Column2Name, 80 | ..., 81 | na.rm = FALSE) { 82 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::wrapCohenD.data.frame") 83 | if(!'data.frame' %in% class(x)) { 84 | stop('sigr::wrapCohenD expected class data.frame') 85 | } 86 | if(!is.numeric(x[[Column1Name]])) { 87 | stop("sigr::wrapCohenD expected column 1 to be numeric") 88 | } 89 | if(!is.numeric(x[[Column2Name]])) { 90 | stop("sigr::wrapCohenD expected column 2 to be numeric") 91 | } 92 | c1 <- x[[Column1Name]] 93 | c2 <- x[[Column2Name]] 94 | nNA <- sum(is.na(c1) | is.na(c2)) 95 | if(na.rm) { 96 | goodPosns <- (!is.na(c1)) & (!is.na(c2)) 97 | c1 <- c1[goodPosns] 98 | c2 <- c2[goodPosns] 99 | } 100 | n <- length(c1) 101 | cohen_d <- calcCohenD(c1, c2) 102 | r <- list(cohen_d=cohen_d, 103 | test='Cohen_D_approx', 104 | Column1Name=Column1Name, 105 | Column2Name=Column2Name, 106 | n=n, 107 | nNA=nNA) 108 | class(r) <- c('sigr_cohend', 'sigr_statistic') 109 | r 110 | } 111 | 112 | 113 | #' Wrap Cohen's D (effect size between groups). 114 | #' 115 | #' @param x numeric reference or control measurements 116 | #' @param treatment numeric treatment or group-2 measurements 117 | #' @param ... extra arguments (not used) 118 | #' @param na.rm if TRUE remove NAs 119 | #' @return formatted string and fields 120 | #' 121 | #' @examples 122 | #' 123 | #' d <- data.frame(x = c(1,1,2,2,3,3,4,4), 124 | #' y = c(1,2,3,4,5,6,7,7)) 125 | #' render(wrapCohenD(d$x, d$y)) 126 | #' 127 | #' @export 128 | wrapCohenD.numeric <- function(x, 129 | treatment, 130 | ..., 131 | na.rm = FALSE) { 132 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::wrapCohenD.numeric") 133 | if(!is.numeric(x)) { 134 | stop('sigr::wrapCohenD expected class x to be numeric') 135 | } 136 | if(!is.numeric(treatment)) { 137 | stop("sigr::wrapCohenD expected class treatment to be numeric") 138 | } 139 | c1 <- x 140 | c2 <- treatment 141 | nNA <- sum(is.na(c1) | is.na(c2)) 142 | if(na.rm) { 143 | goodPosns <- (!is.na(c1)) & (!is.na(c2)) 144 | c1 <- c1[goodPosns] 145 | c2 <- c2[goodPosns] 146 | } 147 | n <- length(c1) 148 | cohen_d <- calcCohenD(c1, c2) 149 | r <- list(cohen_d=cohen_d, 150 | test='Cohen_D_approx', 151 | Column1Name='control', 152 | Column2Name='treatment', 153 | n=n, 154 | nNA=nNA) 155 | class(r) <- c('sigr_cohend', 'sigr_statistic') 156 | r 157 | } 158 | -------------------------------------------------------------------------------- /R/CorTest.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Format cor.test (test of liner correlation). 4 | #' 5 | #' @param statistic wrapped cor.test. 6 | #' @param ... extra arguments (not used) 7 | #' @param format if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...) 8 | #' @param statDigits integer number of digits to show in summaries. 9 | #' @param sigDigits integer number of digits to show in significances. 10 | #' @param pLargeCutoff value to declare non-significance at or above. 11 | #' @param pSmallCutoff smallest value to print 12 | #' @return formatted string 13 | #' 14 | #' @examples 15 | #' 16 | #' d <- data.frame(x=c(1,2,3,4,5,6,7,7), 17 | #' y=c(1,1,2,2,3,3,4,4)) 18 | #' ct <- cor.test(d$x,d$y) 19 | #' wrapCorTest(ct) 20 | #' 21 | #' 22 | #' @export 23 | render.sigr_cortest <- function(statistic, 24 | ..., 25 | format, 26 | statDigits=4, 27 | sigDigits=4, 28 | pLargeCutoff=0.05, 29 | pSmallCutoff=1.0e-5) { 30 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::render.sigr_cortest") 31 | if (missing(format) || is.null(format)) { 32 | format <- getRenderingFormat() 33 | } 34 | if(!isTRUE(format %in% formats)) { 35 | format <- "ascii" 36 | } 37 | fsyms <- syms[format,] 38 | stat_format_str <- paste0('%.',statDigits,'g') 39 | ct <- statistic$ct 40 | pString <- render(wrapSignificance(ct$p.value, 41 | symbol='p'), 42 | format=format, 43 | pLargeCutoff=pLargeCutoff, 44 | pSmallCutoff=pSmallCutoff) 45 | formatStr <- paste0(fsyms['startB'],ct$method,fsyms['endB'], 46 | ': (',fsyms['startI'],'r',fsyms['endI'], 47 | '=',sprintf(stat_format_str,ct$estimate), 48 | ', ',pString,').') 49 | formatStr 50 | } 51 | 52 | 53 | #' Wrap cor.test (test of liner correlation). 54 | #' 55 | #' @param x numeric, data.frame or test. 56 | #' @param ... extra arguments 57 | #' 58 | #' @seealso \code{\link{wrapCorTest.htest}}, and \code{\link{wrapCorTest.data.frame}} 59 | #' @export 60 | wrapCorTest <- function(x,...) { 61 | UseMethod('wrapCorTest') 62 | } 63 | 64 | 65 | 66 | #' Wrap cor.test (test of liner correlation). 67 | #' 68 | #' @param x cor.test result 69 | #' @param ... extra arguments (not used) 70 | #' @return wrapped stat 71 | #' 72 | #' @examples 73 | #' 74 | #' d <- data.frame(x=c(1,2,3,4,5,6,7,7), 75 | #' y=c(1,1,2,2,3,3,4,4)) 76 | #' ct <- cor.test(d$x,d$y) 77 | #' wrapCorTest(ct) 78 | #' 79 | #' 80 | #' @export 81 | wrapCorTest.htest <- function(x, 82 | ...) { 83 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::wrapCorTest.htest") 84 | r <- list(ct=x, 85 | test='cor.test') 86 | class(r) <- c('sigr_cortest', 'sigr_statistic') 87 | r 88 | } 89 | 90 | #' Wrap cor.test (test of liner correlation). 91 | #' 92 | #' @param x data.frame 93 | #' @param Column1Name character column 1 name 94 | #' @param Column2Name character column 2 name 95 | #' @param ... extra arguments passed to cor.test 96 | #' @param alternative passed to \code{\link[stats]{cor.test}} 97 | #' @param method passed to \code{\link[stats]{cor.test}} 98 | #' @param exact passed to \code{\link[stats]{cor.test}} 99 | #' @param conf.level passed to \code{\link[stats]{cor.test}} 100 | #' @param continuity passed to \code{\link[stats]{cor.test}} 101 | #' @param na.rm logical, if TRUE remove NA values 102 | #' @return wrapped stat 103 | #' 104 | #' @examples 105 | #' 106 | #' d <- data.frame(x=c(1,2,3,4,5,6,7,7), 107 | #' y=c(1,1,2,2,3,3,4,4)) 108 | #' wrapCorTest(d,'x','y') 109 | #' 110 | #' 111 | #' @importFrom stats cor.test 112 | #' 113 | #' @export 114 | wrapCorTest.data.frame <- function(x, 115 | Column1Name, 116 | Column2Name, 117 | ..., 118 | alternative = c("two.sided", "less", "greater"), 119 | method = c("pearson", "kendall", "spearman"), 120 | exact = NULL, conf.level = 0.95, continuity = FALSE, 121 | na.rm= FALSE) { 122 | if(!is.numeric(x[[Column1Name]])) { 123 | stop("wrapr::wrapCorTest.data.frame column 1 must be numeric") 124 | } 125 | if(!is.numeric(x[[Column2Name]])) { 126 | stop("wrapr::wrapCorTest.data.frame column 2 must be numeric") 127 | } 128 | c1 <- x[[Column1Name]] 129 | c2 <- x[[Column2Name]] 130 | nNA <- sum(is.na(c1) | is.na(c2)) 131 | if(na.rm) { 132 | goodPosns <- (!is.na(c1)) & (!is.na(c2)) 133 | c1 <- c1[goodPosns] 134 | c2 <- c2[goodPosns] 135 | } 136 | n <- length(c1) 137 | ct <- stats::cor.test(x=c1,y=c2, 138 | alternative = alternative, 139 | method = method, 140 | exact = exact, conf.level = conf.level, continuity = continuity, 141 | ...) 142 | r <- list(ct=ct, 143 | test='cor.test', 144 | Column1Name=Column1Name, 145 | Column2Name=Column2Name, 146 | n=n, 147 | nNA=nNA) 148 | class(r) <- c('sigr_cortest', 'sigr_statistic') 149 | r 150 | } 151 | -------------------------------------------------------------------------------- /R/DifferenceDistribution2.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Replacement for DifferenceDistribution 4 | 5 | 6 | #' @importFrom stats dbinom convolve 7 | NULL 8 | 9 | is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) { 10 | (length(x)==1) && (abs(x - round(x)) < tol) 11 | } 12 | 13 | is.pos_wholenumber <- function(x, tol = .Machine$double.eps^0.5) { 14 | is.wholenumber(x) && (x>0) 15 | } 16 | 17 | 18 | #' Build a table of observation probabilities for a difference of scaled Binomial counts. 19 | #' 20 | #' Must have nA*multA == nB*multB. 21 | #' 22 | #' @param nA number of events in process A 23 | #' @param multA nA success multiplier 24 | #' @param nB number of event sin process B 25 | #' @param multB nB success multiplier 26 | #' @param probi common success probability. 27 | #' @return table of event probabilities 28 | #' 29 | #' @examples 30 | #' 31 | #' scaled_binomial_difference_table(3, 2, 2, 3, 0.5) 32 | #' scaled_binomial_difference_table(1, 2, 2, 1, 0.5) 33 | #' 34 | #' @noRd 35 | #' 36 | scaled_binomial_difference_table <- function(nA, multA, 37 | nB, multB, 38 | probi) { 39 | if(!is.pos_wholenumber(nA)) { 40 | stop("sigr::scaled_binomial_difference_table nA must be a positive integer") 41 | } 42 | if(!is.pos_wholenumber(multA)) { 43 | stop("sigr::scaled_binomial_difference_table multA must be a positive integer") 44 | } 45 | if(!is.pos_wholenumber(nB)) { 46 | stop("sigr::scaled_binomial_difference_table nB must be a positive integer") 47 | } 48 | if(!is.pos_wholenumber(multB)) { 49 | stop("sigr::scaled_binomial_difference_table multB must be a positive integer") 50 | } 51 | if((probi<0)||(probi>1)) { 52 | stop("sigr::scaled_binomial_difference_table probi must in the interval [0,1]") 53 | } 54 | if(abs(nA*multA - nB*multB)>1.e-3) { 55 | stop("scaled_binomial_difference_table: (nA*multA - nB*multB) must be zero") 56 | } 57 | vA <- dbinom(0:nA, prob = probi, size = nA) 58 | if(multA>1) { 59 | pad <- numeric(multA-1) 60 | vA <- unlist(lapply(vA, function(vi) c(vi, pad)))[1:(nA*multA+1)] 61 | } 62 | if(length(vA)!=(nA*multA+1)) { 63 | stop("sigr::scaled_binomial_difference_table bad vA length") 64 | } 65 | vB <- dbinom(0:nB, prob = probi, size = nB) 66 | if(multB>1) { 67 | pad <- numeric(multB-1) 68 | vB <- unlist(lapply(vB, function(vi) c(vi, pad)))[1:(nB*multB+1)] 69 | } 70 | if(length(vB)!=(nB*multB+1)) { 71 | stop("sigr::scaled_binomial_difference_table bad vA length") 72 | } 73 | probs <- convolve(vA, vB, type = "open") 74 | probs <- pmax(probs, 0) 75 | probs <- probs/sum(probs) 76 | d <- data.frame( 77 | diff = (-nA*multA):(nA*multA), 78 | prob = probs) 79 | d$prob_le <- cumsum(d$prob) 80 | d$prob_lt <- d$prob_le - d$prob 81 | d$prob_ge <- rev(cumsum(rev(d$prob))) 82 | d$prob_gt <- d$prob_ge - d$prob 83 | d 84 | } 85 | 86 | 87 | calc_probs <- function(d, 88 | nA, multA, 89 | nB, multB, 90 | test_rate_difference) { 91 | if(!is.pos_wholenumber(nA)) { 92 | stop("sigr::scaled_binomial_difference_table nA must be a positive integer") 93 | } 94 | if(!is.pos_wholenumber(multA)) { 95 | stop("sigr::scaled_binomial_difference_table multA must be a positive integer") 96 | } 97 | if(!is.pos_wholenumber(nB)) { 98 | stop("sigr::scaled_binomial_difference_table nB must be a positive integer") 99 | } 100 | if(!is.pos_wholenumber(multB)) { 101 | stop("sigr::scaled_binomial_difference_table multB must be a positive integer") 102 | } 103 | if((test_rate_difference<0)||(test_rate_difference>1)) { 104 | stop("sigr::scaled_binomial_difference_table test_rate_difference must in the interval [0,1]") 105 | } 106 | if(abs(nA*multA - nB*multB)>1.e-3) { 107 | stop("scaled_binomial_difference_table: (nA*multA - nB*multB) must be zero") 108 | } 109 | # avoid rounding issues as seen in extras/RateDiffs.Rmd 110 | # Bernoulli_diff_stat(82, 200, 55, 100) 111 | en <- round(max(nA, nB)*test_rate_difference, digits = 7) 112 | i1 <- match(ceiling(-en), d$diff) 113 | if(is.na(i1)) { 114 | i1 <- 1 115 | } else { 116 | if((i1>1)&&(d$diff[[i1]] > (-en))) { 117 | i1 <- i1 - 1 118 | } 119 | } 120 | i2 <- match(floor(en), d$diff) 121 | if(is.na(i2)) { 122 | i2 <- nrow(d) 123 | } else { 124 | if((i2B is to run experiments of size 149 | # ( A + (B - (A %% B)), B ) and 150 | # ( A - (A %% B), B ). 151 | # 152 | # Instead we should run more variations. 153 | # 154 | # 1) Write A/B as a short continued fraction. Take the first or second 155 | # convergent of this (the last one where at least one of the numerator or 156 | # denominator or small). A/B ~ x/y so y A ~ x B. 157 | # 2) Solve (by rounding) for a, b such that y (A + a) = x (B + b) 158 | # (easy look at floor(y A / ( x B)) and ceiling(y A / (x B)) 159 | # and pick b integral and sign satifying and then a for equality). 160 | # 3) push best over and best under (according to f()) as the bounding estimates. 161 | # 162 | # 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /R/fns.R: -------------------------------------------------------------------------------- 1 | 2 | # set up per-format symbols 3 | formats <- c('markdown','html','ascii','latex', 'docx', 'pandoc', 4 | 'markdown_github') 5 | markdownSynonyms <- c('markdown_github') 6 | symCodes <- c('startB','endB','startI','endI','eq','lt', 7 | 'RSq','chiSq') 8 | syms <- matrix('',nrow=length(formats),ncol=length(symCodes), 9 | dimnames=list(formats,symCodes)) 10 | syms[,'eq'] <- '=' 11 | syms[,'lt'] <- '<' 12 | syms[,'RSq'] <- 'R2' 13 | syms[,'chiSq'] <- 'X2' 14 | syms['html','startI'] <- '' 15 | syms['html','endI'] <- '' 16 | syms['html','startB'] <- '' 17 | syms['html','endB'] <- '' 18 | syms['html','lt'] <- '<' 19 | syms['html','RSq'] <- 'R2' 20 | syms['html','chiSq'] <- 'χ2' 21 | syms['latex','startI'] <- '\\textit{' 22 | syms['latex','endI'] <- '}' 23 | syms['latex','startB'] <- '\\textbf{' 24 | syms['latex','endB'] <- '}' 25 | syms['latex','lt'] <- ' $\\lt$ ' 26 | syms['latex','RSq'] <- '$R^2$' 27 | syms['latex','chiSq'] <- '$\\chi^2$' 28 | syms['markdown',] <- syms['html',] 29 | syms['markdown','startI'] <- '*' 30 | syms['markdown','endI'] <- '*' 31 | syms['markdown','startB'] <- '**' 32 | syms['markdown','endB'] <- '**' 33 | syms['markdown','RSq'] <- 'R^2^' 34 | syms['markdown','chiSq'] <- 'χ^2^' 35 | syms['pandoc',] <- syms['markdown',] 36 | syms['docx',] <- syms['markdown',] 37 | for(fi in markdownSynonyms) { 38 | syms[fi,] <- syms['markdown',] 39 | } 40 | 41 | #' Detect rendering format (using knitr). 42 | #' 43 | #' 44 | #' @return rendering format 45 | #' 46 | #' @examples 47 | #' 48 | #' getRenderingFormat() 49 | #' 50 | #' @export 51 | getRenderingFormat <- function() { 52 | fmt <- NULL 53 | if(requireNamespace("knitr",quietly=TRUE)) { 54 | fmt <- knitr::opts_knit$get("rmarkdown.pandoc.to") 55 | } 56 | if(is.null(fmt)) { 57 | fmt <- 'ascii' 58 | } 59 | if(!isTRUE(fmt %in% formats)) { 60 | fmt <- "ascii" 61 | } 62 | fmt 63 | } 64 | 65 | 66 | #' @importFrom parallel parLapplyLB 67 | NULL 68 | 69 | # maybe run parallel 70 | plapply <- function(workList, worker, parallelCluster) { 71 | if(is.null(parallelCluster) || (!requireNamespace("parallel",quietly=TRUE))) { 72 | res <- lapply(workList,worker) 73 | } else { 74 | res <- parallel::parLapplyLB(parallelCluster,workList,worker) 75 | } 76 | res 77 | } 78 | 79 | 80 | #' Calculate deviance. 81 | #' 82 | #' @param pred numeric predictions 83 | #' @param y logical truth 84 | #' @param na.rm logical, if TRUE remove NA values 85 | #' @param eps numeric, smoothing term 86 | #' @return deviance 87 | #' 88 | #' @examples 89 | #' 90 | #' sigr::calcDeviance(1:4,c(TRUE,FALSE,TRUE,TRUE)) 91 | #' 92 | #' @export 93 | calcDeviance <- function(pred, y, 94 | na.rm= FALSE, 95 | eps= 1.0e-6) { 96 | if(!is.numeric(pred)) { 97 | stop("sigr::calcDeviance pred must be numeric") 98 | } 99 | if(!is.logical(y)) { 100 | stop("sigr::calcDeviance y must be logical") 101 | } 102 | if((length(pred)==1)&&(length(y)>1)) { 103 | pred <- rep(pred, length(y)) 104 | } 105 | if(length(pred)!=length(y)) { 106 | stop("sigr::calcDeviance must have length(pred)==length(y)") 107 | } 108 | if(na.rm) { 109 | goodPosns <- (!is.na(pred)) & (!is.na(y)) 110 | pred <- pred[goodPosns] 111 | y <- y[goodPosns] 112 | } 113 | -2*sum(log(pmin(1-eps,pmax(eps,ifelse(y,pred,1-pred))))) 114 | } 115 | 116 | 117 | #' Calculate sum of squared error. 118 | #' 119 | #' @param pred numeric predictions 120 | #' @param y numeric truth 121 | #' @param na.rm logical, if TRUE remove NA values 122 | #' @return sum of squared error 123 | #' 124 | #' @examples 125 | #' 126 | #' sigr::calcSSE(1:4,c(1,0,1,1)) 127 | #' 128 | #' @export 129 | calcSSE <- function(pred, y, 130 | na.rm= FALSE) { 131 | if(!is.numeric(pred)) { 132 | stop("sigr::calcSSE pred must be numeric") 133 | } 134 | if(!is.numeric(y)) { 135 | stop("sigr::calcSSE y must be numeric") 136 | } 137 | if((length(pred)==1)&&(length(y)>1)) { 138 | pred <- rep(pred, length(y)) 139 | } 140 | if(length(pred)!=length(y)) { 141 | stop("sigr::calcSSE must have length(pred)==length(y)") 142 | } 143 | if(na.rm) { 144 | goodPosns <- (!is.na(pred)) & (!is.na(y)) 145 | pred <- pred[goodPosns] 146 | y <- y[goodPosns] 147 | } 148 | sum((y-pred)^2) 149 | } 150 | 151 | 152 | -------------------------------------------------------------------------------- /R/pwr.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Format a pwr-test 4 | #' 5 | #' @param statistic wrapped test from pwr package 6 | #' @param ... not used, force use of named binding for later arguments 7 | #' @param format if set the format to return ("html", "latex", "markdown", "ascii") 8 | #' @param statDigits integer number of digits to show in summaries. 9 | #' @param sigDigits integer number of digits to show in significances. 10 | #' @param pLargeCutoff value to declare non-significance at or above. 11 | #' @param pSmallCutoff smallest value to print 12 | #' @return formatted string 13 | #' 14 | #' 15 | #' @export 16 | render.sigr_pwr_htest <- function(statistic, 17 | ..., 18 | format, 19 | statDigits=4, 20 | sigDigits=4, 21 | pLargeCutoff=1, 22 | pSmallCutoff=1.0e-5) { 23 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::render.sigr_pwr_htest") 24 | if (missing(format) || is.null(format)) { 25 | format <- getRenderingFormat() 26 | } 27 | if(!isTRUE(format %in% formats)) { 28 | format <- "ascii" 29 | } 30 | fsyms <- syms[format,] 31 | statStr <- paste0('%.',statDigits,'g') 32 | pwr <- statistic$pwr 33 | sigString <- render(wrapSignificance(pwr$sig.level, 34 | symbol='sig'), 35 | format=format, 36 | pLargeCutoff=pLargeCutoff, 37 | pSmallCutoff=pSmallCutoff) 38 | powString <- render(wrapSignificance(1-pwr$power, 39 | symbol='1-pwr'), 40 | format=format, 41 | pLargeCutoff=pLargeCutoff, 42 | pSmallCutoff=pSmallCutoff) 43 | others <- setdiff(names(pwr), 44 | c('sig.level', 'power', 'method', 'note')) 45 | fmt <- vapply(others, 46 | function(ni) { 47 | vi <- pwr[[ni]] 48 | if(is.numeric(vi)) { 49 | paste0(ni, ': ', sprintf(statStr, vi)) 50 | } else { 51 | paste0(ni, ': ', vi) 52 | } 53 | }, character(1)) 54 | formatStr <- paste0(fsyms['startB'],pwr$method,fsyms['endB'], 55 | " ", sigString, 56 | ", ", powString, 57 | "; ", paste(fmt, collapse = ', '), 58 | '.') 59 | formatStr 60 | } 61 | 62 | #' Wrap pwr test (difference in means by group). 63 | #' 64 | #' @param x test from pwr package 65 | #' @param ... extra arguments 66 | #' 67 | #' @seealso \code{\link[pwr]{pwr.2p.test}} 68 | #' @export 69 | wrapPWR <- function(x,...) { 70 | UseMethod('wrapPWR') 71 | } 72 | 73 | 74 | #' Wrap pwr test. 75 | #' 76 | #' @param x pwr test result 77 | #' @param ... extra arguments (not used) 78 | #' @return formatted string and fields 79 | #' 80 | #' @examples 81 | #' 82 | #' if(require("pwr", quietly = TRUE)) { 83 | #' # Example from pwr package 84 | #' # Exercise 6.1 p. 198 from Cohen (1988) 85 | #' test <- pwr::pwr.2p.test(h=0.3,n=80,sig.level=0.05,alternative="greater") 86 | #' wrapPWR(test) 87 | #' } 88 | #' 89 | #' @export 90 | wrapPWR.power.htest <- function(x, 91 | ...) { 92 | wrapr::stop_if_dot_args(substitute(list(...)), "sigr::wrapPWR.power.htest") 93 | if(!('power.htest' %in% class(x))) { 94 | stop('wrapTTest expected class htest') 95 | } 96 | r <- list(pwr=x, 97 | test='pwr test') 98 | class(r) <- c('sigr_pwr_htest', 'sigr_statistic') 99 | r 100 | } 101 | 102 | -------------------------------------------------------------------------------- /R/rexport.R: -------------------------------------------------------------------------------- 1 | 2 | #' @importFrom wrapr %.>% 3 | #' @export 4 | wrapr::`%.>%` 5 | 6 | #' @importFrom wrapr let 7 | #' @export 8 | wrapr::let 9 | 10 | #' @importFrom wrapr qc 11 | #' @export 12 | wrapr::qc 13 | 14 | #' @importFrom wrapr build_frame 15 | #' @export 16 | wrapr::build_frame 17 | 18 | #' @importFrom wrapr draw_frame 19 | #' @export 20 | wrapr::draw_frame 21 | 22 | #' @importFrom wrapr qchar_frame 23 | #' @export 24 | wrapr::qchar_frame 25 | -------------------------------------------------------------------------------- /R/sigr.R: -------------------------------------------------------------------------------- 1 | #' sigr: Format Significance Summaries for Reports 2 | #' 3 | #' Succinctly format significance summaries of 4 | #' various models and tests (F-test, Chi-Sq-test, Fisher-test, T-test, and rank-significance). The main purpose is unified reporting and planning 5 | #' of experimental results, working around issue such as the difficulty of 6 | #' extracting model summary facts (such as with 'lm'/'glm'). This package also 7 | #' includes empirical tests, such as bootstrap estimates. 8 | #' 9 | 10 | #' To learn more about sigr, please start with the vignette: 11 | #' \code{vignette('sigrFormatting','sigr')} 12 | #' 13 | "_PACKAGE" 14 | 15 | #' @importFrom wrapr stop_if_dot_args 16 | NULL 17 | -------------------------------------------------------------------------------- /R/wrapr_exports.R: -------------------------------------------------------------------------------- 1 | 2 | #' @importFrom wrapr apply_left 3 | #' @export 4 | wrapr::apply_left 5 | 6 | #' @importFrom wrapr apply_right 7 | #' @export 8 | wrapr::apply_right 9 | 10 | 11 | #' @importFrom wrapr mk_tmp_name_source 12 | #' @export 13 | wrapr::mk_tmp_name_source 14 | 15 | #' @importFrom wrapr map_to_char 16 | #' @export 17 | wrapr::map_to_char 18 | 19 | #' @importFrom wrapr %.>% 20 | #' @export 21 | wrapr::`%.>%` 22 | 23 | #' @importFrom wrapr let 24 | #' @export 25 | wrapr::let 26 | 27 | #' @importFrom wrapr qc 28 | #' @export 29 | wrapr::qc 30 | 31 | #' @importFrom wrapr qe 32 | #' @export 33 | wrapr::qe 34 | 35 | #' @importFrom wrapr qae 36 | #' @export 37 | wrapr::qae 38 | 39 | #' @importFrom wrapr build_frame 40 | #' @export 41 | wrapr::build_frame 42 | 43 | #' @importFrom wrapr draw_frame 44 | #' @export 45 | wrapr::draw_frame 46 | 47 | #' @importFrom wrapr qchar_frame 48 | #' @export 49 | wrapr::qchar_frame 50 | 51 | #' @importFrom wrapr %:=% 52 | #' @export 53 | wrapr::`%:=%` 54 | 55 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/sigr)](https://cran.r-project.org/package=sigr) 7 | [![status](https://tinyverse.netlify.com/badge/sigr)](https://CRAN.R-project.org/package=sigr) 8 | 9 | 10 | 11 | 12 | # sigr 13 | 14 | Concise formatting of significances in R. 15 | 16 | ![](https://github.com/WinVector/sigr/raw/master/tools/sigr.png) 17 | 18 | Please see [Adding polished significance summaries to papers using R](https://win-vector.com/2016/10/04/adding-polished-significance-summaries-to-papers-using-r/) for some discussion. 19 | 20 | See also: 21 | 22 | * ["The prevalence of statistical reporting errors in psychology (1985–2013)", Nuijten, M.B., Hartgerink, C.H.J., van Assen, M.A.L.M. et al., Behav Res (2015), doi:10.3758/s13428-015-0664-2](https://link.springer.com/article/10.3758/s13428-015-0664-2) 23 | * Reporting Statistics in APA Style 24 | * [Publication Manual of the American Psychological Association, Seventh Edition](https://apastyle.apa.org/products/publication-manual-7th-edition) 25 | * [Proofing statistics in papers](https://win-vector.com/2016/10/02/proofing-statistics-in-papers/) 26 | * [apa](https://CRAN.R-project.org/package=apa) 27 | * [bootstrap](https://CRAN.R-project.org/package=bootstrap) 28 | * [broom](https://cran.r-project.org/package=broom) 29 | * [achetverikov/APAstats](https://github.com/achetverikov/APAstats) 30 | * [pwr](https://CRAN.R-project.org/package=pwr) 31 | * [ggstatsplot](https://indrajeetpatil.github.io/ggstatsplot/) 32 | * ["Why Most Published Research Findings Are False", John P. A. Ioannidis 33 | PLOS Medicine, August 30, 2005](https://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.0020124) 34 | * ["The garden of forking paths", Andrew Gelman and Eric Loken, 14 Nov 2013](http://www.stat.columbia.edu/~gelman/research/unpublished/p_hacking.pdf) 35 | 36 | 37 | ----------- 38 | 39 | 40 | _sigr_ is a small package that concentrates on computing summary 41 | statistics and reporting in an appropriate format. 42 | 43 | For example here is formatting the quality of a logistic regression. 44 | 45 | ```{r} 46 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 47 | y=c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 48 | model <- glm(y~x,data=d,family=binomial) 49 | summary(model) 50 | ``` 51 | 52 | 53 | 54 | ```{r} 55 | library("sigr") 56 | ``` 57 | ```{r results='asis'} 58 | cat(render(wrapChiSqTest(model), 59 | pLargeCutoff=1, format='markdown')) 60 | ``` 61 | 62 | ----------- 63 | 64 | To install, from inside `R` please run: 65 | 66 | ```{r, eval=FALSE} 67 | install.packages("sigr") 68 | ``` 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/sigr)](https://cran.r-project.org/package=sigr) 3 | [![status](https://tinyverse.netlify.com/badge/sigr)](https://CRAN.R-project.org/package=sigr) 4 | 5 | 6 | 7 | # sigr 8 | 9 | Concise formatting of significances in R. 10 | 11 | ![](https://github.com/WinVector/sigr/raw/master/tools/sigr.png) 12 | 13 | Please see [Adding polished significance summaries to papers using 14 | R](https://win-vector.com/2016/10/04/adding-polished-significance-summaries-to-papers-using-r/) 15 | for some discussion. 16 | 17 | See also: 18 | 19 | - [“The prevalence of statistical reporting errors in psychology 20 | (1985–2013)”, Nuijten, M.B., Hartgerink, C.H.J., van Assen, M.A.L.M. 21 | et al., Behav Res (2015), 22 | doi:10.3758/s13428-015-0664-2](https://link.springer.com/article/10.3758/s13428-015-0664-2) 23 | - Reporting Statistics in APA Style 24 | - [Publication Manual of the American Psychological Association, Seventh 25 | Edition](https://apastyle.apa.org/products/publication-manual-7th-edition) 26 | - [Proofing statistics in 27 | papers](https://win-vector.com/2016/10/02/proofing-statistics-in-papers/) 28 | - [apa](https://CRAN.R-project.org/package=apa) 29 | - [bootstrap](https://CRAN.R-project.org/package=bootstrap) 30 | - [broom](https://cran.r-project.org/package=broom) 31 | - [achetverikov/APAstats](https://github.com/achetverikov/APAstats) 32 | - [pwr](https://CRAN.R-project.org/package=pwr) 33 | - [ggstatsplot](https://indrajeetpatil.github.io/ggstatsplot/) 34 | - [“Why Most Published Research Findings Are False”, John P. A. 35 | Ioannidis PLOS Medicine, August 30, 36 | 2005](https://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.0020124) 37 | - [“The garden of forking paths”, Andrew Gelman and Eric Loken, 14 Nov 38 | 2013](http://www.stat.columbia.edu/~gelman/research/unpublished/p_hacking.pdf) 39 | 40 | ------------------------------------------------------------------------ 41 | 42 | *sigr* is a small package that concentrates on computing summary 43 | statistics and reporting in an appropriate format. 44 | 45 | For example here is formatting the quality of a logistic regression. 46 | 47 | ``` r 48 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 49 | y=c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 50 | model <- glm(y~x,data=d,family=binomial) 51 | summary(model) 52 | ``` 53 | 54 | ## 55 | ## Call: 56 | ## glm(formula = y ~ x, family = binomial, data = d) 57 | ## 58 | ## Coefficients: 59 | ## Estimate Std. Error z value Pr(>|z|) 60 | ## (Intercept) -0.7455 1.6672 -0.447 0.655 61 | ## x 0.1702 0.3429 0.496 0.620 62 | ## 63 | ## (Dispersion parameter for binomial family taken to be 1) 64 | ## 65 | ## Null deviance: 11.090 on 7 degrees of freedom 66 | ## Residual deviance: 10.837 on 6 degrees of freedom 67 | ## AIC: 14.837 68 | ## 69 | ## Number of Fisher Scoring iterations: 4 70 | 71 | ``` r 72 | library("sigr") 73 | ``` 74 | 75 | ``` r 76 | cat(render(wrapChiSqTest(model), 77 | pLargeCutoff=1, format='markdown')) 78 | ``` 79 | 80 | **Chi-Square Test** summary: *pseudo-R2*=0.02282 81 | (χ2(1,*N*=8)=0.2531, *p*=0.6149). 82 | 83 | ------------------------------------------------------------------------ 84 | 85 | To install, from inside `R` please run: 86 | 87 | ``` r 88 | install.packages("sigr") 89 | ``` 90 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | 2 | url: https://winvector.github.io/sigr/ 3 | 4 | navbar: 5 | right: 6 | - text: "Sponsor: Win-Vector LLC" 7 | href: https://win-vector.com/ 8 | 9 | 10 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Test environments 4 | 5 | R CMD check --as-cran sigr_1.1.5.tar.gz 6 | * using R version 4.3.0 (2023-04-21) 7 | * using platform: x86_64-apple-darwin20 (64-bit) 8 | 9 | devtools::check_win_devel() 10 | * using R Under development (unstable) (2023-08-19 r84989 ucrt) 11 | * using platform: x86_64-w64-mingw32 12 | 13 | rhub::check_for_cran() 14 | skipped 15 | 16 | ## Downstream dependencies 17 | 18 | Checked all reverse dependencies: https://github.com/WinVector/sigr/blob/master/extras/check_reverse_dependencies.md 19 | 20 | Zumel is not a mis-spelling. 21 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • sigr 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
24 |
73 | 74 | 75 | 76 | 77 |
78 |
79 | 82 | 83 | Content not found. Please use links in the navbar. 84 | 85 |
86 | 87 | 91 | 92 |
93 | 94 | 95 | 96 |
100 | 101 |
102 |

103 |

Site built with pkgdown 2.0.7.

104 |
105 | 106 |
107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • sigr 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 | 58 | 59 |
60 |

All vignettes

61 |

62 | 63 |
lm example
64 |
65 |
sigr formatting
66 |
67 |
68 |
69 |
70 | 71 | 72 |
75 | 76 |
77 |

Site built with pkgdown 2.0.7.

78 |
79 | 80 |
81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /docs/articles/lmExample_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/sigrFormatting_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • sigr 6 | 7 | 8 |
9 |
50 | 51 | 52 | 53 |
54 |
55 |
56 | 59 | 60 | 61 |
  • 62 |

    John Mount. Author, maintainer. 63 |

    64 |
  • 65 |
  • 66 |

    Nina Zumel. Author. 67 |

    68 |
  • 69 |
  • 70 |

    Win-Vector LLC. Copyright holder. 71 |

    72 |
  • 73 |
74 |
75 |
76 |

Citation

77 | Source: DESCRIPTION 78 |
79 |
80 | 81 | 82 |

Mount J, Zumel N (2023). 83 | sigr: Succinct and Correct Statistical Summaries for Reports. 84 | https://github.com/WinVector/sigr/, https://winvector.github.io/sigr/. 85 |

86 |
@Manual{,
 87 |   title = {sigr: Succinct and Correct Statistical Summaries for Reports},
 88 |   author = {John Mount and Nina Zumel},
 89 |   year = {2023},
 90 |   note = {https://github.com/WinVector/sigr/, https://winvector.github.io/sigr/},
 91 | }
92 | 93 |
94 | 95 |
96 | 97 | 98 | 99 |
102 | 103 |
104 |

Site built with pkgdown 2.0.7.

105 |
106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /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/bootstrap-toc.js: -------------------------------------------------------------------------------- 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 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 3.1.1 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | lmExample: lmExample.html 6 | sigrFormatting: sigrFormatting.html 7 | last_built: 2023-08-20T00:06Z 8 | urls: 9 | reference: https://winvector.github.io/sigr/reference 10 | article: https://winvector.github.io/sigr/articles 11 | 12 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/model_utility-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/docs/reference/model_utility-1.png -------------------------------------------------------------------------------- /docs/reference/wrapCohenD.html: -------------------------------------------------------------------------------- 1 | 2 | Wrap Cohen's D (effect size between groups). — wrapCohenD • sigr 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    Wrap Cohen's D (effect size between groups).

    63 |
    64 | 65 |
    66 |
    wrapCohenD(x, ...)
    67 |
    68 | 69 |
    70 |

    Arguments

    71 |
    x
    72 |

    numeric, data.frame or test.

    73 | 74 | 75 |
    ...
    76 |

    extra arguments

    77 | 78 |
    79 |
    80 |

    See also

    81 | 82 |
    83 | 84 |
    85 | 88 |
    89 | 90 | 91 |
    100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /extras/BiasEstsNormal.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Bias Estimates Normal" 3 | output: github_document 4 | --- 5 | 6 | ```{r} 7 | library("cdata") 8 | library("ggplot2") 9 | 10 | # https://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation 11 | c4 <- function(n) { 12 | sqrt(2/(n-1))*gamma(n/2)/gamma((n-1)/2) 13 | } 14 | 15 | d <- data.frame(n = 2:10) 16 | d$correct <- sqrt(d$n/(d$n-1))*c4(d$n) 17 | d$naive_ratio <- 1/d$correct 18 | d$Bessel_ratio <- sqrt(d$n/(d$n-1))/d$correct 19 | d$arithmetic_mean <- (d$naive_ratio + d$Bessel_ratio)/2 20 | d$geometric_mean <- sqrt(d$naive_ratio * d$Bessel_ratio) 21 | 22 | 23 | dplot <- unpivot_to_blocks( 24 | d, 25 | nameForNewKeyColumn = "estimate_type", 26 | nameForNewValueColumn = "estimate", 27 | columnsToTakeFrom = qc(naive_ratio, Bessel_ratio, 28 | arithmetic_mean, geometric_mean)) 29 | 30 | ggplot( 31 | data = dplot[dplot$estimate_type %in% qc(naive_ratio, Bessel_ratio), , drop = FALSE], 32 | aes(x = n, y = estimate, 33 | color = estimate_type, shape = estimate_type)) + 34 | geom_point() + 35 | geom_line() + 36 | geom_hline(yintercept = 1, linetype = 2) + 37 | ggtitle("ratio of estimation type over unbiased expected value") 38 | 39 | ggplot( 40 | data = dplot[dplot$estimate_type %in% qc(arithmetic_mean, geometric_mean), , drop = FALSE], 41 | aes(x = n, y = estimate, 42 | color = estimate_type, shape = estimate_type)) + 43 | geom_point() + 44 | geom_line() + 45 | geom_hline(yintercept = 1, linetype = 2) 46 | 47 | 48 | ``` 49 | -------------------------------------------------------------------------------- /extras/BiasEstsNormal.md: -------------------------------------------------------------------------------- 1 | Bias Estimates Normal 2 | ================ 3 | 4 | ``` r 5 | library("cdata") 6 | library("ggplot2") 7 | 8 | # https://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation 9 | c4 <- function(n) { 10 | sqrt(2/(n-1))*gamma(n/2)/gamma((n-1)/2) 11 | } 12 | 13 | d <- data.frame(n = 2:10) 14 | d$correct <- sqrt(d$n/(d$n-1))*c4(d$n) 15 | d$naive_ratio <- 1/d$correct 16 | d$Bessel_ratio <- sqrt(d$n/(d$n-1))/d$correct 17 | d$arithmetic_mean <- (d$naive_ratio + d$Bessel_ratio)/2 18 | d$geometric_mean <- sqrt(d$naive_ratio * d$Bessel_ratio) 19 | 20 | 21 | dplot <- unpivot_to_blocks( 22 | d, 23 | nameForNewKeyColumn = "estimate_type", 24 | nameForNewValueColumn = "estimate", 25 | columnsToTakeFrom = qc(naive_ratio, Bessel_ratio, 26 | arithmetic_mean, geometric_mean)) 27 | 28 | ggplot( 29 | data = dplot[dplot$estimate_type %in% qc(naive_ratio, Bessel_ratio), , drop = FALSE], 30 | aes(x = n, y = estimate, 31 | color = estimate_type, shape = estimate_type)) + 32 | geom_point() + 33 | geom_line() + 34 | geom_hline(yintercept = 1, linetype = 2) + 35 | ggtitle("ratio of estimation type over unbiased expected value") 36 | ``` 37 | 38 | ![](BiasEstsNormal_files/figure-markdown_github/unnamed-chunk-1-1.png) 39 | 40 | ``` r 41 | ggplot( 42 | data = dplot[dplot$estimate_type %in% qc(arithmetic_mean, geometric_mean), , drop = FALSE], 43 | aes(x = n, y = estimate, 44 | color = estimate_type, shape = estimate_type)) + 45 | geom_point() + 46 | geom_line() + 47 | geom_hline(yintercept = 1, linetype = 2) 48 | ``` 49 | 50 | ![](BiasEstsNormal_files/figure-markdown_github/unnamed-chunk-1-2.png) 51 | -------------------------------------------------------------------------------- /extras/BiasEstsNormal_files/figure-markdown_github/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEstsNormal_files/figure-markdown_github/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /extras/BiasEstsNormal_files/figure-markdown_github/unnamed-chunk-1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEstsNormal_files/figure-markdown_github/unnamed-chunk-1-2.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-1.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-10.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-11.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-12.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-13.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-14.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-15.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-16.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-17.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-18.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-19.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-2.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-20.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-21.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-22.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-23.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-24.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-3.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-4.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-5.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-6.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-7.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-8.png -------------------------------------------------------------------------------- /extras/BiasEsts_files/figure-markdown_github/run-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/BiasEsts_files/figure-markdown_github/run-9.png -------------------------------------------------------------------------------- /extras/UtilityExample_files/figure-gfm/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/UtilityExample_files/figure-gfm/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /extras/UtilityExample_files/figure-gfm/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/UtilityExample_files/figure-gfm/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /extras/UtilityExample_files/figure-gfm/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/UtilityExample_files/figure-gfm/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /extras/UtilityExample_files/figure-gfm/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/UtilityExample_files/figure-gfm/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /extras/UtilityExample_files/figure-gfm/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/UtilityExample_files/figure-gfm/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /extras/UtilityExample_files/figure-gfm/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/UtilityExample_files/figure-gfm/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /extras/check_reverse_dependencies.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "check_reverse_dependencies" 3 | output: github_document 4 | --- 5 | 6 | ```{r, error=TRUE} 7 | library("prrd") 8 | td <- tempdir() 9 | package = "sigr" 10 | date() 11 | 12 | parallelCluster <- NULL 13 | # # parallel doesn't work due to https://github.com/r-lib/liteq/issues/22 14 | #ncores <- parallel::detectCores() 15 | #parallelCluster <- parallel::makeCluster(ncores) 16 | 17 | orig_dir <- getwd() 18 | print(orig_dir) 19 | setwd(td) 20 | print(td) 21 | 22 | options(repos = c(CRAN="https://cloud.r-project.org")) 23 | jobsdfe <- enqueueJobs(package=package, directory=td) 24 | 25 | mk_fn <- function(package, directory) { 26 | force(package) 27 | force(directory) 28 | function(i) { 29 | library("prrd") 30 | setwd(directory) 31 | Sys.sleep(1*i) 32 | dequeueJobs(package=package, directory=directory) 33 | } 34 | } 35 | f <- mk_fn(package=package, directory=td) 36 | 37 | if(!is.null(parallelCluster)) { 38 | parallel::parLapply(parallelCluster, seq_len(ncores), f) 39 | } else { 40 | f(0) 41 | } 42 | 43 | summariseQueue(package=package, directory=td) 44 | 45 | setwd(orig_dir) 46 | if(!is.null(parallelCluster)) { 47 | parallel::stopCluster(parallelCluster) 48 | } 49 | 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /extras/check_reverse_dependencies.md: -------------------------------------------------------------------------------- 1 | check_reverse_dependencies 2 | ================ 3 | 4 | ``` r 5 | library("prrd") 6 | td <- tempdir() 7 | package = "sigr" 8 | date() 9 | ``` 10 | 11 | ## [1] "Sat Aug 19 16:52:21 2023" 12 | 13 | ``` r 14 | parallelCluster <- NULL 15 | # # parallel doesn't work due to https://github.com/r-lib/liteq/issues/22 16 | #ncores <- parallel::detectCores() 17 | #parallelCluster <- parallel::makeCluster(ncores) 18 | 19 | orig_dir <- getwd() 20 | print(orig_dir) 21 | ``` 22 | 23 | ## [1] "/Users/johnmount/Documents/work/sigr/extras" 24 | 25 | ``` r 26 | setwd(td) 27 | print(td) 28 | ``` 29 | 30 | ## [1] "/var/folders/7f/sdjycp_d08n8wwytsbgwqgsw0000gn/T//RtmpN9AUSz" 31 | 32 | ``` r 33 | options(repos = c(CRAN="https://cloud.r-project.org")) 34 | jobsdfe <- enqueueJobs(package=package, directory=td) 35 | 36 | mk_fn <- function(package, directory) { 37 | force(package) 38 | force(directory) 39 | function(i) { 40 | library("prrd") 41 | setwd(directory) 42 | Sys.sleep(1*i) 43 | dequeueJobs(package=package, directory=directory) 44 | } 45 | } 46 | f <- mk_fn(package=package, directory=td) 47 | 48 | if(!is.null(parallelCluster)) { 49 | parallel::parLapply(parallelCluster, seq_len(ncores), f) 50 | } else { 51 | f(0) 52 | } 53 | ``` 54 | 55 | ## ## Reverse depends check of sigr 1.1.5 56 | ## WVPlots_1.3.5 started at 2023-08-19 16:52:22 success at 2023-08-19 16:53:17 (1/0/0) 57 | 58 | ## [1] id title status 59 | ## <0 rows> (or 0-length row.names) 60 | 61 | ``` r 62 | summariseQueue(package=package, directory=td) 63 | ``` 64 | 65 | ## Test of sigr 1.1.5 had 1 successes, 0 failures, and 0 skipped packages. 66 | ## Ran from 2023-08-19 16:52:22 to 2023-08-19 16:53:17 for 55 secs 67 | ## Average of 55 secs relative to 54.887 secs using 1 runners 68 | ## 69 | ## Failed packages: 70 | ## 71 | ## Skipped packages: 72 | ## 73 | ## None still working 74 | ## 75 | ## None still scheduled 76 | 77 | ``` r 78 | setwd(orig_dir) 79 | if(!is.null(parallelCluster)) { 80 | parallel::stopCluster(parallelCluster) 81 | } 82 | ``` 83 | -------------------------------------------------------------------------------- /extras/nina_check/nina_check.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "temp" 3 | author: "Nina Zumel" 4 | date: "9/29/2020" 5 | output: html_document 6 | --- 7 | 8 | ```{r setup, include=FALSE} 9 | knitr::opts_chunk$set(echo = TRUE) 10 | library(wrapr) 11 | library(ggplot2) 12 | library(sigr) 13 | ``` 14 | 15 | functions 16 | 17 | ```{r} 18 | # Plot data and thresholds 19 | plot_data_and_T = function(d, expect) { 20 | df = d[, dvars] 21 | df$y = runif(nrow(df), max=0.1) 22 | ggplot() + 23 | geom_point(data=df, aes(x=predicted_probability, y=y, color=made_purchase)) + 24 | geom_vline(data=expect, aes(xintercept=threshold), linetype=2) + 25 | scale_color_brewer(palette="Dark2") 26 | } 27 | 28 | # calculate the counts for a threshold 29 | get_counts = function(d, threshold) { 30 | p = d$predicted_probability 31 | cls = d$made_purchase 32 | 33 | total = sum(p >= threshold) 34 | tn_count = sum(p < threshold & cls==FALSE) 35 | fn_count = sum(p < threshold & cls==TRUE) 36 | tp_count = sum(p >= threshold & cls==TRUE) 37 | fp_count = sum(p >= threshold & cls==FALSE) 38 | 39 | data.frame(threshold=threshold, 40 | total=total, 41 | tn_count=tn_count, 42 | fn_count=fn_count, 43 | tp_count=tp_count, 44 | fp_count=fp_count) 45 | } 46 | 47 | get_all_counts = function(d, expect) { 48 | thresholds = expect$threshold 49 | thresholds = ifelse(is.na(thresholds), 1.01, thresholds) 50 | flist = lapply(thresholds, function(th) get_counts(d, th)) 51 | data.table::rbindlist(flist) 52 | } 53 | 54 | ``` 55 | 56 | test 1 57 | 58 | ```{r} 59 | d <- data.frame( 60 | predicted_probability = c(0, 0.5, 0.5, 0.5), 61 | made_purchase = c(FALSE, TRUE, FALSE, FALSE), 62 | false_positive_value = -5, # acting on any predicted positive costs $5 63 | true_positive_value = 95, # revenue on a true positive is $100 minus action cost 64 | true_negative_value = 0.001, # true negatives have no value in our application 65 | # but just give ourselves a small reward for being right 66 | false_negative_value = -0.01 # adding a small notional tax for false negatives, 67 | # don't want our competitor getting these accounts. 68 | ) 69 | dvars = qc(predicted_probability, made_purchase) 70 | 71 | values <- model_utility(d, 'predicted_probability', 'made_purchase') 72 | 73 | evars = qc(threshold, count_taken, true_negative_count, false_negative_count, true_positive_count, false_positive_count) 74 | 75 | d[, dvars] 76 | plot_data_and_T(d, values) + ggtitle("test 1") 77 | get_all_counts(d, values) 78 | values[, evars] 79 | 80 | ``` 81 | 82 | test 2 83 | 84 | ```{r} 85 | d <- data.frame( 86 | predicted_probability = c(0, 0.25, 0.5, 0.5, 0.5, 0.75, 0.8, 1.0), 87 | made_purchase = c(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE), 88 | false_positive_value = -5, # acting on any predicted positive costs $5 89 | true_positive_value = 95, # revenue on a true positive is $100 minus action cost 90 | true_negative_value = 0.001, # true negatives have no value in our application 91 | # but just give ourselves a small reward for being right 92 | false_negative_value = -0.01 # adding a small notional tax for false negatives, 93 | # don't want our competitor getting these accounts. 94 | ) 95 | 96 | values <- model_utility(d, 'predicted_probability', 'made_purchase') 97 | 98 | d[, dvars] 99 | plot_data_and_T(d, values) + ggtitle("test 2") 100 | get_all_counts(d, values) 101 | values[, evars] 102 | 103 | 104 | ``` 105 | 106 | test 3 107 | 108 | ```{r} 109 | d <- data.frame( 110 | predicted_probability = runif(100), 111 | made_purchase = sample(c(FALSE, TRUE), replace = TRUE, size = 100), 112 | false_positive_value = -5, # acting on any predicted positive costs $5 113 | true_positive_value = 95, # revenue on a true positive is $100 minus action cost 114 | true_negative_value = 0.001, # true negatives have no value in our application 115 | # but just give ourselves a small reward for being right 116 | false_negative_value = -0.01 # adding a small notional tax for false negatives, 117 | # don't want our competitor getting these accounts. 118 | ) 119 | 120 | values <- model_utility(d, 'predicted_probability', 'made_purchase') 121 | 122 | # d[, dvars] 123 | 124 | mycheck = get_all_counts(d, values) 125 | vals = values[, evars] 126 | 127 | thr = vals$threshold 128 | vals$threshold = ifelse(is.na(thr), 1.01, thr) 129 | colnames(mycheck) = colnames(vals) 130 | ``` 131 | 132 | ```{r} 133 | wrapr::check_equiv_frames(mycheck, vals, tolerance = 1.e-3) 134 | 135 | mycheck$calc = "my check" 136 | vals$calc = "model_utility" 137 | 138 | allf = rbind(mycheck, vals) 139 | 140 | library(cdata) 141 | 142 | allf_long = pivot_to_blocks(allf, 143 | nameForNewKeyColumn = "count_type", 144 | nameForNewValueColumn = "count", 145 | columnsToTakeFrom = evars[-1] # no threshold 146 | ) 147 | 148 | ggplot() + 149 | geom_vline(data=d, aes(xintercept=predicted_probability), color="darkgray") + 150 | geom_vline(data=values, aes(xintercept=threshold), linetype=2, color="darkblue") + 151 | ggtitle("test 3") 152 | 153 | ggplot(allf_long, aes(x=threshold, y=count, color=calc)) + 154 | geom_point() + geom_line() + 155 | facet_wrap(~count_type, ncol=1, scale="free_y") + 156 | scale_color_brewer(palette="Dark2") 157 | 158 | 159 | 160 | ``` -------------------------------------------------------------------------------- /extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/ROC_optimization_files/figure-gfm/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-1-2.png -------------------------------------------------------------------------------- /extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/extras/utility_modeling/Utility_Sampling_Distribution_files/figure-gfm/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /inst/tinytest/test_BD.R: -------------------------------------------------------------------------------- 1 | 2 | test_BD <- function() { 3 | # near an empirical value 4 | v <- Bernoulli_diff_stat(82, 200, 55, 100)$pValue 5 | empirical <- 0.02403 # from a large empirical run of extras/RateDiffs.Rmd 6 | expect_true(abs(v - empirical)<1e-4) 7 | 8 | # symmetry 9 | v1 <- Bernoulli_diff_stat(2000, 5000, 100, 200)$pValue 10 | v2 <- Bernoulli_diff_stat(100, 200, 2000, 5000)$pValue 11 | expect_true(abs(v1 - v2)<1e-7) 12 | 13 | # moderate continuity 14 | v1 <- Bernoulli_diff_stat(2000, 5000, 100, 200)$pValue 15 | v2 <- Bernoulli_diff_stat(2000, 5000, 100, 199)$pValue 16 | expect_true(abs(v1 - v2)<2e-3) 17 | v2 <- Bernoulli_diff_stat(2000, 4999, 100, 200)$pValue 18 | expect_true(abs(v1 - v2)<1e-4) 19 | 20 | invisible(NULL) 21 | } 22 | 23 | test_BD() 24 | -------------------------------------------------------------------------------- /inst/tinytest/test_T1.R: -------------------------------------------------------------------------------- 1 | 2 | test_T1 <- function() { 3 | set.seed(25325) 4 | s1 <- sigr::getRenderingFormat() 5 | s2 <- sigr::wrapSignificance(1/300) 6 | s3 <- sigr::wrapFTestImpl(numdf=2,dendf=55,FValue=5.56) 7 | 8 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 9 | y=c(1,1,2,2,3,3,4,4)) 10 | model <- lm(y~x,data=d) 11 | # summary(model) 12 | expect <- 3.094301e-05 13 | d$pred <- predict(model,newdata=d) 14 | s4 <- sigr::wrapFTest(model) 15 | expect_true(abs(s4$pValue - expect)<1e-6) 16 | s5 <- sigr::wrapFTest(d,'pred','y') 17 | expect_true(abs(s5$pValue - expect)<1e-6) 18 | 19 | invisible(NULL) 20 | } 21 | 22 | test_T1() 23 | -------------------------------------------------------------------------------- /man/Bernoulli_diff_stat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DifferenceDistribution.R 3 | \name{Bernoulli_diff_stat} 4 | \alias{Bernoulli_diff_stat} 5 | \title{Compute the distribution of differences of replacement samples of two Binomial or Bernoulli experiments.} 6 | \usage{ 7 | Bernoulli_diff_stat(kA, nA, kB, nB, test_rate_difference, common_rate) 8 | } 9 | \arguments{ 10 | \item{kA}{number of A successes observed.} 11 | 12 | \item{nA}{number of A experiments.} 13 | 14 | \item{kB}{number of B successes observed.} 15 | 16 | \item{nB}{number of B experiments.} 17 | 18 | \item{test_rate_difference}{numeric, difference in rate of A-B to test. Note: it is best to specify this prior to looking at the data.} 19 | 20 | \item{common_rate}{rate numeric, assumed null-rate.} 21 | } 22 | \value{ 23 | Bernoulli difference test statistic. 24 | } 25 | \description{ 26 | Assuming \code{max(nA, nB) \%\% min(nA, nB) == 0}: 27 | compute the distribution of differences of weighted sums between 28 | \code{max(1, nB/nA)*sum(a)} 29 | and \code{max(1, nA/nB)*sum(b)} 30 | where \code{a} is a 0/1 vector of length \code{nA} with each item 1 with independent probability \code{(kA+kB)/(nA+nB)}, 31 | and \code{b} is a 0/1 vector of length \code{nB} with each item 1 with independent probability \code{(kA+kB)/(nA+nB)}. 32 | Then return the significance of a direct two-sided test that the absolute value of this difference is at least as large 33 | as the test_rate_difference (if supplied) or the empirically observed rate difference \code{abs(nB*kA - nA*kB)/(nA*nB)}. 34 | The idea is: under this scaling differences in success rates between the two processes are easily observed as differences 35 | in counts returned by the scaled processes. 36 | The method can be used to get the exact probability of a given difference under the null hypothesis that 37 | both the \code{A} and \code{B} processes have the same success rate \code{(kA+kB)/(nA+nB)}. 38 | When \code{nA} and \code{nB} don't divide evenly into to each 39 | other two calculations are run with the larger process is alternately padded and truncated to look like a larger or smaller 40 | experiment that meets the above conditions. This gives us a good range of significances. 41 | } 42 | \details{ 43 | Note the intent is that we are measuring the results of an A/B test with \code{max(nA, nB) \%\% min(nA, nB) == 0} 44 | (no padding needed), or \code{max(nA,nB) >> min(nA,nB)} (padding is small effect). 45 | 46 | The idea of converting a rate problem into a counting problem follows from reading Wald's \emph{Sequential Analysis}. 47 | 48 | For very small p-values the calculation is sensitive to rounding in the observed ratio-difference, 49 | as an arbitrarily small change in test-rate can move an entire set of observed differences in or out of the significance calculation. 50 | } 51 | \examples{ 52 | 53 | Bernoulli_diff_stat(2000, 5000, 100, 200) 54 | Bernoulli_diff_stat(2000, 5000, 100, 200, 0.1) 55 | Bernoulli_diff_stat(2000, 5000, 100, 199) 56 | Bernoulli_diff_stat(2000, 5000, 100, 199, 0.1) 57 | Bernoulli_diff_stat(100, 200, 2000, 5000) 58 | 59 | # sigr adjusts experiment sizes when lengths 60 | # don't divide into each other. 61 | Bernoulli_diff_stat(100, 199, 2000, 5000) 62 | Bernoulli_diff_stat(100, 199, 2000, 5000)$pValue 63 | 64 | } 65 | -------------------------------------------------------------------------------- /man/TInterval.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TInterval.R 3 | \name{TInterval} 4 | \alias{TInterval} 5 | \title{Wrap TInterval (test of Binomial/Bernoulli rate).} 6 | \usage{ 7 | TInterval(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or test.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap TInterval (test of Binomial/Bernoulli rate). 16 | } 17 | \seealso{ 18 | \code{\link{TIntervalS}}, \code{\link{TInterval.numeric}}, \code{\link{TInterval.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/TInterval.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TInterval.R 3 | \name{TInterval.data.frame} 4 | \alias{TInterval.data.frame} 5 | \title{Student-T tolerance-style interval around an estimate of a mean from a data.frame.} 6 | \usage{ 7 | \method{TInterval}{data.frame}(x, ColumnName, ..., conf.level = 0.95, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{data.frame} 11 | 12 | \item{ColumnName}{character name of measurment column} 13 | 14 | \item{...}{extra arguments passed to TInterval} 15 | 16 | \item{conf.level}{confidence level to draw interval} 17 | 18 | \item{na.rm}{logical, if TRUE remove NA values} 19 | } 20 | \value{ 21 | wrapped stat 22 | } 23 | \description{ 24 | Student-T tolerance-style interval around an estimate of a mean from a data.frame. 25 | } 26 | \examples{ 27 | 28 | set.seed(2018) 29 | d <- data.frame(x = rnorm(100) + 3.2) 30 | TInterval(d, "x") 31 | 32 | 33 | } 34 | \seealso{ 35 | \code{\link{TInterval}}, \code{\link{TIntervalS}}, \code{\link{TInterval.numeric}}, \code{\link{TInterval.data.frame}} 36 | } 37 | -------------------------------------------------------------------------------- /man/TInterval.numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TInterval.R 3 | \name{TInterval.numeric} 4 | \alias{TInterval.numeric} 5 | \title{Student-T tolerance-style interval around an estimate of a mean from observations.} 6 | \usage{ 7 | \method{TInterval}{numeric}(x, ..., conf.level = 0.95, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{logical, vector of observations.} 11 | 12 | \item{...}{extra arguments passed to TInterval} 13 | 14 | \item{conf.level}{confidence level to draw interval} 15 | 16 | \item{na.rm}{logical, if TRUE remove NA values} 17 | } 18 | \value{ 19 | wrapped stat 20 | } 21 | \description{ 22 | Student-T tolerance-style interval around an estimate of a mean from observations. 23 | } 24 | \examples{ 25 | 26 | set.seed(2018) 27 | d <- rnorm(100) + 3.2 28 | TInterval(d) 29 | 30 | 31 | } 32 | \seealso{ 33 | \code{\link{TInterval}}, \code{\link{TIntervalS}}, \code{\link{TInterval.numeric}}, \code{\link{TInterval.data.frame}} 34 | } 35 | -------------------------------------------------------------------------------- /man/TIntervalS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TInterval.R 3 | \name{TIntervalS} 4 | \alias{TIntervalS} 5 | \title{Student-T tolerance-style interval around an estimate of a mean from summary.} 6 | \usage{ 7 | TIntervalS( 8 | sample_size, 9 | sample_mean, 10 | sample_var, 11 | ..., 12 | nNA = 0, 13 | conf.level = 0.95 14 | ) 15 | } 16 | \arguments{ 17 | \item{sample_size}{numeric scalar integer, size of sample.} 18 | 19 | \item{sample_mean}{numeric scalar, mean of sample.} 20 | 21 | \item{sample_var}{numeric scalar, variance of sample (Bessel-corrected).} 22 | 23 | \item{...}{extra arguments passed to TInterval.} 24 | 25 | \item{nNA}{number of NAs seen.} 26 | 27 | \item{conf.level}{confidence level to draw interval} 28 | } 29 | \value{ 30 | wrapped stat 31 | } 32 | \description{ 33 | Student-T tolerance-style interval around an estimate of a mean from summary. 34 | } 35 | \examples{ 36 | 37 | set.seed(2018) 38 | d <- rnorm(100) + 3.2 39 | TIntervalS(length(d), mean(d), stats::var(d)) 40 | 41 | } 42 | \seealso{ 43 | \code{\link{TInterval}}, \code{\link{TIntervalS}}, \code{\link{TInterval.numeric}}, \code{\link{TInterval.data.frame}} 44 | } 45 | -------------------------------------------------------------------------------- /man/add_ROC_derived_columns.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{add_ROC_derived_columns} 4 | \alias{add_ROC_derived_columns} 5 | \title{Add ROC derived columns.} 6 | \usage{ 7 | add_ROC_derived_columns(d, positive_prevalence) 8 | } 9 | \arguments{ 10 | \item{d}{input data frame, must at lest of columns Sensitivity and Specificity} 11 | 12 | \item{positive_prevalence}{scalar, the prevalence of the positive class or prior odds} 13 | } 14 | \value{ 15 | extended data frame with more columns 16 | } 17 | \description{ 18 | Add ROC columns derived from sensitivity and specificity. 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(pred = 1:4, truth = c(TRUE,FALSE,TRUE,TRUE)) 23 | roc <- build_ROC_curve(d$pred, d$truth) 24 | add_ROC_derived_columns(roc, mean(d$truth)) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/as.character.sigr_statistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toPresentation.R 3 | \name{as.character.sigr_statistic} 4 | \alias{as.character.sigr_statistic} 5 | \title{as.character} 6 | \usage{ 7 | \method{as.character}{sigr_statistic}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{sigr wrapper to print} 11 | 12 | \item{...}{extra arguments for sigr::render} 13 | } 14 | \value{ 15 | formatted string 16 | } 17 | \description{ 18 | as.character 19 | } 20 | \examples{ 21 | 22 | as.character(wrapSignificance(1/300)) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/build_ROC_curve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{build_ROC_curve} 4 | \alias{build_ROC_curve} 5 | \title{calculate ROC curve.} 6 | \usage{ 7 | build_ROC_curve(modelPredictions, yValues, ..., na.rm = FALSE, yTarget = TRUE) 8 | } 9 | \arguments{ 10 | \item{modelPredictions}{numeric predictions (not empty)} 11 | 12 | \item{yValues}{truth values (not empty, same length as model predictions)} 13 | 14 | \item{...}{force later arguments to bind by name.} 15 | 16 | \item{na.rm}{logical, if TRUE remove NA values.} 17 | 18 | \item{yTarget}{value considered to be positive.} 19 | } 20 | \value{ 21 | the ROC graph of Score (model score), Sensitivity, and Specificity. Guaranteed to have the (0, 0) and (1, 1) (1-Specificity,Sensitivity) endpoints. 22 | } 23 | \description{ 24 | Based on: 25 | \url{https://blog.revolutionanalytics.com/2016/08/roc-curves-in-two-lines-of-code.html} 26 | } 27 | \examples{ 28 | 29 | sigr::build_ROC_curve(1:4, c(TRUE,FALSE,TRUE,TRUE)) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/calcAUC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{calcAUC} 4 | \alias{calcAUC} 5 | \title{calculate AUC.} 6 | \usage{ 7 | calcAUC(modelPredictions, yValues, ..., na.rm = FALSE, yTarget = TRUE) 8 | } 9 | \arguments{ 10 | \item{modelPredictions}{numeric predictions (not empty), ordered (either increasing or decreasing)} 11 | 12 | \item{yValues}{truth values (not empty, same length as model predictions)} 13 | 14 | \item{...}{force later arguments to bind by name.} 15 | 16 | \item{na.rm}{logical, if TRUE remove NA values.} 17 | 18 | \item{yTarget}{value considered to be positive.} 19 | } 20 | \value{ 21 | area under curve 22 | } 23 | \description{ 24 | Based on: 25 | \url{https://blog.revolutionanalytics.com/2016/08/roc-curves-in-two-lines-of-code.html} 26 | } 27 | \examples{ 28 | 29 | sigr::calcAUC(1:4, c(TRUE,FALSE,TRUE,TRUE)) # should be 2/3 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/calcDeviance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fns.R 3 | \name{calcDeviance} 4 | \alias{calcDeviance} 5 | \title{Calculate deviance.} 6 | \usage{ 7 | calcDeviance(pred, y, na.rm = FALSE, eps = 1e-06) 8 | } 9 | \arguments{ 10 | \item{pred}{numeric predictions} 11 | 12 | \item{y}{logical truth} 13 | 14 | \item{na.rm}{logical, if TRUE remove NA values} 15 | 16 | \item{eps}{numeric, smoothing term} 17 | } 18 | \value{ 19 | deviance 20 | } 21 | \description{ 22 | Calculate deviance. 23 | } 24 | \examples{ 25 | 26 | sigr::calcDeviance(1:4,c(TRUE,FALSE,TRUE,TRUE)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/calcSSE.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fns.R 3 | \name{calcSSE} 4 | \alias{calcSSE} 5 | \title{Calculate sum of squared error.} 6 | \usage{ 7 | calcSSE(pred, y, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{pred}{numeric predictions} 11 | 12 | \item{y}{numeric truth} 13 | 14 | \item{na.rm}{logical, if TRUE remove NA values} 15 | } 16 | \value{ 17 | sum of squared error 18 | } 19 | \description{ 20 | Calculate sum of squared error. 21 | } 22 | \examples{ 23 | 24 | sigr::calcSSE(1:4,c(1,0,1,1)) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/check_utility_calc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/model_utility.R 3 | \name{check_utility_calc} 4 | \alias{check_utility_calc} 5 | \title{Check a few things we expect to be true for the utility frame.} 6 | \usage{ 7 | check_utility_calc( 8 | values, 9 | ..., 10 | orig_score = NULL, 11 | orig_outcome = NULL, 12 | constant_utilities = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{values}{model_utility result} 17 | 18 | \item{...}{Not used, forces later argument to be specified by name.} 19 | 20 | \item{constant_utilities}{logical, if TRUE assume utilities were constant per-row.} 21 | } 22 | \value{ 23 | NULL if okay, else a string describing the problem. 24 | } 25 | \description{ 26 | Utility to inspect a utility frame for some debugging. 27 | } 28 | \examples{ 29 | 30 | d <- data.frame( 31 | predicted_probability = c(0, 0.5, 0.5, 0.5), 32 | made_purchase = c(FALSE, TRUE, FALSE, FALSE), 33 | false_positive_value = -5, # acting on any predicted positive costs $5 34 | true_positive_value = 95, # revenue on a true positive is $100 minus action cost 35 | true_negative_value = 0.001, # true negatives have no value in our application 36 | # but just give ourselves a small reward for being right 37 | false_negative_value = -0.01 # adding a small notional tax for false negatives, 38 | # don't want our competitor getting these accounts. 39 | ) 40 | 41 | values <- model_utility(d, 'predicted_probability', 'made_purchase') 42 | check_utility_calc(values, 43 | orig_score = d$predicted_probability, 44 | orig_outcome = d$made_purchase) 45 | 46 | } 47 | \keyword{internal} 48 | -------------------------------------------------------------------------------- /man/estimateDifferenceZeroCrossing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EmpiricalFns.R 3 | \name{estimateDifferenceZeroCrossing} 4 | \alias{estimateDifferenceZeroCrossing} 5 | \title{Studentized estimate of how often a difference is below zero.} 6 | \usage{ 7 | estimateDifferenceZeroCrossing(resampledDiffs, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{resampledDiffs}{numeric vector resampled observations} 11 | 12 | \item{na.rm}{logical, if TRUE remove NA values} 13 | } 14 | \value{ 15 | estimated probability of seeing a re-sampled difference below zero. 16 | } 17 | \description{ 18 | Studentized estimate of how often a difference is below zero. 19 | } 20 | \examples{ 21 | 22 | set.seed(2352) 23 | resampledDiffs <- rnorm(10)+1 24 | estimateDifferenceZeroCrossing(resampledDiffs) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/find_AUC_q.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{find_AUC_q} 4 | \alias{find_AUC_q} 5 | \title{Find area matching polynomial curve.} 6 | \usage{ 7 | find_AUC_q( 8 | modelPredictions, 9 | yValues, 10 | ..., 11 | na.rm = FALSE, 12 | yTarget = TRUE, 13 | n_points = 101 14 | ) 15 | } 16 | \arguments{ 17 | \item{modelPredictions}{numeric predictions (not empty), ordered (either increasing or decreasing)} 18 | 19 | \item{yValues}{truth values (not empty, same length as model predictions)} 20 | 21 | \item{...}{force later arguments to bind by name.} 22 | 23 | \item{na.rm}{logical, if TRUE remove NA values.} 24 | 25 | \item{yTarget}{value considered to be positive.} 26 | 27 | \item{n_points}{number of points to use in estimates.} 28 | } 29 | \value{ 30 | q that such that curve 1 - (1 - (1-ideal_roc$Specificity)^q)^(1/q) matches area 31 | } 32 | \description{ 33 | Based on \url{https://win-vector.com/2020/09/13/why-working-with-auc-is-more-powerful-than-one-might-think/} 34 | } 35 | \examples{ 36 | 37 | d <- data.frame(pred = 1:4, truth = c(TRUE,FALSE,TRUE,TRUE)) 38 | q <- find_AUC_q(d$pred, d$truth) 39 | roc <- build_ROC_curve(d$pred, d$truth) 40 | ideal_roc <- data.frame(Specificity = seq(0, 1, length.out = 101)) 41 | ideal_roc$Sensitivity <- sensitivity_from_specificity_q(ideal_roc$Specificity, q) 42 | # library(ggplot2) 43 | # ggplot(mapping = aes(x = 1 - Specificity, y = Sensitivity)) + 44 | # geom_line(data = roc, color = "DarkBlue") + 45 | # geom_line(data = ideal_roc, color = "Orange") + 46 | # theme(aspect.ratio=1) + 47 | # ggtitle("example actual and ideal curve") 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/find_area_q.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{find_area_q} 4 | \alias{find_area_q} 5 | \title{Find area matching polynomial curve.} 6 | \usage{ 7 | find_area_q(area, ..., n_points = 101) 8 | } 9 | \arguments{ 10 | \item{area}{area to match} 11 | 12 | \item{...}{not used, force later arguments to bind by name} 13 | 14 | \item{n_points}{how many points to use to estimte area.} 15 | } 16 | \value{ 17 | q that such that curve \code{1 - (1 - (1-Specificity)^q)^(1/q)} matches area 18 | } 19 | \description{ 20 | Based on \url{https://win-vector.com/2020/09/13/why-working-with-auc-is-more-powerful-than-one-might-think/} 21 | } 22 | \examples{ 23 | 24 | find_area_q(0.75) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/find_matching_a1_1b.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{find_matching_a1_1b} 4 | \alias{find_matching_a1_1b} 5 | \alias{find_ROC_matching_ab1} 6 | \title{Find beta-1 shape parameters matching the conditional distributions.} 7 | \usage{ 8 | find_matching_a1_1b( 9 | modelPredictions, 10 | yValues, 11 | ..., 12 | yTarget = TRUE, 13 | step_size = 0.001 14 | ) 15 | 16 | find_ROC_matching_ab1( 17 | modelPredictions, 18 | yValues, 19 | ..., 20 | yTarget = TRUE, 21 | step_size = 0.001 22 | ) 23 | } 24 | \arguments{ 25 | \item{modelPredictions}{numeric predictions (not empty), ordered (either increasing or decreasing)} 26 | 27 | \item{yValues}{truth values (not empty, same length as model predictions)} 28 | 29 | \item{...}{force later arguments to bind by name.} 30 | 31 | \item{yTarget}{value considered to be positive.} 32 | 33 | \item{step_size}{size of steps in curve drawing} 34 | } 35 | \value{ 36 | beta curve shape parameters 37 | } 38 | \description{ 39 | Based on \doi{10.1177/0272989X15582210}. Fits a Beta(a, 1) distribuiton on 40 | positive examples and an Beta(1, b) distribution on negative examples. 41 | } 42 | \examples{ 43 | 44 | d <- rbind( 45 | data.frame(x = rbeta(1000, shape1 = 6, shape2 = 4), y = TRUE), 46 | data.frame(x = rbeta(1000, shape1 = 2, shape2 = 5), y = FALSE) 47 | ) 48 | find_ROC_matching_ab1(modelPredictions = d$x, yValues = d$y) 49 | # should be near 50 | # shape1_pos shape2_pos shape1_neg shape2_neg a b 51 | # 3.985017 1.000000 1.000000 1.746613 3.985017 1.746613 52 | # 53 | # # How to land what you want as variables 54 | # unpack[a, b] <- 55 | # find_matching_a1_1b(modelPredictions = d$x, yValues = d$y) 56 | 57 | } 58 | -------------------------------------------------------------------------------- /man/find_matching_conditional_betas.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{find_matching_conditional_betas} 4 | \alias{find_matching_conditional_betas} 5 | \alias{find_ROC_matching_ab} 6 | \title{Find beta shape parameters matching the conditional distributions.} 7 | \usage{ 8 | find_matching_conditional_betas(modelPredictions, yValues, ..., yTarget = TRUE) 9 | 10 | find_ROC_matching_ab(modelPredictions, yValues, ..., yTarget = TRUE) 11 | } 12 | \arguments{ 13 | \item{modelPredictions}{numeric predictions (not empty), ordered (either increasing or decreasing)} 14 | 15 | \item{yValues}{truth values (not empty, same length as model predictions)} 16 | 17 | \item{...}{force later arguments to bind by name.} 18 | 19 | \item{yTarget}{value considered to be positive.} 20 | } 21 | \value{ 22 | beta curve shape parameters 23 | } 24 | \description{ 25 | Based on \url{https://win-vector.com/2020/09/13/why-working-with-auc-is-more-powerful-than-one-might-think/}. Used to find 26 | one beta distribution on positive examples, and another on negative examples. 27 | } 28 | \examples{ 29 | 30 | d <- rbind( 31 | data.frame(x = rbeta(1000, shape1 = 6, shape2 = 4), y = TRUE), 32 | data.frame(x = rbeta(1000, shape1 = 2, shape2 = 3), y = FALSE) 33 | ) 34 | find_matching_conditional_betas(modelPredictions = d$x, yValues = d$y) 35 | # should be near 36 | # shape1_pos shape2_pos shape1_neg shape2_neg 37 | # 6 4 2 3 38 | # 39 | # # How to land all as variables 40 | # unpack[shape1_pos, shape2_pos, shape1_neg, shape2_neg] <- 41 | # find_ROC_matching_ab(modelPredictions = d$x, yValues = d$y) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/fit_beta_shapes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{fit_beta_shapes} 4 | \alias{fit_beta_shapes} 5 | \title{Fit beta parameters from data.} 6 | \usage{ 7 | fit_beta_shapes(x) 8 | } 9 | \arguments{ 10 | \item{x}{numeric predictions} 11 | } 12 | \value{ 13 | beta shape1, shape2 parameters in a named list 14 | } 15 | \description{ 16 | Fit shape1, shape2 using the method of moments. 17 | } 18 | \examples{ 19 | 20 | x <- rbeta(1000, shape1 = 3, shape2 = 5.5) 21 | fit_beta_shapes(x) # should often be near [3, 5.5] 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/format.sigr_statistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toPresentation.R 3 | \name{format.sigr_statistic} 4 | \alias{format.sigr_statistic} 5 | \title{Format} 6 | \usage{ 7 | \method{format}{sigr_statistic}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{sigr wrapper to print} 11 | 12 | \item{...}{extra arguments for sigr::render} 13 | } 14 | \value{ 15 | formatted string 16 | } 17 | \description{ 18 | Format 19 | } 20 | \examples{ 21 | 22 | format(wrapSignificance(1/300)) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/getRenderingFormat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fns.R 3 | \name{getRenderingFormat} 4 | \alias{getRenderingFormat} 5 | \title{Detect rendering format (using knitr).} 6 | \usage{ 7 | getRenderingFormat() 8 | } 9 | \value{ 10 | rendering format 11 | } 12 | \description{ 13 | Detect rendering format (using knitr). 14 | } 15 | \examples{ 16 | 17 | getRenderingFormat() 18 | 19 | } 20 | -------------------------------------------------------------------------------- /man/model_utility.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/model_utility.R 3 | \name{model_utility} 4 | \alias{model_utility} 5 | \title{Estimate model utility} 6 | \usage{ 7 | model_utility( 8 | d, 9 | model_name, 10 | outcome_name, 11 | ..., 12 | outcome_target = TRUE, 13 | true_positive_value_column_name = "true_positive_value", 14 | false_positive_value_column_name = "false_positive_value", 15 | true_negative_value_column_name = "true_negative_value", 16 | false_negative_value_column_name = "false_negative_value" 17 | ) 18 | } 19 | \arguments{ 20 | \item{d}{A data.frame containing all data and outcome values.} 21 | 22 | \item{model_name}{Name of the column containing model predictions.} 23 | 24 | \item{outcome_name}{Name of the column containing the truth values.} 25 | 26 | \item{...}{Not used, forces later argument to be specified by name.} 27 | 28 | \item{outcome_target}{truth value considered to be TRUE.} 29 | 30 | \item{true_positive_value_column_name}{column name of per-row values of true positive cases. Only used on positive instances.} 31 | 32 | \item{false_positive_value_column_name}{column name of per-row values of false positive cases. Only used on negative instances.} 33 | 34 | \item{true_negative_value_column_name}{column name of per-row values of true negative cases. Only used on negative instances.} 35 | 36 | \item{false_negative_value_column_name}{column name of per-row values of false negative cases. Only used on positive instances.} 37 | } 38 | \value{ 39 | data.frame of all threshold values. 40 | } 41 | \description{ 42 | Compute the utility of a model score on a classification data set. For each 43 | threshold of interest we compute the utility of the classification rule of taking all items 44 | with model score greater than or equal to the threshold. The user 45 | specifies the outcome (a binary classification target), a model 46 | score (numeric), and the utility values (positive, negative, or zero) of 47 | each case: true positives, false positives, true negatives, and 48 | false negatives. What is returned is a table of model thresholds 49 | and the total value of using this model score plus the given threshold 50 | as a classification rule. NA is used to mark a threshold where no rows 51 | are selected. 52 | } 53 | \details{ 54 | A worked example can be found here: \url{https://github.com/WinVector/sigr/blob/main/extras/UtilityExample.md}. 55 | } 56 | \examples{ 57 | 58 | d <- data.frame( 59 | predicted_probability = c(0, 0.5, 0.5, 0.5), 60 | made_purchase = c(FALSE, TRUE, FALSE, FALSE), 61 | false_positive_value = -5, # acting on any predicted positive costs $5 62 | true_positive_value = 95, # revenue on a true positive is $100 minus action cost 63 | true_negative_value = 0.001, # true negatives have no value in our application 64 | # but just give ourselves a small reward for being right 65 | false_negative_value = -0.01 # adding a small notional tax for false negatives, 66 | # don't want our competitor getting these accounts. 67 | ) 68 | 69 | values <- model_utility(d, 'predicted_probability', 'made_purchase') 70 | best_strategy <- values[values$total_value >= max(values$total_value), ][1, ] 71 | t(best_strategy) 72 | 73 | 74 | 75 | # a bigger example 76 | 77 | d <- data.frame( 78 | predicted_probability = stats::runif(100), 79 | made_purchase = sample(c(FALSE, TRUE), replace = TRUE, size = 100), 80 | false_positive_value = -5, # acting on any predicted positive costs $5 81 | true_positive_value = 95, # revenue on a true positive is $100 minus action cost 82 | true_negative_value = 0.001, # true negatives have no value in our application 83 | # but just give ourselves a small reward for being right 84 | false_negative_value = -0.01 # adding a small notional tax for false negatives, 85 | # don't want our competitor getting these accounts. 86 | ) 87 | 88 | values <- model_utility(d, 'predicted_probability', 'made_purchase') 89 | 90 | # plot the estimated total utility as a function of threshold 91 | plot(values$threshold, values$total_value) 92 | 93 | best_strategy <- values[values$total_value >= max(values$total_value), ][1, ] 94 | t(best_strategy) 95 | 96 | 97 | # without utilities example 98 | 99 | d <- data.frame( 100 | predicted_probability = c(0, 0.5, 0.5, 0.5), 101 | made_purchase = c(FALSE, TRUE, FALSE, FALSE)) 102 | model_utility(d, 'predicted_probability', 'made_purchase') 103 | 104 | } 105 | -------------------------------------------------------------------------------- /man/permTestAUC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCTest.R 3 | \name{permTestAUC} 4 | \alias{permTestAUC} 5 | \title{Perform AUC permutation test.} 6 | \usage{ 7 | permTestAUC( 8 | d, 9 | modelName, 10 | yName, 11 | yTarget = TRUE, 12 | ..., 13 | na.rm = FALSE, 14 | returnScores = FALSE, 15 | nrep = 100, 16 | parallelCluster = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{d}{data.frame} 21 | 22 | \item{modelName}{character model column name} 23 | 24 | \item{yName}{character outcome column name} 25 | 26 | \item{yTarget}{target to match to y} 27 | 28 | \item{...}{extra arguments (not used)} 29 | 30 | \item{na.rm}{logical, if TRUE remove NA values} 31 | 32 | \item{returnScores}{logical if TRUE return detailed permutedScores} 33 | 34 | \item{nrep}{number of permutation repetitions to estimate p values.} 35 | 36 | \item{parallelCluster}{(optional) a cluster object created by package parallel or package snow} 37 | } 38 | \value{ 39 | AUC statistic 40 | } 41 | \description{ 42 | Estimate significance of AUC by permutation test. 43 | } 44 | \examples{ 45 | 46 | set.seed(25325) 47 | d <- data.frame(x1=c(1,2,3,4,5,6,7,7), 48 | y=c(FALSE,TRUE,FALSE,FALSE, 49 | TRUE,TRUE,FALSE,TRUE)) 50 | permTestAUC(d,'x1','y',TRUE) 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /man/permutationScoreModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EmpiricalFns.R 3 | \name{permutationScoreModel} 4 | \alias{permutationScoreModel} 5 | \title{Empirical permutation test of significance of scoreFn(modelValues,yValues) >= scoreFn(modelValues,perm(yValues)).} 6 | \usage{ 7 | permutationScoreModel( 8 | modelValues, 9 | yValues, 10 | scoreFn, 11 | ..., 12 | na.rm = FALSE, 13 | returnScores = FALSE, 14 | nRep = 100, 15 | parallelCluster = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{modelValues}{numeric array of predictions.} 20 | 21 | \item{yValues}{numeric/logical array of outcomes, dependent, or truth values} 22 | 23 | \item{scoreFn}{function with signature scoreFn(modelValues,yValues) returning scalar numeric score.} 24 | 25 | \item{...}{not used, forces later arguments to be bound by name} 26 | 27 | \item{na.rm}{logical, if TRUE remove NA values} 28 | 29 | \item{returnScores}{logical if TRUE return detailed permutedScores} 30 | 31 | \item{nRep}{integer number of repititions to perform} 32 | 33 | \item{parallelCluster}{optional snow-style parallel cluster.} 34 | } 35 | \value{ 36 | summaries 37 | } 38 | \description{ 39 | Treat permutation re-samples as similar to bootstrap replications. 40 | } 41 | \examples{ 42 | 43 | set.seed(25325) 44 | y <- 1:5 45 | m <- c(1,1,2,2,2) 46 | cor.test(m,y,alternative='greater') 47 | f <- function(modelValues,yValues) cor(modelValues,yValues) 48 | permutationScoreModel(m,y,f) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /man/print.sigr_statistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toPresentation.R 3 | \name{print.sigr_statistic} 4 | \alias{print.sigr_statistic} 5 | \title{Print} 6 | \usage{ 7 | \method{print}{sigr_statistic}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{sigr wrapper to print} 11 | 12 | \item{...}{extra arguments for sigr::render and print} 13 | } 14 | \value{ 15 | formatted string 16 | } 17 | \description{ 18 | Print 19 | } 20 | \examples{ 21 | 22 | print(wrapSignificance(1/300)) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rexport.R, R/wrapr_exports.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{\%.>\%} 7 | \alias{let} 8 | \alias{qc} 9 | \alias{build_frame} 10 | \alias{draw_frame} 11 | \alias{qchar_frame} 12 | \alias{apply_left} 13 | \alias{apply_right} 14 | \alias{mk_tmp_name_source} 15 | \alias{map_to_char} 16 | \alias{qe} 17 | \alias{qae} 18 | \alias{\%:=\%} 19 | \title{Objects exported from other packages} 20 | \keyword{internal} 21 | \description{ 22 | These objects are imported from other packages. Follow the links 23 | below to see their documentation. 24 | 25 | \describe{ 26 | \item{wrapr}{\code{\link[wrapr:named_map_builder]{\%:=\%}}, \code{\link[wrapr:dot_arrow]{\%.>\%}}, \code{\link[wrapr:dot_arrow]{\%.>\%}}, \code{\link[wrapr]{apply_left}}, \code{\link[wrapr]{apply_right}}, \code{\link[wrapr]{build_frame}}, \code{\link[wrapr]{build_frame}}, \code{\link[wrapr]{draw_frame}}, \code{\link[wrapr]{draw_frame}}, \code{\link[wrapr]{let}}, \code{\link[wrapr]{let}}, \code{\link[wrapr]{map_to_char}}, \code{\link[wrapr]{mk_tmp_name_source}}, \code{\link[wrapr]{qae}}, \code{\link[wrapr]{qc}}, \code{\link[wrapr]{qc}}, \code{\link[wrapr]{qchar_frame}}, \code{\link[wrapr]{qchar_frame}}, \code{\link[wrapr]{qe}}} 27 | }} 28 | 29 | -------------------------------------------------------------------------------- /man/render.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toPresentation.R 3 | \name{render} 4 | \alias{render} 5 | \title{Format summary roughly in "APA Style" ( American Psychological Association ).} 6 | \usage{ 7 | render( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{sigr summary statistic} 19 | 20 | \item{...}{extra arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format summary roughly in "APA Style" ( American Psychological Association ). 37 | } 38 | \seealso{ 39 | \code{\link{render.sigr_significance}}, \code{\link{render.sigr_ftest}} 40 | } 41 | -------------------------------------------------------------------------------- /man/render.sigr_Bernoulli_diff_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DifferenceDistribution.R 3 | \name{render.sigr_Bernoulli_diff_test} 4 | \alias{render.sigr_Bernoulli_diff_test} 5 | \title{Format sigr_Bernoulli_diff_test (test of difference of Bernoulli processes).} 6 | \usage{ 7 | \method{render}{sigr_Bernoulli_diff_test}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped cor.test.} 19 | 20 | \item{...}{extra arguments (not used)} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format sigr_Bernoulli_diff_test (test of difference of Bernoulli processes). 37 | } 38 | \examples{ 39 | 40 | Bernoulli_diff_stat(2000, 5000, 100, 200) 41 | Bernoulli_diff_stat(2000, 5000, 100, 200, 0.1) 42 | Bernoulli_diff_stat(2000, 5000, 100, 199) 43 | Bernoulli_diff_stat(2000, 5000, 100, 199, 0.1) 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/render.sigr_aucpairtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCTest.R 3 | \name{render.sigr_aucpairtest} 4 | \alias{render.sigr_aucpairtest} 5 | \title{Format an AUC-test (quality of a probability score)} 6 | \usage{ 7 | \method{render}{sigr_aucpairtest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped AUC test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format an AUC-test (quality of a probability score) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_aucpermtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCTest.R 3 | \name{render.sigr_aucpermtest} 4 | \alias{render.sigr_aucpermtest} 5 | \title{Format an AUC-test (quality of a probability score)} 6 | \usage{ 7 | \method{render}{sigr_aucpermtest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped AUC test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format an AUC-test (quality of a probability score) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_aucresamptest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCTest.R 3 | \name{render.sigr_aucresamptest} 4 | \alias{render.sigr_aucresamptest} 5 | \title{Format an AUC-test (quality of a probability score)} 6 | \usage{ 7 | \method{render}{sigr_aucresamptest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped AUC test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format an AUC-test (quality of a probability score) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_binomtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{render.sigr_binomtest} 4 | \alias{render.sigr_binomtest} 5 | \title{Format binom.test (test of rate of a Binomial/Bernoulli experiment).} 6 | \usage{ 7 | \method{render}{sigr_binomtest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped binom.test.} 19 | 20 | \item{...}{extra arguments (not used)} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format binom.test (test of rate of a Binomial/Bernoulli experiment). 37 | } 38 | \examples{ 39 | 40 | bt <- binom.test(7, 10, 0.5) 41 | wrapBinomTest(bt) 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/render.sigr_chisqtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{render.sigr_chisqtest} 4 | \alias{render.sigr_chisqtest} 5 | \title{Format a chi-square test (quality of categorical prediction)} 6 | \usage{ 7 | \method{render}{sigr_chisqtest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped T-test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format a chi-square test (quality of categorical prediction) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_cohend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CohenD.R 3 | \name{render.sigr_cohend} 4 | \alias{render.sigr_cohend} 5 | \title{Format Cohen-D (effect size between groups)} 6 | \usage{ 7 | \method{render}{sigr_cohend}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 1, 14 | pSmallCutoff = 0 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{CohenD-approximation} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format Cohen-D (effect size between groups) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_cortest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CorTest.R 3 | \name{render.sigr_cortest} 4 | \alias{render.sigr_cortest} 5 | \title{Format cor.test (test of liner correlation).} 6 | \usage{ 7 | \method{render}{sigr_cortest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped cor.test.} 19 | 20 | \item{...}{extra arguments (not used)} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format cor.test (test of liner correlation). 37 | } 38 | \examples{ 39 | 40 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 41 | y=c(1,1,2,2,3,3,4,4)) 42 | ct <- cor.test(d$x,d$y) 43 | wrapCorTest(ct) 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/render.sigr_emptest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EmpiricalFns.R 3 | \name{render.sigr_emptest} 4 | \alias{render.sigr_emptest} 5 | \title{Format an empirical test (quality of categorical prediction)} 6 | \usage{ 7 | \method{render}{sigr_emptest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped T-test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format an empirical test (quality of categorical prediction) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_fishertest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FisherTest.R 3 | \name{render.sigr_fishertest} 4 | \alias{render.sigr_fishertest} 5 | \title{Format fisher.test (test of categorical independence).} 6 | \usage{ 7 | \method{render}{sigr_fishertest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped Fisher test} 19 | 20 | \item{...}{extra arguments (not used)} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string and fields 34 | } 35 | \description{ 36 | Format fisher.test (test of categorical independence). 37 | } 38 | \examples{ 39 | 40 | d <- data.frame(x=c('b','a','a','a','b','b','b'), 41 | y=c('1','1','1','2','2','2','2')) 42 | ft <- fisher.test(table(d)) 43 | wrapFisherTest(ft) 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/render.sigr_ftest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{render.sigr_ftest} 4 | \alias{render.sigr_ftest} 5 | \title{Format an F-test} 6 | \usage{ 7 | \method{render}{sigr_ftest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format an F-test 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_permtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EmpiricalFns.R 3 | \name{render.sigr_permtest} 4 | \alias{render.sigr_permtest} 5 | \title{Format an empirical test (quality of categorical prediction)} 6 | \usage{ 7 | \method{render}{sigr_permtest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped T-test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summary.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format an empirical test (quality of categorical prediction) 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_pwr_htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pwr.R 3 | \name{render.sigr_pwr_htest} 4 | \alias{render.sigr_pwr_htest} 5 | \title{Format a pwr-test} 6 | \usage{ 7 | \method{render}{sigr_pwr_htest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 1, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped test from pwr package} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format a pwr-test 37 | } 38 | -------------------------------------------------------------------------------- /man/render.sigr_significance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toPresentation.R 3 | \name{render.sigr_significance} 4 | \alias{render.sigr_significance} 5 | \title{Format a significance} 6 | \usage{ 7 | \method{render}{sigr_significance}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped significance} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries (not used in significance reports).} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format a significance 37 | } 38 | \examples{ 39 | 40 | cat(render(wrapSignificance(1/300),format='html')) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/render.sigr_tinterval.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TInterval.R 3 | \name{render.sigr_tinterval} 4 | \alias{render.sigr_tinterval} 5 | \title{Format a Student-T tolerance-style interval around an estimate of a mean.} 6 | \usage{ 7 | \method{render}{sigr_tinterval}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped TInterval.} 19 | 20 | \item{...}{extra arguments (not used)} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Report sample size (n), sample mean, bias-corrected standard deviation estimate 37 | (assuming normality, using a chi-square distribution correction 38 | from \url{https://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation#Bias_correction}), 39 | and a Student t-test tolerance-style confidence interval. 40 | } 41 | \examples{ 42 | 43 | set.seed(2018) 44 | d <- rnorm(100) + 3.2 45 | TInterval(d) 46 | 47 | } 48 | -------------------------------------------------------------------------------- /man/render.sigr_ttest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TTest.R 3 | \name{render.sigr_ttest} 4 | \alias{render.sigr_ttest} 5 | \title{Format a T-test (difference in means by group)} 6 | \usage{ 7 | \method{render}{sigr_ttest}( 8 | statistic, 9 | ..., 10 | format, 11 | statDigits = 4, 12 | sigDigits = 4, 13 | pLargeCutoff = 0.05, 14 | pSmallCutoff = 1e-05 15 | ) 16 | } 17 | \arguments{ 18 | \item{statistic}{wrapped T-test} 19 | 20 | \item{...}{not used, force use of named binding for later arguments} 21 | 22 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii")} 23 | 24 | \item{statDigits}{integer number of digits to show in summaries.} 25 | 26 | \item{sigDigits}{integer number of digits to show in significances.} 27 | 28 | \item{pLargeCutoff}{value to declare non-significance at or above.} 29 | 30 | \item{pSmallCutoff}{smallest value to print} 31 | } 32 | \value{ 33 | formatted string 34 | } 35 | \description{ 36 | Format a T-test (difference in means by group) 37 | } 38 | -------------------------------------------------------------------------------- /man/resampleScoreModel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EmpiricalFns.R 3 | \name{resampleScoreModel} 4 | \alias{resampleScoreModel} 5 | \title{Studentized bootstrap variance estimate for scoreFn(yValues,modelValues).} 6 | \usage{ 7 | resampleScoreModel( 8 | modelValues, 9 | yValues, 10 | scoreFn, 11 | ..., 12 | na.rm = FALSE, 13 | returnScores = FALSE, 14 | nRep = 100, 15 | parallelCluster = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{modelValues}{numeric array of predictions (model to test).} 20 | 21 | \item{yValues}{numeric/logical array of outcomes, dependent, or truth values} 22 | 23 | \item{scoreFn}{function with signature scoreFn(modelValues,yValues) returning scalar numeric score.} 24 | 25 | \item{...}{not used, forces later arguments to be bound by name} 26 | 27 | \item{na.rm}{logical, if TRUE remove NA values} 28 | 29 | \item{returnScores}{logical if TRUE return detailed resampledScores} 30 | 31 | \item{nRep}{integer number of repititions to perform} 32 | 33 | \item{parallelCluster}{optional snow-style parallel cluster.} 34 | } 35 | \value{ 36 | summaries 37 | } 38 | \description{ 39 | Studentized bootstrap variance estimate for scoreFn(yValues,modelValues). 40 | } 41 | \examples{ 42 | 43 | set.seed(25325) 44 | y <- 1:5 45 | m1 <- c(1,1,2,2,2) 46 | cor.test(m1,y,alternative='greater') 47 | f <- function(modelValues,yValues) { 48 | if((sd(modelValues)<=0)||(sd(yValues)<=0)) { 49 | return(0) 50 | } 51 | cor(modelValues,yValues) 52 | } 53 | s <- sigr::resampleScoreModel(m1,y,f) 54 | print(s) 55 | z <- (s$observedScore-0)/s$sd # should check size of z relative to bias! 56 | pValue <- pt(z,df=length(y)-2,lower.tail=FALSE) 57 | pValue 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /man/resampleScoreModelPair.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/EmpiricalFns.R 3 | \name{resampleScoreModelPair} 4 | \alias{resampleScoreModelPair} 5 | \title{Studentized bootstrap test of strength of scoreFn(yValues,model1Values) > scoreFn(yValues,model1Values).} 6 | \usage{ 7 | resampleScoreModelPair( 8 | model1Values, 9 | model2Values, 10 | yValues, 11 | scoreFn, 12 | ..., 13 | na.rm = FALSE, 14 | returnScores = FALSE, 15 | nRep = 100, 16 | parallelCluster = NULL, 17 | sameSample = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{model1Values}{numeric array of predictions (model to test).} 22 | 23 | \item{model2Values}{numeric array of predictions (reference model).} 24 | 25 | \item{yValues}{numeric/logical array of outcomes, dependent, or truth values} 26 | 27 | \item{scoreFn}{function with signature scoreFn(modelValues,yValues) returning scalar numeric score.} 28 | 29 | \item{...}{not used, forces later arguments to be bound by name.} 30 | 31 | \item{na.rm}{logical, if TRUE remove NA values} 32 | 33 | \item{returnScores}{logical if TRUE return detailed resampledScores.} 34 | 35 | \item{nRep}{integer number of repititions to perform.} 36 | 37 | \item{parallelCluster}{optional snow-style parallel cluster.} 38 | 39 | \item{sameSample}{logical if TRUE use the same sample in computing both scores during bootstrap replication (else use independent samples).} 40 | } 41 | \value{ 42 | summaries 43 | } 44 | \description{ 45 | Studentized bootstrap test of strength of scoreFn(yValues,model1Values) > scoreFn(yValues,model1Values) 46 | sampled with replacement. 47 | } 48 | \details{ 49 | True confidence intervals are harder to get right (see 50 | "An Introduction to the Bootstrap", Bradely Efron, 51 | and Robert J. Tibshirani, Chapman & Hall/CRC, 1993.), 52 | but we will settle for simple p-value estimates. 53 | } 54 | \examples{ 55 | 56 | set.seed(25325) 57 | y <- 1:5 58 | m1 <- c(1,1,2,2,2) 59 | m2 <- c(1,1,1,1,2) 60 | cor(m1,y) 61 | cor(m2,y) 62 | f <- function(modelValues,yValues) { 63 | if((sd(modelValues)<=0)||(sd(yValues)<=0)) { 64 | return(0) 65 | } 66 | cor(modelValues,yValues) 67 | } 68 | resampleScoreModelPair(m1,m2,y,f) 69 | 70 | } 71 | -------------------------------------------------------------------------------- /man/resampleTestAUC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCTest.R 3 | \name{resampleTestAUC} 4 | \alias{resampleTestAUC} 5 | \title{Wrap AUC resampling test results.} 6 | \usage{ 7 | resampleTestAUC( 8 | d, 9 | modelName, 10 | yName, 11 | yTarget = TRUE, 12 | ..., 13 | na.rm = FALSE, 14 | returnScores = FALSE, 15 | nrep = 100, 16 | parallelCluster = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{d}{data.frame} 21 | 22 | \item{modelName}{character model column name} 23 | 24 | \item{yName}{character outcome column name} 25 | 26 | \item{yTarget}{target to match to y} 27 | 28 | \item{...}{extra arguments (not used)} 29 | 30 | \item{na.rm}{logical, if TRUE remove NA values} 31 | 32 | \item{returnScores}{logical if TRUE return detailed resampledScores.} 33 | 34 | \item{nrep}{number of permutation repetitions to estimate p values.} 35 | 36 | \item{parallelCluster}{(optional) a cluster object created by package parallel or package snow.} 37 | } 38 | \value{ 39 | AUC statistic 40 | } 41 | \description{ 42 | Estimate significance of AUC by resampling test. 43 | } 44 | \examples{ 45 | 46 | set.seed(25325) 47 | d <- data.frame(x1=c(1,2,3,4,5,6,7,7), 48 | y=c(FALSE,TRUE,FALSE,FALSE, 49 | TRUE,TRUE,FALSE,TRUE)) 50 | resampleTestAUC(d,'x1','y',TRUE) 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /man/sensitivity_and_specificity_s12p12n.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{sensitivity_and_specificity_s12p12n} 4 | \alias{sensitivity_and_specificity_s12p12n} 5 | \title{Compute the shape1_pos, shape2_pos, shape1_neg, shape2_neg graph.} 6 | \usage{ 7 | sensitivity_and_specificity_s12p12n( 8 | Score, 9 | ..., 10 | shape1_pos, 11 | shape2_pos, 12 | shape1_neg, 13 | shape2_neg 14 | ) 15 | } 16 | \arguments{ 17 | \item{Score}{vector of sensitivities to evaluate} 18 | 19 | \item{...}{force later arguments to bind by name.} 20 | 21 | \item{shape1_pos}{beta shape1 parameter for positive examples} 22 | 23 | \item{shape2_pos}{beta shape2 parameter for positive examples} 24 | 25 | \item{shape1_neg}{beta shape1 parameter for negative examples} 26 | 27 | \item{shape2_neg}{beta shape1 parameter for negative examples} 28 | } 29 | \value{ 30 | Score, Specificity and Sensitivity data frame 31 | } 32 | \description{ 33 | Compute specificity and sensitivity given specificity and model fit parameters. 34 | } 35 | \examples{ 36 | 37 | library(wrapr) 38 | 39 | empirical_data <- rbind( 40 | data.frame( 41 | Score = rbeta(1000, shape1 = 3, shape2 = 2), 42 | y = TRUE), 43 | data.frame( 44 | Score = rbeta(1000, shape1 = 5, shape2 = 4), 45 | y = FALSE) 46 | ) 47 | 48 | unpack[shape1_pos = shape1, shape2_pos = shape2] <- 49 | fit_beta_shapes(empirical_data$Score[empirical_data$y]) 50 | 51 | shape1_pos 52 | shape2_pos 53 | 54 | unpack[shape1_neg = shape1, shape2_neg = shape2] <- 55 | fit_beta_shapes(empirical_data$Score[!empirical_data$y]) 56 | 57 | shape1_neg 58 | shape2_neg 59 | 60 | ideal_roc <- sensitivity_and_specificity_s12p12n( 61 | seq(0, 1, 0.1), 62 | shape1_pos = shape1_pos, 63 | shape1_neg = shape1_neg, 64 | shape2_pos = shape2_pos, 65 | shape2_neg = shape2_neg) 66 | 67 | 68 | empirical_roc <- build_ROC_curve( 69 | modelPredictions = empirical_data$Score, 70 | yValues = empirical_data$y 71 | ) 72 | 73 | # # should look very similar 74 | # library(ggplot2) 75 | # ggplot(mapping = aes(x = 1 - Specificity, y = Sensitivity)) + 76 | # geom_line(data = empirical_roc, color='DarkBlue') + 77 | # geom_line(data = ideal_roc, color = 'Orange') 78 | 79 | } 80 | -------------------------------------------------------------------------------- /man/sensitivity_from_specificity_q.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ROC.R 3 | \name{sensitivity_from_specificity_q} 4 | \alias{sensitivity_from_specificity_q} 5 | \title{Compute the q-graph.} 6 | \usage{ 7 | sensitivity_from_specificity_q(Specificity, q) 8 | } 9 | \arguments{ 10 | \item{Specificity}{vector of sensitivities to evaluate} 11 | 12 | \item{q}{shape parameter for \code{1 - (1 - (1-Specificity)^q)^(1/q)}} 13 | } 14 | \value{ 15 | Sensitivity 16 | } 17 | \description{ 18 | Based on: 19 | \url{https://blog.revolutionanalytics.com/2016/08/roc-curves-in-two-lines-of-code.html} 20 | } 21 | \examples{ 22 | 23 | sensitivity_from_specificity_q(seq(0, 1, 0.1), 0.61) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/sigr-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sigr.R 3 | \docType{package} 4 | \name{sigr-package} 5 | \alias{sigr} 6 | \alias{sigr-package} 7 | \title{sigr: Format Significance Summaries for Reports} 8 | \description{ 9 | Succinctly format significance summaries of 10 | various models and tests (F-test, Chi-Sq-test, Fisher-test, T-test, and rank-significance). The main purpose is unified reporting and planning 11 | of experimental results, working around issue such as the difficulty of 12 | extracting model summary facts (such as with 'lm'/'glm'). This package also 13 | includes empirical tests, such as bootstrap estimates. 14 | } 15 | \details{ 16 | To learn more about sigr, please start with the vignette: 17 | \code{vignette('sigrFormatting','sigr')} 18 | } 19 | \seealso{ 20 | Useful links: 21 | \itemize{ 22 | \item \url{https://github.com/WinVector/sigr/} 23 | \item \url{https://winvector.github.io/sigr/} 24 | \item Report bugs at \url{https://github.com/WinVector/sigr/issues} 25 | } 26 | 27 | } 28 | \author{ 29 | \strong{Maintainer}: John Mount \email{jmount@win-vector.com} 30 | 31 | Authors: 32 | \itemize{ 33 | \item Nina Zumel \email{nzumel@win-vector.com} 34 | } 35 | 36 | Other contributors: 37 | \itemize{ 38 | \item Win-Vector LLC [copyright holder] 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/testAUCpair.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCTest.R 3 | \name{testAUCpair} 4 | \alias{testAUCpair} 5 | \title{Test AUC pair results.} 6 | \usage{ 7 | testAUCpair( 8 | d, 9 | model1Name, 10 | model2Name, 11 | yName, 12 | yTarget = TRUE, 13 | ..., 14 | na.rm = FALSE, 15 | returnScores = FALSE, 16 | nrep = 100, 17 | parallelCluster = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{d}{data.frame} 22 | 23 | \item{model1Name}{character model 1 column name} 24 | 25 | \item{model2Name}{character model 2 column name} 26 | 27 | \item{yName}{character outcome column name} 28 | 29 | \item{yTarget}{target to match to y} 30 | 31 | \item{...}{extra arguments (not used)} 32 | 33 | \item{na.rm}{logical, if TRUE remove NA values} 34 | 35 | \item{returnScores}{logical if TRUE return detailed resampledScores} 36 | 37 | \item{nrep}{number of re-sample repetition to estimate p value.} 38 | 39 | \item{parallelCluster}{(optional) a cluster object created by package parallel or package snow} 40 | } 41 | \value{ 42 | AUC pair test 43 | } 44 | \description{ 45 | Estimate significance of difference in two AUCs by resampling. 46 | } 47 | \examples{ 48 | 49 | set.seed(25325) 50 | d <- data.frame(x1=c(1,2,3,4,5,6,7,7), 51 | x2=1, 52 | y=c(FALSE,TRUE,FALSE,FALSE, 53 | TRUE,TRUE,FALSE,TRUE)) 54 | testAUCpair(d,'x1','x2','y',TRUE) 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /man/wrapBinomTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{wrapBinomTest} 4 | \alias{wrapBinomTest} 5 | \title{Wrap binom.test (test of Binomial/Bernoulli rate).} 6 | \usage{ 7 | wrapBinomTest(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or test.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap binom.test (test of Binomial/Bernoulli rate). 16 | } 17 | \seealso{ 18 | \code{\link{wrapBinomTest.htest}}, \code{\link{wrapBinomTestS}}, \code{\link{wrapBinomTest.logical}}, \code{\link{wrapBinomTest.numeric}}, \code{\link{wrapBinomTest.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapBinomTest.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{wrapBinomTest.data.frame} 4 | \alias{wrapBinomTest.data.frame} 5 | \title{Wrap binom.test (test of Binomial/Bernoulli rate).} 6 | \usage{ 7 | \method{wrapBinomTest}{data.frame}( 8 | x, 9 | ColumnName, 10 | SuccessValue = TRUE, 11 | ..., 12 | p = NA, 13 | alternative = c("two.sided", "less", "greater"), 14 | conf.level = 0.95, 15 | na.rm = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{data.frame} 20 | 21 | \item{ColumnName}{character name of measurment column} 22 | 23 | \item{SuccessValue}{value considered a success (positive)} 24 | 25 | \item{...}{extra arguments passed to binom.test} 26 | 27 | \item{p}{number, hypothesized probability of success.} 28 | 29 | \item{alternative}{passed to \code{\link[stats]{binom.test}}} 30 | 31 | \item{conf.level}{passed to \code{\link[stats]{binom.test}}} 32 | 33 | \item{na.rm}{logical, if TRUE remove NA values} 34 | } 35 | \value{ 36 | wrapped stat 37 | } 38 | \description{ 39 | Wrap binom.test (test of Binomial/Bernoulli rate). 40 | } 41 | \examples{ 42 | 43 | d <- data.frame(x = c(rep(0, 3), rep(1, 7))) 44 | wrapBinomTest(d, "x", 1, p = 0.5) 45 | d <- data.frame(x = c(rep(0, 15), rep(1, 35))) 46 | wrapBinomTest(d, "x", 1, p = 0.5) 47 | 48 | 49 | } 50 | \seealso{ 51 | \code{\link{wrapBinomTest}}, \code{\link{wrapBinomTest.htest}}, \code{\link{wrapBinomTestS}}, \code{\link{wrapBinomTest.logical}}, \code{\link{wrapBinomTest.numeric}}, \code{\link{wrapBinomTest.data.frame}} 52 | } 53 | -------------------------------------------------------------------------------- /man/wrapBinomTest.htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{wrapBinomTest.htest} 4 | \alias{wrapBinomTest.htest} 5 | \title{Wrap binom.test (test of Binomial/Bernoulli rate).} 6 | \usage{ 7 | \method{wrapBinomTest}{htest}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{binom.test result} 11 | 12 | \item{...}{not used, just for argument compatibility} 13 | } 14 | \value{ 15 | wrapped stat 16 | } 17 | \description{ 18 | Wrap binom.test (test of Binomial/Bernoulli rate). 19 | } 20 | \examples{ 21 | 22 | bt <- binom.test(7, 10, 0.5) 23 | wrapBinomTest(bt) 24 | 25 | } 26 | \seealso{ 27 | \code{\link{wrapBinomTest}}, \code{\link{wrapBinomTest.htest}}, \code{\link{wrapBinomTestS}}, \code{\link{wrapBinomTest.logical}}, \code{\link{wrapBinomTest.numeric}}, \code{\link{wrapBinomTest.data.frame}} 28 | } 29 | -------------------------------------------------------------------------------- /man/wrapBinomTest.logical.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{wrapBinomTest.logical} 4 | \alias{wrapBinomTest.logical} 5 | \title{Wrap binom.test (test of Binomial/Bernoulli rate).} 6 | \usage{ 7 | \method{wrapBinomTest}{logical}( 8 | x, 9 | ..., 10 | p = NA, 11 | alternative = c("two.sided", "less", "greater"), 12 | conf.level = 0.95, 13 | na.rm = FALSE 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{logical, vector of trials.} 18 | 19 | \item{...}{extra arguments passed to binom.test} 20 | 21 | \item{p}{number, hypothesized probability of success.} 22 | 23 | \item{alternative}{passed to \code{\link[stats]{binom.test}}} 24 | 25 | \item{conf.level}{passed to \code{\link[stats]{binom.test}}} 26 | 27 | \item{na.rm}{logical, if TRUE remove NA values} 28 | } 29 | \value{ 30 | wrapped stat 31 | } 32 | \description{ 33 | Wrap binom.test (test of Binomial/Bernoulli rate). 34 | } 35 | \examples{ 36 | 37 | x = c(rep(FALSE, 3), rep(TRUE, 7)) 38 | wrapBinomTest(x) 39 | x = c(rep(FALSE, 15), rep(TRUE, 35)) 40 | wrapBinomTest(x) 41 | 42 | 43 | } 44 | \seealso{ 45 | \code{\link{wrapBinomTest}}, \code{\link{wrapBinomTest.htest}}, \code{\link{wrapBinomTestS}}, \code{\link{wrapBinomTest.logical}}, \code{\link{wrapBinomTest.numeric}}, \code{\link{wrapBinomTest.data.frame}} 46 | } 47 | -------------------------------------------------------------------------------- /man/wrapBinomTest.numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{wrapBinomTest.numeric} 4 | \alias{wrapBinomTest.numeric} 5 | \title{Wrap binom.test (test of Binomial/Bernoulli rate).} 6 | \usage{ 7 | \method{wrapBinomTest}{numeric}( 8 | x, 9 | SuccessValue = TRUE, 10 | ..., 11 | p = NA, 12 | alternative = c("two.sided", "less", "greater"), 13 | conf.level = 0.95, 14 | na.rm = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{x}{numeric, vector of trials.} 19 | 20 | \item{SuccessValue}{value considered a success (positive)} 21 | 22 | \item{...}{extra arguments passed to binom.test} 23 | 24 | \item{p}{number, hypothesized probability of success.} 25 | 26 | \item{alternative}{passed to \code{\link[stats]{binom.test}}} 27 | 28 | \item{conf.level}{passed to \code{\link[stats]{binom.test}}} 29 | 30 | \item{na.rm}{logical, if TRUE remove NA values} 31 | } 32 | \value{ 33 | wrapped stat 34 | } 35 | \description{ 36 | Wrap binom.test (test of Binomial/Bernoulli rate). 37 | } 38 | \examples{ 39 | 40 | x = c(rep(0, 3), rep(1, 7)) 41 | wrapBinomTest(x, 1) 42 | x = c(rep(0, 15), rep(1, 35)) 43 | wrapBinomTest(x, 1) 44 | 45 | 46 | } 47 | \seealso{ 48 | \code{\link{wrapBinomTest}}, \code{\link{wrapBinomTest.htest}}, \code{\link{wrapBinomTestS}}, \code{\link{wrapBinomTest.logical}}, \code{\link{wrapBinomTest.numeric}}, \code{\link{wrapBinomTest.data.frame}} 49 | } 50 | -------------------------------------------------------------------------------- /man/wrapBinomTestS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BinomTest.R 3 | \name{wrapBinomTestS} 4 | \alias{wrapBinomTestS} 5 | \title{Wrap binom.test (test of Binomial/Bernoulli rate) from summary.} 6 | \usage{ 7 | wrapBinomTestS( 8 | x, 9 | n, 10 | ..., 11 | p = NA, 12 | alternative = c("two.sided", "less", "greater"), 13 | conf.level = 0.95 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{numeric scalar, number of successes.} 18 | 19 | \item{n}{numeric scalar, number of trials.} 20 | 21 | \item{...}{extra arguments passed to binom.test} 22 | 23 | \item{p}{number, hypothesized probability of success.} 24 | 25 | \item{alternative}{passed to \code{\link[stats]{binom.test}}} 26 | 27 | \item{conf.level}{passed to \code{\link[stats]{binom.test}}} 28 | } 29 | \value{ 30 | wrapped stat 31 | } 32 | \description{ 33 | Wrap binom.test (test of Binomial/Bernoulli rate) from summary. 34 | } 35 | \examples{ 36 | 37 | wrapBinomTestS(3, 7, p = 0.5) 38 | wrapBinomTestS(300, 700, p = 0.5) 39 | 40 | 41 | } 42 | \seealso{ 43 | \code{\link{wrapBinomTest}}, \code{\link{wrapBinomTest.htest}}, \code{\link{wrapBinomTestS}}, \code{\link{wrapBinomTest.logical}}, \code{\link{wrapBinomTest.numeric}}, \code{\link{wrapBinomTest.data.frame}} 44 | } 45 | -------------------------------------------------------------------------------- /man/wrapChiSqTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{wrapChiSqTest} 4 | \alias{wrapChiSqTest} 5 | \title{Wrap quality of a categorical prediction roughly in "APA Style" ( American Psychological Association ).} 6 | \usage{ 7 | wrapChiSqTest(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or lm where to get model or data to score.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap quality of a categorical prediction roughly in "APA Style" ( American Psychological Association ). 16 | } 17 | \seealso{ 18 | \code{\link{wrapChiSqTestImpl}}, \code{\link{wrapChiSqTest.glm}}, and \code{\link{wrapChiSqTest.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapChiSqTest.anova.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{wrapChiSqTest.anova} 4 | \alias{wrapChiSqTest.anova} 5 | \title{Format ChiSqTest from anova of logistic model.} 6 | \usage{ 7 | \method{wrapChiSqTest}{anova}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{result from stats::anova(stats::glm(family=binomial))} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | list of formatted string and fields 16 | } 17 | \description{ 18 | Format ChiSqTest from anova of logistic model. 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x1= c(1,2,3,4,5,6,7,7), 23 | x2= c(1,0,3,0,5,0,7,0), 24 | y= c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 25 | model <- glm(y~x1+x2, data=d, family=binomial) 26 | summary(model) 27 | render(wrapChiSqTest(model), 28 | pLargeCutoff=1, format='ascii') 29 | anov <- anova(model) 30 | print(anov) 31 | lapply(sigr::wrapChiSqTest(anov), 32 | function(ti) { 33 | sigr::render(ti, 34 | pLargeCutoff= 1, 35 | pSmallCutoff= 0, 36 | statDigits=4, 37 | sigDigits=4, 38 | format='ascii') 39 | }) 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/wrapChiSqTest.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{wrapChiSqTest.data.frame} 4 | \alias{wrapChiSqTest.data.frame} 5 | \title{Format ChiSqTest from data.} 6 | \usage{ 7 | \method{wrapChiSqTest}{data.frame}( 8 | x, 9 | predictionColumnName, 10 | yColumnName, 11 | ..., 12 | yTarget = TRUE, 13 | nParameters = 1, 14 | meany = mean(x[[yColumnName]] == yTarget), 15 | na.rm = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{data frame containing columns to compare} 20 | 21 | \item{predictionColumnName}{character name of prediction column} 22 | 23 | \item{yColumnName}{character name of column containing dependent variable} 24 | 25 | \item{...}{extra arguments (not used)} 26 | 27 | \item{yTarget}{y value to consider positive} 28 | 29 | \item{nParameters}{number of variables in model} 30 | 31 | \item{meany}{(optional) mean of y} 32 | 33 | \item{na.rm}{logical, if TRUE remove NA values} 34 | } 35 | \value{ 36 | wrapped test 37 | } 38 | \description{ 39 | Format ChiSqTest from data. 40 | } 41 | \examples{ 42 | 43 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 44 | y=c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 45 | model <- glm(y~x, data=d, family=binomial) 46 | summary(model) 47 | d$pred <- predict(model,type='response',newdata=d) 48 | render(wrapChiSqTest(d,'pred','y'),pLargeCutoff=1) 49 | 50 | } 51 | -------------------------------------------------------------------------------- /man/wrapChiSqTest.glm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{wrapChiSqTest.glm} 4 | \alias{wrapChiSqTest.glm} 5 | \title{Format ChiSqTest from model.} 6 | \usage{ 7 | \method{wrapChiSqTest}{glm}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{glm logistic regression model (glm(family=binomial))} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | wrapped test 16 | } 17 | \description{ 18 | Format ChiSqTest from model. 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 23 | y=c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 24 | model <- glm(y~x,data=d,family=binomial) 25 | summary(model) 26 | render(wrapChiSqTest(model),pLargeCutoff=1,format='ascii') 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/wrapChiSqTest.summary.glm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{wrapChiSqTest.summary.glm} 4 | \alias{wrapChiSqTest.summary.glm} 5 | \title{Format ChiSqTest from model summary.} 6 | \usage{ 7 | \method{wrapChiSqTest}{summary.glm}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{summary(glm(family=binomial)) object.} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | wrapped test 16 | } 17 | \description{ 18 | Format ChiSqTest from model summary. 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 23 | y=c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 24 | model <- glm(y~x,data=d,family=binomial) 25 | sum <- summary(model) 26 | render(wrapChiSqTest(sum),pLargeCutoff=1,format='ascii') 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/wrapChiSqTestImpl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ChiSqTest.R 3 | \name{wrapChiSqTestImpl} 4 | \alias{wrapChiSqTestImpl} 5 | \title{Format quality of a logistic regression roughly in "APA Style" 6 | ( American Psychological Association ).} 7 | \usage{ 8 | wrapChiSqTestImpl(df.null, df.residual, null.deviance, deviance) 9 | } 10 | \arguments{ 11 | \item{df.null}{null degrees of freedom.} 12 | 13 | \item{df.residual}{residual degrees of freedom.} 14 | 15 | \item{null.deviance}{null deviance} 16 | 17 | \item{deviance}{residual deviance} 18 | } 19 | \value{ 20 | wrapped statistic 21 | } 22 | \description{ 23 | Format quality of a logistic regression roughly in "APA Style" 24 | ( American Psychological Association ). 25 | } 26 | \examples{ 27 | 28 | wrapChiSqTestImpl(df.null=7,df.residual=6, 29 | null.deviance=11.09035,deviance=10.83726) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/wrapCohenD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CohenD.R 3 | \name{wrapCohenD} 4 | \alias{wrapCohenD} 5 | \title{Wrap Cohen's D (effect size between groups).} 6 | \usage{ 7 | wrapCohenD(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or test.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap Cohen's D (effect size between groups). 16 | } 17 | \seealso{ 18 | \code{\link{wrapCohenD.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapCohenD.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CohenD.R 3 | \name{wrapCohenD.data.frame} 4 | \alias{wrapCohenD.data.frame} 5 | \title{Wrap Cohen's D (effect size between groups).} 6 | \usage{ 7 | \method{wrapCohenD}{data.frame}(x, Column1Name, Column2Name, ..., na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{data.frame} 11 | 12 | \item{Column1Name}{character column 1 name} 13 | 14 | \item{Column2Name}{character column 2 name} 15 | 16 | \item{...}{extra arguments (not used)} 17 | 18 | \item{na.rm}{if TRUE remove NAs} 19 | } 20 | \value{ 21 | formatted string and fields 22 | } 23 | \description{ 24 | Wrap Cohen's D (effect size between groups). 25 | } 26 | \examples{ 27 | 28 | d <- data.frame(x = c(1,1,2,2,3,3,4,4), 29 | y = c(1,2,3,4,5,6,7,7)) 30 | render(wrapCohenD(d,'x','y')) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/wrapCohenD.numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CohenD.R 3 | \name{wrapCohenD.numeric} 4 | \alias{wrapCohenD.numeric} 5 | \title{Wrap Cohen's D (effect size between groups).} 6 | \usage{ 7 | \method{wrapCohenD}{numeric}(x, treatment, ..., na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{numeric reference or control measurements} 11 | 12 | \item{treatment}{numeric treatment or group-2 measurements} 13 | 14 | \item{...}{extra arguments (not used)} 15 | 16 | \item{na.rm}{if TRUE remove NAs} 17 | } 18 | \value{ 19 | formatted string and fields 20 | } 21 | \description{ 22 | Wrap Cohen's D (effect size between groups). 23 | } 24 | \examples{ 25 | 26 | d <- data.frame(x = c(1,1,2,2,3,3,4,4), 27 | y = c(1,2,3,4,5,6,7,7)) 28 | render(wrapCohenD(d$x, d$y)) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/wrapCorTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CorTest.R 3 | \name{wrapCorTest} 4 | \alias{wrapCorTest} 5 | \title{Wrap cor.test (test of liner correlation).} 6 | \usage{ 7 | wrapCorTest(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or test.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap cor.test (test of liner correlation). 16 | } 17 | \seealso{ 18 | \code{\link{wrapCorTest.htest}}, and \code{\link{wrapCorTest.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapCorTest.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CorTest.R 3 | \name{wrapCorTest.data.frame} 4 | \alias{wrapCorTest.data.frame} 5 | \title{Wrap cor.test (test of liner correlation).} 6 | \usage{ 7 | \method{wrapCorTest}{data.frame}( 8 | x, 9 | Column1Name, 10 | Column2Name, 11 | ..., 12 | alternative = c("two.sided", "less", "greater"), 13 | method = c("pearson", "kendall", "spearman"), 14 | exact = NULL, 15 | conf.level = 0.95, 16 | continuity = FALSE, 17 | na.rm = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{x}{data.frame} 22 | 23 | \item{Column1Name}{character column 1 name} 24 | 25 | \item{Column2Name}{character column 2 name} 26 | 27 | \item{...}{extra arguments passed to cor.test} 28 | 29 | \item{alternative}{passed to \code{\link[stats]{cor.test}}} 30 | 31 | \item{method}{passed to \code{\link[stats]{cor.test}}} 32 | 33 | \item{exact}{passed to \code{\link[stats]{cor.test}}} 34 | 35 | \item{conf.level}{passed to \code{\link[stats]{cor.test}}} 36 | 37 | \item{continuity}{passed to \code{\link[stats]{cor.test}}} 38 | 39 | \item{na.rm}{logical, if TRUE remove NA values} 40 | } 41 | \value{ 42 | wrapped stat 43 | } 44 | \description{ 45 | Wrap cor.test (test of liner correlation). 46 | } 47 | \examples{ 48 | 49 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 50 | y=c(1,1,2,2,3,3,4,4)) 51 | wrapCorTest(d,'x','y') 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /man/wrapCorTest.htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CorTest.R 3 | \name{wrapCorTest.htest} 4 | \alias{wrapCorTest.htest} 5 | \title{Wrap cor.test (test of liner correlation).} 6 | \usage{ 7 | \method{wrapCorTest}{htest}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{cor.test result} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | wrapped stat 16 | } 17 | \description{ 18 | Wrap cor.test (test of liner correlation). 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 23 | y=c(1,1,2,2,3,3,4,4)) 24 | ct <- cor.test(d$x,d$y) 25 | wrapCorTest(ct) 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/wrapFTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTest} 4 | \alias{wrapFTest} 5 | \title{Wrap F-test (significance identity relation).} 6 | \usage{ 7 | wrapFTest(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or lm where to get model or data to score.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap F-test (significance identity relation). 16 | } 17 | \seealso{ 18 | \code{\link{wrapFTestImpl}}, \code{\link{wrapFTest.lm}}, and \code{\link{wrapFTest.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapFTest.anova.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTest.anova} 4 | \alias{wrapFTest.anova} 5 | \title{Wrap quality statistic of a linear relation from anova.} 6 | \usage{ 7 | \method{wrapFTest}{anova}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{result from stats::anova(stats::lm())} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | list of formatted string and fields 16 | } 17 | \description{ 18 | Wrap quality statistic of a linear relation from anova. 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x1 = c(1,2,3,4,5,6,7,7), 23 | x2 = c(1,0,3,0,5,6,0,7), 24 | y = c(1,1,2,2,3,3,4,4)) 25 | model <- lm(y~x1+x2, data=d) 26 | summary(model) 27 | sigr::wrapFTest(model) 28 | anov <- stats::anova(model) 29 | print(anov) 30 | lapply(sigr::wrapFTest(anov), 31 | function(ti) { 32 | sigr::render(ti, 33 | pLargeCutoff= 1, 34 | pSmallCutoff= 0, 35 | statDigits=4, 36 | sigDigits=4, 37 | format='ascii') 38 | }) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/wrapFTest.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTest.data.frame} 4 | \alias{wrapFTest.data.frame} 5 | \title{Wrap quality statistic of identity relation from data.} 6 | \usage{ 7 | \method{wrapFTest}{data.frame}( 8 | x, 9 | predictionColumnName, 10 | yColumnName, 11 | nParameters = 1, 12 | meany = mean(x[[yColumnName]]), 13 | ..., 14 | na.rm = FALSE, 15 | format = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{data frame containing columns to compare} 20 | 21 | \item{predictionColumnName}{character name of prediction column} 22 | 23 | \item{yColumnName}{character name of column containing dependent variable} 24 | 25 | \item{nParameters}{number of variables in model} 26 | 27 | \item{meany}{(optional) mean of y} 28 | 29 | \item{...}{extra arguments (not used)} 30 | 31 | \item{na.rm}{logical, if TRUE remove NA values} 32 | 33 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx")} 34 | } 35 | \value{ 36 | formatted string and fields 37 | } 38 | \description{ 39 | Wrap quality statistic of identity relation from data. 40 | } 41 | \examples{ 42 | 43 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 44 | y=c(1,1,2,2,3,3,4,4)) 45 | model <- lm(y~x,data=d) 46 | summary(model) 47 | d$pred <- predict(model,newdata=d) 48 | sigr::wrapFTest(d,'pred','y') 49 | 50 | } 51 | -------------------------------------------------------------------------------- /man/wrapFTest.htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTest.htest} 4 | \alias{wrapFTest.htest} 5 | \title{Wrap F-test (ratio of variances).} 6 | \usage{ 7 | \method{wrapFTest}{htest}(x, ..., format = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{lm model} 11 | 12 | \item{...}{extra arguments (not used)} 13 | 14 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 15 | } 16 | \value{ 17 | formatted string 18 | } 19 | \description{ 20 | Wrap F-test (ratio of variances). 21 | } 22 | \examples{ 23 | 24 | v <- var.test(c(1,2,3,4,5,6,7,7), c(1, 1, 2)) 25 | sigr::wrapFTest(v) 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/wrapFTest.lm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTest.lm} 4 | \alias{wrapFTest.lm} 5 | \title{Wrap quality statistic of identity r regression.} 6 | \usage{ 7 | \method{wrapFTest}{lm}(x, ..., format = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{lm model} 11 | 12 | \item{...}{extra arguments (not used)} 13 | 14 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 15 | } 16 | \value{ 17 | formatted string 18 | } 19 | \description{ 20 | Wrap quality statistic of identity r regression. 21 | } 22 | \examples{ 23 | 24 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 25 | y=c(1,1,2,2,3,3,4,4)) 26 | model <- lm(y~x,data=d) 27 | summary(model) 28 | sigr::wrapFTest(model) 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/wrapFTest.summary.lm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTest.summary.lm} 4 | \alias{wrapFTest.summary.lm} 5 | \title{Wrap quality statistic of linear regression summary.} 6 | \usage{ 7 | \method{wrapFTest}{summary.lm}(x, ..., format = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{summary.lm summary(lm()) object} 11 | 12 | \item{...}{extra arguments (not used)} 13 | 14 | \item{format}{if set the format to return ("html", "latex", "markdown", "ascii", "docx", ...)} 15 | } 16 | \value{ 17 | formatted string 18 | } 19 | \description{ 20 | Wrap quality statistic of linear regression summary. 21 | } 22 | \examples{ 23 | 24 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 25 | y=c(1,1,2,2,3,3,4,4)) 26 | model <- lm(y~x,data=d) 27 | sum <- summary(model) 28 | sigr::wrapFTest(sum) 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/wrapFTestImpl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTestImpl} 4 | \alias{wrapFTestImpl} 5 | \title{Wrap F-test (significance of identity relation).} 6 | \usage{ 7 | wrapFTestImpl(numdf, dendf, FValue, ..., format = NULL) 8 | } 9 | \arguments{ 10 | \item{numdf}{degrees of freedom 1.} 11 | 12 | \item{dendf}{degrees of freedom 2.} 13 | 14 | \item{FValue}{observed F test statistic} 15 | 16 | \item{...}{not used, force later arguments to bind by name} 17 | 18 | \item{format}{optional, suggested format} 19 | } 20 | \value{ 21 | wrapped statistic 22 | } 23 | \description{ 24 | Wrap F-test (significance of identity relation). 25 | } 26 | \examples{ 27 | 28 | wrapFTestImpl(numdf=2,dendf=55,FValue=5.56) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/wrapFTestezANOVA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FTest.R 3 | \name{wrapFTestezANOVA} 4 | \alias{wrapFTestezANOVA} 5 | \title{Wrap quality statistic of a linear relation from ezANOVA (package ez).} 6 | \usage{ 7 | wrapFTestezANOVA(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{list result from ezANOVA (package ez).} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | list of formatted string and fields 16 | } 17 | \description{ 18 | Please see \url{https://github.com/WinVector/sigr/issues/1#issuecomment-322311947} for an example. 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapFisherTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FisherTest.R 3 | \name{wrapFisherTest} 4 | \alias{wrapFisherTest} 5 | \title{Wrap fisher.test (test of categorical independence).} 6 | \usage{ 7 | wrapFisherTest(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or test.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap fisher.test (test of categorical independence). 16 | } 17 | \seealso{ 18 | \code{\link{wrapFisherTest.htest}}, and \code{\link{wrapFisherTest.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapFisherTest.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FisherTest.R 3 | \name{wrapFisherTest.data.frame} 4 | \alias{wrapFisherTest.data.frame} 5 | \title{Wrap fisher.test (test of categorical independence).} 6 | \usage{ 7 | \method{wrapFisherTest}{data.frame}( 8 | x, 9 | Column1Name, 10 | Column2Name, 11 | ..., 12 | na.rm = FALSE, 13 | workspace = 2e+05, 14 | hybrid = FALSE, 15 | control = list(), 16 | or = 1, 17 | alternative = "two.sided", 18 | conf.int = TRUE, 19 | conf.level = 0.95, 20 | simulate.p.value = FALSE, 21 | B = 2000 22 | ) 23 | } 24 | \arguments{ 25 | \item{x}{data.frame} 26 | 27 | \item{Column1Name}{character column 1 name} 28 | 29 | \item{Column2Name}{character column 2 name} 30 | 31 | \item{...}{extra arguments (not used)} 32 | 33 | \item{na.rm}{logical, if TRUE remove NA values} 34 | 35 | \item{workspace}{passed to \code{\link[stats]{fisher.test}}} 36 | 37 | \item{hybrid}{passed to \code{\link[stats]{fisher.test}}} 38 | 39 | \item{control}{passed to \code{\link[stats]{fisher.test}}} 40 | 41 | \item{or}{passed to \code{\link[stats]{fisher.test}}} 42 | 43 | \item{alternative}{passed to \code{\link[stats]{fisher.test}}} 44 | 45 | \item{conf.int}{passed to \code{\link[stats]{fisher.test}}} 46 | 47 | \item{conf.level}{passed to \code{\link[stats]{fisher.test}}} 48 | 49 | \item{simulate.p.value}{passed to \code{\link[stats]{fisher.test}}} 50 | 51 | \item{B}{passed to \code{\link[stats]{fisher.test}}} 52 | } 53 | \value{ 54 | wrapped test. 55 | } 56 | \description{ 57 | Wrap fisher.test (test of categorical independence). 58 | } 59 | \examples{ 60 | 61 | d <- data.frame(x=c('b','a','a','a','b','b','b'), 62 | y=c('1','1','1','2','2','2','2')) 63 | wrapFisherTest(d, 'x', 'y') 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /man/wrapFisherTest.htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FisherTest.R 3 | \name{wrapFisherTest.htest} 4 | \alias{wrapFisherTest.htest} 5 | \title{Wrap fisher.test (test of categorical independence).} 6 | \usage{ 7 | \method{wrapFisherTest}{htest}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{fisher.test result} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | wrapped test. 16 | } 17 | \description{ 18 | Wrap fisher.test (test of categorical independence). 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x=c('b','a','a','a','b','b','b'), 23 | y=c('1','1','1','2','2','2','2')) 24 | ft <- fisher.test(table(d)) 25 | wrapFisherTest(ft) 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/wrapFisherTest.table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FisherTest.R 3 | \name{wrapFisherTest.table} 4 | \alias{wrapFisherTest.table} 5 | \title{Wrap fisher.test (test of categorical independence).} 6 | \usage{ 7 | \method{wrapFisherTest}{table}( 8 | x, 9 | ..., 10 | workspace = 2e+05, 11 | hybrid = FALSE, 12 | control = list(), 13 | or = 1, 14 | alternative = "two.sided", 15 | conf.int = TRUE, 16 | conf.level = 0.95, 17 | simulate.p.value = FALSE, 18 | B = 2000 19 | ) 20 | } 21 | \arguments{ 22 | \item{x}{data.frame} 23 | 24 | \item{...}{extra arguments (not used)} 25 | 26 | \item{workspace}{passed to \code{\link[stats]{fisher.test}}} 27 | 28 | \item{hybrid}{passed to \code{\link[stats]{fisher.test}}} 29 | 30 | \item{control}{passed to \code{\link[stats]{fisher.test}}} 31 | 32 | \item{or}{passed to \code{\link[stats]{fisher.test}}} 33 | 34 | \item{alternative}{passed to \code{\link[stats]{fisher.test}}} 35 | 36 | \item{conf.int}{passed to \code{\link[stats]{fisher.test}}} 37 | 38 | \item{conf.level}{passed to \code{\link[stats]{fisher.test}}} 39 | 40 | \item{simulate.p.value}{passed to \code{\link[stats]{fisher.test}}} 41 | 42 | \item{B}{passed to \code{\link[stats]{fisher.test}}} 43 | } 44 | \value{ 45 | wrapped test. 46 | } 47 | \description{ 48 | Wrap fisher.test (test of categorical independence). 49 | } 50 | \examples{ 51 | 52 | d <- data.frame(x=c('b','a','a','a','b','b','b'), 53 | y=c('1','1','1','2','2','2','2')) 54 | t <- table(d) 55 | wrapFisherTest(t) 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /man/wrapPWR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pwr.R 3 | \name{wrapPWR} 4 | \alias{wrapPWR} 5 | \title{Wrap pwr test (difference in means by group).} 6 | \usage{ 7 | wrapPWR(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{test from pwr package} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap pwr test (difference in means by group). 16 | } 17 | \seealso{ 18 | \code{\link[pwr]{pwr.2p.test}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapPWR.power.htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pwr.R 3 | \name{wrapPWR.power.htest} 4 | \alias{wrapPWR.power.htest} 5 | \title{Wrap pwr test.} 6 | \usage{ 7 | \method{wrapPWR}{power.htest}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{pwr test result} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | formatted string and fields 16 | } 17 | \description{ 18 | Wrap pwr test. 19 | } 20 | \examples{ 21 | 22 | if(require("pwr", quietly = TRUE)) { 23 | # Example from pwr package 24 | # Exercise 6.1 p. 198 from Cohen (1988) 25 | test <- pwr::pwr.2p.test(h=0.3,n=80,sig.level=0.05,alternative="greater") 26 | wrapPWR(test) 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/wrapSignificance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toPresentation.R 3 | \name{wrapSignificance} 4 | \alias{wrapSignificance} 5 | \title{Wrap a significance} 6 | \usage{ 7 | wrapSignificance(significance, symbol = "p") 8 | } 9 | \arguments{ 10 | \item{significance}{numeric the significance value.} 11 | 12 | \item{symbol}{the name of the value (e.g. "p", "t", ...).} 13 | } 14 | \value{ 15 | wrapped significance 16 | } 17 | \description{ 18 | Wrap a significance 19 | } 20 | \examples{ 21 | 22 | wrapSignificance(1/300) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/wrapTTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TTest.R 3 | \name{wrapTTest} 4 | \alias{wrapTTest} 5 | \title{Wrap t.test (difference in means by group).} 6 | \usage{ 7 | wrapTTest(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numeric, data.frame or test.} 11 | 12 | \item{...}{extra arguments} 13 | } 14 | \description{ 15 | Wrap t.test (difference in means by group). 16 | } 17 | \seealso{ 18 | \code{\link{wrapTTest.htest}}, and \code{\link{wrapTTest.data.frame}} 19 | } 20 | -------------------------------------------------------------------------------- /man/wrapTTest.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TTest.R 3 | \name{wrapTTest.data.frame} 4 | \alias{wrapTTest.data.frame} 5 | \title{Wrap t.test (difference in means by group).} 6 | \usage{ 7 | \method{wrapTTest}{data.frame}( 8 | x, 9 | Column1Name, 10 | Column2Name, 11 | ..., 12 | y = NULL, 13 | alternative = c("two.sided", "less", "greater"), 14 | mu = 0, 15 | paired = FALSE, 16 | var.equal = FALSE, 17 | conf.level = 0.95, 18 | na.rm = FALSE 19 | ) 20 | } 21 | \arguments{ 22 | \item{x}{data.frame} 23 | 24 | \item{Column1Name}{character column 1 name} 25 | 26 | \item{Column2Name}{character column 2 name} 27 | 28 | \item{...}{extra arguments passed to ttest} 29 | 30 | \item{y}{passed to \code{\link[stats]{t.test}}} 31 | 32 | \item{alternative}{passed to \code{\link[stats]{t.test}}} 33 | 34 | \item{mu}{passed to \code{\link[stats]{t.test}}} 35 | 36 | \item{paired}{passed to \code{\link[stats]{t.test}}} 37 | 38 | \item{var.equal}{passed to \code{\link[stats]{t.test}}} 39 | 40 | \item{conf.level}{passed to \code{\link[stats]{t.test}}} 41 | 42 | \item{na.rm}{logical, if TRUE remove NA values} 43 | } 44 | \value{ 45 | formatted string and fields 46 | } 47 | \description{ 48 | Wrap t.test (difference in means by group). 49 | } 50 | \examples{ 51 | 52 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 53 | y=c(1,1,2,2,3,3,4,4)) 54 | render(wrapTTest(d,'x','y'),pLargeCutoff=1) 55 | # confirm p not order depedent 56 | render(wrapTTest(d,'y','x'),pLargeCutoff=1) 57 | 58 | } 59 | -------------------------------------------------------------------------------- /man/wrapTTest.htest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TTest.R 3 | \name{wrapTTest.htest} 4 | \alias{wrapTTest.htest} 5 | \title{Wrap t.test (difference in means by group).} 6 | \usage{ 7 | \method{wrapTTest}{htest}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{t.test result} 11 | 12 | \item{...}{extra arguments (not used)} 13 | } 14 | \value{ 15 | formatted string and fields 16 | } 17 | \description{ 18 | Wrap t.test (difference in means by group). 19 | } 20 | \examples{ 21 | 22 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 23 | y=c(1,1,2,2,3,3,4,4)) 24 | tt <- t.test(d$x,d$y) 25 | render(wrapTTest(tt),pLargeCutoff=1) 26 | # confirm not rescaling, as a correlation test would 27 | render(wrapTTest(t.test(d$x,2*d$y)),pLargeCutoff=1) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/wrapTTest.numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TTest.R 3 | \name{wrapTTest.numeric} 4 | \alias{wrapTTest.numeric} 5 | \title{Wrap t.test (difference in means by group).} 6 | \usage{ 7 | \method{wrapTTest}{numeric}( 8 | x, 9 | pop2, 10 | ..., 11 | y = NULL, 12 | alternative = c("two.sided", "less", "greater"), 13 | mu = 0, 14 | paired = FALSE, 15 | var.equal = FALSE, 16 | conf.level = 0.95, 17 | na.rm = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{x}{numeric population 1} 22 | 23 | \item{pop2}{numeric population 2} 24 | 25 | \item{...}{extra arguments passed to ttest} 26 | 27 | \item{y}{passed to \code{\link[stats]{t.test}}} 28 | 29 | \item{alternative}{passed to \code{\link[stats]{t.test}}} 30 | 31 | \item{mu}{passed to \code{\link[stats]{t.test}}} 32 | 33 | \item{paired}{passed to \code{\link[stats]{t.test}}} 34 | 35 | \item{var.equal}{passed to \code{\link[stats]{t.test}}} 36 | 37 | \item{conf.level}{passed to \code{\link[stats]{t.test}}} 38 | 39 | \item{na.rm}{logical, if TRUE remove NA values} 40 | } 41 | \value{ 42 | formatted string and fields 43 | } 44 | \description{ 45 | Wrap t.test (difference in means by group). 46 | } 47 | \examples{ 48 | 49 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 50 | y=c(1,1,2,2,3,3,4,4)) 51 | render(wrapTTest(d$x, d$y), pLargeCutoff=1) 52 | # confirm p not order depedent 53 | render(wrapTTest(d$y, d$x),pLargeCutoff=1) 54 | 55 | } 56 | -------------------------------------------------------------------------------- /sigr.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: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | StripTrailingWhitespace: Yes 16 | 17 | BuildType: Package 18 | PackageUseDevtools: Yes 19 | PackageInstallArgs: --no-multiarch --with-keep.source 20 | -------------------------------------------------------------------------------- /tests/tinytest.R: -------------------------------------------------------------------------------- 1 | 2 | if ( requireNamespace("tinytest", quietly=TRUE) ){ 3 | tinytest::test_package("sigr") 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tools/sigr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WinVector/sigr/019233dfbb555583d6081d7409e14e7d14f648a8/tools/sigr.png -------------------------------------------------------------------------------- /vignettes/lmExample.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "lm example" 3 | author: "John Mount" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{lm example} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r} 13 | library('sigr') 14 | set.seed(352532) 15 | d <- data.frame(x=1:10, z=c(4,5)) 16 | d$y <- 2*d$x + 0.1*rnorm(nrow(d)) 17 | 18 | ``` 19 | 20 | ```{r lm} 21 | model <- lm(y~x+z, data=d) 22 | d$pred <- predict(model, newdata = d) 23 | 24 | s <- summary(model) 25 | print(s) 26 | print(s$fstatistic) 27 | ``` 28 | 29 | ```{r cortest1, results='asis'} 30 | cat(render(wrapFTest(model), 31 | pSmallCutoff=0)) 32 | ``` 33 | 34 | ```{r cortestp, results='asis'} 35 | cat(render(wrapFTest(d, 'pred', 'y', nParameters=2), 36 | pSmallCutoff=0)) 37 | ``` 38 | 39 | Intentionally forget to inform `wrapFTest` of the true 40 | number of parameters: 41 | 42 | ```{r cortestpwrong, results='asis'} 43 | cat(render(wrapFTest(d, 'pred', 'y'), 44 | pSmallCutoff=0)) 45 | ``` 46 | -------------------------------------------------------------------------------- /vignettes/sigrFormatting.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "sigr formatting" 3 | author: "John Mount" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{sigr formatting} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | \usepackage[utf8]{inputenc} 10 | --- 11 | 12 | Examples of `sigr` formatting. Inspired by APA format 13 | (American Psychological Association), but not fully compliant. Discussed [here](https://win-vector.com/2016/10/02/proofing-statistics-in-papers/). 14 | 15 | Please see the APA stat guidelines for more notes. 16 | 17 | Simple formatting. 18 | 19 | ```{r results='asis'} 20 | library("sigr") 21 | sigr::getRenderingFormat() 22 | cat(render(wrapSignificance(1/300))) 23 | ``` 24 | 25 | F-test examples (quality of a numeric model of a numeric outcome). 26 | 27 | ```{r results='asis'} 28 | cat(render(wrapFTestImpl(numdf=2,dendf=55,FValue=5.56))) 29 | ``` 30 | 31 | ```{r} 32 | d <- data.frame(x=0.2*(1:20)) 33 | d$y <- cos(d$x) 34 | model <- lm(y~x,data=d) 35 | d$prediction <- predict(model,newdata=d) 36 | print(summary(model)) 37 | ``` 38 | 39 | ```{r results='asis'} 40 | cat(render(wrapFTest(model),pSmallCutoff=1.0e-12)) 41 | cat(render(wrapFTest(d,'prediction','y'), 42 | pSmallCutoff=1.0e-12)) 43 | ``` 44 | 45 | Chi-squared test examples (quality of a probability model 46 | of a two category outcome). 47 | 48 | ```{r} 49 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 50 | y=c(TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE)) 51 | model <- glm(y~x,data=d,family=binomial) 52 | model$converged 53 | summary(model) 54 | d$pred <- predict(model,type='response',newdata=d) 55 | ``` 56 | ```{r results='asis'} 57 | cat(render(wrapChiSqTest(model),pLargeCutoff=1)) 58 | cat(render(wrapChiSqTest(d,'pred','y'),pLargeCutoff=1)) 59 | ``` 60 | 61 | ```{r} 62 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 63 | y=c(1,1,2,2,3,3,4,4)) 64 | ct <- cor.test(d$x,d$y) 65 | ``` 66 | ```{r results='asis'} 67 | cat(render(wrapCorTest(ct))) 68 | ``` 69 | 70 | ```{r} 71 | d <- data.frame(x=c('b','a','a','a','b','b','b'), 72 | y=c('1','1','1','2','2','2','2')) 73 | ft <- fisher.test(table(d)) 74 | ``` 75 | ```{r results='asis'} 76 | cat(render(wrapFisherTest(ft),pLargeCutoff=1)) 77 | ``` 78 | 79 | ```{r} 80 | d <- data.frame(x=c(1,2,3,4,5,6,7,7), 81 | y=c(1,1,2,2,3,3,4,4)) 82 | ft <- t.test(d$x,d$y) 83 | ``` 84 | ```{r results='asis'} 85 | cat(render(wrapTTest(ft),pLargeCutoff=1)) 86 | ``` 87 | 88 | ```{r results='asis'} 89 | parallelCluster <- NULL 90 | #parallelCluster <- parallel::makeCluster(parallel::detectCores()) 91 | 92 | set.seed(25325) 93 | d <- data.frame(x1=c(1,2,3,4,5,6,7,7), 94 | y=c(FALSE,TRUE,FALSE,FALSE, 95 | TRUE,TRUE,FALSE,TRUE)) 96 | d <- rbind(d,d,d,d) 97 | sigr::resampleTestAUC(d,'x1','y',TRUE, 98 | nrep=200, 99 | parallelCluster=parallelCluster) 100 | 101 | set.seed(25325) 102 | d <- data.frame(x1=c(1,2,3,4,5,6,7,7), 103 | x2=1, 104 | y=c(FALSE,TRUE,FALSE,FALSE, 105 | TRUE,TRUE,FALSE,TRUE)) 106 | d <- rbind(d,d,d,d) 107 | sigr::testAUCpair(d,'x1','x2','y',TRUE, 108 | nrep=200, 109 | parallelCluster=parallelCluster) 110 | if(!is.null(parallelCluster)) { 111 | parallel::stopCluster(parallelCluster) 112 | } 113 | ``` 114 | 115 | 116 | permutationScoreModel 117 | 118 | ```{r} 119 | set.seed(25325) 120 | y <- 1:5 121 | m <- c(1,1,2,2,2) 122 | cor.test(m,y,alternative='greater') 123 | f <- function(modelValues, yValues) { cor(modelValues, yValues) } 124 | sigr::permutationScoreModel(m,y,f) 125 | ``` 126 | 127 | resampleScoreModel 128 | 129 | ```{r} 130 | set.seed(25325) 131 | y <- 1:5 132 | m1 <- c(1,1,2,2,2) 133 | cor.test(m1,y,alternative='greater') 134 | f <- function(modelValues,yValues) { 135 | if((sd(modelValues)<=0)||(sd(yValues)<=0)) { 136 | return(0) 137 | } 138 | cor(modelValues,yValues) 139 | } 140 | s <- sigr::resampleScoreModel(m1,y,f) 141 | print(s) 142 | z <- s$observedScore/s$sd # always check size of z relative to bias! 143 | pValue <- pt(z,df=length(y)-2,lower.tail=FALSE) 144 | pValue 145 | ``` 146 | 147 | resampleScoreModelPair 148 | 149 | ```{r} 150 | set.seed(25325) 151 | y <- 1:5 152 | m1 <- c(1,1,2,2,2) 153 | m2 <- c(1,1,1,1,2) 154 | cor(m1,y) 155 | cor(m2,y) 156 | f <- function(modelValues,yValues) { 157 | if((sd(modelValues)<=0)||(sd(yValues)<=0)) { 158 | return(0) 159 | } 160 | cor(modelValues,yValues) 161 | } 162 | sigr::render(sigr::resampleScoreModelPair(m1,m2,y,f), 163 | pLargeCutoff=1,format='ascii') 164 | ``` 165 | 166 | 167 | 168 | --------------------------------------------------------------------------------