├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── CGPfunctions.R ├── Mode.R ├── OurConfidence.R ├── Plot2WayANOVA.R ├── PlotXTabs.R ├── PlotXTabs2.R ├── aovtype2.R ├── aovtype2_helpers.R ├── chaid_table.R ├── cross2_var_vectors.R ├── data.R ├── global_vars.R ├── helpers.R ├── newggslopegraph.R └── seedist.R ├── README.Rmd ├── README.md ├── _pkgdown.yaml ├── cran-comments.md ├── data ├── USvoteS.RData ├── chaidUS.RData ├── newcancer.RData └── newgdp.RData ├── docs ├── 404.html ├── LICENSE-text.html ├── articles │ ├── Using-Plot2WayANOVA.html │ ├── Using-Plot2WayANOVA_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── figure-html │ │ │ ├── Plot2WayANOVA-1.png │ │ │ ├── Plot2WayANOVA2-1.png │ │ │ └── Plot2WayANOVA3-1.png │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.2 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ ├── Using-PlotXTabs.html │ ├── Using-PlotXTabs2.html │ ├── Using-PlotXTabs2_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── figure-html │ │ │ ├── simple-1.png │ │ │ ├── simple2-1.png │ │ │ ├── vignette1-1.png │ │ │ ├── vignette2-1.png │ │ │ ├── vignette2-2.png │ │ │ ├── vignette2-3.png │ │ │ ├── vignette2-4.png │ │ │ └── vignette2-5.png │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.2 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ ├── Using-PlotXTabs_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── figure-html │ │ │ ├── vignette1-1.png │ │ │ ├── vignette1-10.png │ │ │ ├── vignette1-11.png │ │ │ ├── vignette1-12.png │ │ │ ├── vignette1-13.png │ │ │ ├── vignette1-14.png │ │ │ ├── vignette1-15.png │ │ │ ├── vignette1-16.png │ │ │ ├── vignette1-17.png │ │ │ ├── vignette1-18.png │ │ │ ├── vignette1-19.png │ │ │ ├── vignette1-2.png │ │ │ ├── vignette1-20.png │ │ │ ├── vignette1-21.png │ │ │ ├── vignette1-22.png │ │ │ ├── vignette1-23.png │ │ │ ├── vignette1-3.png │ │ │ ├── vignette1-4.png │ │ │ ├── vignette1-5.png │ │ │ ├── vignette1-6.png │ │ │ ├── vignette1-7.png │ │ │ ├── vignette1-8.png │ │ │ └── vignette1-9.png │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.2 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ ├── Using-chaid_table.html │ ├── Using-chaid_table_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── figure-html │ │ │ └── one-1.png │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.2 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ ├── Using-newggslopegraph.html │ ├── Using-newggslopegraph_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── figure-html │ │ │ ├── ggslope1-1.png │ │ │ ├── ggslope2-1.png │ │ │ ├── ggslope3-1.png │ │ │ ├── ggslope4-1.png │ │ │ ├── ggslope5-1.png │ │ │ ├── ggslope6-1.png │ │ │ ├── ggslope7-1.png │ │ │ └── ggslope7-2.png │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.2 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ └── index.html ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── docsearch.json ├── index.html ├── jquery.sticky-kit.min.js ├── link.svg ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── BrownForsytheTest.html │ ├── CGPfunctions.html │ ├── Mode.html │ ├── OurConf-1.png │ ├── OurConf-2.png │ ├── OurConf-3.png │ ├── OurConf.html │ ├── Plot2WayANOVA-1.png │ ├── Plot2WayANOVA-2.png │ ├── Plot2WayANOVA-3.png │ ├── Plot2WayANOVA.html │ ├── PlotXTabs-1.png │ ├── PlotXTabs-10.png │ ├── PlotXTabs-11.png │ ├── PlotXTabs-12.png │ ├── PlotXTabs-13.png │ ├── PlotXTabs-2.png │ ├── PlotXTabs-3.png │ ├── PlotXTabs-4.png │ ├── PlotXTabs-5.png │ ├── PlotXTabs-6.png │ ├── PlotXTabs-7.png │ ├── PlotXTabs-8.png │ ├── PlotXTabs-9.png │ ├── PlotXTabs.html │ ├── PlotXTabs2-1.png │ ├── PlotXTabs2-2.png │ ├── PlotXTabs2-3.png │ ├── PlotXTabs2-4.png │ ├── PlotXTabs2.html │ ├── Rplot001.png │ ├── Rplot002.png │ ├── Rplot003.png │ ├── Rplot004.png │ ├── Rplot005.png │ ├── Rplot006.png │ ├── Rplot007.png │ ├── Rplot008.png │ ├── Rplot009.png │ ├── Rplot010.png │ ├── Rplot011.png │ ├── Rplot012.png │ ├── Rplot013.png │ ├── SeeDist-1.png │ ├── SeeDist-2.png │ ├── SeeDist-3.png │ ├── SeeDist-4.png │ ├── SeeDist-5.png │ ├── SeeDist-6.png │ ├── SeeDist-7.png │ ├── SeeDist-8.png │ ├── SeeDist-9.png │ ├── SeeDist.html │ ├── USvoteS.html │ ├── aovtype2.html │ ├── bf_display.html │ ├── chaidUS.html │ ├── chaid_table.html │ ├── cross2_var_vectors.html │ ├── exponent.html │ ├── index.html │ ├── justifyme.html │ ├── newbroom.html │ ├── newcancer.html │ ├── neweta.html │ ├── newgdp.html │ ├── newggslopegraph-1.png │ ├── newggslopegraph-2.png │ ├── newggslopegraph-3.png │ ├── newggslopegraph-4.png │ ├── newggslopegraph-5.png │ ├── newggslopegraph.html │ └── number_to_word.html └── sitemap.xml ├── man ├── BrownForsytheTest.Rd ├── CGPfunctions.Rd ├── Mode.Rd ├── OurConf.Rd ├── Plot2WayANOVA.Rd ├── PlotXTabs.Rd ├── PlotXTabs2.Rd ├── SeeDist.Rd ├── USvoteS.Rd ├── aovtype2.Rd ├── bf_display.Rd ├── chaidUS.Rd ├── chaid_table.Rd ├── cross2_var_vectors.Rd ├── exponent.Rd ├── justifyme.Rd ├── newbroom.Rd ├── newcancer.Rd ├── newgdp.Rd ├── newggslopegraph.Rd └── number_to_word.Rd ├── tests ├── figs │ ├── deps.txt │ ├── ggplot2-histogram.svg │ ├── newggslopegraph │ │ ├── ggplot2-histogram.svg │ │ └── slopegraph1.svg │ └── slopegraph1.svg ├── testthat.R └── testthat │ └── test-newggslopegraph.R └── vignettes ├── Using-Plot2WayANOVA.R ├── Using-Plot2WayANOVA.Rmd ├── Using-Plot2WayANOVA.html ├── Using-PlotXTabs.R ├── Using-PlotXTabs.Rmd ├── Using-PlotXTabs.html ├── Using-PlotXTabs2.R ├── Using-PlotXTabs2.Rmd ├── Using-PlotXTabs2.html ├── Using-chaid_table.R ├── Using-chaid_table.Rmd ├── Using-chaid_table.html ├── Using-newggslopegraph.R ├── Using-newggslopegraph.Rmd └── Using-newggslopegraph.html /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^cran-comments\.md$ 2 | ^Meta$ 3 | ^doc$ 4 | ^CRAN-RELEASE$ 5 | ^.*\.Rproj$ 6 | ^\.Rproj\.user$ 7 | ^README\.Rmd$ 8 | ^docs$ 9 | ^_pkgdown\.yaml 10 | .travis.yml 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Meta 2 | doc 3 | .Rproj.user 4 | .Rhistory 5 | .RData 6 | .Ruserdata 7 | .DS_Store 8 | myfunctions.Rproj 9 | inst/doc 10 | CGPfunctions.Rproj 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | r: 3 | - oldrel 4 | - release 5 | - devel 6 | 7 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: CGPfunctions 2 | Title: Powell Miscellaneous Functions for Teaching and Learning Statistics 3 | Version: 0.6.3 4 | Authors@R: person("Chuck", 5 | "Powell", 6 | email = "ibecav@gmail.com", 7 | role = c("aut", "cre"), 8 | comment = c(ORCID = "0000-0002-3606-2188") 9 | ) 10 | Description: Miscellaneous functions useful for teaching statistics as well as actually practicing the art. They typically are not new methods but rather wrappers around either base R or other packages. 11 | Depends: R (>= 3.6.0) 12 | License: MIT + file LICENSE 13 | Encoding: UTF-8 14 | LazyData: true 15 | Imports: 16 | BayesFactor, 17 | DescTools (>= 0.99.32), 18 | dplyr, 19 | forcats, 20 | ggmosaic, 21 | ggplot2 (>= 3.3.0), 22 | ggrepel, 23 | methods, 24 | paletteer, 25 | partykit, 26 | purrr, 27 | rlang, 28 | scales (>= 1.1.0), 29 | sjstats (>= 0.17.9), 30 | stats, 31 | stringr, 32 | tidyr 33 | Suggests: 34 | BSDA, 35 | ggthemes, 36 | hrbrthemes, 37 | janitor, 38 | knitr, 39 | lsr, 40 | magrittr, 41 | productplots, 42 | pwr, 43 | rmarkdown, 44 | stringi, 45 | tibble, 46 | testthat, 47 | tidyselect 48 | VignetteBuilder: knitr 49 | RoxygenNote: 7.1.1 50 | URL: https://github.com/ibecav/CGPfunctions 51 | BugReports: https://github.com/ibecav/CGPfunctions/issues 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2018 2 | COPYRIGHT HOLDER: Chuck Powell 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(Mode) 4 | export(OurConf) 5 | export(Plot2WayANOVA) 6 | export(PlotXTabs) 7 | export(PlotXTabs2) 8 | export(SeeDist) 9 | export(aovtype2) 10 | export(chaid_table) 11 | export(cross2_var_vectors) 12 | export(newggslopegraph) 13 | import(dplyr) 14 | import(ggmosaic) 15 | import(ggplot2) 16 | import(partykit) 17 | import(rlang) 18 | import(scales) 19 | importFrom(BayesFactor,anovaBF) 20 | importFrom(BayesFactor,contingencyTableBF) 21 | importFrom(BayesFactor,extractBF) 22 | importFrom(DescTools,Desc) 23 | importFrom(DescTools,PostHocTest) 24 | importFrom(dplyr,"%>%") 25 | importFrom(dplyr,arrange) 26 | importFrom(dplyr,as_tibble) 27 | importFrom(dplyr,case_when) 28 | importFrom(dplyr,count) 29 | importFrom(dplyr,desc) 30 | importFrom(dplyr,filter) 31 | importFrom(dplyr,filter_all) 32 | importFrom(dplyr,group_by) 33 | importFrom(dplyr,if_else) 34 | importFrom(dplyr,mutate) 35 | importFrom(dplyr,mutate_at) 36 | importFrom(dplyr,mutate_if) 37 | importFrom(dplyr,n) 38 | importFrom(dplyr,select) 39 | importFrom(dplyr,summarise) 40 | importFrom(dplyr,summarize) 41 | importFrom(forcats,fct_rev) 42 | importFrom(ggrepel,geom_label_repel) 43 | importFrom(ggrepel,geom_text_repel) 44 | importFrom(grDevices,nclass.FD) 45 | importFrom(grid,depth) 46 | importFrom(methods,hasArg) 47 | importFrom(methods,is) 48 | importFrom(paletteer,scale_fill_paletteer_d) 49 | importFrom(purrr,map_dfr) 50 | importFrom(rlang,"!!") 51 | importFrom(rlang,enquo) 52 | importFrom(rlang,quo_name) 53 | importFrom(scales,label_percent) 54 | importFrom(sjstats,anova_stats) 55 | importFrom(sjstats,crosstable_statistics) 56 | importFrom(stats,AIC) 57 | importFrom(stats,BIC) 58 | importFrom(stats,anova) 59 | importFrom(stats,aov) 60 | importFrom(stats,complete.cases) 61 | importFrom(stats,dnorm) 62 | importFrom(stats,dt) 63 | importFrom(stats,formula) 64 | importFrom(stats,lm) 65 | importFrom(stats,median) 66 | importFrom(stats,pf) 67 | importFrom(stats,qnorm) 68 | importFrom(stats,qt) 69 | importFrom(stats,replications) 70 | importFrom(stats,residuals) 71 | importFrom(stats,rnorm) 72 | importFrom(stats,sd) 73 | importFrom(stats,shapiro.test) 74 | importFrom(stats,symnum) 75 | importFrom(stringr,str_replace_all) 76 | importFrom(stringr,str_split) 77 | importFrom(stringr,str_trim) 78 | importFrom(tidyr,complete) 79 | importFrom(tidyr,drop_na) 80 | importFrom(tidyr,pivot_wider) 81 | importFrom(tidyr,separate) 82 | importFrom(tidyr,uncount) 83 | importFrom(utils,getFromNamespace) 84 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # CGPfunctions 0.6.3 2 | 3 | * Release 0.6.3 started development July 2020 CRAN submission November 11, 2020 4 | - Eliminated dependency on car package and broom package. Great packages but I only need a couple of functions and they have a lot of dependencies 5 | - tibble 3.0.2 introduces a silly warning about dots fixed in 3.0.3 6 | - Added a short Bayesian analysis of the model 7 | - Better checking for cell counts of zero or less than 3 8 | - Now possible to plot without errorbars 9 | - Updated title to be more informative 10 | - Added better data labeling to newggslopegraph 11 | - Tweaks to ggrepel parameters to deconflict y axis labels 12 | 13 | * Release 0.6.2 in development July 2020 CRAN submission July 16 14 | - Planned enhancements to Plot2WayANOVA 15 | - Implemented `ggtheme` so user can choose their theme 16 | - Implemented `ggplot.component` so user can add arbitary ggplot formatting 17 | - Corrected doco to fix failing links under devel https://github.com/r-lib/roxygen2/issues/707 18 | - Tested against ggplot2 version 3.3.2 19 | - Uexpected consequences of broom upgrade breaks Plot2WayANOVA now reporting eta squared versus r squared 20 | - tibble 3.0.2 introduces a silly warning about dots fixed in 3.0.3 21 | 22 | * Release 0.6.1 in development April 2020 CRAN release sumitted May 27 23 | - Builds locally with R 4.0.0 24 | - Mosaic plots in PlotXTabs2 waiting on the next version 25 | of ggmosaic for some bug fixes before it can get in CRAN version 26 | - Changes in advance of ggplot2 3.3.1 release ggplot(data.frame(x)) 27 | - numbr for BF results 28 | 29 | * Release 0.6.0 submitted and accepted by CRAN 2 April 2020 30 | - Fixed tibble 3.0.0 issue 31 | - Fixed dependency issues with ggplot2, scales, sjstats and added ggmosaic 32 | - Adding mosaic plots to PlotXTabs2 still debugging and waiting on the next version 33 | of ggmosaic for some bu fixes 34 | - Significant upgrades to seedist including lots of customization options and the 35 | addition of violin plots. 36 | 37 | * Release 0.5.9 deployed to CRAN March 2020 38 | - Added functionality to PlotXTabs2 will be deprecating PlotXtabs next 39 | release 40 | - Another vignette example for newggslopegraph 41 | - Added chaid_table() including vignette 42 | - Added cross2_var_vectors function 43 | - Requiring R >= 3.6.0 to support DescTools 44 | - Cleaned up dependencies 45 | - Corrected overly aggresive error checking in newggslopegraph 46 | - Remove deprecated neweta() 47 | * Release 0.5.8 feature release 20 June 2019 48 | - Updated newslopegraph to add aditional formatting options 49 | - Added support for selected themes from ggthemes 50 | - Updating github web pages 51 | * Release 0.5.7 feature release 12 June 2019 52 | - Updated newslopegraph to add aditional formatting options 53 | * Release 0.5.4 hotfix release 8 April 2019 54 | - Updated Plot2WayANOVA to remedy an error when there were zero significant effects 55 | and post hoc tests failed 56 | * Release 0.5.3 stable release 3 April 2019 57 | - Updated vignette for Plot2WayANOVA 58 | - Major improvements and features added to Plot2WayANOVA 59 | * Release 0.5.2 accepted by CRAN 22 March 2019 60 | - Hotfix to Plot2WayANOVA 61 | - Minor improvements and features added to Plot2WayANOVA 62 | * v0.5.1 in development on 21 March 2019 63 | - Minor improvements and features added to Plot2WayANOVA 64 | * Release 0.5.0 released on CRAN 21 March 2019 65 | - Major improvements and features added to Plot2WayANOVA 66 | - Deprecated function neweta 67 | * Release 0.4 published on CRAN 13 June 2018 68 | * Release 0.4 published on Github 11 June 2018 69 | - Changed version # to .4 70 | - Added new function newggslopegraph 71 | * Release 0.3.1 (hotfix) published on Github 25 April 2018 72 | - Changed version # to 3.1 73 | - Added percent scales to percent plot using the scales package which necessitated changes in DESCRIPTION and NAMESPACE 74 | - Added some code to keep track of missing values that are omitted in calculations and plotting 75 | - Creating the ggtitle with a bquote seemed to be creating issues with both performance and also creating intermittent errors if the title was long. Replaced bquote with sprintf and while I was at it changed how it presents 76 | - Rebuilt vignettes and doco as needed to show the changes 77 | 78 | * Release 0.3 published on CRAN 79 | 80 | * Release 0.1 81 | -------------------------------------------------------------------------------- /R/CGPfunctions.R: -------------------------------------------------------------------------------- 1 | #' CGPfunctions: A package of miscellaneous functions for teaching statistics. 2 | #' 3 | #' A package that includes miscellaneous functions useful for teaching statistics as well as actually practicing the art. They typically are not new methods but rather wrappers around either base R or other packages. 4 | #' 5 | #' @section Functions included: 6 | #' \itemize{ 7 | #' \item \code{\link{newggslopegraph}} creates a "slopegraph" as conceptualized by Edward Tufte. 8 | #' \item \code{\link{Plot2WayANOVA}} which as the name implies conducts a 2 way ANOVA and plots the results using `ggplot2` 9 | #' \item \code{\link{PlotXTabs2}} which wraps around ggplot2 to provide Bivariate bar charts for categorical and ordinal data. 10 | #' \item \code{\link{chaid_table}} provides tabular summary of CHAID partykit object. 11 | #' \item \code{\link{cross2_var_vectors}} helper function to cross a vector of variables. 12 | #' \item \code{\link{PlotXTabs}} Plots cross tabulated variables using `ggplot2` 13 | #' \item \code{\link{Mode}} which finds the modal value in a vector of data 14 | #' \item \code{\link{SeeDist}} which wraps around ggplot2 to provide visualizations of univariate data. 15 | #' \item \code{\link{OurConf}} which wraps around ggplot2 to provide visualizations of sampling confidence intervals. 16 | #' } 17 | #' 18 | #' @docType package 19 | #' @name CGPfunctions 20 | NULL 21 | -------------------------------------------------------------------------------- /R/Mode.R: -------------------------------------------------------------------------------- 1 | #' Derive the modal value(s) for a set of data 2 | #' 3 | #' This function takes a vector and returns one or mode values 4 | #' that represent the mode point of the data 5 | #' 6 | #' @param x a vector 7 | #' 8 | #' @return a vector containing one or more modal values for the input vector 9 | #' @export 10 | #' 11 | #' @section Warning: 12 | #' Be careful the function does some basic error checking but the return to 13 | #' \code{Mode(NA)} is \code{NA} and a vector where the majority of entries 14 | #' are \code{NA} is also NA 15 | #' 16 | #' @examples 17 | #' Mode(sample(1:100, 1000, replace = TRUE)) 18 | #' Mode(mtcars$hp) 19 | #' Mode(iris$Sepal.Length) 20 | Mode <- function(x) { 21 | # error checking 22 | if (missing(x)) { 23 | stop("Argument \"x\" is missing, with no default") 24 | } 25 | if (!is.vector(x)) { 26 | stop("I can only process a vector of data") 27 | } 28 | 29 | ux <- unique(x) 30 | # ux[which.max(tabulate(match(x, ux)))] 31 | tab <- tabulate(match(x, ux)) 32 | ux[tab == max(tab)] 33 | } 34 | -------------------------------------------------------------------------------- /R/OurConfidence.R: -------------------------------------------------------------------------------- 1 | # stable 2 | # modified from https://www.rdocumentation.org/packages/BSDA/versions/1.2.0/topics/CIsim 3 | #' Plotting random samples of confidence intervals around the mean 4 | #' 5 | #' This function takes some parameters and simulates random samples and 6 | #' their confidence intervals 7 | #' 8 | #' @param samples The number of times to draw random samples 9 | #' @param n The sample size we draw each time 10 | #' @param mu The population mean mu 11 | #' @param sigma The population standard deviation 12 | #' @param conf.level What confidence level to compute 1 - alpha (significance level) 13 | #' 14 | #' @return A ggplot2 object 15 | #' @export 16 | #' @importFrom stats qnorm rnorm 17 | #' @seealso \code{stats::qnorm}, \code{stats::rnorm}, \code{BSDA::CIsim} 18 | #' 19 | #' @author Chuck Powell 20 | #' 21 | #' @examples 22 | #' OurConf(samples = 100, n = 30, mu = 0, sigma = 1, conf.level = 0.95) 23 | #' OurConf(samples = 2, n = 5) 24 | #' OurConf(samples = 25, n = 25, mu = 100, sigma = 20, conf.level = 0.99) 25 | OurConf <- function(samples = 100, n = 30, mu = 0, sigma = 1, conf.level = 0.95) { 26 | alpha <- 1 - conf.level 27 | CL <- conf.level * 100 28 | n <- round(n) 29 | N <- round(samples) 30 | if (N <= 0 || n <= 1) { 31 | stop("Number of random samples and sample size must both be at least 2") 32 | } 33 | if (!missing(conf.level) && (length(conf.level) != 1 || !is.finite(conf.level) || 34 | conf.level <= 0 || conf.level >= 1)) { 35 | stop("'conf.level' must be a single number between 0 and 1") 36 | } 37 | if (sigma <= 0) { 38 | stop("Variance must be a positive value") 39 | } 40 | 41 | junk <- rnorm(N * n, mu, sigma) 42 | jmat <- matrix(junk, N, n) 43 | xbar <- apply(jmat, 1, mean) 44 | ll <- xbar - qnorm(1 - alpha / 2) * sigma / sqrt(n) 45 | ul <- xbar + qnorm(1 - alpha / 2) * sigma / sqrt(n) 46 | notin <- sum((ll > mu) + (ul < mu)) 47 | percentage <- round((1 - notin / N) * 100, 2) 48 | data <- data.frame(xbar = xbar, ll = ll, ul = ul) 49 | data$samplenumb <- factor(as.integer(rownames(data))) 50 | data$correct <- "Includes" 51 | data$correct[data$ul < mu] <- "Low" 52 | data$correct[data$ll > mu] <- "High" 53 | bestfit <- function(NN = N) { 54 | list( 55 | scale_y_continuous(limits = c((mu - 2 * sigma), (mu + 2 * sigma))), 56 | if (NN >= 51) { 57 | scale_x_discrete(breaks = seq(0, 500, 10)) 58 | } 59 | ) 60 | } 61 | 62 | p <- ggplot(data, aes(y = xbar, x = samplenumb)) + 63 | geom_point() + 64 | geom_hline(yintercept = mu) + 65 | geom_errorbar(aes(ymin = ll, ymax = ul, color = correct), width = 0.3) + 66 | labs( 67 | title = bquote(.(N) ~ "random samples with" ~ .(CL) * "% confidence intervals where" ~ mu ~ "=" ~ .(mu) ~ "and" ~ sigma ~ "=" ~ .(sigma)), 68 | subtitle = bquote("Note:" ~ .(percentage) * "% of the confidence intervals contain" ~ mu ~ "=" ~ .(mu)), 69 | y = expression("Sample mean" ~ (bar(X))), 70 | x = paste0("Random samples of size = ", n), 71 | caption = ("modified from the CIsim function in package BSDA") 72 | ) + 73 | bestfit() + 74 | guides(color = guide_legend(title = NULL)) + 75 | theme_bw() 76 | print(p) 77 | cat(percentage, "% of the confidence intervals contain Mu =", mu, ".", "\n") 78 | } 79 | -------------------------------------------------------------------------------- /R/aovtype2.R: -------------------------------------------------------------------------------- 1 | #' Anova Tables for Type 2 sums of squares 2 | #' 3 | #' Calculates and displays type-II analysis-of-variance tables for model objects 4 | #' produced by aov. This is a vastly reduced version of the Anova function from 5 | #' package car 6 | #' 7 | #' Details about how the function works in order of steps taken. 8 | #' Type-II tests are invariant with respect to (full-rank) contrast coding. 9 | #' Type-II tests are calculated according to the principle of marginality, 10 | #' testing each term after all others, except ignoring the term's higher-order 11 | #' relatives. This definition of Type-II tests corresponds to the tests 12 | #' produced by SAS for analysis-of-variance models, where all of the 13 | #' predictors are factors, but not more generally (i.e., when there are 14 | #' quantitative predictors). 15 | #' 16 | #' @usage aovtype2(mod) 17 | #' @param mod aov model object from base R. 18 | #' @return An object of class "anova", which usually is printed. 19 | #' 20 | #' @references: Fox, J. (2016) Applied Regression Analysis and Generalized Linear Models, Third Edition. Sage. 21 | #' 22 | #' @author John Fox jfox@mcmaster.ca; as modified by Chuck Powell 23 | #' @seealso \code{\link[stats]{aov}} 24 | #' @examples 25 | #' 26 | #' mtcars$cyl <- factor(mtcars$cyl) 27 | #' mtcars$am <- factor(mtcars$am) 28 | #' mod <- aov(hp ~ cyl * am, data = mtcars) 29 | #' aovtype2(mod) 30 | #' 31 | #' @export 32 | #' 33 | aovtype2 <- function(mod) 34 | { 35 | if (class(mod)[[1]] != "aov") stop("Function is only for aov models") 36 | else class(mod) <- "lm" 37 | if (df.residual(mod) == 0) stop("residual df = 0") 38 | if (deviance(mod) < sqrt(.Machine$double.eps)) stop("residual sum of squares is 0 (within rounding error)") 39 | 40 | SS.term <- function(term){ 41 | which.term <- which(term == names) 42 | subs.term <- which(assign == which.term) 43 | relatives <- relatives(term, names, fac) 44 | subs.relatives <- NULL 45 | for (relative in relatives) 46 | subs.relatives <- c(subs.relatives, which(assign == relative)) 47 | hyp.matrix.1 <- I.p[subs.relatives,,drop=FALSE] 48 | hyp.matrix.1 <- hyp.matrix.1[, not.aliased, drop=FALSE] 49 | hyp.matrix.2 <- I.p[c(subs.relatives,subs.term),,drop=FALSE] 50 | hyp.matrix.2 <- hyp.matrix.2[, not.aliased, drop=FALSE] 51 | hyp.matrix.term <- if (nrow(hyp.matrix.1) == 0) hyp.matrix.2 52 | else t(ConjComp(t(hyp.matrix.1), t(hyp.matrix.2), vcov(mod, complete=FALSE))) 53 | hyp.matrix.term <- hyp.matrix.term[!apply(hyp.matrix.term, 1, 54 | function(x) all(x == 0)), , drop=FALSE] 55 | if (nrow(hyp.matrix.term) == 0) 56 | return(c(SS=NA, df=0)) 57 | lh <- linearHypothesis(mod, 58 | hyp.matrix.term, 59 | singular.ok = TRUE) 60 | abs(c(SS=lh$"Sum of Sq"[2], df=lh$Df[2])) 61 | } 62 | 63 | not.aliased <- !is.na(coef(mod)) 64 | if (!all(not.aliased)) 65 | stop("there are aliased coefficients in the model") 66 | fac <- attr(terms(mod), "factors") 67 | intercept <- has.intercept(mod) 68 | I.p <- diag(length(coefficients(mod))) 69 | assign <- mod$assign 70 | assign[!not.aliased] <- NA 71 | names <- term.names(mod) 72 | if (intercept) names <-names[-1] 73 | n.terms <- length(names) 74 | p <- df <- f <- SS <- rep(0, n.terms + 1) 75 | sumry <- summary(mod, corr = FALSE) 76 | SS[n.terms + 1] <- sumry$sigma^2*mod$df.residual 77 | 78 | df[n.terms + 1] <- mod$df.residual 79 | p[n.terms + 1] <- f[n.terms + 1] <- NA 80 | for (i in 1:n.terms){ 81 | ss <- SS.term(names[i]) 82 | SS[i] <- ss["SS"] 83 | df[i] <- ss["df"] 84 | f[i] <- df[n.terms+1]*SS[i]/(df[i]*SS[n.terms + 1]) 85 | p[i] <- pf(f[i], df[i], df[n.terms + 1], lower.tail = FALSE) 86 | } 87 | result <- data.frame(SS, df, f, p) 88 | row.names(result) <- c(names,"Residuals") 89 | names(result) <- c("Sum Sq", "Df", "F value", "Pr(>F)") 90 | class(result) <- c("anova", "data.frame") 91 | attr(result, "heading") <- c("Anova Table (Type II tests)\n", 92 | paste("Response:", responseName(mod))) 93 | result 94 | } 95 | 96 | 97 | -------------------------------------------------------------------------------- /R/chaid_table.R: -------------------------------------------------------------------------------- 1 | #' Produce CHAID results tables from a partykit CHAID model 2 | #' 3 | #' @param chaidobject An object of type `constparty` or `party` which 4 | #' was produced by `CHAID::chaid` see simple example below. 5 | #' @return A tibble containing the results. 6 | #' 7 | #' @import dplyr 8 | #' @import partykit 9 | #' 10 | #' @importFrom purrr map_dfr 11 | #' @importFrom stringr str_replace_all str_split str_trim 12 | #' @importFrom dplyr as_tibble 13 | #' @importFrom utils getFromNamespace 14 | #' @importFrom tidyr pivot_wider separate 15 | #' @importFrom grid depth 16 | #' @importFrom stats complete.cases formula 17 | #' 18 | #' @author Chuck Powell 19 | #' 20 | #' @examples 21 | #' library(CGPfunctions) 22 | #' chaid_table(chaidUS) 23 | #' 24 | #' @export 25 | #' 26 | 27 | chaid_table <- function(chaidobject) { 28 | # circumventing the fact that partykit doesn't export a function I need 29 | .list.rules.party = getFromNamespace(".list.rules.party", 30 | "partykit") 31 | 32 | # extract the formula from the object 33 | model.formula <- formula(chaidobject) 34 | 35 | # extract the name of the outcome variable 36 | # all.vars(model.formula)[[1]] 37 | outcome.variable <- all.vars(model.formula)[[1]] 38 | 39 | # get all the nodeids as a vector 40 | all_nodes <- partykit::nodeids(chaidobject) 41 | 42 | # get the terminal nodes as a vector 43 | terminal_nodes <- partykit::nodeids(chaidobject, 44 | terminal = TRUE) 45 | 46 | # get the split points or inner nodes or non-terminal nodes as a vector 47 | inner_nodes <- all_nodes[!(all_nodes %in% nodeids(chaidobject, 48 | terminal = TRUE))] 49 | 50 | # partykit:::.list.rules.party extracts the split rule that generates 51 | # the prediction for a single node we've pulled it in above with 52 | # getFromNamespace(".list.rules.party", "partykit") 53 | node_rules <- .list.rules.party(chaidobject, 54 | 1:length(chaidobject)) 55 | 56 | # create an empty tibble to start populating the node table 57 | node_table <- tibble::tibble() 58 | 59 | # rejoin the oucome variable to the rest of the data frame 60 | # since chaid separated them 61 | original_df <- cbind(chaidobject$data, 62 | outcome = chaidobject$fitted$`(response)`) 63 | 64 | # a simple for loop to iterate through all the nodes 65 | # logic for the top node #1 is slightly different since 66 | # it has no split rule since it was never split 67 | # Complete cases is probably unnecessary 68 | # .drop = FLASE keeps us from losing counts to NA if there are no cases 69 | # eval(parse(text = node_rules[[i]])) uses valid filter conditions 70 | for (i in all_nodes) { 71 | if (i == 1) { 72 | xxx <- original_df %>% 73 | filter(complete.cases(.)) %>% 74 | group_by(outcome) %>% 75 | summarise(N = n()) %>% 76 | tidyr::pivot_wider( 77 | names_from = outcome, 78 | values_from = N 79 | ) 80 | xxx$splitrule <- NA 81 | } else { 82 | xxx <- original_df %>% 83 | filter(complete.cases(.)) %>% 84 | group_by(outcome, .drop = FALSE) %>% 85 | filter(eval(parse(text = node_rules[[i]]))) %>% 86 | summarise(N = n()) %>% 87 | pivot_wider( 88 | names_from = outcome, 89 | values_from = N 90 | ) 91 | xxx$splitrule <- gsub("\"", 92 | "'", 93 | node_rules[i], 94 | fixed = TRUE 95 | ) 96 | } 97 | xxx$nodeID <- i 98 | node_table <- rbind(node_table, xxx) 99 | } 100 | 101 | # technically may be more than 2 must test 102 | outcome.levels <- nlevels(original_df$outcome) 103 | 104 | node_table <- 105 | tidyr::separate( 106 | data = node_table, 107 | col = splitrule, 108 | sep = "&", 109 | into = paste0("split", 110 | 1:depth(chaidobject)), 111 | remove = FALSE, 112 | fill = "right") %>% 113 | mutate(NodeN = rowSums(.[1:outcome.levels])) %>% 114 | select(nodeID, 115 | NodeN, 116 | everything()) %>% 117 | mutate_at(vars(starts_with("split")), 118 | str_trim) 119 | 120 | find_my_parent <- function(node) { 121 | # depth-first walk on partynode structure (recursive function) 122 | # decision rules are extracted for every branch 123 | # parents and children are linked 124 | # because or recursion using <<- which isn't my favorite 125 | if (!is.terminal(node)) { 126 | for (i in 1:length(node)) { 127 | child <- node$kids[[i]]$id 128 | parent <- node$id 129 | node_table[node_table$nodeID == child, "parent"] <<- parent 130 | find_my_parent(node[[i]]) 131 | } 132 | } 133 | } 134 | 135 | find_my_parent(chaidobject$node) 136 | 137 | # splitrule is hard to read make ruletext as more plain text 138 | node_table$ruletext <- 139 | str_replace_all(node_table$splitrule, 140 | c("%in%" = "is", 141 | "c\\('" = "'", 142 | "'\\)" = "'") 143 | ) 144 | 145 | # give the inner nodes names to use later on so we don't lose track 146 | # during map_dfr operation 147 | names(inner_nodes) <- inner_nodes 148 | 149 | # Create an empty split table 150 | split_table <- tibble::tibble() 151 | 152 | # build the split table with relevant stats 153 | split_table <- 154 | map_dfr( 155 | .x = inner_nodes, 156 | ~ node_table %>% 157 | filter(parent == .x) %>% 158 | select(levels(original_df$outcome)) %>% 159 | chisq.test(correct = FALSE) %>% 160 | newbroom(), .id = "nodeID") %>% 161 | rename( 162 | chisq = statistic, 163 | rawpvalue = p.value, 164 | df = parameter) %>% 165 | select(-method) 166 | 167 | split_table$nodeID <- as.integer(split_table$nodeID) 168 | split_table$adjustedp <- NA_real_ 169 | split_table$split.variable <- NA_character_ 170 | 171 | for (i in inner_nodes) { 172 | split_table[split_table$nodeID == i, "adjustedp"] <- 173 | min(unlist(nodeapply(chaidobject, 174 | ids = all_nodes, 175 | FUN = function(n) n$info)[[i]] 176 | ) 177 | ) 178 | split_table[split_table$nodeID == i, "split.variable"] <- 179 | attr(which.min(unlist(nodeapply(chaidobject, 180 | ids = all_nodes, 181 | FUN = function(n) n$info)[[i]] 182 | ) 183 | ), "names" 184 | ) 185 | } 186 | 187 | split_table$split.variable <- 188 | str_split(split_table$split.variable, 189 | "\\.", 190 | n = 2, 191 | simplify = TRUE)[,2] 192 | 193 | node_table <- full_join(node_table, split_table, by = "nodeID") 194 | 195 | node_table <- 196 | node_table %>% 197 | select(nodeID, 198 | parent, 199 | NodeN, 200 | levels(original_df$outcome), 201 | ruletext, 202 | split.variable, 203 | chisq, 204 | df, 205 | adjustedp, 206 | rawpvalue, 207 | everything()) 208 | node_table 209 | } 210 | -------------------------------------------------------------------------------- /R/cross2_var_vectors.R: -------------------------------------------------------------------------------- 1 | #' Cross two vectors of variable names from a dataframe 2 | #' 3 | #' @param data the dataframe or tibble the variables are contained in. 4 | #' @param x,y These are either character or integer vectors containing 5 | #' the names, e.g. "am" or the column numbers e.g. 9 6 | #' @param verbose the default is FALSE, setting to TRUE will cat additional 7 | #' output to the screen 8 | #' 9 | #' @return a list with two sublists `lista` and `listb`. Very handy for 10 | #' feeding the lists to `purrr` for further processing. 11 | #' @author Chuck Powell 12 | #' @export 13 | #' 14 | #' @examples 15 | #' cross2_var_vectors(mtcars, 9, c(2, 10:11)) 16 | #' cross2_var_vectors(mtcars, "am", c("cyl", "gear", "carb")) 17 | #' x2 <- c("am", "carb") 18 | #' y2 <- c("vs", "cyl", "gear") 19 | #' cross2_var_vectors(mtcars, x2, y2, verbose = TRUE) 20 | #' 21 | #' \dontrun{ 22 | #' variables_list <- cross2_var_vectors(mtcars, x2, y2) 23 | #' mytitles <- stringr::str_c( 24 | #' stringr::str_to_title(variables_list$listb), 25 | #' " by ", 26 | #' stringr::str_to_title(variables_list$lista), 27 | #' " in mtcars data" 28 | #' ) 29 | #' purrr::pmap( 30 | #' .l = list( 31 | #' x = variables_list[[1]], # variables_list$lista 32 | #' y = variables_list[[2]], # variables_list$listb 33 | #' title = mytitles 34 | #' ), 35 | #' .f = CGPfunctions::PlotXTabs2, 36 | #' data = mtcars, 37 | #' ylab = NULL, 38 | #' perc.k = 1, 39 | #' palette = "Set2" 40 | #' ) 41 | #' 42 | #' } 43 | #' 44 | cross2_var_vectors <- function(data, 45 | x, 46 | y, 47 | verbose = FALSE) { 48 | # some quick sanity checks 49 | if (!is.data.frame(data)) { 50 | stop("data must be a dataframe or tibble") 51 | } 52 | 53 | if (!is.character(y) && !is.numeric(y)) { 54 | stop("x and y need to be either character or numeric vectors") 55 | } 56 | 57 | if (!is.character(x) && !is.numeric(x)) { 58 | stop("x and y need to be either character or numeric vectors") 59 | } 60 | ######## 61 | if (is.numeric(x) && (max(x) > ncol(data) || min(x) < 1)) { 62 | stop("x contains one or more items that are not a valid column number") 63 | } 64 | 65 | if (is.numeric(y) && (max(y) > ncol(data) || min(y) < 1)) { 66 | stop("y contains one or more items that are not a valid column number") 67 | } 68 | ######## 69 | if (is.character(x) && !all(x %in% colnames(data))) { 70 | stop("x contains one or more items that are not columns in data") 71 | } 72 | 73 | if (is.character(y) && !all(y %in% colnames(data))) { 74 | stop("y contains one or more items that are not columns in data") 75 | } 76 | 77 | if (any(colnames(data[x]) %in% colnames(data[y]))) { 78 | stop("x and y cannot contain a common variable") 79 | } 80 | 81 | # initialize two empty lists of the proper length x * y 82 | listb <- lista <- vector( 83 | mode = "list", 84 | length = (length(x) * length(y)) 85 | ) 86 | 87 | # do the work by looping through both vectors 88 | current_combo <- 1 89 | 90 | for (j in seq_along(x)) { 91 | for (k in seq_along(y)) { 92 | listb[[current_combo]] <- colnames(data[x[[j]]]) 93 | lista[[current_combo]] <- colnames(data[y[[k]]]) 94 | if (verbose) { 95 | cat("Pair ", 96 | current_combo, 97 | " lista = ", 98 | lista[[current_combo]], 99 | " listb = ", 100 | listb[[current_combo]], "\n", 101 | sep = "" 102 | ) 103 | } 104 | current_combo <- current_combo + 1 105 | } 106 | } 107 | 108 | # return a list with two sublists 109 | return(list(lista = lista, listb = listb)) 110 | } 111 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' @rdname newcancer 2 | #' @title Tufte dataset on cancer survival rates 3 | #' @aliases newcancer 4 | #' 5 | #' @description A dataset containing cancer survival rates for different types of cancer 6 | #' over a 20 year period. 7 | #' 8 | #' @format A data frame with 96 rows and 3 variables: 9 | #' \describe{ 10 | #' \item{Year}{ordered factor for the 5, 10, 15 and 20 year survival rates} 11 | #' \item{Type}{factor containing the name of the cancer type} 12 | #' \item{Survival}{numeric for this data a whole number corresponding to the percent survival rate} 13 | #' 14 | #' } 15 | #' @source \url{https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk} 16 | #' @keywords datasets 17 | "newcancer" 18 | 19 | #' @rdname newgdp 20 | #' @title Tufte dataset on Gross Domestic Product, 1970 and 1979 21 | #' @aliases newgdp 22 | #' @description Current receipts of fifteen national governments as a percentage of gross domestic product 23 | #' 24 | #' @format A data frame with 30 rows and 3 variables: 25 | #' \describe{ 26 | #' \item{Year}{character for 1970 and 1979} 27 | #' \item{Country}{factor country name} 28 | #' \item{GDP}{numeric a percentage of gross domestic product} 29 | #' 30 | #' } 31 | #' @source Edward Tufte. \emph{Beautiful Evidence}. Graphics Press, 174-176. 32 | #' @keywords datasets 33 | "newgdp" 34 | 35 | #' @rdname USvoteS 36 | #' @title U.S. 2000 Election Data (short) 37 | #' @aliases USvoteS 38 | #' @description Data from a post-election survey following the year 2000 U.S. 39 | #' presidential elections. This is a subset from package `CHAID`. 40 | #' 41 | #' @format A data frame with 1000 observations on the following 6 variables.: 42 | #' \describe{ 43 | #' \item{vote3}{candidate voted for Gore or Bush} 44 | #' \item{gender}{gender, a factor with levels male and female} 45 | #' \item{ager}{age group, an ordered factor with levels 18-24 < 25-34 < 35-44 < 45-54 < 55-64 < 65+} 46 | #' \item{empstat}{status of employment, a factor with levels yes, no or retired} 47 | #' \item{educr}{status of education, an ordered factor with levels HS < College < Post Coll} 48 | #' \item{marstat}{status of living situation, a factor with levels married, widowed, divorced or never married} 49 | #' 50 | #' } 51 | #' @source https://r-forge.r-project.org/R/?group_id=343 52 | #' @keywords datasets 53 | "USvoteS" 54 | 55 | #' @rdname chaidUS 56 | #' @title U.S. 2000 Election Data (short) 57 | #' @aliases chaidUS 58 | #' @description Data from a post-election survey following the year 2000 U.S. 59 | #' presidential elections. This is a subset from package `CHAID`. 60 | #' 61 | #' @format A partykit on the following 6 variables.: 62 | #' \describe{ 63 | #' \item{vote3}{candidate voted for Gore or Bush} 64 | #' \item{gender}{gender, a factor with levels male and female} 65 | #' \item{ager}{age group, an ordered factor with levels 18-24 < 25-34 < 35-44 < 45-54 < 55-64 < 65+} 66 | #' \item{empstat}{status of employment, a factor with levels yes, no or retired} 67 | #' \item{educr}{status of education, an ordered factor with levels HS < College < Post Coll} 68 | #' \item{marstat}{status of living situation, a factor with levels married, widowed, divorced or never married} 69 | #' 70 | #' } 71 | #' @source https://r-forge.r-project.org/R/?group_id=343 72 | #' @keywords datasets 73 | "chaidUS" 74 | -------------------------------------------------------------------------------- /R/global_vars.R: -------------------------------------------------------------------------------- 1 | # defining global variables and functions to appease R CMD Check 2 | 3 | utils::globalVariables( 4 | names = c( 5 | ".", 6 | ".wt", 7 | "perc", 8 | "N", 9 | "NN", 10 | "n", 11 | "samplenumb", 12 | "correct", 13 | "TheMean", 14 | "TheSEM", 15 | "TheSD", 16 | "CIMuliplier", 17 | "LowerBound", 18 | "UpperBound", 19 | "p.value", 20 | "term", 21 | "outcome", 22 | "splitrule", 23 | "df", 24 | "chisq", 25 | "method", 26 | "NodeN", 27 | "nodeID", 28 | "adjustedp", 29 | "parent", 30 | "ruletext", 31 | "split.variable", 32 | "rawpvalue", 33 | "statistic", 34 | "parameter", 35 | "support", 36 | "logged", 37 | "sensible", 38 | "astext", 39 | "xmin", 40 | "xmax", 41 | "ymin", 42 | "ymax", 43 | "pct", 44 | ".", 45 | "alias", 46 | "coef", 47 | "coefficients", 48 | "deviance", 49 | "df.residual", 50 | "makeHypothesis", 51 | "model.frame", 52 | "model.matrix", 53 | "model.response", 54 | "pchisq", 55 | "setNames", 56 | "terms", 57 | "vcov", 58 | "model", 59 | "error", 60 | "bf" 61 | ), 62 | package = "CGPfunctions", 63 | add = FALSE 64 | ) -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | [![CRAN Version](https://www.r-pkg.org/badges/version/CGPfunctions)](https://CRAN.R-project.org/package=CGPfunctions) [![Build Status](https://travis-ci.org/ibecav/CGPfunctions.svg?branch=master)](https://travis-ci.org/ibecav/CGPfunctions) [![Downloads](https://cranlogs.r-pkg.org:443/badges/grand-total/CGPfunctions)](https://cranlogs.r-pkg.org:443/badges/grand-total/CGPfunctions) 6 | 7 | 8 | ```{r, include = FALSE} 9 | knitr::opts_chunk$set( 10 | collapse = TRUE, 11 | comment = "#>", 12 | fig.path = "README-" 13 | ) 14 | ``` 15 | 16 | ### Overview 17 | 18 | A package that includes functions that I find useful for teaching statistics as 19 | well as actually practicing the art. They typically are not "new" methods but 20 | rather wrappers around either base R or `tidyverse` packages. Currently contains 21 | the following major user oriented functions: 22 | 23 | - `Plot2WayANOVA` which as the name implies conducts a 2 way ANOVA and plots 24 | the results using `ggplot2` 25 | - `PlotXTabs2` which wraps around `ggplot2` to provide Bivariate bar charts 26 | for categorical and ordinal data. 27 | - `newggslopegraph` which creates a Tufte"esque" slopegraph using `ggplot2` 28 | - `chaid_table` provides tabular summary of `CHAID` `partykit` object 29 | - `cross2_var_vectors` a helper function to build lists of "crossed" variables 30 | - `SeeDist` which wraps around `ggplot2` to provide visualizations of univariate data. 31 | - `OurConf` is a simulation function that helps you learn about confidence intervals 32 | 33 | ### Installation 34 | 35 | ```{r eval = FALSE} 36 | # Install from CRAN 37 | install.packages("CGPfunctions") 38 | 39 | # Or the development version from GitHub 40 | # install.packages("devtools") 41 | devtools::install_github("ibecav/CGPfunctions", 42 | build_vignettes = TRUE, 43 | upgrade = "ask") 44 | ``` 45 | 46 | ### Usage 47 | 48 | [Online documentation and vignettes are located here](https://ibecav.github.io/CGPfunctions/). 49 | 50 | #### Example [Plot2WayANOVA](https://ibecav.github.io/CGPfunctions/articles/Using-Plot2WayANOVA.html) plot 51 | 52 | ```{r example1, echo=FALSE, fig.cap="Example Plot2WayANOVA", out.width = '100%'} 53 | knitr::include_graphics("https://ibecav.github.io/CGPfunctions/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA3-1.png") 54 | ``` 55 | 56 | #### Example [PlotXTabs2](https://ibecav.github.io/CGPfunctions/articles/Using-PlotXTabs2.html) plot 57 | 58 | ```{r example2, echo=FALSE, fig.cap="Example PlotXTabs2 plot", out.width = '100%'} 59 | knitr::include_graphics("https://ibecav.github.io/CGPfunctions/articles/Using-PlotXTabs2_files/figure-html/vignette2-2.png") 60 | ``` 61 | 62 | #### Example [newggslopegraph](https://ibecav.github.io/CGPfunctions/articles/Using-newggslopegraph.html) plot 63 | 64 | ```{r example3, echo=FALSE, fig.cap="Example newggslopegraph plot", out.width = '80%'} 65 | knitr::include_graphics("https://ibecav.github.io/CGPfunctions/articles/Using-newggslopegraph_files/figure-html/ggslope7-1.png") 66 | ``` 67 | 68 | 69 | ### Credits 70 | 71 | Many thanks to Danielle Navarro and the 72 | book *[Learning Statistics with R](https://learningstatisticswithr.com/book/)*. 73 | 74 | ### Leaving Feedback 75 | 76 | If you like **CGPfunctions**, please consider 77 | leaving [feedback here](https://github.com/ibecav/CGPfunctions/issues). 78 | 79 | ### Contributing 80 | 81 | Contributions in the form of feedback, comments, code, and bug reports 82 | are most welcome. How to contribute: 83 | 84 | - Issues, bug reports, and wish lists: [File a GitHub 85 | issue](https://github.com/ibecav/CGPfunctions/issues). 86 | - Contact the maintainer ibecav at gmail.com by email. 87 | 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | [![CRAN 5 | Version](https://www.r-pkg.org/badges/version/CGPfunctions)](https://CRAN.R-project.org/package=CGPfunctions) 6 | [![Build 7 | Status](https://travis-ci.org/ibecav/CGPfunctions.svg?branch=master)](https://travis-ci.org/ibecav/CGPfunctions) 8 | [![Downloads]( https://cranlogs.r-pkg.org:443/badges/grand-total/CGPfunctions)]( https://cranlogs.r-pkg.org:443/badges/grand-total/CGPfunctions) 9 | 10 | ### Overview 11 | 12 | A package that includes functions that I find useful for teaching 13 | statistics as well as actually practicing the art. They typically are 14 | not “new” methods but rather wrappers around either base R or 15 | `tidyverse` packages. Currently contains the following major user 16 | oriented functions: 17 | 18 | - `Plot2WayANOVA` which as the name implies conducts a 2 way ANOVA and 19 | plots the results using `ggplot2` 20 | - `PlotXTabs2` which wraps around `ggplot2` to provide Bivariate bar 21 | charts for categorical and ordinal data. 22 | - `newggslopegraph` which creates a Tufte“esque” slopegraph using 23 | `ggplot2` 24 | - `chaid_table` provides tabular summary of `CHAID` `partykit` object 25 | - `cross2_var_vectors` a helper function to build lists of “crossed” 26 | variables 27 | - `SeeDist` which wraps around `ggplot2` to provide visualizations of 28 | univariate data. 29 | - `OurConf` is a simulation function that helps you learn about 30 | confidence intervals 31 | 32 | ### Installation 33 | 34 | ``` r 35 | # Install from CRAN 36 | install.packages("CGPfunctions") 37 | 38 | # Or the development version from GitHub 39 | # install.packages("devtools") 40 | devtools::install_github("ibecav/CGPfunctions", 41 | build_vignettes = TRUE, 42 | upgrade = "ask") 43 | ``` 44 | 45 | ### Usage 46 | 47 | [Online documentation and vignettes are located 48 | here](https://ibecav.github.io/CGPfunctions/). 49 | 50 | #### Example [Plot2WayANOVA](https://ibecav.github.io/CGPfunctions/articles/Using-Plot2WayANOVA.html) plot 51 | 52 |
53 | 54 | Example Plot2WayANOVA 55 | 56 |

57 | 58 | Example Plot2WayANOVA 59 | 60 |

61 | 62 |
63 | 64 | #### Example [PlotXTabs2](https://ibecav.github.io/CGPfunctions/articles/Using-PlotXTabs2.html) plot 65 | 66 |
67 | 68 | Example PlotXTabs2 plot 69 | 70 |

71 | 72 | Example PlotXTabs2 plot 73 | 74 |

75 | 76 |
77 | 78 | #### Example [newggslopegraph](https://ibecav.github.io/CGPfunctions/articles/Using-newggslopegraph.html) plot 79 | 80 |
81 | 82 | Example newggslopegraph plot 83 | 84 |

85 | 86 | Example newggslopegraph plot 87 | 88 |

89 | 90 |
91 | 92 | ### Credits 93 | 94 | Many thanks to Danielle Navarro and the book *[Learning Statistics with 95 | R](https://learningstatisticswithr.com/book/)*. 96 | 97 | ### Leaving Feedback 98 | 99 | If you like **CGPfunctions**, please consider leaving [feedback 100 | here](https://github.com/ibecav/CGPfunctions/issues). 101 | 102 | ### Contributing 103 | 104 | Contributions in the form of feedback, comments, code, and bug reports 105 | are most welcome. How to contribute: 106 | 107 | - Issues, bug reports, and wish lists: [File a GitHub 108 | issue](https://github.com/ibecav/CGPfunctions/issues). 109 | - Contact the maintainer ibecav at gmail.com by email. 110 | -------------------------------------------------------------------------------- /_pkgdown.yaml: -------------------------------------------------------------------------------- 1 | title: CGPfunctions 2 | url: http://ibecav.github.io/CGPfunctions 3 | template: 4 | params: 5 | bootswatch: cosmo 6 | ganalytics: UA-117082388-1 7 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Second Resubmission 2 | 3 | Dear CRAN maintainers sorry about the extra trouble for some reason my changes to README.rmd didn't propagate to README.md. Fixed now 4 | 5 | ## Resubmission 6 | 7 | Corrected the following 8 | 9 | Found the following (possibly) invalid URLs: 10 | URL: http://cranlogs.r-pkg.org/badges/grand-total/CGPfunctions 11 | (moved to https://cranlogs.r-pkg.org:443/badges/grand-total/CGPfunctions) 12 | From: README.md 13 | 14 | URL: https://ibecav.github.io/CGPfunctions (moved to 15 | https://ibecav.github.io/CGPfunctions/) 16 | From: README.md 17 | 18 | URL: https://ibecav.netlify.com/tags/chaid/ (moved to 19 | https://ibecav.netlify.app/tags/chaid/) 20 | From: inst/doc/Using-chaid_table.html 21 | 22 | URL: https://www.electionstudies.org/ (moved to 23 | https://electionstudies.org/) 24 | From: inst/doc/Using-chaid_table.html 25 | 26 | Please change http --> https, add trailing slashes, or follow moved 27 | content as appropriate. 28 | 29 | ## Test environments 30 | * local OS X install, R 4.0.3 31 | * rhub() Ubuntu, Fedora, Windows server 32 | Have to force utf-8 build with 33 | rhub::check( 34 | platform="windows-x86_64-devel", 35 | env_vars=c(R_COMPILE_AND_INSTALL_PACKAGES = "always") 36 | ) 37 | * win-builder (devel and release) 38 | 39 | ## R CMD check results 40 | 41 | ── R CMD check results ───────────────────────────────── CGPfunctions 0.6.3 ──── 42 | Duration: 2m 19.5s 43 | 44 | 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 45 | 46 | R CMD check succeeded 47 | -------------------------------------------------------------------------------- /data/USvoteS.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/data/USvoteS.RData -------------------------------------------------------------------------------- /data/chaidUS.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/data/chaidUS.RData -------------------------------------------------------------------------------- /data/newcancer.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/data/newcancer.RData -------------------------------------------------------------------------------- /data/newgdp.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/data/newgdp.RData -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • CGPfunctions 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 66 | 67 | 68 | 69 | 70 | 71 |
72 |
73 | 139 | 140 | 141 | 142 |
143 | 144 |
145 |
146 | 149 | 150 | Content not found. Please use links in the navbar. 151 | 152 |
153 | 154 | 159 | 160 |
161 | 162 | 163 | 164 |
165 | 168 | 169 |
170 |

Site built with pkgdown 1.6.1.

171 |
172 | 173 |
174 |
175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • CGPfunctions 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 66 | 67 | 68 | 69 | 70 | 71 |
72 |
73 | 139 | 140 | 141 | 142 |
143 | 144 |
145 |
146 | 149 | 150 |
YEAR: 2018
151 | COPYRIGHT HOLDER: Chuck Powell
152 | 
153 | 154 |
155 | 156 | 161 | 162 |
163 | 164 | 165 | 166 |
167 | 170 | 171 |
172 |

Site built with pkgdown 1.6.1.

173 |
174 | 175 |
176 |
177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_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/Using-Plot2WayANOVA_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA-1.png -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA2-1.png -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-Plot2WayANOVA_files/figure-html/Plot2WayANOVA3-1.png -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/header-attrs-2.2/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-Plot2WayANOVA_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_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/Using-PlotXTabs2_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/simple-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/simple-1.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/simple2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/simple2-1.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/vignette1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/vignette1-1.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-1.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-2.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-3.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-4.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs2_files/figure-html/vignette2-5.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/header-attrs-2.2/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs2_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_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/Using-PlotXTabs_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-1.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-10.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-11.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-12.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-13.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-14.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-15.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-16.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-17.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-18.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-19.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-2.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-20.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-21.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-22.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-23.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-3.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-4.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-5.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-6.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-7.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-8.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/figure-html/vignette1-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-PlotXTabs_files/figure-html/vignette1-9.png -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/header-attrs-2.2/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-PlotXTabs_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-chaid_table_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/Using-chaid_table_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/Using-chaid_table_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/Using-chaid_table_files/figure-html/one-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-chaid_table_files/figure-html/one-1.png -------------------------------------------------------------------------------- /docs/articles/Using-chaid_table_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-chaid_table_files/header-attrs-2.2/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-chaid_table_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_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/Using-newggslopegraph_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope1-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope2-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope3-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope4-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope5-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope6-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope7-1.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/figure-html/ggslope7-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/articles/Using-newggslopegraph_files/figure-html/ggslope7-2.png -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/header-attrs-2.2/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Using-newggslopegraph_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • CGPfunctions 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 66 | 67 | 68 | 69 | 70 | 71 |
72 |
73 | 139 | 140 | 141 | 142 |
143 | 144 |
145 |
146 | 149 | 150 |
151 |

All vignettes

152 |

153 | 154 |
155 |
Using Plot2WayAnova
156 |
157 |
Using PlotXTabs
158 |
159 |
Using PlotXTabs2
160 |
161 |
Using chaid_table
162 |
163 |
Using newggslopegraph
164 |
165 |
166 |
167 |
168 |
169 | 170 | 171 |
172 | 175 | 176 |
177 |

Site built with pkgdown 1.6.1.

178 |
179 | 180 |
181 |
182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • CGPfunctions 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 66 | 67 | 68 | 69 | 70 | 71 |
72 |
73 | 139 | 140 | 141 | 142 |
143 | 144 |
145 |
146 | 149 | 150 |
    151 |
  • 152 |

    Chuck Powell. Author, maintainer. 153 |

    154 |
  • 155 |
156 | 157 |
158 | 159 |
160 | 161 | 162 | 163 |
164 | 167 | 168 |
169 |

Site built with pkgdown 1.6.1.

170 |
171 | 172 |
173 |
174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /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/docsearch.json: -------------------------------------------------------------------------------- 1 | { 2 | "index_name": "CGPfunctions", 3 | "start_urls": "http://ibecav.github.io/CGPfunctions", 4 | "sitemap_urls": "http://ibecav.github.io/CGPfunctions/sitemap.xml", 5 | "selectors": { 6 | "lvl0": ".contents h1", 7 | "lvl1": ".contents h2", 8 | "lvl2": ".contents h3, .contents th, .contents dt", 9 | "lvl3": ".contents h4", 10 | "lvl4": ".contents h5", 11 | "text": ".contents p, .contents li, .usage, .template-article .contents .pre" 12 | }, 13 | "selectors_exclude": ".dont-index" 14 | } 15 | -------------------------------------------------------------------------------- /docs/jquery.sticky-kit.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net 3 | */ 4 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); 5 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
    "))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, 6 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), 8 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", 9 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n 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 | $(".examples, 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; 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: 2.7.3 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | Using-Plot2WayANOVA: Using-Plot2WayANOVA.html 6 | Using-PlotXTabs: Using-PlotXTabs.html 7 | Using-PlotXTabs2: Using-PlotXTabs2.html 8 | Using-chaid_table: Using-chaid_table.html 9 | Using-newggslopegraph: Using-newggslopegraph.html 10 | last_built: 2020-11-12T13:05Z 11 | urls: 12 | reference: http://ibecav.github.io/CGPfunctions/reference 13 | article: http://ibecav.github.io/CGPfunctions/articles 14 | 15 | -------------------------------------------------------------------------------- /docs/reference/OurConf-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/OurConf-1.png -------------------------------------------------------------------------------- /docs/reference/OurConf-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/OurConf-2.png -------------------------------------------------------------------------------- /docs/reference/OurConf-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/OurConf-3.png -------------------------------------------------------------------------------- /docs/reference/Plot2WayANOVA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Plot2WayANOVA-1.png -------------------------------------------------------------------------------- /docs/reference/Plot2WayANOVA-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Plot2WayANOVA-2.png -------------------------------------------------------------------------------- /docs/reference/Plot2WayANOVA-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Plot2WayANOVA-3.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-1.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-10.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-11.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-12.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-13.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-2.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-3.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-4.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-5.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-6.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-7.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-8.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs-9.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs2-1.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs2-2.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs2-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs2-3.png -------------------------------------------------------------------------------- /docs/reference/PlotXTabs2-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/PlotXTabs2-4.png -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/Rplot003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot003.png -------------------------------------------------------------------------------- /docs/reference/Rplot004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot004.png -------------------------------------------------------------------------------- /docs/reference/Rplot005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot005.png -------------------------------------------------------------------------------- /docs/reference/Rplot006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot006.png -------------------------------------------------------------------------------- /docs/reference/Rplot007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot007.png -------------------------------------------------------------------------------- /docs/reference/Rplot008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot008.png -------------------------------------------------------------------------------- /docs/reference/Rplot009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot009.png -------------------------------------------------------------------------------- /docs/reference/Rplot010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot010.png -------------------------------------------------------------------------------- /docs/reference/Rplot011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot011.png -------------------------------------------------------------------------------- /docs/reference/Rplot012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot012.png -------------------------------------------------------------------------------- /docs/reference/Rplot013.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/Rplot013.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-1.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-2.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-3.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-4.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-5.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-6.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-7.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-8.png -------------------------------------------------------------------------------- /docs/reference/SeeDist-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/SeeDist-9.png -------------------------------------------------------------------------------- /docs/reference/newgdp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Tufte dataset on Gross Domestic Product, 1970 and 1979 — newgdp • CGPfunctions 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 67 | 68 | 69 | 70 | 71 | 72 |
    73 |
    74 | 140 | 141 | 142 | 143 |
    144 | 145 |
    146 |
    147 | 152 | 153 |
    154 |

    Current receipts of fifteen national governments as a percentage of gross domestic product

    155 |
    156 | 157 |
    newgdp
    158 | 159 | 160 |

    Format

    161 | 162 |

    A data frame with 30 rows and 3 variables:

    163 |
    Year

    character for 1970 and 1979

    164 |
    Country

    factor country name

    165 |
    GDP

    numeric a percentage of gross domestic product

    166 | 167 | 168 |
    169 | 170 |

    Source

    171 | 172 |

    Edward Tufte. Beautiful Evidence. Graphics Press, 174-176.

    173 | 174 |
    175 | 180 |
    181 | 182 | 183 |
    184 | 187 | 188 |
    189 |

    Site built with pkgdown 1.6.1.

    190 |
    191 | 192 |
    193 |
    194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /docs/reference/newggslopegraph-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/newggslopegraph-1.png -------------------------------------------------------------------------------- /docs/reference/newggslopegraph-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/newggslopegraph-2.png -------------------------------------------------------------------------------- /docs/reference/newggslopegraph-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/newggslopegraph-3.png -------------------------------------------------------------------------------- /docs/reference/newggslopegraph-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/newggslopegraph-4.png -------------------------------------------------------------------------------- /docs/reference/newggslopegraph-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibecav/CGPfunctions/999a2c12831c268e94aa5921f4de662f1943fb65/docs/reference/newggslopegraph-5.png -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://ibecav.github.io/CGPfunctions/index.html 5 | 6 | 7 | http://ibecav.github.io/CGPfunctions/reference/BrownForsytheTest.html 8 | 9 | 10 | http://ibecav.github.io/CGPfunctions/reference/CGPfunctions.html 11 | 12 | 13 | http://ibecav.github.io/CGPfunctions/reference/Mode.html 14 | 15 | 16 | http://ibecav.github.io/CGPfunctions/reference/OurConf.html 17 | 18 | 19 | http://ibecav.github.io/CGPfunctions/reference/Plot2WayANOVA.html 20 | 21 | 22 | http://ibecav.github.io/CGPfunctions/reference/PlotXTabs.html 23 | 24 | 25 | http://ibecav.github.io/CGPfunctions/reference/PlotXTabs2.html 26 | 27 | 28 | http://ibecav.github.io/CGPfunctions/reference/SeeDist.html 29 | 30 | 31 | http://ibecav.github.io/CGPfunctions/reference/USvoteS.html 32 | 33 | 34 | http://ibecav.github.io/CGPfunctions/reference/aovtype2.html 35 | 36 | 37 | http://ibecav.github.io/CGPfunctions/reference/bf_display.html 38 | 39 | 40 | http://ibecav.github.io/CGPfunctions/reference/chaidUS.html 41 | 42 | 43 | http://ibecav.github.io/CGPfunctions/reference/chaid_table.html 44 | 45 | 46 | http://ibecav.github.io/CGPfunctions/reference/cross2_var_vectors.html 47 | 48 | 49 | http://ibecav.github.io/CGPfunctions/reference/exponent.html 50 | 51 | 52 | http://ibecav.github.io/CGPfunctions/reference/justifyme.html 53 | 54 | 55 | http://ibecav.github.io/CGPfunctions/reference/newbroom.html 56 | 57 | 58 | http://ibecav.github.io/CGPfunctions/reference/newcancer.html 59 | 60 | 61 | http://ibecav.github.io/CGPfunctions/reference/newgdp.html 62 | 63 | 64 | http://ibecav.github.io/CGPfunctions/reference/newggslopegraph.html 65 | 66 | 67 | http://ibecav.github.io/CGPfunctions/reference/number_to_word.html 68 | 69 | 70 | http://ibecav.github.io/CGPfunctions/articles/Using-Plot2WayANOVA.html 71 | 72 | 73 | http://ibecav.github.io/CGPfunctions/articles/Using-PlotXTabs.html 74 | 75 | 76 | http://ibecav.github.io/CGPfunctions/articles/Using-PlotXTabs2.html 77 | 78 | 79 | http://ibecav.github.io/CGPfunctions/articles/Using-chaid_table.html 80 | 81 | 82 | http://ibecav.github.io/CGPfunctions/articles/Using-newggslopegraph.html 83 | 84 | 85 | -------------------------------------------------------------------------------- /man/BrownForsytheTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{BrownForsytheTest} 4 | \alias{BrownForsytheTest} 5 | \title{Brown-Forsythe Test for Homogeneity of Variance using median} 6 | \usage{ 7 | BrownForsytheTest(formula, data) 8 | } 9 | \arguments{ 10 | \item{formula}{A fully crossed anova formula.} 11 | 12 | \item{data}{A datafram containing the data.} 13 | } 14 | \value{ 15 | a table containing the results. 16 | } 17 | \description{ 18 | Brown-Forsythe Test for Homogeneity of Variance using median 19 | } 20 | \author{ 21 | J. Fox, Chuck Powell 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/CGPfunctions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CGPfunctions.R 3 | \docType{package} 4 | \name{CGPfunctions} 5 | \alias{CGPfunctions} 6 | \title{CGPfunctions: A package of miscellaneous functions for teaching statistics.} 7 | \description{ 8 | A package that includes miscellaneous functions useful for teaching statistics as well as actually practicing the art. They typically are not new methods but rather wrappers around either base R or other packages. 9 | } 10 | \section{Functions included}{ 11 | 12 | \itemize{ 13 | \item \code{\link{newggslopegraph}} creates a "slopegraph" as conceptualized by Edward Tufte. 14 | \item \code{\link{Plot2WayANOVA}} which as the name implies conducts a 2 way ANOVA and plots the results using `ggplot2` 15 | \item \code{\link{PlotXTabs2}} which wraps around ggplot2 to provide Bivariate bar charts for categorical and ordinal data. 16 | \item \code{\link{chaid_table}} provides tabular summary of CHAID partykit object. 17 | \item \code{\link{cross2_var_vectors}} helper function to cross a vector of variables. 18 | \item \code{\link{PlotXTabs}} Plots cross tabulated variables using `ggplot2` 19 | \item \code{\link{Mode}} which finds the modal value in a vector of data 20 | \item \code{\link{SeeDist}} which wraps around ggplot2 to provide visualizations of univariate data. 21 | \item \code{\link{OurConf}} which wraps around ggplot2 to provide visualizations of sampling confidence intervals. 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/Mode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Mode.R 3 | \name{Mode} 4 | \alias{Mode} 5 | \title{Derive the modal value(s) for a set of data} 6 | \usage{ 7 | Mode(x) 8 | } 9 | \arguments{ 10 | \item{x}{a vector} 11 | } 12 | \value{ 13 | a vector containing one or more modal values for the input vector 14 | } 15 | \description{ 16 | This function takes a vector and returns one or mode values 17 | that represent the mode point of the data 18 | } 19 | \section{Warning}{ 20 | 21 | Be careful the function does some basic error checking but the return to 22 | \code{Mode(NA)} is \code{NA} and a vector where the majority of entries 23 | are \code{NA} is also NA 24 | } 25 | 26 | \examples{ 27 | Mode(sample(1:100, 1000, replace = TRUE)) 28 | Mode(mtcars$hp) 29 | Mode(iris$Sepal.Length) 30 | } 31 | -------------------------------------------------------------------------------- /man/OurConf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/OurConfidence.R 3 | \name{OurConf} 4 | \alias{OurConf} 5 | \title{Plotting random samples of confidence intervals around the mean} 6 | \usage{ 7 | OurConf(samples = 100, n = 30, mu = 0, sigma = 1, conf.level = 0.95) 8 | } 9 | \arguments{ 10 | \item{samples}{The number of times to draw random samples} 11 | 12 | \item{n}{The sample size we draw each time} 13 | 14 | \item{mu}{The population mean mu} 15 | 16 | \item{sigma}{The population standard deviation} 17 | 18 | \item{conf.level}{What confidence level to compute 1 - alpha (significance level)} 19 | } 20 | \value{ 21 | A ggplot2 object 22 | } 23 | \description{ 24 | This function takes some parameters and simulates random samples and 25 | their confidence intervals 26 | } 27 | \examples{ 28 | OurConf(samples = 100, n = 30, mu = 0, sigma = 1, conf.level = 0.95) 29 | OurConf(samples = 2, n = 5) 30 | OurConf(samples = 25, n = 25, mu = 100, sigma = 20, conf.level = 0.99) 31 | } 32 | \seealso{ 33 | \code{stats::qnorm}, \code{stats::rnorm}, \code{BSDA::CIsim} 34 | } 35 | \author{ 36 | Chuck Powell 37 | } 38 | -------------------------------------------------------------------------------- /man/PlotXTabs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PlotXTabs.R 3 | \name{PlotXTabs} 4 | \alias{PlotXTabs} 5 | \title{Plot a Cross Tabulation of two variables using dplyr and ggplot2} 6 | \usage{ 7 | PlotXTabs(dataframe, xwhich, ywhich, plottype = "side") 8 | } 9 | \arguments{ 10 | \item{dataframe}{an object that is of class dataframe} 11 | 12 | \item{xwhich}{either a bare variable name that is valid in the 13 | dataframe or one or more column numbers. An attempt will be 14 | made to coerce the variable to a factor but odd plots will occur 15 | if you pass it a variable that is by rights continuous in nature.} 16 | 17 | \item{ywhich}{either a bare variable name that is valid in the 18 | dataframe or one or more column numbers that exist in the dataframe. 19 | An attempt will be 20 | made to coerce the variable to a factor but odd plots will occur 21 | if you pass it a variable that is by rights continuous in nature.} 22 | 23 | \item{plottype}{one of three options "side", "stack" or "percent"} 24 | } 25 | \value{ 26 | One or more ggplots to the default graphics device as well as 27 | advisory information in the console 28 | } 29 | \description{ 30 | Takes a dataframe and at least two variables as input, conducts a 31 | crosstabulation of the variables using dplyr. Removes NAs and then 32 | plots the results as one of three types of bar (column) graphs 33 | using ggplot2. The function accepts either bare variable names or 34 | column numbers as input (see examples for the possibilities) 35 | } 36 | \examples{ 37 | PlotXTabs(mtcars, am, vs) 38 | PlotXTabs(mtcars, am, vs, "stack") 39 | PlotXTabs(mtcars, am, vs, "percent") 40 | PlotXTabs(mtcars, am, 8, "side") 41 | PlotXTabs(mtcars, 8, am, "stack") 42 | PlotXTabs(mtcars, am, c(8, 10), "percent") 43 | PlotXTabs(mtcars, c(10, 8), am) 44 | PlotXTabs(mtcars, c(2, 9), c(10, 8), "mispelled") 45 | \dontrun{ 46 | PlotXTabs(happy, happy, sex) # baseline 47 | PlotXTabs(happy, 2, 5, "stack") # same thing using column numbers 48 | PlotXTabs(happy, 2, c(5:9), plottype = "percent") # multiple columns RHS 49 | PlotXTabs(happy, c(2, 5), 9, plottype = "side") # multiple columns LHS 50 | PlotXTabs(happy, c(2, 5), c(6:9), plottype = "percent") 51 | PlotXTabs(happy, happy, c(6, 7, 9), plottype = "percent") 52 | PlotXTabs(happy, c(6, 7, 9), happy, plottype = "percent") 53 | } 54 | 55 | } 56 | \seealso{ 57 | \code{\link[janitor]{janitor}} 58 | } 59 | \author{ 60 | Chuck Powell 61 | } 62 | -------------------------------------------------------------------------------- /man/PlotXTabs2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PlotXTabs2.R 3 | \name{PlotXTabs2} 4 | \alias{PlotXTabs2} 5 | \title{Bivariate bar (column) charts with statistical tests} 6 | \usage{ 7 | PlotXTabs2( 8 | data, 9 | x, 10 | y, 11 | counts = NULL, 12 | results.subtitle = TRUE, 13 | title = NULL, 14 | subtitle = NULL, 15 | caption = NULL, 16 | plottype = "percent", 17 | xlab = NULL, 18 | ylab = "Percent", 19 | legend.title = NULL, 20 | legend.position = "right", 21 | labels.legend = NULL, 22 | sample.size.label = TRUE, 23 | data.label = "percentage", 24 | label.text.size = 4, 25 | label.fill.color = "white", 26 | label.fill.alpha = 1, 27 | bar.outline.color = "black", 28 | x.axis.orientation = NULL, 29 | conf.level = 0.95, 30 | k = 2, 31 | perc.k = 0, 32 | mosaic.offset = 0.003, 33 | mosaic.alpha = 1, 34 | bf.details = FALSE, 35 | bf.display = "regular", 36 | sampling.plan = "jointMulti", 37 | fixed.margin = "rows", 38 | prior.concentration = 1, 39 | paired = FALSE, 40 | ggtheme = ggplot2::theme_bw(), 41 | package = "RColorBrewer", 42 | palette = "Dark2", 43 | direction = 1, 44 | ggplot.component = NULL 45 | ) 46 | } 47 | \arguments{ 48 | \item{data}{A dataframe or tibble containing the `x` and `y` variables.} 49 | 50 | \item{x}{The variable to plot on the X axis of the chart.} 51 | 52 | \item{y}{The variable to segment the **columns** and test for independence.} 53 | 54 | \item{counts}{If the dataframe is based upon counts rather than individual 55 | rows for observations, `counts` must contain the name of variable 56 | that contains the counts. See `HairEyeColor` example.} 57 | 58 | \item{results.subtitle}{Decides whether the results of statistical tests 59 | are displayed as a subtitle (Default: TRUE). If set to FALSE, no subtitle.} 60 | 61 | \item{title}{The text for the plot title.} 62 | 63 | \item{subtitle}{The text for the plot subtitle. **N.B** if statistical 64 | results are requested through `results.subtitle = TRUE` the results 65 | will have precedence.} 66 | 67 | \item{caption}{The text for the plot caption. Please note the interaction 68 | with `bf.details`.} 69 | 70 | \item{plottype}{one of four options "side", "stack", "mosaic" or "percent"} 71 | 72 | \item{xlab}{Custom text for the `x` axis label (Default: `NULL`, which 73 | will cause the `x` axis label to be the `x` variable).} 74 | 75 | \item{ylab}{Custom text for the `y` axis label (Default: `"Percent"`). Set 76 | to `NULL` for no label.} 77 | 78 | \item{legend.title}{Title text for the legend.} 79 | 80 | \item{legend.position}{The position of the legend 81 | `"none"`, `"left"`, `"right"`, `"bottom"`, `"top"` (Default: `"right"`).} 82 | 83 | \item{labels.legend}{A character vector with custom labels for levels of 84 | the `y` variable displayed in the legend.} 85 | 86 | \item{sample.size.label}{Logical that decides whether sample size information 87 | should be displayed for each level of the grouping variable `y` 88 | (Default: `TRUE`).} 89 | 90 | \item{data.label}{Character decides what information needs to be displayed 91 | on the label in each bar segment. Possible options are `"percentage"` 92 | (default), `"counts"`, `"both"`.} 93 | 94 | \item{label.text.size}{Numeric that decides size for bar labels 95 | (Default: `4`).} 96 | 97 | \item{label.fill.color}{Character that specifies fill color for bar labels 98 | (Default: `white`).} 99 | 100 | \item{label.fill.alpha}{Numeric that specifies fill color transparency or 101 | `"alpha"` for bar labels (Default: `1` range `0` to `1`).} 102 | 103 | \item{bar.outline.color}{Character specifying color for bars (default: `"black"`).} 104 | 105 | \item{x.axis.orientation}{The orientation of the `x` axis labels one of 106 | "slant" or "vertical" to change from the default horizontal 107 | orientation (Default: `NULL` which is horizontal).} 108 | 109 | \item{conf.level}{Scalar between 0 and 1. If unspecified, the defaults return 110 | lower and upper confidence intervals (0.95).} 111 | 112 | \item{k}{Number of digits after decimal point (should be an integer) 113 | (Default: k = 2) for statistical results.} 114 | 115 | \item{perc.k}{Numeric that decides number of decimal places for percentage 116 | labels (Default: `0`).} 117 | 118 | \item{mosaic.offset}{Numeric that decides size of spacing between mosaic 119 | blocks (Default: `.003` which is very narrow). "reasonable" values 120 | probably lie between .05 and .001} 121 | 122 | \item{mosaic.alpha}{Numeric that controls the "alpha" level of the mosaic 123 | plot blocks (Default: `1` which is essentially no "fading"). Values must 124 | be in the range 0 to 1 see: `ggplot2::aes_colour_fill_alpha`} 125 | 126 | \item{bf.details}{Logical that decides whether to display additional 127 | information from the Bayes Factor test in the caption (default:`FALSE`). 128 | This will take precedence over any text you enter as a `caption`.} 129 | 130 | \item{bf.display}{Character that determines how the Bayes factor value is 131 | is displayed. The default is simply the number rounded to `k`. Other 132 | options include "sensible", "log" and "support".} 133 | 134 | \item{sampling.plan}{the sampling plan (see details in ?contingencyTableBF).} 135 | 136 | \item{fixed.margin}{(see details in ?contingencyTableBF).} 137 | 138 | \item{prior.concentration}{(see details in ?contingencyTableBF).} 139 | 140 | \item{paired}{Not used yet.} 141 | 142 | \item{ggtheme}{A function, ggplot2 theme name. Default value is ggplot2::theme_bw(). 143 | Any of the ggplot2 themes, or themes from extension packages are allowed (e.g., 144 | hrbrthemes::theme_ipsum(), etc.).} 145 | 146 | \item{package}{Name of package from which the palette is desired as string 147 | or symbol.} 148 | 149 | \item{palette}{Name of palette as string or symbol.} 150 | 151 | \item{direction}{Either `1` or `-1`. If `-1` the palette will be reversed.} 152 | 153 | \item{ggplot.component}{A ggplot component to be added to the plot prepared by 154 | ggstatsplot. Default is NULL. The argument should be entered as a function. 155 | If the given function has an argument axes.range.restrict and if it has been set 156 | to TRUE, the added ggplot component might not work as expected.} 157 | } 158 | \description{ 159 | Bivariate bar charts for nominal and ordinal data with 160 | (optionally) statistical details included in the plot as a subtitle. 161 | } 162 | \examples{ 163 | 164 | # for reproducibility 165 | set.seed(123) 166 | 167 | # simplest possible call with the defaults 168 | PlotXTabs2( 169 | data = mtcars, 170 | y = vs, 171 | x = cyl 172 | ) 173 | 174 | # more complex call 175 | PlotXTabs2( 176 | data = datasets::mtcars, 177 | y = vs, 178 | x = cyl, 179 | bf.details = TRUE, 180 | labels.legend = c("0 = V-shaped", "1 = straight"), 181 | legend.title = "Engine Style", 182 | legend.position = "right", 183 | title = "The perenial mtcars example", 184 | palette = "Pastel1" 185 | ) 186 | 187 | PlotXTabs2( 188 | data = as.data.frame(HairEyeColor), 189 | y = Eye, 190 | x = Hair, 191 | counts = Freq 192 | ) 193 | 194 | \dontrun{ 195 | # mosaic plot requires ggmosaic 0.2.2 or higher from github 196 | PlotXTabs2( 197 | data = mtcars, 198 | x = vs, 199 | y = am, 200 | plottype = "mosaic", 201 | data.label = "both", 202 | mosaic.alpha = .9, 203 | bf.display = "support", 204 | title = "Motorcars Mosaic Plot VS by AM" 205 | ) 206 | } 207 | 208 | } 209 | \author{ 210 | Chuck Powell, Indrajeet Patil 211 | } 212 | -------------------------------------------------------------------------------- /man/SeeDist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/seedist.R 3 | \name{SeeDist} 4 | \alias{SeeDist} 5 | \title{SeeDist -- See The Distribution} 6 | \usage{ 7 | SeeDist( 8 | x, 9 | title = "Default", 10 | subtitle = "Default", 11 | numbins = 0, 12 | xlab = NULL, 13 | var_explain = NULL, 14 | data.fill.color = "deepskyblue", 15 | mean.line.color = "darkgreen", 16 | median.line.color = "yellow", 17 | mode.line.color = "orange", 18 | mean.line.type = "longdash", 19 | median.line.type = "dashed", 20 | mode.line.type = "dashed", 21 | mean.line.size = 1.5, 22 | median.line.size = 1.5, 23 | mean.point.shape = 21, 24 | median.point.shape = 23, 25 | mean.point.size = 4, 26 | median.point.size = 4, 27 | zcurve.color = "red", 28 | zcurve.type = "twodash", 29 | zcurve.size = 1, 30 | tcurve.color = "black", 31 | tcurve.type = "dotted", 32 | tcurve.size = 1, 33 | mode.line.size = 1, 34 | whatplots = c("d", "b", "h", "v"), 35 | k = 2, 36 | add_jitter = TRUE, 37 | add_rug = TRUE, 38 | xlim_left = NULL, 39 | xlim_right = NULL, 40 | ggtheme = ggplot2::theme_bw() 41 | ) 42 | } 43 | \arguments{ 44 | \item{x}{the data to be visualized. Must be numeric.} 45 | 46 | \item{title}{Optionally replace the default title displayed. title = NULL 47 | will remove it entirely. title = "" will provide an empty title but 48 | retain the spacing. A sensible default is provided otherwise.} 49 | 50 | \item{subtitle}{Optionally replace the default subtitle displayed. subtitle = NULL 51 | will remove it entirely. subtitle = "" will provide an empty subtitle but 52 | retain the spacing. A sensible default is provided otherwise.} 53 | 54 | \item{numbins}{the number of bins to use for any plots that bin. If nothing is 55 | specified the function will calculate a rational number using Freedman-Diaconis 56 | via the \code{nclass.FD} function} 57 | 58 | \item{xlab}{Custom text for the `x` axis label (Default: `NULL`, which 59 | will cause the `x` axis label to be the `x` variable).} 60 | 61 | \item{var_explain}{additional contextual information about the variable as a string 62 | such as "Miles Per Gallon" which is appended to the default title information.} 63 | 64 | \item{data.fill.color}{Character string that specifies fill color for the main data 65 | area (Default: `deepskyblue`).} 66 | 67 | \item{mean.line.color, median.line.color, mode.line.color}{Character string that 68 | specifies line color (Default: `darkgreen`, `yellow`, `orange`).} 69 | 70 | \item{mean.line.type, median.line.type, mode.line.type}{Character string that 71 | specifies line color (Default: `longdash`, `dashed`, `dashed`).} 72 | 73 | \item{mean.line.size, median.line.size, mode.line.size}{Numeric that 74 | specifies line size (Default: `1.5`, `1.5`, `1`). You can set to `0` to make 75 | any of the lines "disappear".} 76 | 77 | \item{mean.point.shape, median.point.shape}{Integer in 0 - 25 78 | specifies shape of mean or median point mark on the violin plot 79 | (Default: `21`, `23`).} 80 | 81 | \item{mean.point.size, median.point.size}{Integer 82 | specifies size of mean or median point mark on the violin plot 83 | (Default: `4`). You can set to `0` to make any of the points "disappear".} 84 | 85 | \item{zcurve.color, tcurve.color}{Character string that 86 | specifies line color (Default: `red`, `black`).} 87 | 88 | \item{zcurve.type, tcurve.type}{Character string that 89 | specifies line color (Default: `twodash`, `dotted`).} 90 | 91 | \item{zcurve.size, tcurve.size}{Numeric that 92 | specifies line size (Default: `1`). You can set to `0` to make 93 | any of the lines "disappear".} 94 | 95 | \item{whatplots}{what type of plots? The default is whatplots = c("d", "b", 96 | "h", "v") for a density, a boxplot, a histogram, and a violin plot} 97 | 98 | \item{k}{Number of digits after decimal point (should be an integer) 99 | (Default: k = 2) for statistical results.} 100 | 101 | \item{add_jitter}{Logical (Default: `TRUE`) controls whether jittered data 102 | ponts are added to violin plot.} 103 | 104 | \item{add_rug}{Logical (Default: `TRUE`) controls whether "rug" data 105 | points are added to density plot and histogram.} 106 | 107 | \item{xlim_left, xlim_right}{Logical. For density plots can be used to 108 | override the default which is 3 std deviations left and right of 109 | the mean of x. Useful for theoretical reasons like horsepower < 0 110 | or when `ggplot2` warns you that it has removed rows containing 111 | non-finite values (stat_density).} 112 | 113 | \item{ggtheme}{A function, ggplot2 theme name. Default value is ggplot2::theme_bw(). 114 | Any of the ggplot2 themes, or themes from extension packages are allowed (e.g., 115 | hrbrthemes::theme_ipsum(), etc.).} 116 | } 117 | \value{ 118 | from 1 to 4 plots depending on what the user specifies as well as an 119 | extensive summary courtesy `DescTools::Desc` printed to the console 120 | } 121 | \description{ 122 | This function takes a vector of numeric data and returns one or more ggplot2 123 | plots that help you visualize the data. Meant to be a useful wrapper for 124 | exploring univariate data. Has a plethora of options including type of 125 | visualization (histogram, boxplot, density, violin) as well as commonly 126 | desired overplots like mean and median points, z and t curves etc.. Common 127 | descriptive statistics are provided as a subtitle if desired and sent to the 128 | console as well. 129 | } 130 | \section{Warning}{ 131 | 132 | If the data has more than 3 modal values only the first three of them are plotted. 133 | The rest are ignored and the user is warned on the console. 134 | 135 | Missing values are removed with a warning to the user 136 | } 137 | 138 | \examples{ 139 | SeeDist(rnorm(100, mean = 100, sd = 20), numbins = 15, var_explain = "A Random Sample") 140 | SeeDist(mtcars$hp, var_explain = "Horsepower", whatplots = c("d", "b")) 141 | SeeDist(iris$Sepal.Length, var_explain = "Sepal Length", whatplots = "d") 142 | } 143 | \seealso{ 144 | \code{\link[grDevices]{nclass}} 145 | } 146 | \author{ 147 | Chuck Powell 148 | } 149 | -------------------------------------------------------------------------------- /man/USvoteS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{USvoteS} 5 | \alias{USvoteS} 6 | \title{U.S. 2000 Election Data (short)} 7 | \format{ 8 | A data frame with 1000 observations on the following 6 variables.: 9 | \describe{ 10 | \item{vote3}{candidate voted for Gore or Bush} 11 | \item{gender}{gender, a factor with levels male and female} 12 | \item{ager}{age group, an ordered factor with levels 18-24 < 25-34 < 35-44 < 45-54 < 55-64 < 65+} 13 | \item{empstat}{status of employment, a factor with levels yes, no or retired} 14 | \item{educr}{status of education, an ordered factor with levels HS < College < Post Coll} 15 | \item{marstat}{status of living situation, a factor with levels married, widowed, divorced or never married} 16 | 17 | } 18 | } 19 | \source{ 20 | https://r-forge.r-project.org/R/?group_id=343 21 | } 22 | \usage{ 23 | USvoteS 24 | } 25 | \description{ 26 | Data from a post-election survey following the year 2000 U.S. 27 | presidential elections. This is a subset from package `CHAID`. 28 | } 29 | \keyword{datasets} 30 | -------------------------------------------------------------------------------- /man/aovtype2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aovtype2.R 3 | \name{aovtype2} 4 | \alias{aovtype2} 5 | \title{Anova Tables for Type 2 sums of squares} 6 | \usage{ 7 | aovtype2(mod) 8 | } 9 | \arguments{ 10 | \item{mod}{aov model object from base R.} 11 | } 12 | \value{ 13 | An object of class "anova", which usually is printed. 14 | } 15 | \description{ 16 | Calculates and displays type-II analysis-of-variance tables for model objects 17 | produced by aov. This is a vastly reduced version of the Anova function from 18 | package car 19 | } 20 | \details{ 21 | Details about how the function works in order of steps taken. 22 | Type-II tests are invariant with respect to (full-rank) contrast coding. 23 | Type-II tests are calculated according to the principle of marginality, 24 | testing each term after all others, except ignoring the term's higher-order 25 | relatives. This definition of Type-II tests corresponds to the tests 26 | produced by SAS for analysis-of-variance models, where all of the 27 | predictors are factors, but not more generally (i.e., when there are 28 | quantitative predictors). 29 | } 30 | \examples{ 31 | 32 | mtcars$cyl <- factor(mtcars$cyl) 33 | mtcars$am <- factor(mtcars$am) 34 | mod <- aov(hp ~ cyl * am, data = mtcars) 35 | aovtype2(mod) 36 | 37 | } 38 | \references{ 39 | : Fox, J. (2016) Applied Regression Analysis and Generalized Linear Models, Third Edition. Sage. 40 | } 41 | \seealso{ 42 | \code{\link[stats]{aov}} 43 | } 44 | \author{ 45 | John Fox jfox@mcmaster.ca; as modified by Chuck Powell 46 | } 47 | -------------------------------------------------------------------------------- /man/bf_display.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{bf_display} 4 | \alias{bf_display} 5 | \title{Choose display type for BF formatting.} 6 | \usage{ 7 | bf_display(bf = NULL, display_type = "bf", k = 2) 8 | } 9 | \arguments{ 10 | \item{bf}{A numeric vector containing one or more BF values.} 11 | 12 | \item{display_type}{A string containing which option one of 13 | "support", "logged", or "sensible".} 14 | 15 | \item{k}{A numeric for the number of rounded digits.} 16 | } 17 | \value{ 18 | a formatted character string. 19 | } 20 | \description{ 21 | Choose display type for BF formatting. 22 | } 23 | \author{ 24 | Chuck Powell 25 | } 26 | -------------------------------------------------------------------------------- /man/chaidUS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{chaidUS} 5 | \alias{chaidUS} 6 | \title{U.S. 2000 Election Data (short)} 7 | \format{ 8 | A partykit on the following 6 variables.: 9 | \describe{ 10 | \item{vote3}{candidate voted for Gore or Bush} 11 | \item{gender}{gender, a factor with levels male and female} 12 | \item{ager}{age group, an ordered factor with levels 18-24 < 25-34 < 35-44 < 45-54 < 55-64 < 65+} 13 | \item{empstat}{status of employment, a factor with levels yes, no or retired} 14 | \item{educr}{status of education, an ordered factor with levels HS < College < Post Coll} 15 | \item{marstat}{status of living situation, a factor with levels married, widowed, divorced or never married} 16 | 17 | } 18 | } 19 | \source{ 20 | https://r-forge.r-project.org/R/?group_id=343 21 | } 22 | \usage{ 23 | chaidUS 24 | } 25 | \description{ 26 | Data from a post-election survey following the year 2000 U.S. 27 | presidential elections. This is a subset from package `CHAID`. 28 | } 29 | \keyword{datasets} 30 | -------------------------------------------------------------------------------- /man/chaid_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chaid_table.R 3 | \name{chaid_table} 4 | \alias{chaid_table} 5 | \title{Produce CHAID results tables from a partykit CHAID model} 6 | \usage{ 7 | chaid_table(chaidobject) 8 | } 9 | \arguments{ 10 | \item{chaidobject}{An object of type `constparty` or `party` which 11 | was produced by `CHAID::chaid` see simple example below.} 12 | } 13 | \value{ 14 | A tibble containing the results. 15 | } 16 | \description{ 17 | Produce CHAID results tables from a partykit CHAID model 18 | } 19 | \examples{ 20 | library(CGPfunctions) 21 | chaid_table(chaidUS) 22 | 23 | } 24 | \author{ 25 | Chuck Powell 26 | } 27 | -------------------------------------------------------------------------------- /man/cross2_var_vectors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cross2_var_vectors.R 3 | \name{cross2_var_vectors} 4 | \alias{cross2_var_vectors} 5 | \title{Cross two vectors of variable names from a dataframe} 6 | \usage{ 7 | cross2_var_vectors(data, x, y, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{the dataframe or tibble the variables are contained in.} 11 | 12 | \item{x, y}{These are either character or integer vectors containing 13 | the names, e.g. "am" or the column numbers e.g. 9} 14 | 15 | \item{verbose}{the default is FALSE, setting to TRUE will cat additional 16 | output to the screen} 17 | } 18 | \value{ 19 | a list with two sublists `lista` and `listb`. Very handy for 20 | feeding the lists to `purrr` for further processing. 21 | } 22 | \description{ 23 | Cross two vectors of variable names from a dataframe 24 | } 25 | \examples{ 26 | cross2_var_vectors(mtcars, 9, c(2, 10:11)) 27 | cross2_var_vectors(mtcars, "am", c("cyl", "gear", "carb")) 28 | x2 <- c("am", "carb") 29 | y2 <- c("vs", "cyl", "gear") 30 | cross2_var_vectors(mtcars, x2, y2, verbose = TRUE) 31 | 32 | \dontrun{ 33 | variables_list <- cross2_var_vectors(mtcars, x2, y2) 34 | mytitles <- stringr::str_c( 35 | stringr::str_to_title(variables_list$listb), 36 | " by ", 37 | stringr::str_to_title(variables_list$lista), 38 | " in mtcars data" 39 | ) 40 | purrr::pmap( 41 | .l = list( 42 | x = variables_list[[1]], # variables_list$lista 43 | y = variables_list[[2]], # variables_list$listb 44 | title = mytitles 45 | ), 46 | .f = CGPfunctions::PlotXTabs2, 47 | data = mtcars, 48 | ylab = NULL, 49 | perc.k = 1, 50 | palette = "Set2" 51 | ) 52 | 53 | } 54 | 55 | } 56 | \author{ 57 | Chuck Powell 58 | } 59 | -------------------------------------------------------------------------------- /man/exponent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{exponent} 4 | \alias{exponent} 5 | \title{Exponent of a number in scientific notation} 6 | \usage{ 7 | exponent(x) 8 | } 9 | \arguments{ 10 | \item{x}{(required) numeric. A number.} 11 | } 12 | \value{ 13 | the exponent of the scientific notation representation of the number \code{x} 14 | } 15 | \description{ 16 | Returns the exponent of a number as it is written in scientific 17 | notation (powers of 10). 18 | } 19 | \references{ 20 | Thanks to Stackoverflow answer by Paul McMurdie \url{https://stackoverflow.com/a/25555105} 21 | } 22 | \author{ 23 | Tom Hopper 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/justifyme.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{justifyme} 4 | \alias{justifyme} 5 | \title{Justification for titles, subtitles and captions.} 6 | \usage{ 7 | justifyme(x) 8 | } 9 | \arguments{ 10 | \item{x}{A numeric or character vector.} 11 | } 12 | \value{ 13 | a numeric value suitable for `ggplot2` `hjust` value. 14 | } 15 | \description{ 16 | Justification for titles, subtitles and captions. 17 | } 18 | \author{ 19 | Chuck Powell 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/newbroom.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{newbroom} 4 | \alias{newbroom} 5 | \title{Tidy Tables for htest objects} 6 | \usage{ 7 | newbroom(x) 8 | } 9 | \arguments{ 10 | \item{x}{An `htest` object, such as those created by [stats::cor.test()], 11 | [stats::t.test()], [stats::wilcox.test()], [stats::chisq.test()], etc.} 12 | } 13 | \value{ 14 | An object of class "tibble". 15 | } 16 | \description{ 17 | Produces tidy tibbles of results from htest objects. 18 | This is a vastly reduced version of the tidy.htest function from 19 | package broom 20 | } 21 | \examples{ 22 | 23 | chit <- chisq.test(xtabs(Freq ~ Sex + Class, data = as.data.frame(Titanic))) 24 | CGPfunctions:::newbroom(chit) 25 | } 26 | \seealso{ 27 | [stats::t.test()], [stats::oneway.test()] 28 | [stats::wilcox.test()], [stats::chisq.test()] 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/newcancer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{newcancer} 5 | \alias{newcancer} 6 | \title{Tufte dataset on cancer survival rates} 7 | \format{ 8 | A data frame with 96 rows and 3 variables: 9 | \describe{ 10 | \item{Year}{ordered factor for the 5, 10, 15 and 20 year survival rates} 11 | \item{Type}{factor containing the name of the cancer type} 12 | \item{Survival}{numeric for this data a whole number corresponding to the percent survival rate} 13 | 14 | } 15 | } 16 | \source{ 17 | \url{https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk} 18 | } 19 | \usage{ 20 | newcancer 21 | } 22 | \description{ 23 | A dataset containing cancer survival rates for different types of cancer 24 | over a 20 year period. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/newgdp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{newgdp} 5 | \alias{newgdp} 6 | \title{Tufte dataset on Gross Domestic Product, 1970 and 1979} 7 | \format{ 8 | A data frame with 30 rows and 3 variables: 9 | \describe{ 10 | \item{Year}{character for 1970 and 1979} 11 | \item{Country}{factor country name} 12 | \item{GDP}{numeric a percentage of gross domestic product} 13 | 14 | } 15 | } 16 | \source{ 17 | Edward Tufte. \emph{Beautiful Evidence}. Graphics Press, 174-176. 18 | } 19 | \usage{ 20 | newgdp 21 | } 22 | \description{ 23 | Current receipts of fifteen national governments as a percentage of gross domestic product 24 | } 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/number_to_word.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{number_to_word} 4 | \alias{number_to_word} 5 | \title{Convert a vector of numbers to large-number word representation} 6 | \usage{ 7 | number_to_word(x, nsmall = 0) 8 | } 9 | \arguments{ 10 | \item{x}{A vector of numbers to convert.} 11 | 12 | \item{nsmall}{Optional. An integer number of digits to include to the right of the the leading digit} 13 | } 14 | \value{ 15 | A string representation of the number 16 | } 17 | \description{ 18 | Converts a vector of numbers to a character string approximation 19 | using the "short scale" version of large number names. e.g. 312e6 returns 20 | as '300 million.' Simultaneously returns a numeric representation of the 21 | approximation. 22 | } 23 | \author{ 24 | Tom Hopper 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /tests/figs/deps.txt: -------------------------------------------------------------------------------- 1 | - vdiffr-svg-engine: 1.0 2 | - vdiffr: 0.3.1 3 | - freetypeharfbuzz: 0.2.5 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(CGPfunctions) 3 | 4 | test_check("CGPfunctions") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-newggslopegraph.R: -------------------------------------------------------------------------------- 1 | test_that("multiplication works", { 2 | expect_equal(2 * 2, 4) 3 | }) 4 | 5 | testthat::test_that( 6 | desc = "insufficient arguments", 7 | code = { 8 | testthat::expect_error( 9 | CGPfunctions::newggslopegraph( 10 | dataframe = mtcars 11 | ) 12 | ) 13 | } 14 | ) 15 | 16 | # path issue? 17 | # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() 18 | # vdiffr::expect_doppelganger("ggplot2 histogram", disp_hist_ggplot) 19 | 20 | # complex formatting with recycling and wider labels see vignette for more examples 21 | # disp_slopegraph1 <- newggslopegraph(newcancer, Year, Survival, Type, 22 | # Title = "Estimates of Percent Survival Rates", 23 | # SubTitle = "Based on: Edward Tufte, Beautiful Evidence, 174, 176.", 24 | # Caption = "https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk", 25 | # LineColor = c("black", "red", "grey"), 26 | # LineThickness = .5 27 | # ) 28 | # vdiffr::expect_doppelganger("slopegraph1", disp_slopegraph1) 29 | 30 | p <- newggslopegraph(newcancer, Year, Survival, Type, 31 | Title = "Estimates of Percent Survival Rates", 32 | SubTitle = "Based on: Edward Tufte, Beautiful Evidence, 174, 176.", 33 | Caption = "https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk", 34 | LineColor = c("black", "red", "grey"), 35 | LineThickness = .5, 36 | WiderLabels = TRUE 37 | ) 38 | pb <- ggplot2::ggplot_build(p) 39 | 40 | testthat::expect_equal(length(pb$data), 5L) 41 | yyy <- c("Prostate", "Thyroid", "Testis", "Melanomas", "Breast", "Hodgkin's", "Uterus", "Urinary", "Cervix", "Larynx", "Rectum", "Kidney", "Colon", "Non-Hodgkin's", "Oral", "Ovary", "Leukemia", "Brain", "Multiple myeloma", "Stomach", "Lung", "Esophagus", "Liver", "Pancreas") 42 | testthat::expect_identical(as.character(pb$data[[3]]$label), yyy) 43 | -------------------------------------------------------------------------------- /vignettes/Using-Plot2WayANOVA.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include = FALSE--------------------------------------------------- 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | 7 | ## ----eval = FALSE------------------------------------------------------------- 8 | # # Install from CRAN 9 | # install.packages("CGPfunctions") 10 | # 11 | # # Or the development version from GitHub 12 | # # install.packages("devtools") 13 | # devtools::install_github("ibecav/CGPfunctions") 14 | 15 | ## ----LoadLibrary, warning = FALSE--------------------------------------------- 16 | library(CGPfunctions) 17 | 18 | ## ----Plot2WayANOVA, echo=TRUE, message=TRUE, warning=FALSE, fig.width=7, fig.height=4---- 19 | Plot2WayANOVA(formula = mpg ~ am * cyl, dataframe = mtcars) 20 | 21 | ## ----Plot2WayANOVA2, echo=TRUE, fig.height=4, fig.width=7, message=FALSE, warning=FALSE---- 22 | Plot2WayANOVA(formula = mpg ~ cyl * am, 23 | dataframe = mtcars, 24 | confidence = .99, 25 | title = "MPG by cylinders and type transmission", 26 | xlab = "Cylinders", 27 | ylab = "Miles per gallon", 28 | mean.label = TRUE, 29 | mean.shape = 22, 30 | posthoc.method = "lsd", 31 | errorbar.display = "SEM" 32 | ) 33 | 34 | ## ----Plot2WayANOVA3, echo=TRUE, fig.height=4, fig.width=7, message=FALSE, warning=FALSE---- 35 | # Create a new dataset 36 | library(dplyr) 37 | library(ggplot2) 38 | library(stringi) 39 | newmpg <- mpg %>% 40 | filter(cyl != 5) %>% 41 | mutate(am = stringi::stri_extract(trans, regex = "auto|manual")) 42 | Plot2WayANOVA(formula = hwy ~ am * cyl, 43 | dataframe = newmpg, 44 | ylab = "Highway mileage", 45 | xlab = "Transmission type", 46 | plottype = "line", 47 | offset.style = "wide", 48 | overlay.type = "box", 49 | mean.label = TRUE, 50 | mean.shape = 20, 51 | mean.size = 3, 52 | mean.label.size = 3, 53 | show.dots = TRUE, 54 | errorbar.display = "SD", 55 | ggtheme = ggplot2::theme_minimal(), 56 | ggplot.component = theme(axis.text.x = element_text(size=14, color="darkblue")) 57 | ) 58 | 59 | -------------------------------------------------------------------------------- /vignettes/Using-PlotXTabs.R: -------------------------------------------------------------------------------- 1 | ## ----setup, echo = FALSE, warning=FALSE, message=FALSE------------------------ 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | library(CGPfunctions) 7 | 8 | ## ----LoadLibrary-------------------------------------------------------------- 9 | library(productplots) 10 | str(happy) 11 | 12 | ## ----vignette1, fig.width=6.0, fig.height=2.5--------------------------------- 13 | # who's happier by gender 14 | PlotXTabs(happy,happy,sex) 15 | # same thing using column numbers and a stacked bar 16 | PlotXTabs(happy,2,5,"stack") 17 | # happiness by a variety of possible factors as a percent 18 | PlotXTabs(happy, 2, c(5:9), plottype = "percent") 19 | # turn the numbers around and change them up basically just showing all 20 | # the permutations 21 | PlotXTabs(happy, c(2,5), 9, plottype = "side") 22 | PlotXTabs(happy, c(2,5), c(6:9), plottype = "percent") 23 | PlotXTabs(happy, happy, c(6,7,9), plottype = "percent") 24 | PlotXTabs(happy, c(6,7,9), happy, plottype = "percent") 25 | 26 | -------------------------------------------------------------------------------- /vignettes/Using-PlotXTabs.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using PlotXTabs" 3 | author: "Chuck Powell" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Using PlotXTabs} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, echo = FALSE, warning=FALSE, message=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | library(CGPfunctions) 18 | ``` 19 | 20 | This function is designed to automate and make efficient a relatively common task in some branches of science. The task of cross tabulating and displaying certain types of variables. It makes use of `dplyr` and `ggplot2` to achieve those ends. 21 | 22 | Imagine that you want to take two of the `mtcars` variables, for example `am` and `cyl`, and conduct a cross tabulation and then plot it. Since it's the sort of thing I'm likely to do often seemed like a good candidate to write a function for. Then I decided that I might very well want the function to allow me to input more than two variables at a time. It would be very tedious to execute the command 25 times if I had 5 dependent variables and 5 independent variables and needed to fully cross them. 23 | 24 | It provides visually appealing and sensibly labelled charts quickly and efficiently. It does some basic error checking and allows the user some choice as to exact style without having to know any underlying syntax or semantics. 25 | 26 | ## Possible cases 27 | 28 | The function is designed to handle four possible scenarios. 29 | 30 | Take the user's input and parse it into one of four known possibilities and then take appropriate action. The possibilities are: 31 | 32 | 1. If both are `bare` variables and found in the dataframe immediately print the plot 33 | 2. At least one of the variables is `bare` and found in the dataframe (variable x) and the other is one or more column numbers (variable y) 34 | 3. At least one of the variables is `bare` and found in the dataframe (variable y) and the other is one or more column numbers (variable x) 35 | 4. Both the variables were passed to us as numbers. Could be one or more numbers for either variable. 36 | 37 | ## Example scenario ... What makes us happy? 38 | 39 | The documentation examples use the `mtcars` built-in dataset. It's handy, convenient, and it's installed by default. To actually show the function in action, however, I'm going to use a different dataset. Something that should allow you to better see the value of making plots of the crosstabs rather than simple tables. It also has the happy property of being much much larger than `mtcars` so we can see if there are lags in performance due to the number of rows. 40 | 41 | Rather than provide my own or make anyone work too hard I selected that `happy` dataset that comes bundled with several `R` packages including `productplots` and `GGally`. From the description: 42 | 43 | > The data is a small sample of variables related to happiness from the general social survey (GSS). The GSS is a yearly cross-sectional survey of Americans, run from 1976. We combine data for 25 years to yield 51,020 observations, and of the over 5,000 variables, we select nine related to happiness. 44 | 45 | We'll load the library and take a quick look at the structure of the data. 46 | 47 | ```{r LoadLibrary} 48 | library(productplots) 49 | str(happy) 50 | ``` 51 | 52 | We'll be focusing on the non numeric variables. I certainly can't claim to do a detailed analysis here but at least the questions will be fun I hope... 53 | 54 | ```{r vignette1, fig.width=6.0, fig.height=2.5} 55 | # who's happier by gender 56 | PlotXTabs(happy,happy,sex) 57 | # same thing using column numbers and a stacked bar 58 | PlotXTabs(happy,2,5,"stack") 59 | # happiness by a variety of possible factors as a percent 60 | PlotXTabs(happy, 2, c(5:9), plottype = "percent") 61 | # turn the numbers around and change them up basically just showing all 62 | # the permutations 63 | PlotXTabs(happy, c(2,5), 9, plottype = "side") 64 | PlotXTabs(happy, c(2,5), c(6:9), plottype = "percent") 65 | PlotXTabs(happy, happy, c(6,7,9), plottype = "percent") 66 | PlotXTabs(happy, c(6,7,9), happy, plottype = "percent") 67 | ``` 68 | 69 | I hope you've found this useful. I am always open to comments, corrections and suggestions. 70 | 71 | Chuck (ibecav at gmail dot com) 72 | 73 | ### License 74 | Creative Commons License
    This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. 75 | 76 | > "He who gives up [code] safety for [code] speed deserves neither." 77 | ([via](https://twitter.com/hadleywickham/status/504368538874703872)) 78 | -------------------------------------------------------------------------------- /vignettes/Using-PlotXTabs2.R: -------------------------------------------------------------------------------- 1 | ## ----setup, echo = FALSE, warning=FALSE, message=FALSE------------------------ 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | library(CGPfunctions) 7 | 8 | ## ----simple, fig.width=7.0, fig.height=3.5------------------------------------ 9 | # simplest possible call with the defaults 10 | PlotXTabs2( 11 | data = mtcars, 12 | y = am, 13 | x = cyl 14 | ) 15 | 16 | ## ----simple2, fig.width=7.0, fig.height=3.5----------------------------------- 17 | # more complex call 18 | PlotXTabs2( 19 | data = datasets::mtcars, 20 | y = am, 21 | x = cyl, 22 | bf.details = TRUE, 23 | xlab = "Number of cylinders", 24 | ylab = NULL, 25 | data.label = "both", 26 | label.fill.alpha = .3, 27 | labels.legend = c("0 = Manual", "1 = Automatic"), 28 | legend.title = "Transmission Type", 29 | legend.position = "left", 30 | title = "The perenial mtcars example", 31 | palette = "Pastel1" 32 | ) 33 | 34 | ## ----LoadLibrary-------------------------------------------------------------- 35 | library(dplyr) 36 | library(purrr) 37 | library(productplots) 38 | library(tidyselect) 39 | str(happy) 40 | 41 | ## ----vignette1, fig.width=7.0, fig.height=3.5--------------------------------- 42 | # who's happier by gender 43 | PlotXTabs2(happy,happy,sex) 44 | 45 | ## ----vignette2, fig.width=7.0, fig.height=3.5--------------------------------- 46 | myvariables <- happy %>% 47 | select_if(is.factor) %>% 48 | select(-happy) %>% 49 | names 50 | mytitles <- stringr::str_c("Happiness by ", 51 | stringr::str_to_title(myvariables), 52 | " status") 53 | 54 | myvariables 55 | mytitles 56 | 57 | purrr::map2(.x = myvariables, 58 | .y = mytitles, 59 | .f = ~ PlotXTabs2(x = all_of(.x), 60 | title = .y, 61 | data = happy, 62 | y = happy, 63 | legend.title = "Rating", 64 | xlab = stringr::str_to_title(.x), 65 | ylab = NULL, 66 | perc.k = 1, 67 | palette = "Set2" 68 | ) 69 | ) 70 | 71 | -------------------------------------------------------------------------------- /vignettes/Using-PlotXTabs2.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using PlotXTabs2" 3 | author: "Chuck Powell" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Using PlotXTabs2} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, echo = FALSE, warning=FALSE, message=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | library(CGPfunctions) 18 | ``` 19 | 20 | Like `PlotXTabs` this function is designed to automate and make efficient a 21 | relatively common task in some branches of science. The task of cross tabulating 22 | and displaying certain nominal and ordinal variables. It makes use of the 23 | `tidyverse` and to achieve those ends and is optimized to work with `purrr`. 24 | 25 | Imagine that you want to take two of the `mtcars` variables, for example `am` 26 | and `cyl`, and conduct a cross tabulation, get some basic statistics about 27 | whether they are "independent" and then plot it. Since it's the sort of thing 28 | I'm likely to do often seemed like a good candidate for a function. The function 29 | should allow us to efficiently repeat across more than two variables at a time. 30 | It would be very tedious to execute the command 25 times if I had 1 dependent 31 | variables and 25 independent variables. 32 | 33 | It provides visually appealing and sensibly labelled charts quickly and 34 | efficiently. It does some basic error checking and allows the user some choice 35 | as to exact style without having to know any underlying syntax or semantics. 36 | 37 | ```{r simple, fig.width=7.0, fig.height=3.5} 38 | # simplest possible call with the defaults 39 | PlotXTabs2( 40 | data = mtcars, 41 | y = am, 42 | x = cyl 43 | ) 44 | ``` 45 | 46 | ## Important considerations 47 | 48 | 1. The variables may be `bare` or quoted text. 49 | 50 | 2. By default a simple summary of key frequentist and bayesian information is 51 | supplied but this subtitle can be suppressed. 52 | 53 | 3. Thanks to `ggstatsplot` there are a plethora of formatting options. 54 | 55 | To demonstrate just a few... 56 | 57 | ```{r simple2, fig.width=7.0, fig.height=3.5} 58 | # more complex call 59 | PlotXTabs2( 60 | data = datasets::mtcars, 61 | y = am, 62 | x = cyl, 63 | bf.details = TRUE, 64 | xlab = "Number of cylinders", 65 | ylab = NULL, 66 | data.label = "both", 67 | label.fill.alpha = .3, 68 | labels.legend = c("0 = Manual", "1 = Automatic"), 69 | legend.title = "Transmission Type", 70 | legend.position = "left", 71 | title = "The perenial mtcars example", 72 | palette = "Pastel1" 73 | ) 74 | ``` 75 | 76 | ## Example scenario ... What makes us happy? 77 | 78 | The documentation examples use the `mtcars` and `HairEyeColor` built-in 79 | datasets. They are handy, convenient, and available by default. To demonstrate 80 | the function in action, however, I'm going to use a different dataset. Something 81 | that should allow you to better see the value of making plots of the crosstabs 82 | rather than simple tables. It also has the happy property of being much much 83 | larger than `mtcars` so we can see if there are lags in performance due to the 84 | number of rows. 85 | 86 | Rather than provide my own or make anyone work too hard I selected that `happy` 87 | dataset that comes bundled with several `R` packages including `productplots` 88 | and `GGally`. From the description: 89 | 90 | > The data is a small sample of variables related to happiness from the general 91 | social survey (GSS). The GSS is a yearly cross-sectional survey of Americans, 92 | run from 1976. We combine data for 25 years to yield 51,020 observations, and of 93 | the over 5,000 variables, we select nine related to happiness. 94 | 95 | We'll load the library and take a quick look at the structure of the data. 96 | 97 | ```{r LoadLibrary} 98 | library(dplyr) 99 | library(purrr) 100 | library(productplots) 101 | library(tidyselect) 102 | str(happy) 103 | ``` 104 | 105 | We'll be focusing on the non numeric variables. I certainly can't claim to do a 106 | detailed analysis here but at least the questions will be fun I hope... Here's 107 | the shortest possible call. 108 | 109 | ```{r vignette1, fig.width=7.0, fig.height=3.5} 110 | # who's happier by gender 111 | PlotXTabs2(happy,happy,sex) 112 | ``` 113 | 114 | That's useful, especially when you consider the variety of formatting options, 115 | but far more useful in my work flows when we make use of `purrr` `map` 116 | operators. Let's imagine a scenario where we want to see how happiness is 117 | related to all the other `factor` (categorical - be they nomainal or ordinal) 118 | variables in our dataset. For each of them (`sex`, `marital`, `degree`, 119 | `finrela` and `health`) we want to plot consistent graphs and have the same 120 | information available. Rather than the tedium of cutting and pasting five times 121 | and then changing the variable name let's let `purrr` handles as much of the 122 | workflow as possible. 123 | 124 | Using a simple set of `dplyr` verbs we'll create a simple list of the variables 125 | we are interested in. Technically it's a vector but `purrr` will coerce it to a 126 | list. Since I dislike plots without titles we can also create a vector of titles 127 | by prepending "Happiness by " to the capitalized variable name. 128 | 129 | After checking our handiwork in creating the vectors we can then feed them to 130 | `purrr:map2`. We could conceivably have used any `map` depending on complexity. 131 | Just for a little "twist" we'll actually use the `myvariables` list twice. Once 132 | as the variable name for the x variable and then again after capitalizing it as 133 | the X axis label. 134 | 135 | ```{r vignette2, fig.width=7.0, fig.height=3.5} 136 | myvariables <- happy %>% 137 | select_if(is.factor) %>% 138 | select(-happy) %>% 139 | names 140 | mytitles <- stringr::str_c("Happiness by ", 141 | stringr::str_to_title(myvariables), 142 | " status") 143 | 144 | myvariables 145 | mytitles 146 | 147 | purrr::map2(.x = myvariables, 148 | .y = mytitles, 149 | .f = ~ PlotXTabs2(x = all_of(.x), 150 | title = .y, 151 | data = happy, 152 | y = happy, 153 | legend.title = "Rating", 154 | xlab = stringr::str_to_title(.x), 155 | ylab = NULL, 156 | perc.k = 1, 157 | palette = "Set2" 158 | ) 159 | ) 160 | ``` 161 | 162 | ### Leaving Feedback 163 | If you like CGPfunctions, please consider Filing a GitHub issue by [leaving 164 | feedback here](https://github.com/ibecav/CGPfunctions/issues), or by contacting 165 | me at ibecav at gmail.com by email. 166 | 167 | I hope you've found this useful. I am always open to comments, corrections and 168 | suggestions. 169 | 170 | Chuck 171 | 172 | ### License 173 | Creative Commons License
    This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. 174 | 175 | -------------------------------------------------------------------------------- /vignettes/Using-chaid_table.R: -------------------------------------------------------------------------------- 1 | ## ----setup, echo = FALSE, warning=FALSE, message=FALSE------------------------ 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | 7 | ## ----one, fig.width=7.0, fig.height=5.5, warning=FALSE, message=FALSE--------- 8 | library(CGPfunctions) 9 | # library(CHAID) 10 | library(dplyr) 11 | library(knitr) 12 | 13 | ### fit tree to subsample see ?chaid 14 | ## set.seed(290875) 15 | ## USvoteS <- USvote[sample(1:nrow(USvote), 1000),] 16 | 17 | ## ctrl <- chaid_control(minsplit = 200, minprob = 0.1) 18 | ## chaidUS <- chaid(vote3 ~ ., data = USvoteS, control = ctrl) 19 | print(chaidUS) 20 | plot(chaidUS) 21 | 22 | ## ----simple2, fig.width=7.0, fig.height=3.5----------------------------------- 23 | # simplest use --- chaidUS is included in the package 24 | class(chaidUS) 25 | 26 | chaid_table(chaidUS) 27 | 28 | mychaidtable <- chaid_table(chaidUS) 29 | 30 | ## ----simple3------------------------------------------------------------------ 31 | mychaidtable %>% 32 | select(nodeID:ruletext) %>% 33 | kable() 34 | 35 | # Just node #2 show percentage 36 | mychaidtable %>% 37 | select(nodeID:ruletext) %>% 38 | filter(nodeID == 2) %>% 39 | mutate(pctBush = Bush/NodeN * 100) %>% 40 | kable(digits = 1) 41 | 42 | # Just the children of node #5 43 | mychaidtable %>% 44 | select(nodeID:ruletext) %>% 45 | filter(parent == 5) %>% 46 | kable() 47 | 48 | # stats for all splits including raw (unadjusted) p value 49 | mychaidtable %>% 50 | select(nodeID, NodeN, split.variable:rawpvalue) %>% 51 | filter(!is.na(split.variable)) %>% 52 | kable() 53 | 54 | 55 | -------------------------------------------------------------------------------- /vignettes/Using-chaid_table.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using chaid_table" 3 | author: "Chuck Powell" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Using chaid_table} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, echo = FALSE, warning=FALSE, message=FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | **Chi-square automatic interaction detection (CHAID)** is a decision tree 20 | technique, based on adjusted significance testing (Bonferroni testing). The 21 | technique was developed in South Africa and was published in 1980 by Gordon V. 22 | Kass, who had completed a PhD thesis on this topic. [Wikipedia](https://en.wikipedia.org/wiki/Chi-square_automatic_interaction_detection) 23 | 24 | I've [written a few blog posts](https://ibecav.netlify.app/tags/chaid/) about 25 | using this venerable technique. The default output using `print()` and `plot()` 26 | is sparse, elegant and useful as is, and can be adjusted in many ways that [I 27 | have documented here](https://ibecav.github.io/chaidtutor1/). 28 | 29 | The code chunk below is taken straight from the example in the help page for 30 | `CHAID::chaid` 31 | 32 | > The dataset is based on data from a post-election survey on persons who voted for either Bush or Gore in the 2000 U.S. election. The specific variables are related to the publication of Magidson and Vermunt (2005). 33 | 34 | > Further information (and datasets) about the 2000 U.S. election and other National Election Studies is available on the American National Election Studies Web site (https://electionstudies.org/). 35 | 36 | 37 | ```{r one, fig.width=7.0, fig.height=5.5, warning=FALSE, message=FALSE} 38 | library(CGPfunctions) 39 | # library(CHAID) 40 | library(dplyr) 41 | library(knitr) 42 | 43 | ### fit tree to subsample see ?chaid 44 | ## set.seed(290875) 45 | ## USvoteS <- USvote[sample(1:nrow(USvote), 1000),] 46 | 47 | ## ctrl <- chaid_control(minsplit = 200, minprob = 0.1) 48 | ## chaidUS <- chaid(vote3 ~ ., data = USvoteS, control = ctrl) 49 | print(chaidUS) 50 | plot(chaidUS) 51 | ``` 52 | 53 | ## Getting more detailed 54 | 55 | But what happens if you want to investigate your results more closely? I 56 | actually had at least one reader of my blog posts point out that [some other 57 | statistical 58 | packages](https://www.ibm.com/support/knowledgecenter/en/SSLVMB_23.0.0/spss/tutorials/tree_credit_treetable.html#tree_credit_treetable) 59 | produce more detailed information in a tabular format. 60 | 61 | Some additional things you may want to know that are actually contained in 62 | `chaidUS` but aren't especially easy to see from the default plot and print and 63 | aren't necessarily easy to ferret out of the `chaidUS` object: 64 | 65 | 1. It's clear from our call that we fed `chaid` 1,000 random rows of the 66 | dataset `USvote`. It must be safe to assume that's how many valid cases there were 67 | right? The documentation is mute on how it handles missing cases. 68 | 69 | 2. There's information about counts and frequencies in the terminal nodes (3, 4, 70 | 6, 8, 9) and we could manually calculate the answers to other questions like 71 | how many people voted for Bush in node #9 (115 * 40.9% = 47)? How many total 72 | voters are in node #2 (311 + 249 = 560)? But getting more information gets 73 | increasingly tedious. At node #2 what was the breakdown of votes for Bush -v- 74 | Gore (hint 245 -v- 315 respectively). 75 | 76 | 3. It would also be nice to have easy access to the results of the $\chi^2$ 77 | tests that are the inherent workhorse of CHAID. We know that `marstat` was 78 | selected as the first split by virtue of having the smallest `p value` after 79 | a Bonferroni adjustment, but what were the results? 80 | 81 | `chaid_table` attempts to provide much more granular information in a tibble and 82 | also make it possible for you to derive even more nuanced questions through 83 | piping operations. The simplest call is just to feed it the name of the object 84 | after it has been processed by `CHAID`. That object will be of class 85 | "constparty" "party". 86 | 87 | ```{r simple2, fig.width=7.0, fig.height=3.5} 88 | # simplest use --- chaidUS is included in the package 89 | class(chaidUS) 90 | 91 | chaid_table(chaidUS) 92 | 93 | mychaidtable <- chaid_table(chaidUS) 94 | ``` 95 | 96 | I debated the wisdom of providing tables as output in the manner I found most 97 | useful and aesthetically pleasing but in the end decided to simply provide the 98 | tibble and let the user decide what and how to format. 99 | 100 | ## Example uses 101 | 102 | Some easy examples using `kable` and `dplyr`. 103 | 104 | ```{r simple3} 105 | mychaidtable %>% 106 | select(nodeID:ruletext) %>% 107 | kable() 108 | 109 | # Just node #2 show percentage 110 | mychaidtable %>% 111 | select(nodeID:ruletext) %>% 112 | filter(nodeID == 2) %>% 113 | mutate(pctBush = Bush/NodeN * 100) %>% 114 | kable(digits = 1) 115 | 116 | # Just the children of node #5 117 | mychaidtable %>% 118 | select(nodeID:ruletext) %>% 119 | filter(parent == 5) %>% 120 | kable() 121 | 122 | # stats for all splits including raw (unadjusted) p value 123 | mychaidtable %>% 124 | select(nodeID, NodeN, split.variable:rawpvalue) %>% 125 | filter(!is.na(split.variable)) %>% 126 | kable() 127 | 128 | ``` 129 | 130 | Hopefully those are enough examples to get your creative juices going. 131 | 132 | ### Leaving Feedback 133 | If you like CGPfunctions, please consider Filing a GitHub issue by [leaving 134 | feedback here](https://github.com/ibecav/CGPfunctions/issues), or by contacting 135 | me at ibecav at gmail.com by email. 136 | 137 | I hope you've found this useful. I am always open to comments, corrections and 138 | suggestions. 139 | 140 | Chuck 141 | 142 | ### License 143 | Creative Commons License
    This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. 144 | 145 | -------------------------------------------------------------------------------- /vignettes/Using-newggslopegraph.R: -------------------------------------------------------------------------------- 1 | ## ----setup-------------------------------------------------------------------- 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | # Install from CRAN 7 | # install.packages("CGPfunctions") 8 | 9 | # Or the development version from GitHub 10 | # install.packages("devtools") 11 | # devtools::install_github("ibecav/CGPfunctions") 12 | library(CGPfunctions) 13 | library(tidyr) 14 | library(dplyr) 15 | 16 | ## ----ggslope1, fig.height=10, fig.width=7------------------------------------- 17 | newggslopegraph(newcancer,Year,Survival,Type) 18 | 19 | ## ----ggslope2, fig.height=10, fig.width=7------------------------------------- 20 | newggslopegraph(dataframe = newcancer, 21 | Times = Year, 22 | Measurement = Survival, 23 | Grouping = Type, 24 | Title = "Estimates of Percent Survival Rates", 25 | SubTitle = "Based on: Edward Tufte, Beautiful Evidence, 174, 176.", 26 | Caption = NULL 27 | ) 28 | 29 | ## ----ggslope3, fig.height=5, fig.width=5-------------------------------------- 30 | moredata <- structure(list(Date = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), 31 | .Label = c("11-May-18", "18-May-18", "25-May-18"), 32 | class = "factor"), 33 | Party = structure(c(5L, 3L, 2L, 1L, 4L, 5L, 3L, 2L, 1L, 4L, 5L, 3L, 2L, 1L, 4L), 34 | .Label = c("Green", "Liberal", "NDP", "Others", "PC"), 35 | class = "factor"), 36 | Pct = c(42.3, 28.4, 22.1, 5.4, 1.8, 41.9, 29.3, 22.3, 5, 1.4, 41.9, 26.8, 26.8, 5, 1.4)), 37 | class = "data.frame", 38 | row.names = c(NA, -15L)) 39 | #tail(moredata) 40 | newggslopegraph(moredata,Date,Pct,Party, Title = "Notional data", SubTitle = NULL, Caption = NULL) 41 | 42 | ## ----ggslope4, fig.height=5, fig.width=5-------------------------------------- 43 | newggslopegraph(moredata, Date, Pct, Party, 44 | Title = "Notional data", 45 | SubTitle = "none", 46 | Caption = "imaginary", 47 | LineColor = "gray", 48 | LineThickness = .5, 49 | YTextSize = 4 50 | ) 51 | 52 | ## ----ggslope5, fig.height=5, fig.width=5-------------------------------------- 53 | newggslopegraph(moredata, Date, Pct, Party, 54 | Title = "Notional data", 55 | SubTitle = "none", 56 | Caption = "imaginary", 57 | LineColor = c("Green" = "gray", "Liberal" = "green", "NDP" = "red", "Others" = "gray", "PC" = "gray"), 58 | LineThickness = .5, 59 | YTextSize = 4 60 | ) 61 | 62 | ## ----ggslope6, fig.height=12, fig.width=6------------------------------------- 63 | newggslopegraph(newgdp, 64 | Year, 65 | GDP, 66 | Country, 67 | Title = "Gross GDP", 68 | SubTitle = NULL, 69 | Caption = NULL, 70 | LineThickness = .5, 71 | YTextSize = 4, 72 | LineColor = c(rep("gray",3), "red", rep("gray",3), "red", rep("gray",10)) 73 | ) 74 | 75 | ## ----ggslope7, fig.height=7, fig.width=6-------------------------------------- 76 | newgdp$rGDP <- signif(newgdp$GDP, 2) 77 | newggslopegraph(newgdp, 78 | Year, 79 | rGDP, 80 | Country, 81 | Title = "Gross GDP", 82 | SubTitle = NULL, 83 | Caption = NULL, 84 | LineThickness = .5, 85 | YTextSize = 4, 86 | LineColor = c(rep("gray",6), rep("red",2), "red", rep("gray",10)) 87 | ) 88 | 89 | custom_colors <- tidyr::pivot_wider(newgdp, 90 | id_cols = Country, 91 | names_from = Year, 92 | values_from = GDP) %>% 93 | mutate(difference = Year1979 - Year1970) %>% 94 | mutate(trend = case_when( 95 | difference >= 2 ~ "green", 96 | difference <= -1 ~ "red", 97 | TRUE ~ "gray" 98 | ) 99 | ) %>% 100 | select(Country, trend) %>% 101 | tibble::deframe() 102 | 103 | custom_colors 104 | 105 | newggslopegraph(newgdp, 106 | Year, 107 | rGDP, 108 | Country, 109 | Title = "Gross GDP", 110 | SubTitle = NULL, 111 | Caption = NULL, 112 | LineThickness = .5, 113 | YTextSize = 4, 114 | LineColor = custom_colors 115 | ) 116 | 117 | 118 | --------------------------------------------------------------------------------