diff --git a/DESCRIPTION b/DESCRIPTION index bc405a3..f6d71b7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rstatix Type: Package Title: Pipe-Friendly Framework for Basic Statistical Tests -Version: 0.7.1.999 +Version: 0.7.2 Authors@R: c( person("Alboukadel", "Kassambara", role = c("aut", "cre"), email = "alboukadel.kassambara@gmail.com")) Description: Provides a simple and intuitive pipe-friendly framework, coherent with the 'tidyverse' design philosophy, @@ -43,7 +43,7 @@ Suggests: spelling URL: https://rpkgs.datanovia.com/rstatix/ BugReports: https://github.com/kassambara/rstatix/issues -RoxygenNote: 7.1.0 +RoxygenNote: 7.2.3 Collate: 'utilities.R' 'add_significance.R' diff --git a/NEWS.md b/NEWS.md index 75fd124..3734879 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,12 +1,9 @@ -# rstatix 0.7.1.999 +# rstatix 0.7.2 -## New features - -## Major changes - ## Minor changes - Required `tidyselect` versions is `>= 1.2.0` + ## Bug fixes - `emmeans_test()`: restoring grouping variable class (`factor`) in the final results `emmeans_test()` (#169) diff --git a/_pkgdown.yml b/_pkgdown.yml index 0b73e5f..fe87fe9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -77,7 +77,7 @@ reference: contents: - adjust_pvalue - add_significance - - p_value + - p_round - title: Extract Information From Statistical Tests contents: - get_test_label diff --git a/cran-comments.md b/cran-comments.md index 68d5861..93a731d 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -8,4 +8,4 @@ There were no ERRORs, WARNINGs or NOTEs. ## Update -This is an updated version 0.7.1 (see NEWS.md). +This is an updated version 0.7.2 (see NEWS.md). diff --git a/docs/404.html b/docs/404.html index 4170c41..4a549be 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,68 +1,27 @@ - - - - + + + + - Page not found (404) • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - -
-
- + +
+ + + - - -
+
+
-
+ + - - diff --git a/docs/authors.html b/docs/authors.html index bf96f52..4b81e50 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,68 +1,12 @@ - - - - - - - -Authors • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • rstatix - - + + - - - -
-
-
- -
+
- @@ -128,22 +79,20 @@

Authors

-
- +
- - + + diff --git a/docs/index.html b/docs/index.html index 2820a0a..2a4ee82 100644 --- a/docs/index.html +++ b/docs/index.html @@ -27,6 +27,8 @@ + +
- - -
+
-
-

-rstatix 0.7.1 Unreleased -

-
-

-Minor changes

-
    +
    + +
    +

    Minor changes

    +
    • Required tidyselect versions is >= 1.2.0 +
    +
    +

    Bug fixes

    +
    +
    +
    + +
    +

    Minor changes

    +
    • +cor_plot() now accepts additional arguments to pass to corrplot() (#66)
    • +
    • suppressMessages() used to suppress this message (“Coefficient covariances computed by hccm()”) generated by car::Anova().
    • -cor_plot() now accepts additional arguments to pass to corrplot() (#66)
    • -
    • suppressMessages() used to suppress this message (“Coefficient covariances computed by hccm()”) generated by car::Anova().
    • -
    • -get_comparisons() now drops unused levels before creating possible comparisons (#67)
    • -
    • Now, the function get_summary_stats() keeps the order of columns specified by the user (#46).
    • -
    • internal two_sample_test() now counts group sizes (n1 and n2) by the number of non-NA values #104 +get_comparisons() now drops unused levels before creating possible comparisons (#67)
    • +
    • Now, the function get_summary_stats() keeps the order of columns specified by the user (#46).
    • +
    • internal two_sample_test() now counts group sizes (n1 and n2) by the number of non-NA values #104
    • -
    -
    -
    -

    -Bug fixes

    -
      -
    • Name collisions bug fixes in the shapiro_test() function. Shapiro_test() throws an error if the input data contains column names “value” or “variable”. This is fixed now (#52).
    • -
    • Bug fixed in the cor_test() function, where there was a tidy evaluation conflict when the input data contains “x” and “y” as column names (#68).
    • -
    • The dunn_test() documentation is updated to describe the discrepancy between the default behavior of the rstatix::dunn_test() compared to other packages (dunn.test and jamovi). The default of the rstatix::dunn_test() function is to perform a two-sided Dunn test like the well known commercial softwares, such as SPSS and GraphPad. This is not the case for some other R packages (dunn.test and jamovi), where the default is to perform one-sided test (#50).
    • -
    • Now, the function get_summary_stats() handles the user defined probabilities for grouped data (#78)
    • -
    -
    -
    -
    -

    -rstatix 0.7.0 2021-02-13 -

    -
    -

    -New features

    -
      -
    • New function to extract information from rstatix statistical tests: - get_n() to extract sample count (n) from statistical test results. - get_description to extract stat test description or name - remove_ns() to remove non-significant rows.
    • -
    -
    -
    -

    -Major changes

    -
      -
    • Rewriting add_x_position() to better support different situations (#73).
    • -
    • Now, the output of the function dunn_test() include estimate1 and estimate2 when the argument detailed = TRUE is specified. The estimate1 and estimate2 values represent the mean rank values of the two groups being compared, respectively (#59).
    • -
    -
    -
    -

    -Minor changes

    -
      +
    +
    +

    Bug fixes

    +
    • Name collisions bug fixes in the shapiro_test() function. Shapiro_test() throws an error if the input data contains column names “value” or “variable”. This is fixed now (#52).
    • +
    • Bug fixed in the cor_test() function, where there was a tidy evaluation conflict when the input data contains “x” and “y” as column names (#68).
    • +
    • The dunn_test() documentation is updated to describe the discrepancy between the default behavior of the rstatix::dunn_test() compared to other packages (dunn.test and jamovi). The default of the rstatix::dunn_test() function is to perform a two-sided Dunn test like the well known commercial softwares, such as SPSS and GraphPad. This is not the case for some other R packages (dunn.test and jamovi), where the default is to perform one-sided test (#50).
    • +
    • Now, the function get_summary_stats() handles the user defined probabilities for grouped data (#78)
    • +
    +
    +
    + +
    +

    New features

    +
    • New function to extract information from rstatix statistical tests: - get_n() to extract sample count (n) from statistical test results. - get_description to extract stat test description or name - remove_ns() to remove non-significant rows.
    +
    +

    Major changes

    +
    • Rewriting add_x_position() to better support different situations (#73).
    • +
    • Now, the output of the function dunn_test() include estimate1 and estimate2 when the argument detailed = TRUE is specified. The estimate1 and estimate2 values represent the mean rank values of the two groups being compared, respectively (#59).
    • +
    +
    +

    Minor changes

    +
    • +cor_spread() doc updated, error is explicitly shown if the input data doesn’t contain the columns “var1”, “var2” and “cor” (#95)
    • +
    • Maintenance updates of the functions emmeans_test() and levene_test() to adapt to broom release 0.7.4 (#89)
    • +
    • The documentation of the function anova_test() is updated to explain the internal contrast setting (#74).
    • +
    • Now, p_mark_significance() works when all p-values are NA. Empty character ("") is returned for NA (#64).
    • +
    • Classes (rstatix and grouped_anova_test) added to grouped ANOVA test (#61)
    • +
    • New argument scales added in the function get_y_position(). If the specified value is “free” or “free_y”, then the step increase of y positions will be calculated by plot panels. Note that, using “free” or “free_y” gives the same result. A global step increase is computed when scales = “fixed” (#56).
    • +
    +
    +

    Bug fixes

    +
    • The function anova_test() computes now repeated measures ANOVA without error when unused columns are present in the input data frame (#55)
    +
    +
    + +
    +

    Minor changes

    +
    • Adapted to upcoming broom v0.7.0 release (#49)
    • +
    • New argument stack added in get_y_position() to compute p-values y position for stacked bar plots (#48).
    • -cor_spread() doc updated, error is explicitly shown if the input data doesn’t contain the columns “var1”, “var2” and “cor” (#95)
    • -
    • Maintenance updates of the functions emmeans_test() and levene_test() to adapt to broom release 0.7.4 (#89)
    • -
    • The documentation of the function anova_test() is updated to explain the internal contrast setting (#74).
    • -
    • Now, p_mark_significance() works when all p-values are NA. Empty character ("") is returned for NA (#64).
    • -
    • Classes (rstatix and grouped_anova_test) added to grouped ANOVA test (#61)
    • -
    • New argument scales added in the function get_y_position(). If the specified value is “free” or “free_y”, then the step increase of y positions will be calculated by plot panels. Note that, using “free” or “free_y” gives the same result. A global step increase is computed when scales = “fixed” (#56).
    • -
    -
    -
    -

    -Bug fixes

    -
      -
    • The function anova_test() computes now repeated measures ANOVA without error when unused columns are present in the input data frame (#55)
    • -
    -
    -
    -
    -

    -rstatix 0.6.0 2020-06-18 -

    -
    -

    -Minor changes

    -
      -
    • Adapted to upcoming broom v0.7.0 release (#49)
    • -
    • New argument stack added in get_y_position() to compute p-values y position for stacked bar plots (#48).
    • -
    • -wilcox_test(): Now, if detailed = TRUE, an estimate of the location parameter (Only present if argument detailed = TRUE). This corresponds to the pseudomedian (for one-sample case) or to the difference of the location parameter (for two-samples case) (#45).
    • -
    -
    -
    -

    -Bug fixes

    -
      -
    • -anova_test() function: Changing R default contrast setting (contr.treatment) into orthogonal contrasts (contr.sum) to have comparable results to SPSS when users define the model using formula (@benediktclaus, #40).
    • -
    • Now, the option type = "quantile" of get_summary_stats() works properly (@Boyoron, #39).
    • -
    -
    -
    -
    -

    -rstatix 0.5.0 2020-04-28 -

    -
    -

    -New features

    -
      -
    • New functions added for easy data frame manipulation. These functions are internally used in the rstatix and the ggpubr package and makes it easy to program with tidyverse packages using non standard evaluation. - df_select - df_arrange - df_group_by - df_nest_by - df_split_by - df_unite - df_get_var_names - df_label_both - df_label_value
    • -
    -
    -
    -

    -Minor changes

    -
      -
    • Now, in freq_table() the option na.rm removes only missing values in the variables used to create the frequency table (@JuhlinF, #25).
    • -
    • Missing values are now correctly handled in anova_test() (@benediktclaus, #31)
    • -
    • Maintenance for adapting to the future dplyr 1.0.0 version #32 +wilcox_test(): Now, if detailed = TRUE, an estimate of the location parameter (Only present if argument detailed = TRUE). This corresponds to the pseudomedian (for one-sample case) or to the difference of the location parameter (for two-samples case) (#45).
    • +
    +
    +

    Bug fixes

    +
    • +anova_test() function: Changing R default contrast setting (contr.treatment) into orthogonal contrasts (contr.sum) to have comparable results to SPSS when users define the model using formula (@benediktclaus, #40).
    • +
    • Now, the option type = "quantile" of get_summary_stats() works properly (@Boyoron, #39).
    • +
    +
    +
    + +
    +

    New features

    +
    • New functions added for easy data frame manipulation. These functions are internally used in the rstatix and the ggpubr package and makes it easy to program with tidyverse packages using non standard evaluation. - df_select - df_arrange - df_group_by - df_nest_by - df_split_by - df_unite - df_get_var_names - df_label_both - df_label_value
    +
    +

    Minor changes

    +
    • Now, in freq_table() the option na.rm removes only missing values in the variables used to create the frequency table (@JuhlinF, #25).
    • +
    • Missing values are now correctly handled in anova_test() (@benediktclaus, #31)
    • +
    • Maintenance for adapting to the future dplyr 1.0.0 version #32
    • -
    -
    -
    -

    -Bug fixes

    -
      -
    • An informative message is now displayed when users try to apply Hedge’s correction when computing the Cohen’s D for one sample test (@GegznaV, #36).
    • -
    • Bug fixes in the games_howell_test() function : the t-statistic is now calculated using the absolute mean difference between groups (@GegznaV, #37).
    • -
    • x position is now correctly computed when when making custom comparisons (@barrel0luck, #28).
    • -
    -
    -
    -
    -

    -rstatix 0.4.0 2020-02-13 -

    -
    -

    -New features

    -
      -
    • The cohens_d() function now supports Hedge’s correction. New argument hedge.correction added . logical indicating whether apply the Hedges correction by multiplying the usual value of Cohen’s d by (N-3)/(N-2.25) (for unpaired t-test) and by (n1-2)/(n1-1.25) for paired t-test; where N is the total size of the two groups being compared (N = n1 + n2) (@IndrajeetPatil, #9).
    • -
    -
    -
    -

    -Minor changes

    -
      -
    • Now, the function cohens_d() outputs values with directionality. The absolute value is no longer returned. It can now be positive or negative depending on the data (@narunpat, #9).
    • -
    -
    -
    -

    -Bug fixes

    - -
    -
    -
    -

    -rstatix 0.3.1 2019-12-16 -

    -
    -

    -Minor changes

    -
      -
    • tidyr > 1.0.0 now required
    • +
    +
    +

    Bug fixes

    +
    • An informative message is now displayed when users try to apply Hedge’s correction when computing the Cohen’s D for one sample test (@GegznaV, #36).
    • +
    • Bug fixes in the games_howell_test() function : the t-statistic is now calculated using the absolute mean difference between groups (@GegznaV, #37).
    • +
    • x position is now correctly computed when when making custom comparisons (@barrel0luck, #28).
    • +
    +
    +
    + +
    +

    New features

    +
    • The cohens_d() function now supports Hedge’s correction. New argument hedge.correction added . logical indicating whether apply the Hedges correction by multiplying the usual value of Cohen’s d by (N-3)/(N-2.25) (for unpaired t-test) and by (n1-2)/(n1-1.25) for paired t-test; where N is the total size of the two groups being compared (N = n1 + n2) (@IndrajeetPatil, #9).
    +
    +

    Minor changes

    +
    • Now, the function cohens_d() outputs values with directionality. The absolute value is no longer returned. It can now be positive or negative depending on the data (@narunpat, #9).
    +
    +

    Bug fixes

    +
    +
    +
    + +
    +

    Minor changes

    +
    • tidyr > 1.0.0 now required
    • know, identify_outliers returns a basic data frame instead of tibble when nrow = 0 (for nice printing)
    • new argument detailed added in dunn_test(). If TRUE, then estimate and method columns are shown in the results.
    • -
    -
    -
    -
    -

    -rstatix 0.3.0 2019-11-14 -

    -
    -

    -New features

    -
      -
    • -prop_test(), pairwise_prop_test() and row_wise_prop_test(). Performs one-sample and two-samples z-test of proportions. Wrappers around the R base function prop.test() but have the advantage of performing pairwise and row-wise z-test of two proportions, the post-hoc tests following a significant chi-square test of homogeneity for 2xc and rx2 contingency tables.
    • +
    +
    +
    + +
    +

    New features

    + -
    -
    -

    -Minor changes

    -
    +
    +

    Minor changes

    + +
-
-
-

-rstatix 0.2.0 2019-09-03 -

-
-

-Minor changes

-
    -
  • +
    + +
    +

    Minor changes

    +
    • get_anova_table() supports now an object of class grouped_anova_test
    • ANOVA table is now correctly returned when correction = "none" for repeated measures ANOVA
    • -NAs are now automatically removed before quantile computation for identifying outliers (@IndrajeetPatil, #10).
    • +NAs are now automatically removed before quantile computation for identifying outliers (@IndrajeetPatil, #10).
    • Unquoted factor variable name is now supported in factor manipulation functions: set_ref_level(), reorder_levels() and make_valid_levels()
    • New argument model added in the function emmeans_test()
    • -
    • Adapting to tidyr v1.0.0 (@jennybc, #6)
    • -
    -
    -
    -

    -New features

    -
      -
    • New function welch_anova_test(): Welch one-Way ANOVA test. A wrapper around the base function stats::oneway.test(). This is is an alternative to the standard one-way ANOVA in the situation where the homogeneity of variance assumption is violated.
    • +
    • Adapting to tidyr v1.0.0 (@jennybc, #6)
    • +
    +
    +

    New features

    +
    • New function welch_anova_test(): Welch one-Way ANOVA test. A wrapper around the base function stats::oneway.test(). This is is an alternative to the standard one-way ANOVA in the situation where the homogeneity of variance assumption is violated.
    • New function friedman_effsize(), computes the effect size of Friedman test using the Kendall’s W value.
    • New function friedman_test(), provides a pipe-friendly framework to perform a Friedman rank sum test, which is the non-parametric alternative to the one-way repeated measures ANOVA test.
    • New function games_howell_test(): Performs Games-Howell test, which is used to compare all possible combinations of group differences when the assumption of homogeneity of variances is violated.
    • @@ -350,14 +217,11 @@

    • New functions added to extract information from statistical tests: get_anova_label()
    • New function emmeans_test() added for pairwise comparisons of estimated marginal means.
    • -

    -
    -
    -

    -Minor changes

    -
    +
    +

    Minor changes

    + -
    -
    -

    -Bug fixes

    -
      -
    • -detailed arguments correctly propagated when grouped stats are performed
    • -
    -
    -
    -
    -

    -rstatix 0.1.1 2019-06-20 -

    -
    -

    -New features

    -
      -
    • New function get_pvalue_position added to autocompute p-value positions for plotting significance using ggplot2.
    • +
    +
    +

    Bug fixes

    +
    • +detailed arguments correctly propagated when grouped stats are performed
    +
    +
    + +
    +

    New features

    +
    • New function get_pvalue_position added to autocompute p-value positions for plotting significance using ggplot2.
    • New function get_comparisons() added to create a list of possible pairwise comparisons between groups.
    • New function dunn_test() added for multiple pairwise comparisons following Kruskal-Wallis test.
    • New function sign_test() added.
    • -
    -
    -
    -

    -Minor changes

    -
      -
    • +
    +
    +

    Minor changes

    + +
+
+

Bug fixes

+
  • the argument detatiled is now passed to compare_pairs().
-
-

-Bug fixes

-
    -
  • the argument detatiled is now passed to compare_pairs().
  • -
-
-
-
-

-rstatix 0.1.0 2019-05-27 -

+
+

First release

+
-
- +
- - + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css index c01e592..80ea5b8 100644 --- a/docs/pkgdown.css +++ b/docs/pkgdown.css @@ -56,8 +56,10 @@ img.icon { float: right; } -img { +/* Ensure in-page images don't run outside their container */ +.contents img { max-width: 100%; + height: auto; } /* Fix bug in bootstrap (only seen in firefox) */ @@ -78,11 +80,10 @@ dd { /* Section anchors ---------------------------------*/ a.anchor { - margin-left: -30px; - display:inline-block; - width: 30px; - height: 30px; - visibility: hidden; + display: none; + margin-left: 5px; + width: 20px; + height: 20px; background-image: url(./link.svg); background-repeat: no-repeat; @@ -90,17 +91,15 @@ a.anchor { background-position: center center; } -.hasAnchor:hover a.anchor { - visibility: visible; -} - -@media (max-width: 767px) { - .hasAnchor:hover a.anchor { - visibility: hidden; - } +h1:hover .anchor, +h2:hover .anchor, +h3:hover .anchor, +h4:hover .anchor, +h5:hover .anchor, +h6:hover .anchor { + display: inline-block; } - /* Fixes for fixed navbar --------------------------*/ .contents h1, .contents h2, .contents h3, .contents h4 { @@ -244,14 +243,14 @@ nav[data-toggle='toc'] .nav .nav > .active:focus > a { .ref-index th {font-weight: normal;} -.ref-index td {vertical-align: top;} +.ref-index td {vertical-align: top; min-width: 100px} .ref-index .icon {width: 40px;} .ref-index .alias {width: 40%;} .ref-index-icons .alias {width: calc(40% - 40px);} .ref-index .title {width: 60%;} .ref-arguments th {text-align: right; padding-right: 10px;} -.ref-arguments th, .ref-arguments td {vertical-align: top;} +.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} .ref-arguments .name {width: 20%;} .ref-arguments .desc {width: 80%;} @@ -264,31 +263,26 @@ table { /* Syntax highlighting ---------------------------------------------------- */ -pre { - word-wrap: normal; - word-break: normal; - border: 1px solid #eee; -} - -pre, code { +pre, code, pre code { background-color: #f8f8f8; color: #333; } +pre, pre code { + white-space: pre-wrap; + word-break: break-all; + overflow-wrap: break-word; +} -pre code { - overflow: auto; - word-wrap: normal; - white-space: pre; +pre { + border: 1px solid #eee; } -pre .img { +pre .img, pre .r-plt { margin: 5px 0; } -pre .img img { +pre .img img, pre .r-plt img { background-color: #fff; - display: block; - height: auto; } code a, pre a { @@ -305,9 +299,8 @@ a.sourceLine:hover { .kw {color: #264D66;} /* keyword */ .co {color: #888888;} /* comment */ -.message { color: black; font-weight: bolder;} -.error { color: orange; font-weight: bolder;} -.warning { color: #6A0366; font-weight: bolder;} +.error {font-weight: bolder;} +.warning {font-weight: bolder;} /* Clipboard --------------------------*/ @@ -365,3 +358,27 @@ mark { content: ""; } } + +/* Section anchors --------------------------------- + Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 +*/ + +div.csl-bib-body { } +div.csl-entry { + clear: both; +} +.hanging-indent div.csl-entry { + margin-left:2em; + text-indent:-2em; +} +div.csl-left-margin { + min-width:2em; + float:left; +} +div.csl-right-inline { + margin-left:2em; + padding-left:1em; +} +div.csl-indent { + margin-left: 2em; +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js index 7e7048f..6f0eee4 100644 --- a/docs/pkgdown.js +++ b/docs/pkgdown.js @@ -80,7 +80,7 @@ $(document).ready(function() { var copyButton = ""; - $(".examples, div.sourceCode").addClass("hasCopyButton"); + $("div.sourceCode").addClass("hasCopyButton"); // Insert copy buttons: $(copyButton).prependTo(".hasCopyButton"); @@ -91,7 +91,7 @@ // Initialize clipboard: var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { text: function(trigger) { - return trigger.parentNode.textContent; + return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); } }); diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 6c05149..f80af02 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,6 +1,6 @@ pandoc: 2.7.3 -pkgdown: 1.5.1 +pkgdown: 2.0.7 pkgdown_sha: ~ -articles: [] -last_built: 2022-11-09T00:52Z +articles: {} +last_built: 2023-02-01T19:47Z diff --git a/docs/reference/Manova.html b/docs/reference/Manova.html index 688fe1d..880f6fa 100644 --- a/docs/reference/Manova.html +++ b/docs/reference/Manova.html @@ -1,69 +1,12 @@ - - - - - - - -Manova exported from car package — Manova • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Manova exported from car package — Manova • rstatix + + - - - - -
-
- -
- -
+
-

See car::Manova for details.

+

See car::Manova for details.

-
+
-
- +
- - + + diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png new file mode 100644 index 0000000..17a3580 Binary files /dev/null and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/Rplot002.png b/docs/reference/Rplot002.png new file mode 100644 index 0000000..b9cdf9a Binary files /dev/null and b/docs/reference/Rplot002.png differ diff --git a/docs/reference/Rplot003.png b/docs/reference/Rplot003.png new file mode 100644 index 0000000..a279412 Binary files /dev/null and b/docs/reference/Rplot003.png differ diff --git a/docs/reference/Rplot004.png b/docs/reference/Rplot004.png new file mode 100644 index 0000000..323bf51 Binary files /dev/null and b/docs/reference/Rplot004.png differ diff --git a/docs/reference/Rplot005.png b/docs/reference/Rplot005.png new file mode 100644 index 0000000..195d560 Binary files /dev/null and b/docs/reference/Rplot005.png differ diff --git a/docs/reference/Rplot006.png b/docs/reference/Rplot006.png new file mode 100644 index 0000000..3a4ed5d Binary files /dev/null and b/docs/reference/Rplot006.png differ diff --git a/docs/reference/Rplot007.png b/docs/reference/Rplot007.png new file mode 100644 index 0000000..72759ef Binary files /dev/null and b/docs/reference/Rplot007.png differ diff --git a/docs/reference/Rplot008.png b/docs/reference/Rplot008.png new file mode 100644 index 0000000..e38379a Binary files /dev/null and b/docs/reference/Rplot008.png differ diff --git a/docs/reference/add_significance.html b/docs/reference/add_significance.html index 0e611d0..e2301cc 100644 --- a/docs/reference/add_significance.html +++ b/docs/reference/add_significance.html @@ -1,69 +1,12 @@ - - - - - - - -Add P-value Significance Symbols — add_significance • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add P-value Significance Symbols — add_significance • rstatix - - - - + + -
-
- -
- -
+
@@ -122,81 +52,83 @@

Add P-value Significance Symbols

Add p-value significance symbols into a data frame.

-
add_significance(
-  data,
-  p.col = NULL,
-  output.col = NULL,
-  cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
-  symbols = c("****", "***", "**", "*", "ns")
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
data

a data frame containing a p-value column.

p.col

column name containing p-values.

output.col

the output column name to hold the adjusted p-values.

cutpoints

numeric vector used for intervals.

symbols

character vector, one shorter than cutpoints, used as -significance symbols.

- -

Value

- -

a data frame

- -

Examples

-
# Perform pairwise comparisons and adjust p-values -ToothGrowth %>% - t_test(len ~ dose) %>% - adjust_pvalue() %>% - add_significance("p.adj")
#> # A tibble: 3 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 -6.48 38.0 1.27e- 7 2.54e- 7 **** -#> 2 len 0.5 2 20 20 -11.8 36.9 4.4 e-14 1.32e-13 **** -#> 3 len 1 2 20 20 -4.90 37.1 1.91e- 5 1.91e- 5 ****
-
+
+
add_significance(
+  data,
+  p.col = NULL,
+  output.col = NULL,
+  cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
+  symbols = c("****", "***", "**", "*", "ns")
+)
+
+ +
+

Arguments

+
data
+

a data frame containing a p-value column.

+ + +
p.col
+

column name containing p-values.

+ + +
output.col
+

the output column name to hold the adjusted p-values.

+ + +
cutpoints
+

numeric vector used for intervals.

+ + +
symbols
+

character vector, one shorter than cutpoints, used as +significance symbols.

+ +
+
+

Value

+ + +

a data frame

+
+ +
+

Examples

+
# Perform pairwise comparisons and adjust p-values
+ToothGrowth %>%
+ t_test(len ~ dose) %>%
+ adjust_pvalue() %>%
+ add_significance("p.adj")
+#> # A tibble: 3 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df        p    p.adj p.adj.signif
+#>   <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 len   0.5    1         20    20     -6.48  38.0 1.27e- 7 2.54e- 7 ****        
+#> 2 len   0.5    2         20    20    -11.8   36.9 4.4 e-14 1.32e-13 ****        
+#> 3 len   1      2         20    20     -4.90  37.1 1.91e- 5 1.91e- 5 ****        
+
+
+
+
-
- - + + diff --git a/docs/reference/adjust_pvalue.html b/docs/reference/adjust_pvalue.html index 7ae4307..52c9e82 100644 --- a/docs/reference/adjust_pvalue.html +++ b/docs/reference/adjust_pvalue.html @@ -1,70 +1,13 @@ - - - - - - - -Adjust P-values for Multiple Comparisons — adjust_pvalue • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Adjust P-values for Multiple Comparisons — adjust_pvalue • rstatix - - + + - - -
-
- -
- -
+
@@ -124,72 +54,74 @@

Adjust P-values for Multiple Comparisons

a data frame. Supports grouped data.

-
adjust_pvalue(data, p.col = NULL, output.col = NULL, method = "holm")
- -

Arguments

- - - - - - - - - - - - - - - - - - -
data

a data frame containing a p-value column

p.col

column name containing p-values

output.col

the output column name to hold the adjusted p-values

method

method for adjusting p values (see -p.adjust). Allowed values include "holm", "hochberg", +

+
adjust_pvalue(data, p.col = NULL, output.col = NULL, method = "holm")
+
+ +
+

Arguments

+
data
+

a data frame containing a p-value column

+ + +
p.col
+

column name containing p-values

+ + +
output.col
+

the output column name to hold the adjusted p-values

+ + +
method
+

method for adjusting p values (see +p.adjust). Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't want to -adjust the p value (not recommended), use p.adjust.method = "none".

- -

Value

- -

a data frame

- -

Examples

-
# Perform pairwise comparisons and adjust p-values -ToothGrowth %>% - t_test(len ~ dose) %>% - adjust_pvalue()
#> # A tibble: 3 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 -6.48 38.0 1.27e- 7 2.54e- 7 **** -#> 2 len 0.5 2 20 20 -11.8 36.9 4.4 e-14 1.32e-13 **** -#> 3 len 1 2 20 20 -4.90 37.1 1.91e- 5 1.91e- 5 ****
-
+adjust the p value (not recommended), use p.adjust.method = "none".

+ +
+
+

Value

+ + +

a data frame

+
+ +
+

Examples

+
# Perform pairwise comparisons and adjust p-values
+ToothGrowth %>%
+ t_test(len ~ dose) %>%
+ adjust_pvalue()
+#> # A tibble: 3 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df        p    p.adj p.adj.signif
+#>   <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 len   0.5    1         20    20     -6.48  38.0 1.27e- 7 2.54e- 7 ****        
+#> 2 len   0.5    2         20    20    -11.8   36.9 4.4 e-14 1.32e-13 ****        
+#> 3 len   1      2         20    20     -4.90  37.1 1.91e- 5 1.91e- 5 ****        
+
+
+
+
- - - + + diff --git a/docs/reference/anova_summary.html b/docs/reference/anova_summary.html index 6e09633..b12c875 100644 --- a/docs/reference/anova_summary.html +++ b/docs/reference/anova_summary.html @@ -1,72 +1,15 @@ - - - - - - - -Create Nice Summary Tables of ANOVA Results — anova_summary • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create Nice Summary Tables of ANOVA Results — anova_summary • rstatix - - - - - - - - - - + + - - - -
-
- -
- -
+

Create beautiful summary tables of ANOVA test results obtained - from either Anova() or aov().

+ from either Anova() or aov().

The results include ANOVA table, generalized effect size and some assumption checks.

-
anova_summary(object, effect.size = "ges", detailed = FALSE, observed = NULL)
+
+
anova_summary(object, effect.size = "ges", detailed = FALSE, observed = NULL)
+
+ +
+

Arguments

+
object
+

an object of returned by either Anova(), or +aov().

+ -

Arguments

- - - - - - - - - - - - - - - - - - -
object

an object of returned by either Anova(), or -aov().

effect.size

the effect size to compute and to show in the ANOVA +

effect.size
+

the effect size to compute and to show in the ANOVA results. Allowed values can be either "ges" (generalized eta squared) or -"pes" (partial eta squared) or both. Default is "ges".

detailed

If TRUE, returns extra information (sums of squares columns, -intercept row, etc.) in the ANOVA table.

observed

Variables that are observed (i.e, measured) as compared to +"pes" (partial eta squared) or both. Default is "ges".

+ + +
detailed
+

If TRUE, returns extra information (sums of squares columns, +intercept row, etc.) in the ANOVA table.

+ + +
observed
+

Variables that are observed (i.e, measured) as compared to experimentally manipulated. The default effect size reported (generalized -eta-squared) requires correct specification of the observed variables.

+eta-squared) requires correct specification of the observed variables.

-

Value

+
+
+

Value

+ -

return an object of class anova_test a data frame containing +

return an object of class anova_test a data frame containing the ANOVA table for independent measures ANOVA. However, for repeated/mixed measures ANOVA, it is a list containing the following components are returned:

-

    -
  • ANOVA: a data frame containing ANOVA results

  • +

    +
    • ANOVA: a data frame containing ANOVA results

    • Mauchly's Test for Sphericity: If any within-Ss variables with more than 2 levels are present, a data frame containing the results of Mauchly's test for Sphericity. Only reported for effects that have more than 2 levels @@ -172,16 +103,16 @@

      Value

    • Sphericity Corrections: If any within-Ss variables are present, a data frame containing the Greenhouse-Geisser and Huynh-Feldt epsilon values, and corresponding corrected p-values.

    • -
    - -

    The returned object might have an attribute called args if - you compute ANOVA using the function anova_test(). The attribute args is a +

The returned object might have an attribute called args if + you compute ANOVA using the function anova_test(). The attribute args is a list holding the arguments used to fit the ANOVA model, including: data, dv, within, between, type, model, etc.

+ +

The following abbreviations are used in the different results tables:

-

    -
  • DFn Degrees of Freedom in the numerator (i.e. DF effect).

  • +

    +
    • DFn Degrees of Freedom in the numerator (i.e. DF effect).

    • DFd Degrees of Freedom in the denominator (i.e., DF error).

    • SSn Sum of Squares in the numerator (i.e., SS effect).

    • SSd Sum of @@ -203,103 +134,117 @@

      Value

    • p[HFe]<.05 Highlights p-values (after correction using Huynh-Feldt epsilon) less than the traditional alpha level of .05.

    • W Mauchly's W statistic

    • -
    - -

    See also

    - - - -

    Examples

    -
    # Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth -df$dose <- as.factor(df$dose) +
+
+

See also

+ +
+
+

Author

+

Alboukadel Kassambara, alboukadel.kassambara@gmail.com

+
-# Independent measures ANOVA -#::::::::::::::::::::::::::::::::::::::::: -# Compute ANOVA and display the summary -res.anova <- Anova(lm(len ~ dose*supp, data = df)) -anova_summary(res.anova)
#> Effect DFn DFd F p p<.05 ges -#> 1 dose 2 54 92.000 4.05e-18 * 0.773 -#> 2 supp 1 54 15.572 2.31e-04 * 0.224 -#> 3 dose:supp 2 54 4.107 2.20e-02 * 0.132
-# Display both SSn and SSd using detailed = TRUE -# Show generalized eta squared using effect.size = "ges" -anova_summary(res.anova, detailed = TRUE, effect.size = "ges")
#> Effect SSn SSd DFn DFd F p p<.05 ges -#> 1 dose 2426.434 712.106 2 54 92.000 4.05e-18 * 0.773 -#> 2 supp 205.350 712.106 1 54 15.572 2.31e-04 * 0.224 -#> 3 dose:supp 108.319 712.106 2 54 4.107 2.20e-02 * 0.132
-# Show partial eta squared using effect.size = "pes" -anova_summary(res.anova, detailed = TRUE, effect.size = "pes")
#> Effect SSn SSd DFn DFd F p p<.05 pes -#> 1 dose 2426.434 712.106 2 54 92.000 4.05e-18 * 0.773 -#> 2 supp 205.350 712.106 1 54 15.572 2.31e-04 * 0.224 -#> 3 dose:supp 108.319 712.106 2 54 4.107 2.20e-02 * 0.132
-# Repeated measures designs using car::Anova() -#::::::::::::::::::::::::::::::::::::::::: -# Prepare the data -df$id <- as.factor(rep(1:10, 6)) # Add individuals ids -head(df)
#> len supp dose id -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 3 -#> 4 5.8 VC 0.5 4 -#> 5 6.4 VC 0.5 5 -#> 6 10.0 VC 0.5 6
-# Easily perform repeated measures ANOVA using the car package -design <- factorial_design(df, dv = len, wid = id, within = c(supp, dose)) -res.anova <- Anova(design$model, idata = design$idata, idesign = design$idesign, type = 3) -anova_summary(res.anova)
#> $ANOVA -#> Effect DFn DFd F p p<.05 ges -#> 1 supp 1 9 34.866 2.28e-04 * 0.224 -#> 2 dose 2 18 106.470 1.06e-10 * 0.773 -#> 3 supp:dose 2 18 2.534 1.07e-01 0.132 -#> -#> $`Mauchly's Test for Sphericity` -#> Effect W p p<.05 -#> 1 dose 0.807 0.425 -#> 2 supp:dose 0.934 0.761 -#> -#> $`Sphericity Corrections` -#> Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF] -#> 1 dose 0.838 1.68, 15.09 2.79e-09 * 1.008 2.02, 18.15 1.06e-10 -#> 2 supp:dose 0.938 1.88, 16.88 1.12e-01 1.176 2.35, 21.17 1.07e-01 -#> p[HF]<.05 -#> 1 * -#> 2 -#>
-# Repeated measures designs using stats::Aov() -#::::::::::::::::::::::::::::::::::::::::: -res.anova <- aov(len ~ dose*supp + Error(id/(supp*dose)), data = df) -anova_summary(res.anova)
#> Effect DFn DFd F p p<.05 ges -#> 1 supp 1 9 34.866 2.28e-04 * 0.242 -#> 2 dose 2 18 106.470 1.06e-10 * 0.791 -#> 3 dose:supp 2 18 2.534 1.07e-01 0.144
+
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+
+# Independent measures ANOVA
+#:::::::::::::::::::::::::::::::::::::::::
+# Compute ANOVA and display the summary
+res.anova <- Anova(lm(len ~ dose*supp, data = df))
+anova_summary(res.anova)
+#>      Effect DFn DFd      F        p p<.05   ges
+#> 1      dose   2  54 92.000 4.05e-18     * 0.773
+#> 2      supp   1  54 15.572 2.31e-04     * 0.224
+#> 3 dose:supp   2  54  4.107 2.20e-02     * 0.132
+
+# Display both SSn and SSd using detailed = TRUE
+# Show generalized eta squared using effect.size = "ges"
+anova_summary(res.anova, detailed = TRUE, effect.size = "ges")
+#>      Effect      SSn     SSd DFn DFd      F        p p<.05   ges
+#> 1      dose 2426.434 712.106   2  54 92.000 4.05e-18     * 0.773
+#> 2      supp  205.350 712.106   1  54 15.572 2.31e-04     * 0.224
+#> 3 dose:supp  108.319 712.106   2  54  4.107 2.20e-02     * 0.132
+
+# Show partial eta squared using effect.size = "pes"
+anova_summary(res.anova, detailed = TRUE, effect.size = "pes")
+#>      Effect      SSn     SSd DFn DFd      F        p p<.05   pes
+#> 1      dose 2426.434 712.106   2  54 92.000 4.05e-18     * 0.773
+#> 2      supp  205.350 712.106   1  54 15.572 2.31e-04     * 0.224
+#> 3 dose:supp  108.319 712.106   2  54  4.107 2.20e-02     * 0.132
+
+# Repeated measures designs using car::Anova()
+#:::::::::::::::::::::::::::::::::::::::::
+# Prepare the data
+df$id <- as.factor(rep(1:10, 6)) # Add individuals ids
+head(df)
+#>    len supp dose id
+#> 1  4.2   VC  0.5  1
+#> 2 11.5   VC  0.5  2
+#> 3  7.3   VC  0.5  3
+#> 4  5.8   VC  0.5  4
+#> 5  6.4   VC  0.5  5
+#> 6 10.0   VC  0.5  6
+
+# Easily perform repeated measures ANOVA using the car package
+design <- factorial_design(df, dv = len, wid = id, within = c(supp, dose))
+res.anova <- Anova(design$model, idata = design$idata, idesign = design$idesign, type = 3)
+anova_summary(res.anova)
+#> $ANOVA
+#>      Effect DFn DFd       F        p p<.05   ges
+#> 1      supp   1   9  34.866 2.28e-04     * 0.224
+#> 2      dose   2  18 106.470 1.06e-10     * 0.773
+#> 3 supp:dose   2  18   2.534 1.07e-01       0.132
+#> 
+#> $`Mauchly's Test for Sphericity`
+#>      Effect     W     p p<.05
+#> 1      dose 0.807 0.425      
+#> 2 supp:dose 0.934 0.761      
+#> 
+#> $`Sphericity Corrections`
+#>      Effect   GGe      DF[GG]    p[GG] p[GG]<.05   HFe      DF[HF]    p[HF]
+#> 1      dose 0.838 1.68, 15.09 2.79e-09         * 1.008 2.02, 18.15 1.06e-10
+#> 2 supp:dose 0.938 1.88, 16.88 1.12e-01           1.176 2.35, 21.17 1.07e-01
+#>   p[HF]<.05
+#> 1         *
+#> 2          
+#> 
+
+# Repeated measures designs using stats::Aov()
+#:::::::::::::::::::::::::::::::::::::::::
+res.anova <- aov(len ~ dose*supp + Error(id/(supp*dose)), data = df)
+anova_summary(res.anova)
+#>      Effect DFn DFd       F        p p<.05   ges
+#> 1      supp   1   9  34.866 2.28e-04     * 0.242
+#> 2      dose   2  18 106.470 1.06e-10     * 0.791
+#> 3 dose:supp   2  18   2.534 1.07e-01       0.144
+
+
+
- - - + + diff --git a/docs/reference/anova_test.html b/docs/reference/anova_test.html index 9d27247..beedfb1 100644 --- a/docs/reference/anova_test.html +++ b/docs/reference/anova_test.html @@ -1,48 +1,5 @@ - - - - - - - -Anova Test — anova_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Anova Test — anova_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Provides a pipe-friendly framework to perform different types of - ANOVA tests, including:

The function is an easy to use wrapper around Anova() and + aov(). It makes ANOVA computation handy in R and It's highly flexible: can support model and formula as input. Variables can be also specified as character vector using the arguments dv, wid, between, within, covariate.

@@ -160,126 +87,122 @@

Anova Test

checks.

-
anova_test(
-  data,
-  formula,
-  dv,
-  wid,
-  between,
-  within,
-  covariate,
-  type = NULL,
-  effect.size = "ges",
-  error = NULL,
-  white.adjust = FALSE,
-  observed = NULL,
-  detailed = FALSE
-)
-
-get_anova_table(x, correction = c("auto", "GG", "HF", "none"))
-
-# S3 method for anova_test
-print(x, ...)
-
-# S3 method for anova_test
-plot(x, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame or a model to be analyzed.

formula

a formula specifying the ANOVA model similar to - aov. Can be of the form y ~ group where y is a +

+
anova_test(
+  data,
+  formula,
+  dv,
+  wid,
+  between,
+  within,
+  covariate,
+  type = NULL,
+  effect.size = "ges",
+  error = NULL,
+  white.adjust = FALSE,
+  observed = NULL,
+  detailed = FALSE
+)
+
+get_anova_table(x, correction = c("auto", "GG", "HF", "none"))
+
+# S3 method for anova_test
+print(x, ...)
+
+# S3 method for anova_test
+plot(x, ...)
+
+ +
+

Arguments

+
data
+

a data.frame or a model to be analyzed.

+ + +
formula
+

a formula specifying the ANOVA model similar to + aov. Can be of the form y ~ group where y is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, formula = TP53 ~ cancer_group.

-

Examples of supported formula include:

    -
  • Between-Ss ANOVA +

    Examples of supported formula include:

    • Between-Ss ANOVA (independent measures ANOVA): y ~ b1*b2

    • Within-Ss ANOVA (repeated measures ANOVA): y ~ w1*w2 + Error(id/(w1*w2))

    • Mixed ANOVA: y ~ b1*b2*w1 + Error(id/w1)

    • -
    - -

    If the formula doesn't contain any within vars, a linear model is directly +

If the formula doesn't contain any within vars, a linear model is directly fitted and passed to the ANOVA function. For repeated designs, the ANOVA - variables are parsed from the formula.

dv

(numeric) dependent variable name.

wid

(factor) column name containing individuals/subjects identifier. -Should be unique per individual.

between

(optional) between-subject factor variables.

within

(optional) within-subjects factor variables

covariate

(optional) covariate names (for ANCOVA)

type

the type of sums of squares for ANOVA. Allowed values are either + variables are parsed from the formula.

+ + +
dv
+

(numeric) dependent variable name.

+ + +
wid
+

(factor) column name containing individuals/subjects identifier. +Should be unique per individual.

+ + +
between
+

(optional) between-subject factor variables.

+ + +
within
+

(optional) within-subjects factor variables

+ + +
covariate
+

(optional) covariate names (for ANCOVA)

+ + +
type
+

the type of sums of squares for ANOVA. Allowed values are either 1, 2 or 3. type = 2 is the default because this will yield identical ANOVA results as type = 1 when data are balanced but type = 2 will additionally yield various assumption tests where appropriate. When the data are unbalanced the type = 3 is used by popular commercial softwares -including SPSS.

effect.size

the effect size to compute and to show in the ANOVA +including SPSS.

+ + +
effect.size
+

the effect size to compute and to show in the ANOVA results. Allowed values can be either "ges" (generalized eta squared) or -"pes" (partial eta squared) or both. Default is "ges".

error

(optional) for a linear model, an lm model object from which the +"pes" (partial eta squared) or both. Default is "ges".

+ + +
error
+

(optional) for a linear model, an lm model object from which the overall error sum of squares and degrees of freedom are to be calculated. -Read more in Anova() documentation.

white.adjust

Default is FALSE. If TRUE, heteroscedasticity correction +Read more in Anova() documentation.

+ + +
white.adjust
+

Default is FALSE. If TRUE, heteroscedasticity correction is applied to the coefficient of covariance matrix. Used only for -independent measures ANOVA.

observed

Variables that are observed (i.e, measured) as compared to +independent measures ANOVA.

+ + +
observed
+

Variables that are observed (i.e, measured) as compared to experimentally manipulated. The default effect size reported (generalized -eta-squared) requires correct specification of the observed variables.

detailed

If TRUE, returns extra information (sums of squares columns, -intercept row, etc.) in the ANOVA table.

x

an object of class anova_test

correction

character. Used only in repeated measures ANOVA test to +eta-squared) requires correct specification of the observed variables.

+ + +
detailed
+

If TRUE, returns extra information (sums of squares columns, +intercept row, etc.) in the ANOVA table.

+ + +
x
+

an object of class anova_test

+ + +
correction
+

character. Used only in repeated measures ANOVA test to specify which correction of the degrees of freedom should be reported for -the within-subject factors. Possible values are:

    -
  • "GG": +the within-subject factors. Possible values are:

    • "GG": applies Greenhouse-Geisser correction to all within-subjects factors even if the assumption of sphericity is met (i.e., Mauchly's test is not significant, p > 0.05).

    • @@ -289,183 +212,206 @@

      Arg
    • "auto": apply automatically GG correction to only within-subjects factors violating the sphericity assumption (i.e., Mauchly's test p-value is significant, p <= 0.05).

    • -

...

additional arguments

+ + -

Value

+
...
+

additional arguments

+ +
+
+

Value

+ -

return an object of class anova_test a data frame containing +

return an object of class anova_test a data frame containing the ANOVA table for independent measures ANOVA.

+ +

However, for repeated/mixed measures ANOVA, a list containing the following components are returned: ANOVA table, Mauchly's Test for Sphericity, Sphericity Corrections. These table are described more in the documentation - of the function anova_summary().

+ of the function anova_summary().

+ +

The returned object has an attribute called args, which is a list holding the arguments used to fit the ANOVA model, including: data, dv, within, between, type, model, etc.

-

Details

- +
+
+

Details

The setting in anova_test() is done in such a way that it gives the same results as SPSS, one of the most used commercial software. By default, R uses treatment contrasts, where each of the levels is compared to the first level used as baseline. The default contrast can be checked using - options('contrasts'). In the function anova_test(), the + options('contrasts'). In the function anova_test(), the following setting is used - options(contrasts=c('contr.sum','contr.poly')), which gives + options(contrasts=c('contr.sum','contr.poly')), which gives orthogonal contrasts where you compare every level to the overall mean. This setting gives the same output as the most commonly used commercial softwares, like SPSS. If you want to obtain the same result with the - function car::Anova() as the one obtained with + function car::Anova() as the one obtained with rstatix::anova_test(), then don't forget to set - options(contrasts=c('contr.sum','contr.poly')).

-

Functions

- + options(contrasts=c('contr.sum','contr.poly')).

+
+
+

Functions

-
    -
  • anova_test: perform anova test

  • -
  • get_anova_table: extract anova table from an object of class +

    • anova_test(): perform anova test

    • +
    • get_anova_table(): extract anova table from an object of class anova_test. When within-subject factors are present, either sphericity corrected or uncorrected degrees of freedom can be reported.

    • -
    -

    See also

    - - - -

    Examples

    -
    # Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# One-way ANOVA test -#::::::::::::::::::::::::::::::::::::::::: -df %>% anova_test(len ~ dose)
    #> ANOVA Table (type II tests) -#> -#> Effect DFn DFd F p p<.05 ges -#> 1 dose 1 58 105.065 1.23e-14 * 0.644
    -# Grouped One-way ANOVA test -#::::::::::::::::::::::::::::::::::::::::: -df %>% - group_by(supp) %>% - anova_test(len ~ dose)
    #> # A tibble: 2 x 8 -#> supp Effect DFn DFd F p `p<.05` ges -#> * <fct> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl> -#> 1 OJ dose 1 28 36.0 1.82e- 6 * 0.563 -#> 2 VC dose 1 28 118. 1.51e-11 * 0.808
    -# Two-way ANOVA test -#::::::::::::::::::::::::::::::::::::::::: -df %>% anova_test(len ~ supp*dose)
    #> ANOVA Table (type II tests) -#> -#> Effect DFn DFd F p p<.05 ges -#> 1 supp 1 56 12.317 8.94e-04 * 0.180 -#> 2 dose 1 56 133.415 1.91e-16 * 0.704 -#> 3 supp:dose 1 56 5.333 2.50e-02 * 0.087
    -# Two-way repeated measures ANOVA -#::::::::::::::::::::::::::::::::::::::::: -df$id <- rep(1:10, 6) # Add individuals id -# Use formula -# \donttest{ -df %>% anova_test(len ~ supp*dose + Error(id/(supp*dose)))
    #> ANOVA Table (type III tests) -#> -#> $ANOVA -#> Effect DFn DFd F p p<.05 ges -#> 1 supp 1 9 34.866 2.28e-04 * 0.224 -#> 2 dose 2 18 106.470 1.06e-10 * 0.773 -#> 3 supp:dose 2 18 2.534 1.07e-01 0.132 -#> -#> $`Mauchly's Test for Sphericity` -#> Effect W p p<.05 -#> 1 dose 0.807 0.425 -#> 2 supp:dose 0.934 0.761 -#> -#> $`Sphericity Corrections` -#> Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF] -#> 1 dose 0.838 1.68, 15.09 2.79e-09 * 1.008 2.02, 18.15 1.06e-10 -#> 2 supp:dose 0.938 1.88, 16.88 1.12e-01 1.176 2.35, 21.17 1.07e-01 -#> p[HF]<.05 -#> 1 * -#> 2 -#>
    # } - - -# or use character vector -df %>% anova_test(dv = len, wid = id, within = c(supp, dose))
    #> ANOVA Table (type III tests) -#> -#> $ANOVA -#> Effect DFn DFd F p p<.05 ges -#> 1 supp 1 9 34.866 2.28e-04 * 0.224 -#> 2 dose 2 18 106.470 1.06e-10 * 0.773 -#> 3 supp:dose 2 18 2.534 1.07e-01 0.132 -#> -#> $`Mauchly's Test for Sphericity` -#> Effect W p p<.05 -#> 1 dose 0.807 0.425 -#> 2 supp:dose 0.934 0.761 -#> -#> $`Sphericity Corrections` -#> Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF] -#> 1 dose 0.838 1.68, 15.09 2.79e-09 * 1.008 2.02, 18.15 1.06e-10 -#> 2 supp:dose 0.938 1.88, 16.88 1.12e-01 1.176 2.35, 21.17 1.07e-01 -#> p[HF]<.05 -#> 1 * -#> 2 -#>
    -# Extract ANOVA table and apply correction -#::::::::::::::::::::::::::::::::::::::::: -res.aov <- df %>% anova_test(dv = len, wid = id, within = c(supp, dose)) -get_anova_table(res.aov, correction = "GG")
    #> ANOVA Table (type III tests) -#> -#> Effect DFn DFd F p p<.05 ges -#> 1 supp 1.00 9.00 34.866 2.28e-04 * 0.224 -#> 2 dose 1.68 15.09 106.470 2.79e-09 * 0.773 -#> 3 supp:dose 1.88 16.88 2.534 1.12e-01 0.132
    - -# Use model as arguments -#::::::::::::::::::::::::::::::::::::::::: -.my.model <- lm(yield ~ block + N*P*K, npk) -anova_test(.my.model)
    #> ANOVA Table (type II tests) -#> -#> Effect DFn DFd F p p<.05 ges -#> 1 block 4 12 4.959 0.014 * 0.623 -#> 2 N 1 12 12.259 0.004 * 0.505 -#> 3 P 1 12 0.544 0.475 0.043 -#> 4 K 1 12 6.166 0.029 * 0.339 -#> 5 N:P 1 12 1.378 0.263 0.103 -#> 6 N:K 1 12 2.146 0.169 0.152 -#> 7 P:K 1 12 0.031 0.863 0.003 -#> 8 N:P:K 0 12 NA NA <NA> NA
    - -
    +
+
+

See also

+ +
+
+

Author

+

Alboukadel Kassambara, alboukadel.kassambara@gmail.com

+
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# One-way ANOVA test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% anova_test(len ~ dose)
+#> ANOVA Table (type II tests)
+#> 
+#>   Effect DFn DFd       F        p p<.05   ges
+#> 1   dose   1  58 105.065 1.23e-14     * 0.644
+
+# Grouped One-way ANOVA test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>%
+  group_by(supp) %>%
+  anova_test(len ~ dose)
+#> # A tibble: 2 × 8
+#>   supp  Effect   DFn   DFd     F        p `p<.05`   ges
+#> * <fct> <chr>  <dbl> <dbl> <dbl>    <dbl> <chr>   <dbl>
+#> 1 OJ    dose       1    28  36.0 1.82e- 6 *       0.563
+#> 2 VC    dose       1    28 118.  1.51e-11 *       0.808
+
+# Two-way ANOVA test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% anova_test(len ~ supp*dose)
+#> ANOVA Table (type II tests)
+#> 
+#>      Effect DFn DFd       F        p p<.05   ges
+#> 1      supp   1  56  12.317 8.94e-04     * 0.180
+#> 2      dose   1  56 133.415 1.91e-16     * 0.704
+#> 3 supp:dose   1  56   5.333 2.50e-02     * 0.087
+
+# Two-way repeated measures ANOVA
+#:::::::::::::::::::::::::::::::::::::::::
+df$id <- rep(1:10, 6) # Add individuals id
+# Use formula
+# \donttest{
+df %>% anova_test(len ~ supp*dose + Error(id/(supp*dose)))
+#> ANOVA Table (type III tests)
+#> 
+#> $ANOVA
+#>      Effect DFn DFd       F        p p<.05   ges
+#> 1      supp   1   9  34.866 2.28e-04     * 0.224
+#> 2      dose   2  18 106.470 1.06e-10     * 0.773
+#> 3 supp:dose   2  18   2.534 1.07e-01       0.132
+#> 
+#> $`Mauchly's Test for Sphericity`
+#>      Effect     W     p p<.05
+#> 1      dose 0.807 0.425      
+#> 2 supp:dose 0.934 0.761      
+#> 
+#> $`Sphericity Corrections`
+#>      Effect   GGe      DF[GG]    p[GG] p[GG]<.05   HFe      DF[HF]    p[HF]
+#> 1      dose 0.838 1.68, 15.09 2.79e-09         * 1.008 2.02, 18.15 1.06e-10
+#> 2 supp:dose 0.938 1.88, 16.88 1.12e-01           1.176 2.35, 21.17 1.07e-01
+#>   p[HF]<.05
+#> 1         *
+#> 2          
+#> 
+# }
+
+
+# or use character vector
+df %>% anova_test(dv = len, wid = id, within = c(supp, dose))
+#> ANOVA Table (type III tests)
+#> 
+#> $ANOVA
+#>      Effect DFn DFd       F        p p<.05   ges
+#> 1      supp   1   9  34.866 2.28e-04     * 0.224
+#> 2      dose   2  18 106.470 1.06e-10     * 0.773
+#> 3 supp:dose   2  18   2.534 1.07e-01       0.132
+#> 
+#> $`Mauchly's Test for Sphericity`
+#>      Effect     W     p p<.05
+#> 1      dose 0.807 0.425      
+#> 2 supp:dose 0.934 0.761      
+#> 
+#> $`Sphericity Corrections`
+#>      Effect   GGe      DF[GG]    p[GG] p[GG]<.05   HFe      DF[HF]    p[HF]
+#> 1      dose 0.838 1.68, 15.09 2.79e-09         * 1.008 2.02, 18.15 1.06e-10
+#> 2 supp:dose 0.938 1.88, 16.88 1.12e-01           1.176 2.35, 21.17 1.07e-01
+#>   p[HF]<.05
+#> 1         *
+#> 2          
+#> 
+
+# Extract ANOVA table and apply correction
+#:::::::::::::::::::::::::::::::::::::::::
+res.aov <- df %>% anova_test(dv = len, wid = id, within = c(supp, dose))
+get_anova_table(res.aov, correction = "GG")
+#> ANOVA Table (type III tests)
+#> 
+#>      Effect  DFn   DFd       F        p p<.05   ges
+#> 1      supp 1.00  9.00  34.866 2.28e-04     * 0.224
+#> 2      dose 1.68 15.09 106.470 2.79e-09     * 0.773
+#> 3 supp:dose 1.88 16.88   2.534 1.12e-01       0.132
+
+
+# Use model as arguments
+#:::::::::::::::::::::::::::::::::::::::::
+.my.model <- lm(yield ~ block + N*P*K, npk)
+anova_test(.my.model)
+#> ANOVA Table (type II tests)
+#> 
+#>   Effect DFn DFd      F     p p<.05   ges
+#> 1  block   4  12  4.959 0.014     * 0.623
+#> 2      N   1  12 12.259 0.004     * 0.505
+#> 3      P   1  12  0.544 0.475       0.043
+#> 4      K   1  12  6.166 0.029     * 0.339
+#> 5    N:P   1  12  1.378 0.263       0.103
+#> 6    N:K   1  12  2.146 0.169       0.152
+#> 7    P:K   1  12  0.031 0.863       0.003
+#> 8  N:P:K   0  12     NA    NA  <NA>    NA
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/as_cor_mat.html b/docs/reference/as_cor_mat.html index 64b177c..fff9a5d 100644 --- a/docs/reference/as_cor_mat.html +++ b/docs/reference/as_cor_mat.html @@ -1,70 +1,13 @@ - - - - - - - -Convert a Correlation Test Data Frame into a Correlation Matrix — as_cor_mat • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Convert a Correlation Test Data Frame into a Correlation Matrix — as_cor_mat • rstatix - - - - + + -
-
- -
- -
+

Convert a correlation test data frame, returned by the - cor_test(), into a correlation matrix format.

+ cor_test(), into a correlation matrix format.

-
as_cor_mat(x)
+
+
as_cor_mat(x)
+
-

Arguments

- - - - - - -
x

an object of class cor_test.

+
+

Arguments

+
x
+

an object of class cor_test.

-

Value

+
+
+

Value

+ -

Returns a data frame containing the matrix of the correlation +

Returns a data frame containing the matrix of the correlation coefficients. The output has an attribute named "pvalue", which contains the matrix of the correlation test p-values.

-

See also

- - - -

Examples

-
# Pairwise correlation tests between variables -#::::::::::::::::::::::::::::::::::::::::::::::: -res.cor.test <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_test() -res.cor.test
#> # A tibble: 36 x 8 -#> var1 var2 cor statistic p conf.low conf.high method -#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 mpg mpg 1 Inf 0 1 1 Pearson -#> 2 mpg disp -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson -#> 3 mpg hp -0.78 -6.74 1.79e- 7 -0.885 -0.586 Pearson -#> 4 mpg drat 0.68 5.10 1.78e- 5 0.436 0.832 Pearson -#> 5 mpg wt -0.87 -9.56 1.29e-10 -0.934 -0.744 Pearson -#> 6 mpg qsec 0.42 2.53 1.71e- 2 0.0820 0.670 Pearson -#> 7 disp mpg -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson -#> 8 disp disp 1 Inf 0 1 1 Pearson -#> 9 disp hp 0.79 7.08 7.14e- 8 0.611 0.893 Pearson -#> 10 disp drat -0.71 -5.53 5.28e- 6 -0.849 -0.481 Pearson -#> # … with 26 more rows
-# Convert the correlation test into a correlation matrix -#::::::::::::::::::::::::::::::::::::::::::::::: -res.cor.test %>% as_cor_mat()
#> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 -#> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 -#> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1
-
+
+
+

See also

+ +
+ +
+

Examples

+
# Pairwise correlation tests between variables
+#:::::::::::::::::::::::::::::::::::::::::::::::
+res.cor.test <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec) %>%
+  cor_test()
+res.cor.test
+#> # A tibble: 36 × 8
+#>    var1  var2    cor statistic        p conf.low conf.high method 
+#>    <chr> <chr> <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>  
+#>  1 mpg   mpg    1       Inf    0          1          1     Pearson
+#>  2 mpg   disp  -0.85     -8.75 9.38e-10  -0.923     -0.708 Pearson
+#>  3 mpg   hp    -0.78     -6.74 1.79e- 7  -0.885     -0.586 Pearson
+#>  4 mpg   drat   0.68      5.10 1.78e- 5   0.436      0.832 Pearson
+#>  5 mpg   wt    -0.87     -9.56 1.29e-10  -0.934     -0.744 Pearson
+#>  6 mpg   qsec   0.42      2.53 1.71e- 2   0.0820     0.670 Pearson
+#>  7 disp  mpg   -0.85     -8.75 9.38e-10  -0.923     -0.708 Pearson
+#>  8 disp  disp   1       Inf    0          1          1     Pearson
+#>  9 disp  hp     0.79      7.08 7.14e- 8   0.611      0.893 Pearson
+#> 10 disp  drat  -0.71     -5.53 5.28e- 6  -0.849     -0.481 Pearson
+#> # … with 26 more rows
+
+# Convert the correlation test into a correlation matrix
+#:::::::::::::::::::::::::::::::::::::::::::::::
+res.cor.test %>% as_cor_mat()
+#> # A tibble: 6 × 7
+#>   rowname   mpg  disp    hp   drat    wt   qsec
+#> * <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 mpg      1    -0.85 -0.78  0.68  -0.87  0.42 
+#> 2 disp    -0.85  1     0.79 -0.71   0.89 -0.43 
+#> 3 hp      -0.78  0.79  1    -0.45   0.66 -0.71 
+#> 4 drat     0.68 -0.71 -0.45  1     -0.71  0.091
+#> 5 wt      -0.87  0.89  0.66 -0.71   1    -0.17 
+#> 6 qsec     0.42 -0.43 -0.71  0.091 -0.17  1    
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/binom_test.html b/docs/reference/binom_test.html index 0fa51a3..ecfb197 100644 --- a/docs/reference/binom_test.html +++ b/docs/reference/binom_test.html @@ -1,71 +1,14 @@ - - - - - - - -Exact Binomial Test — binom_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Exact Binomial Test — binom_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -126,77 +56,77 @@

Exact Binomial Test

link[stats]{binom.test}() that returns a data frame as a result.

-
binom_test(
-  x,
-  n,
-  p = 0.5,
-  alternative = "two.sided",
-  conf.level = 0.95,
-  detailed = FALSE
-)
+    
+
binom_test(
+  x,
+  n,
+  p = 0.5,
+  alternative = "two.sided",
+  conf.level = 0.95,
+  detailed = FALSE
+)
+
+pairwise_binom_test(
+  x,
+  p.adjust.method = "holm",
+  alternative = "two.sided",
+  conf.level = 0.95
+)
+
+pairwise_binom_test_against_p(
+  x,
+  p = rep(1/length(x), length(x)),
+  p.adjust.method = "holm",
+  alternative = "two.sided",
+  conf.level = 0.95
+)
+
-pairwise_binom_test( - x, - p.adjust.method = "holm", - alternative = "two.sided", - conf.level = 0.95 -) +
+

Arguments

+
x
+

numeric vector containing the counts.

-pairwise_binom_test_against_p( - x, - p = rep(1/length(x), length(x)), - p.adjust.method = "holm", - alternative = "two.sided", - conf.level = 0.95 -)
-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

numeric vector containing the counts.

n

number of trials; ignored if x has length 2.

p

a vector of probabilities of success. The length of p must be the +

n
+

number of trials; ignored if x has length 2.

+ + +
p
+

a vector of probabilities of success. The length of p must be the same as the number of groups specified by x, and its elements must be -greater than 0 and less than 1.

alternative

indicates the alternative hypothesis and must be +greater than 0 and less than 1.

+ + +
alternative
+

indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". - You can specify just the initial letter.

conf.level

confidence level for the returned confidence - interval.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

p.adjust.method

method to adjust p values for multiple comparisons. + You can specify just the initial letter.

+ + +
conf.level
+

confidence level for the returned confidence + interval.

+ + +
detailed
+

logical value. Default is FALSE. If TRUE, a detailed result is +shown.

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

+want to adjust the p value (not recommended), use p.adjust.method = "none".

-

Value

+
+
+

Value

+ -

return a data frame containing the p-value and its significance. with - some the following columns:

    -
  • group, group1, group2: +

    return a data frame containing the p-value and its significance. with + some the following columns:

    • group, group1, group2: the categories or groups being compared.

    • statistic: the number of successes.

    • @@ -213,114 +143,128 @@

      Value

      hypothesis.

    • conf.low,conf.high: Lower and upper bound on a confidence interval for the probability of success.

    • -
    - -

    The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Functions

- +
+
+

Functions

-
    -
  • binom_test: performs exact binomial test. Wrapper around the R -base function binom.test that returns a dataframe as a +

    • binom_test(): performs exact binomial test. Wrapper around the R +base function binom.test that returns a dataframe as a result.

    • -
    • pairwise_binom_test: performs pairwise comparisons (binomial test) +

    • pairwise_binom_test(): performs pairwise comparisons (binomial test) following a significant exact multinomial test.

    • -
    • pairwise_binom_test_against_p: performs pairwise comparisons (binomial test) +

    • pairwise_binom_test_against_p(): performs pairwise comparisons (binomial test) following a significant exact multinomial test for given probabilities.

    • -
    -

    See also

    - - - -

    Examples

    -
    # Exact binomial test -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: 160 mice with cancer including 95 male and 65 female -# Q1: Does cancer affect more males than females? -binom_test(x = 95, n = 160)
    #> # A tibble: 1 x 6 -#> n estimate conf.low conf.high p p.signif -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 160 0.594 0.513 0.671 0.0216 *
    # => yes, there are a significant difference - - -# Q2: compare the observed proportion of males -# to an expected proportion (p = 3/5) -binom_test(x = 95, n = 160, p = 3/5)
    #> # A tibble: 1 x 6 -#> n estimate conf.low conf.high p p.signif -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 160 0.594 0.513 0.671 0.872 ns
    # => there are no significant difference - -# Multinomial test -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data -tulip <- c(red = 81, yellow = 50, white = 27) -# Question 1: are the color equally common ? -# this is a test of homogeneity -res <- multinom_test(tulip) -res
    #> # A tibble: 1 x 2 -#> p p.signif -#> * <dbl> <chr> -#> 1 0.000000711 ****
    attr(res, "descriptives")
    #> # A tibble: 3 x 3 -#> group observed expected -#> <chr> <dbl> <dbl> -#> 1 red 81 52.7 -#> 2 yellow 50 52.7 -#> 3 white 27 52.7
    -# Pairwise comparisons between groups -pairwise_binom_test(tulip, p.adjust.method = "bonferroni")
    #> # A tibble: 3 x 9 -#> group1 group2 n estimate conf.low conf.high p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 red yellow 131 0.618 0.529 0.702 8.51e-3 2.55e-2 * -#> 2 red white 108 0.75 0.657 0.828 1.91e-7 5.72e-7 **** -#> 3 yellow white 77 0.649 0.532 0.755 1.17e-2 3.5 e-2 *
    +
+
+

See also

+ +
-# Question 2: comparing observed to expected proportions -# this is a goodness-of-fit test -expected.p <- c(red = 0.5, yellow = 0.33, white = 0.17) -res <- multinom_test(tulip, expected.p) -res
#> # A tibble: 1 x 2 -#> p p.signif -#> * <dbl> <chr> -#> 1 0.942 ns
attr(res, "descriptives")
#> # A tibble: 3 x 3 -#> group observed expected -#> <chr> <dbl> <dbl> -#> 1 red 81 79 -#> 2 yellow 50 52.1 -#> 3 white 27 26.9
-# Pairwise comparisons against a given probabilities -pairwise_binom_test_against_p(tulip, expected.p)
#> # A tibble: 3 x 10 -#> group observed expected n estimate conf.low conf.high p p.adj -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 red 81 79 158 0.513 0.432 0.593 0.811 1 -#> 2 yellow 50 52.1 158 0.316 0.245 0.395 0.800 1 -#> 3 white 27 26.9 158 0.171 0.116 0.239 1 1 -#> # … with 1 more variable: p.adj.signif <chr>
+
+

Examples

+
# Exact binomial test
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: 160 mice with cancer including 95 male and 65 female
+# Q1: Does cancer affect more males than females?
+binom_test(x = 95, n = 160)
+#> # A tibble: 1 × 6
+#>       n estimate conf.low conf.high      p p.signif
+#> * <dbl>    <dbl>    <dbl>     <dbl>  <dbl> <chr>   
+#> 1   160    0.594    0.513     0.671 0.0216 *       
+# => yes, there are a significant difference
+
+
+# Q2: compare the observed proportion of males
+# to an expected proportion (p = 3/5)
+binom_test(x = 95, n = 160, p = 3/5)
+#> # A tibble: 1 × 6
+#>       n estimate conf.low conf.high     p p.signif
+#> * <dbl>    <dbl>    <dbl>     <dbl> <dbl> <chr>   
+#> 1   160    0.594    0.513     0.671 0.872 ns      
+# => there are no significant difference
+
+# Multinomial test
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data
+tulip <- c(red = 81, yellow = 50, white = 27)
+# Question 1: are the color equally common ?
+# this is a test of homogeneity
+res <- multinom_test(tulip)
+res
+#> # A tibble: 1 × 2
+#>             p p.signif
+#> *       <dbl> <chr>   
+#> 1 0.000000711 ****    
+attr(res, "descriptives")
+#> # A tibble: 3 × 3
+#>   group  observed expected
+#>   <chr>     <dbl>    <dbl>
+#> 1 red          81     52.7
+#> 2 yellow       50     52.7
+#> 3 white        27     52.7
+
+# Pairwise comparisons between groups
+pairwise_binom_test(tulip, p.adjust.method = "bonferroni")
+#> # A tibble: 3 × 9
+#>   group1 group2     n estimate conf.low conf.high           p      p.adj p.adj…¹
+#> * <chr>  <chr>  <dbl>    <dbl>    <dbl>     <dbl>       <dbl>      <dbl> <chr>  
+#> 1 red    yellow   131    0.618    0.529     0.702 0.00851        2.55e-2 *      
+#> 2 red    white    108    0.75     0.657     0.828 0.000000191    5.72e-7 ****   
+#> 3 yellow white     77    0.649    0.532     0.755 0.0117         3.5 e-2 *      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+# Question 2: comparing observed to expected proportions
+# this is a goodness-of-fit test
+expected.p <- c(red = 0.5, yellow = 0.33, white = 0.17)
+res <- multinom_test(tulip, expected.p)
+res
+#> # A tibble: 1 × 2
+#>       p p.signif
+#> * <dbl> <chr>   
+#> 1 0.942 ns      
+attr(res, "descriptives")
+#> # A tibble: 3 × 3
+#>   group  observed expected
+#>   <chr>     <dbl>    <dbl>
+#> 1 red          81     79  
+#> 2 yellow       50     52.1
+#> 3 white        27     26.9
+
+# Pairwise comparisons against a given probabilities
+pairwise_binom_test_against_p(tulip, expected.p)
+#> # A tibble: 3 × 10
+#>   group  observed expected     n estimate conf.low conf.high     p p.adj p.adj…¹
+#> * <chr>     <dbl>    <dbl> <dbl>    <dbl>    <dbl>     <dbl> <dbl> <dbl> <chr>  
+#> 1 red          81     79     158    0.513    0.432     0.593 0.811     1 ns     
+#> 2 yellow       50     52.1   158    0.316    0.245     0.395 0.800     1 ns     
+#> 3 white        27     26.9   158    0.171    0.116     0.239 1         1 ns     
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+ -
- +
- - + + diff --git a/docs/reference/box_m.html b/docs/reference/box_m.html index 68ed01e..87bf2e7 100644 --- a/docs/reference/box_m.html +++ b/docs/reference/box_m.html @@ -1,71 +1,14 @@ - - - - - - - -Box's M-test for Homogeneity of Covariance Matrices — box_m • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Box's M-test for Homogeneity of Covariance Matrices — box_m • rstatix - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -126,64 +56,63 @@

Box's M-test for Homogeneity of Covariance Matrices

The test is based on the chi-square approximation.

-
box_m(data, group)
- -

Arguments

- - - - - - - - - - -
data

a numeric data.frame or matrix containing n observations of p -variables; it is expected that n > p.

group

a vector of length n containing the class of each -observation; it is usually a factor.

- -

Value

- -

A data frame containing the following components:

    -
  • statistic an approximated value of the chi-square distribution.

  • +
    +
    box_m(data, group)
    +
    + +
    +

    Arguments

    +
    data
    +

    a numeric data.frame or matrix containing n observations of p +variables; it is expected that n > p.

    + + +
    group
    +

    a vector of length n containing the class of each +observation; it is usually a factor.

    + +
    +
    +

    Value

    + + +

    A data frame containing the following components:

    • statistic an approximated value of the chi-square distribution.

    • parameter the degrees of freedom related of the test statistic in this case that it follows a Chi-square distribution.

    • p.value the p-value of the test.

    • method the character string "Box's M-test for Homogeneity of Covariance Matrices".

    • -
    - - -

    Examples

    -
    data(iris) -box_m(iris[, -5], iris[, 5])
    #> # A tibble: 1 x 4 -#> statistic p.value parameter method -#> <dbl> <dbl> <dbl> <chr> -#> 1 141. 3.35e-20 20 Box's M-test for Homogeneity of Covariance Matri…
    +
+ +
+

Examples

+
data(iris)
+box_m(iris[, -5], iris[, 5])
+#> # A tibble: 1 × 4
+#>   statistic  p.value parameter method                                           
+#>       <dbl>    <dbl>     <dbl> <chr>                                            
+#> 1      141. 3.35e-20        20 Box's M-test for Homogeneity of Covariance Matri…
+
+
+
-
- +
- - + + diff --git a/docs/reference/chisq_test.html b/docs/reference/chisq_test.html index c0ffb29..4cea8d1 100644 --- a/docs/reference/chisq_test.html +++ b/docs/reference/chisq_test.html @@ -1,70 +1,13 @@ - - - - - - - -Chi-squared Test for Count Data — chisq_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Chi-squared Test for Count Data — chisq_test • rstatix - - - - + + -
-
- -
- -
+
@@ -124,98 +54,98 @@

Chi-squared Test for Count Data

homogeneity and independence tests.

-
chisq_test(
-  x,
-  y = NULL,
-  correct = TRUE,
-  p = rep(1/length(x), length(x)),
-  rescale.p = FALSE,
-  simulate.p.value = FALSE,
-  B = 2000
-)
-
-pairwise_chisq_gof_test(x, p.adjust.method = "holm", ...)
-
-pairwise_chisq_test_against_p(
-  x,
-  p = rep(1/length(x), length(x)),
-  p.adjust.method = "holm",
-  ...
-)
-
-chisq_descriptives(res.chisq)
-
-expected_freq(res.chisq)
-
-observed_freq(res.chisq)
-
-pearson_residuals(res.chisq)
-
-std_residuals(res.chisq)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

a numeric vector or matrix. x and y can also - both be factors.

y

a numeric vector; ignored if x is a matrix. If - x is a factor, y should be a factor of the same length.

correct

a logical indicating whether to apply continuity +

+
chisq_test(
+  x,
+  y = NULL,
+  correct = TRUE,
+  p = rep(1/length(x), length(x)),
+  rescale.p = FALSE,
+  simulate.p.value = FALSE,
+  B = 2000
+)
+
+pairwise_chisq_gof_test(x, p.adjust.method = "holm", ...)
+
+pairwise_chisq_test_against_p(
+  x,
+  p = rep(1/length(x), length(x)),
+  p.adjust.method = "holm",
+  ...
+)
+
+chisq_descriptives(res.chisq)
+
+expected_freq(res.chisq)
+
+observed_freq(res.chisq)
+
+pearson_residuals(res.chisq)
+
+std_residuals(res.chisq)
+
+ +
+

Arguments

+
x
+

a numeric vector or matrix. x and y can also + both be factors.

+ + +
y
+

a numeric vector; ignored if x is a matrix. If + x is a factor, y should be a factor of the same length.

+ + +
correct
+

a logical indicating whether to apply continuity correction when computing the test statistic for 2 by 2 tables: one half is subtracted from all \(|O - E|\) differences; however, the correction will not be bigger than the differences themselves. No correction - is done if simulate.p.value = TRUE.

p

a vector of probabilities of the same length of x. - An error is given if any entry of p is negative.

rescale.p

a logical scalar; if TRUE then p is rescaled + is done if simulate.p.value = TRUE.

+ + +
p
+

a vector of probabilities of the same length of x. + An error is given if any entry of p is negative.

+ + +
rescale.p
+

a logical scalar; if TRUE then p is rescaled (if necessary) to sum to 1. If rescale.p is FALSE, and - p does not sum to 1, an error is given.

simulate.p.value

a logical indicating whether to compute - p-values by Monte Carlo simulation.

B

an integer specifying the number of replicates used in the - Monte Carlo test.

p.adjust.method

method to adjust p values for multiple comparisons. + p does not sum to 1, an error is given.

+ + +
simulate.p.value
+

a logical indicating whether to compute + p-values by Monte Carlo simulation.

+ + +
B
+

an integer specifying the number of replicates used in the + Monte Carlo test.

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

...

other arguments passed to the function {chisq_test}().

res.chisq

an object of class chisq_test.

- -

Value

- -

return a data frame with some the following columns:

    -
  • n: the number of participants.

  • +want to adjust the p value (not recommended), use p.adjust.method = "none".

    + + +
    ...
    +

    other arguments passed to the function {chisq_test}().

    + + +
    res.chisq
    +

    an object of class chisq_test.

    + +
+
+

Value

+ + +

return a data frame with some the following columns:

  • n: the number of participants.

  • group, group1, group2: the categories or groups being compared.

  • statistic: the value @@ -234,103 +164,115 @@

    Value

  • expected: the expected counts under the null hypothesis.

The returned object has an attribute called args, which is a list holding the test arguments.

-

Functions

- +
+
+

Functions

-
    -
  • chisq_test: performs chi-square tests including goodness-of-fit, +

    • chisq_test(): performs chi-square tests including goodness-of-fit, homogeneity and independence tests.

    • -
    • pairwise_chisq_gof_test: perform pairwise comparisons between groups following a global +

    • pairwise_chisq_gof_test(): perform pairwise comparisons between groups following a global chi-square goodness of fit test.

    • -
    • pairwise_chisq_test_against_p: perform pairwise comparisons after a global +

    • pairwise_chisq_test_against_p(): perform pairwise comparisons after a global chi-squared test for given probabilities. For each group, the observed and the expected proportions are shown. Each group is compared to the sum of all others.

    • -
    • chisq_descriptives: returns the descriptive statistics of the chi-square +

    • chisq_descriptives(): returns the descriptive statistics of the chi-square test. These include, observed and expected frequencies, proportions, residuals and standardized residuals.

    • -
    • expected_freq: returns the expected counts from the chi-square test result.

    • -
    • observed_freq: returns the observed counts from the chi-square test result.

    • -
    • pearson_residuals: returns the Pearson residuals, (observed - expected) / sqrt(expected).

    • -
    • std_residuals: returns the standardized residuals

    • -
    - -

    Examples

    -
    # Chi-square goodness of fit test -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -tulip <- c(red = 81, yellow = 50, white = 27) -# Q1: Are the colors equally common? -chisq_test(tulip)
    #> # A tibble: 1 x 6 -#> n statistic p df method p.signif -#> * <int> <dbl> <dbl> <dbl> <chr> <chr> -#> 1 3 27.9 0.00000088 2 Chi-square test ****
    pairwise_chisq_gof_test(tulip)
    #> # A tibble: 3 x 8 -#> n group1 group2 statistic p df p.adj p.adj.signif -#> * <int> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 2 red yellow 7.34 0.00676 1 0.0135 * -#> 2 2 red white 27 0.000000203 1 0.000000609 **** -#> 3 2 yellow white 6.87 0.00876 1 0.0135 *
    # Q2: comparing observed to expected proportions -chisq_test(tulip, p = c(1/2, 1/3, 1/6))
    #> # A tibble: 1 x 6 -#> n statistic p df method p.signif -#> * <int> <dbl> <dbl> <dbl> <chr> <chr> -#> 1 3 0.203 0.904 2 Chi-square test ns
    pairwise_chisq_test_against_p(tulip, p = c(0.5, 0.33, 0.17))
    #> # A tibble: 3 x 9 -#> group observed expected n statistic p df p.adj p.adj.signif -#> * <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 red 81 79 2 0.101 0.75 1 1 ns -#> 2 yellow 50 52.1 2 0.131 0.717 1 1 ns -#> 3 white 27 26.9 2 0.000879 0.976 1 1 ns
    -# Homogeneity of proportions between groups -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: Titanic -xtab <- as.table(rbind( - c(203, 118, 178, 212), - c(122, 167, 528, 673) -)) -dimnames(xtab) <- list( - Survived = c("Yes", "No"), - Class = c("1st", "2nd", "3rd", "Crew") -) -xtab
    #> Class -#> Survived 1st 2nd 3rd Crew -#> Yes 203 118 178 212 -#> No 122 167 528 673
    # Chi-square test -chisq_test(xtab)
    #> # A tibble: 1 x 6 -#> n statistic p df method p.signif -#> * <dbl> <dbl> <dbl> <int> <chr> <chr> -#> 1 2201 190. 5e-41 3 Chi-square test ****
    # Compare the proportion of survived between groups -pairwise_prop_test(xtab)
    #> # A tibble: 6 x 5 -#> group1 group2 p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <chr> -#> 1 1st 2nd 3.13e- 7 9.38e- 7 **** -#> 2 1st 3rd 2.55e-30 1.27e-29 **** -#> 3 2nd 3rd 6.9 e- 7 1.38e- 6 **** -#> 4 1st Crew 1.62e-35 9.73e-35 **** -#> 5 2nd Crew 1.94e- 8 7.75e- 8 **** -#> 6 3rd Crew 6.03e- 1 6.03e- 1 ns
    +
  • expected_freq(): returns the expected counts from the chi-square test result.

  • +
  • observed_freq(): returns the observed counts from the chi-square test result.

  • +
  • pearson_residuals(): returns the Pearson residuals, (observed - expected) / sqrt(expected).

  • +
  • std_residuals(): returns the standardized residuals

  • +
+ +
+

Examples

+
# Chi-square goodness of fit test
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+tulip <- c(red = 81, yellow = 50, white = 27)
+# Q1: Are the colors equally common?
+chisq_test(tulip)
+#> # A tibble: 1 × 6
+#>       n statistic          p    df method          p.signif
+#> * <int>     <dbl>      <dbl> <dbl> <chr>           <chr>   
+#> 1     3      27.9 0.00000088     2 Chi-square test ****    
+pairwise_chisq_gof_test(tulip)
+#> # A tibble: 3 × 8
+#>       n group1 group2 statistic           p    df       p.adj p.adj.signif
+#> * <int> <chr>  <chr>      <dbl>       <dbl> <dbl>       <dbl> <chr>       
+#> 1     2 red    yellow      7.34 0.00676         1 0.0135      *           
+#> 2     2 red    white      27    0.000000203     1 0.000000609 ****        
+#> 3     2 yellow white       6.87 0.00876         1 0.0135      *           
+# Q2: comparing observed to expected proportions
+chisq_test(tulip, p = c(1/2, 1/3, 1/6))
+#> # A tibble: 1 × 6
+#>       n statistic     p    df method          p.signif
+#> * <int>     <dbl> <dbl> <dbl> <chr>           <chr>   
+#> 1     3     0.203 0.904     2 Chi-square test ns      
+pairwise_chisq_test_against_p(tulip, p = c(0.5, 0.33, 0.17))
+#> # A tibble: 3 × 9
+#>   group  observed expected     n statistic     p    df p.adj p.adj.signif
+#> * <chr>     <dbl>    <dbl> <int>     <dbl> <dbl> <dbl> <dbl> <chr>       
+#> 1 red          81     79       2  0.101    0.75      1     1 ns          
+#> 2 yellow       50     52.1     2  0.131    0.717     1     1 ns          
+#> 3 white        27     26.9     2  0.000879 0.976     1     1 ns          
+
+# Homogeneity of proportions between groups
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: Titanic
+xtab <- as.table(rbind(
+  c(203, 118, 178, 212),
+  c(122, 167, 528, 673)
+))
+dimnames(xtab) <- list(
+  Survived = c("Yes", "No"),
+  Class = c("1st", "2nd", "3rd", "Crew")
+)
+xtab
+#>         Class
+#> Survived 1st 2nd 3rd Crew
+#>      Yes 203 118 178  212
+#>      No  122 167 528  673
+# Chi-square test
+chisq_test(xtab)
+#> # A tibble: 1 × 6
+#>       n statistic     p    df method          p.signif
+#> * <dbl>     <dbl> <dbl> <int> <chr>           <chr>   
+#> 1  2201      190. 5e-41     3 Chi-square test ****    
+# Compare the proportion of survived between groups
+pairwise_prop_test(xtab)
+#> # A tibble: 6 × 5
+#>   group1 group2        p    p.adj p.adj.signif
+#> * <chr>  <chr>     <dbl>    <dbl> <chr>       
+#> 1 1st    2nd    3.13e- 7 9.38e- 7 ****        
+#> 2 1st    3rd    2.55e-30 1.27e-29 ****        
+#> 3 2nd    3rd    6.9 e- 7 1.38e- 6 ****        
+#> 4 1st    Crew   1.62e-35 9.73e-35 ****        
+#> 5 2nd    Crew   1.94e- 8 7.75e- 8 ****        
+#> 6 3rd    Crew   6.03e- 1 6.03e- 1 ns          
+
+
+
-
- +
- - + + diff --git a/docs/reference/cochran_qtest.html b/docs/reference/cochran_qtest.html index d07d222..47e64e9 100644 --- a/docs/reference/cochran_qtest.html +++ b/docs/reference/cochran_qtest.html @@ -1,73 +1,16 @@ - - - - - - - -Cochran's Q Test — cochran_qtest • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cochran's Q Test — cochran_qtest • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Performs the Cochran's Q test for unreplicated randomized block design experiments with a binary response variable and paired data. This - test is analogue to the friedman.test() with 0,1 coded + test is analogue to the friedman.test() with 0,1 coded response. It's an extension of the McNemar Chi-squared test for comparing more than two paired proportions.

-
cochran_qtest(data, formula)
- -

Arguments

- - - - - - - - - - -
data

a data frame containing the variables in the formula.

formula

a formula of the form a ~ b | c, where a is the +

+
cochran_qtest(data, formula)
+
+ +
+

Arguments

+
data
+

a data frame containing the variables in the formula.

+ + +
formula
+

a formula of the form a ~ b | c, where a is the outcome variable name; b is the within-subjects factor variables; and c (factor) is the column name containing individuals/subjects identifier. -Should be unique per individual.

- - -

Examples

-
# Generate a demo data -mydata <- data.frame( - outcome = c(0,1,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1), - treatment = gl(3,1,30,labels=LETTERS[1:3]), - participant = gl(10,3,labels=letters[1:10]) -) -mydata$outcome <- factor( - mydata$outcome, levels = c(1, 0), - labels = c("success", "failure") - ) -# Cross-tabulation -xtabs(~outcome + treatment, mydata)
#> treatment -#> outcome A B C -#> success 2 5 10 -#> failure 8 5 0
-# Compare the proportion of success between treatments -cochran_qtest(mydata, outcome ~ treatment|participant)
#> # A tibble: 1 x 6 -#> .y. n statistic df p method -#> * <chr> <int> <dbl> <dbl> <dbl> <chr> -#> 1 outcome 10 10.9 2 0.00432 Cochran's Q test
-# pairwise comparisons between groups -pairwise_mcnemar_test(mydata, outcome ~ treatment|participant)
#> # A tibble: 3 x 6 -#> group1 group2 p p.adj p.adj.signif method -#> * <chr> <chr> <dbl> <dbl> <chr> <chr> -#> 1 A B 0.371 1 ns McNemar test -#> 2 A C 0.0133 0.0399 * McNemar test -#> 3 B C 0.0736 0.221 ns McNemar test
-
+Should be unique per individual.

+ +
+ +
+

Examples

+
# Generate a demo data
+mydata <- data.frame(
+  outcome = c(0,1,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1),
+  treatment = gl(3,1,30,labels=LETTERS[1:3]),
+  participant = gl(10,3,labels=letters[1:10])
+)
+mydata$outcome <- factor(
+  mydata$outcome, levels = c(1, 0),
+  labels = c("success", "failure")
+  )
+# Cross-tabulation
+xtabs(~outcome + treatment, mydata)
+#>          treatment
+#> outcome    A  B  C
+#>   success  2  5 10
+#>   failure  8  5  0
+
+# Compare the proportion of success between treatments
+cochran_qtest(mydata, outcome ~ treatment|participant)
+#> # A tibble: 1 × 6
+#>   .y.         n statistic    df       p method          
+#> * <chr>   <int>     <dbl> <dbl>   <dbl> <chr>           
+#> 1 outcome    10      10.9     2 0.00432 Cochran's Q test
+
+# pairwise comparisons between groups
+pairwise_mcnemar_test(mydata, outcome ~ treatment|participant)
+#> # A tibble: 3 × 6
+#>   group1 group2      p  p.adj p.adj.signif method      
+#> * <chr>  <chr>   <dbl>  <dbl> <chr>        <chr>       
+#> 1 A      B      0.371  1      ns           McNemar test
+#> 2 A      C      0.0133 0.0399 *            McNemar test
+#> 3 B      C      0.0736 0.221  ns           McNemar test
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cohens_d.html b/docs/reference/cohens_d.html index 08822b4..4cbf69a 100644 --- a/docs/reference/cohens_d.html +++ b/docs/reference/cohens_d.html @@ -1,48 +1,5 @@ - - - - - - - -Compute Cohen's d Measure of Effect Size — cohens_d • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Cohen's d Measure of Effect Size — cohens_d • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -144,96 +74,96 @@

Compute Cohen's d Measure of Effect Size

It can also returns confidence intervals by bootstap.

-
cohens_d(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  paired = FALSE,
-  mu = 0,
-  var.equal = FALSE,
-  hedges.correction = FALSE,
-  ci = FALSE,
-  conf.level = 0.95,
-  ci.type = "perc",
-  nboot = 1000
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
cohens_d(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  paired = FALSE,
+  mu = 0,
+  var.equal = FALSE,
+  hedges.correction = FALSE,
+  ci = FALSE,
+  conf.level = 0.95,
+  ci.type = "perc",
+  nboot = 1000
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

comparisons

A list of length-2 vectors specifying the groups of +formula = TP53 ~ cancer_group.

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

ref.group

a character string specifying the reference group. If +"C"))

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).

If ref.group = "all", pairwise two sample tests are performed for - comparing each grouping variable levels against all (i.e. basemean).

paired

a logical indicating whether you want a paired test.

mu

theoretical mean, use for one-sample t-test. Default is 0.

var.equal

a logical variable indicating whether to treat the two + comparing each grouping variable levels against all (i.e. basemean).

+ + +
paired
+

a logical indicating whether you want a paired test.

+ + +
mu
+

theoretical mean, use for one-sample t-test. Default is 0.

+ + +
var.equal
+

a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation -to the degrees of freedom is used. Used only for unpaired or independent samples test.

hedges.correction

logical indicating whether apply the Hedges +to the degrees of freedom is used. Used only for unpaired or independent samples test.

+ + +
hedges.correction
+

logical indicating whether apply the Hedges correction by multiplying the usual value of Cohen's d by (N-3)/(N-2.25) (for unpaired t-test) and by (n1-2)/(n1-1.25) for paired t-test; where N is the total size of the two groups being compared (N = n1 + -n2).

ci

If TRUE, returns confidence intervals by bootstrap. May be slow.

conf.level

The level for the confidence interval.

ci.type

The type of confidence interval to use. Can be any of "norm", -"basic", "perc", or "bca". Passed to boot::boot.ci.

nboot

The number of replications to use for bootstrap.

- -

Value

- -

return a data frame with some of the following columns:

    -
  • .y.: the y variable used in the test.

  • +n2).

    + + +
    ci
    +

    If TRUE, returns confidence intervals by bootstrap. May be slow.

    + + +
    conf.level
    +

    The level for the confidence interval.

    + + +
    ci.type
    +

    The type of confidence interval to use. Can be any of "norm", +"basic", "perc", or "bca". Passed to boot::boot.ci.

    + + +
    nboot
    +

    The number of replications to use for bootstrap.

    + +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n,n1,n2: Sample counts.

  • effsize: estimate of the effect @@ -241,19 +171,18 @@

    Value

  • magnitude: magnitude of effect size.

  • conf.low,conf.high: lower and upper bound of the effect size confidence interval.

  • -
- -

Details

- +
+
+

Details

Quantification of the effect size magnitude is performed using the thresholds defined in Cohen (1992). The magnitude is assessed using the thresholds provided in (Cohen 1992), i.e. |d| < 0.2 "negligible", |d| < 0.5 "small", |d| < 0.8 "medium", otherwise "large".

-

References

- +
+
+

References

-
    -
  • Cohen, J. (1988). Statistical power analysis for +

    • Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). New York:Academic Press.

    • Cohen, J. (1992). A power primer. Psychological Bulletin, 112, 155-159.

    • @@ -262,63 +191,68 @@

      R 10.2307/1164953.

    • Navarro, Daniel. 2015. Learning Statistics with R: A Tutorial for Psychology Students and Other Beginners (Version 0.5).

    • -

    - - -

    Examples

    -
    # One-sample t test effect size -ToothGrowth %>% cohens_d(len ~ 1, mu = 0)
    #> # A tibble: 1 x 6 -#> .y. group1 group2 effsize n magnitude -#> * <chr> <chr> <chr> <dbl> <int> <ord> -#> 1 len 1 null model 2.46 60 large
    -# Two indepedent samples t-test effect size -ToothGrowth %>% cohens_d(len ~ supp, var.equal = TRUE)
    #> # A tibble: 1 x 7 -#> .y. group1 group2 effsize n1 n2 magnitude -#> * <chr> <chr> <chr> <dbl> <int> <int> <ord> -#> 1 len OJ VC 0.495 30 30 small
    -# Paired samples effect size -df <- data.frame( - id = 1:5, - pre = c(110, 122, 101, 120, 140), - post = c(150, 160, 110, 140, 155) -) -df <- df %>% gather(key = "treatment", value = "value", -id) -head(df)
    #> id treatment value -#> 1 1 pre 110 -#> 2 2 pre 122 -#> 3 3 pre 101 -#> 4 4 pre 120 -#> 5 5 pre 140 -#> 6 1 post 150
    -df %>% cohens_d(value ~ treatment, paired = TRUE)
    #> # A tibble: 1 x 7 -#> .y. group1 group2 effsize n1 n2 magnitude -#> * <chr> <chr> <chr> <dbl> <int> <int> <ord> -#> 1 value post pre 1.75 5 5 large
    +
+ +
+

Examples

+
# One-sample t test effect size
+ToothGrowth %>% cohens_d(len ~ 1, mu = 0)
+#> # A tibble: 1 × 6
+#>   .y.   group1 group2     effsize     n magnitude
+#> * <chr> <chr>  <chr>        <dbl> <int> <ord>    
+#> 1 len   1      null model    2.46    60 large    
+
+# Two indepedent samples t-test effect size
+ToothGrowth %>% cohens_d(len ~ supp, var.equal = TRUE)
+#> # A tibble: 1 × 7
+#>   .y.   group1 group2 effsize    n1    n2 magnitude
+#> * <chr> <chr>  <chr>    <dbl> <int> <int> <ord>    
+#> 1 len   OJ     VC       0.495    30    30 small    
+
+# Paired samples effect size
+df <- data.frame(
+  id = 1:5,
+  pre  = c(110, 122, 101, 120, 140),
+  post = c(150, 160, 110, 140, 155)
+)
+df <- df %>% gather(key = "treatment", value = "value", -id)
+head(df)
+#>   id treatment value
+#> 1  1       pre   110
+#> 2  2       pre   122
+#> 3  3       pre   101
+#> 4  4       pre   120
+#> 5  5       pre   140
+#> 6  1      post   150
+
+df %>% cohens_d(value ~ treatment, paired = TRUE)
+#> # A tibble: 1 × 7
+#>   .y.   group1 group2 effsize    n1    n2 magnitude
+#> * <chr> <chr>  <chr>    <dbl> <int> <int> <ord>    
+#> 1 value post   pre       1.75     5     5 large    
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_as_symbols.html b/docs/reference/cor_as_symbols.html index a4ae11a..8b5b9ad 100644 --- a/docs/reference/cor_as_symbols.html +++ b/docs/reference/cor_as_symbols.html @@ -1,70 +1,13 @@ - - - - - - - -Replace Correlation Coefficients by Symbols — cor_as_symbols • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Replace Correlation Coefficients by Symbols — cor_as_symbols • rstatix - + + - - - -
-
- -
- -
+
@@ -124,80 +54,80 @@

Replace Correlation Coefficients by Symbols

level of the correlation.

-
cor_as_symbols(
-  x,
-  cutpoints = c(0, 0.25, 0.5, 0.75, 1),
-  symbols = c(" ", ".", "+", "*")
-)
- -

Arguments

- - - - - - - - - - - - - - -
x

a correlation matrix. Particularly, an object of class cor_mat.

cutpoints

numeric vector used for intervals. Default values are -c(0, 0.25, 0.5, 0.75, 1).

symbols

character vector, one shorter than cutpoints, used as -correlation coefficient symbols. Default values are c(" ", ".", "+", -"*").

- -

See also

- - - -

Examples

-
# Compute correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_mat() - -# Replace correlation coefficient by symbols -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat %>% - cor_as_symbols() %>% - pull_lower_triangle()
#> rowname mpg disp hp drat wt qsec -#> 1 mpg -#> 2 disp * -#> 3 hp * * -#> 4 drat + + . -#> 5 wt * * + + -#> 6 qsec . . +
-
+
+
cor_as_symbols(
+  x,
+  cutpoints = c(0, 0.25, 0.5, 0.75, 1),
+  symbols = c(" ", ".", "+", "*")
+)
+
+ +
+

Arguments

+
x
+

a correlation matrix. Particularly, an object of class cor_mat.

+ + +
cutpoints
+

numeric vector used for intervals. Default values are +c(0, 0.25, 0.5, 0.75, 1).

+ + +
symbols
+

character vector, one shorter than cutpoints, used as +correlation coefficient symbols. Default values are c(" ", ".", "+", +"*").

+ +
+
+

See also

+ +
+ +
+

Examples

+
# Compute correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec) %>%
+  cor_mat()
+
+# Replace correlation coefficient by symbols
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat %>%
+  cor_as_symbols() %>%
+  pull_lower_triangle()
+#>   rowname mpg disp hp drat wt qsec
+#> 1     mpg                         
+#> 2    disp   *                     
+#> 3      hp   *    *                
+#> 4    drat   +    +  .             
+#> 5      wt   *    *  +    +        
+#> 6    qsec   .    .  +             
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_mark_significant.html b/docs/reference/cor_mark_significant.html index 4d664e2..89e639d 100644 --- a/docs/reference/cor_mark_significant.html +++ b/docs/reference/cor_mark_significant.html @@ -1,70 +1,13 @@ - - - - - - - -Add Significance Levels To a Correlation Matrix — cor_mark_significant • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add Significance Levels To a Correlation Matrix — cor_mark_significant • rstatix - + + - - - -
-
- -
- -
+
@@ -124,71 +54,73 @@

Add Significance Levels To a Correlation Matrix

correlation matrix data.

-
cor_mark_significant(
-  x,
-  cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
-  symbols = c("****", "***", "**", "*", "")
-)
- -

Arguments

- - - - - - - - - - - - - - -
x

an object of class cor_mat().

cutpoints

numeric vector used for intervals.

symbols

character vector, one shorter than cutpoints, used as -significance symbols.

- -

Value

- -

a data frame containing the lower triangular part of the correlation +

+
cor_mark_significant(
+  x,
+  cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
+  symbols = c("****", "***", "**", "*", "")
+)
+
+ +
+

Arguments

+
x
+

an object of class cor_mat().

+ + +
cutpoints
+

numeric vector used for intervals.

+ + +
symbols
+

character vector, one shorter than cutpoints, used as +significance symbols.

+ +
+
+

Value

+ + +

a data frame containing the lower triangular part of the correlation matrix marked by significance symbols.

+
-

Examples

-
mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_mat() %>% - cor_mark_significant()
#> rowname mpg disp hp drat wt qsec -#> 1 mpg -#> 2 disp -0.85**** -#> 3 hp -0.78**** 0.79**** -#> 4 drat 0.68**** -0.71**** -0.45** -#> 5 wt -0.87**** 0.89**** 0.66**** -0.71**** -#> 6 qsec 0.42* -0.43* -0.71**** 0.091 -0.17
+
+

Examples

+
mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec) %>%
+  cor_mat() %>%
+  cor_mark_significant()
+#>   rowname       mpg      disp        hp      drat    wt qsec
+#> 1     mpg                                                   
+#> 2    disp -0.85****                                         
+#> 3      hp -0.78****  0.79****                               
+#> 4    drat  0.68**** -0.71****   -0.45**                     
+#> 5      wt -0.87****  0.89****  0.66**** -0.71****           
+#> 6    qsec     0.42*    -0.43* -0.71****     0.091 -0.17     
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_mat-1.png b/docs/reference/cor_mat-1.png index dadb1d4..d650f3e 100644 Binary files a/docs/reference/cor_mat-1.png and b/docs/reference/cor_mat-1.png differ diff --git a/docs/reference/cor_mat.html b/docs/reference/cor_mat.html index 522c3ad..a1d3547 100644 --- a/docs/reference/cor_mat.html +++ b/docs/reference/cor_mat.html @@ -1,71 +1,14 @@ - - - - - - - -Compute Correlation Matrix with P-values — cor_mat • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Correlation Matrix with P-values — cor_mat • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -126,190 +56,204 @@

Compute Correlation Matrix with P-values

specify variables of interest to be used in the correlation analysis.

-
cor_mat(
-  data,
-  ...,
-  vars = NULL,
-  method = "pearson",
-  alternative = "two.sided",
-  conf.level = 0.95
-)
+    
+
cor_mat(
+  data,
+  ...,
+  vars = NULL,
+  method = "pearson",
+  alternative = "two.sided",
+  conf.level = 0.95
+)
+
+cor_pmat(
+  data,
+  ...,
+  vars = NULL,
+  method = "pearson",
+  alternative = "two.sided",
+  conf.level = 0.95
+)
+
+cor_get_pval(x)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables.

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to select a variable of interest.

-cor_pmat( - data, - ..., - vars = NULL, - method = "pearson", - alternative = "two.sided", - conf.level = 0.95 -) -cor_get_pval(x)
+
vars
+

a character vector containing the variable names of interest.

-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables.

...

One or more unquoted expressions (or variable names) separated by -commas. Used to select a variable of interest.

vars

a character vector containing the variable names of interest.

method

a character string indicating which correlation + +

method
+

a character string indicating which correlation coefficient is to be used for the test. One of "pearson", - "kendall", or "spearman", can be abbreviated.

alternative

indicates the alternative hypothesis and must be + "kendall", or "spearman", can be abbreviated.

+ + +
alternative
+

indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". You can specify just the initial letter. "greater" corresponds - to positive association, "less" to negative association.

conf.level

confidence level for the returned confidence + to positive association, "less" to negative association.

+ + +
conf.level
+

confidence level for the returned confidence interval. Currently only used for the Pearson product moment correlation coefficient if there are at least 4 complete pairs of - observations.

x

an object of class cor_mat

+ observations.

+ -

Value

+
x
+

an object of class cor_mat

-

a data frame

-

Functions

+
+
+

Value

+ +

a data frame

+
+
+

Functions

-
    -
  • cor_mat: compute correlation matrix with p-values. Returns a data +

    • cor_mat(): compute correlation matrix with p-values. Returns a data frame containing the matrix of the correlation coefficients. The output has an attribute named "pvalue", which contains the matrix of the correlation test p-values.

    • -
    • cor_pmat: compute the correlation matrix but returns only the p-values of the tests.

    • -
    • cor_get_pval: extract a correlation matrix p-values from an object of +

    • cor_pmat(): compute the correlation matrix but returns only the p-values of the tests.

    • +
    • cor_get_pval(): extract a correlation matrix p-values from an object of class cor_mat(). P-values are not adjusted.

    • -
    -

    See also

    - - - -

    Examples

    -
    # Data preparation -#::::::::::::::::::::::::::::::::::::::::::: -mydata <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) -head(mydata, 3)
    #> mpg disp hp drat wt qsec -#> Mazda RX4 21.0 160 110 3.90 2.620 16.46 -#> Mazda RX4 Wag 21.0 160 110 3.90 2.875 17.02 -#> Datsun 710 22.8 108 93 3.85 2.320 18.61
    -# Compute correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -# Correlation matrix between all variables -cor.mat <- mydata %>% cor_mat() -cor.mat
    #> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 -#> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 -#> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1
    -# Specify some variables of interest -mydata %>% cor_mat(mpg, hp, wt)
    #> # A tibble: 3 x 4 -#> rowname mpg hp wt -#> * <chr> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.78 -0.87 -#> 2 hp -0.78 1 0.66 -#> 3 wt -0.87 0.66 1
    -# Or remove some variables in the data -# before the analysis -mydata %>% cor_mat(-mpg, -hp)
    #> # A tibble: 4 x 5 -#> rowname disp drat wt qsec -#> * <chr> <dbl> <dbl> <dbl> <dbl> -#> 1 disp 1 -0.71 0.89 -0.43 -#> 2 drat -0.71 1 -0.71 0.091 -#> 3 wt 0.89 -0.71 1 -0.17 -#> 4 qsec -0.43 0.091 -0.17 1
    -# Significance levels -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat %>% cor_get_pval()
    #> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 0 9.38e-10 0.000000179 0.0000178 1.29e- 10 0.0171 -#> 2 disp 9.38e-10 0 0.0000000714 0.00000528 1.22e- 11 0.0131 -#> 3 hp 1.79e- 7 7.14e- 8 0 0.00999 4.15e- 5 0.00000577 -#> 4 drat 1.78e- 5 5.28e- 6 0.00999 0 4.78e- 6 0.62 -#> 5 wt 1.29e-10 1.22e-11 0.0000415 0.00000478 2.27e-236 0.339 -#> 6 qsec 1.71e- 2 1.31e- 2 0.00000577 0.62 3.39e- 1 0
    - -# Visualize -#:::::::::::::::::::::::::::::::::::::::::: -# Insignificant correlations are marked by crosses -cor.mat %>% - cor_reorder() %>% - pull_lower_triangle() %>% - cor_plot(label = TRUE)
    -# Gather/collapse correlation matrix into long format -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat %>% cor_gather()
    #> # A tibble: 36 x 4 -#> var1 var2 cor p -#> <chr> <chr> <dbl> <dbl> -#> 1 mpg mpg 1 0 -#> 2 disp mpg -0.85 9.38e-10 -#> 3 hp mpg -0.78 1.79e- 7 -#> 4 drat mpg 0.68 1.78e- 5 -#> 5 wt mpg -0.87 1.29e-10 -#> 6 qsec mpg 0.42 1.71e- 2 -#> 7 mpg disp -0.85 9.38e-10 -#> 8 disp disp 1 0 -#> 9 hp disp 0.79 7.14e- 8 -#> 10 drat disp -0.71 5.28e- 6 -#> # … with 26 more rows
    +
+ -
+
+

Examples

+
# Data preparation
+#:::::::::::::::::::::::::::::::::::::::::::
+mydata <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec)
+head(mydata, 3)
+#>                mpg disp  hp drat    wt  qsec
+#> Mazda RX4     21.0  160 110 3.90 2.620 16.46
+#> Mazda RX4 Wag 21.0  160 110 3.90 2.875 17.02
+#> Datsun 710    22.8  108  93 3.85 2.320 18.61
+
+# Compute correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+# Correlation matrix between all variables
+cor.mat <- mydata %>% cor_mat()
+cor.mat
+#> # A tibble: 6 × 7
+#>   rowname   mpg  disp    hp   drat    wt   qsec
+#> * <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 mpg      1    -0.85 -0.78  0.68  -0.87  0.42 
+#> 2 disp    -0.85  1     0.79 -0.71   0.89 -0.43 
+#> 3 hp      -0.78  0.79  1    -0.45   0.66 -0.71 
+#> 4 drat     0.68 -0.71 -0.45  1     -0.71  0.091
+#> 5 wt      -0.87  0.89  0.66 -0.71   1    -0.17 
+#> 6 qsec     0.42 -0.43 -0.71  0.091 -0.17  1    
+
+# Specify some variables of interest
+mydata %>% cor_mat(mpg, hp, wt)
+#> # A tibble: 3 × 4
+#>   rowname   mpg    hp    wt
+#> * <chr>   <dbl> <dbl> <dbl>
+#> 1 mpg      1    -0.78 -0.87
+#> 2 hp      -0.78  1     0.66
+#> 3 wt      -0.87  0.66  1   
+
+# Or remove some variables in the data
+# before the analysis
+mydata %>% cor_mat(-mpg, -hp)
+#> # A tibble: 4 × 5
+#>   rowname  disp   drat    wt   qsec
+#> * <chr>   <dbl>  <dbl> <dbl>  <dbl>
+#> 1 disp     1    -0.71   0.89 -0.43 
+#> 2 drat    -0.71  1     -0.71  0.091
+#> 3 wt       0.89 -0.71   1    -0.17 
+#> 4 qsec    -0.43  0.091 -0.17  1    
+
+# Significance levels
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat %>% cor_get_pval()
+#> # A tibble: 6 × 7
+#>   rowname      mpg     disp           hp       drat        wt       qsec
+#>   <chr>      <dbl>    <dbl>        <dbl>      <dbl>     <dbl>      <dbl>
+#> 1 mpg     0        9.38e-10 0.000000179  0.0000178  1.29e- 10 0.0171    
+#> 2 disp    9.38e-10 0        0.0000000714 0.00000528 1.22e- 11 0.0131    
+#> 3 hp      1.79e- 7 7.14e- 8 0            0.00999    4.15e-  5 0.00000577
+#> 4 drat    1.78e- 5 5.28e- 6 0.00999      0          4.78e-  6 0.62      
+#> 5 wt      1.29e-10 1.22e-11 0.0000415    0.00000478 2.27e-236 0.339     
+#> 6 qsec    1.71e- 2 1.31e- 2 0.00000577   0.62       3.39e-  1 0         
+
+
+# Visualize
+#::::::::::::::::::::::::::::::::::::::::::
+# Insignificant correlations are marked by crosses
+cor.mat %>%
+  cor_reorder() %>%
+  pull_lower_triangle() %>%
+  cor_plot(label = TRUE)
+
+
+# Gather/collapse correlation matrix into long format
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat %>% cor_gather()
+#> # A tibble: 36 × 4
+#>    var1  var2    cor        p
+#>    <chr> <chr> <dbl>    <dbl>
+#>  1 mpg   mpg    1    0       
+#>  2 disp  mpg   -0.85 9.38e-10
+#>  3 hp    mpg   -0.78 1.79e- 7
+#>  4 drat  mpg    0.68 1.78e- 5
+#>  5 wt    mpg   -0.87 1.29e-10
+#>  6 qsec  mpg    0.42 1.71e- 2
+#>  7 mpg   disp  -0.85 9.38e-10
+#>  8 disp  disp   1    0       
+#>  9 hp    disp   0.79 7.14e- 8
+#> 10 drat  disp  -0.71 5.28e- 6
+#> # … with 26 more rows
+
+
+
+
+ -
- +
- - + + diff --git a/docs/reference/cor_plot-1.png b/docs/reference/cor_plot-1.png index d78237b..b358c6a 100644 Binary files a/docs/reference/cor_plot-1.png and b/docs/reference/cor_plot-1.png differ diff --git a/docs/reference/cor_plot-2.png b/docs/reference/cor_plot-2.png index 142756a..c6c7e0c 100644 Binary files a/docs/reference/cor_plot-2.png and b/docs/reference/cor_plot-2.png differ diff --git a/docs/reference/cor_plot-3.png b/docs/reference/cor_plot-3.png index 7bdac3c..7ecb045 100644 Binary files a/docs/reference/cor_plot-3.png and b/docs/reference/cor_plot-3.png differ diff --git a/docs/reference/cor_plot-4.png b/docs/reference/cor_plot-4.png index f45c80f..151f187 100644 Binary files a/docs/reference/cor_plot-4.png and b/docs/reference/cor_plot-4.png differ diff --git a/docs/reference/cor_plot-5.png b/docs/reference/cor_plot-5.png index 1e709ab..6bf78c8 100644 Binary files a/docs/reference/cor_plot-5.png and b/docs/reference/cor_plot-5.png differ diff --git a/docs/reference/cor_plot-6.png b/docs/reference/cor_plot-6.png index 36f4cc4..3d81b2b 100644 Binary files a/docs/reference/cor_plot-6.png and b/docs/reference/cor_plot-6.png differ diff --git a/docs/reference/cor_plot-7.png b/docs/reference/cor_plot-7.png index c1a9b25..4790bb2 100644 Binary files a/docs/reference/cor_plot-7.png and b/docs/reference/cor_plot-7.png differ diff --git a/docs/reference/cor_plot-8.png b/docs/reference/cor_plot-8.png index 5e3846f..31f0ae6 100644 Binary files a/docs/reference/cor_plot-8.png and b/docs/reference/cor_plot-8.png differ diff --git a/docs/reference/cor_plot.html b/docs/reference/cor_plot.html index ca17ba4..220bef2 100644 --- a/docs/reference/cor_plot.html +++ b/docs/reference/cor_plot.html @@ -1,48 +1,5 @@ - - - - - - - -Visualize Correlation Matrix Using Base Plot — cor_plot • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Visualize Correlation Matrix Using Base Plot — cor_plot • rstatix - - - - - - - - - - + + - - - -
-
- -
- -
+

Provide a tibble-friendly framework to visualize a correlation matrix. Wrapper around the R base function - corrplot(). Compared to - corrplot(), it can handle directly the output of the - functions cor_mat() (in rstatix), rcorr() (in Hmisc), + corrplot(). Compared to + corrplot(), it can handle directly the output of the + functions cor_mat() (in rstatix), rcorr() (in Hmisc), correlate() (in corrr) and cor() (in stats).

The p-values contained in the outputs of the functions - cor_mat() and rcorr() are automatically detected and + cor_mat() and rcorr() are automatically detected and used in the visualization.

-
cor_plot(
-  cor.mat,
-  method = "circle",
-  type = "full",
-  palette = NULL,
-  p.mat = NULL,
-  significant.level = 0.05,
-  insignificant = c("cross", "blank"),
-  label = FALSE,
-  font.label = list(),
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cor.mat

the correlation matrix to visualize

method

Character, the visualization method of correlation matrix to be +

+
cor_plot(
+  cor.mat,
+  method = "circle",
+  type = "full",
+  palette = NULL,
+  p.mat = NULL,
+  significant.level = 0.05,
+  insignificant = c("cross", "blank"),
+  label = FALSE,
+  font.label = list(),
+  ...
+)
+
+ +
+

Arguments

+
cor.mat
+

the correlation matrix to visualize

+ + +
method
+

Character, the visualization method of correlation matrix to be used. Currently, it supports seven methods, named "circle" (default), "square", "ellipse", "number", "pie", "shade" and "color". See examples for details.

@@ -168,133 +98,149 @@

Arg correlation coefficients. Method "pie" and "shade" came from Michael Friendly's job (with some adjustment about the shade added on), and "ellipse" came from D.J. Murdoch and E.D. Chow's job, see in section - References.

type

Character, "full" (default), "upper" or + References.

+ + +
type
+

Character, "full" (default), "upper" or "lower", display full matrix, lower triangular or upper triangular -matrix.

palette

character vector containing the color palette.

p.mat

matrix of p-value corresponding to the correlation matrix.

significant.level

significant level, if the p-value is bigger than +matrix.

+ + +
palette
+

character vector containing the color palette.

+ + +
p.mat
+

matrix of p-value corresponding to the correlation matrix.

+ + +
significant.level
+

significant level, if the p-value is bigger than significant.level, then the corresponding correlation coefficient is -regarded as insignificant.

insignificant

character, specialized insignificant correlation +regarded as insignificant.

+ + +
insignificant
+

character, specialized insignificant correlation coefficients, "cross" (default), "blank". If "blank", wipe away the -corresponding glyphs; if "cross", add crosses (X) on corresponding glyphs.

label

logical value. If TRUE, shows the correlation coefficient -labels.

font.label

a list with one or more of the following elements: size +corresponding glyphs; if "cross", add crosses (X) on corresponding glyphs.

+ + +
label
+

logical value. If TRUE, shows the correlation coefficient +labels.

+ + +
font.label
+

a list with one or more of the following elements: size (e.g., 1), color (e.g., "black") and style (e.g., "bold"). Used to customize the correlation coefficient labels. For example font.label -= list(size = 1, color = "black", style = "bold").

...

additional options not listed (i.e. "tl.cex") here to pass to corrplot.

- -

See also

- - - -

Examples

-
# Compute correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_mat() - -# Visualize correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -# Full correlation matrix, -# insignificant correlations are marked by crosses -cor.mat %>% cor_plot()
-# Reorder by correlation coefficient -# pull lower triangle and visualize -cor.lower.tri <- cor.mat %>% - cor_reorder() %>% - pull_lower_triangle() -cor.lower.tri %>% cor_plot()
-# Change visualization methods -#:::::::::::::::::::::::::::::::::::::::::: -cor.lower.tri %>% - cor_plot(method = "pie")
-cor.lower.tri %>% - cor_plot(method = "color")
-cor.lower.tri %>% - cor_plot(method = "number")
-# Show the correlation coefficient: label = TRUE -# Blank the insignificant correlation -#:::::::::::::::::::::::::::::::::::::::::: -cor.lower.tri %>% - cor_plot( - method = "color", - label = TRUE, - insignificant = "blank" - )
-# Change the color palettes -#:::::::::::::::::::::::::::::::::::::::::: - -# Using custom color palette -# Require ggpubr: install.packages("ggpubr") -if(require("ggpubr")){ - my.palette <- get_palette(c("red", "white", "blue"), 200) - cor.lower.tri %>% - cor_plot(palette = my.palette) -}
#> Le chargement a nécessité le package : ggpubr
#> Le chargement a nécessité le package : ggplot2
-# Using RcolorBrewer color palette -if(require("ggpubr")){ - my.palette <- get_palette("PuOr", 200) - cor.lower.tri %>% - cor_plot(palette = my.palette) -}
-
+= list(size = 1, color = "black", style = "bold").

+ + +
...
+

additional options not listed (i.e. "tl.cex") here to pass to corrplot.

+ +
+
+

See also

+ +
+ +
+

Examples

+
# Compute correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec) %>%
+  cor_mat()
+
+# Visualize correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+# Full correlation matrix,
+# insignificant correlations are marked by crosses
+cor.mat %>% cor_plot()
+
+
+# Reorder by correlation coefficient
+# pull lower triangle and visualize
+cor.lower.tri <- cor.mat %>%
+  cor_reorder() %>%
+  pull_lower_triangle()
+cor.lower.tri %>% cor_plot()
+
+
+# Change visualization methods
+#::::::::::::::::::::::::::::::::::::::::::
+cor.lower.tri %>%
+  cor_plot(method = "pie")
+
+
+cor.lower.tri %>%
+  cor_plot(method = "color")
+
+
+cor.lower.tri %>%
+  cor_plot(method = "number")
+
+
+# Show the correlation coefficient: label = TRUE
+# Blank the insignificant correlation
+#::::::::::::::::::::::::::::::::::::::::::
+cor.lower.tri %>%
+  cor_plot(
+    method = "color",
+    label = TRUE,
+    insignificant = "blank"
+  )
+
+
+# Change the color palettes
+#::::::::::::::::::::::::::::::::::::::::::
+
+# Using custom color palette
+# Require ggpubr: install.packages("ggpubr")
+if(require("ggpubr")){
+  my.palette <- get_palette(c("red", "white", "blue"), 200)
+  cor.lower.tri %>%
+   cor_plot(palette = my.palette)
+}
+#> Loading required package: ggpubr
+#> Loading required package: ggplot2
+
+
+# Using RcolorBrewer color palette
+if(require("ggpubr")){
+  my.palette <- get_palette("PuOr", 200)
+  cor.lower.tri %>%
+   cor_plot(palette = my.palette)
+}
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_reorder.html b/docs/reference/cor_reorder.html index 4384278..d83fe70 100644 --- a/docs/reference/cor_reorder.html +++ b/docs/reference/cor_reorder.html @@ -1,70 +1,13 @@ - - - - - - - -Reorder Correlation Matrix — cor_reorder • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Reorder Correlation Matrix — cor_reorder • rstatix + + - - - - -
-
- -
- -
+
@@ -124,81 +54,86 @@

Reorder Correlation Matrix

using the hierarchical clustering method.

-
cor_reorder(x)
- -

Arguments

- - - - - - -
x

a correlation matrix. Particularly, an object of class cor_mat.

- -

Value

- -

a data frame

-

See also

- - - -

Examples

-
# Compute correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_mat() - -# Reorder by correlation and get p-values -#:::::::::::::::::::::::::::::::::::::::::: -# Reorder -cor.mat %>% - cor_reorder()
#> # A tibble: 6 x 7 -#> rowname hp disp wt qsec mpg drat -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 hp 1 0.79 0.66 -0.71 -0.78 -0.45 -#> 2 disp 0.79 1 0.89 -0.43 -0.85 -0.71 -#> 3 wt 0.66 0.89 1 -0.17 -0.87 -0.71 -#> 4 qsec -0.71 -0.43 -0.17 1 0.42 0.091 -#> 5 mpg -0.78 -0.85 -0.87 0.42 1 0.68 -#> 6 drat -0.45 -0.71 -0.71 0.091 0.68 1
# Get p-values of the reordered cor_mat -cor.mat %>% - cor_reorder() %>% - cor_get_pval()
#> # A tibble: 6 x 7 -#> rowname hp disp wt qsec mpg drat -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 hp 0 7.14e- 8 4.15e- 5 0.00000577 1.79e- 7 0.00999 -#> 2 disp 0.0000000714 0 1.22e- 11 0.0131 9.38e-10 0.00000528 -#> 3 wt 0.0000415 1.22e-11 2.27e-236 0.339 1.29e-10 0.00000478 -#> 4 qsec 0.00000577 1.31e- 2 3.39e- 1 0 1.71e- 2 0.62 -#> 5 mpg 0.000000179 9.38e-10 1.29e- 10 0.0171 0 0.0000178 -#> 6 drat 0.00999 5.28e- 6 4.78e- 6 0.62 1.78e- 5 0
-
+
+
cor_reorder(x)
+
+ +
+

Arguments

+
x
+

a correlation matrix. Particularly, an object of class cor_mat.

+ +
+
+

Value

+ + +

a data frame

+
+
+

See also

+ +
+ +
+

Examples

+
# Compute correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec) %>%
+  cor_mat()
+
+# Reorder by correlation and get p-values
+#::::::::::::::::::::::::::::::::::::::::::
+# Reorder
+cor.mat %>%
+  cor_reorder()
+#> # A tibble: 6 × 7
+#>   rowname    hp  disp    wt   qsec   mpg   drat
+#> * <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 hp       1     0.79  0.66 -0.71  -0.78 -0.45 
+#> 2 disp     0.79  1     0.89 -0.43  -0.85 -0.71 
+#> 3 wt       0.66  0.89  1    -0.17  -0.87 -0.71 
+#> 4 qsec    -0.71 -0.43 -0.17  1      0.42  0.091
+#> 5 mpg     -0.78 -0.85 -0.87  0.42   1     0.68 
+#> 6 drat    -0.45 -0.71 -0.71  0.091  0.68  1    
+# Get p-values of the reordered cor_mat
+cor.mat %>%
+  cor_reorder() %>%
+  cor_get_pval()
+#> # A tibble: 6 × 7
+#>   rowname           hp     disp        wt       qsec      mpg       drat
+#>   <chr>          <dbl>    <dbl>     <dbl>      <dbl>    <dbl>      <dbl>
+#> 1 hp      0            7.14e- 8 4.15e-  5 0.00000577 1.79e- 7 0.00999   
+#> 2 disp    0.0000000714 0        1.22e- 11 0.0131     9.38e-10 0.00000528
+#> 3 wt      0.0000415    1.22e-11 2.27e-236 0.339      1.29e-10 0.00000478
+#> 4 qsec    0.00000577   1.31e- 2 3.39e-  1 0          1.71e- 2 0.62      
+#> 5 mpg     0.000000179  9.38e-10 1.29e- 10 0.0171     0        0.0000178 
+#> 6 drat    0.00999      5.28e- 6 4.78e-  6 0.62       1.78e- 5 0         
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_reshape.html b/docs/reference/cor_reshape.html index 4748f97..1965df4 100644 --- a/docs/reference/cor_reshape.html +++ b/docs/reference/cor_reshape.html @@ -1,76 +1,19 @@ - - - - - - - -Reshape Correlation Data — cor_gather • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Reshape Correlation Data — cor_gather • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
-

Reshape correlation analysis results. Key functions:

    -
  • cor_gather(): takes a correlation matrix and collapses (i.e. melt) it into a paired list +

    Reshape correlation analysis results. Key functions:

    • cor_gather(): takes a correlation matrix and collapses (i.e. melt) it into a paired list (long format).

    • cor_spread(): spread a long correlation data format across - multiple columns. Particularly, it takes the results of cor_test + multiple columns. Particularly, it takes the results of cor_test and transforms it into a correlation matrix.

    • -
    +
+
+
cor_gather(data, drop.na = TRUE)
+
+cor_spread(data, value = "cor")
-
cor_gather(data, drop.na = TRUE)
+    
+

Arguments

+
data
+

a data frame or matrix.

-cor_spread(data, value = "cor")
-

Arguments

- - - - - - - - - - - - - - -
data

a data frame or matrix.

drop.na

logical. If TRUE, drop rows containing missing values after gathering the data.

value

column name containing the value to spread.

+
drop.na
+

logical. If TRUE, drop rows containing missing values after gathering the data.

-

Functions

+
value
+

column name containing the value to spread.

+ +
+
+

Functions

-
    -
  • cor_gather: takes a correlation matrix and collapses (or melt) it into long +

    • cor_gather(): takes a correlation matrix and collapses (or melt) it into long format data frame (paired list)

    • -
    • cor_spread: spread a long correlation data frame into wide +

    • cor_spread(): spread a long correlation data frame into wide format. Expects the columns "var1", "var2" and "cor" in the data. (correlation matrix).

    • -
    -

    See also

    - - +
+
+

See also

+ +
-

Examples

-
# Data preparation -#:::::::::::::::::::::::::::::::::::::::::: -mydata <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) -head(mydata, 3)
#> mpg disp hp drat wt qsec -#> Mazda RX4 21.0 160 110 3.90 2.620 16.46 -#> Mazda RX4 Wag 21.0 160 110 3.90 2.875 17.02 -#> Datsun 710 22.8 108 93 3.85 2.320 18.61
-# Reshape a correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -# Compute a correlation matrix -cor.mat <- mydata %>% cor_mat() -cor.mat
#> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 -#> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 -#> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1
-# Collapse the correlation matrix into long format -# paired list data frame -long.format <- cor.mat %>% cor_gather() -long.format
#> # A tibble: 36 x 4 -#> var1 var2 cor p -#> <chr> <chr> <dbl> <dbl> -#> 1 mpg mpg 1 0 -#> 2 disp mpg -0.85 9.38e-10 -#> 3 hp mpg -0.78 1.79e- 7 -#> 4 drat mpg 0.68 1.78e- 5 -#> 5 wt mpg -0.87 1.29e-10 -#> 6 qsec mpg 0.42 1.71e- 2 -#> 7 mpg disp -0.85 9.38e-10 -#> 8 disp disp 1 0 -#> 9 hp disp 0.79 7.14e- 8 -#> 10 drat disp -0.71 5.28e- 6 -#> # … with 26 more rows
-# Spread a correlation data format -#:::::::::::::::::::::::::::::::::::::::::: -# Spread the correlation coefficient value -long.format %>% cor_spread(value = "cor")
#> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 -#> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 -#> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1
# Spread the p-value -long.format %>% cor_spread(value = "p")
#> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 0 9.38e-10 0.000000179 0.0000178 1.29e- 10 0.0171 -#> 2 disp 9.38e-10 0 0.0000000714 0.00000528 1.22e- 11 0.0131 -#> 3 hp 1.79e- 7 7.14e- 8 0 0.00999 4.15e- 5 0.00000577 -#> 4 drat 1.78e- 5 5.28e- 6 0.00999 0 4.78e- 6 0.62 -#> 5 wt 1.29e-10 1.22e-11 0.0000415 0.00000478 2.27e-236 0.339 -#> 6 qsec 1.71e- 2 1.31e- 2 0.00000577 0.62 3.39e- 1 0
+
+

Examples

+
# Data preparation
+#::::::::::::::::::::::::::::::::::::::::::
+mydata <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec)
+head(mydata, 3)
+#>                mpg disp  hp drat    wt  qsec
+#> Mazda RX4     21.0  160 110 3.90 2.620 16.46
+#> Mazda RX4 Wag 21.0  160 110 3.90 2.875 17.02
+#> Datsun 710    22.8  108  93 3.85 2.320 18.61
+
+# Reshape a correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+# Compute a correlation matrix
+cor.mat <- mydata %>% cor_mat()
+cor.mat
+#> # A tibble: 6 × 7
+#>   rowname   mpg  disp    hp   drat    wt   qsec
+#> * <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 mpg      1    -0.85 -0.78  0.68  -0.87  0.42 
+#> 2 disp    -0.85  1     0.79 -0.71   0.89 -0.43 
+#> 3 hp      -0.78  0.79  1    -0.45   0.66 -0.71 
+#> 4 drat     0.68 -0.71 -0.45  1     -0.71  0.091
+#> 5 wt      -0.87  0.89  0.66 -0.71   1    -0.17 
+#> 6 qsec     0.42 -0.43 -0.71  0.091 -0.17  1    
+
+# Collapse the correlation matrix into long format
+# paired list data frame
+long.format <- cor.mat %>% cor_gather()
+long.format
+#> # A tibble: 36 × 4
+#>    var1  var2    cor        p
+#>    <chr> <chr> <dbl>    <dbl>
+#>  1 mpg   mpg    1    0       
+#>  2 disp  mpg   -0.85 9.38e-10
+#>  3 hp    mpg   -0.78 1.79e- 7
+#>  4 drat  mpg    0.68 1.78e- 5
+#>  5 wt    mpg   -0.87 1.29e-10
+#>  6 qsec  mpg    0.42 1.71e- 2
+#>  7 mpg   disp  -0.85 9.38e-10
+#>  8 disp  disp   1    0       
+#>  9 hp    disp   0.79 7.14e- 8
+#> 10 drat  disp  -0.71 5.28e- 6
+#> # … with 26 more rows
+
+# Spread a correlation data format
+#::::::::::::::::::::::::::::::::::::::::::
+# Spread the correlation coefficient value
+long.format %>% cor_spread(value = "cor")
+#> # A tibble: 6 × 7
+#>   rowname   mpg  disp    hp   drat    wt   qsec
+#>   <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 mpg      1    -0.85 -0.78  0.68  -0.87  0.42 
+#> 2 disp    -0.85  1     0.79 -0.71   0.89 -0.43 
+#> 3 hp      -0.78  0.79  1    -0.45   0.66 -0.71 
+#> 4 drat     0.68 -0.71 -0.45  1     -0.71  0.091
+#> 5 wt      -0.87  0.89  0.66 -0.71   1    -0.17 
+#> 6 qsec     0.42 -0.43 -0.71  0.091 -0.17  1    
+# Spread the p-value
+long.format %>% cor_spread(value = "p")
+#> # A tibble: 6 × 7
+#>   rowname      mpg     disp           hp       drat        wt       qsec
+#>   <chr>      <dbl>    <dbl>        <dbl>      <dbl>     <dbl>      <dbl>
+#> 1 mpg     0        9.38e-10 0.000000179  0.0000178  1.29e- 10 0.0171    
+#> 2 disp    9.38e-10 0        0.0000000714 0.00000528 1.22e- 11 0.0131    
+#> 3 hp      1.79e- 7 7.14e- 8 0            0.00999    4.15e-  5 0.00000577
+#> 4 drat    1.78e- 5 5.28e- 6 0.00999      0          4.78e-  6 0.62      
+#> 5 wt      1.29e-10 1.22e-11 0.0000415    0.00000478 2.27e-236 0.339     
+#> 6 qsec    1.71e- 2 1.31e- 2 0.00000577   0.62       3.39e-  1 0         
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_select.html b/docs/reference/cor_select.html index 1b01723..f1b001e 100644 --- a/docs/reference/cor_select.html +++ b/docs/reference/cor_select.html @@ -1,69 +1,12 @@ - - - - - - - -Subset Correlation Matrix — cor_select • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Subset Correlation Matrix — cor_select • rstatix - - + + - - -
-
- -
- -
+
@@ -122,86 +52,91 @@

Subset Correlation Matrix

Subset Correlation Matrix

-
cor_select(x, ..., vars = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
x

a correlation matrix. Particularly, an object of class cor_mat.

...

One or more unquoted expressions (or variable names) separated by -commas. Used to select variables of interest.

vars

a character vector containing the variable names of interest.

- -

Value

- -

a data frame

-

See also

- - - -

Examples

-
# Compute correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_mat() - -# Subsetting correlation matrix -#:::::::::::::::::::::::::::::::::::::::::: - -# Select some variables of interest -cor.mat %>% - cor_select(mpg, drat, wt)
#> # A tibble: 3 x 4 -#> rowname mpg drat wt -#> <chr> <dbl> <dbl> <dbl> -#> 1 mpg 1 0.68 -0.87 -#> 2 drat 0.68 1 -0.71 -#> 3 wt -0.87 -0.71 1
-# Remove variables -cor.mat %>% - cor_select(-mpg, -wt)
#> # A tibble: 4 x 5 -#> rowname disp hp drat qsec -#> <chr> <dbl> <dbl> <dbl> <dbl> -#> 1 disp 1 0.79 -0.71 -0.43 -#> 2 hp 0.79 1 -0.45 -0.71 -#> 3 drat -0.71 -0.45 1 0.091 -#> 4 qsec -0.43 -0.71 0.091 1
-
+
+
cor_select(x, ..., vars = NULL)
+
+ +
+

Arguments

+
x
+

a correlation matrix. Particularly, an object of class cor_mat.

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to select variables of interest.

+ + +
vars
+

a character vector containing the variable names of interest.

+ +
+
+

Value

+ + +

a data frame

+
+
+

See also

+ +
+ +
+

Examples

+
# Compute correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec) %>%
+  cor_mat()
+
+# Subsetting correlation matrix
+#::::::::::::::::::::::::::::::::::::::::::
+
+# Select some variables of interest
+cor.mat %>%
+  cor_select(mpg, drat, wt)
+#> # A tibble: 3 × 4
+#>   rowname   mpg  drat    wt
+#>   <chr>   <dbl> <dbl> <dbl>
+#> 1 mpg      1     0.68 -0.87
+#> 2 drat     0.68  1    -0.71
+#> 3 wt      -0.87 -0.71  1   
+
+# Remove variables
+cor.mat %>%
+  cor_select(-mpg, -wt)
+#> # A tibble: 4 × 5
+#>   rowname  disp    hp   drat   qsec
+#>   <chr>   <dbl> <dbl>  <dbl>  <dbl>
+#> 1 disp     1     0.79 -0.71  -0.43 
+#> 2 hp       0.79  1    -0.45  -0.71 
+#> 3 drat    -0.71 -0.45  1      0.091
+#> 4 qsec    -0.43 -0.71  0.091  1    
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cor_test.html b/docs/reference/cor_test.html index 7b49fae..5d61793 100644 --- a/docs/reference/cor_test.html +++ b/docs/reference/cor_test.html @@ -1,75 +1,18 @@ - - - - - - - -Correlation Test — cor_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Correlation Test — cor_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Provides a pipe-friendly framework to perform correlation test between paired samples, using Pearson, Kendall or Spearman method. Wrapper - around the function cor.test().

+ around the function cor.test().

Can also performs multiple pairwise correlation analyses between more than two variables or between two different vectors of variables. Using this function, you can also compute, for example, the correlation between one variable vs many.

-
cor_test(
-  data,
-  ...,
-  vars = NULL,
-  vars2 = NULL,
-  alternative = "two.sided",
-  method = "pearson",
-  conf.level = 0.95,
-  use = "pairwise.complete.obs"
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables.

...

One or more unquoted expressions (or variable names) separated by +

+
cor_test(
+  data,
+  ...,
+  vars = NULL,
+  vars2 = NULL,
+  alternative = "two.sided",
+  method = "pearson",
+  conf.level = 0.95,
+  use = "pairwise.complete.obs"
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables.

+ + +
...
+

One or more unquoted expressions (or variable names) separated by commas. Used to select a variable of interest. Alternative to the argument -vars.

vars

optional character vector containing variable names for -correlation analysis. Ignored when dot vars are specified.

    -
  • If vars is NULL, multiple pairwise correlation tests is performed +vars.

    + + +
    vars
    +

    optional character vector containing variable names for +correlation analysis. Ignored when dot vars are specified.

    • If vars is NULL, multiple pairwise correlation tests is performed between all variables in the data.

    • If vars contain only one variable, a pairwise correlation analysis is performed between the specified @@ -174,167 +103,177 @@

      Arg variables. ii) if vars2 is specified, each element in vars is tested against all elements in vars2

    . Accept unquoted -variable names: c(var1, var2).

vars2

optional character vector. If specified, each element in +variable names: c(var1, var2).

+ + +
vars2
+

optional character vector. If specified, each element in vars is tested against all elements in vars2. Accept unquoted -variable names: c(var1, var2).

alternative

indicates the alternative hypothesis and must be +variable names: c(var1, var2).

+ + +
alternative
+

indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". You can specify just the initial letter. "greater" corresponds - to positive association, "less" to negative association.

method

a character string indicating which correlation + to positive association, "less" to negative association.

+ + +
method
+

a character string indicating which correlation coefficient is to be used for the test. One of "pearson", - "kendall", or "spearman", can be abbreviated.

conf.level

confidence level for the returned confidence + "kendall", or "spearman", can be abbreviated.

+ + +
conf.level
+

confidence level for the returned confidence interval. Currently only used for the Pearson product moment correlation coefficient if there are at least 4 complete pairs of - observations.

use

an optional character string giving a + observations.

+ + +
use
+

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", - "na.or.complete", or "pairwise.complete.obs".

+ "na.or.complete", or "pairwise.complete.obs".

-

Value

+
+
+

Value

+ -

return a data frame with the following columns:

    -
  • var1, var2: the variables used in the correlation test.

  • +

    return a data frame with the following columns:

    • var1, var2: the variables used in the correlation test.

    • cor: the correlation coefficient.

    • statistic: Test statistic used to compute the p-value.

    • p: p-value.

    • conf.low,conf.high: Lower and upper bounds on a confidence interval.

    • method: the method used to compute the statistic.

    • -
    - -

    Functions

    - +
+
+

Functions

-
    -
  • cor_test: correlation test between two or more variables.

  • -
-

See also

- - - -

Examples

-
-# Correlation between the specified variable vs -# the remaining numeric variables in the data -#::::::::::::::::::::::::::::::::::::::::: -mtcars %>% cor_test(mpg)
#> # A tibble: 10 x 8 -#> var1 var2 cor statistic p conf.low conf.high method -#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 mpg cyl -0.85 -8.92 6.11e-10 -0.926 -0.716 Pearson -#> 2 mpg disp -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson -#> 3 mpg hp -0.78 -6.74 1.79e- 7 -0.885 -0.586 Pearson -#> 4 mpg drat 0.68 5.10 1.78e- 5 0.436 0.832 Pearson -#> 5 mpg wt -0.87 -9.56 1.29e-10 -0.934 -0.744 Pearson -#> 6 mpg qsec 0.42 2.53 1.71e- 2 0.0820 0.670 Pearson -#> 7 mpg vs 0.66 4.86 3.42e- 5 0.410 0.822 Pearson -#> 8 mpg am 0.6 4.11 2.85e- 4 0.318 0.784 Pearson -#> 9 mpg gear 0.48 3.00 5.4 e- 3 0.158 0.710 Pearson -#> 10 mpg carb -0.55 -3.62 1.08e- 3 -0.755 -0.250 Pearson
-# Correlation test between two variables -#::::::::::::::::::::::::::::::::::::::::: -mtcars %>% cor_test(wt, mpg)
#> # A tibble: 1 x 8 -#> var1 var2 cor statistic p conf.low conf.high method -#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 wt mpg -0.87 -9.56 1.29e-10 -0.934 -0.744 Pearson
-# Pairwise correlation between multiple variables -#::::::::::::::::::::::::::::::::::::::::: -mtcars %>% cor_test(wt, mpg, disp)
#> # A tibble: 9 x 8 -#> var1 var2 cor statistic p conf.low conf.high method -#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 wt wt 1 367570386. 2.27e-236 1 1 Pearson -#> 2 wt mpg -0.87 -9.56 1.29e- 10 -0.934 -0.744 Pearson -#> 3 wt disp 0.89 10.6 1.22e- 11 0.781 0.944 Pearson -#> 4 mpg wt -0.87 -9.56 1.29e- 10 -0.934 -0.744 Pearson -#> 5 mpg mpg 1 Inf 0 1 1 Pearson -#> 6 mpg disp -0.85 -8.75 9.38e- 10 -0.923 -0.708 Pearson -#> 7 disp wt 0.89 10.6 1.22e- 11 0.781 0.944 Pearson -#> 8 disp mpg -0.85 -8.75 9.38e- 10 -0.923 -0.708 Pearson -#> 9 disp disp 1 Inf 0 1 1 Pearson
-# Grouped data -#::::::::::::::::::::::::::::::::::::::::: -iris %>% - group_by(Species) %>% - cor_test(Sepal.Width, Sepal.Length)
#> # A tibble: 3 x 9 -#> Species var1 var2 cor statistic p conf.low conf.high method -#> <fct> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 setosa Sepal.W… Sepal.L… 0.74 7.68 6.71e-10 0.585 0.846 Pears… -#> 2 versicol… Sepal.W… Sepal.L… 0.53 4.28 8.77e- 5 0.290 0.702 Pears… -#> 3 virginica Sepal.W… Sepal.L… 0.46 3.56 8.43e- 4 0.205 0.653 Pears…
-# Multiple correlation test -#::::::::::::::::::::::::::::::::::::::::: -# Correlation between one variable vs many -mtcars %>% cor_test( - vars = "mpg", - vars2 = c("disp", "hp", "drat") - )
#> # A tibble: 3 x 8 -#> var1 var2 cor statistic p conf.low conf.high method -#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 mpg disp -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson -#> 2 mpg hp -0.78 -6.74 1.79e- 7 -0.885 -0.586 Pearson -#> 3 mpg drat 0.68 5.10 1.78e- 5 0.436 0.832 Pearson
-# Correlation between two vectors of variables -# Each element in vars is tested against all elements in vars2 -mtcars %>% cor_test( - vars = c("mpg", "wt"), - vars2 = c("disp", "hp", "drat") - )
#> # A tibble: 6 x 8 -#> var1 var2 cor statistic p conf.low conf.high method -#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 mpg disp -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson -#> 2 mpg hp -0.78 -6.74 1.79e- 7 -0.885 -0.586 Pearson -#> 3 mpg drat 0.68 5.10 1.78e- 5 0.436 0.832 Pearson -#> 4 wt disp 0.89 10.6 1.22e-11 0.781 0.944 Pearson -#> 5 wt hp 0.66 4.80 4.15e- 5 0.403 0.819 Pearson -#> 6 wt drat -0.71 -5.56 4.78e- 6 -0.850 -0.484 Pearson
- -
+
  • cor_test(): correlation test between two or more variables.

  • +
+
+

See also

+ +
+ +
+

Examples

+

+# Correlation between the specified variable vs
+# the remaining numeric variables in the data
+#:::::::::::::::::::::::::::::::::::::::::
+mtcars %>% cor_test(mpg)
+#> # A tibble: 10 × 8
+#>    var1  var2    cor statistic        p conf.low conf.high method 
+#>    <chr> <chr> <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>  
+#>  1 mpg   cyl   -0.85     -8.92 6.11e-10  -0.926     -0.716 Pearson
+#>  2 mpg   disp  -0.85     -8.75 9.38e-10  -0.923     -0.708 Pearson
+#>  3 mpg   hp    -0.78     -6.74 1.79e- 7  -0.885     -0.586 Pearson
+#>  4 mpg   drat   0.68      5.10 1.78e- 5   0.436      0.832 Pearson
+#>  5 mpg   wt    -0.87     -9.56 1.29e-10  -0.934     -0.744 Pearson
+#>  6 mpg   qsec   0.42      2.53 1.71e- 2   0.0820     0.670 Pearson
+#>  7 mpg   vs     0.66      4.86 3.42e- 5   0.410      0.822 Pearson
+#>  8 mpg   am     0.6       4.11 2.85e- 4   0.318      0.784 Pearson
+#>  9 mpg   gear   0.48      3.00 5.4 e- 3   0.158      0.710 Pearson
+#> 10 mpg   carb  -0.55     -3.62 1.08e- 3  -0.755     -0.250 Pearson
+
+# Correlation test between two variables
+#:::::::::::::::::::::::::::::::::::::::::
+mtcars %>% cor_test(wt, mpg)
+#> # A tibble: 1 × 8
+#>   var1  var2    cor statistic        p conf.low conf.high method 
+#>   <chr> <chr> <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>  
+#> 1 wt    mpg   -0.87     -9.56 1.29e-10   -0.934    -0.744 Pearson
+
+# Pairwise correlation between multiple variables
+#:::::::::::::::::::::::::::::::::::::::::
+mtcars %>% cor_test(wt, mpg, disp)
+#> # A tibble: 9 × 8
+#>   var1  var2    cor    statistic         p conf.low conf.high method 
+#>   <chr> <chr> <dbl>        <dbl>     <dbl>    <dbl>     <dbl> <chr>  
+#> 1 wt    wt     1    367570386.   2.27e-236    1         1     Pearson
+#> 2 wt    mpg   -0.87        -9.56 1.29e- 10   -0.934    -0.744 Pearson
+#> 3 wt    disp   0.89        10.6  1.22e- 11    0.781     0.944 Pearson
+#> 4 mpg   wt    -0.87        -9.56 1.29e- 10   -0.934    -0.744 Pearson
+#> 5 mpg   mpg    1          Inf    0            1         1     Pearson
+#> 6 mpg   disp  -0.85        -8.75 9.38e- 10   -0.923    -0.708 Pearson
+#> 7 disp  wt     0.89        10.6  1.22e- 11    0.781     0.944 Pearson
+#> 8 disp  mpg   -0.85        -8.75 9.38e- 10   -0.923    -0.708 Pearson
+#> 9 disp  disp   1          Inf    0            1         1     Pearson
+
+# Grouped data
+#:::::::::::::::::::::::::::::::::::::::::
+iris %>%
+  group_by(Species) %>%
+ cor_test(Sepal.Width, Sepal.Length)
+#> # A tibble: 3 × 9
+#>   Species    var1        var2        cor stati…¹        p conf.…² conf.…³ method
+#>   <fct>      <chr>       <chr>     <dbl>   <dbl>    <dbl>   <dbl>   <dbl> <chr> 
+#> 1 setosa     Sepal.Width Sepal.Le…  0.74    7.68 6.71e-10   0.585   0.846 Pears…
+#> 2 versicolor Sepal.Width Sepal.Le…  0.53    4.28 8.77e- 5   0.290   0.702 Pears…
+#> 3 virginica  Sepal.Width Sepal.Le…  0.46    3.56 8.43e- 4   0.205   0.653 Pears…
+#> # … with abbreviated variable names ¹​statistic, ²​conf.low, ³​conf.high
+
+# Multiple correlation test
+#:::::::::::::::::::::::::::::::::::::::::
+# Correlation between one variable vs many
+mtcars %>% cor_test(
+  vars = "mpg",
+  vars2 = c("disp", "hp", "drat")
+ )
+#> # A tibble: 3 × 8
+#>   var1  var2    cor statistic        p conf.low conf.high method 
+#>   <chr> <chr> <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>  
+#> 1 mpg   disp  -0.85     -8.75 9.38e-10   -0.923    -0.708 Pearson
+#> 2 mpg   hp    -0.78     -6.74 1.79e- 7   -0.885    -0.586 Pearson
+#> 3 mpg   drat   0.68      5.10 1.78e- 5    0.436     0.832 Pearson
+
+# Correlation between two vectors of variables
+# Each element in vars is tested against all elements in vars2
+mtcars %>% cor_test(
+  vars = c("mpg", "wt"),
+  vars2 = c("disp", "hp", "drat")
+ )
+#> # A tibble: 6 × 8
+#>   var1  var2    cor statistic        p conf.low conf.high method 
+#>   <chr> <chr> <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>  
+#> 1 mpg   disp  -0.85     -8.75 9.38e-10   -0.923    -0.708 Pearson
+#> 2 mpg   hp    -0.78     -6.74 1.79e- 7   -0.885    -0.586 Pearson
+#> 3 mpg   drat   0.68      5.10 1.78e- 5    0.436     0.832 Pearson
+#> 4 wt    disp   0.89     10.6  1.22e-11    0.781     0.944 Pearson
+#> 5 wt    hp     0.66      4.80 4.15e- 5    0.403     0.819 Pearson
+#> 6 wt    drat  -0.71     -5.56 4.78e- 6   -0.850    -0.484 Pearson
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/counts_to_cases.html b/docs/reference/counts_to_cases.html index f18a4ad..c896f5b 100644 --- a/docs/reference/counts_to_cases.html +++ b/docs/reference/counts_to_cases.html @@ -1,70 +1,13 @@ - - - - - - - -Convert a Table of Counts into a Data Frame of cases — counts_to_cases • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Convert a Table of Counts into a Data Frame of cases — counts_to_cases • rstatix + + - - - - -
-
- -
- -
+
@@ -124,75 +54,79 @@

Convert a Table of Counts into a Data Frame of cases

data frame of individual observations.

-
counts_to_cases(x, count.col = "Freq")
- -

Arguments

- - - - - - - - - - -
x

a contingency table or a data frame

count.col

the name of the column containing the counts. Default is "Freq".

- -

Value

- -

a data frame of cases

- -

Examples

-
# Create a cross-tabulation demo data -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -xtab <- as.table( - rbind(c(20, 5), c(16,9)) -) -dimnames(xtab) <- list( - before = c("non.smoker", "smoker"), - after = c("non.smoker", "smoker") -) -xtab
#> after -#> before non.smoker smoker -#> non.smoker 20 5 -#> smoker 16 9
-# Convert into a data frame of cases -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -df <- counts_to_cases(xtab) -head(df)
#> before after -#> 1 non.smoker non.smoker -#> 2 non.smoker non.smoker -#> 3 non.smoker non.smoker -#> 4 non.smoker non.smoker -#> 5 non.smoker non.smoker -#> 6 non.smoker non.smoker
-
+
+
counts_to_cases(x, count.col = "Freq")
+
+ +
+

Arguments

+
x
+

a contingency table or a data frame

+ + +
count.col
+

the name of the column containing the counts. Default is "Freq".

+ +
+
+

Value

+ + +

a data frame of cases

+
+ +
+

Examples

+
# Create a cross-tabulation demo data
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+xtab <- as.table(
+  rbind(c(20, 5), c(16,9))
+)
+dimnames(xtab) <- list(
+  before = c("non.smoker", "smoker"),
+  after = c("non.smoker", "smoker")
+)
+xtab
+#>             after
+#> before       non.smoker smoker
+#>   non.smoker         20      5
+#>   smoker             16      9
+
+# Convert into a data frame of cases
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+df <- counts_to_cases(xtab)
+head(df)
+#>       before      after
+#> 1 non.smoker non.smoker
+#> 2 non.smoker non.smoker
+#> 3 non.smoker non.smoker
+#> 4 non.smoker non.smoker
+#> 5 non.smoker non.smoker
+#> 6 non.smoker non.smoker
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cramer_v.html b/docs/reference/cramer_v.html index f518894..c7895d4 100644 --- a/docs/reference/cramer_v.html +++ b/docs/reference/cramer_v.html @@ -1,70 +1,13 @@ - - - - - - - -Compute Cramer's V — cramer_v • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Cramer's V — cramer_v • rstatix - - + + - - -
-
- -
- -
+
@@ -124,76 +54,77 @@

Compute Cramer's V

association between categorical variables.

-
cramer_v(x, y = NULL, correct = TRUE, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
x

a numeric vector or matrix. x and y can also - both be factors.

y

a numeric vector; ignored if x is a matrix. If - x is a factor, y should be a factor of the same length.

correct

a logical indicating whether to apply continuity +

+
cramer_v(x, y = NULL, correct = TRUE, ...)
+
+ +
+

Arguments

+
x
+

a numeric vector or matrix. x and y can also + both be factors.

+ + +
y
+

a numeric vector; ignored if x is a matrix. If + x is a factor, y should be a factor of the same length.

+ + +
correct
+

a logical indicating whether to apply continuity correction when computing the test statistic for 2 by 2 tables: one half is subtracted from all \(|O - E|\) differences; however, the correction will not be bigger than the differences themselves. No correction - is done if simulate.p.value = TRUE.

...

other arguments passed to the function -chisq.test().

- - -

Examples

-
-# Data preparation -df <- as.table(rbind(c(762, 327, 468), c(484, 239, 477))) -dimnames(df) <- list( - gender = c("F", "M"), - party = c("Democrat","Independent", "Republican") -) -df
#> party -#> gender Democrat Independent Republican -#> F 762 327 468 -#> M 484 239 477
# Compute cramer's V -cramer_v(df)
#> [1] 0.1044358
-
+ is done if simulate.p.value = TRUE.

+ + +
...
+

other arguments passed to the function +chisq.test().

+ +
+ +
+

Examples

+

+# Data preparation
+df <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
+dimnames(df) <- list(
+  gender = c("F", "M"),
+  party = c("Democrat","Independent", "Republican")
+)
+df
+#>       party
+#> gender Democrat Independent Republican
+#>      F      762         327        468
+#>      M      484         239        477
+# Compute cramer's V
+cramer_v(df)
+#> [1] 0.1044358
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_arrange.html b/docs/reference/df_arrange.html index 12c1836..46984f6 100644 --- a/docs/reference/df_arrange.html +++ b/docs/reference/df_arrange.html @@ -1,71 +1,14 @@ - - - - - - - -Arrange Rows by Column Values — df_arrange • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Arrange Rows by Column Values — df_arrange • rstatix - - - - - - - - - - - + + - - -
-
- -
- -
+

Order the rows of a data frame by values of specified columns. - Wrapper arround the arrange() function. Supports + Wrapper arround the arrange() function. Supports standard and non standard evaluation.

-
df_arrange(data, ..., vars = NULL, .by_group = FALSE)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by +

+
df_arrange(data, ..., vars = NULL, .by_group = FALSE)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by commas. Used to select a variable of interest. Use -desc() to sort a variable in descending order.

vars

a character vector containing the variable names of interest.

.by_group

If TRUE, will sort first by grouping variable. Applies to -grouped data frames only.

- -

Value

- -

a data frame

- -

Examples

-
df <- head(ToothGrowth) -df
#> len supp dose -#> 1 4.2 VC 0.5 -#> 2 11.5 VC 0.5 -#> 3 7.3 VC 0.5 -#> 4 5.8 VC 0.5 -#> 5 6.4 VC 0.5 -#> 6 10.0 VC 0.5
-# Select column using standard evaluation -df %>% df_arrange(vars = c("dose", "len"))
#> len supp dose -#> 1 4.2 VC 0.5 -#> 2 5.8 VC 0.5 -#> 3 6.4 VC 0.5 -#> 4 7.3 VC 0.5 -#> 5 10.0 VC 0.5 -#> 6 11.5 VC 0.5
-# Select column using non-standard evaluation -df %>% df_arrange(dose, desc(len))
#> len supp dose -#> 1 11.5 VC 0.5 -#> 2 10.0 VC 0.5 -#> 3 7.3 VC 0.5 -#> 4 6.4 VC 0.5 -#> 5 5.8 VC 0.5 -#> 6 4.2 VC 0.5
+desc() to sort a variable in descending order.

+ + +
vars
+

a character vector containing the variable names of interest.

+ + +
.by_group
+

If TRUE, will sort first by grouping variable. Applies to +grouped data frames only.

+ +
+
+

Value

+ + +

a data frame

+
+ +
+

Examples

+
df <- head(ToothGrowth)
+df
+#>    len supp dose
+#> 1  4.2   VC  0.5
+#> 2 11.5   VC  0.5
+#> 3  7.3   VC  0.5
+#> 4  5.8   VC  0.5
+#> 5  6.4   VC  0.5
+#> 6 10.0   VC  0.5
+
+# Select column using standard evaluation
+df %>% df_arrange(vars = c("dose", "len"))
+#>    len supp dose
+#> 1  4.2   VC  0.5
+#> 2  5.8   VC  0.5
+#> 3  6.4   VC  0.5
+#> 4  7.3   VC  0.5
+#> 5 10.0   VC  0.5
+#> 6 11.5   VC  0.5
+
+# Select column using non-standard evaluation
+df %>% df_arrange(dose, desc(len))
+#>    len supp dose
+#> 1 11.5   VC  0.5
+#> 2 10.0   VC  0.5
+#> 3  7.3   VC  0.5
+#> 4  6.4   VC  0.5
+#> 5  5.8   VC  0.5
+#> 6  4.2   VC  0.5
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_get_var_names.html b/docs/reference/df_get_var_names.html index b08bea3..f7189d3 100644 --- a/docs/reference/df_get_var_names.html +++ b/docs/reference/df_get_var_names.html @@ -1,69 +1,12 @@ - - - - - - - -Get User Specified Variable Names — df_get_var_names • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Get User Specified Variable Names — df_get_var_names • rstatix - + + - - - -
-
- -
- -
+
@@ -122,63 +52,67 @@

Get User Specified Variable Names

Returns user specified variable names. Supports standard and non standard evaluation.

-
df_get_var_names(data, ..., vars = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used to select a variable of interest.

vars

a character vector containing the variable names of interest.

- -

Value

- -

a character vector

- -

Examples

-
-# Non standard evaluation -ToothGrowth %>% - df_get_var_names(dose, len)
#> [1] "dose" "len"
-# Standard evaluation -ToothGrowth %>% - df_get_var_names(vars = c("len", "dose"))
#> [1] "len" "dose"
+
+
df_get_var_names(data, ..., vars = NULL)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to select a variable of interest.

+ + +
vars
+

a character vector containing the variable names of interest.

+ +
+
+

Value

+ + +

a character vector

+
+ +
+

Examples

+

+# Non standard evaluation
+ToothGrowth %>%
+ df_get_var_names(dose, len)
+#> [1] "dose" "len" 
+
+# Standard evaluation
+ToothGrowth %>%
+ df_get_var_names(vars = c("len", "dose"))
+#> [1] "len"  "dose"
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_group_by.html b/docs/reference/df_group_by.html index 4518cb6..d4e865e 100644 --- a/docs/reference/df_group_by.html +++ b/docs/reference/df_group_by.html @@ -1,70 +1,13 @@ - - - - - - - -Group a Data Frame by One or more Variables — df_group_by • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Group a Data Frame by One or more Variables — df_group_by • rstatix - - + + - - -
-
- -
- -
+
@@ -124,79 +54,80 @@

Group a Data Frame by One or more Variables

and non standard evaluation.

-
df_group_by(data, ..., vars = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used to select a variable of interest.

vars

a character vector containing the variable names of interest.

- - -

Examples

-
-# Non standard evaluation -by_dose <- head(ToothGrowth) %>% - df_group_by(dose) -by_dose
#> # A tibble: 6 x 3 -#> # Groups: dose [1] -#> len supp dose -#> <dbl> <fct> <dbl> -#> 1 4.2 VC 0.5 -#> 2 11.5 VC 0.5 -#> 3 7.3 VC 0.5 -#> 4 5.8 VC 0.5 -#> 5 6.4 VC 0.5 -#> 6 10 VC 0.5
-# Standard evaluation -head(ToothGrowth) %>% - df_group_by(vars = c("dose", "supp"))
#> # A tibble: 6 x 3 -#> # Groups: dose, supp [1] -#> len supp dose -#> <dbl> <fct> <dbl> -#> 1 4.2 VC 0.5 -#> 2 11.5 VC 0.5 -#> 3 7.3 VC 0.5 -#> 4 5.8 VC 0.5 -#> 5 6.4 VC 0.5 -#> 6 10 VC 0.5
+
+
df_group_by(data, ..., vars = NULL)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to select a variable of interest.

+ + +
vars
+

a character vector containing the variable names of interest.

+ +
+ +
+

Examples

+

+# Non standard evaluation
+by_dose <- head(ToothGrowth) %>%
+   df_group_by(dose)
+by_dose
+#> # A tibble: 6 × 3
+#> # Groups:   dose [1]
+#>     len supp   dose
+#>   <dbl> <fct> <dbl>
+#> 1   4.2 VC      0.5
+#> 2  11.5 VC      0.5
+#> 3   7.3 VC      0.5
+#> 4   5.8 VC      0.5
+#> 5   6.4 VC      0.5
+#> 6  10   VC      0.5
+
+# Standard evaluation
+head(ToothGrowth) %>%
+   df_group_by(vars = c("dose", "supp"))
+#> # A tibble: 6 × 3
+#> # Groups:   dose, supp [1]
+#>     len supp   dose
+#>   <dbl> <fct> <dbl>
+#> 1   4.2 VC      0.5
+#> 2  11.5 VC      0.5
+#> 3   7.3 VC      0.5
+#> 4   5.8 VC      0.5
+#> 5   6.4 VC      0.5
+#> 6  10   VC      0.5
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_label_value.html b/docs/reference/df_label_value.html index bf7dcce..2bed632 100644 --- a/docs/reference/df_label_value.html +++ b/docs/reference/df_label_value.html @@ -1,70 +1,13 @@ - - - - - - - -Functions to Label Data Frames by Grouping Variables — df_label_both • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Functions to Label Data Frames by Grouping Variables — df_label_both • rstatix - - - - + + -
-
- -
- -
+
@@ -124,111 +54,116 @@

Functions to Label Data Frames by Grouping Variables

variables.

-
df_label_both(data, ..., vars = NULL, label_col = "label", sep = c(", ", ":"))
-
-df_label_value(data, ..., vars = NULL, label_col = "label", sep = ", ")
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used as grouping variables.

vars

a character vector containing the grouping variables of interest.

label_col

column to hold the label of the data subsets. Default column -name is "label".

sep

String separating labelling variables and values. Should be of +

+
df_label_both(data, ..., vars = NULL, label_col = "label", sep = c(", ", ":"))
+
+df_label_value(data, ..., vars = NULL, label_col = "label", sep = ", ")
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used as grouping variables.

+ + +
vars
+

a character vector containing the grouping variables of interest.

+ + +
label_col
+

column to hold the label of the data subsets. Default column +name is "label".

+ + +
sep
+

String separating labelling variables and values. Should be of length 2 in the function df_label_both(). 1) One sep is used to separate groups, for example ','; 2) The other sep between group name and -levels; for example ':'.

- -

Value

+levels; for example ':'.

-

a modified data frame with a column containing row labels.

-

Functions

+
+
+

Value

+ +

a modified data frame with a column containing row labels.

+
+
+

Functions

-
    -
  • df_label_both: Displays both the variable name and the factor value.

  • -
  • df_label_value: Displays only the value of a factor.

  • -
- -

Examples

-
# Data preparation -df <- head(ToothGrowth) - -# Labelling: Non standard evaluation -df %>% - df_label_both(dose, supp)
#> len supp dose label -#> 1 4.2 VC 0.5 dose:0.5, supp:VC -#> 2 11.5 VC 0.5 dose:0.5, supp:VC -#> 3 7.3 VC 0.5 dose:0.5, supp:VC -#> 4 5.8 VC 0.5 dose:0.5, supp:VC -#> 5 6.4 VC 0.5 dose:0.5, supp:VC -#> 6 10.0 VC 0.5 dose:0.5, supp:VC
-# Standard evaluation -df %>% - df_label_both(dose, supp)
#> len supp dose label -#> 1 4.2 VC 0.5 dose:0.5, supp:VC -#> 2 11.5 VC 0.5 dose:0.5, supp:VC -#> 3 7.3 VC 0.5 dose:0.5, supp:VC -#> 4 5.8 VC 0.5 dose:0.5, supp:VC -#> 5 6.4 VC 0.5 dose:0.5, supp:VC -#> 6 10.0 VC 0.5 dose:0.5, supp:VC
-# Nesting the data then label each subset by groups -ToothGrowth %>% - df_nest_by(dose, supp) %>% - df_label_both(supp, dose)
#> # A tibble: 6 x 4 -#> supp dose data label -#> <fct> <dbl> <list> <fct> -#> 1 VC 0.5 <tibble [10 × 1]> supp:OJ, dose:0.5 -#> 2 VC 1 <tibble [10 × 1]> supp:OJ, dose:1 -#> 3 VC 2 <tibble [10 × 1]> supp:OJ, dose:2 -#> 4 OJ 0.5 <tibble [10 × 1]> supp:VC, dose:0.5 -#> 5 OJ 1 <tibble [10 × 1]> supp:VC, dose:1 -#> 6 OJ 2 <tibble [10 × 1]> supp:VC, dose:2
-
+
  • df_label_both(): Displays both the variable name and the factor value.

  • +
  • df_label_value(): Displays only the value of a factor.

  • +
+ +
+

Examples

+
# Data preparation
+df <- head(ToothGrowth)
+
+# Labelling: Non standard evaluation
+df %>%
+  df_label_both(dose, supp)
+#>    len supp dose             label
+#> 1  4.2   VC  0.5 dose:0.5, supp:VC
+#> 2 11.5   VC  0.5 dose:0.5, supp:VC
+#> 3  7.3   VC  0.5 dose:0.5, supp:VC
+#> 4  5.8   VC  0.5 dose:0.5, supp:VC
+#> 5  6.4   VC  0.5 dose:0.5, supp:VC
+#> 6 10.0   VC  0.5 dose:0.5, supp:VC
+
+# Standard evaluation
+df %>%
+  df_label_both(dose, supp)
+#>    len supp dose             label
+#> 1  4.2   VC  0.5 dose:0.5, supp:VC
+#> 2 11.5   VC  0.5 dose:0.5, supp:VC
+#> 3  7.3   VC  0.5 dose:0.5, supp:VC
+#> 4  5.8   VC  0.5 dose:0.5, supp:VC
+#> 5  6.4   VC  0.5 dose:0.5, supp:VC
+#> 6 10.0   VC  0.5 dose:0.5, supp:VC
+
+# Nesting the data then label each subset by groups
+ToothGrowth %>%
+  df_nest_by(dose, supp) %>%
+  df_label_both(supp, dose)
+#> # A tibble: 6 × 4
+#>   supp   dose data              label            
+#>   <fct> <dbl> <list>            <fct>            
+#> 1 VC      0.5 <tibble [10 × 1]> supp:OJ, dose:0.5
+#> 2 VC      1   <tibble [10 × 1]> supp:OJ, dose:1  
+#> 3 VC      2   <tibble [10 × 1]> supp:OJ, dose:2  
+#> 4 OJ      0.5 <tibble [10 × 1]> supp:VC, dose:0.5
+#> 5 OJ      1   <tibble [10 × 1]> supp:VC, dose:1  
+#> 6 OJ      2   <tibble [10 × 1]> supp:VC, dose:2  
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_nest_by.html b/docs/reference/df_nest_by.html index ca8af18..45fde30 100644 --- a/docs/reference/df_nest_by.html +++ b/docs/reference/df_nest_by.html @@ -1,69 +1,12 @@ - - - - - - - -Nest a Tibble By Groups — df_nest_by • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Nest a Tibble By Groups — df_nest_by • rstatix - + + - - - -
-
- -
- -
+
@@ -122,82 +52,86 @@

Nest a Tibble By Groups

Nest a tibble data frame using grouping specification. Supports standard and non standard evaluation.

-
df_nest_by(data, ..., vars = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used as grouping variables.

vars

a character vector containing the grouping variables of interest.

- -

Value

- -

A tbl with one row per unique combination of the grouping variables. +

+
df_nest_by(data, ..., vars = NULL)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used as grouping variables.

+ + +
vars
+

a character vector containing the grouping variables of interest.

+ +
+
+

Value

+ + +

A tbl with one row per unique combination of the grouping variables. The first columns are the grouping variables, followed by a list column of tibbles with matching rows of the remaining columns.

+
-

Examples

-
-# Non standard evaluation -ToothGrowth %>% - df_nest_by(dose, supp)
#> # A tibble: 6 x 3 -#> supp dose data -#> <fct> <dbl> <list> -#> 1 VC 0.5 <tibble [10 × 1]> -#> 2 VC 1 <tibble [10 × 1]> -#> 3 VC 2 <tibble [10 × 1]> -#> 4 OJ 0.5 <tibble [10 × 1]> -#> 5 OJ 1 <tibble [10 × 1]> -#> 6 OJ 2 <tibble [10 × 1]>
-# Standard evaluation -ToothGrowth %>% - df_nest_by(vars = c("dose", "supp"))
#> # A tibble: 6 x 3 -#> supp dose data -#> <fct> <dbl> <list> -#> 1 VC 0.5 <tibble [10 × 1]> -#> 2 VC 1 <tibble [10 × 1]> -#> 3 VC 2 <tibble [10 × 1]> -#> 4 OJ 0.5 <tibble [10 × 1]> -#> 5 OJ 1 <tibble [10 × 1]> -#> 6 OJ 2 <tibble [10 × 1]>
-
+
+

Examples

+

+# Non standard evaluation
+ToothGrowth %>%
+ df_nest_by(dose, supp)
+#> # A tibble: 6 × 3
+#>   supp   dose data             
+#>   <fct> <dbl> <list>           
+#> 1 VC      0.5 <tibble [10 × 1]>
+#> 2 VC      1   <tibble [10 × 1]>
+#> 3 VC      2   <tibble [10 × 1]>
+#> 4 OJ      0.5 <tibble [10 × 1]>
+#> 5 OJ      1   <tibble [10 × 1]>
+#> 6 OJ      2   <tibble [10 × 1]>
+
+# Standard evaluation
+ToothGrowth %>%
+ df_nest_by(vars = c("dose", "supp"))
+#> # A tibble: 6 × 3
+#>   supp   dose data             
+#>   <fct> <dbl> <list>           
+#> 1 VC      0.5 <tibble [10 × 1]>
+#> 2 VC      1   <tibble [10 × 1]>
+#> 3 VC      2   <tibble [10 × 1]>
+#> 4 OJ      0.5 <tibble [10 × 1]>
+#> 5 OJ      1   <tibble [10 × 1]>
+#> 6 OJ      2   <tibble [10 × 1]>
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_select.html b/docs/reference/df_select.html index c800025..3c9c826 100644 --- a/docs/reference/df_select.html +++ b/docs/reference/df_select.html @@ -1,71 +1,14 @@ - - - - - - - -Select Columns in a Data Frame — df_select • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Select Columns in a Data Frame — df_select • rstatix - - - - - - - - - - + + - - - -
-
- -
- -
+
-

A wrapper around the select() function for +

A wrapper around the select() function for selection data frame columns. Supports standard and non standard evaluations. Usefull to easily program with dplyr

-
df_select(data, ..., vars = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used to select a variable of interest.

vars

a character vector containing the variable names of interest.

- -

Value

- -

a data frame

- -

Examples

-
df <- head(ToothGrowth) -df
#> len supp dose -#> 1 4.2 VC 0.5 -#> 2 11.5 VC 0.5 -#> 3 7.3 VC 0.5 -#> 4 5.8 VC 0.5 -#> 5 6.4 VC 0.5 -#> 6 10.0 VC 0.5
-# Select column using standard evaluation -df %>% df_select(vars = c("dose", "len"))
#> dose len -#> 1 0.5 4.2 -#> 2 0.5 11.5 -#> 3 0.5 7.3 -#> 4 0.5 5.8 -#> 5 0.5 6.4 -#> 6 0.5 10.0
-# Select column using non-standard evaluation -df %>% df_select(dose, len)
#> dose len -#> 1 0.5 4.2 -#> 2 0.5 11.5 -#> 3 0.5 7.3 -#> 4 0.5 5.8 -#> 5 0.5 6.4 -#> 6 0.5 10.0
+
+
df_select(data, ..., vars = NULL)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to select a variable of interest.

+ + +
vars
+

a character vector containing the variable names of interest.

+ +
+
+

Value

+ + +

a data frame

+
+ +
+

Examples

+
df <- head(ToothGrowth)
+df
+#>    len supp dose
+#> 1  4.2   VC  0.5
+#> 2 11.5   VC  0.5
+#> 3  7.3   VC  0.5
+#> 4  5.8   VC  0.5
+#> 5  6.4   VC  0.5
+#> 6 10.0   VC  0.5
+
+# Select column using standard evaluation
+df %>% df_select(vars = c("dose", "len"))
+#>   dose  len
+#> 1  0.5  4.2
+#> 2  0.5 11.5
+#> 3  0.5  7.3
+#> 4  0.5  5.8
+#> 5  0.5  6.4
+#> 6  0.5 10.0
+
+# Select column using non-standard evaluation
+df %>% df_select(dose, len)
+#>   dose  len
+#> 1  0.5  4.2
+#> 2  0.5 11.5
+#> 3  0.5  7.3
+#> 4  0.5  5.8
+#> 5  0.5  6.4
+#> 6  0.5 10.0
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_split_by.html b/docs/reference/df_split_by.html index f475e53..1861223 100644 --- a/docs/reference/df_split_by.html +++ b/docs/reference/df_split_by.html @@ -1,72 +1,15 @@ - - - - - - - -Split a Data Frame into Subset — df_split_by • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Split a Data Frame into Subset — df_split_by • rstatix - - + + - - -
-
- -
- -
+

Split a data frame by groups into subsets or data panel. Very - similar to the function df_nest_by(). The only difference is + similar to the function df_nest_by(). The only difference is that, it adds label to each data subset. Labels are the combination of the grouping variable levels. The column holding labels are named "label".

-
df_split_by(
-  data,
-  ...,
-  vars = NULL,
-  label_col = "label",
-  labeller = df_label_both,
-  sep = c(", ", ":")
-)
+
+
df_split_by(
+  data,
+  ...,
+  vars = NULL,
+  label_col = "label",
+  labeller = df_label_both,
+  sep = c(", ", ":")
+)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used as grouping variables.

-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used as grouping variables.

vars

a character vector containing the grouping variables of interest.

label_col

column to hold the label of the data subsets. Default column -name is "label".

labeller

A function that takes a data frame, the grouping variables, + +

vars
+

a character vector containing the grouping variables of interest.

+ + +
label_col
+

column to hold the label of the data subsets. Default column +name is "label".

+ + +
labeller
+

A function that takes a data frame, the grouping variables, label_col and label_sep arguments, and add labels into the data frame. -Example of possible values are: df_label_both() and -df_label_value().

sep

String separating labelling variables and values. Should be of -length 2 in the function df_label_both(). 1) One sep is used to +Example of possible values are: df_label_both() and +df_label_value().

+ + +
sep
+

String separating labelling variables and values. Should be of +length 2 in the function df_label_both(). 1) One sep is used to separate groups, for example ','; 2) The other sep between group name and -levels; for example ':'.

+levels; for example ':'.

-

Value

+
+
+

Value

+ -

A tbl with one row per unique combination of the grouping variables. +

A tbl with one row per unique combination of the grouping variables. The first columns are the grouping variables, followed by a list column of tibbles with matching rows of the remaining columns, and a column named label, containing labels.

+
-

Examples

-
-# Split a data frame -# ::::::::::::::::::::::::::::::::::::::::::::::::: -# Create a grouped data -res <- ToothGrowth %>% - df_split_by(dose, supp) -res
#> # A tibble: 6 x 4 -#> supp dose data label -#> <fct> <dbl> <list> <fct> -#> 1 VC 0.5 <tibble [10 × 2]> dose:0.5, supp:OJ -#> 2 VC 1 <tibble [10 × 2]> dose:0.5, supp:VC -#> 3 VC 2 <tibble [10 × 2]> dose:1, supp:OJ -#> 4 OJ 0.5 <tibble [10 × 2]> dose:1, supp:VC -#> 5 OJ 1 <tibble [10 × 2]> dose:2, supp:OJ -#> 6 OJ 2 <tibble [10 × 2]> dose:2, supp:VC
-# Show subsets -res$data
#> [[1]] -#> # A tibble: 10 x 2 -#> len label -#> <dbl> <fct> -#> 1 4.2 dose:0.5, supp:OJ -#> 2 11.5 dose:0.5, supp:OJ -#> 3 7.3 dose:0.5, supp:OJ -#> 4 5.8 dose:0.5, supp:OJ -#> 5 6.4 dose:0.5, supp:OJ -#> 6 10 dose:0.5, supp:OJ -#> 7 11.2 dose:0.5, supp:OJ -#> 8 11.2 dose:0.5, supp:OJ -#> 9 5.2 dose:0.5, supp:OJ -#> 10 7 dose:0.5, supp:OJ -#> -#> [[2]] -#> # A tibble: 10 x 2 -#> len label -#> <dbl> <fct> -#> 1 16.5 dose:0.5, supp:VC -#> 2 16.5 dose:0.5, supp:VC -#> 3 15.2 dose:0.5, supp:VC -#> 4 17.3 dose:0.5, supp:VC -#> 5 22.5 dose:0.5, supp:VC -#> 6 17.3 dose:0.5, supp:VC -#> 7 13.6 dose:0.5, supp:VC -#> 8 14.5 dose:0.5, supp:VC -#> 9 18.8 dose:0.5, supp:VC -#> 10 15.5 dose:0.5, supp:VC -#> -#> [[3]] -#> # A tibble: 10 x 2 -#> len label -#> <dbl> <fct> -#> 1 23.6 dose:1, supp:OJ -#> 2 18.5 dose:1, supp:OJ -#> 3 33.9 dose:1, supp:OJ -#> 4 25.5 dose:1, supp:OJ -#> 5 26.4 dose:1, supp:OJ -#> 6 32.5 dose:1, supp:OJ -#> 7 26.7 dose:1, supp:OJ -#> 8 21.5 dose:1, supp:OJ -#> 9 23.3 dose:1, supp:OJ -#> 10 29.5 dose:1, supp:OJ -#> -#> [[4]] -#> # A tibble: 10 x 2 -#> len label -#> <dbl> <fct> -#> 1 15.2 dose:1, supp:VC -#> 2 21.5 dose:1, supp:VC -#> 3 17.6 dose:1, supp:VC -#> 4 9.7 dose:1, supp:VC -#> 5 14.5 dose:1, supp:VC -#> 6 10 dose:1, supp:VC -#> 7 8.2 dose:1, supp:VC -#> 8 9.4 dose:1, supp:VC -#> 9 16.5 dose:1, supp:VC -#> 10 9.7 dose:1, supp:VC -#> -#> [[5]] -#> # A tibble: 10 x 2 -#> len label -#> <dbl> <fct> -#> 1 19.7 dose:2, supp:OJ -#> 2 23.3 dose:2, supp:OJ -#> 3 23.6 dose:2, supp:OJ -#> 4 26.4 dose:2, supp:OJ -#> 5 20 dose:2, supp:OJ -#> 6 25.2 dose:2, supp:OJ -#> 7 25.8 dose:2, supp:OJ -#> 8 21.2 dose:2, supp:OJ -#> 9 14.5 dose:2, supp:OJ -#> 10 27.3 dose:2, supp:OJ -#> -#> [[6]] -#> # A tibble: 10 x 2 -#> len label -#> <dbl> <fct> -#> 1 25.5 dose:2, supp:VC -#> 2 26.4 dose:2, supp:VC -#> 3 22.4 dose:2, supp:VC -#> 4 24.5 dose:2, supp:VC -#> 5 24.8 dose:2, supp:VC -#> 6 30.9 dose:2, supp:VC -#> 7 26.4 dose:2, supp:VC -#> 8 27.3 dose:2, supp:VC -#> 9 29.4 dose:2, supp:VC -#> 10 23 dose:2, supp:VC -#>
-# Add panel/subset labels -res <- ToothGrowth %>% - df_split_by(dose, supp) -res
#> # A tibble: 6 x 4 -#> supp dose data label -#> <fct> <dbl> <list> <fct> -#> 1 VC 0.5 <tibble [10 × 2]> dose:0.5, supp:OJ -#> 2 VC 1 <tibble [10 × 2]> dose:0.5, supp:VC -#> 3 VC 2 <tibble [10 × 2]> dose:1, supp:OJ -#> 4 OJ 0.5 <tibble [10 × 2]> dose:1, supp:VC -#> 5 OJ 1 <tibble [10 × 2]> dose:2, supp:OJ -#> 6 OJ 2 <tibble [10 × 2]> dose:2, supp:VC
+
+

Examples

+

+# Split a data frame
+# :::::::::::::::::::::::::::::::::::::::::::::::::
+# Create a grouped data
+res <- ToothGrowth %>%
+  df_split_by(dose, supp)
+res
+#> # A tibble: 6 × 4
+#>   supp   dose data              label            
+#>   <fct> <dbl> <list>            <fct>            
+#> 1 VC      0.5 <tibble [10 × 2]> dose:0.5, supp:OJ
+#> 2 VC      1   <tibble [10 × 2]> dose:0.5, supp:VC
+#> 3 VC      2   <tibble [10 × 2]> dose:1, supp:OJ  
+#> 4 OJ      0.5 <tibble [10 × 2]> dose:1, supp:VC  
+#> 5 OJ      1   <tibble [10 × 2]> dose:2, supp:OJ  
+#> 6 OJ      2   <tibble [10 × 2]> dose:2, supp:VC  
+
+# Show subsets
+res$data
+#> [[1]]
+#> # A tibble: 10 × 2
+#>      len label            
+#>    <dbl> <fct>            
+#>  1   4.2 dose:0.5, supp:OJ
+#>  2  11.5 dose:0.5, supp:OJ
+#>  3   7.3 dose:0.5, supp:OJ
+#>  4   5.8 dose:0.5, supp:OJ
+#>  5   6.4 dose:0.5, supp:OJ
+#>  6  10   dose:0.5, supp:OJ
+#>  7  11.2 dose:0.5, supp:OJ
+#>  8  11.2 dose:0.5, supp:OJ
+#>  9   5.2 dose:0.5, supp:OJ
+#> 10   7   dose:0.5, supp:OJ
+#> 
+#> [[2]]
+#> # A tibble: 10 × 2
+#>      len label            
+#>    <dbl> <fct>            
+#>  1  16.5 dose:0.5, supp:VC
+#>  2  16.5 dose:0.5, supp:VC
+#>  3  15.2 dose:0.5, supp:VC
+#>  4  17.3 dose:0.5, supp:VC
+#>  5  22.5 dose:0.5, supp:VC
+#>  6  17.3 dose:0.5, supp:VC
+#>  7  13.6 dose:0.5, supp:VC
+#>  8  14.5 dose:0.5, supp:VC
+#>  9  18.8 dose:0.5, supp:VC
+#> 10  15.5 dose:0.5, supp:VC
+#> 
+#> [[3]]
+#> # A tibble: 10 × 2
+#>      len label          
+#>    <dbl> <fct>          
+#>  1  23.6 dose:1, supp:OJ
+#>  2  18.5 dose:1, supp:OJ
+#>  3  33.9 dose:1, supp:OJ
+#>  4  25.5 dose:1, supp:OJ
+#>  5  26.4 dose:1, supp:OJ
+#>  6  32.5 dose:1, supp:OJ
+#>  7  26.7 dose:1, supp:OJ
+#>  8  21.5 dose:1, supp:OJ
+#>  9  23.3 dose:1, supp:OJ
+#> 10  29.5 dose:1, supp:OJ
+#> 
+#> [[4]]
+#> # A tibble: 10 × 2
+#>      len label          
+#>    <dbl> <fct>          
+#>  1  15.2 dose:1, supp:VC
+#>  2  21.5 dose:1, supp:VC
+#>  3  17.6 dose:1, supp:VC
+#>  4   9.7 dose:1, supp:VC
+#>  5  14.5 dose:1, supp:VC
+#>  6  10   dose:1, supp:VC
+#>  7   8.2 dose:1, supp:VC
+#>  8   9.4 dose:1, supp:VC
+#>  9  16.5 dose:1, supp:VC
+#> 10   9.7 dose:1, supp:VC
+#> 
+#> [[5]]
+#> # A tibble: 10 × 2
+#>      len label          
+#>    <dbl> <fct>          
+#>  1  19.7 dose:2, supp:OJ
+#>  2  23.3 dose:2, supp:OJ
+#>  3  23.6 dose:2, supp:OJ
+#>  4  26.4 dose:2, supp:OJ
+#>  5  20   dose:2, supp:OJ
+#>  6  25.2 dose:2, supp:OJ
+#>  7  25.8 dose:2, supp:OJ
+#>  8  21.2 dose:2, supp:OJ
+#>  9  14.5 dose:2, supp:OJ
+#> 10  27.3 dose:2, supp:OJ
+#> 
+#> [[6]]
+#> # A tibble: 10 × 2
+#>      len label          
+#>    <dbl> <fct>          
+#>  1  25.5 dose:2, supp:VC
+#>  2  26.4 dose:2, supp:VC
+#>  3  22.4 dose:2, supp:VC
+#>  4  24.5 dose:2, supp:VC
+#>  5  24.8 dose:2, supp:VC
+#>  6  30.9 dose:2, supp:VC
+#>  7  26.4 dose:2, supp:VC
+#>  8  27.3 dose:2, supp:VC
+#>  9  29.4 dose:2, supp:VC
+#> 10  23   dose:2, supp:VC
+#> 
+
+# Add panel/subset labels
+res <- ToothGrowth %>%
+  df_split_by(dose, supp)
+res
+#> # A tibble: 6 × 4
+#>   supp   dose data              label            
+#>   <fct> <dbl> <list>            <fct>            
+#> 1 VC      0.5 <tibble [10 × 2]> dose:0.5, supp:OJ
+#> 2 VC      1   <tibble [10 × 2]> dose:0.5, supp:VC
+#> 3 VC      2   <tibble [10 × 2]> dose:1, supp:OJ  
+#> 4 OJ      0.5 <tibble [10 × 2]> dose:1, supp:VC  
+#> 5 OJ      1   <tibble [10 × 2]> dose:2, supp:OJ  
+#> 6 OJ      2   <tibble [10 × 2]> dose:2, supp:VC  
+
+
+
-
- +
- - + + diff --git a/docs/reference/df_unite.html b/docs/reference/df_unite.html index dbe1a60..49cd7fe 100644 --- a/docs/reference/df_unite.html +++ b/docs/reference/df_unite.html @@ -1,71 +1,14 @@ - - - - - - - -Unite Multiple Columns into One — df_unite • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Unite Multiple Columns into One — df_unite • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Paste together multiple columns into one. Wrapper arround - unite() that supports standard and non standard + unite() that supports standard and non standard evaluation.

-
df_unite(data, col, ..., vars = NULL, sep = "_", remove = TRUE, na.rm = FALSE)
-
-df_unite_factors(
-  data,
-  col,
-  ...,
-  vars = NULL,
-  sep = "_",
-  remove = TRUE,
-  na.rm = FALSE
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data frame

col

the name of the new column as a string or a symbol.

...

a selection of columns. One or more unquoted expressions (or variable names) separated by -commas.

vars

a character vector containing the column names of interest.

sep

Separator to use between values.

remove

If TRUE, remove input columns from output data frame.

na.rm

If TRUE, missing values will be remove prior to uniting -each value.

- -

Functions

+
+
df_unite(data, col, ..., vars = NULL, sep = "_", remove = TRUE, na.rm = FALSE)
+
+df_unite_factors(
+  data,
+  col,
+  ...,
+  vars = NULL,
+  sep = "_",
+  remove = TRUE,
+  na.rm = FALSE
+)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
col
+

the name of the new column as a string or a symbol.

+ + +
...
+

a selection of columns. One or more unquoted expressions (or variable names) separated by +commas.

+ +
vars
+

a character vector containing the column names of interest.

+ + +
sep
+

Separator to use between values.

+ + +
remove
+

If TRUE, remove input columns from output data frame.

+ + +
na.rm
+

If TRUE, missing values will be removed prior to uniting +each value.

+ +
+
+

Functions

-
    -
  • df_unite: Unite multiple columns into one.

  • -
  • df_unite_factors: Unite factor columns. First, order factors levels then +

    • df_unite(): Unite multiple columns into one.

    • +
    • df_unite_factors(): Unite factor columns. First, order factors levels then merge them into one column. The output column is a factor.

    • -
    - -

    Examples

    -
    # Non standard evaluation -head(ToothGrowth) %>% - df_unite(col = "dose_supp", dose, supp)
    #> len dose_supp -#> 1 4.2 0.5_VC -#> 2 11.5 0.5_VC -#> 3 7.3 0.5_VC -#> 4 5.8 0.5_VC -#> 5 6.4 0.5_VC -#> 6 10.0 0.5_VC
    -# Standard evaluation -head(ToothGrowth) %>% - df_unite(col = "dose_supp", vars = c("dose", "supp"))
    #> len dose_supp -#> 1 4.2 0.5_VC -#> 2 11.5 0.5_VC -#> 3 7.3 0.5_VC -#> 4 5.8 0.5_VC -#> 5 6.4 0.5_VC -#> 6 10.0 0.5_VC
    +
+ +
+

Examples

+
# Non standard evaluation
+head(ToothGrowth) %>%
+ df_unite(col = "dose_supp", dose, supp)
+#>    len dose_supp
+#> 1  4.2    0.5_VC
+#> 2 11.5    0.5_VC
+#> 3  7.3    0.5_VC
+#> 4  5.8    0.5_VC
+#> 5  6.4    0.5_VC
+#> 6 10.0    0.5_VC
+
+# Standard evaluation
+head(ToothGrowth) %>%
+ df_unite(col = "dose_supp", vars = c("dose", "supp"))
+#>    len dose_supp
+#> 1  4.2    0.5_VC
+#> 2 11.5    0.5_VC
+#> 3  7.3    0.5_VC
+#> 4  5.8    0.5_VC
+#> 5  6.4    0.5_VC
+#> 6 10.0    0.5_VC
+
+
+
-
- +
- - + + diff --git a/docs/reference/doo.html b/docs/reference/doo.html index d7f7db7..8d3eaa1 100644 --- a/docs/reference/doo.html +++ b/docs/reference/doo.html @@ -1,75 +1,18 @@ - - - - - - - -Alternative to dplyr::do for Doing Anything — doo • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alternative to dplyr::do for Doing Anything — doo • rstatix + + - - - - -
-
- -
- -
+
@@ -134,153 +64,166 @@

Alternative to dplyr::do for Doing Anything

containing the results for group combinations.

-
doo(data, .f, ..., result = ".results.")
+
+
doo(data, .f, ..., result = ".results.")
+
+ +
+

Arguments

+
data
+

a (grouped) data frame

+ + +
.f
+

A function, formula, or atomic vector. For example +~t.test(len ~ supp, data = .).

+ + +
...
+

Additional arguments passed on to .f

-

Arguments

- - - - - - - - - - - - - - - - - - -
data

a (grouped) data frame

.f

A function, formula, or atomic vector. For example -~t.test(len ~ supp, data = .).

...

Additional arguments passed on to .f

result

the column name to hold the results. Default is ".results.".

-

Value

+
result
+

the column name to hold the results. Default is ".results.".

-

a data frame

+
+
+

Value

+ -

Examples

-
# Custom function -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -stat_test <- function(data, formula){ - t.test(formula, data) %>% - tidy() -} -# Example 1: pipe-friendly stat_test(). -# Two possibilities of usage are available -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Use this -ToothGrowth %>% - group_by(dose) %>% - doo(~stat_test(data =., len ~ supp))
#> # A tibble: 3 x 11 -#> dose estimate estimate1 estimate2 statistic p.value parameter conf.low -#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 0.5 5.25 13.2 7.98 3.17 0.00636 15.0 1.72 -#> 2 1 5.93 22.7 16.8 4.03 0.00104 15.4 2.80 -#> 3 2 -0.0800 26.1 26.1 -0.0461 0.964 14.0 -3.80 -#> # … with 3 more variables: conf.high <dbl>, method <chr>, alternative <chr>
-# Or this -ToothGrowth %>% - group_by(dose) %>% - doo(stat_test, len ~ supp)
#> # A tibble: 3 x 11 -#> dose estimate estimate1 estimate2 statistic p.value parameter conf.low -#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 0.5 5.25 13.2 7.98 3.17 0.00636 15.0 1.72 -#> 2 1 5.93 22.7 16.8 4.03 0.00104 15.4 2.80 -#> 3 2 -0.0800 26.1 26.1 -0.0461 0.964 14.0 -3.80 -#> # … with 3 more variables: conf.high <dbl>, method <chr>, alternative <chr>
-# Example 2: R base function t.test() (not pipe friendly) -# One possibility of usage -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -comparisons <- ToothGrowth %>% - group_by(dose) %>% - doo(~t.test(len ~ supp, data =.)) -comparisons
#> # A tibble: 3 x 2 -#> dose .results. -#> <dbl> <list> -#> 1 0.5 <htest> -#> 2 1 <htest> -#> 3 2 <htest>
comparisons$.results.
#> [[1]] -#> -#> Welch Two Sample t-test -#> -#> data: len by supp -#> t = 3.1697, df = 14.969, p-value = 0.006359 -#> alternative hypothesis: true difference in means is not equal to 0 -#> 95 percent confidence interval: -#> 1.719057 8.780943 -#> sample estimates: -#> mean in group OJ mean in group VC -#> 13.23 7.98 -#> -#> -#> [[2]] -#> -#> Welch Two Sample t-test -#> -#> data: len by supp -#> t = 4.0328, df = 15.358, p-value = 0.001038 -#> alternative hypothesis: true difference in means is not equal to 0 -#> 95 percent confidence interval: -#> 2.802148 9.057852 -#> sample estimates: -#> mean in group OJ mean in group VC -#> 22.70 16.77 -#> -#> -#> [[3]] -#> -#> Welch Two Sample t-test -#> -#> data: len by supp -#> t = -0.046136, df = 14.04, p-value = 0.9639 -#> alternative hypothesis: true difference in means is not equal to 0 -#> 95 percent confidence interval: -#> -3.79807 3.63807 -#> sample estimates: -#> mean in group OJ mean in group VC -#> 26.06 26.14 -#> -#>
-# Example 3: R base function combined with tidy() -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ToothGrowth %>% - group_by(dose) %>% - doo(~t.test(len ~ supp, data =.) %>% tidy())
#> # A tibble: 3 x 11 -#> dose estimate estimate1 estimate2 statistic p.value parameter conf.low -#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 0.5 5.25 13.2 7.98 3.17 0.00636 15.0 1.72 -#> 2 1 5.93 22.7 16.8 4.03 0.00104 15.4 2.80 -#> 3 2 -0.0800 26.1 26.1 -0.0461 0.964 14.0 -3.80 -#> # … with 3 more variables: conf.high <dbl>, method <chr>, alternative <chr>
+

a data frame

+
+ +
+

Examples

+
# Custom function
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+stat_test <- function(data, formula){
+  t.test(formula, data) %>%
+    tidy()
+}
+# Example 1: pipe-friendly stat_test().
+# Two possibilities of usage are available
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Use this
+ToothGrowth %>%
+  group_by(dose) %>%
+  doo(~stat_test(data =., len ~ supp))
+#> # A tibble: 3 × 11
+#>    dose estimate estima…¹ estim…² stati…³ p.value param…⁴ conf.…⁵ conf.…⁶ method
+#>   <dbl>    <dbl>    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl> <chr> 
+#> 1   0.5   5.25       13.2    7.98  3.17   0.00636    15.0    1.72    8.78 Welch…
+#> 2   1     5.93       22.7   16.8   4.03   0.00104    15.4    2.80    9.06 Welch…
+#> 3   2    -0.0800     26.1   26.1  -0.0461 0.964      14.0   -3.80    3.64 Welch…
+#> # … with 1 more variable: alternative <chr>, and abbreviated variable names
+#> #   ¹​estimate1, ²​estimate2, ³​statistic, ⁴​parameter, ⁵​conf.low, ⁶​conf.high
+
+# Or this
+ToothGrowth %>%
+  group_by(dose) %>%
+  doo(stat_test, len ~ supp)
+#> # A tibble: 3 × 11
+#>    dose estimate estima…¹ estim…² stati…³ p.value param…⁴ conf.…⁵ conf.…⁶ method
+#>   <dbl>    <dbl>    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl> <chr> 
+#> 1   0.5   5.25       13.2    7.98  3.17   0.00636    15.0    1.72    8.78 Welch…
+#> 2   1     5.93       22.7   16.8   4.03   0.00104    15.4    2.80    9.06 Welch…
+#> 3   2    -0.0800     26.1   26.1  -0.0461 0.964      14.0   -3.80    3.64 Welch…
+#> # … with 1 more variable: alternative <chr>, and abbreviated variable names
+#> #   ¹​estimate1, ²​estimate2, ³​statistic, ⁴​parameter, ⁵​conf.low, ⁶​conf.high
+
+# Example 2: R base function t.test() (not pipe friendly)
+# One possibility of usage
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+comparisons <- ToothGrowth %>%
+   group_by(dose) %>%
+   doo(~t.test(len ~ supp, data =.))
+comparisons
+#> # A tibble: 3 × 2
+#>    dose .results.
+#>   <dbl> <list>   
+#> 1   0.5 <htest>  
+#> 2   1   <htest>  
+#> 3   2   <htest>  
+comparisons$.results.
+#> [[1]]
+#> 
+#> 	Welch Two Sample t-test
+#> 
+#> data:  len by supp
+#> t = 3.1697, df = 14.969, p-value = 0.006359
+#> alternative hypothesis: true difference in means is not equal to 0
+#> 95 percent confidence interval:
+#>  1.719057 8.780943
+#> sample estimates:
+#> mean in group OJ mean in group VC 
+#>            13.23             7.98 
+#> 
+#> 
+#> [[2]]
+#> 
+#> 	Welch Two Sample t-test
+#> 
+#> data:  len by supp
+#> t = 4.0328, df = 15.358, p-value = 0.001038
+#> alternative hypothesis: true difference in means is not equal to 0
+#> 95 percent confidence interval:
+#>  2.802148 9.057852
+#> sample estimates:
+#> mean in group OJ mean in group VC 
+#>            22.70            16.77 
+#> 
+#> 
+#> [[3]]
+#> 
+#> 	Welch Two Sample t-test
+#> 
+#> data:  len by supp
+#> t = -0.046136, df = 14.04, p-value = 0.9639
+#> alternative hypothesis: true difference in means is not equal to 0
+#> 95 percent confidence interval:
+#>  -3.79807  3.63807
+#> sample estimates:
+#> mean in group OJ mean in group VC 
+#>            26.06            26.14 
+#> 
+#> 
+
+# Example 3: R base function combined with tidy()
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ToothGrowth %>%
+   group_by(dose) %>%
+   doo(~t.test(len ~ supp, data =.) %>% tidy())
+#> # A tibble: 3 × 11
+#>    dose estimate estima…¹ estim…² stati…³ p.value param…⁴ conf.…⁵ conf.…⁶ method
+#>   <dbl>    <dbl>    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl> <chr> 
+#> 1   0.5   5.25       13.2    7.98  3.17   0.00636    15.0    1.72    8.78 Welch…
+#> 2   1     5.93       22.7   16.8   4.03   0.00104    15.4    2.80    9.06 Welch…
+#> 3   2    -0.0800     26.1   26.1  -0.0461 0.964      14.0   -3.80    3.64 Welch…
+#> # … with 1 more variable: alternative <chr>, and abbreviated variable names
+#> #   ¹​estimate1, ²​estimate2, ³​statistic, ⁴​parameter, ⁵​conf.low, ⁶​conf.high
+
+
+
-
- +
- - + + diff --git a/docs/reference/dunn_test.html b/docs/reference/dunn_test.html index 242035c..b1d02b9 100644 --- a/docs/reference/dunn_test.html +++ b/docs/reference/dunn_test.html @@ -1,48 +1,5 @@ - - - - - - - -Dunn's Test of Multiple Comparisons — dunn_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Dunn's Test of Multiple Comparisons — dunn_test • rstatix - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -135,43 +65,43 @@

Dunn's Test of Multiple Comparisons

and GraphPad. This is not the case for some other R packages (dunn.test and jamovi), where the default is to perform one-sided test. This discrepancy is documented at - https://github.com/kassambara/rstatix/issues/50.

+ https://github.com/kassambara/rstatix/issues/50.

+
+ +
+
dunn_test(data, formula, p.adjust.method = "holm", detailed = FALSE)
-
dunn_test(data, formula, p.adjust.method = "holm", detailed = FALSE)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

p.adjust.method

method to adjust p values for multiple comparisons. +formula = TP53 ~ cancer_group.

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

- -

Value

- -

return a data frame with some of the following columns:

    -
  • .y.: the y (outcome) variable used in the test.

  • +want to adjust the p value (not recommended), use p.adjust.method = "none".

    + + +
    detailed
    +

    logical value. Default is FALSE. If TRUE, a detailed result is +shown.

    + +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y (outcome) variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n1,n2: Sample counts.

  • estimate: mean ranks difference.

  • @@ -186,12 +116,11 @@

    Value

    groups.

  • p.signif, p.adj.signif: the significance level of p-values and adjusted p-values, respectively.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Details

- +
+
+

Details

DunnTest performs the post hoc pairwise multiple comparisons procedure appropriate to follow up a Kruskal-Wallis test, which is a non-parametric analog of the one-way ANOVA. The Wilcoxon rank sum test, @@ -200,56 +129,61 @@

Details fails to retain the dependent ranking that produced the Kruskal-Wallis test statistic, and (2) it does not incorporate the pooled variance estimate implied by the null hypothesis of the Kruskal-Wallis test.

-

References

- +
+
+

References

Dunn, O. J. (1964) Multiple comparisons using rank sums Technometrics, 6(3):241-252.

+
-

Examples

-
# Simple test -ToothGrowth %>% dunn_test(len ~ dose)
#> # A tibble: 3 x 9 -#> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 3.55 3.78e- 4 7.56e- 4 *** -#> 2 len 0.5 2 20 20 6.36 1.98e-10 5.95e-10 **** -#> 3 len 1 2 20 20 2.81 4.99e- 3 4.99e- 3 **
-# Grouped data -ToothGrowth %>% - group_by(supp) %>% - dunn_test(len ~ dose)
#> # A tibble: 6 x 10 -#> supp .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif -#> * <fct> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> -#> 1 OJ len 0.5 1 10 10 2.83 4.59e-3 9.18e-3 ** -#> 2 OJ len 0.5 2 10 10 4.22 2.45e-5 7.34e-5 **** -#> 3 OJ len 1 2 10 10 1.39 1.66e-1 1.66e-1 ns -#> 4 VC len 0.5 1 10 10 2.62 8.87e-3 1.77e-2 * -#> 5 VC len 0.5 2 10 10 5.01 5.57e-7 1.67e-6 **** -#> 6 VC len 1 2 10 10 2.39 1.69e-2 1.77e-2 *
+
+

Examples

+
# Simple test
+ToothGrowth %>% dunn_test(len ~ dose)
+#> # A tibble: 3 × 9
+#>   .y.   group1 group2    n1    n2 statistic        p    p.adj p.adj.signif
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl>    <dbl>    <dbl> <chr>       
+#> 1 len   0.5    1         20    20      3.55 3.78e- 4 7.56e- 4 ***         
+#> 2 len   0.5    2         20    20      6.36 1.98e-10 5.95e-10 ****        
+#> 3 len   1      2         20    20      2.81 4.99e- 3 4.99e- 3 **          
+
+# Grouped data
+ToothGrowth %>%
+  group_by(supp) %>%
+  dunn_test(len ~ dose)
+#> # A tibble: 6 × 10
+#>   supp  .y.   group1 group2    n1    n2 statistic           p      p.adj p.adj…¹
+#> * <fct> <chr> <chr>  <chr>  <int> <int>     <dbl>       <dbl>      <dbl> <chr>  
+#> 1 OJ    len   0.5    1         10    10      2.83 0.00459     0.00918    **     
+#> 2 OJ    len   0.5    2         10    10      4.22 0.0000245   0.0000734  ****   
+#> 3 OJ    len   1      2         10    10      1.39 0.166       0.166      ns     
+#> 4 VC    len   0.5    1         10    10      2.62 0.00887     0.0177     *      
+#> 5 VC    len   0.5    2         10    10      5.01 0.000000557 0.00000167 ****   
+#> 6 VC    len   1      2         10    10      2.39 0.0169      0.0177     *      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+
-
- +
- - + + diff --git a/docs/reference/emmeans_test.html b/docs/reference/emmeans_test.html index 2ed6cd5..8a61d68 100644 --- a/docs/reference/emmeans_test.html +++ b/docs/reference/emmeans_test.html @@ -1,73 +1,16 @@ - - - - - - - -Pairwise Comparisons of Estimated Marginal Means — emmeans_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Pairwise Comparisons of Estimated Marginal Means — emmeans_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -130,85 +60,85 @@

Pairwise Comparisons of Estimated Marginal Means

analyses following ANOVA/ANCOVA tests.

-
emmeans_test(
-  data,
-  formula,
-  covariate = NULL,
-  ref.group = NULL,
-  comparisons = NULL,
-  p.adjust.method = "bonferroni",
-  conf.level = 0.95,
-  model = NULL,
-  detailed = FALSE
-)
-
-get_emmeans(emmeans.test)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
emmeans_test(
+  data,
+  formula,
+  covariate = NULL,
+  ref.group = NULL,
+  comparisons = NULL,
+  p.adjust.method = "bonferroni",
+  conf.level = 0.95,
+  model = NULL,
+  detailed = FALSE
+)
+
+get_emmeans(emmeans.test)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

covariate

(optional) covariate names (for ANCOVA)

ref.group

a character string specifying the reference group. If +formula = TP53 ~ cancer_group.

+ + +
covariate
+

(optional) covariate names (for ANCOVA)

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).

If ref.group = "all", pairwise two sample tests are performed for - comparing each grouping variable levels against all (i.e. basemean).

comparisons

A list of length-2 vectors specifying the groups of + comparing each grouping variable levels against all (i.e. basemean).

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

p.adjust.method

method to adjust p values for multiple comparisons. +"C"))

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

conf.level

confidence level of the interval.

model

a fitted-model objects such as the result of a call to -lm(), from which the overall degrees of -freedom are to be calculated.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

emmeans.test

an object of class emmeans_test.

- -

Value

- -

return a data frame with some the following columns:

    -
  • .y.: the y variable used in the test.

  • +want to adjust the p value (not recommended), use p.adjust.method = "none".

    + + +
    conf.level
    +

    confidence level of the interval.

    + + +
    model
    +

    a fitted-model objects such as the result of a call to +lm(), from which the overall degrees of +freedom are to be calculated.

    + + +
    detailed
    +

    logical value. Default is FALSE. If TRUE, a detailed result is +shown.

    + + +
    emmeans.test
    +

    an object of class emmeans_test.

    + +
+
+

Value

+ + +

return a data frame with some the following columns:

  • .y.: the y variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • statistic: Test @@ -225,85 +155,88 @@

    Value

    marginal means).

  • conf.low,conf.high: Lower and upper bound on a confidence interval of the estimate.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments. It has also an attribute named "emmeans", a data frame containing the groups emmeans.

-

Functions

- +
+
+

Functions

-
    -
  • get_emmeans: returns the estimated marginal means from an object of class emmeans_test

  • -
- -

Examples

-
# Data preparation -df <- ToothGrowth -df$dose <- as.factor(df$dose) - -# Pairwise comparisons -res <- df %>% - group_by(supp) %>% - emmeans_test(len ~ dose, p.adjust.method = "bonferroni") -res
#> # A tibble: 6 x 10 -#> supp term .y. group1 group2 df statistic p p.adj p.adj.signif -#> * <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 OJ dose len 0.5 1 54 -5.83 3.18e- 7 9.53e- 7 **** -#> 2 OJ dose len 0.5 2 54 -7.90 1.43e-10 4.29e-10 **** -#> 3 OJ dose len 1 2 54 -2.07 4.34e- 2 1.30e- 1 ns -#> 4 VC dose len 0.5 1 54 -5.41 1.46e- 6 4.39e- 6 **** -#> 5 VC dose len 0.5 2 54 -11.2 1.13e-15 3.39e-15 **** -#> 6 VC dose len 1 2 54 -5.77 3.98e- 7 1.19e- 6 ****
-# Display estimated marginal means -attr(res, "emmeans")
#> # A tibble: 6 x 8 -#> supp dose emmean se df conf.low conf.high method -#> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 OJ 0.5 13.2 1.15 54 10.9 15.5 Emmeans test -#> 2 OJ 1 22.7 1.15 54 20.4 25.0 Emmeans test -#> 3 OJ 2 26.1 1.15 54 23.8 28.4 Emmeans test -#> 4 VC 0.5 7.98 1.15 54 5.68 10.3 Emmeans test -#> 5 VC 1 16.8 1.15 54 14.5 19.1 Emmeans test -#> 6 VC 2 26.1 1.15 54 23.8 28.4 Emmeans test
-# Show details -df %>% - group_by(supp) %>% - emmeans_test(len ~ dose, p.adjust.method = "bonferroni", detailed = TRUE)
#> # A tibble: 6 x 15 -#> supp term .y. group1 group2 null.value estimate se df conf.low -#> * <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 OJ dose len 0.5 1 0 -9.47 1.62 54 -12.7 -#> 2 OJ dose len 0.5 2 0 -12.8 1.62 54 -16.1 -#> 3 OJ dose len 1 2 0 -3.36 1.62 54 -6.62 -#> 4 VC dose len 0.5 1 0 -8.79 1.62 54 -12.0 -#> 5 VC dose len 0.5 2 0 -18.2 1.62 54 -21.4 -#> 6 VC dose len 1 2 0 -9.37 1.62 54 -12.6 -#> # … with 5 more variables: conf.high <dbl>, statistic <dbl>, p <dbl>, -#> # p.adj <dbl>, p.adj.signif <chr>
+
  • get_emmeans(): returns the estimated marginal means from an object of class emmeans_test

  • +
+ +
+

Examples

+
# Data preparation
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+
+# Pairwise comparisons
+res <- df %>%
+ group_by(supp) %>%
+ emmeans_test(len ~ dose, p.adjust.method = "bonferroni")
+res
+#> # A tibble: 6 × 10
+#>   supp  term  .y.   group1 group2    df statistic        p    p.adj p.adj.signif
+#> * <fct> <chr> <chr> <chr>  <chr>  <dbl>     <dbl>    <dbl>    <dbl> <chr>       
+#> 1 OJ    dose  len   0.5    1         54     -5.83 3.18e- 7 9.53e- 7 ****        
+#> 2 OJ    dose  len   0.5    2         54     -7.90 1.43e-10 4.29e-10 ****        
+#> 3 OJ    dose  len   1      2         54     -2.07 4.34e- 2 1.30e- 1 ns          
+#> 4 VC    dose  len   0.5    1         54     -5.41 1.46e- 6 4.39e- 6 ****        
+#> 5 VC    dose  len   0.5    2         54    -11.2  1.13e-15 3.39e-15 ****        
+#> 6 VC    dose  len   1      2         54     -5.77 3.98e- 7 1.19e- 6 ****        
+
+# Display estimated marginal means
+attr(res, "emmeans")
+#> # A tibble: 6 × 8
+#>   supp  dose  emmean    se    df conf.low conf.high method      
+#>   <fct> <fct>  <dbl> <dbl> <dbl>    <dbl>     <dbl> <chr>       
+#> 1 OJ    0.5    13.2   1.15    54    10.9       15.5 Emmeans test
+#> 2 OJ    1      22.7   1.15    54    20.4       25.0 Emmeans test
+#> 3 OJ    2      26.1   1.15    54    23.8       28.4 Emmeans test
+#> 4 VC    0.5     7.98  1.15    54     5.68      10.3 Emmeans test
+#> 5 VC    1      16.8   1.15    54    14.5       19.1 Emmeans test
+#> 6 VC    2      26.1   1.15    54    23.8       28.4 Emmeans test
+
+# Show details
+df %>%
+ group_by(supp) %>%
+ emmeans_test(len ~ dose, p.adjust.method = "bonferroni", detailed = TRUE)
+#> # A tibble: 6 × 15
+#>   supp  term  .y.   group1 group2 null.value estim…¹    se    df conf.…² conf.…³
+#> * <fct> <chr> <chr> <chr>  <chr>       <dbl>   <dbl> <dbl> <dbl>   <dbl>   <dbl>
+#> 1 OJ    dose  len   0.5    1               0   -9.47  1.62    54  -12.7   -6.21 
+#> 2 OJ    dose  len   0.5    2               0  -12.8   1.62    54  -16.1   -9.57 
+#> 3 OJ    dose  len   1      2               0   -3.36  1.62    54   -6.62  -0.104
+#> 4 VC    dose  len   0.5    1               0   -8.79  1.62    54  -12.0   -5.53 
+#> 5 VC    dose  len   0.5    2               0  -18.2   1.62    54  -21.4  -14.9  
+#> 6 VC    dose  len   1      2               0   -9.37  1.62    54  -12.6   -6.11 
+#> # … with 4 more variables: statistic <dbl>, p <dbl>, p.adj <dbl>,
+#> #   p.adj.signif <chr>, and abbreviated variable names ¹​estimate, ²​conf.low,
+#> #   ³​conf.high
+
+
+
-
- +
- - + + diff --git a/docs/reference/eta_squared.html b/docs/reference/eta_squared.html index f380fce..d58d0cf 100644 --- a/docs/reference/eta_squared.html +++ b/docs/reference/eta_squared.html @@ -1,70 +1,13 @@ - - - - - - - -Effect Size for ANOVA — eta_squared • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Effect Size for ANOVA — eta_squared • rstatix - - - - + + -
-
- -
- -
+
@@ -124,73 +54,78 @@

Effect Size for ANOVA

ANOVA model.

-
eta_squared(model)
-
-partial_eta_squared(model)
- -

Arguments

- - - - - - -
model

an object of class aov or anova.

+
+
eta_squared(model)
+
+partial_eta_squared(model)
+
-

Value

+
+

Arguments

+
model
+

an object of class aov or anova.

-

a numeric vector with the effect size statistics

-

Functions

+
+
+

Value

+ +

a numeric vector with the effect size statistics

+
+
+

Functions

-
    -
  • eta_squared: compute eta squared

  • -
  • partial_eta_squared: compute partial eta squared.

  • -
- -

Examples

-
# Data preparation -df <- ToothGrowth -df$dose <- as.factor(df$dose) - -# Compute ANOVA -res.aov <- aov(len ~ supp*dose, data = df) -summary(res.aov)
#> Df Sum Sq Mean Sq F value Pr(>F) -#> supp 1 205.4 205.4 15.572 0.000231 *** -#> dose 2 2426.4 1213.2 92.000 < 2e-16 *** -#> supp:dose 2 108.3 54.2 4.107 0.021860 * -#> Residuals 54 712.1 13.2 -#> --- -#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
-# Effect size -eta_squared(res.aov)
#> supp dose supp:dose -#> 0.05948365 0.70286419 0.03137672
partial_eta_squared(res.aov)
#> supp dose supp:dose -#> 0.2238254 0.7731092 0.1320279
+
  • eta_squared(): compute eta squared

  • +
  • partial_eta_squared(): compute partial eta squared.

  • +
+ +
+

Examples

+
# Data preparation
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+
+# Compute ANOVA
+res.aov <- aov(len ~ supp*dose, data = df)
+summary(res.aov)
+#>             Df Sum Sq Mean Sq F value   Pr(>F)    
+#> supp         1  205.4   205.4  15.572 0.000231 ***
+#> dose         2 2426.4  1213.2  92.000  < 2e-16 ***
+#> supp:dose    2  108.3    54.2   4.107 0.021860 *  
+#> Residuals   54  712.1    13.2                     
+#> ---
+#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
+
+# Effect size
+eta_squared(res.aov)
+#>       supp       dose  supp:dose 
+#> 0.05948365 0.70286419 0.03137672 
+partial_eta_squared(res.aov)
+#>      supp      dose supp:dose 
+#> 0.2238254 0.7731092 0.1320279 
+
+
+
-
- +
- - + + diff --git a/docs/reference/factorial_design.html b/docs/reference/factorial_design.html index a22c058..94fd23f 100644 --- a/docs/reference/factorial_design.html +++ b/docs/reference/factorial_design.html @@ -1,72 +1,15 @@ - - - - - - - -Build Factorial Designs for ANOVA — factorial_design • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Build Factorial Designs for ANOVA — factorial_design • rstatix - - - - - - - - - - + + - - - -
-
- -
- -
+

Provides helper functions to build factorial design for easily - computing ANOVA using the Anova() function. This might be + computing ANOVA using the Anova() function. This might be very useful for repeated measures ANOVA, which is hard to set up with the car package.

-
factorial_design(data, dv, wid, between, within, covariate)
+
+
factorial_design(data, dv, wid, between, within, covariate)
+
+ +
+

Arguments

+
data
+

a data frame containing the variables

+ + +
dv
+

(numeric) dependent variable name.

+ + +
wid
+

(factor) column name containing individuals/subjects identifier. +Should be unique per individual.

+ -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data frame containing the variables

dv

(numeric) dependent variable name.

wid

(factor) column name containing individuals/subjects identifier. -Should be unique per individual.

between

(optional) between-subject factor variables.

within

(optional) within-subjects factor variables

covariate

(optional) covariate names (for ANCOVA)

+
between
+

(optional) between-subject factor variables.

-

Value

-

a list with the following components:

    -
  • the +

    within
    +

    (optional) within-subjects factor variables

    + + +
    covariate
    +

    (optional) covariate names (for ANCOVA)

    + +
+
+

Value

+ + +

a list with the following components:

  • the specified arguments: dv, wid, between, within

  • data: the original data (long format) or independent ANOVA. The wide format is @@ -182,238 +112,253 @@

    Value

    model. Can be either in a long format (i.e., the original data for independent measures ANOVA) or in a wide format (case of repeated measures ANOVA).

  • model: the lm model

  • -
- -

See also

- - +
+
+

See also

+ +
+
+

Author

+

Alboukadel Kassambara, alboukadel.kassambara@gmail.com

+
-

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth -head(df)
#> len supp dose -#> 1 4.2 VC 0.5 -#> 2 11.5 VC 0.5 -#> 3 7.3 VC 0.5 -#> 4 5.8 VC 0.5 -#> 5 6.4 VC 0.5 -#> 6 10.0 VC 0.5
-# Repeated measures designs -#::::::::::::::::::::::::::::::::::::::::: -# Prepare the data -df$id <- rep(1:10, 6) # Add individuals id -head(df)
#> len supp dose id -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 3 -#> 4 5.8 VC 0.5 4 -#> 5 6.4 VC 0.5 5 -#> 6 10.0 VC 0.5 6
# Build factorial designs -design <- factorial_design(df, dv = len, wid = id, within = c(supp, dose)) -design
#> $dv -#> [1] "len" -#> -#> $wid -#> [1] "id" -#> -#> $within -#> [1] "supp" "dose" -#> -#> $data -#> # A tibble: 60 x 4 -#> len supp dose id -#> <dbl> <fct> <fct> <fct> -#> 1 4.2 VC X0.5 1 -#> 2 11.5 VC X0.5 2 -#> 3 7.3 VC X0.5 3 -#> 4 5.8 VC X0.5 4 -#> 5 6.4 VC X0.5 5 -#> 6 10 VC X0.5 6 -#> 7 11.2 VC X0.5 7 -#> 8 11.2 VC X0.5 8 -#> 9 5.2 VC X0.5 9 -#> 10 7 VC X0.5 10 -#> # … with 50 more rows -#> -#> $idata -#> supp dose -#> 1 OJ X0.5 -#> 2 OJ X1 -#> 3 OJ X2 -#> 4 VC X0.5 -#> 5 VC X1 -#> 6 VC X2 -#> -#> $idesign -#> ~supp * dose -#> <environment: 0x7fdfe6df9fc8> -#> -#> $lm_data -#> # A tibble: 10 x 7 -#> id OJ_X0.5 OJ_X1 OJ_X2 VC_X0.5 VC_X1 VC_X2 -#> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 1 15.2 19.7 25.5 4.2 16.5 23.6 -#> 2 2 21.5 23.3 26.4 11.5 16.5 18.5 -#> 3 3 17.6 23.6 22.4 7.3 15.2 33.9 -#> 4 4 9.7 26.4 24.5 5.8 17.3 25.5 -#> 5 5 14.5 20 24.8 6.4 22.5 26.4 -#> 6 6 10 25.2 30.9 10 17.3 32.5 -#> 7 7 8.2 25.8 26.4 11.2 13.6 26.7 -#> 8 8 9.4 21.2 27.3 11.2 14.5 21.5 -#> 9 9 16.5 14.5 29.4 5.2 18.8 23.3 -#> 10 10 9.7 27.3 23 7 15.5 29.5 -#> -#> $repeated -#> [1] TRUE -#> -#> $lm_formula -#> cbind(OJ_X0.5, OJ_X1, OJ_X2, VC_X0.5, VC_X1, VC_X2) ~ 1 -#> <environment: 0x7fdfe6862be0> -#> -#> $model -#> -#> Call: -#> stats::lm(formula = lm_formula, data = data) -#> -#> Coefficients: -#> OJ_X0.5 OJ_X1 OJ_X2 VC_X0.5 VC_X1 VC_X2 -#> (Intercept) 13.23 22.70 26.06 7.98 16.77 26.14 -#> -#>
# Easily perform repeated measures ANOVA using the car package -res.anova <- Anova(design$model, idata = design$idata, idesign = design$idesign, type = 3) -summary(res.anova, multivariate = FALSE)
#> Warning: HF eps > 1 treated as 1
#> -#> Univariate Type III Repeated-Measures ANOVA Assuming Sphericity -#> -#> Sum Sq num Df Error SS den Df F value Pr(>F) -#> (Intercept) 21236.5 1 69.33 9 2756.9514 1.656e-12 *** -#> supp 205.3 1 53.01 9 34.8664 0.0002277 *** -#> dose 2426.4 2 205.11 18 106.4698 1.062e-10 *** -#> supp:dose 108.3 2 384.66 18 2.5343 0.1072129 -#> --- -#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 -#> -#> -#> Mauchly Tests for Sphericity -#> -#> Test statistic p-value -#> dose 0.80739 0.42495 -#> supp:dose 0.93390 0.76068 -#> -#> -#> Greenhouse-Geisser and Huynh-Feldt Corrections -#> for Departure from Sphericity -#> -#> GG eps Pr(>F[GG]) -#> dose 0.8385 2.79e-09 *** -#> supp:dose 0.9380 0.1115 -#> --- -#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 -#> -#> HF eps Pr(>F[HF]) -#> dose 1.008462 1.061617e-10 -#> supp:dose 1.176302 1.072129e-01
-# Independent measures designs -#::::::::::::::::::::::::::::::::::::::::: -# Build factorial designs -df$id <- 1:nrow(df) -design <- factorial_design(df, dv = len, wid = id, between = c(supp, dose)) -design
#> $dv -#> [1] "len" -#> -#> $between -#> [1] "supp" "dose" -#> -#> $wid -#> [1] "id" -#> -#> $data -#> # A tibble: 60 x 4 -#> len supp dose id -#> <dbl> <fct> <fct> <fct> -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 3 -#> 4 5.8 VC 0.5 4 -#> 5 6.4 VC 0.5 5 -#> 6 10 VC 0.5 6 -#> 7 11.2 VC 0.5 7 -#> 8 11.2 VC 0.5 8 -#> 9 5.2 VC 0.5 9 -#> 10 7 VC 0.5 10 -#> # … with 50 more rows -#> -#> $lm_data -#> # A tibble: 60 x 4 -#> len supp dose id -#> <dbl> <fct> <fct> <fct> -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 3 -#> 4 5.8 VC 0.5 4 -#> 5 6.4 VC 0.5 5 -#> 6 10 VC 0.5 6 -#> 7 11.2 VC 0.5 7 -#> 8 11.2 VC 0.5 8 -#> 9 5.2 VC 0.5 9 -#> 10 7 VC 0.5 10 -#> # … with 50 more rows -#> -#> $repeated -#> [1] FALSE -#> -#> $lm_formula -#> len ~ supp * dose -#> <environment: 0x7fdfc8b40b28> -#> -#> $model -#> -#> Call: -#> stats::lm(formula = lm_formula, data = data) -#> -#> Coefficients: -#> (Intercept) supp1 dose1 dose2 supp1:dose1 supp1:dose2 -#> 18.8133 1.8500 -8.2083 0.9217 0.7750 1.1150 -#> -#>
# Perform ANOVA -Anova(design$model, type = 3)
#> Anova Table (Type III tests) -#> -#> Response: len -#> Sum Sq Df F value Pr(>F) -#> (Intercept) 21236.5 1 1610.393 < 2.2e-16 *** -#> supp 205.4 1 15.572 0.0002312 *** -#> dose 2426.4 2 92.000 < 2.2e-16 *** -#> supp:dose 108.3 2 4.107 0.0218603 * -#> Residuals 712.1 54 -#> --- -#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
-
+
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+head(df)
+#>    len supp dose
+#> 1  4.2   VC  0.5
+#> 2 11.5   VC  0.5
+#> 3  7.3   VC  0.5
+#> 4  5.8   VC  0.5
+#> 5  6.4   VC  0.5
+#> 6 10.0   VC  0.5
+
+# Repeated measures designs
+#:::::::::::::::::::::::::::::::::::::::::
+# Prepare the data
+df$id <- rep(1:10, 6) # Add individuals id
+head(df)
+#>    len supp dose id
+#> 1  4.2   VC  0.5  1
+#> 2 11.5   VC  0.5  2
+#> 3  7.3   VC  0.5  3
+#> 4  5.8   VC  0.5  4
+#> 5  6.4   VC  0.5  5
+#> 6 10.0   VC  0.5  6
+# Build factorial designs
+design <- factorial_design(df, dv = len, wid = id, within = c(supp, dose))
+design
+#> $dv
+#> [1] "len"
+#> 
+#> $wid
+#> [1] "id"
+#> 
+#> $within
+#> [1] "supp" "dose"
+#> 
+#> $data
+#> # A tibble: 60 × 4
+#>      len supp  dose  id   
+#>    <dbl> <fct> <fct> <fct>
+#>  1   4.2 VC    X0.5  1    
+#>  2  11.5 VC    X0.5  2    
+#>  3   7.3 VC    X0.5  3    
+#>  4   5.8 VC    X0.5  4    
+#>  5   6.4 VC    X0.5  5    
+#>  6  10   VC    X0.5  6    
+#>  7  11.2 VC    X0.5  7    
+#>  8  11.2 VC    X0.5  8    
+#>  9   5.2 VC    X0.5  9    
+#> 10   7   VC    X0.5  10   
+#> # … with 50 more rows
+#> 
+#> $idata
+#>   supp dose
+#> 1   OJ X0.5
+#> 2   OJ   X1
+#> 3   OJ   X2
+#> 4   VC X0.5
+#> 5   VC   X1
+#> 6   VC   X2
+#> 
+#> $idesign
+#> ~supp * dose
+#> <environment: 0x7fb8b3117708>
+#> 
+#> $lm_data
+#> # A tibble: 10 × 7
+#>    id    OJ_X0.5 OJ_X1 OJ_X2 VC_X0.5 VC_X1 VC_X2
+#>    <fct>   <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl>
+#>  1 1        15.2  19.7  25.5     4.2  16.5  23.6
+#>  2 2        21.5  23.3  26.4    11.5  16.5  18.5
+#>  3 3        17.6  23.6  22.4     7.3  15.2  33.9
+#>  4 4         9.7  26.4  24.5     5.8  17.3  25.5
+#>  5 5        14.5  20    24.8     6.4  22.5  26.4
+#>  6 6        10    25.2  30.9    10    17.3  32.5
+#>  7 7         8.2  25.8  26.4    11.2  13.6  26.7
+#>  8 8         9.4  21.2  27.3    11.2  14.5  21.5
+#>  9 9        16.5  14.5  29.4     5.2  18.8  23.3
+#> 10 10        9.7  27.3  23       7    15.5  29.5
+#> 
+#> $repeated
+#> [1] TRUE
+#> 
+#> $lm_formula
+#> cbind(OJ_X0.5, OJ_X1, OJ_X2, VC_X0.5, VC_X1, VC_X2) ~ 1
+#> <environment: 0x7fb8a693d6d0>
+#> 
+#> $model
+#> 
+#> Call:
+#> stats::lm(formula = lm_formula, data = data)
+#> 
+#> Coefficients:
+#>              OJ_X0.5  OJ_X1  OJ_X2  VC_X0.5  VC_X1  VC_X2
+#> (Intercept)  13.23    22.70  26.06   7.98    16.77  26.14
+#> 
+#> 
+# Easily perform repeated measures ANOVA using the car package
+res.anova <- Anova(design$model, idata = design$idata, idesign = design$idesign, type = 3)
+summary(res.anova, multivariate = FALSE)
+#> Warning: HF eps > 1 treated as 1
+#> 
+#> Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
+#> 
+#>              Sum Sq num Df Error SS den Df   F value    Pr(>F)    
+#> (Intercept) 21236.5      1    69.33      9 2756.9514 1.656e-12 ***
+#> supp          205.3      1    53.01      9   34.8664 0.0002277 ***
+#> dose         2426.4      2   205.11     18  106.4698 1.062e-10 ***
+#> supp:dose     108.3      2   384.66     18    2.5343 0.1072129    
+#> ---
+#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
+#> 
+#> 
+#> Mauchly Tests for Sphericity
+#> 
+#>           Test statistic p-value
+#> dose             0.80739 0.42495
+#> supp:dose        0.93390 0.76068
+#> 
+#> 
+#> Greenhouse-Geisser and Huynh-Feldt Corrections
+#>  for Departure from Sphericity
+#> 
+#>           GG eps Pr(>F[GG])    
+#> dose      0.8385   2.79e-09 ***
+#> supp:dose 0.9380     0.1115    
+#> ---
+#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
+#> 
+#>             HF eps   Pr(>F[HF])
+#> dose      1.008462 1.061617e-10
+#> supp:dose 1.176302 1.072129e-01
+
+# Independent measures designs
+#:::::::::::::::::::::::::::::::::::::::::
+# Build factorial designs
+df$id <- 1:nrow(df)
+design <- factorial_design(df, dv = len, wid = id, between = c(supp, dose))
+design
+#> $dv
+#> [1] "len"
+#> 
+#> $between
+#> [1] "supp" "dose"
+#> 
+#> $wid
+#> [1] "id"
+#> 
+#> $data
+#> # A tibble: 60 × 4
+#>      len supp  dose  id   
+#>    <dbl> <fct> <fct> <fct>
+#>  1   4.2 VC    0.5   1    
+#>  2  11.5 VC    0.5   2    
+#>  3   7.3 VC    0.5   3    
+#>  4   5.8 VC    0.5   4    
+#>  5   6.4 VC    0.5   5    
+#>  6  10   VC    0.5   6    
+#>  7  11.2 VC    0.5   7    
+#>  8  11.2 VC    0.5   8    
+#>  9   5.2 VC    0.5   9    
+#> 10   7   VC    0.5   10   
+#> # … with 50 more rows
+#> 
+#> $lm_data
+#> # A tibble: 60 × 4
+#>      len supp  dose  id   
+#>    <dbl> <fct> <fct> <fct>
+#>  1   4.2 VC    0.5   1    
+#>  2  11.5 VC    0.5   2    
+#>  3   7.3 VC    0.5   3    
+#>  4   5.8 VC    0.5   4    
+#>  5   6.4 VC    0.5   5    
+#>  6  10   VC    0.5   6    
+#>  7  11.2 VC    0.5   7    
+#>  8  11.2 VC    0.5   8    
+#>  9   5.2 VC    0.5   9    
+#> 10   7   VC    0.5   10   
+#> # … with 50 more rows
+#> 
+#> $repeated
+#> [1] FALSE
+#> 
+#> $lm_formula
+#> len ~ supp * dose
+#> <environment: 0x7fb8b65ceb00>
+#> 
+#> $model
+#> 
+#> Call:
+#> stats::lm(formula = lm_formula, data = data)
+#> 
+#> Coefficients:
+#> (Intercept)        supp1        dose1        dose2  supp1:dose1  supp1:dose2  
+#>     18.8133       1.8500      -8.2083       0.9217       0.7750       1.1150  
+#> 
+#> 
+# Perform ANOVA
+Anova(design$model, type = 3)
+#> Anova Table (Type III tests)
+#> 
+#> Response: len
+#>              Sum Sq Df  F value    Pr(>F)    
+#> (Intercept) 21236.5  1 1610.393 < 2.2e-16 ***
+#> supp          205.4  1   15.572 0.0002312 ***
+#> dose         2426.4  2   92.000 < 2.2e-16 ***
+#> supp:dose     108.3  2    4.107 0.0218603 *  
+#> Residuals     712.1 54                       
+#> ---
+#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/factors.html b/docs/reference/factors.html index 7d7b904..23453a0 100644 --- a/docs/reference/factors.html +++ b/docs/reference/factors.html @@ -1,72 +1,15 @@ - - - - - - - -Factors — convert_as_factor • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Factors — convert_as_factor • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -128,120 +58,126 @@

Factors

levels order.

-
convert_as_factor(data, ..., vars = NULL, make.valid.levels = FALSE)
+    
+
convert_as_factor(data, ..., vars = NULL, make.valid.levels = FALSE)
+
+set_ref_level(data, name, ref)
+
+reorder_levels(data, name, order)
+
-set_ref_level(data, name, ref) +
+

Arguments

+
data
+

a data frame

-reorder_levels(data, name, order)
-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data frame

...

one unquoted expressions (or variable name) specifying the name of +

...
+

one unquoted expressions (or variable name) specifying the name of the variables you want to convert into factor. Alternative to the argument -vars.

vars

a character vector specifying the variables to convert into -factor.

make.valid.levels

logical. Default is FALSE. If TRUE, converts the -variable to factor and add a leading character (x) if starting with a digit.

name

a factor variable name. Can be unquoted. For example, use -group or "group".

ref

the reference level.

order

a character vector specifying the order of the factor levels

- -

Functions

+vars.

+ + +
vars
+

a character vector specifying the variables to convert into +factor.

+ +
make.valid.levels
+

logical. Default is FALSE. If TRUE, converts the +variable to factor and add a leading character (x) if starting with a digit.

+ + +
name
+

a factor variable name. Can be unquoted. For example, use +group or "group".

+ + +
ref
+

the reference level.

+ + +
order
+

a character vector specifying the order of the factor levels

+ +
+
+

Functions

-
    -
  • convert_as_factor: Convert one or multiple variables into factor.

  • -
  • set_ref_level: Change a factor reference level or group.

  • -
  • reorder_levels: Change the order of a factor levels

  • -
- -

Examples

-
# Create a demo data -df <- tibble( - group = c("a", "a", "b", "b", "c", "c"), - time = c("t1", "t2", "t1", "t2", "t1", "t2"), - value = c(5, 6, 1, 3, 4, 5) -) -df
#> # A tibble: 6 x 3 -#> group time value -#> <chr> <chr> <dbl> -#> 1 a t1 5 -#> 2 a t2 6 -#> 3 b t1 1 -#> 4 b t2 3 -#> 5 c t1 4 -#> 6 c t2 5
# Convert group and time into factor variable -result <- df %>% convert_as_factor(group, time) -result
#> # A tibble: 6 x 3 -#> group time value -#> <fct> <fct> <dbl> -#> 1 a t1 5 -#> 2 a t2 6 -#> 3 b t1 1 -#> 4 b t2 3 -#> 5 c t1 4 -#> 6 c t2 5
# Show group levels -levels(result$group)
#> [1] "a" "b" "c"
-# Set c as the reference level (the first one) -result <- result %>% - set_ref_level("group", ref = "c") -levels(result$group)
#> [1] "c" "a" "b"
-# Set the order of levels -result <- result %>% - reorder_levels("group", order = c("b", "c", "a")) -levels(result$group)
#> [1] "b" "c" "a"
-
+
  • convert_as_factor(): Convert one or multiple variables into factor.

  • +
  • set_ref_level(): Change a factor reference level or group.

  • +
  • reorder_levels(): Change the order of a factor levels

  • +
+ +
+

Examples

+
# Create a demo data
+df <- tibble(
+  group = c("a", "a", "b", "b", "c", "c"),
+  time = c("t1", "t2", "t1", "t2", "t1", "t2"),
+  value = c(5, 6, 1, 3, 4, 5)
+)
+df
+#> # A tibble: 6 × 3
+#>   group time  value
+#>   <chr> <chr> <dbl>
+#> 1 a     t1        5
+#> 2 a     t2        6
+#> 3 b     t1        1
+#> 4 b     t2        3
+#> 5 c     t1        4
+#> 6 c     t2        5
+# Convert group and time into factor variable
+result <- df %>% convert_as_factor(group, time)
+result
+#> # A tibble: 6 × 3
+#>   group time  value
+#>   <fct> <fct> <dbl>
+#> 1 a     t1        5
+#> 2 a     t2        6
+#> 3 b     t1        1
+#> 4 b     t2        3
+#> 5 c     t1        4
+#> 6 c     t2        5
+# Show group levels
+levels(result$group)
+#> [1] "a" "b" "c"
+
+# Set c as the reference level (the first one)
+result <- result %>%
+  set_ref_level("group", ref = "c")
+levels(result$group)
+#> [1] "c" "a" "b"
+
+# Set the order of levels
+result <- result %>%
+  reorder_levels("group", order = c("b", "c", "a"))
+levels(result$group)
+#> [1] "b" "c" "a"
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/fisher_test.html b/docs/reference/fisher_test.html index 576a6fc..28b98cb 100644 --- a/docs/reference/fisher_test.html +++ b/docs/reference/fisher_test.html @@ -1,74 +1,17 @@ - - - - - - - -Fisher's Exact Test for Count Data — fisher_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Fisher's Exact Test for Count Data — fisher_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Performs Fisher's exact test for testing the null of independence of rows and columns in a contingency table.

-

Wrappers around the R base function fisher.test() but +

Wrappers around the R base function fisher.test() but have the advantage of performing pairwise and row-wise fisher tests, the post-hoc tests following a significant chi-square test of homogeneity for 2xc and rx2 contingency tables.

-
fisher_test(
-  xtab,
-  workspace = 2e+05,
-  alternative = "two.sided",
-  conf.int = TRUE,
-  conf.level = 0.95,
-  simulate.p.value = FALSE,
-  B = 2000,
-  detailed = FALSE,
-  ...
-)
-
-pairwise_fisher_test(xtab, p.adjust.method = "holm", detailed = FALSE, ...)
-
-row_wise_fisher_test(xtab, p.adjust.method = "holm", detailed = FALSE, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
xtab

a contingency table in a matrix form.

workspace

an integer specifying the size of the workspace +

+
fisher_test(
+  xtab,
+  workspace = 2e+05,
+  alternative = "two.sided",
+  conf.int = TRUE,
+  conf.level = 0.95,
+  simulate.p.value = FALSE,
+  B = 2000,
+  detailed = FALSE,
+  ...
+)
+
+pairwise_fisher_test(xtab, p.adjust.method = "holm", detailed = FALSE, ...)
+
+row_wise_fisher_test(xtab, p.adjust.method = "holm", detailed = FALSE, ...)
+
+ +
+

Arguments

+
xtab
+

a contingency table in a matrix form.

+ + +
workspace
+

an integer specifying the size of the workspace used in the network algorithm. In units of 4 bytes. Only used for non-simulated p-values larger than \(2 \times 2\) tables. Since R version 3.5.0, this also increases the internal stack size which allows larger problems to be solved, however sometimes needing hours. In such cases, simulate.p.values=TRUE may be more - reasonable.

alternative

indicates the alternative hypothesis and must be + reasonable.

+ + +
alternative
+

indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". You can specify just the initial letter. Only used in the - \(2 \times 2\) case.

conf.int

logical indicating if a confidence interval for the + \(2 \times 2\) case.

+ + +
conf.int
+

logical indicating if a confidence interval for the odds ratio in a \(2 \times 2\) table should be - computed (and returned).

conf.level

confidence level for the returned confidence + computed (and returned).

+ + +
conf.level
+

confidence level for the returned confidence interval. Only used in the \(2 \times 2\) case and if - conf.int = TRUE.

simulate.p.value

a logical indicating whether to compute + conf.int = TRUE.

+ + +
simulate.p.value
+

a logical indicating whether to compute p-values by Monte Carlo simulation, in larger than \(2 \times - 2\) tables.

B

an integer specifying the number of replicates used in the - Monte Carlo test.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

...

Other arguments passed to the function fisher_test().

p.adjust.method

method to adjust p values for multiple comparisons. + 2\) tables.

+ + +
B
+

an integer specifying the number of replicates used in the + Monte Carlo test.

+ + +
detailed
+

logical value. Default is FALSE. If TRUE, a detailed result is +shown.

+ + +
...
+

Other arguments passed to the function fisher_test().

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

+want to adjust the p value (not recommended), use p.adjust.method = "none".

-

Value

+
+
+

Value

+ -

return a data frame with some the following columns:

    -
  • group: the categories in the row-wise proportion tests.

  • +

    return a data frame with some the following columns:

    • group: the categories in the row-wise proportion tests.

    • p: p-value.

    • p.adj: the adjusted p-value.

    • method: the used statistical test.

    • @@ -230,163 +160,182 @@

      Value

    • conf.low,conf.high: a confidence interval for the odds ratio. Only present in the 2 by 2 case and if argument conf.int = TRUE.

    • -
    - -

    The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Functions

- +
+
+

Functions

-
    -
  • fisher_test: performs Fisher's exact test for testing the null of +

    • fisher_test(): performs Fisher's exact test for testing the null of independence of rows and columns in a contingency table with fixed -marginals. Wrapper around the function fisher.test().

    • -
    • pairwise_fisher_test: pairwise comparisons between proportions, a post-hoc +marginals. Wrapper around the function fisher.test().

    • +
    • pairwise_fisher_test(): pairwise comparisons between proportions, a post-hoc tests following a significant Fisher's exact test of homogeneity for 2xc design.

    • -
    • row_wise_fisher_test: performs row-wise Fisher's exact test of count data, a post-hoc tests following a significant chi-square test +

    • row_wise_fisher_test(): performs row-wise Fisher's exact test of count data, a post-hoc tests following a significant chi-square test of homogeneity for rx2 contingency table. The test is conducted for each category (row).

    • -
    - -

    Examples

    -
    -# Comparing two proportions -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: frequencies of smokers between two groups -xtab <- as.table(rbind(c(490, 10), c(400, 100))) -dimnames(xtab) <- list( - group = c("grp1", "grp2"), - smoker = c("yes", "no") -) -xtab
    #> smoker -#> group yes no -#> grp1 490 10 -#> grp2 400 100
    # compare the proportion of smokers -fisher_test(xtab, detailed = TRUE)
    #> # A tibble: 1 x 8 -#> n estimate p conf.low conf.high method alternative p.signif -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> -#> 1 1000 12.2 8.77e-22 6.27 26.6 Fisher's Exac… two.sided ****
    -# Homogeneity of proportions between groups -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# H0: the proportion of smokers is similar in the four groups -# Ha: this proportion is different in at least one of the populations. -# -# Data preparation -grp.size <- c( 106, 113, 156, 102 ) -smokers <- c( 50, 100, 139, 80 ) -no.smokers <- grp.size - smokers -xtab <- as.table(rbind( - smokers, - no.smokers -)) -dimnames(xtab) <- list( - Smokers = c("Yes", "No"), - Groups = c("grp1", "grp2", "grp3", "grp4") -) -xtab
    #> Groups -#> Smokers grp1 grp2 grp3 grp4 -#> Yes 50 100 139 80 -#> No 56 13 17 22
    -# Compare the proportions of smokers between groups -fisher_test(xtab, detailed = TRUE)
    #> # A tibble: 1 x 5 -#> n p method alternative p.signif -#> * <dbl> <dbl> <chr> <chr> <chr> -#> 1 477 6.1e-15 Fisher's Exact test two.sided ****
    -# Pairwise comparison between groups -pairwise_fisher_test(xtab)
    #> # A tibble: 6 x 6 -#> group1 group2 n p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <dbl> <chr> -#> 1 grp1 grp2 219 2.39e-11 1.2 e-10 **** -#> 2 grp1 grp3 262 1.22e-13 7.32e-13 **** -#> 3 grp1 grp4 208 3.79e- 6 1.52e- 5 **** -#> 4 grp2 grp3 269 1 e+ 0 1 e+ 0 ns -#> 5 grp2 grp4 215 6.35e- 2 1.27e- 1 ns -#> 6 grp3 grp4 258 2.17e- 2 6.51e- 2 ns
    - -# Pairwise proportion tests -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: Titanic -xtab <- as.table(rbind( - c(122, 167, 528, 673), - c(203, 118, 178, 212) -)) -dimnames(xtab) <- list( - Survived = c("No", "Yes"), - Class = c("1st", "2nd", "3rd", "Crew") -) -xtab
    #> Class -#> Survived 1st 2nd 3rd Crew -#> No 122 167 528 673 -#> Yes 203 118 178 212
    # Compare the proportion of survived between groups -pairwise_fisher_test(xtab)
    #> # A tibble: 6 x 6 -#> group1 group2 n p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <dbl> <chr> -#> 1 1st 2nd 610 2.78e- 7 8.34e- 7 **** -#> 2 1st 3rd 1031 3.68e-30 1.84e-29 **** -#> 3 1st Crew 1210 1.81e-34 1.09e-33 **** -#> 4 2nd 3rd 991 8.19e- 7 1.64e- 6 **** -#> 5 2nd Crew 1170 2.77e- 8 1.11e- 7 **** -#> 6 3rd Crew 1591 5.98e- 1 5.98e- 1 ns
    -# Row-wise proportion tests -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: Titanic -xtab <- as.table(rbind( - c(180, 145), c(179, 106), - c(510, 196), c(862, 23) -)) -dimnames(xtab) <- list( - Class = c("1st", "2nd", "3rd", "Crew"), - Gender = c("Male", "Female") -) -xtab
    #> Gender -#> Class Male Female -#> 1st 180 145 -#> 2nd 179 106 -#> 3rd 510 196 -#> Crew 862 23
    # Compare the proportion of males and females in each category -row_wise_fisher_test(xtab)
    #> # A tibble: 4 x 5 -#> group n p p.adj p.adj.signif -#> * <chr> <dbl> <dbl> <dbl> <chr> -#> 1 1st 2201 9.38e-25 2.81e-24 **** -#> 2 2nd 2201 3.96e-11 7.92e-11 **** -#> 3 3rd 2201 8.67e- 7 8.67e- 7 **** -#> 4 Crew 2201 8.02e-85 3.21e-84 ****
    -# A r x c table Agresti (2002, p. 57) Job Satisfaction -Job <- matrix(c(1,2,1,0, 3,3,6,1, 10,10,14,9, 6,7,12,11), 4, 4, - dimnames = list(income = c("< 15k", "15-25k", "25-40k", "> 40k"), - satisfaction = c("VeryD", "LittleD", "ModerateS", "VeryS"))) -fisher_test(Job)
    #> # A tibble: 1 x 3 -#> n p p.signif -#> * <dbl> <dbl> <chr> -#> 1 96 0.783 ns
    fisher_test(Job, simulate.p.value = TRUE, B = 1e5)
    #> # A tibble: 1 x 3 -#> n p p.signif -#> * <dbl> <dbl> <chr> -#> 1 96 0.784 ns
    +
+ +
+

Examples

+

+# Comparing two proportions
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: frequencies of smokers between two groups
+xtab <- as.table(rbind(c(490, 10), c(400, 100)))
+dimnames(xtab) <- list(
+  group = c("grp1", "grp2"),
+  smoker = c("yes", "no")
+)
+xtab
+#>       smoker
+#> group  yes  no
+#>   grp1 490  10
+#>   grp2 400 100
+# compare the proportion of smokers
+fisher_test(xtab, detailed = TRUE)
+#> # A tibble: 1 × 8
+#>       n estimate        p conf.low conf.high method              alter…¹ p.sig…²
+#> * <dbl>    <dbl>    <dbl>    <dbl>     <dbl> <chr>               <chr>   <chr>  
+#> 1  1000     12.2 8.77e-22     6.27      26.6 Fisher's Exact test two.si… ****   
+#> # … with abbreviated variable names ¹​alternative, ²​p.signif
+
+# Homogeneity of proportions between groups
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# H0: the proportion of smokers is similar in the four groups
+# Ha:  this proportion is different in at least one of the populations.
+#
+# Data preparation
+grp.size <- c( 106, 113, 156, 102 )
+smokers  <- c( 50, 100, 139, 80 )
+no.smokers <- grp.size - smokers
+xtab <- as.table(rbind(
+  smokers,
+  no.smokers
+))
+dimnames(xtab) <- list(
+  Smokers = c("Yes", "No"),
+  Groups = c("grp1", "grp2", "grp3", "grp4")
+)
+xtab
+#>        Groups
+#> Smokers grp1 grp2 grp3 grp4
+#>     Yes   50  100  139   80
+#>     No    56   13   17   22
+
+# Compare the proportions of smokers between groups
+fisher_test(xtab, detailed = TRUE)
+#> # A tibble: 1 × 5
+#>       n       p method              alternative p.signif
+#> * <dbl>   <dbl> <chr>               <chr>       <chr>   
+#> 1   477 6.1e-15 Fisher's Exact test two.sided   ****    
+
+# Pairwise comparison between groups
+pairwise_fisher_test(xtab)
+#> # A tibble: 6 × 6
+#>   group1 group2     n        p    p.adj p.adj.signif
+#> * <chr>  <chr>  <dbl>    <dbl>    <dbl> <chr>       
+#> 1 grp1   grp2     219 2.39e-11 1.2 e-10 ****        
+#> 2 grp1   grp3     262 1.22e-13 7.32e-13 ****        
+#> 3 grp1   grp4     208 3.79e- 6 1.52e- 5 ****        
+#> 4 grp2   grp3     269 1   e+ 0 1   e+ 0 ns          
+#> 5 grp2   grp4     215 6.35e- 2 1.27e- 1 ns          
+#> 6 grp3   grp4     258 2.17e- 2 6.51e- 2 ns          
+
+
+# Pairwise proportion tests
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: Titanic
+xtab <- as.table(rbind(
+  c(122, 167, 528, 673),
+  c(203, 118, 178, 212)
+))
+dimnames(xtab) <- list(
+  Survived = c("No", "Yes"),
+  Class = c("1st", "2nd", "3rd", "Crew")
+)
+xtab
+#>         Class
+#> Survived 1st 2nd 3rd Crew
+#>      No  122 167 528  673
+#>      Yes 203 118 178  212
+# Compare the proportion of survived between groups
+pairwise_fisher_test(xtab)
+#> # A tibble: 6 × 6
+#>   group1 group2     n        p    p.adj p.adj.signif
+#> * <chr>  <chr>  <dbl>    <dbl>    <dbl> <chr>       
+#> 1 1st    2nd      610 2.78e- 7 8.34e- 7 ****        
+#> 2 1st    3rd     1031 3.68e-30 1.84e-29 ****        
+#> 3 1st    Crew    1210 1.81e-34 1.09e-33 ****        
+#> 4 2nd    3rd      991 8.19e- 7 1.64e- 6 ****        
+#> 5 2nd    Crew    1170 2.77e- 8 1.11e- 7 ****        
+#> 6 3rd    Crew    1591 5.98e- 1 5.98e- 1 ns          
+
+# Row-wise proportion tests
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: Titanic
+xtab <- as.table(rbind(
+  c(180, 145), c(179, 106),
+  c(510, 196), c(862, 23)
+))
+dimnames(xtab) <- list(
+  Class = c("1st", "2nd", "3rd", "Crew"),
+  Gender = c("Male", "Female")
+)
+xtab
+#>       Gender
+#> Class  Male Female
+#>   1st   180    145
+#>   2nd   179    106
+#>   3rd   510    196
+#>   Crew  862     23
+# Compare the proportion of males and females in each category
+row_wise_fisher_test(xtab)
+#> # A tibble: 4 × 5
+#>   group     n        p    p.adj p.adj.signif
+#> * <chr> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 1st    2201 9.38e-25 2.81e-24 ****        
+#> 2 2nd    2201 3.96e-11 7.92e-11 ****        
+#> 3 3rd    2201 8.67e- 7 8.67e- 7 ****        
+#> 4 Crew   2201 8.02e-85 3.21e-84 ****        
+
+# A r x c table  Agresti (2002, p. 57) Job Satisfaction
+Job <- matrix(c(1,2,1,0, 3,3,6,1, 10,10,14,9, 6,7,12,11), 4, 4,
+              dimnames = list(income = c("< 15k", "15-25k", "25-40k", "> 40k"),
+                             satisfaction = c("VeryD", "LittleD", "ModerateS", "VeryS")))
+fisher_test(Job)
+#> # A tibble: 1 × 3
+#>       n     p p.signif
+#> * <dbl> <dbl> <chr>   
+#> 1    96 0.783 ns      
+fisher_test(Job, simulate.p.value = TRUE, B = 1e5)
+#> # A tibble: 1 × 3
+#>       n     p p.signif
+#> * <dbl> <dbl> <chr>   
+#> 1    96 0.783 ns      
+
+
+
-
- +
- - + + diff --git a/docs/reference/freq_table.html b/docs/reference/freq_table.html index 1e1d33e..8c46fca 100644 --- a/docs/reference/freq_table.html +++ b/docs/reference/freq_table.html @@ -1,69 +1,12 @@ - - - - - - - -Compute Frequency Table — freq_table • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Frequency Table — freq_table • rstatix - - + + - - -
-
- -
- -
+
@@ -122,71 +52,73 @@

Compute Frequency Table

compute frequency table.

-
freq_table(data, ..., vars = NULL, na.rm = TRUE)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
data

a data frame

...

One or more unquoted expressions (or variable names) separated by -commas. Used to specify variables of interest.

vars

optional character vector containing variable names.

na.rm

logical value. If TRUE (default), remove missing values in the -variables used to create the frequency table.

- -

Value

- -

a data frame

- -

Examples

-
data("ToothGrowth") -ToothGrowth %>% freq_table(supp, dose)
#> # A tibble: 6 x 4 -#> supp dose n prop -#> <fct> <dbl> <int> <dbl> -#> 1 OJ 0.5 10 33.3 -#> 2 OJ 1 10 33.3 -#> 3 OJ 2 10 33.3 -#> 4 VC 0.5 10 33.3 -#> 5 VC 1 10 33.3 -#> 6 VC 2 10 33.3
+
+
freq_table(data, ..., vars = NULL, na.rm = TRUE)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to specify variables of interest.

+ + +
vars
+

optional character vector containing variable names.

+ + +
na.rm
+

logical value. If TRUE (default), remove missing values in the +variables used to create the frequency table.

+ +
+
+

Value

+ + +

a data frame

+
+ +
+

Examples

+
data("ToothGrowth")
+ToothGrowth %>% freq_table(supp, dose)
+#> # A tibble: 6 × 4
+#>   supp   dose     n  prop
+#>   <fct> <dbl> <int> <dbl>
+#> 1 OJ      0.5    10  33.3
+#> 2 OJ      1      10  33.3
+#> 3 OJ      2      10  33.3
+#> 4 VC      0.5    10  33.3
+#> 5 VC      1      10  33.3
+#> 6 VC      2      10  33.3
+
+
+
-
- +
- - + + diff --git a/docs/reference/friedman_effsize.html b/docs/reference/friedman_effsize.html index a8c7983..0370353 100644 --- a/docs/reference/friedman_effsize.html +++ b/docs/reference/friedman_effsize.html @@ -1,48 +1,5 @@ - - - - - - - -Friedman Test Effect Size (Kendall's W Value) — friedman_effsize • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Friedman Test Effect Size (Kendall's W Value) — friedman_effsize • rstatix - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -140,116 +70,118 @@

Friedman Test Effect Size (Kendall's W Value)

Confidence intervals are calculated by bootstap.

-
friedman_effsize(
-  data,
-  formula,
-  ci = FALSE,
-  conf.level = 0.95,
-  ci.type = "perc",
-  nboot = 1000,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form a ~ b | c, where a +

+
friedman_effsize(
+  data,
+  formula,
+  ci = FALSE,
+  conf.level = 0.95,
+  ci.type = "perc",
+  nboot = 1000,
+  ...
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form a ~ b | c, where a (numeric) is the dependent variable name; b is the within-subjects factor variables; and c (factor) is the column name containing -individuals/subjects identifier. Should be unique per individual.

ci

If TRUE, returns confidence intervals by bootstrap. May be slow.

conf.level

The level for the confidence interval.

ci.type

The type of confidence interval to use. Can be any of "norm", -"basic", "perc", or "bca". Passed to boot::boot.ci.

nboot

The number of replications to use for bootstrap.

...

other arguments passed to the function friedman.test()

- -

Value

- -

return a data frame with some of the following columns:

    -
  • .y.: the y variable used in the test.

  • +individuals/subjects identifier. Should be unique per individual.

    + + +
    ci
    +

    If TRUE, returns confidence intervals by bootstrap. May be slow.

    + + +
    conf.level
    +

    The level for the confidence interval.

    + + +
    ci.type
    +

    The type of confidence interval to use. Can be any of "norm", +"basic", "perc", or "bca". Passed to boot::boot.ci.

    + + +
    nboot
    +

    The number of replications to use for bootstrap.

    + + +
    ...
    +

    other arguments passed to the function friedman.test()

    + +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y variable used in the test.

  • n: Sample counts.

  • effsize: estimate of the effect size.

  • magnitude: magnitude of effect size.

  • conf.low,conf.high: lower and upper bound of the effect size confidence interval.

  • -
- -

References

- +
+
+

References

Maciej Tomczak and Ewa Tomczak. The need to report effect size estimates revisited. An overview of some recommended measures of effect size. Trends in Sport Sciences. 2014; 1(21):19-25.

+
-

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth %>% - filter(supp == "VC") %>% - mutate(id = rep(1:10, 3)) -head(df)
#> len supp dose id -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 3 -#> 4 5.8 VC 0.5 4 -#> 5 6.4 VC 0.5 5 -#> 6 10.0 VC 0.5 6
-# Friedman test effect size -#::::::::::::::::::::::::::::::::::::::::: -df %>% friedman_effsize(len ~ dose | id)
#> # A tibble: 1 x 5 -#> .y. n effsize method magnitude -#> * <chr> <int> <dbl> <chr> <ord> -#> 1 len 10 1 Kendall W large
+
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth %>%
+    filter(supp == "VC") %>%
+    mutate(id = rep(1:10, 3))
+head(df)
+#>    len supp dose id
+#> 1  4.2   VC  0.5  1
+#> 2 11.5   VC  0.5  2
+#> 3  7.3   VC  0.5  3
+#> 4  5.8   VC  0.5  4
+#> 5  6.4   VC  0.5  5
+#> 6 10.0   VC  0.5  6
+
+# Friedman test effect size
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% friedman_effsize(len ~ dose | id)
+#> # A tibble: 1 × 5
+#>   .y.       n effsize method    magnitude
+#> * <chr> <int>   <dbl> <chr>     <ord>    
+#> 1 len      10       1 Kendall W large    
+
+
+
-
- +
- - + + diff --git a/docs/reference/friedman_test.html b/docs/reference/friedman_test.html index 7b679a0..aba0fdb 100644 --- a/docs/reference/friedman_test.html +++ b/docs/reference/friedman_test.html @@ -1,74 +1,17 @@ - - - - - - - -Friedman Rank Sum Test — friedman_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Friedman Rank Sum Test — friedman_test • rstatix - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -127,93 +57,94 @@

Friedman Rank Sum Test

Provides a pipe-friendly framework to perform a Friedman rank sum test, which is the non-parametric alternative to the one-way repeated measures ANOVA test. Wrapper around the function - friedman.test(). Read more: - Friedman + friedman.test(). Read more: + Friedman test in R.

-
friedman_test(data, formula, ...)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form a ~ b | c, where a +

+
friedman_test(data, formula, ...)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form a ~ b | c, where a (numeric) is the dependent variable name; b is the within-subjects factor variables; and c (factor) is the column name containing -individuals/subjects identifier. Should be unique per individual.

...

other arguments to be passed to the function -friedman.test.

- -

Value

- -

return a data frame with the following columns:

    -
  • .y.: the y (dependent) variable used in the test.

  • +individuals/subjects identifier. Should be unique per individual.

    + + +
    ...
    +

    other arguments to be passed to the function +friedman.test.

    + +
+
+

Value

+ + +

return a data frame with the following columns:

  • .y.: the y (dependent) variable used in the test.

  • n: sample count.

  • statistic: the value of Friedman's chi-squared statistic, used to compute the p-value.

  • p: p-value.

  • method: the statistical test used to compare groups.

  • -
- - -

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth %>% - filter(supp == "VC") %>% - mutate(id = rep(1:10, 3)) -head(df)
#> len supp dose id -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 3 -#> 4 5.8 VC 0.5 4 -#> 5 6.4 VC 0.5 5 -#> 6 10.0 VC 0.5 6
-# Friedman rank sum test -#::::::::::::::::::::::::::::::::::::::::: -df %>% friedman_test(len ~ dose | id)
#> # A tibble: 1 x 6 -#> .y. n statistic df p method -#> * <chr> <int> <dbl> <dbl> <dbl> <chr> -#> 1 len 10 20 2 0.0000454 Friedman test
-
+
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth %>%
+    filter(supp == "VC") %>%
+    mutate(id = rep(1:10, 3))
+head(df)
+#>    len supp dose id
+#> 1  4.2   VC  0.5  1
+#> 2 11.5   VC  0.5  2
+#> 3  7.3   VC  0.5  3
+#> 4  5.8   VC  0.5  4
+#> 5  6.4   VC  0.5  5
+#> 6 10.0   VC  0.5  6
+
+# Friedman rank sum test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% friedman_test(len ~ dose | id)
+#> # A tibble: 1 × 6
+#>   .y.       n statistic    df         p method       
+#> * <chr> <int>     <dbl> <dbl>     <dbl> <chr>        
+#> 1 len      10        20     2 0.0000454 Friedman test
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/games_howell_test.html b/docs/reference/games_howell_test.html index 22b007a..783276f 100644 --- a/docs/reference/games_howell_test.html +++ b/docs/reference/games_howell_test.html @@ -1,48 +1,5 @@ - - - - - - - -Games Howell Post-hoc Tests — games_howell_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Games Howell Post-hoc Tests — games_howell_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -140,37 +70,37 @@

Games Howell Post-hoc Tests

corrections.

-
games_howell_test(data, formula, conf.level = 0.95, detailed = FALSE)
+
+
games_howell_test(data, formula, conf.level = 0.95, detailed = FALSE)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ -

Arguments

- - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

conf.level

confidence level of the interval.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

+formula = TP53 ~ cancer_group.

+ + +
conf.level
+

confidence level of the interval.

+ -

Value

+
detailed
+

logical value. Default is FALSE. If TRUE, a detailed result is +shown.

-

return a data frame with some of the following columns:

    -
  • .y.: the y (outcome) variable used in the test.

  • +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y (outcome) variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n1,n2: Sample counts.

  • estimate, conf.low, conf.high: @@ -182,12 +112,11 @@

    Value

  • p.adj: adjusted p-value using Tukey's method.

  • method: the statistical test used to compare groups.

  • p.adj.signif: the significance level of p-values.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Details

- +
+
+

Details

The Games-Howell method is an improved version of the Tukey-Kramer method and is applicable in cases where the equivalence of variance assumption is violated. It is a t-test using Welch’s degree of freedom. This @@ -196,64 +125,65 @@

Details the size of the sample is different. However, the smaller the number of samples in each group, the it is more tolerant the type I error control. Thus, this method can be applied when the number of samples is six or more.

-

References

- +
+
+

References

-
    -
  • Aaron Schlege, +

    • Aaron Schlege, https://rpubs.com/aaronsc32/games-howell-test.

    • Sangseok Lee, Dong Kyu Lee. What is the proper way to apply the multiple comparison test?. Korean J Anesthesiol. 2018;71(5):353-360.

    • -
    - - -

    Examples

    -
    # Simple test -ToothGrowth %>% games_howell_test(len ~ dose)
    #> # A tibble: 3 x 8 -#> .y. group1 group2 estimate conf.low conf.high p.adj p.adj.signif -#> * <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 9.13 5.69 12.6 0.000000376 **** -#> 2 len 0.5 2 15.5 12.3 18.7 0 **** -#> 3 len 1 2 6.37 3.19 9.54 0.0000557 ****
    -# Grouped data -ToothGrowth %>% - group_by(supp) %>% - games_howell_test(len ~ dose)
    #> # A tibble: 6 x 9 -#> supp .y. group1 group2 estimate conf.low conf.high p.adj p.adj.signif -#> * <fct> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 OJ len 0.5 1 9.47 4.68 14.3 0.000247 *** -#> 2 OJ len 0.5 2 12.8 8.56 17.1 0.00000376 **** -#> 3 OJ len 1 2 3.36 -0.501 7.22 0.094 ns -#> 4 VC len 0.5 1 8.79 5.78 11.8 0.00000196 **** -#> 5 VC len 0.5 2 18.2 13.6 22.7 0.000000134 **** -#> 6 VC len 1 2 9.37 4.87 13.9 0.000253 ***
    -
    +
+ +
+

Examples

+
# Simple test
+ToothGrowth %>% games_howell_test(len ~ dose)
+#> # A tibble: 3 × 8
+#>   .y.   group1 group2 estimate conf.low conf.high       p.adj p.adj.signif
+#> * <chr> <chr>  <chr>     <dbl>    <dbl>     <dbl>       <dbl> <chr>       
+#> 1 len   0.5    1          9.13     5.69     12.6  0.000000376 ****        
+#> 2 len   0.5    2         15.5     12.3      18.7  0           ****        
+#> 3 len   1      2          6.37     3.19      9.54 0.0000557   ****        
+
+# Grouped data
+ToothGrowth %>%
+  group_by(supp) %>%
+  games_howell_test(len ~ dose)
+#> # A tibble: 6 × 9
+#>   supp  .y.   group1 group2 estimate conf.low conf.high       p.adj p.adj.signif
+#> * <fct> <chr> <chr>  <chr>     <dbl>    <dbl>     <dbl>       <dbl> <chr>       
+#> 1 OJ    len   0.5    1          9.47    4.68      14.3  0.000247    ***         
+#> 2 OJ    len   0.5    2         12.8     8.56      17.1  0.00000376  ****        
+#> 3 OJ    len   1      2          3.36   -0.501      7.22 0.094       ns          
+#> 4 VC    len   0.5    1          8.79    5.78      11.8  0.00000196  ****        
+#> 5 VC    len   0.5    2         18.2    13.6       22.7  0.000000134 ****        
+#> 6 VC    len   1      2          9.37    4.87      13.9  0.000253    ***         
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_comparisons.html b/docs/reference/get_comparisons.html index 448ad20..522b3dc 100644 --- a/docs/reference/get_comparisons.html +++ b/docs/reference/get_comparisons.html @@ -1,71 +1,14 @@ - - - - - - - -Create a List of Possible Comparisons Between Groups — get_comparisons • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create a List of Possible Comparisons Between Groups — get_comparisons • rstatix - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -126,90 +56,96 @@

Create a List of Possible Comparisons Between Groups

kept.

-
get_comparisons(data, variable, ref.group = NULL)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame

variable

the grouping variable name. Can be unquoted.

ref.group

a character string specifying the reference group. Can be +

+
get_comparisons(data, variable, ref.group = NULL)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
variable
+

the grouping variable name. Can be unquoted.

+ + +
ref.group
+

a character string specifying the reference group. Can be unquoted. If numeric, then it should be quoted. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).

If ref.group = "all", pairwise comparisons are performed between each - grouping variable levels against all (i.e. basemean).

- -

Value

- -

a list of all possible pairwise comparisons.

- -

Examples

-
# All possible pairwise comparisons -ToothGrowth %>% - get_comparisons("dose")
#> $V1 -#> [1] "0.5" "1" -#> -#> $V2 -#> [1] "0.5" "2" -#> -#> $V3 -#> [1] "1" "2" -#>
-# Comparisons against reference groups -ToothGrowth %>% - get_comparisons("dose", ref.group = "0.5")
#> $V1 -#> [1] "0.5" "1" -#> -#> $V2 -#> [1] "0.5" "2" -#>
-# Comparisons against all (basemean) -ToothGrowth %>% - get_comparisons("dose", ref.group = "all")
#> $V1 -#> [1] "all" "0.5" -#> -#> $V2 -#> [1] "all" "1" -#> -#> $V3 -#> [1] "all" "2" -#>
+ grouping variable levels against all (i.e. basemean).

+ +
+
+

Value

+ + +

a list of all possible pairwise comparisons.

+
+ +
+

Examples

+
# All possible pairwise comparisons
+ToothGrowth %>%
+  get_comparisons("dose")
+#> $V1
+#> [1] "0.5" "1"  
+#> 
+#> $V2
+#> [1] "0.5" "2"  
+#> 
+#> $V3
+#> [1] "1" "2"
+#> 
+
+# Comparisons against reference groups
+ToothGrowth %>%
+  get_comparisons("dose", ref.group = "0.5")
+#> $V1
+#> [1] "0.5" "1"  
+#> 
+#> $V2
+#> [1] "0.5" "2"  
+#> 
+
+# Comparisons against  all (basemean)
+ToothGrowth %>%
+  get_comparisons("dose", ref.group = "all")
+#> $V1
+#> [1] "all" "0.5"
+#> 
+#> $V2
+#> [1] "all" "1"  
+#> 
+#> $V3
+#> [1] "all" "2"  
+#> 
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_mode.html b/docs/reference/get_mode.html index 8b9f22a..4b3a64f 100644 --- a/docs/reference/get_mode.html +++ b/docs/reference/get_mode.html @@ -1,70 +1,13 @@ - - - - - - - -Compute Mode — get_mode • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Mode — get_mode • rstatix - - + + - - -
-
- -
- -
+
@@ -124,57 +54,62 @@

Compute Mode

value.

-
get_mode(x)
- -

Arguments

- - - - - - -
x

a vector. Can be numeric, factor or character vector.

- - -

Examples

-
-# Mode of numeric vector -x <- c(1:5, 6, 6, 7:10) -get_mode(x)
#> [1] 6
-# Bimodal -x <- c(1:5, 6, 6, 7, 8, 9, 9, 10) -get_mode(x)
#> [1] 6 9
-# No mode -x <- c(1, 2, 3, 4, 5) -get_mode(x)
#> [1] NA
-# Nominal vector -fruits <- c(rep("orange", 10), rep("apple", 5), rep("lemon", 2)) -get_mode(fruits)
#> [1] "orange"
+
+
get_mode(x)
+
+ +
+

Arguments

+
x
+

a vector. Can be numeric, factor or character vector.

+ +
+ +
+

Examples

+

+# Mode of numeric vector
+x <- c(1:5, 6, 6, 7:10)
+get_mode(x)
+#> [1] 6
+
+# Bimodal
+x <- c(1:5, 6, 6, 7, 8, 9, 9, 10)
+get_mode(x)
+#> [1] 6 9
+
+# No mode
+x <- c(1, 2, 3, 4, 5)
+get_mode(x)
+#> [1] NA
+
+# Nominal vector
+fruits <-  c(rep("orange", 10), rep("apple", 5), rep("lemon", 2))
+get_mode(fruits)
+#> [1] "orange"
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_pvalue_position-1.png b/docs/reference/get_pvalue_position-1.png index df137cb..4d456a2 100644 Binary files a/docs/reference/get_pvalue_position-1.png and b/docs/reference/get_pvalue_position-1.png differ diff --git a/docs/reference/get_pvalue_position.html b/docs/reference/get_pvalue_position.html index b30043f..e1682cd 100644 --- a/docs/reference/get_pvalue_position.html +++ b/docs/reference/get_pvalue_position.html @@ -1,48 +1,5 @@ - - - - - - - -Autocompute P-value Positions For Plotting Significance — get_y_position • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Autocompute P-value Positions For Plotting Significance — get_y_position • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
+ +
+
get_y_position(
+  data,
+  formula,
+  fun = "max",
+  ref.group = NULL,
+  comparisons = NULL,
+  step.increase = 0.12,
+  y.trans = NULL,
+  stack = FALSE,
+  scales = c("fixed", "free", "free_y")
+)
+
+add_y_position(
+  test,
+  fun = "max",
+  step.increase = 0.12,
+  data = NULL,
+  formula = NULL,
+  ref.group = NULL,
+  comparisons = NULL,
+  y.trans = NULL,
+  stack = FALSE,
+  scales = c("fixed", "free", "free_y")
+)
+
+add_x_position(test, x = NULL, group = NULL, dodge = 0.8)
+
+add_xy_position(
+  test,
+  x = NULL,
+  group = NULL,
+  dodge = 0.8,
+  stack = FALSE,
+  fun = "max",
+  step.increase = 0.12,
+  scales = c("fixed", "free", "free_y"),
+  ...
+)
-
get_y_position(
-  data,
-  formula,
-  fun = "max",
-  ref.group = NULL,
-  comparisons = NULL,
-  step.increase = 0.12,
-  y.trans = NULL,
-  stack = FALSE,
-  scales = c("fixed", "free", "free_y")
-)
-
-add_y_position(
-  test,
-  fun = "max",
-  step.increase = 0.12,
-  data = NULL,
-  formula = NULL,
-  ref.group = NULL,
-  comparisons = NULL,
-  y.trans = NULL,
-  stack = FALSE,
-  scales = c("fixed", "free", "free_y")
-)
-
-add_x_position(test, x = NULL, group = NULL, dodge = 0.8)
-
-add_xy_position(
-  test,
-  x = NULL,
-  group = NULL,
-  dodge = 0.8,
-  stack = FALSE,
-  fun = "max",
-  step.increase = 0.12,
-  scales = c("fixed", "free", "free_y"),
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

fun

summary statistics functions used to compute automatically suitable +formula = TP53 ~ cancer_group.

+ + +
fun
+

summary statistics functions used to compute automatically suitable y positions of p-value labels and brackets. Possible values include: "max", "mean", "mean_sd", "mean_se", "mean_ci", "median", "median_iqr", "median_mad".

-

For example, if fun = "max", the y positions are guessed as follow:

    -
  • 1. Compute the maximum of each group (groups.maximum)

  • +

    For example, if fun = "max", the y positions are guessed as follow:

    • 1. Compute the maximum of each group (groups.maximum)

    • 2. Use the highest groups maximum as the first bracket y position

    • 3. Add successively a step increase for remaining bracket y positions.

    • -
    - -

    When the main plot is a boxplot, you need the option fun = "max", to +

When the main plot is a boxplot, you need the option fun = "max", to have the p-value bracket displayed at the maximum point of the group.

In some situations the main plot is a line plot or a barplot showing the mean+/-error bars of the groups, where error can be SE (standard error), SD (standard deviation) or CI (confidence interval). In this case, to correctly compute the bracket y position you need the option fun = - "mean_se", etc.

ref.group

a character string specifying the reference group. If + "mean_se", etc.

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be -compared to the reference group (i.e. control group).

comparisons

A list of length-2 vectors specifying the groups of +compared to the reference group (i.e. control group).

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

step.increase

numeric vector with the increase in fraction of total -height for every additional comparison to minimize overlap.

y.trans

a function for transforming y axis scale. Value can be +"C"))

+ + +
step.increase
+

numeric vector with the increase in fraction of total +height for every additional comparison to minimize overlap.

+ + +
y.trans
+

a function for transforming y axis scale. Value can be log2, log10 and sqrt. Can be also any custom function that can take a numeric vector as input and returns a numeric vector, -example: y.trans = function(x){log2(x+1)}

stack

logical. If TRUE, computes y position for a stacked plot. Useful -when dealing with stacked bar plots.

scales

Should scales be fixed ("fixed", the default), free +example: y.trans = function(x){log2(x+1)}

+ + +
stack
+

logical. If TRUE, computes y position for a stacked plot. Useful +when dealing with stacked bar plots.

+ + +
scales
+

Should scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_y")?. This option is considered only when determining the y position. If the specified value is "free" or "free_y", then the step increase of y positions will be calculated by plot panels. Note that, using "free" or "free_y" gives the same result. A global step increase is computed -when scales = "fixed".

test

an object of class rstatix_test as returned by -t_test(), wilcox_test(), -sign_test(), tukey_hsd(), -dunn_test().

x

variable on x axis.

group

group variable (legend variable).

dodge

dodge width for grouped ggplot/test. Default is 0.8. Used only -when x specified.

...

other arguments to be passed to the function -t.test.

- -

Functions

+when scales = "fixed".

+ + +
test
+

an object of class rstatix_test as returned by +t_test(), wilcox_test(), +sign_test(), tukey_hsd(), +dunn_test().

+ + +
x
+

variable on x axis.

+ + +
group
+

group variable (legend variable).

+ +
dodge
+

dodge width for grouped ggplot/test. Default is 0.8. Used only +when x specified.

+ + +
...
+

other arguments to be passed to the function +t.test.

+ +
+
+

Functions

-
    -
  • get_y_position: compute the p-value y positions

  • -
  • add_y_position: add p-value y positions to an object of class rstatix_test

  • -
  • add_x_position: compute and add p-value x positions.

  • -
  • add_xy_position: compute and add both x and y positions.

  • -
- -

Examples

-
# Data preparation -#:::::::::::::::::::::::::::::::::::: -df <- ToothGrowth -df$dose <- as.factor(df$dose) -df$group <- factor(rep(c(1, 2), 30)) -head(df)
#> len supp dose group -#> 1 4.2 VC 0.5 1 -#> 2 11.5 VC 0.5 2 -#> 3 7.3 VC 0.5 1 -#> 4 5.8 VC 0.5 2 -#> 5 6.4 VC 0.5 1 -#> 6 10.0 VC 0.5 2
-# Stat tests -#:::::::::::::::::::::::::::::::::::: -stat.test <- df %>% - t_test(len ~ dose) -stat.test
#> # A tibble: 3 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 -6.48 38.0 1.27e- 7 2.54e- 7 **** -#> 2 len 0.5 2 20 20 -11.8 36.9 4.4 e-14 1.32e-13 **** -#> 3 len 1 2 20 20 -4.90 37.1 1.91e- 5 1.91e- 5 ****
-# Add the test into box plots -#:::::::::::::::::::::::::::::::::::: -stat.test <- stat.test %>% - add_y_position() -# \donttest{ - if(require("ggpubr")){ - ggboxplot(df, x = "dose", y = "len") + - stat_pvalue_manual(stat.test, label = "p.adj.signif", tip.length = 0.01) - }
# } -
+
  • get_y_position(): compute the p-value y positions

  • +
  • add_y_position(): add p-value y positions to an object of class rstatix_test

  • +
  • add_x_position(): compute and add p-value x positions.

  • +
  • add_xy_position(): compute and add both x and y positions.

  • +
+ +
+

Examples

+
# Data preparation
+#::::::::::::::::::::::::::::::::::::
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+df$group <- factor(rep(c(1, 2), 30))
+head(df)
+#>    len supp dose group
+#> 1  4.2   VC  0.5     1
+#> 2 11.5   VC  0.5     2
+#> 3  7.3   VC  0.5     1
+#> 4  5.8   VC  0.5     2
+#> 5  6.4   VC  0.5     1
+#> 6 10.0   VC  0.5     2
+
+# Stat tests
+#::::::::::::::::::::::::::::::::::::
+stat.test <- df %>%
+  t_test(len ~ dose)
+stat.test
+#> # A tibble: 3 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df        p    p.adj p.adj.signif
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 len   0.5    1         20    20     -6.48  38.0 1.27e- 7 2.54e- 7 ****        
+#> 2 len   0.5    2         20    20    -11.8   36.9 4.4 e-14 1.32e-13 ****        
+#> 3 len   1      2         20    20     -4.90  37.1 1.91e- 5 1.91e- 5 ****        
+
+# Add the test into box plots
+#::::::::::::::::::::::::::::::::::::
+stat.test <- stat.test %>%
+  add_y_position()
+# \donttest{
+ if(require("ggpubr")){
+   ggboxplot(df, x = "dose", y = "len") +
+     stat_pvalue_manual(stat.test, label = "p.adj.signif", tip.length = 0.01)
+  }
+
+# }
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_summary_stats.html b/docs/reference/get_summary_stats.html index 1a8a5fd..3443cbe 100644 --- a/docs/reference/get_summary_stats.html +++ b/docs/reference/get_summary_stats.html @@ -1,69 +1,12 @@ - - - - - - - -Compute Summary Statistics — get_summary_stats • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Summary Statistics — get_summary_stats • rstatix - - + + - - -
-
- -
- -
+
@@ -122,51 +52,51 @@

Compute Summary Statistics

Compute summary statistics for one or multiple numeric variables.

-
get_summary_stats(
-  data,
-  ...,
-  type = c("full", "common", "robust", "five_number", "mean_sd", "mean_se", "mean_ci",
-    "median_iqr", "median_mad", "quantile", "mean", "median", "min", "max"),
-  show = NULL,
-  probs = seq(0, 1, 0.25)
-)
+
+
get_summary_stats(
+  data,
+  ...,
+  type = c("full", "common", "robust", "five_number", "mean_sd", "mean_se", "mean_ci",
+    "median_iqr", "median_mad", "quantile", "mean", "median", "min", "max"),
+  show = NULL,
+  probs = seq(0, 1, 0.25)
+)
+
+ +
+

Arguments

+
data
+

a data frame

-

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
data

a data frame

...

(optional) One or more unquoted expressions (or variable names) + +

...
+

(optional) One or more unquoted expressions (or variable names) separated by commas. Used to select a variable of interest. If no variable is specified, then the summary statistics of all numeric variables in the -data frame is computed.

type

type of summary statistics. Possible values include: "full", +data frame is computed.

+ + +
type
+

type of summary statistics. Possible values include: "full", "common", "robust", "five_number", "mean_sd", "mean_se", "mean_ci", -"median_iqr", "median_mad", "quantile", "mean", "median", "min", "max"

show

a character vector specifying the summary statistics you want to +"median_iqr", "median_mad", "quantile", "mean", "median", "min", "max"

+ + +
show
+

a character vector specifying the summary statistics you want to show. Example: show = c("n", "mean", "sd"). This is used to filter -the output after computation.

probs

numeric vector of probabilities with values in [0,1]. Used only when type = "quantile".

+the output after computation.

+ + +
probs
+

numeric vector of probabilities with values in [0,1]. Used only when type = "quantile".

-

Value

+
+
+

Value

+ -

A data frame containing descriptive statistics, such as:

    -
  • n: the number of individuals

  • +

    A data frame containing descriptive statistics, such as:

    • n: the number of individuals

    • min: minimum

    • max: maximum

    • median: median

    • @@ -180,77 +110,86 @@

      Value

      of the mean

    • se: standard error of the mean

    • ci: 95 percent confidence interval of the mean

    • -
    - - -

    Examples

    -
    # Full summary statistics -data("ToothGrowth") -ToothGrowth %>% get_summary_stats(len)
    #> # A tibble: 1 x 13 -#> variable n min max median q1 q3 iqr mad mean sd se -#> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 len 60 4.2 33.9 19.2 13.1 25.3 12.2 9.04 18.8 7.65 0.988 -#> # … with 1 more variable: ci <dbl>
    -# Summary statistics of grouped data -# Show only common summary -ToothGrowth %>% - group_by(dose, supp) %>% - get_summary_stats(len, type = "common")
    #> # A tibble: 6 x 12 -#> supp dose variable n min max median iqr mean sd se ci -#> <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 OJ 0.5 len 10 8.2 21.5 12.2 6.48 13.2 4.46 1.41 3.19 -#> 2 VC 0.5 len 10 4.2 11.5 7.15 4.95 7.98 2.75 0.869 1.96 -#> 3 OJ 1 len 10 14.5 27.3 23.4 5.35 22.7 3.91 1.24 2.80 -#> 4 VC 1 len 10 13.6 22.5 16.5 2.02 16.8 2.52 0.795 1.80 -#> 5 OJ 2 len 10 22.4 30.9 26.0 2.5 26.1 2.66 0.84 1.90 -#> 6 VC 2 len 10 18.5 33.9 26.0 5.42 26.1 4.80 1.52 3.43
    -# Robust summary statistics -ToothGrowth %>% get_summary_stats(len, type = "robust")
    #> # A tibble: 1 x 4 -#> variable n median iqr -#> <fct> <dbl> <dbl> <dbl> -#> 1 len 60 19.2 12.2
    -# Five number summary statistics -ToothGrowth %>% get_summary_stats(len, type = "five_number")
    #> # A tibble: 1 x 7 -#> variable n min max q1 median q3 -#> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 len 60 4.2 33.9 13.1 19.2 25.3
    -# Compute only mean and sd -ToothGrowth %>% get_summary_stats(len, type = "mean_sd")
    #> # A tibble: 1 x 4 -#> variable n mean sd -#> <fct> <dbl> <dbl> <dbl> -#> 1 len 60 18.8 7.65
    -# Compute full summary statistics but show only mean, sd, median, iqr -ToothGrowth %>% - get_summary_stats(len, show = c("mean", "sd", "median", "iqr"))
    #> # A tibble: 1 x 6 -#> variable n mean sd median iqr -#> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 len 60 18.8 7.65 19.2 12.2
    -
    +
+ +
+

Examples

+
# Full summary statistics
+data("ToothGrowth")
+ToothGrowth %>% get_summary_stats(len)
+#> # A tibble: 1 × 13
+#>   variable     n   min   max median    q1    q3   iqr   mad  mean    sd    se
+#>   <fct>    <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
+#> 1 len         60   4.2  33.9   19.2  13.1  25.3  12.2  9.04  18.8  7.65 0.988
+#> # … with 1 more variable: ci <dbl>
+
+# Summary statistics of grouped data
+# Show only common summary
+ToothGrowth %>%
+  group_by(dose, supp) %>%
+  get_summary_stats(len, type = "common")
+#> # A tibble: 6 × 12
+#>   supp   dose variable     n   min   max median   iqr  mean    sd    se    ci
+#>   <fct> <dbl> <fct>    <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
+#> 1 OJ      0.5 len         10   8.2  21.5  12.2   6.48 13.2   4.46 1.41   3.19
+#> 2 VC      0.5 len         10   4.2  11.5   7.15  4.95  7.98  2.75 0.869  1.96
+#> 3 OJ      1   len         10  14.5  27.3  23.4   5.35 22.7   3.91 1.24   2.80
+#> 4 VC      1   len         10  13.6  22.5  16.5   2.02 16.8   2.52 0.795  1.80
+#> 5 OJ      2   len         10  22.4  30.9  26.0   2.5  26.1   2.66 0.84   1.90
+#> 6 VC      2   len         10  18.5  33.9  26.0   5.42 26.1   4.80 1.52   3.43
+
+# Robust summary statistics
+ToothGrowth %>% get_summary_stats(len, type = "robust")
+#> # A tibble: 1 × 4
+#>   variable     n median   iqr
+#>   <fct>    <dbl>  <dbl> <dbl>
+#> 1 len         60   19.2  12.2
+
+# Five number summary statistics
+ToothGrowth %>% get_summary_stats(len, type = "five_number")
+#> # A tibble: 1 × 7
+#>   variable     n   min   max    q1 median    q3
+#>   <fct>    <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>
+#> 1 len         60   4.2  33.9  13.1   19.2  25.3
+
+# Compute only mean and sd
+ToothGrowth %>% get_summary_stats(len, type = "mean_sd")
+#> # A tibble: 1 × 4
+#>   variable     n  mean    sd
+#>   <fct>    <dbl> <dbl> <dbl>
+#> 1 len         60  18.8  7.65
+
+# Compute full summary statistics but show only mean, sd, median, iqr
+ToothGrowth %>%
+    get_summary_stats(len, show = c("mean", "sd", "median", "iqr"))
+#> # A tibble: 1 × 6
+#>   variable     n  mean    sd median   iqr
+#>   <fct>    <dbl> <dbl> <dbl>  <dbl> <dbl>
+#> 1 len         60  18.8  7.65   19.2  12.2
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_test_label.html b/docs/reference/get_test_label.html index 04f0abe..308478a 100644 --- a/docs/reference/get_test_label.html +++ b/docs/reference/get_test_label.html @@ -1,70 +1,13 @@ - - - - - - - -Extract Label Information from Statistical Tests — get_pwc_label • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Extract Label Information from Statistical Tests — get_pwc_label • rstatix - - - - + + -
-
- -
- -
+
@@ -124,217 +54,236 @@

Extract Label Information from Statistical Tests

labelling plots with test outputs.

-
get_pwc_label(stat.test, type = c("expression", "text"))
-
-get_test_label(
-  stat.test,
-  description = NULL,
-  p.col = "p",
-  type = c("expression", "text"),
-  correction = c("auto", "GG", "HF", "none"),
-  row = NULL,
-  detailed = FALSE
-)
-
-create_test_label(
-  statistic.text,
-  statistic,
-  p,
-  parameter = NA,
-  description = NULL,
-  n = NA,
-  effect.size = NA,
-  effect.size.text = NA,
-  type = c("expression", "text"),
-  detailed = FALSE
-)
-
-get_n(stat.test)
-
-get_description(stat.test)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
stat.test

statistical test results returned by rstatix -functions.

type

the label type. Can be one of "text" and "expression". Partial +

+
get_pwc_label(stat.test, type = c("expression", "text"))
+
+get_test_label(
+  stat.test,
+  description = NULL,
+  p.col = "p",
+  type = c("expression", "text"),
+  correction = c("auto", "GG", "HF", "none"),
+  row = NULL,
+  detailed = FALSE
+)
+
+create_test_label(
+  statistic.text,
+  statistic,
+  p,
+  parameter = NA,
+  description = NULL,
+  n = NA,
+  effect.size = NA,
+  effect.size.text = NA,
+  type = c("expression", "text"),
+  detailed = FALSE
+)
+
+get_n(stat.test)
+
+get_description(stat.test)
+
+ +
+

Arguments

+
stat.test
+

statistical test results returned by rstatix +functions.

+ + +
type
+

the label type. Can be one of "text" and "expression". Partial match allowed. If you want to add the label onto a ggplot, it might be -useful to specify type = "expresion".

description

the test description used as the prefix of the label. +useful to specify type = "expresion".

+ + +
description
+

the test description used as the prefix of the label. Examples of description are "ANOVA", "Two Way ANOVA". To remove the default description, specify description = NULL. If missing, we'll try to -guess the statistical test default description.

p.col

character specifying the column containing the p-value. Default -is "p", can be "p.adj".

correction

character, considered only in the case of ANOVA test. Which sphericity +guess the statistical test default description.

+ + +
p.col
+

character specifying the column containing the p-value. Default +is "p", can be "p.adj".

+ + +
correction
+

character, considered only in the case of ANOVA test. Which sphericity correction of the degrees of freedom should be reported for the within-subject factors (repeated measures). The default is set to "GG" corresponding to the Greenhouse-Geisser correction. Possible values are "GG", "HF" (i.e., Hyunh-Feldt correction), "none" (i.e., no correction) and "auto" (apply automatically GG correction if the sphericity assumption is not for within-subject -design.

row

numeric, the row index to be considered. If NULL, the last row is -automatically considered for ANOVA test.

detailed

logical value. If TRUE, returns detailed label.

statistic.text

character specifying the test statistic. For example +design.

+ + +
row
+

numeric, the row index to be considered. If NULL, the last row is +automatically considered for ANOVA test.

+ + +
detailed
+

logical value. If TRUE, returns detailed label.

+ + +
statistic.text
+

character specifying the test statistic. For example statistic.text = "F" (for ANOVA test ); statistic.text = "t" -(for t-test ).

statistic

the numeric value of a statistic.

p

the p-value of the test.

parameter

string containing the degree of freedom (if exists). Default +(for t-test ).

+ + +
statistic
+

the numeric value of a statistic.

+ + +
p
+

the p-value of the test.

+ + +
parameter
+

string containing the degree of freedom (if exists). Default is NA to accommodate non-parametric tests. For example parameter = "1,9" (for ANOVA test. Two parameters exist: DFn and -DFd); sparameter = "9" (for t-test ).

n

sample count, example: n = 10.

effect.size

the effect size value

effect.size.text

a character specifying the relevant effect size. For -example, for Cohens d statistic, effect.size.text = "d". You -can also use plotmath expression as follow quote(italic("d")).

+DFd); sparameter = "9" (for t-test ).

+ + +
n
+

sample count, example: n = 10.

+ -

Value

+
effect.size
+

the effect size value

-

a text label or an expression to pass to a plotting function.

-

Functions

+
effect.size.text
+

a character specifying the relevant effect size. For +example, for Cohens d statistic, effect.size.text = "d". You +can also use plotmath expression as follow quote(italic("d")).

+ +
+
+

Value

+ + +

a text label or an expression to pass to a plotting function.

+
+
+

Functions

-
    -
  • get_pwc_label: Extract label from pairwise comparisons.

  • -
  • get_test_label: Extract labels for statistical tests.

  • -
  • create_test_label: Create labels from user specified test results.

  • -
  • get_n: Extracts sample counts (n) from an rstatix test outputs. Returns a numeric vector.

  • -
  • get_description: Extracts the description of an rstatix test outputs. Returns a character vector.

  • -
- -

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# One-way ANOVA test -#::::::::::::::::::::::::::::::::::::::::: -anov <- df %>% anova_test(len ~ dose) -get_test_label(anov, detailed = TRUE, type = "text")
#> [1] "Anova, F(1,58) = 105.06, p = <0.0001, eta2[g] = 0.644"
-# Two-way ANOVA test -#::::::::::::::::::::::::::::::::::::::::: -anov <- df %>% anova_test(len ~ supp*dose) -get_test_label(anov, detailed = TRUE, type = "text", - description = "Two Way ANOVA")
#> [1] "Two Way ANOVA, F(1,56) = 5.33, p = 0.025, eta2[g] = 0.087"
- -# Kruskal-Wallis test -#::::::::::::::::::::::::::::::::::::::::: -kruskal<- df %>% kruskal_test(len ~ dose) -get_test_label(kruskal, detailed = TRUE, type = "text")
#> [1] "Kruskal-Wallis, X2(2) = 40.67, p = <0.0001, n = 60"
-# Wilcoxon test -#::::::::::::::::::::::::::::::::::::::::: -# Unpaired test -wilcox <- df %>% wilcox_test(len ~ supp) -get_test_label(wilcox, detailed = TRUE, type = "text")
#> [1] "Wilcoxon test, W = 575.5, p = 0.065, n = 60"
# Paired test -wilcox <- df %>% wilcox_test(len ~ supp, paired = TRUE) -get_test_label(wilcox, detailed = TRUE, type = "text")
#> [1] "Wilcoxon test, V = 350, p = 0.0043, n = 30"
-# T test -#::::::::::::::::::::::::::::::::::::::::: -ttest <- df %>% t_test(len ~ dose) -get_test_label(ttest, detailed = TRUE, type = "text")
#> [[1]] -#> [1] "T test, t(37.99) = -6.48, p = <0.0001, n = 40" -#> -#> [[2]] -#> [1] "T test, t(36.88) = -11.8, p = <0.0001, n = 40" -#> -#> [[3]] -#> [1] "T test, t(37.1) = -4.9, p = <0.0001, n = 40" -#>
- -# Pairwise comparisons labels -#::::::::::::::::::::::::::::::::::::::::: -get_pwc_label(ttest, type = "text")
#> [1] "pwc: T test; p.adjust: Holm"
- -# Create test labels -#::::::::::::::::::::::::::::::::::::::::: -create_test_label( - statistic.text = "F", statistic = 71.82, - parameter = "4, 294", - p = "<0.0001", - description = "ANOVA", - type = "text" -)
#> [1] "ANOVA, p = <0.0001"
- -# Extract infos -#::::::::::::::::::::::::::::::::::::::::: -stat.test <- df %>% t_test(len ~ dose) -get_n(stat.test)
#> [1] 40 40 40
get_description(stat.test)
#> [1] "T test"
- -
+
  • get_pwc_label(): Extract label from pairwise comparisons.

  • +
  • get_test_label(): Extract labels for statistical tests.

  • +
  • create_test_label(): Create labels from user specified test results.

  • +
  • get_n(): Extracts sample counts (n) from an rstatix test outputs. Returns a numeric vector.

  • +
  • get_description(): Extracts the description of an rstatix test outputs. Returns a character vector.

  • +
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# One-way ANOVA test
+#:::::::::::::::::::::::::::::::::::::::::
+anov <- df %>% anova_test(len ~ dose)
+get_test_label(anov, detailed = TRUE, type = "text")
+#> [1] "Anova, F(1,58) = 105.06, p = <0.0001, eta2[g] = 0.644"
+
+# Two-way ANOVA test
+#:::::::::::::::::::::::::::::::::::::::::
+anov <- df %>% anova_test(len ~ supp*dose)
+get_test_label(anov, detailed = TRUE, type = "text",
+   description = "Two Way ANOVA")
+#> [1] "Two Way ANOVA, F(1,56) = 5.33, p = 0.025, eta2[g] = 0.087"
+
+
+# Kruskal-Wallis test
+#:::::::::::::::::::::::::::::::::::::::::
+kruskal<- df %>% kruskal_test(len ~ dose)
+get_test_label(kruskal, detailed = TRUE, type = "text")
+#> [1] "Kruskal-Wallis, X2(2) = 40.67, p = <0.0001, n = 60"
+
+# Wilcoxon test
+#:::::::::::::::::::::::::::::::::::::::::
+# Unpaired test
+wilcox <- df %>% wilcox_test(len ~ supp)
+get_test_label(wilcox, detailed = TRUE, type = "text")
+#> [1] "Wilcoxon test, W = 575.5, p = 0.065, n = 60"
+# Paired test
+wilcox <- df %>% wilcox_test(len ~ supp, paired = TRUE)
+get_test_label(wilcox, detailed = TRUE, type = "text")
+#> [1] "Wilcoxon test, V = 350, p = 0.0043, n = 30"
+
+# T test
+#:::::::::::::::::::::::::::::::::::::::::
+ttest <- df %>% t_test(len ~ dose)
+get_test_label(ttest, detailed = TRUE, type = "text")
+#> [[1]]
+#> [1] "T test, t(37.99) = -6.48, p = <0.0001, n = 40"
+#> 
+#> [[2]]
+#> [1] "T test, t(36.88) = -11.8, p = <0.0001, n = 40"
+#> 
+#> [[3]]
+#> [1] "T test, t(37.1) = -4.9, p = <0.0001, n = 40"
+#> 
+
+
+# Pairwise comparisons labels
+#:::::::::::::::::::::::::::::::::::::::::
+get_pwc_label(ttest, type = "text")
+#> [1] "pwc: T test; p.adjust: Holm"
+
+
+# Create test labels
+#:::::::::::::::::::::::::::::::::::::::::
+create_test_label(
+  statistic.text = "F", statistic = 71.82,
+  parameter = "4, 294",
+  p = "<0.0001",
+  description = "ANOVA",
+  type = "text"
+)
+#> [1] "ANOVA, p = <0.0001"
+
+
+# Extract infos
+#:::::::::::::::::::::::::::::::::::::::::
+stat.test <- df %>% t_test(len ~ dose)
+get_n(stat.test)
+#> [1] 40 40 40
+get_description(stat.test)
+#> [1] "T test"
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/index.html b/docs/reference/index.html index 1665d09..c682211 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,68 +1,12 @@ - - - - - - - -Function reference • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Function reference • rstatix - + + - - - -
-
- -
- -
+
- - - - - - - - - - -
-

Descriptive Statistics

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+

Descriptive Statistics

+

get_summary_stats()

Compute Summary Statistics

+

freq_table()

Compute Frequency Table

+

get_mode()

Compute Mode

+

identify_outliers() is_outlier() is_extreme()

Identify Univariate Outliers Using Boxplot Methods

+

mahalanobis_distance()

Compute Mahalanobis Distance and Flag Multivariate Outliers

+

shapiro_test() mshapiro_test()

Shapiro-Wilk Normality Test

-

Comparing Means

+
+

Comparing Means

+

t_test() pairwise_t_test()

T-test

+

wilcox_test() pairwise_wilcox_test()

Wilcoxon Tests

+

sign_test() pairwise_sign_test()

Sign Test

+

anova_test() get_anova_table() print(<anova_test>) plot(<anova_test>)

Anova Test

+

welch_anova_test()

Welch One-Way ANOVA Test

+

kruskal_test()

Kruskal-Wallis Test

+

friedman_test()

Friedman Rank Sum Test

+

get_comparisons()

Create a List of Possible Comparisons Between Groups

+

get_y_position() add_y_position() add_x_position() add_xy_position()

Autocompute P-value Positions For Plotting Significance

-

ANOVA helpers

+
+

ANOVA helpers

+

factorial_design()

Build Factorial Designs for ANOVA

+

anova_summary()

Create Nice Summary Tables of ANOVA Results

-

Post-Hoc Analyses

+
+

Post-Hoc Analyses

+

tukey_hsd()

Tukey Honest Significant Differences

+

dunn_test()

Dunn's Test of Multiple Comparisons

+

games_howell_test()

Games Howell Post-hoc Tests

+

emmeans_test() get_emmeans()

Pairwise Comparisons of Estimated Marginal Means

-

Comparing Proportions

+
+

Comparing Proportions

+

prop_test() pairwise_prop_test() row_wise_prop_test()

Proportion Test

+

chisq_test() pairwise_chisq_gof_test() pairwise_chisq_test_against_p() chisq_descriptives() expected_freq() observed_freq() pearson_residuals() std_residuals()

Chi-squared Test for Count Data

+

fisher_test() pairwise_fisher_test() row_wise_fisher_test()

Fisher's Exact Test for Count Data

+

binom_test() pairwise_binom_test() pairwise_binom_test_against_p()

Exact Binomial Test

+

multinom_test()

Exact Multinomial Test

+

mcnemar_test() pairwise_mcnemar_test()

McNemar's Chi-squared Test for Count Data

+

cochran_qtest()

Cochran's Q Test

+

prop_trend_test()

Test for Trend in Proportions

-

Comparing Variances

+
+

Comparing Variances

+

levene_test()

Levene's Test

+

box_m()

Box's M-test for Homogeneity of Covariance Matrices

-

Effect Size

+
+

Effect Size

+

cohens_d()

Compute Cohen's d Measure of Effect Size

+

wilcox_effsize()

Wilcoxon Effect Size

+

eta_squared() partial_eta_squared()

Effect Size for ANOVA

+

kruskal_effsize()

Kruskal-Wallis Effect Size

+

friedman_effsize()

Friedman Test Effect Size (Kendall's W Value)

+

cramer_v()

Compute Cramer's V

-

Correlation analysis

+
+

Correlation analysis

+

cor_test()

Correlation Test

+

cor_mat() cor_pmat() cor_get_pval()

Compute Correlation Matrix with P-values

+

as_cor_mat()

Convert a Correlation Test Data Frame into a Correlation Matrix

+

cor_select()

Subset Correlation Matrix

+

pull_triangle() pull_upper_triangle() pull_lower_triangle()

Pull Lower and Upper Triangular Part of a Matrix

+

replace_triangle() replace_upper_triangle() replace_lower_triangle()

Replace Lower and Upper Triangular Part of a Matrix

+

cor_reorder()

Reorder Correlation Matrix

+

cor_gather() cor_spread()

Reshape Correlation Data

+

cor_as_symbols()

Replace Correlation Coefficients by Symbols

+

cor_plot()

Visualize Correlation Matrix Using Base Plot

+

cor_mark_significant()

Add Significance Levels To a Correlation Matrix

-

Adjust p-values and add significance symbols

+
+

Adjust p-values and add significance symbols

+

adjust_pvalue()

Adjust P-values for Multiple Comparisons

+

add_significance()

Add P-value Significance Symbols

-

Extract Information From Statistical Tests

+
+

p_round() p_format() p_mark_significant() p_detect() p_names() p_adj_names()

+

Rounding and Formatting p-values

+

Extract Information From Statistical Tests

+

get_pwc_label() get_test_label() create_test_label() get_n() get_description()

Extract Label Information from Statistical Tests

+

remove_ns()

Remove Non-Significant from Statistical Tests

-

Data Manipulation Helper Functions

-

These functions are internally used in rstatix and in ggpubr R package to make it easy to program with tidyverse packages using non standard evaluation.

+
+

Data Manipulation Helper Functions

+

These functions are internally used in rstatix and in ggpubr R package to make it easy to program with tidyverse packages using non standard evaluation.

+

df_select()

Select Columns in a Data Frame

+

df_arrange()

Arrange Rows by Column Values

+

df_group_by()

Group a Data Frame by One or more Variables

+

df_nest_by()

Nest a Tibble By Groups

+

df_split_by()

Split a Data Frame into Subset

+

df_unite() df_unite_factors()

Unite Multiple Columns into One

+

df_label_both() df_label_value()

Functions to Label Data Frames by Grouping Variables

+

df_get_var_names()

Get User Specified Variable Names

-

Others

+
+

Others

-

reexports

+
+

reexports tibble mutate filter group_by select desc drop_na gather spread tidy augment Anova

Objects exported from other packages

+

doo()

Alternative to dplyr::do for Doing Anything

+

sample_n_by()

Sample n Rows By Group From a Table

+

convert_as_factor() set_ref_level() reorder_levels()

Factors

+

make_clean_names()

Make Clean Names

+

counts_to_cases()

Convert a Table of Counts into a Data Frame of cases

- +
+
-
- +
- - + + diff --git a/docs/reference/kruskal_effsize.html b/docs/reference/kruskal_effsize.html index 05a47ae..90b2caa 100644 --- a/docs/reference/kruskal_effsize.html +++ b/docs/reference/kruskal_effsize.html @@ -1,48 +1,5 @@ - - - - - - - -Kruskal-Wallis Effect Size — kruskal_effsize • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Kruskal-Wallis Effect Size — kruskal_effsize • rstatix - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -142,113 +72,115 @@

Kruskal-Wallis Effect Size

Confidence intervals are calculated by bootstap.

-
kruskal_effsize(
-  data,
-  formula,
-  ci = FALSE,
-  conf.level = 0.95,
-  ci.type = "perc",
-  nboot = 1000
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
kruskal_effsize(
+  data,
+  formula,
+  ci = FALSE,
+  conf.level = 0.95,
+  ci.type = "perc",
+  nboot = 1000
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

ci

If TRUE, returns confidence intervals by bootstrap. May be slow.

conf.level

The level for the confidence interval.

ci.type

The type of confidence interval to use. Can be any of "norm", -"basic", "perc", or "bca". Passed to boot::boot.ci.

nboot

The number of replications to use for bootstrap.

- -

Value

- -

return a data frame with some of the following columns:

    -
  • .y.: the y variable used in the test.

  • +formula = TP53 ~ cancer_group.

    + + +
    ci
    +

    If TRUE, returns confidence intervals by bootstrap. May be slow.

    + + +
    conf.level
    +

    The level for the confidence interval.

    + + +
    ci.type
    +

    The type of confidence interval to use. Can be any of "norm", +"basic", "perc", or "bca". Passed to boot::boot.ci.

    + + +
    nboot
    +

    The number of replications to use for bootstrap.

    + +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y variable used in the test.

  • n: Sample counts.

  • effsize: estimate of the effect size.

  • magnitude: magnitude of effect size.

  • conf.low,conf.high: lower and upper bound of the effect size confidence interval.

  • -
- -

References

- +
+
+

References

Maciej Tomczak and Ewa Tomczak. The need to report effect size estimates revisited. An overview of some recommended measures of effect size. Trends in Sport Sciences. 2014; 1(21):19-25.

http://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize

http://www.psy.gla.ac.uk/~steve/best/effect.html

+
-

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# Kruskal-wallis rank sum test -#::::::::::::::::::::::::::::::::::::::::: -df %>% kruskal_effsize(len ~ dose)
#> # A tibble: 1 x 5 -#> .y. n effsize method magnitude -#> * <chr> <int> <dbl> <chr> <ord> -#> 1 len 60 0.678 eta2[H] large
-# Grouped data -df %>% - group_by(supp) %>% - kruskal_effsize(len ~ dose)
#> # A tibble: 2 x 6 -#> supp .y. n effsize method magnitude -#> * <fct> <chr> <int> <dbl> <chr> <ord> -#> 1 OJ len 30 0.611 eta2[H] large -#> 2 VC len 30 0.855 eta2[H] large
+
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# Kruskal-wallis rank sum test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% kruskal_effsize(len ~ dose)
+#> # A tibble: 1 × 5
+#>   .y.       n effsize method  magnitude
+#> * <chr> <int>   <dbl> <chr>   <ord>    
+#> 1 len      60   0.678 eta2[H] large    
+
+# Grouped data
+df %>%
+  group_by(supp) %>%
+  kruskal_effsize(len ~ dose)
+#> # A tibble: 2 × 6
+#>   supp  .y.       n effsize method  magnitude
+#> * <fct> <chr> <int>   <dbl> <chr>   <ord>    
+#> 1 OJ    len      30   0.611 eta2[H] large    
+#> 2 VC    len      30   0.855 eta2[H] large    
+
+
+
-
- +
- - + + diff --git a/docs/reference/kruskal_test.html b/docs/reference/kruskal_test.html index 05616d5..c77a88f 100644 --- a/docs/reference/kruskal_test.html +++ b/docs/reference/kruskal_test.html @@ -1,71 +1,14 @@ - - - - - - - -Kruskal-Wallis Test — kruskal_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Kruskal-Wallis Test — kruskal_test • rstatix - - - - - - - - - + + - - - - -
-
- -
- -
+

Provides a pipe-friendly framework to perform Kruskal-Wallis rank sum test. Wrapper around the function - kruskal.test().

+ kruskal.test().

+
+ +
+
kruskal_test(data, formula, ...)
-
kruskal_test(data, formula, ...)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

...

other arguments to be passed to the function -kruskal.test.

- -

Value

- -

return a data frame with the following columns:

    -
  • .y.: the y variable used in the test.

  • +formula = TP53 ~ cancer_group.

    + + +
    ...
    +

    other arguments to be passed to the function +kruskal.test.

    + +
+
+

Value

+ + +

return a data frame with the following columns:

  • .y.: the y variable used in the test.

  • n: sample count.

  • statistic: the kruskal-wallis rank sum statistic used to compute the p-value.

  • p: p-value.

  • method: the statistical test used to compare groups.

  • -
- - -

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# Kruskal-wallis rank sum test -#::::::::::::::::::::::::::::::::::::::::: -df %>% kruskal_test(len ~ dose)
#> # A tibble: 1 x 6 -#> .y. n statistic df p method -#> * <chr> <int> <dbl> <int> <dbl> <chr> -#> 1 len 60 40.7 2 0.00000000148 Kruskal-Wallis
-# Grouped data -df %>% - group_by(supp) %>% - kruskal_test(len ~ dose)
#> # A tibble: 2 x 7 -#> supp .y. n statistic df p method -#> * <fct> <chr> <int> <dbl> <int> <dbl> <chr> -#> 1 OJ len 30 18.5 2 0.0000958 Kruskal-Wallis -#> 2 VC len 30 25.1 2 0.00000359 Kruskal-Wallis
+
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# Kruskal-wallis rank sum test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% kruskal_test(len ~ dose)
+#> # A tibble: 1 × 6
+#>   .y.       n statistic    df             p method        
+#> * <chr> <int>     <dbl> <int>         <dbl> <chr>         
+#> 1 len      60      40.7     2 0.00000000148 Kruskal-Wallis
+
+# Grouped data
+df %>%
+  group_by(supp) %>%
+  kruskal_test(len ~ dose)
+#> # A tibble: 2 × 7
+#>   supp  .y.       n statistic    df          p method        
+#> * <fct> <chr> <int>     <dbl> <int>      <dbl> <chr>         
+#> 1 OJ    len      30      18.5     2 0.0000958  Kruskal-Wallis
+#> 2 VC    len      30      25.1     2 0.00000359 Kruskal-Wallis
+
+
+
-
- +
- - + + diff --git a/docs/reference/levene_test.html b/docs/reference/levene_test.html index 00ebd9c..022f578 100644 --- a/docs/reference/levene_test.html +++ b/docs/reference/levene_test.html @@ -1,72 +1,15 @@ - - - - - - - -Levene's Test — levene_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Levene's Test — levene_test • rstatix - - - - - - - - - + + - - - - -
-
- -
- -
+

Provide a pipe-friendly framework to easily compute Levene's test for homogeneity of variance across groups.

-

Wrapper around the function leveneTest(), which can +

Wrapper around the function leveneTest(), which can additionally handles a grouped data.

-
levene_test(data, formula, center = median)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame for evaluating the formula or a model

formula

a formula

center

The name of a function to compute the center of each group; +

+
levene_test(data, formula, center = median)
+
+ +
+

Arguments

+
data
+

a data frame for evaluating the formula or a model

+ + +
formula
+

a formula

+ + +
center
+

The name of a function to compute the center of each group; mean gives the original Levene's test; the default, median, provides a more -robust test.

+robust test.

-

Value

+
+
+

Value

+ -

a data frame with the following columns: df1, df2 +

a data frame with the following columns: df1, df2 (df.residual), statistic and p.

+
-

Examples

-
# Prepare the data -data("ToothGrowth") -df <- ToothGrowth -df$dose <- as.factor(df$dose) -# Compute Levene's Test -df %>% levene_test(len ~ dose)
#> # A tibble: 1 x 4 -#> df1 df2 statistic p -#> <int> <int> <dbl> <dbl> -#> 1 2 57 0.646 0.528
-# Grouped data -df %>% - group_by(supp) %>% - levene_test(len ~ dose)
#> # A tibble: 2 x 5 -#> supp df1 df2 statistic p -#> <fct> <int> <int> <dbl> <dbl> -#> 1 OJ 2 27 1.84 0.178 -#> 2 VC 2 27 2.17 0.134
-
+
+

Examples

+
# Prepare the data
+data("ToothGrowth")
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+# Compute Levene's Test
+df %>% levene_test(len ~ dose)
+#> # A tibble: 1 × 4
+#>     df1   df2 statistic     p
+#>   <int> <int>     <dbl> <dbl>
+#> 1     2    57     0.646 0.528
+
+# Grouped data
+df %>%
+  group_by(supp) %>%
+  levene_test(len ~ dose)
+#> # A tibble: 2 × 5
+#>   supp    df1   df2 statistic     p
+#>   <fct> <int> <int>     <dbl> <dbl>
+#> 1 OJ        2    27      1.84 0.178
+#> 2 VC        2    27      2.17 0.134
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/mahalanobis_distance.html b/docs/reference/mahalanobis_distance.html index db2a566..ec2a940 100644 --- a/docs/reference/mahalanobis_distance.html +++ b/docs/reference/mahalanobis_distance.html @@ -1,48 +1,5 @@ - - - - - - - -Compute Mahalanobis Distance and Flag Multivariate Outliers — mahalanobis_distance • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Compute Mahalanobis Distance and Flag Multivariate Outliers — mahalanobis_distance • rstatix - - - - - - - - - - - + + - - -
-
- -
- -
+

Pipe-friendly wrapper around to the function - mahalanobis(), which returns the squared + mahalanobis(), which returns the squared Mahalanobis distance of all rows in x. Compared to the base function, it automatically flags multivariate outliers.

Mahalanobis distance is a common metric used to identify multivariate @@ -146,85 +76,89 @@

Compute Mahalanobis Distance and Flag Multivariate Outliers

a chi-square (X^2) distribution with degrees of freedom equal to the number of dependent (outcome) variables and an alpha level of 0.001.

The threshold to declare a multivariate outlier is determined using the - function qchisq(0.999, df) , where df is the degree of freedom (i.e., + function qchisq(0.999, df) , where df is the degree of freedom (i.e., the number of dependent variable used in the computation).

-
mahalanobis_distance(data, ...)
- -

Arguments

- - - - - - - - - - -
data

a data frame. Columns are variables.

...

One unquoted expressions (or variable name). Used to select a +

+
mahalanobis_distance(data, ...)
+
+ +
+

Arguments

+
data
+

a data frame. Columns are variables.

+ + +
...
+

One unquoted expressions (or variable name). Used to select a variable of interest. Can be also used to ignore a variable that are not needed for the computation. For example specify -id to ignore the id -column.

+column.

-

Value

+
+
+

Value

+ -

Returns the input data frame with two additional columns: 1) +

Returns the input data frame with two additional columns: 1) "mahal.dist": Mahalanobis distance values; and 2) "is.outlier": logical values specifying whether a given observation is a multivariate outlier

+
-

Examples

-
-# Compute mahalonobis distance and flag outliers if any -iris %>% - doo(~mahalanobis_distance(.))
#> # A tibble: 150 x 6 -#> Sepal.Length Sepal.Width Petal.Length Petal.Width mahal.dist is.outlier -#> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> -#> 1 5.1 3.5 1.4 0.2 2.13 FALSE -#> 2 4.9 3 1.4 0.2 2.85 FALSE -#> 3 4.7 3.2 1.3 0.2 2.08 FALSE -#> 4 4.6 3.1 1.5 0.2 2.45 FALSE -#> 5 5 3.6 1.4 0.2 2.46 FALSE -#> 6 5.4 3.9 1.7 0.4 3.88 FALSE -#> 7 4.6 3.4 1.4 0.3 2.86 FALSE -#> 8 5 3.4 1.5 0.2 1.83 FALSE -#> 9 4.4 2.9 1.4 0.2 3.38 FALSE -#> 10 4.9 3.1 1.5 0.1 2.38 FALSE -#> # … with 140 more rows
-# Compute distance by groups and filter outliers -iris %>% - group_by(Species) %>% - doo(~mahalanobis_distance(.)) %>% - filter(is.outlier == TRUE)
#> # A tibble: 0 x 7 -#> # … with 7 variables: Species <fct>, Sepal.Length <dbl>, Sepal.Width <dbl>, -#> # Petal.Length <dbl>, Petal.Width <dbl>, mahal.dist <dbl>, is.outlier <lgl>
-
+
+

Examples

+

+# Compute mahalonobis distance and flag outliers if any
+iris %>%
+  doo(~mahalanobis_distance(.))
+#> # A tibble: 150 × 6
+#>    Sepal.Length Sepal.Width Petal.Length Petal.Width mahal.dist is.outlier
+#>           <dbl>       <dbl>        <dbl>       <dbl>      <dbl> <lgl>     
+#>  1          5.1         3.5          1.4         0.2       2.13 FALSE     
+#>  2          4.9         3            1.4         0.2       2.85 FALSE     
+#>  3          4.7         3.2          1.3         0.2       2.08 FALSE     
+#>  4          4.6         3.1          1.5         0.2       2.45 FALSE     
+#>  5          5           3.6          1.4         0.2       2.46 FALSE     
+#>  6          5.4         3.9          1.7         0.4       3.88 FALSE     
+#>  7          4.6         3.4          1.4         0.3       2.86 FALSE     
+#>  8          5           3.4          1.5         0.2       1.83 FALSE     
+#>  9          4.4         2.9          1.4         0.2       3.38 FALSE     
+#> 10          4.9         3.1          1.5         0.1       2.38 FALSE     
+#> # … with 140 more rows
+
+# Compute distance by groups and filter outliers
+iris %>%
+ group_by(Species) %>%
+ doo(~mahalanobis_distance(.)) %>%
+ filter(is.outlier == TRUE)
+#> # A tibble: 0 × 7
+#> # … with 7 variables: Species <fct>, Sepal.Length <dbl>, Sepal.Width <dbl>,
+#> #   Petal.Length <dbl>, Petal.Width <dbl>, mahal.dist <dbl>, is.outlier <lgl>
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/make_clean_names.html b/docs/reference/make_clean_names.html index 9b33a23..71f729d 100644 --- a/docs/reference/make_clean_names.html +++ b/docs/reference/make_clean_names.html @@ -1,70 +1,13 @@ - - - - - - - -Make Clean Names — make_clean_names • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Make Clean Names — make_clean_names • rstatix - - + + - - -
-
- -
- -
+
@@ -124,66 +54,74 @@

Make Clean Names

character vectors.

-
make_clean_names(data)
- -

Arguments

- - - - - - -
data

a data frame or vector

- -

Value

- -

a data frame or a vector depending on the input data

- -

Examples

-
-# Vector -make_clean_names(c("a and b", "a-and-b"))
#> [1] "a.and.b" "a.and.b"
make_clean_names(1:10)
#> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10"
-# data frame -df <- data.frame( -`a and b` = 1:4, -`c and d` = 5:8, - check.names = FALSE -) -df
#> a and b c and d -#> 1 1 5 -#> 2 2 6 -#> 3 3 7 -#> 4 4 8
make_clean_names(df)
#> a.and.b c.and.d -#> 1 1 5 -#> 2 2 6 -#> 3 3 7 -#> 4 4 8
-
+
+
make_clean_names(data)
+
+ +
+

Arguments

+
data
+

a data frame or vector

+ +
+
+

Value

+ + +

a data frame or a vector depending on the input data

+
+ +
+

Examples

+

+# Vector
+make_clean_names(c("a and b", "a-and-b"))
+#> [1] "a.and.b" "a.and.b"
+make_clean_names(1:10)
+#>  [1] "X1"  "X2"  "X3"  "X4"  "X5"  "X6"  "X7"  "X8"  "X9"  "X10"
+
+# data frame
+df <- data.frame(
+`a and b` = 1:4,
+`c and d` = 5:8,
+ check.names = FALSE
+)
+df
+#>   a and b c and d
+#> 1       1       5
+#> 2       2       6
+#> 3       3       7
+#> 4       4       8
+make_clean_names(df)
+#>   a.and.b c.and.d
+#> 1       1       5
+#> 2       2       6
+#> 3       3       7
+#> 4       4       8
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/mcnemar_test.html b/docs/reference/mcnemar_test.html index 27aa9db..f351f3c 100644 --- a/docs/reference/mcnemar_test.html +++ b/docs/reference/mcnemar_test.html @@ -1,71 +1,14 @@ - - - - - - - -McNemar's Chi-squared Test for Count Data — mcnemar_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -McNemar's Chi-squared Test for Count Data — mcnemar_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Performs McNemar chi-squared test to compare paired proportions.

-

Wrappers around the R base function mcnemar.test(), but +

Wrappers around the R base function mcnemar.test(), but provide pairwise comparisons between multiple groups

-
mcnemar_test(x, y = NULL, correct = TRUE)
+    
+
mcnemar_test(x, y = NULL, correct = TRUE)
+
+pairwise_mcnemar_test(
+  data,
+  formula,
+  type = c("mcnemar", "exact"),
+  correct = TRUE,
+  p.adjust.method = "bonferroni"
+)
+
+ +
+

Arguments

+
x
+

either a two-dimensional contingency table in matrix form, + or a factor object.

+ + +
y
+

a factor object; ignored if x is a matrix.

+ + +
correct
+

a logical indicating whether to apply continuity + correction when computing the test statistic.

+ + +
data
+

a data frame containing the variables in the formula.

-pairwise_mcnemar_test( - data, - formula, - type = c("mcnemar", "exact"), - correct = TRUE, - p.adjust.method = "bonferroni" -)
-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

either a two-dimensional contingency table in matrix form, - or a factor object.

y

a factor object; ignored if x is a matrix.

correct

a logical indicating whether to apply continuity - correction when computing the test statistic.

data

a data frame containing the variables in the formula.

formula

a formula of the form a ~ b | c, where a is the +

formula
+

a formula of the form a ~ b | c, where a is the outcome variable name; b is the within-subjects factor variables; and c (factor) is the column name containing individuals/subjects identifier. -Should be unique per individual.

type

type of statistical tests used for pairwise comparisons. Allowed -values are one of c("mcnemar", "exact").

p.adjust.method

method to adjust p values for multiple comparisons. +Should be unique per individual.

+ + +
type
+

type of statistical tests used for pairwise comparisons. Allowed +values are one of c("mcnemar", "exact").

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

+want to adjust the p value (not recommended), use p.adjust.method = "none".

-

Value

+
+
+

Value

+ -

return a data frame with the following columns:

    -
  • n: the number of participants.

  • +

    return a data frame with the following columns:

    • n: the number of participants.

    • statistic: the value of McNemar's statistic.

    • df the degrees of freedom of the approximate chi-squared distribution of the test @@ -191,96 +121,102 @@

      Value

      p-value.

    • method: the used statistical test.

    • p.signif: the significance level of p-values.

    • -
    - -

    The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Functions

- +
+
+

Functions

-
    -
  • mcnemar_test: performs McNemar's chi-squared test for comparing two +

    • mcnemar_test(): performs McNemar's chi-squared test for comparing two paired proportions

    • -
    • pairwise_mcnemar_test: performs pairwise McNemar's chi-squared test between +

    • pairwise_mcnemar_test(): performs pairwise McNemar's chi-squared test between multiple groups. Could be used for post-hoc tests following a significant Cochran's Q test.

    • -
    - -

    Examples

    -
    -# Comparing two paired proportions -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: frequencies of smokers before and after interventions -xtab <- as.table( - rbind(c(25, 6), c(21,10)) -) -dimnames(xtab) <- list( - before = c("non.smoker", "smoker"), - after = c("non.smoker", "smoker") -) -xtab
    #> after -#> before non.smoker smoker -#> non.smoker 25 6 -#> smoker 21 10
    -# Compare the proportion of smokers -mcnemar_test(xtab)
    #> # A tibble: 1 x 6 -#> n statistic df p p.signif method -#> * <dbl> <dbl> <dbl> <dbl> <chr> <chr> -#> 1 62 7.26 1 0.00705 ** McNemar test
    -# Comparing multiple related proportions -# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Generate a demo data -mydata <- data.frame( - outcome = c(0,1,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1), - treatment = gl(3,1,30,labels=LETTERS[1:3]), - participant = gl(10,3,labels=letters[1:10]) -) -mydata$outcome <- factor( - mydata$outcome, levels = c(1, 0), - labels = c("success", "failure") - ) -# Cross-tabulation -xtabs(~outcome + treatment, mydata)
    #> treatment -#> outcome A B C -#> success 2 5 10 -#> failure 8 5 0
    -# Compare the proportion of success between treatments -cochran_qtest(mydata, outcome ~ treatment|participant)
    #> # A tibble: 1 x 6 -#> .y. n statistic df p method -#> * <chr> <int> <dbl> <dbl> <dbl> <chr> -#> 1 outcome 10 10.9 2 0.00432 Cochran's Q test
    -# pairwise comparisons between groups -pairwise_mcnemar_test(mydata, outcome ~ treatment|participant)
    #> # A tibble: 3 x 6 -#> group1 group2 p p.adj p.adj.signif method -#> * <chr> <chr> <dbl> <dbl> <chr> <chr> -#> 1 A B 0.371 1 ns McNemar test -#> 2 A C 0.0133 0.0399 * McNemar test -#> 3 B C 0.0736 0.221 ns McNemar test
    -
    +
+ +
+

Examples

+

+# Comparing two paired proportions
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: frequencies of smokers before and after interventions
+xtab <- as.table(
+  rbind(c(25, 6), c(21,10))
+)
+dimnames(xtab) <- list(
+  before = c("non.smoker", "smoker"),
+  after = c("non.smoker", "smoker")
+)
+xtab
+#>             after
+#> before       non.smoker smoker
+#>   non.smoker         25      6
+#>   smoker             21     10
+
+# Compare the proportion of smokers
+mcnemar_test(xtab)
+#> # A tibble: 1 × 6
+#>       n statistic    df       p p.signif method      
+#> * <dbl>     <dbl> <dbl>   <dbl> <chr>    <chr>       
+#> 1    62      7.26     1 0.00705 **       McNemar test
+
+# Comparing multiple related proportions
+# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Generate a demo data
+mydata <- data.frame(
+  outcome = c(0,1,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1),
+  treatment = gl(3,1,30,labels=LETTERS[1:3]),
+  participant = gl(10,3,labels=letters[1:10])
+)
+mydata$outcome <- factor(
+  mydata$outcome, levels = c(1, 0),
+  labels = c("success", "failure")
+  )
+# Cross-tabulation
+xtabs(~outcome + treatment, mydata)
+#>          treatment
+#> outcome    A  B  C
+#>   success  2  5 10
+#>   failure  8  5  0
+
+# Compare the proportion of success between treatments
+cochran_qtest(mydata, outcome ~ treatment|participant)
+#> # A tibble: 1 × 6
+#>   .y.         n statistic    df       p method          
+#> * <chr>   <int>     <dbl> <dbl>   <dbl> <chr>           
+#> 1 outcome    10      10.9     2 0.00432 Cochran's Q test
+
+# pairwise comparisons between groups
+pairwise_mcnemar_test(mydata, outcome ~ treatment|participant)
+#> # A tibble: 3 × 6
+#>   group1 group2      p  p.adj p.adj.signif method      
+#> * <chr>  <chr>   <dbl>  <dbl> <chr>        <chr>       
+#> 1 A      B      0.371  1      ns           McNemar test
+#> 2 A      C      0.0133 0.0399 *            McNemar test
+#> 3 B      C      0.0736 0.221  ns           McNemar test
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/multinom_test.html b/docs/reference/multinom_test.html index 88b2933..e4d1803 100644 --- a/docs/reference/multinom_test.html +++ b/docs/reference/multinom_test.html @@ -1,70 +1,13 @@ - - - - - - - -Exact Multinomial Test — multinom_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Exact Multinomial Test — multinom_test • rstatix - - - - + + -
-
- -
- -
+
@@ -124,110 +54,126 @@

Exact Multinomial Test

size is small.

-
multinom_test(x, p = rep(1/length(x), length(x)), detailed = FALSE)
- -

Arguments

- - - - - - - - - - - - - - -
x

numeric vector containing the counts.

p

a vector of probabilities of success. The length of p must be the +

+
multinom_test(x, p = rep(1/length(x), length(x)), detailed = FALSE)
+
+ +
+

Arguments

+
x
+

numeric vector containing the counts.

+ + +
p
+

a vector of probabilities of success. The length of p must be the same as the number of groups specified by x, and its elements must be -greater than 0 and less than 1.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

- -

Value

- -

return a data frame containing the p-value and its significance.

+greater than 0 and less than 1.

+ + +
detailed
+

logical value. Default is FALSE. If TRUE, a detailed result is +shown.

+ +
+
+

Value

+ + +

return a data frame containing the p-value and its significance.

+ +

The returned object has an attribute called args, which is a list holding the test arguments.

-

See also

- - - -

Examples

-
# Data -tulip <- c(red = 81, yellow = 50, white = 27) - -# Question 1: are the color equally common ? -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# this is a test of homogeneity -res <- multinom_test(tulip) -res
#> # A tibble: 1 x 2 -#> p p.signif -#> * <dbl> <chr> -#> 1 0.000000711 ****
-attr(res, "descriptives")
#> # A tibble: 3 x 3 -#> group observed expected -#> <chr> <dbl> <dbl> -#> 1 red 81 52.7 -#> 2 yellow 50 52.7 -#> 3 white 27 52.7
-# Pairwise comparisons between groups -pairwise_binom_test(tulip, p.adjust.method = "bonferroni")
#> # A tibble: 3 x 9 -#> group1 group2 n estimate conf.low conf.high p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 red yellow 131 0.618 0.529 0.702 8.51e-3 2.55e-2 * -#> 2 red white 108 0.75 0.657 0.828 1.91e-7 5.72e-7 **** -#> 3 yellow white 77 0.649 0.532 0.755 1.17e-2 3.5 e-2 *
- -# Question 2: comparing observed to expected proportions -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# this is a goodness-of-fit test -expected.p <- c(red = 0.5, yellow = 0.33, white = 0.17) -res <- multinom_test(tulip, expected.p) -res
#> # A tibble: 1 x 2 -#> p p.signif -#> * <dbl> <chr> -#> 1 0.942 ns
attr(res, "descriptives")
#> # A tibble: 3 x 3 -#> group observed expected -#> <chr> <dbl> <dbl> -#> 1 red 81 79 -#> 2 yellow 50 52.1 -#> 3 white 27 26.9
-# Pairwise comparisons against a given probabilities -pairwise_binom_test_against_p(tulip, expected.p)
#> # A tibble: 3 x 10 -#> group observed expected n estimate conf.low conf.high p p.adj -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 red 81 79 158 0.513 0.432 0.593 0.811 1 -#> 2 yellow 50 52.1 158 0.316 0.245 0.395 0.800 1 -#> 3 white 27 26.9 158 0.171 0.116 0.239 1 1 -#> # … with 1 more variable: p.adj.signif <chr>
+
+
+

See also

+ +
+ +
+

Examples

+
# Data
+tulip <- c(red = 81, yellow = 50, white = 27)
+
+# Question 1: are the color equally common ?
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# this is a test of homogeneity
+res <- multinom_test(tulip)
+res
+#> # A tibble: 1 × 2
+#>             p p.signif
+#> *       <dbl> <chr>   
+#> 1 0.000000711 ****    
+
+attr(res, "descriptives")
+#> # A tibble: 3 × 3
+#>   group  observed expected
+#>   <chr>     <dbl>    <dbl>
+#> 1 red          81     52.7
+#> 2 yellow       50     52.7
+#> 3 white        27     52.7
+
+# Pairwise comparisons between groups
+pairwise_binom_test(tulip, p.adjust.method = "bonferroni")
+#> # A tibble: 3 × 9
+#>   group1 group2     n estimate conf.low conf.high           p      p.adj p.adj…¹
+#> * <chr>  <chr>  <dbl>    <dbl>    <dbl>     <dbl>       <dbl>      <dbl> <chr>  
+#> 1 red    yellow   131    0.618    0.529     0.702 0.00851        2.55e-2 *      
+#> 2 red    white    108    0.75     0.657     0.828 0.000000191    5.72e-7 ****   
+#> 3 yellow white     77    0.649    0.532     0.755 0.0117         3.5 e-2 *      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+# Question 2: comparing observed to expected proportions
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# this is a goodness-of-fit test
+expected.p <- c(red = 0.5, yellow = 0.33, white = 0.17)
+res <- multinom_test(tulip, expected.p)
+res
+#> # A tibble: 1 × 2
+#>       p p.signif
+#> * <dbl> <chr>   
+#> 1 0.942 ns      
+attr(res, "descriptives")
+#> # A tibble: 3 × 3
+#>   group  observed expected
+#>   <chr>     <dbl>    <dbl>
+#> 1 red          81     79  
+#> 2 yellow       50     52.1
+#> 3 white        27     26.9
+
+# Pairwise comparisons against a given probabilities
+pairwise_binom_test_against_p(tulip, expected.p)
+#> # A tibble: 3 × 10
+#>   group  observed expected     n estimate conf.low conf.high     p p.adj p.adj…¹
+#> * <chr>     <dbl>    <dbl> <dbl>    <dbl>    <dbl>     <dbl> <dbl> <dbl> <chr>  
+#> 1 red          81     79     158    0.513    0.432     0.593 0.811     1 ns     
+#> 2 yellow       50     52.1   158    0.316    0.245     0.395 0.800     1 ns     
+#> 3 white        27     26.9   158    0.171    0.116     0.239 1         1 ns     
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+
-
- +
- - + + diff --git a/docs/reference/outliers.html b/docs/reference/outliers.html index 4ea04a3..f97a595 100644 --- a/docs/reference/outliers.html +++ b/docs/reference/outliers.html @@ -1,48 +1,5 @@ - - - - - - - -Identify Univariate Outliers Using Boxplot Methods — identify_outliers • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Identify Univariate Outliers Using Boxplot Methods — identify_outliers • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -144,109 +74,108 @@

Identify Univariate Outliers Using Boxplot Methods

before the quantiles are computed.

-
identify_outliers(data, ..., variable = NULL)
-
-is_outlier(x, coef = 1.5)
-
-is_extreme(x)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
data

a data frame

...

One unquoted expressions (or variable name). Used to select a -variable of interest. Alternative to the argument variable.

variable

variable name for detecting outliers

x

a numeric vector

coef

coefficient specifying how far the outlier should be from the edge -of their box. Possible values are 1.5 (for outlier) and 3 (for extreme -points only). Default is 1.5

+
+
identify_outliers(data, ..., variable = NULL)
+
+is_outlier(x, coef = 1.5)
+
+is_extreme(x)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

One unquoted expressions (or variable name). Used to select a +variable of interest. Alternative to the argument variable.

+ -

Value

+
variable
+

variable name for detecting outliers

+ +
x
+

a numeric vector

+ + +
coef
+

coefficient specifying how far the outlier should be from the edge +of their box. Possible values are 1.5 (for outlier) and 3 (for extreme +points only). Default is 1.5

+ +
+
+

Value

-
    -
  • identify_outliers(). Returns the input data + +

    • identify_outliers(). Returns the input data frame with two additional columns: "is.outlier" and "is.extreme", which hold logical values.

    • is_outlier() and is_extreme(). Returns logical vectors.

    • -
    - -

    Functions

    - +
+
+

Functions

-
    -
  • identify_outliers: takes a data frame and extract rows suspected as outliers +

    • identify_outliers(): takes a data frame and extract rows suspected as outliers according to a numeric column. The following columns are added "is.outlier" and "is.extreme".

    • -
    • is_outlier: detect outliers in a numeric vector. Returns logical vector.

    • -
    • is_extreme: detect extreme points in a numeric vector. An alias of +

    • is_outlier(): detect outliers in a numeric vector. Returns logical vector.

    • +
    • is_extreme(): detect extreme points in a numeric vector. An alias of is_outlier(), where coef = 3. Returns logical vector.

    • -
    - -

    Examples

    -
    # Generate a demo data -set.seed(123) -demo.data <- data.frame( - sample = 1:20, - score = c(rnorm(19, mean = 5, sd = 2), 50), - gender = rep(c("Male", "Female"), each = 10) -) - -# Identify outliers according to the variable score -demo.data %>% - identify_outliers(score)
    #> sample score gender is.outlier is.extreme -#> 1 20 50 Female TRUE TRUE
    -# Identify outliers by groups -demo.data %>% - group_by(gender) %>% - identify_outliers("score")
    #> # A tibble: 2 x 5 -#> gender sample score is.outlier is.extreme -#> <fct> <int> <dbl> <lgl> <lgl> -#> 1 Female 18 1.07 TRUE FALSE -#> 2 Female 20 50 TRUE TRUE
    +
+ +
+

Examples

+
# Generate a demo data
+set.seed(123)
+demo.data <- data.frame(
+  sample = 1:20,
+  score = c(rnorm(19, mean = 5, sd = 2), 50),
+  gender = rep(c("Male", "Female"), each = 10)
+)
+
+# Identify outliers according to the variable score
+demo.data %>%
+  identify_outliers(score)
+#>   sample score gender is.outlier is.extreme
+#> 1     20    50 Female       TRUE       TRUE
+
+# Identify outliers by groups
+demo.data %>%
+  group_by(gender) %>%
+  identify_outliers("score")
+#> # A tibble: 2 × 5
+#>   gender sample score is.outlier is.extreme
+#>   <fct>   <int> <dbl> <lgl>      <lgl>     
+#> 1 Female     18  1.07 TRUE       FALSE     
+#> 2 Female     20 50    TRUE       TRUE      
+
+
+
-
- +
- - + + diff --git a/docs/reference/p_value.html b/docs/reference/p_value.html index bec8513..5f3b8ff 100644 --- a/docs/reference/p_value.html +++ b/docs/reference/p_value.html @@ -1,69 +1,12 @@ - - - - - - - -Rounding and Formatting p-values — p_round • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Rounding and Formatting p-values — p_round • rstatix - - - - + + -
-
- -
- -
+
@@ -122,184 +52,199 @@

Rounding and Formatting p-values

Round and format p-values. Can also mark significant p-values with stars.

-
p_round(x, ..., digits = 3)
-
-p_format(
-  x,
-  ...,
-  new.col = FALSE,
-  digits = 2,
-  accuracy = 1e-04,
-  decimal.mark = ".",
-  leading.zero = TRUE,
-  trailing.zero = FALSE,
-  add.p = FALSE,
-  space = FALSE
-)
-
-p_mark_significant(
-  x,
-  ...,
-  new.col = FALSE,
-  cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
-  symbols = c("****", "***", "**", "*", "")
-)
-
-p_detect(data, type = c("all", "p", "p.adj"))
-
-p_names()
-
-p_adj_names()
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

a numeric vector of p-values or a data frame containing a p value +

+
p_round(x, ..., digits = 3)
+
+p_format(
+  x,
+  ...,
+  new.col = FALSE,
+  digits = 2,
+  accuracy = 1e-04,
+  decimal.mark = ".",
+  leading.zero = TRUE,
+  trailing.zero = FALSE,
+  add.p = FALSE,
+  space = FALSE
+)
+
+p_mark_significant(
+  x,
+  ...,
+  new.col = FALSE,
+  cutpoints = c(0, 1e-04, 0.001, 0.01, 0.05, 1),
+  symbols = c("****", "***", "**", "*", "")
+)
+
+p_detect(data, type = c("all", "p", "p.adj"))
+
+p_names()
+
+p_adj_names()
+
+ +
+

Arguments

+
x
+

a numeric vector of p-values or a data frame containing a p value column. If data frame, the p-value column(s) will be automatically detected. Known p-value column names can be obtained using the functions -p_names() and p_adj_names()

...

column names to manipulate in the case where x is a data -frame. P value columns are automatically detected if not specified.

digits

the number of significant digits to be used.

new.col

logical, used only when x is a data frame. If TRUE, add +p_names() and p_adj_names()

+ + +
...
+

column names to manipulate in the case where x is a data +frame. P value columns are automatically detected if not specified.

+ + +
digits
+

the number of significant digits to be used.

+ + +
new.col
+

logical, used only when x is a data frame. If TRUE, add a new column to hold the results. The new column name is created by adding, to the p column, the suffix "format" (for p_format()), "signif" (for -p_mak_significant()).

accuracy

number to round to, that is the threshold value above wich the -function will replace the pvalue by "<0.0xxx".

decimal.mark

the character to be used to indicate the numeric decimal -point.

leading.zero

logical. If FALSE, remove the leading zero.

trailing.zero

logical. If FALSE (default), remove the training extra -zero.

add.p

logical value. If TRUE, add "p=" before the value.

space

logical. If TRUE (default) use space as separator between -different elements and symbols.

cutpoints

numeric vector used for intervals

symbols

character vector, one shorter than cutpoints, used as -significance symbols.

data

a data frame

type

the type of p-value to detect. Can be one of c("all", "p", "p.adj").

- -

Value

- -

a vector or a data frame containing the rounded/formatted p-values.

-

Functions

+p_mak_significant()).

+ + +
accuracy
+

number to round to, that is the threshold value above wich the +function will replace the pvalue by "<0.0xxx".

+ + +
decimal.mark
+

the character to be used to indicate the numeric decimal +point.

+ + +
leading.zero
+

logical. If FALSE, remove the leading zero.

+ + +
trailing.zero
+

logical. If FALSE (default), remove the training extra +zero.

+ + +
add.p
+

logical value. If TRUE, add "p=" before the value.

+ +
space
+

logical. If TRUE (default) use space as separator between +different elements and symbols.

+ + +
cutpoints
+

numeric vector used for intervals

+ + +
symbols
+

character vector, one shorter than cutpoints, used as +significance symbols.

+ + +
data
+

a data frame

+ + +
type
+

the type of p-value to detect. Can be one of c("all", "p", "p.adj").

+ +
+
+

Value

+ + +

a vector or a data frame containing the rounded/formatted p-values.

+
+
+

Functions

-
    -
  • p_round: round p-values

  • -
  • p_format: format p-values. Add a symbol "<" for small p-values.

  • -
  • p_mark_significant: mark p-values with significance levels

  • -
  • p_detect: detects and returns p-value column names in a data frame.

  • -
  • p_names: returns known p-value column names

  • -
  • p_adj_names: returns known adjust p-value column names

  • -
- -

Examples

-
-# Round and format a vector of p-values -# :::::::::::::::::::::::::::::::::::::::::::: -# Format -p <- c(0.5678, 0.127, 0.045, 0.011, 0.009, 0.00002, NA) -p_format(p)
#> [1] "0.568" "0.127" "0.045" "0.011" "0.009" "<0.0001" "NA"
-# Specify the accuracy -p_format(p, accuracy = 0.01)
#> [1] "0.568" "0.127" "0.045" "0.011" "<0.01" "<0.01" "NA"
-# Add p and remove the leading zero -p_format(p, add.p = TRUE, leading.zero = FALSE)
#> [1] "p=.568" "p=.127" "p=.045" "p=.011" "p=.009" "p<.0001" "p=NA"
-# Remove space before and after "=" or "<". -p_format(p, add.p = TRUE, leading.zero = FALSE, space = FALSE)
#> [1] "p=.568" "p=.127" "p=.045" "p=.011" "p=.009" "p<.0001" "p=NA"
-# Mark significant p-values -# :::::::::::::::::::::::::::::::::::::::::::: -p_mark_significant(p)
#> [1] "0.5678" "0.127" "0.045*" "0.011*" "0.009**" "2e-05****" -#> [7] "NA"
-# Round, the mark significant -p %>% p_round(digits = 2) %>% p_mark_significant()
#> [1] "0.57" "0.13" "0.04*" "0.01**" "0.009**" "2e-05****" -#> [7] "NA"
-# Format, then mark significant -p %>% p_format(digits = 2) %>% p_mark_significant()
#> [1] "0.568" "0.127" "0.045*" "0.011*" "0.009**" -#> [6] "<0.0001****" "NA"
-# Perform stat test, format p and mark significant -# :::::::::::::::::::::::::::::::::::::::::::: -ToothGrowth %>% - group_by(dose) %>% - t_test(len ~ supp) %>% - p_format(digits = 2, leading.zero = FALSE) %>% - p_mark_significant()
#> # A tibble: 3 x 9 -#> dose .y. group1 group2 n1 n2 statistic df p -#> * <dbl> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <chr> -#> 1 0.5 len OJ VC 10 10 3.17 15.0 .0064** -#> 2 1 len OJ VC 10 10 4.03 15.4 .001*** -#> 3 2 len OJ VC 10 10 -0.0461 14.0 .964
-
+
  • p_round(): round p-values

  • +
  • p_format(): format p-values. Add a symbol "<" for small p-values.

  • +
  • p_mark_significant(): mark p-values with significance levels

  • +
  • p_detect(): detects and returns p-value column names in a data frame.

  • +
  • p_names(): returns known p-value column names

  • +
  • p_adj_names(): returns known adjust p-value column names

  • +
+ +
+

Examples

+

+# Round and format a vector of p-values
+# ::::::::::::::::::::::::::::::::::::::::::::
+# Format
+p <- c(0.5678, 0.127, 0.045, 0.011, 0.009, 0.00002, NA)
+p_format(p)
+#> [1] "0.568"   "0.127"   "0.045"   "0.011"   "0.009"   "<0.0001" "NA"     
+
+# Specify the accuracy
+p_format(p, accuracy = 0.01)
+#> [1] "0.568" "0.127" "0.045" "0.011" "<0.01" "<0.01" "NA"   
+
+# Add p and remove the leading zero
+p_format(p, add.p = TRUE, leading.zero = FALSE)
+#> [1] "p=.568"  "p=.127"  "p=.045"  "p=.011"  "p=.009"  "p<.0001" "p=NA"   
+
+# Remove space before and after "=" or "<".
+p_format(p, add.p = TRUE, leading.zero = FALSE, space = FALSE)
+#> [1] "p=.568"  "p=.127"  "p=.045"  "p=.011"  "p=.009"  "p<.0001" "p=NA"   
+
+# Mark significant p-values
+# ::::::::::::::::::::::::::::::::::::::::::::
+p_mark_significant(p)
+#> [1] "0.5678"    "0.127"     "0.045*"    "0.011*"    "0.009**"   "2e-05****"
+#> [7] "NA"       
+
+# Round, the mark significant
+p %>% p_round(digits = 2) %>% p_mark_significant()
+#> [1] "0.57"      "0.13"      "0.04*"     "0.01**"    "0.009**"   "2e-05****"
+#> [7] "NA"       
+
+# Format, then mark significant
+p %>% p_format(digits = 2) %>% p_mark_significant()
+#> [1] "0.568"       "0.127"       "0.045*"      "0.011*"      "0.009**"    
+#> [6] "<0.0001****" "NA"         
+
+# Perform stat test, format p and mark significant
+# ::::::::::::::::::::::::::::::::::::::::::::
+ToothGrowth %>%
+  group_by(dose) %>%
+  t_test(len ~ supp) %>%
+  p_format(digits = 2, leading.zero = FALSE) %>%
+  p_mark_significant()
+#> # A tibble: 3 × 9
+#>    dose .y.   group1 group2    n1    n2 statistic    df p      
+#> * <dbl> <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl> <chr>  
+#> 1   0.5 len   OJ     VC        10    10    3.17    15.0 .0064**
+#> 2   1   len   OJ     VC        10    10    4.03    15.4 .001***
+#> 3   2   len   OJ     VC        10    10   -0.0461  14.0 .964   
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html index 59bf9d7..88b605a 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -1,69 +1,12 @@ - - - - - - - -Pipe operator — %>% • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Pipe operator — %>% • rstatix - + + - - - -
-
- -
- -
+
@@ -122,35 +52,32 @@

Pipe operator

See magrittr::%>% for details.

-
lhs %>% rhs
- +
+
lhs %>% rhs
+
+
-
- +
- - + + diff --git a/docs/reference/prop_test.html b/docs/reference/prop_test.html index b0908dc..9823632 100644 --- a/docs/reference/prop_test.html +++ b/docs/reference/prop_test.html @@ -1,75 +1,18 @@ - - - - - - - -Proportion Test — prop_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Proportion Test — prop_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -128,95 +58,95 @@

Proportion Test

Performs proportion tests to either evaluate the homogeneity of proportions (probabilities of success) in several groups or to test that the proportions are equal to certain given values.

-

Wrappers around the R base function prop.test() but have +

Wrappers around the R base function prop.test() but have the advantage of performing pairwise and row-wise z-test of two proportions, the post-hoc tests following a significant chi-square test of homogeneity for 2xc and rx2 contingency tables.

-
prop_test(
-  x,
-  n,
-  p = NULL,
-  alternative = c("two.sided", "less", "greater"),
-  correct = TRUE,
-  conf.level = 0.95,
-  detailed = FALSE
-)
-
-pairwise_prop_test(xtab, p.adjust.method = "holm", ...)
-
-row_wise_prop_test(xtab, p.adjust.method = "holm", detailed = FALSE, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

a vector of counts of successes, a one-dimensional table with +

+
prop_test(
+  x,
+  n,
+  p = NULL,
+  alternative = c("two.sided", "less", "greater"),
+  correct = TRUE,
+  conf.level = 0.95,
+  detailed = FALSE
+)
+
+pairwise_prop_test(xtab, p.adjust.method = "holm", ...)
+
+row_wise_prop_test(xtab, p.adjust.method = "holm", detailed = FALSE, ...)
+
+ +
+

Arguments

+
x
+

a vector of counts of successes, a one-dimensional table with two entries, or a two-dimensional table (or matrix) with 2 columns, - giving the counts of successes and failures, respectively.

n

a vector of counts of trials; ignored if x is a - matrix or a table.

p

a vector of probabilities of success. The length of + giving the counts of successes and failures, respectively.

+ + +
n
+

a vector of counts of trials; ignored if x is a + matrix or a table.

+ + +
p
+

a vector of probabilities of success. The length of p must be the same as the number of groups specified by - x, and its elements must be greater than 0 and less than 1.

alternative

a character string specifying the alternative + x, and its elements must be greater than 0 and less than 1.

+ + +
alternative
+

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter. Only used for testing the null that a single proportion equals a given value, or that two proportions are equal; ignored - otherwise.

correct

a logical indicating whether Yates' continuity - correction should be applied where possible.

conf.level

confidence level of the returned confidence + otherwise.

+ + +
correct
+

a logical indicating whether Yates' continuity + correction should be applied where possible.

+ + +
conf.level
+

confidence level of the returned confidence interval. Must be a single number between 0 and 1. Only used when testing the null that a single proportion equals a given - value, or that two proportions are equal; ignored otherwise.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

xtab

a cross-tabulation (or contingency table) with two columns and + value, or that two proportions are equal; ignored otherwise.

+ + +
detailed
+

logical value. Default is FALSE. If TRUE, a detailed result is +shown.

+ + +
xtab
+

a cross-tabulation (or contingency table) with two columns and multiple rows (rx2 design). The columns give the counts of successes and -failures respectively.

p.adjust.method

method to adjust p values for multiple comparisons. +failures respectively.

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

...

Other arguments passed to the function prop_test().

- -

Value

- -

return a data frame with some the following columns:

    -
  • n: the number of participants.

  • +want to adjust the p value (not recommended), use p.adjust.method = "none".

    + + +
    ...
    +

    Other arguments passed to the function prop_test().

    + +
+
+

Value

+ + +

return a data frame with some the following columns:

  • n: the number of participants.

  • group: the categories in the row-wise proportion tests.

  • statistic: the value of Pearson's chi-squared test statistic.

  • df: the degrees of freedom of the approximate chi-squared @@ -237,161 +167,179 @@

    Value

    p is not given, or NULL otherwise. In the cases where it is not NULL, the returned confidence interval has an asymptotic confidence level as specified by conf.level, and is appropriate to the specified alternative hypothesis.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Functions

- +
+
+

Functions

-
    -
  • prop_test: performs one-sample and two-samples z-test of -proportions. Wrapper around the function prop.test().

  • -
  • pairwise_prop_test: pairwise comparisons between proportions, a post-hoc +

    • prop_test(): performs one-sample and two-samples z-test of +proportions. Wrapper around the function prop.test().

    • +
    • pairwise_prop_test(): pairwise comparisons between proportions, a post-hoc tests following a significant chi-square test of homogeneity for 2xc -design. Wrapper around pairwise.prop.test()

    • -
    • row_wise_prop_test: performs row-wise z-test of two proportions, a post-hoc tests following a significant chi-square test +design. Wrapper around pairwise.prop.test()

    • +
    • row_wise_prop_test(): performs row-wise z-test of two proportions, a post-hoc tests following a significant chi-square test of homogeneity for rx2 contingency table. The z-test of two proportions is calculated for each category (row).

    • -
    - -

    Examples

    -
    # Comparing an observed proportion to an expected proportion -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -prop_test(x = 95, n = 160, p = 0.5, detailed = TRUE)
    #> # A tibble: 1 x 11 -#> n n1 estimate statistic p df conf.low conf.high method -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <chr> -#> 1 160 95 0.594 5.26 0.0219 1 0.513 0.670 Prop test -#> # … with 2 more variables: alternative <chr>, p.signif <chr>
    -# Comparing two proportions -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: frequencies of smokers between two groups -xtab <- as.table(rbind(c(490, 10), c(400, 100))) -dimnames(xtab) <- list( - group = c("grp1", "grp2"), - smoker = c("yes", "no") -) -xtab
    #> smoker -#> group yes no -#> grp1 490 10 -#> grp2 400 100
    # compare the proportion of smokers -prop_test(xtab, detailed = TRUE)
    #> # A tibble: 1 x 13 -#> n n1 n2 estimate1 estimate2 statistic p df conf.low -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 1000 500 500 0.98 0.8 80.9 2.36e-19 1 0.141 -#> # … with 4 more variables: conf.high <dbl>, method <chr>, alternative <chr>, -#> # p.signif <chr>
    -# Homogeneity of proportions between groups -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# H0: the proportion of smokers is similar in the four groups -# Ha: this proportion is different in at least one of the populations. -# -# Data preparation -grp.size <- c( 106, 113, 156, 102 ) -smokers <- c( 50, 100, 139, 80 ) -no.smokers <- grp.size - smokers -xtab <- as.table(rbind( - smokers, - no.smokers -)) -dimnames(xtab) <- list( - Smokers = c("Yes", "No"), - Groups = c("grp1", "grp2", "grp3", "grp4") -) -xtab
    #> Groups -#> Smokers grp1 grp2 grp3 grp4 -#> Yes 50 100 139 80 -#> No 56 13 17 22
    -# Compare the proportions of smokers between groups -prop_test(xtab, detailed = TRUE)
    #> # A tibble: 1 x 15 -#> n n1 n2 n3 n4 estimate1 estimate2 estimate3 estimate4 -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 477 106 113 156 102 0.472 0.885 0.891 0.784 -#> # … with 6 more variables: statistic <dbl>, p <dbl>, df <dbl>, method <chr>, -#> # alternative <chr>, p.signif <chr>
    -# Pairwise comparison between groups -pairwise_prop_test(xtab)
    #> # A tibble: 6 x 5 -#> group1 group2 p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <chr> -#> 1 grp1 grp2 1.25e-10 6.23e-10 **** -#> 2 grp1 grp3 3.09e-13 1.86e-12 **** -#> 3 grp2 grp3 1 e+ 0 1 e+ 0 ns -#> 4 grp1 grp4 6.41e- 6 2.56e- 5 **** -#> 5 grp2 grp4 7.01e- 2 1.4 e- 1 ns -#> 6 grp3 grp4 3.06e- 2 9.19e- 2 ns
    - -# Pairwise proportion tests -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: Titanic -xtab <- as.table(rbind( - c(122, 167, 528, 673), - c(203, 118, 178, 212) -)) -dimnames(xtab) <- list( - Survived = c("No", "Yes"), - Class = c("1st", "2nd", "3rd", "Crew") -) -xtab
    #> Class -#> Survived 1st 2nd 3rd Crew -#> No 122 167 528 673 -#> Yes 203 118 178 212
    # Compare the proportion of survived between groups -pairwise_prop_test(xtab)
    #> # A tibble: 6 x 5 -#> group1 group2 p p.adj p.adj.signif -#> * <chr> <chr> <dbl> <dbl> <chr> -#> 1 1st 2nd 3.13e- 7 9.38e- 7 **** -#> 2 1st 3rd 2.55e-30 1.27e-29 **** -#> 3 2nd 3rd 6.9 e- 7 1.38e- 6 **** -#> 4 1st Crew 1.62e-35 9.73e-35 **** -#> 5 2nd Crew 1.94e- 8 7.75e- 8 **** -#> 6 3rd Crew 6.03e- 1 6.03e- 1 ns
    -# Row-wise proportion tests -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data: Titanic -xtab <- as.table(rbind( - c(180, 145), c(179, 106), - c(510, 196), c(862, 23) -)) -dimnames(xtab) <- list( - Class = c("1st", "2nd", "3rd", "Crew"), - Gender = c("Male", "Female") -) -xtab
    #> Gender -#> Class Male Female -#> 1st 180 145 -#> 2nd 179 106 -#> 3rd 510 196 -#> Crew 862 23
    # Compare the proportion of males and females in each category -row_wise_prop_test(xtab)
    #> # A tibble: 4 x 7 -#> group n statistic df p p.adj p.adj.signif -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 1st 2201 121. 1 3.4 e-28 1.02e-27 **** -#> 2 2nd 2201 47.8 1 4.65e-12 9.3 e-12 **** -#> 3 3rd 2201 24.9 1 6.18e- 7 6.18e- 7 **** -#> 4 Crew 2201 308. 1 5.51e-69 2.2 e-68 ****
    +
+ +
+

Examples

+
# Comparing an observed proportion to an expected proportion
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+prop_test(x = 95, n = 160, p = 0.5, detailed = TRUE)
+#> # A tibble: 1 × 11
+#>       n    n1 estimate statistic      p    df conf.low conf.high method  alter…¹
+#> * <dbl> <dbl>    <dbl>     <dbl>  <dbl> <int>    <dbl>     <dbl> <chr>   <chr>  
+#> 1   160    95    0.594      5.26 0.0219     1    0.513     0.670 Prop t… two.si…
+#> # … with 1 more variable: p.signif <chr>, and abbreviated variable name
+#> #   ¹​alternative
+
+# Comparing two proportions
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: frequencies of smokers between two groups
+xtab <- as.table(rbind(c(490, 10), c(400, 100)))
+dimnames(xtab) <- list(
+  group = c("grp1", "grp2"),
+  smoker = c("yes", "no")
+)
+xtab
+#>       smoker
+#> group  yes  no
+#>   grp1 490  10
+#>   grp2 400 100
+# compare the proportion of smokers
+prop_test(xtab, detailed = TRUE)
+#> # A tibble: 1 × 13
+#>       n    n1    n2 estimate1 estimate2 statistic        p    df conf.…¹ conf.…²
+#> * <dbl> <dbl> <dbl>     <dbl>     <dbl>     <dbl>    <dbl> <dbl>   <dbl>   <dbl>
+#> 1  1000   500   500      0.98       0.8      80.9 2.36e-19     1   0.141   0.219
+#> # … with 3 more variables: method <chr>, alternative <chr>, p.signif <chr>, and
+#> #   abbreviated variable names ¹​conf.low, ²​conf.high
+
+# Homogeneity of proportions between groups
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# H0: the proportion of smokers is similar in the four groups
+# Ha:  this proportion is different in at least one of the populations.
+#
+# Data preparation
+grp.size <- c( 106, 113, 156, 102 )
+smokers  <- c( 50, 100, 139, 80 )
+no.smokers <- grp.size - smokers
+xtab <- as.table(rbind(
+  smokers,
+  no.smokers
+))
+dimnames(xtab) <- list(
+  Smokers = c("Yes", "No"),
+  Groups = c("grp1", "grp2", "grp3", "grp4")
+)
+xtab
+#>        Groups
+#> Smokers grp1 grp2 grp3 grp4
+#>     Yes   50  100  139   80
+#>     No    56   13   17   22
+
+# Compare the proportions of smokers between groups
+prop_test(xtab, detailed = TRUE)
+#> # A tibble: 1 × 15
+#>       n    n1    n2    n3    n4 estim…¹ estim…² estim…³ estim…⁴ stati…⁵        p
+#> * <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    <dbl>
+#> 1   477   106   113   156   102   0.472   0.885   0.891   0.784    75.5 2.82e-16
+#> # … with 4 more variables: df <dbl>, method <chr>, alternative <chr>,
+#> #   p.signif <chr>, and abbreviated variable names ¹​estimate1, ²​estimate2,
+#> #   ³​estimate3, ⁴​estimate4, ⁵​statistic
+
+# Pairwise comparison between groups
+pairwise_prop_test(xtab)
+#> # A tibble: 6 × 5
+#>   group1 group2        p    p.adj p.adj.signif
+#> * <chr>  <chr>     <dbl>    <dbl> <chr>       
+#> 1 grp1   grp2   1.25e-10 6.23e-10 ****        
+#> 2 grp1   grp3   3.09e-13 1.86e-12 ****        
+#> 3 grp2   grp3   1   e+ 0 1   e+ 0 ns          
+#> 4 grp1   grp4   6.41e- 6 2.56e- 5 ****        
+#> 5 grp2   grp4   7.01e- 2 1.4 e- 1 ns          
+#> 6 grp3   grp4   3.06e- 2 9.19e- 2 ns          
+
+
+# Pairwise proportion tests
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: Titanic
+xtab <- as.table(rbind(
+  c(122, 167, 528, 673),
+  c(203, 118, 178, 212)
+))
+dimnames(xtab) <- list(
+  Survived = c("No", "Yes"),
+  Class = c("1st", "2nd", "3rd", "Crew")
+)
+xtab
+#>         Class
+#> Survived 1st 2nd 3rd Crew
+#>      No  122 167 528  673
+#>      Yes 203 118 178  212
+# Compare the proportion of survived between groups
+pairwise_prop_test(xtab)
+#> # A tibble: 6 × 5
+#>   group1 group2        p    p.adj p.adj.signif
+#> * <chr>  <chr>     <dbl>    <dbl> <chr>       
+#> 1 1st    2nd    3.13e- 7 9.38e- 7 ****        
+#> 2 1st    3rd    2.55e-30 1.27e-29 ****        
+#> 3 2nd    3rd    6.9 e- 7 1.38e- 6 ****        
+#> 4 1st    Crew   1.62e-35 9.73e-35 ****        
+#> 5 2nd    Crew   1.94e- 8 7.75e- 8 ****        
+#> 6 3rd    Crew   6.03e- 1 6.03e- 1 ns          
+
+# Row-wise proportion tests
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data: Titanic
+xtab <- as.table(rbind(
+  c(180, 145), c(179, 106),
+  c(510, 196), c(862, 23)
+))
+dimnames(xtab) <- list(
+  Class = c("1st", "2nd", "3rd", "Crew"),
+  Gender = c("Male", "Female")
+)
+xtab
+#>       Gender
+#> Class  Male Female
+#>   1st   180    145
+#>   2nd   179    106
+#>   3rd   510    196
+#>   Crew  862     23
+# Compare the proportion of males and females in each category
+row_wise_prop_test(xtab)
+#> # A tibble: 4 × 7
+#>   group     n statistic    df        p    p.adj p.adj.signif
+#> * <chr> <dbl>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 1st    2201     121.      1 3.4 e-28 1.02e-27 ****        
+#> 2 2nd    2201      47.8     1 4.65e-12 9.3 e-12 ****        
+#> 3 3rd    2201      24.9     1 6.18e- 7 6.18e- 7 ****        
+#> 4 Crew   2201     308.      1 5.51e-69 2.2 e-68 ****        
+
+
+
-
- +
- - + + diff --git a/docs/reference/prop_trend_test.html b/docs/reference/prop_trend_test.html index 6f76749..484ed02 100644 --- a/docs/reference/prop_trend_test.html +++ b/docs/reference/prop_trend_test.html @@ -1,72 +1,15 @@ - - - - - - - -Test for Trend in Proportions — prop_trend_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Test for Trend in Proportions — prop_trend_test • rstatix - - - - - - - - - + + - - - - -
-
- -
- -
+

Performs chi-squared test for trend in proportion. This test is also known as Cochran-Armitage trend test.

-

Wrappers around the R base function prop.trend.test() but +

Wrappers around the R base function prop.trend.test() but returns a data frame for easy data visualization.

-
prop_trend_test(xtab, score = NULL)
+
+
prop_trend_test(xtab, score = NULL)
+
-

Arguments

- - - - - - - - - - -
xtab

a cross-tabulation (or contingency table) with two columns and +

+

Arguments

+
xtab
+

a cross-tabulation (or contingency table) with two columns and multiple rows (rx2 design). The columns give the counts of successes and -failures respectively.

score

group score. If NULL, the default is group number.

- -

Value

- -

return a data frame with some the following columns:

    -
  • n: the number of participants.

  • +failures respectively.

    + + +
    score
    +

    group score. If NULL, the default is group number.

    + +
+
+

Value

+ + +

return a data frame with some the following columns:

  • n: the number of participants.

  • statistic: the value of Chi-squared trend test statistic.

  • df: the degrees of @@ -157,56 +87,57 @@

    Value

  • method: the used statistical test.

  • p.signif: the significance level of p-values and adjusted p-values, respectively.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

+
-

Examples

-
# Proportion of renal stone (calculi) across age -#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# Data -xtab <- as.table(rbind( - c(384, 536, 335), - c(951, 869, 438) -)) -dimnames(xtab) <- list( - stone = c("yes", "no"), - age = c("30-39", "40-49", "50-59") -) -xtab
#> age -#> stone 30-39 40-49 50-59 -#> yes 384 536 335 -#> no 951 869 438
# Compare the proportion of survived between groups -prop_trend_test(xtab)
#> # A tibble: 1 x 6 -#> n statistic p p.signif df method -#> * <dbl> <dbl> <dbl> <chr> <dbl> <chr> -#> 1 3513 49.7 1.78e-12 **** 1 Chi-square trend test
+
+

Examples

+
# Proportion of renal stone (calculi) across age
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+# Data
+xtab <- as.table(rbind(
+  c(384, 536, 335),
+  c(951, 869, 438)
+))
+dimnames(xtab) <- list(
+  stone = c("yes", "no"),
+  age = c("30-39", "40-49", "50-59")
+)
+xtab
+#>      age
+#> stone 30-39 40-49 50-59
+#>   yes   384   536   335
+#>   no    951   869   438
+# Compare the proportion of survived between groups
+prop_trend_test(xtab)
+#> # A tibble: 1 × 6
+#>       n statistic        p p.signif    df method               
+#> * <dbl>     <dbl>    <dbl> <chr>    <dbl> <chr>                
+#> 1  3513      49.7 1.78e-12 ****         1 Chi-square trend test
+
+
+
-
- +
- - + + diff --git a/docs/reference/pull_triangle.html b/docs/reference/pull_triangle.html index 3e14381..c88ef7e 100644 --- a/docs/reference/pull_triangle.html +++ b/docs/reference/pull_triangle.html @@ -1,70 +1,13 @@ - - - - - - - -Pull Lower and Upper Triangular Part of a Matrix — pull_triangle • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Pull Lower and Upper Triangular Part of a Matrix — pull_triangle • rstatix - - - - + + -
-
- -
- -
+
@@ -124,114 +54,122 @@

Pull Lower and Upper Triangular Part of a Matrix

(correlation) matrix.

-
pull_triangle(x, triangle = c("lower", "upper"), diagonal = FALSE)
+    
+
pull_triangle(x, triangle = c("lower", "upper"), diagonal = FALSE)
+
+pull_upper_triangle(x, diagonal = FALSE)
+
+pull_lower_triangle(x, diagonal = FALSE)
+
-pull_upper_triangle(x, diagonal = FALSE) +
+

Arguments

+
x
+

a (correlation) matrix

-pull_lower_triangle(x, diagonal = FALSE)
-

Arguments

- - - - - - - - - - - - - - -
x

a (correlation) matrix

triangle

the triangle to pull. Allowed values are one of -"upper" and "lower".

diagonal

logical. Default is FALSE. If TRUE, the matrix diagonal is -included.

+
triangle
+

the triangle to pull. Allowed values are one of +"upper" and "lower".

-

Value

-

an object of class cor_mat_tri, which is a data frame

-

Functions

+
diagonal
+

logical. Default is FALSE. If TRUE, the matrix diagonal is +included.

+
+
+

Value

-
    -
  • pull_triangle: returns either the lower or upper triangular part of a matrix.

  • -
  • pull_upper_triangle: returns an object of class upper_tri, which + +

    an object of class cor_mat_tri, which is a data frame

    +
+
+

Functions

+ +
  • pull_triangle(): returns either the lower or upper triangular part of a matrix.

  • +
  • pull_upper_triangle(): returns an object of class upper_tri, which is a data frame containing the upper triangular part of a matrix.

  • -
  • pull_lower_triangle: returns an object of class lower_tri, which +

  • pull_lower_triangle(): returns an object of class lower_tri, which is a data frame containing the lower triangular part of a matrix.

  • -
-

See also

- - - -

Examples

-
-# Data preparation -#:::::::::::::::::::::::::::::::::::::::::: -mydata <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) -head(mydata, 3)
#> mpg disp hp drat wt qsec -#> Mazda RX4 21.0 160 110 3.90 2.620 16.46 -#> Mazda RX4 Wag 21.0 160 110 3.90 2.875 17.02 -#> Datsun 710 22.8 108 93 3.85 2.320 18.61
-# Compute correlation matrix and pull triangles -#:::::::::::::::::::::::::::::::::::::::::: -# Correlation matrix -cor.mat <- cor_mat(mydata) -cor.mat
#> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 -#> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 -#> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1
-# Pull lower triangular part -cor.mat %>% pull_lower_triangle()
#> rowname mpg disp hp drat wt qsec -#> 1 mpg -#> 2 disp -0.85 -#> 3 hp -0.78 0.79 -#> 4 drat 0.68 -0.71 -0.45 -#> 5 wt -0.87 0.89 0.66 -0.71 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17
-# Pull upper triangular part -cor.mat %>% pull_upper_triangle()
#> rowname mpg disp hp drat wt qsec -#> 1 mpg -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.45 0.66 -0.71 -#> 4 drat -0.71 0.091 -#> 5 wt -0.17 -#> 6 qsec
- -
+
+
+

See also

+ +
+ +
+

Examples

+

+# Data preparation
+#::::::::::::::::::::::::::::::::::::::::::
+mydata <- mtcars %>%
+  select(mpg, disp, hp, drat, wt, qsec)
+head(mydata, 3)
+#>                mpg disp  hp drat    wt  qsec
+#> Mazda RX4     21.0  160 110 3.90 2.620 16.46
+#> Mazda RX4 Wag 21.0  160 110 3.90 2.875 17.02
+#> Datsun 710    22.8  108  93 3.85 2.320 18.61
+
+# Compute correlation matrix and pull triangles
+#::::::::::::::::::::::::::::::::::::::::::
+# Correlation matrix
+cor.mat <- cor_mat(mydata)
+cor.mat
+#> # A tibble: 6 × 7
+#>   rowname   mpg  disp    hp   drat    wt   qsec
+#> * <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 mpg      1    -0.85 -0.78  0.68  -0.87  0.42 
+#> 2 disp    -0.85  1     0.79 -0.71   0.89 -0.43 
+#> 3 hp      -0.78  0.79  1    -0.45   0.66 -0.71 
+#> 4 drat     0.68 -0.71 -0.45  1     -0.71  0.091
+#> 5 wt      -0.87  0.89  0.66 -0.71   1    -0.17 
+#> 6 qsec     0.42 -0.43 -0.71  0.091 -0.17  1    
+
+# Pull lower triangular part
+cor.mat %>% pull_lower_triangle()
+#>   rowname   mpg  disp    hp  drat    wt qsec
+#> 1     mpg                                   
+#> 2    disp -0.85                             
+#> 3      hp -0.78  0.79                       
+#> 4    drat  0.68 -0.71 -0.45                 
+#> 5      wt -0.87  0.89  0.66 -0.71           
+#> 6    qsec  0.42 -0.43 -0.71 0.091 -0.17     
+
+# Pull upper triangular part
+cor.mat %>% pull_upper_triangle()
+#>   rowname mpg  disp    hp  drat    wt  qsec
+#> 1     mpg     -0.85 -0.78  0.68 -0.87  0.42
+#> 2    disp            0.79 -0.71  0.89 -0.43
+#> 3      hp                 -0.45  0.66 -0.71
+#> 4    drat                       -0.71 0.091
+#> 5      wt                             -0.17
+#> 6    qsec                                  
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index 595cc4f..35a536e 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -1,82 +1,35 @@ - - - - - - - -Objects exported from other packages — reexports • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Objects exported from other packages — reexports • rstatix + tibble +tibble + tidyr +drop_na, gather, spread - - - - - + + - - - -
-
- -
- -
+

These objects are imported from other packages. Follow the links below to see their documentation.

- -
car

Anova

+
car
+

Anova

-
dplyr

desc, filter, group_by, mutate, select

-
generics

augment, tidy

+
dplyr
+

desc, filter, group_by, mutate, select

-
tibble

tibble

-
tidyr

drop_na, gather, spread

+
generics
+

augment, tidy

-
-
+ +
tibble
+

tibble

+ + +
tidyr
+

drop_na, gather, spread

+
+
+
-
- +
- - + + diff --git a/docs/reference/remove_ns.html b/docs/reference/remove_ns.html index 010f372..9908235 100644 --- a/docs/reference/remove_ns.html +++ b/docs/reference/remove_ns.html @@ -1,70 +1,13 @@ - - - - - - - -Remove Non-Significant from Statistical Tests — remove_ns • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Remove Non-Significant from Statistical Tests — remove_ns • rstatix - + + - - - -
-
- -
- -
+
@@ -124,72 +54,76 @@

Remove Non-Significant from Statistical Tests

test. Can detect automatically p-value columns

-
remove_ns(stat.test, col = NULL, signif.cutoff = 0.05)
- -

Arguments

- - - - - - - - - - - - - - -
stat.test

statistical test results returned by rstatix -functions or any data frame containing a p-value column.

col

(optional) character specifying the column containing the p-value +

+
remove_ns(stat.test, col = NULL, signif.cutoff = 0.05)
+
+ +
+

Arguments

+
stat.test
+

statistical test results returned by rstatix +functions or any data frame containing a p-value column.

+ + +
col
+

(optional) character specifying the column containing the p-value or the significance information, to be used for the filtering step. Possible values include: "p", "p.adj", "p.signif", "p.adj.signif". If missing, the function will automatically look for -p.adj.signif, p.adj, p.signif, p in this order.

signif.cutoff

the significance cutoff; default is 0.05. Significance -is declared at p-value <= signif.cutoff

- -

Value

- -

a data frame

- -

Examples

-
# Statistical test -stat.test <- PlantGrowth %>% wilcox_test(weight ~ group) -# Remove ns: automatic detection of p-value columns -stat.test %>% remove_ns()
#> # A tibble: 1 x 9 -#> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif -#> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> -#> 1 weight trt1 trt2 10 10 16 0.009 0.027 *
# Remove ns by the column p -stat.test %>% remove_ns(col ="p")
#> # A tibble: 1 x 9 -#> .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif -#> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> -#> 1 weight trt1 trt2 10 10 16 0.009 0.027 *
+p.adj.signif, p.adj, p.signif, p in this order.

+ + +
signif.cutoff
+

the significance cutoff; default is 0.05. Significance +is declared at p-value <= signif.cutoff

+ +
+
+

Value

+ + +

a data frame

+
+ +
+

Examples

+
# Statistical test
+stat.test <- PlantGrowth %>% wilcox_test(weight ~ group)
+# Remove ns: automatic detection of p-value columns
+stat.test %>% remove_ns()
+#> # A tibble: 1 × 9
+#>   .y.    group1 group2    n1    n2 statistic     p p.adj p.adj.signif
+#>   <chr>  <chr>  <chr>  <int> <int>     <dbl> <dbl> <dbl> <chr>       
+#> 1 weight trt1   trt2      10    10        16 0.009 0.027 *           
+# Remove ns by the column p
+stat.test %>% remove_ns(col ="p")
+#> # A tibble: 1 × 9
+#>   .y.    group1 group2    n1    n2 statistic     p p.adj p.adj.signif
+#>   <chr>  <chr>  <chr>  <int> <int>     <dbl> <dbl> <dbl> <chr>       
+#> 1 weight trt1   trt2      10    10        16 0.009 0.027 *           
+
+
+
-
- +
- - + + diff --git a/docs/reference/replace_triangle.html b/docs/reference/replace_triangle.html index b594ba1..7fc8a70 100644 --- a/docs/reference/replace_triangle.html +++ b/docs/reference/replace_triangle.html @@ -1,70 +1,13 @@ - - - - - - - -Replace Lower and Upper Triangular Part of a Matrix — replace_triangle • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Replace Lower and Upper Triangular Part of a Matrix — replace_triangle • rstatix - - - - + + -
-
- -
- -
+
@@ -124,125 +54,131 @@

Replace Lower and Upper Triangular Part of a Matrix

(correlation) matrix.

-
replace_triangle(x, triangle = c("lower", "upper"), by = "", diagonal = FALSE)
-
-replace_upper_triangle(x, by = "", diagonal = FALSE)
-
-replace_lower_triangle(x, by = "", diagonal = FALSE)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
x

a (correlation) matrix

triangle

the triangle to replace. Allowed values are one of -"upper" and "lower".

by

a replacement argument. Appropriate values are either "" or NA. Used to replace -the upper, lower or the diagonal part of the matrix.

diagonal

logical. Default is FALSE. If TRUE, the matrix diagonal is -included.

- -

Value

- -

an object of class cor_mat_tri, which is a data frame

-

Functions

+
+
replace_triangle(x, triangle = c("lower", "upper"), by = "", diagonal = FALSE)
+
+replace_upper_triangle(x, by = "", diagonal = FALSE)
+
+replace_lower_triangle(x, by = "", diagonal = FALSE)
+
+ +
+

Arguments

+
x
+

a (correlation) matrix

+ + +
triangle
+

the triangle to replace. Allowed values are one of +"upper" and "lower".

+ +
by
+

a replacement argument. Appropriate values are either "" or NA. Used to replace +the upper, lower or the diagonal part of the matrix.

+ + +
diagonal
+

logical. Default is FALSE. If TRUE, the matrix diagonal is +included.

+ +
+
+

Value

+ + +

an object of class cor_mat_tri, which is a data frame

+
+
+

Functions

-
    -
  • replace_triangle: replaces the specified triangle by empty or NA.

  • -
  • replace_upper_triangle: replaces the upper triangular part of a matrix. +

    • replace_triangle(): replaces the specified triangle by empty or NA.

    • +
    • replace_upper_triangle(): replaces the upper triangular part of a matrix. Returns an object of class lower_tri.

    • -
    • replace_lower_triangle: replaces the lower triangular part of a matrix. +

    • replace_lower_triangle(): replaces the lower triangular part of a matrix. Returns an object of class lower_tri

    • -
    -

    See also

    - - - -

    Examples

    -
    # Compute correlation matrix and pull triangles -#:::::::::::::::::::::::::::::::::::::::::: -# Correlation matrix - cor.mat <- mtcars %>% - select(mpg, disp, hp, drat, wt, qsec) %>% - cor_mat() - cor.mat
    #> # A tibble: 6 x 7 -#> rowname mpg disp hp drat wt qsec -#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 -#> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 -#> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 -#> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 -#> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1
    - # Replace upper triangle by NA -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat %>% replace_upper_triangle(by = NA)
    #> rowname mpg disp hp drat wt qsec -#> 1 mpg NA NA NA NA NA NA -#> 2 disp -0.85 NA NA NA NA NA -#> 3 hp -0.78 0.79 NA NA NA NA -#> 4 drat 0.68 -0.71 -0.45 NA NA NA -#> 5 wt -0.87 0.89 0.66 -0.710 NA NA -#> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 NA
    - -# Replace upper triangle by NA and reshape the -# correlation matrix to have unique combinations of variables -#:::::::::::::::::::::::::::::::::::::::::: -cor.mat %>% - replace_upper_triangle(by = NA) %>% - cor_gather()
    #> var1 var2 cor p -#> 1 disp mpg -0.850 9.38e-10 -#> 2 hp mpg -0.780 1.79e-07 -#> 3 drat mpg 0.680 1.78e-05 -#> 4 wt mpg -0.870 1.29e-10 -#> 5 qsec mpg 0.420 1.71e-02 -#> 6 hp disp 0.790 7.14e-08 -#> 7 drat disp -0.710 5.28e-06 -#> 8 wt disp 0.890 1.22e-11 -#> 9 qsec disp -0.430 1.31e-02 -#> 10 drat hp -0.450 9.99e-03 -#> 11 wt hp 0.660 4.15e-05 -#> 12 qsec hp -0.710 5.77e-06 -#> 13 wt drat -0.710 4.78e-06 -#> 14 qsec drat 0.091 6.20e-01 -#> 15 qsec wt -0.170 3.39e-01
    +
+
+

See also

+ +
+ +
+

Examples

+
# Compute correlation matrix and pull triangles
+#::::::::::::::::::::::::::::::::::::::::::
+# Correlation matrix
+ cor.mat <- mtcars %>%
+   select(mpg, disp, hp, drat, wt, qsec) %>%
+   cor_mat()
+ cor.mat
+#> # A tibble: 6 × 7
+#>   rowname   mpg  disp    hp   drat    wt   qsec
+#> * <chr>   <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>
+#> 1 mpg      1    -0.85 -0.78  0.68  -0.87  0.42 
+#> 2 disp    -0.85  1     0.79 -0.71   0.89 -0.43 
+#> 3 hp      -0.78  0.79  1    -0.45   0.66 -0.71 
+#> 4 drat     0.68 -0.71 -0.45  1     -0.71  0.091
+#> 5 wt      -0.87  0.89  0.66 -0.71   1    -0.17 
+#> 6 qsec     0.42 -0.43 -0.71  0.091 -0.17  1    
+
+ # Replace upper triangle by NA
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat %>% replace_upper_triangle(by = NA)
+#>   rowname   mpg  disp    hp   drat    wt qsec
+#> 1     mpg    NA    NA    NA     NA    NA   NA
+#> 2    disp -0.85    NA    NA     NA    NA   NA
+#> 3      hp -0.78  0.79    NA     NA    NA   NA
+#> 4    drat  0.68 -0.71 -0.45     NA    NA   NA
+#> 5      wt -0.87  0.89  0.66 -0.710    NA   NA
+#> 6    qsec  0.42 -0.43 -0.71  0.091 -0.17   NA
+
+
+# Replace upper triangle by NA and reshape the
+# correlation matrix to have unique combinations of variables
+#::::::::::::::::::::::::::::::::::::::::::
+cor.mat %>%
+  replace_upper_triangle(by = NA) %>%
+  cor_gather()
+#>    var1 var2    cor        p
+#> 1  disp  mpg -0.850 9.38e-10
+#> 2    hp  mpg -0.780 1.79e-07
+#> 3  drat  mpg  0.680 1.78e-05
+#> 4    wt  mpg -0.870 1.29e-10
+#> 5  qsec  mpg  0.420 1.71e-02
+#> 6    hp disp  0.790 7.14e-08
+#> 7  drat disp -0.710 5.28e-06
+#> 8    wt disp  0.890 1.22e-11
+#> 9  qsec disp -0.430 1.31e-02
+#> 10 drat   hp -0.450 9.99e-03
+#> 11   wt   hp  0.660 4.15e-05
+#> 12 qsec   hp -0.710 5.77e-06
+#> 13   wt drat -0.710 4.78e-06
+#> 14 qsec drat  0.091 6.20e-01
+#> 15 qsec   wt -0.170 3.39e-01
+
+
+
-
- +
- - + + diff --git a/docs/reference/sample_n_by.html b/docs/reference/sample_n_by.html index 426d465..8b43d8d 100644 --- a/docs/reference/sample_n_by.html +++ b/docs/reference/sample_n_by.html @@ -1,69 +1,12 @@ - - - - - - - -Sample n Rows By Group From a Table — sample_n_by • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Sample n Rows By Group From a Table — sample_n_by • rstatix - + + - - - -
-
- -
- -
+
-

sample n rows by group from a table using the sample_n() function.

+

sample n rows by group from a table using the sample_n() function.

-
sample_n_by(data, ..., size = 1, replace = FALSE)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
data

a data frame

...

Variables to group by

size

the number of rows to select

replace

with or without replacement?

- - -

Examples

-
ToothGrowth %>% sample_n_by(dose, supp, size = 2)
#> # A tibble: 12 x 3 -#> len supp dose -#> <dbl> <fct> <dbl> -#> 1 14.5 OJ 0.5 -#> 2 8.2 OJ 0.5 -#> 3 5.2 VC 0.5 -#> 4 7 VC 0.5 -#> 5 27.3 OJ 1 -#> 6 25.8 OJ 1 -#> 7 22.5 VC 1 -#> 8 13.6 VC 1 -#> 9 24.8 OJ 2 -#> 10 30.9 OJ 2 -#> 11 23.3 VC 2 -#> 12 18.5 VC 2
+
+
sample_n_by(data, ..., size = 1, replace = FALSE)
+
+ +
+

Arguments

+
data
+

a data frame

+ + +
...
+

Variables to group by

+ + +
size
+

the number of rows to select

+ + +
replace
+

with or without replacement?

+ +
+ +
+

Examples

+
ToothGrowth %>% sample_n_by(dose, supp, size = 2)
+#> # A tibble: 12 × 3
+#>      len supp   dose
+#>    <dbl> <fct> <dbl>
+#>  1  14.5 OJ      0.5
+#>  2   8.2 OJ      0.5
+#>  3   5.2 VC      0.5
+#>  4   7   VC      0.5
+#>  5  27.3 OJ      1  
+#>  6  25.8 OJ      1  
+#>  7  22.5 VC      1  
+#>  8  13.6 VC      1  
+#>  9  24.8 OJ      2  
+#> 10  30.9 OJ      2  
+#> 11  23.3 VC      2  
+#> 12  18.5 VC      2  
+
+
+
-
- +
- - + + diff --git a/docs/reference/shapiro_test.html b/docs/reference/shapiro_test.html index 8a21315..531590b 100644 --- a/docs/reference/shapiro_test.html +++ b/docs/reference/shapiro_test.html @@ -1,74 +1,17 @@ - - - - - - - -Shapiro-Wilk Normality Test — shapiro_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Shapiro-Wilk Normality Test — shapiro_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -127,92 +57,97 @@

Shapiro-Wilk Normality Test

Provides a pipe-friendly framework to performs Shapiro-Wilk test of normality. Support grouped data and multiple variables for multivariate normality tests. Wrapper around the R base function - shapiro.test(). Can handle grouped data. Read more: - Normality + shapiro.test(). Can handle grouped data. Read more: + Normality Test in R.

-
shapiro_test(data, ..., vars = NULL)
-
-mshapiro_test(data)
- -

Arguments

- - - - - - - - - - - - - - -
data

a data frame. Columns are variables.

...

One or more unquoted expressions (or variable names) separated by -commas. Used to select a variable of interest.

vars

optional character vector containing variable names. Ignored when -dot vars are specified.

- -

Value

- -

a data frame containing the value of the Shapiro-Wilk statistic and - the corresponding p.value.

-

Functions

+
+
shapiro_test(data, ..., vars = NULL)
+
+mshapiro_test(data)
+
+ +
+

Arguments

+
data
+

a data frame. Columns are variables.

+ +
...
+

One or more unquoted expressions (or variable names) separated by +commas. Used to select a variable of interest.

+ + +
vars
+

optional character vector containing variable names. Ignored when +dot vars are specified.

+ +
+
+

Value

-
    -
  • shapiro_test: univariate Shapiro-Wilk normality test

  • -
  • mshapiro_test: multivariate Shapiro-Wilk normality test. This is a + +

    a data frame containing the value of the Shapiro-Wilk statistic and + the corresponding p.value.

    +
+
+

Functions

+ +
  • shapiro_test(): univariate Shapiro-Wilk normality test

  • +
  • mshapiro_test(): multivariate Shapiro-Wilk normality test. This is a modified copy of the mshapiro.test() function of the package mvnormtest, for internal convenience.

  • -
- -

Examples

-
-# Shapiro Wilk normality test for one variable -iris %>% shapiro_test(Sepal.Length)
#> # A tibble: 1 x 3 -#> variable statistic p -#> <chr> <dbl> <dbl> -#> 1 Sepal.Length 0.976 0.0102
-# Shapiro Wilk normality test for two variables -iris %>% shapiro_test(Sepal.Length, Petal.Width)
#> # A tibble: 2 x 3 -#> variable statistic p -#> <chr> <dbl> <dbl> -#> 1 Petal.Width 0.902 0.0000000168 -#> 2 Sepal.Length 0.976 0.0102
-# Multivariate normality test -mshapiro_test(iris[, 1:3])
#> # A tibble: 1 x 2 -#> statistic p.value -#> <dbl> <dbl> -#> 1 0.991 0.443
-
+
+ +
+

Examples

+

+# Shapiro Wilk normality test for one variable
+iris %>% shapiro_test(Sepal.Length)
+#> # A tibble: 1 × 3
+#>   variable     statistic      p
+#>   <chr>            <dbl>  <dbl>
+#> 1 Sepal.Length     0.976 0.0102
+
+# Shapiro Wilk normality test for two variables
+iris %>% shapiro_test(Sepal.Length, Petal.Width)
+#> # A tibble: 2 × 3
+#>   variable     statistic            p
+#>   <chr>            <dbl>        <dbl>
+#> 1 Petal.Width      0.902 0.0000000168
+#> 2 Sepal.Length     0.976 0.0102      
+
+# Multivariate normality test
+mshapiro_test(iris[, 1:3])
+#> # A tibble: 1 × 2
+#>   statistic p.value
+#>       <dbl>   <dbl>
+#> 1     0.991   0.443
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/sign_test.html b/docs/reference/sign_test.html index 700ca7d..6ff69ea 100644 --- a/docs/reference/sign_test.html +++ b/docs/reference/sign_test.html @@ -1,70 +1,13 @@ - - - - - - - -Sign Test — sign_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Sign Test — sign_test • rstatix - - - - + + -
-
- -
- -
+

Performs one-sample and two-sample sign tests. Read more: - Sign Test in R.

+ Sign Test in R.

-
sign_test(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  p.adjust.method = "holm",
-  alternative = "two.sided",
-  mu = 0,
-  conf.level = 0.95,
-  detailed = FALSE
-)
-
-pairwise_sign_test(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  p.adjust.method = "holm",
-  detailed = FALSE,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
sign_test(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  p.adjust.method = "holm",
+  alternative = "two.sided",
+  mu = 0,
+  conf.level = 0.95,
+  detailed = FALSE
+)
+
+pairwise_sign_test(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  p.adjust.method = "holm",
+  detailed = FALSE,
+  ...
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ treatment.

comparisons

A list of length-2 vectors specifying the groups of +formula = TP53 ~ treatment.

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

ref.group

a character string specifying the reference group. If +"C"))

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be -compared to the reference group (i.e. control group).

p.adjust.method

method to adjust p values for multiple comparisons. +compared to the reference group (i.e. control group).

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

alternative

a character string specifying the alternative +want to adjust the p value (not recommended), use p.adjust.method = "none".

+ + +
alternative
+

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial - letter.

mu

a single number representing the value of the population median -specified by the null hypothesis.

conf.level

confidence level of the interval.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

...

other arguments passed to the function sign_test()

- -

Value

- -

return a data frame with some the following columns:

    -
  • .y.: the y variable used in the test.

  • + letter.

    + + +
    mu
    +

    a single number representing the value of the population median +specified by the null hypothesis.

    + + +
    conf.level
    +

    confidence level of the interval.

    + + +
    detailed
    +

    logical value. Default is FALSE. If TRUE, a detailed result is +shown.

    + + +
    ...
    +

    other arguments passed to the function sign_test()

    + +
+
+

Value

+ + +

return a data frame with some the following columns:

  • .y.: the y variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n,n1,n2: Sample counts.

  • @@ -231,99 +161,108 @@

    Value

    alternative hypothesis.

  • conf.low,conf.high: Lower and upper bound on a confidence interval of the estimate.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Functions

- +
+
+

Functions

-
    -
  • sign_test: Sign test

  • -
  • pairwise_sign_test: performs pairwise two sample Wilcoxon test.

  • -
-

Note

- +
  • sign_test(): Sign test

  • +
  • pairwise_sign_test(): performs pairwise two sample Wilcoxon test.

  • +
+
+

Note

This function is a reimplementation of the function SignTest() from the DescTools package.

+
-

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# One-sample test -#::::::::::::::::::::::::::::::::::::::::: -df %>% sign_test(len ~ 1, mu = 0)
#> # A tibble: 1 x 7 -#> .y. group1 group2 n statistic df p -#> * <chr> <chr> <chr> <int> <dbl> <dbl> <dbl> -#> 1 len 1 null model 60 60 60 1.73e-18
- -# Two-samples paired test -#::::::::::::::::::::::::::::::::::::::::: -df %>% sign_test(len ~ supp)
#> # A tibble: 1 x 8 -#> .y. group1 group2 n1 n2 statistic df p -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> -#> 1 len OJ VC 30 30 19 29 0.136
- -# Compare supp levels after grouping the data by "dose" -#:::::::::::::::::::::::::::::::::::::::: -df %>% - group_by(dose) %>% - sign_test(data =., len ~ supp) %>% - adjust_pvalue(method = "bonferroni") %>% - add_significance("p.adj")
#> # A tibble: 3 x 11 -#> dose .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <dbl> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 0.5 len OJ VC 10 10 7 9 0.18 0.54 ns -#> 2 1 len OJ VC 10 10 8 10 0.109 0.327 ns -#> 3 2 len OJ VC 10 10 4 10 0.754 1 ns
-# pairwise comparisons -#:::::::::::::::::::::::::::::::::::::::: -# As dose contains more than two levels ==> -# pairwise test is automatically performed. -df %>% sign_test(len ~ dose)
#> # A tibble: 3 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 1 20 4.01e-5 8.02e-5 **** -#> 2 len 0.5 2 20 20 0 20 1.91e-6 5.73e-6 **** -#> 3 len 1 2 20 20 3 20 3 e-3 3 e-3 **
-# Comparison against reference group -#:::::::::::::::::::::::::::::::::::::::: -# each level is compared to the ref group -df %>% sign_test(len ~ dose, ref.group = "0.5")
#> # A tibble: 2 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 1 20 4.01e-5 4.01e-5 **** -#> 2 len 0.5 2 20 20 0 20 1.91e-6 3.82e-6 ****
- -
+
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# One-sample test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% sign_test(len ~ 1, mu = 0)
+#> # A tibble: 1 × 7
+#>   .y.   group1 group2         n statistic    df        p
+#> * <chr> <chr>  <chr>      <int>     <dbl> <dbl>    <dbl>
+#> 1 len   1      null model    60        60    60 1.73e-18
+
+
+# Two-samples paired test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% sign_test(len ~ supp)
+#> # A tibble: 1 × 8
+#>   .y.   group1 group2    n1    n2 statistic    df     p
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl> <dbl>
+#> 1 len   OJ     VC        30    30        19    29 0.136
+
+
+# Compare supp levels after grouping the data by "dose"
+#::::::::::::::::::::::::::::::::::::::::
+df %>%
+  group_by(dose) %>%
+  sign_test(data =., len ~ supp) %>%
+  adjust_pvalue(method = "bonferroni") %>%
+  add_significance("p.adj")
+#> # A tibble: 3 × 11
+#>    dose .y.   group1 group2    n1    n2 statistic    df     p p.adj p.adj.signif
+#>   <dbl> <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl> <dbl> <dbl> <chr>       
+#> 1   0.5 len   OJ     VC        10    10         7     9 0.18  0.54  ns          
+#> 2   1   len   OJ     VC        10    10         8    10 0.109 0.327 ns          
+#> 3   2   len   OJ     VC        10    10         4    10 0.754 1     ns          
+
+# pairwise comparisons
+#::::::::::::::::::::::::::::::::::::::::
+# As dose contains more than two levels ==>
+# pairwise test is automatically performed.
+df %>% sign_test(len ~ dose)
+#> # A tibble: 3 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df          p      p.adj p.adj.…¹
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>      <dbl>      <dbl> <chr>   
+#> 1 len   0.5    1         20    20         1    20 0.0000401  0.0000802  ****    
+#> 2 len   0.5    2         20    20         0    20 0.00000191 0.00000573 ****    
+#> 3 len   1      2         20    20         3    20 0.003      0.003      **      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+# Comparison against reference group
+#::::::::::::::::::::::::::::::::::::::::
+# each level is compared to the ref group
+df %>% sign_test(len ~ dose, ref.group = "0.5")
+#> # A tibble: 2 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df          p      p.adj p.adj.…¹
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>      <dbl>      <dbl> <chr>   
+#> 1 len   0.5    1         20    20         1    20 0.0000401  0.0000401  ****    
+#> 2 len   0.5    2         20    20         0    20 0.00000191 0.00000382 ****    
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/t_test.html b/docs/reference/t_test.html index 63319f8..69ec6e1 100644 --- a/docs/reference/t_test.html +++ b/docs/reference/t_test.html @@ -1,70 +1,13 @@ - - - - - - - -T-test — t_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -T-test — t_test • rstatix - - - - + + -
-
- -
- -
+

Provides a pipe-friendly framework to performs one and two sample - t-tests. Read more: T-test in R.

+ t-tests. Read more: T-test in R.

-
t_test(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  p.adjust.method = "holm",
-  paired = FALSE,
-  var.equal = FALSE,
-  alternative = "two.sided",
-  mu = 0,
-  conf.level = 0.95,
-  detailed = FALSE
-)
-
-pairwise_t_test(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  p.adjust.method = "holm",
-  paired = FALSE,
-  pool.sd = !paired,
-  detailed = FALSE,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
t_test(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  p.adjust.method = "holm",
+  paired = FALSE,
+  var.equal = FALSE,
+  alternative = "two.sided",
+  mu = 0,
+  conf.level = 0.95,
+  detailed = FALSE
+)
+
+pairwise_t_test(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  p.adjust.method = "holm",
+  paired = FALSE,
+  pool.sd = !paired,
+  detailed = FALSE,
+  ...
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

comparisons

A list of length-2 vectors specifying the groups of +formula = TP53 ~ cancer_group.

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

ref.group

a character string specifying the reference group. If +"C"))

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).

If ref.group = "all", pairwise two sample tests are performed for - comparing each grouping variable levels against all (i.e. basemean).

p.adjust.method

method to adjust p values for multiple comparisons. + comparing each grouping variable levels against all (i.e. basemean).

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

paired

a logical indicating whether you want a paired test.

var.equal

a logical variable indicating whether to treat the +want to adjust the p value (not recommended), use p.adjust.method = "none".

+ + +
paired
+

a logical indicating whether you want a paired test.

+ + +
var.equal
+

a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch - (or Satterthwaite) approximation to the degrees of freedom is used.

alternative

a character string specifying the alternative + (or Satterthwaite) approximation to the degrees of freedom is used.

+ + +
alternative
+

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial - letter.

mu

a number specifying an optional parameter used to form the null hypothesis.

conf.level

confidence level of the interval.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

pool.sd

logical value used in the function pairwise_t_test(). + letter.

+ + +
mu
+

a number specifying an optional parameter used to form the null hypothesis.

+ + +
conf.level
+

confidence level of the interval.

+ + +
detailed
+

logical value. Default is FALSE. If TRUE, a detailed result is +shown.

+ + +
pool.sd
+

logical value used in the function pairwise_t_test(). Switch to allow/disallow the use of a pooled SD.

The pool.sd = TRUE (default) calculates a common SD for all groups and uses that for all comparisons (this can be useful if some groups are @@ -227,20 +157,20 @@

Arg ignored. Pooling does not generalize to paired tests so pool.sd and paired cannot both be TRUE.

If pool.sd = FALSE the standard two sample t-test is applied to all - possible pairs of groups. This method calls the t.test(), so extra - arguments, such as var.equal are accepted.

...

other arguments to be passed to the function -t.test.

- -

Value

- -

return a data frame with some the following columns:

    -
  • .y.: the y variable used in the test.

  • + possible pairs of groups. This method calls the t.test(), so extra + arguments, such as var.equal are accepted.

    + + +
    ...
    +

    other arguments to be passed to the function +t.test.

    + +
+
+

Value

+ + +

return a data frame with some the following columns:

  • .y.: the y variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n,n1,n2: Sample counts.

  • @@ -263,116 +193,128 @@

    Value

    hypothesis.

  • conf.low,conf.high: Lower and upper bound on a confidence interval.

  • -
- -

The returned object has an attribute called args, which is a list +

The returned object has an attribute called args, which is a list holding the test arguments.

-

Details

- +
+
+

Details

- If a list of comparisons is specified, the result of the pairwise tests is filtered to keep only the comparisons of interest. The p-value is adjusted after filtering.

- For a grouped data, if pairwise test is performed, then the p-values are adjusted for each group level independently.

-

Functions

- +
+
+

Functions

-
    -
  • t_test: t test

  • -
  • pairwise_t_test: performs pairwise two sample t-test. Wrapper around the R -base function pairwise.t.test.

  • -
- -

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# One-sample test -#::::::::::::::::::::::::::::::::::::::::: -df %>% t_test(len ~ 1, mu = 0)
#> # A tibble: 1 x 7 -#> .y. group1 group2 n statistic df p -#> * <chr> <chr> <chr> <int> <dbl> <dbl> <dbl> -#> 1 len 1 null model 60 19.1 59 6.94e-27
- -# Two-samples unpaired test -#::::::::::::::::::::::::::::::::::::::::: -df %>% t_test(len ~ supp)
#> # A tibble: 1 x 8 -#> .y. group1 group2 n1 n2 statistic df p -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> -#> 1 len OJ VC 30 30 1.92 55.3 0.0606
-# Two-samples paired test -#::::::::::::::::::::::::::::::::::::::::: -df %>% t_test (len ~ supp, paired = TRUE)
#> # A tibble: 1 x 8 -#> .y. group1 group2 n1 n2 statistic df p -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> -#> 1 len OJ VC 30 30 3.30 29 0.00255
-# Compare supp levels after grouping the data by "dose" -#:::::::::::::::::::::::::::::::::::::::: -df %>% - group_by(dose) %>% - t_test(data =., len ~ supp) %>% - adjust_pvalue(method = "bonferroni") %>% - add_significance("p.adj")
#> # A tibble: 3 x 11 -#> dose .y. group1 group2 n1 n2 statistic df p p.adj -#> * <dbl> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> -#> 1 0.5 len OJ VC 10 10 3.17 15.0 0.00636 0.0191 -#> 2 1 len OJ VC 10 10 4.03 15.4 0.00104 0.00312 -#> 3 2 len OJ VC 10 10 -0.0461 14.0 0.964 1 -#> # … with 1 more variable: p.adj.signif <chr>
-# pairwise comparisons -#:::::::::::::::::::::::::::::::::::::::: -# As dose contains more than two levels ==> -# pairwise test is automatically performed. -df %>% t_test(len ~ dose)
#> # A tibble: 3 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 -6.48 38.0 1.27e- 7 2.54e- 7 **** -#> 2 len 0.5 2 20 20 -11.8 36.9 4.4 e-14 1.32e-13 **** -#> 3 len 1 2 20 20 -4.90 37.1 1.91e- 5 1.91e- 5 ****
-# Comparison against reference group -#:::::::::::::::::::::::::::::::::::::::: -# each level is compared to the ref group -df %>% t_test(len ~ dose, ref.group = "0.5")
#> # A tibble: 2 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 0.5 1 20 20 -6.48 38.0 1.27e- 7 1.27e- 7 **** -#> 2 len 0.5 2 20 20 -11.8 36.9 4.4 e-14 8.8 e-14 ****
-# Comparison against all -#:::::::::::::::::::::::::::::::::::::::: -df %>% t_test(len ~ dose, ref.group = "all")
#> # A tibble: 3 x 10 -#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif -#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len all 0.5 60 20 5.82 56.4 2.9 e-7 8.7 e-7 **** -#> 2 len all 1 60 20 -0.660 57.5 5.12e-1 5.12e-1 ns -#> 3 len all 2 60 20 -5.61 66.5 4.25e-7 8.7 e-7 ****
-
+
  • t_test(): t test

  • +
  • pairwise_t_test(): performs pairwise two sample t-test. Wrapper around the R +base function pairwise.t.test.

  • +
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# One-sample test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% t_test(len ~ 1, mu = 0)
+#> # A tibble: 1 × 7
+#>   .y.   group1 group2         n statistic    df        p
+#> * <chr> <chr>  <chr>      <int>     <dbl> <dbl>    <dbl>
+#> 1 len   1      null model    60      19.1    59 6.94e-27
+
+
+# Two-samples unpaired test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% t_test(len ~ supp)
+#> # A tibble: 1 × 8
+#>   .y.   group1 group2    n1    n2 statistic    df      p
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>  <dbl>
+#> 1 len   OJ     VC        30    30      1.92  55.3 0.0606
+
+# Two-samples paired test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% t_test (len ~ supp, paired = TRUE)
+#> # A tibble: 1 × 8
+#>   .y.   group1 group2    n1    n2 statistic    df       p
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>   <dbl>
+#> 1 len   OJ     VC        30    30      3.30    29 0.00255
+
+# Compare supp levels after grouping the data by "dose"
+#::::::::::::::::::::::::::::::::::::::::
+df %>%
+  group_by(dose) %>%
+  t_test(data =., len ~ supp) %>%
+  adjust_pvalue(method = "bonferroni") %>%
+  add_significance("p.adj")
+#> # A tibble: 3 × 11
+#>    dose .y.   group1 group2    n1    n2 statistic    df       p   p.adj p.adj.…¹
+#>   <dbl> <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>   <dbl>   <dbl> <chr>   
+#> 1   0.5 len   OJ     VC        10    10    3.17    15.0 0.00636 0.0191  *       
+#> 2   1   len   OJ     VC        10    10    4.03    15.4 0.00104 0.00312 **      
+#> 3   2   len   OJ     VC        10    10   -0.0461  14.0 0.964   1       ns      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+# pairwise comparisons
+#::::::::::::::::::::::::::::::::::::::::
+# As dose contains more than two levels ==>
+# pairwise test is automatically performed.
+df %>% t_test(len ~ dose)
+#> # A tibble: 3 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df        p    p.adj p.adj.signif
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 len   0.5    1         20    20     -6.48  38.0 1.27e- 7 2.54e- 7 ****        
+#> 2 len   0.5    2         20    20    -11.8   36.9 4.4 e-14 1.32e-13 ****        
+#> 3 len   1      2         20    20     -4.90  37.1 1.91e- 5 1.91e- 5 ****        
+
+# Comparison against reference group
+#::::::::::::::::::::::::::::::::::::::::
+# each level is compared to the ref group
+df %>% t_test(len ~ dose, ref.group = "0.5")
+#> # A tibble: 2 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df        p    p.adj p.adj.signif
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
+#> 1 len   0.5    1         20    20     -6.48  38.0 1.27e- 7 1.27e- 7 ****        
+#> 2 len   0.5    2         20    20    -11.8   36.9 4.4 e-14 8.8 e-14 ****        
+
+# Comparison against all
+#::::::::::::::::::::::::::::::::::::::::
+df %>% t_test(len ~ dose, ref.group = "all")
+#> # A tibble: 3 × 10
+#>   .y.   group1 group2    n1    n2 statistic    df           p      p.adj p.adj…¹
+#> * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>       <dbl>      <dbl> <chr>  
+#> 1 len   all    0.5       60    20     5.82   56.4 0.00000029  0.00000087 ****   
+#> 2 len   all    1         60    20    -0.660  57.5 0.512       0.512      ns     
+#> 3 len   all    2         60    20    -5.61   66.5 0.000000425 0.00000087 ****   
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/tukey_hsd.html b/docs/reference/tukey_hsd.html index 0cf4d62..3e49c1c 100644 --- a/docs/reference/tukey_hsd.html +++ b/docs/reference/tukey_hsd.html @@ -1,72 +1,15 @@ - - - - - - - -Tukey Honest Significant Differences — tukey_hsd • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Tukey Honest Significant Differences — tukey_hsd • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Provides a pipe-friendly framework to performs Tukey post-hoc - tests. Wrapper around the function TukeyHSD(). It is + tests. Wrapper around the function TukeyHSD(). It is essentially a t-test that corrects for multiple testing.

Can handle different inputs formats: aov, lm, formula.

-
tukey_hsd(x, ...)
-
-# S3 method for default
-tukey_hsd(x, ...)
+    
+
tukey_hsd(x, ...)
+
+# S3 method for default
+tukey_hsd(x, ...)
+
+# S3 method for lm
+tukey_hsd(x, ...)
+
+# S3 method for data.frame
+tukey_hsd(x, formula, ...)
+
-# S3 method for lm -tukey_hsd(x, ...) +
+

Arguments

+
x
+

an object of class aov, lm or data.frame +containing the variables used in the formula.

-# S3 method for data.frame -tukey_hsd(x, formula, ...)
-

Arguments

- - - - - - - - - - - - - - - - - - -
x

an object of class aov, lm or data.frame -containing the variables used in the formula.

...

other arguments passed to the function -TukeyHSD(). These include:

    -
  • which: A character vector listing terms in the fitted model for +

    ...
    +

    other arguments passed to the function +TukeyHSD(). These include:

    • which: A character vector listing terms in the fitted model for which the intervals should be calculated. Defaults to all the terms.

    • ordered: A logical value indicating if the levels of the factor should be ordered according to increasing average in the sample before taking differences. If ordered is true then the calculated differences in the means will all be positive. The significant differences will be those for which the lwr end point is positive.

    • -
formula

a formula of the form x ~ group where x is a + + + +

formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

data

a data.frame containing the variables in the formula.

+formula = TP53 ~ cancer_group.

-

Value

-

a tibble data frame containing the results of the different - comparisons.

-

Methods (by class)

+
data
+

a data.frame containing the variables in the formula.

+
+
+

Value

-
    -
  • default: performs tukey post-hoc test from aov() results.

  • -
  • lm: performs tukey post-hoc test from lm() model.

  • -
  • data.frame: performs tukey post-hoc tests using data and formula as -inputs. ANOVA will be automatically performed using the function -aov()

  • -
-

Examples

-
# Data preparation -df <- ToothGrowth -df$dose <- as.factor(df$dose) -# Tukey HSD from ANOVA results -aov(len ~ dose, data = df) %>% tukey_hsd()
#> # A tibble: 3 x 9 -#> term group1 group2 null.value estimate conf.low conf.high p.adj -#> * <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 dose 0.5 1 0 9.13 5.90 12.4 2 e- 8 -#> 2 dose 0.5 2 0 15.5 12.3 18.7 1.12e-11 -#> 3 dose 1 2 0 6.36 3.14 9.59 4.25e- 5 -#> # … with 1 more variable: p.adj.signif <chr>
-# two-way anova with interaction -aov(len ~ dose*supp, data = df) %>% tukey_hsd()
#> # A tibble: 19 x 9 -#> term group1 group2 null.value estimate conf.low conf.high p.adj -#> * <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 dose 0.5 1 0 9.13 6.36 11.9 3.55e-10 -#> 2 dose 0.5 2 0 15.5 12.7 18.3 4.38e-13 -#> 3 dose 1 2 0 6.36 3.60 9.13 2.71e- 6 -#> 4 supp OJ VC 0 -3.70 -5.58 -1.82 2.31e- 4 -#> 5 dose:supp 0.5:OJ 1:OJ 0 9.47 4.67 14.3 4.61e- 6 -#> 6 dose:supp 0.5:OJ 2:OJ 0 12.8 8.03 17.6 2.13e- 9 -#> 7 dose:supp 0.5:OJ 0.5:VC 0 -5.25 -10.0 -0.452 2.43e- 2 -#> 8 dose:supp 0.5:OJ 1:VC 0 3.54 -1.26 8.34 2.64e- 1 -#> 9 dose:supp 0.5:OJ 2:VC 0 12.9 8.11 17.7 1.77e- 9 -#> 10 dose:supp 1:OJ 2:OJ 0 3.36 -1.44 8.16 3.19e- 1 -#> 11 dose:supp 1:OJ 0.5:VC 0 -14.7 -19.5 -9.92 2.99e-11 -#> 12 dose:supp 1:OJ 1:VC 0 -5.93 -10.7 -1.13 7.39e- 3 -#> 13 dose:supp 1:OJ 2:VC 0 3.44 -1.36 8.24 2.94e- 1 -#> 14 dose:supp 2:OJ 0.5:VC 0 -18.1 -22.9 -13.3 4.86e-13 -#> 15 dose:supp 2:OJ 1:VC 0 -9.29 -14.1 -4.49 6.91e- 6 -#> 16 dose:supp 2:OJ 2:VC 0 0.0800 -4.72 4.88 1 e+ 0 -#> 17 dose:supp 0.5:VC 1:VC 0 8.79 3.99 13.6 2.1 e- 5 -#> 18 dose:supp 0.5:VC 2:VC 0 18.2 13.4 23.0 4.82e-13 -#> 19 dose:supp 1:VC 2:VC 0 9.37 4.57 14.2 5.77e- 6 -#> # … with 1 more variable: p.adj.signif <chr>
-# Tukey HSD from lm() results -lm(len ~ dose, data = df) %>% tukey_hsd()
#> # A tibble: 3 x 9 -#> term group1 group2 null.value estimate conf.low conf.high p.adj -#> * <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 dose 0.5 1 0 9.13 5.90 12.4 2 e- 8 -#> 2 dose 0.5 2 0 15.5 12.3 18.7 1.12e-11 -#> 3 dose 1 2 0 6.36 3.14 9.59 4.25e- 5 -#> # … with 1 more variable: p.adj.signif <chr>
-# Tukey HSD from data frame and formula -tukey_hsd(df, len ~ dose)
#> # A tibble: 3 x 9 -#> term group1 group2 null.value estimate conf.low conf.high p.adj -#> * <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 dose 0.5 1 0 9.13 5.90 12.4 2 e- 8 -#> 2 dose 0.5 2 0 15.5 12.3 18.7 1.12e-11 -#> 3 dose 1 2 0 6.36 3.14 9.59 4.25e- 5 -#> # … with 1 more variable: p.adj.signif <chr>
-# Tukey HSD using grouped data -df %>% - group_by(supp) %>% - tukey_hsd(len ~ dose)
#> # A tibble: 6 x 10 -#> supp term group1 group2 null.value estimate conf.low conf.high p.adj -#> * <fct> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 OJ dose 0.5 1 0 9.47 5.31 13.6 1.58e- 5 -#> 2 OJ dose 0.5 2 0 12.8 8.67 17.0 9.39e- 8 -#> 3 OJ dose 1 2 0 3.36 -0.800 7.52 1.31e- 1 -#> 4 VC dose 0.5 1 0 8.79 4.90 12.7 1.75e- 5 -#> 5 VC dose 0.5 2 0 18.2 14.3 22.0 1.66e-11 -#> 6 VC dose 1 2 0 9.37 5.48 13.3 6.61e- 6 -#> # … with 1 more variable: p.adj.signif <chr>
-
+

a tibble data frame containing the results of the different + comparisons.

+
+
+

Methods (by class)

+ +
  • tukey_hsd(default): performs tukey post-hoc test from aov() results.

  • +
  • tukey_hsd(lm): performs tukey post-hoc test from lm() model.

  • +
  • tukey_hsd(data.frame): performs tukey post-hoc tests using data and formula as +inputs. ANOVA will be automatically performed using the function +aov()

  • +
+ +
+

Examples

+
# Data preparation
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+# Tukey HSD from ANOVA results
+aov(len ~ dose, data = df) %>% tukey_hsd()
+#> # A tibble: 3 × 9
+#>   term  group1 group2 null.value estimate conf.low conf.high    p.adj p.adj.si…¹
+#> * <chr> <chr>  <chr>       <dbl>    <dbl>    <dbl>     <dbl>    <dbl> <chr>     
+#> 1 dose  0.5    1               0     9.13     5.90     12.4  2   e- 8 ****      
+#> 2 dose  0.5    2               0    15.5     12.3      18.7  1.12e-11 ****      
+#> 3 dose  1      2               0     6.36     3.14      9.59 4.25e- 5 ****      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+# two-way anova with interaction
+aov(len ~ dose*supp, data = df) %>% tukey_hsd()
+#> # A tibble: 19 × 9
+#>    term      group1 group2 null.value estimate conf.low conf.…¹    p.adj p.adj…²
+#>  * <chr>     <chr>  <chr>       <dbl>    <dbl>    <dbl>   <dbl>    <dbl> <chr>  
+#>  1 dose      0.5    1               0   9.13       6.36  11.9   3.55e-10 ****   
+#>  2 dose      0.5    2               0  15.5       12.7   18.3   4.38e-13 ****   
+#>  3 dose      1      2               0   6.36       3.60   9.13  2.71e- 6 ****   
+#>  4 supp      OJ     VC              0  -3.70      -5.58  -1.82  2.31e- 4 ***    
+#>  5 dose:supp 0.5:OJ 1:OJ            0   9.47       4.67  14.3   4.61e- 6 ****   
+#>  6 dose:supp 0.5:OJ 2:OJ            0  12.8        8.03  17.6   2.13e- 9 ****   
+#>  7 dose:supp 0.5:OJ 0.5:VC          0  -5.25     -10.0   -0.452 2.43e- 2 *      
+#>  8 dose:supp 0.5:OJ 1:VC            0   3.54      -1.26   8.34  2.64e- 1 ns     
+#>  9 dose:supp 0.5:OJ 2:VC            0  12.9        8.11  17.7   1.77e- 9 ****   
+#> 10 dose:supp 1:OJ   2:OJ            0   3.36      -1.44   8.16  3.19e- 1 ns     
+#> 11 dose:supp 1:OJ   0.5:VC          0 -14.7      -19.5   -9.92  2.99e-11 ****   
+#> 12 dose:supp 1:OJ   1:VC            0  -5.93     -10.7   -1.13  7.39e- 3 **     
+#> 13 dose:supp 1:OJ   2:VC            0   3.44      -1.36   8.24  2.94e- 1 ns     
+#> 14 dose:supp 2:OJ   0.5:VC          0 -18.1      -22.9  -13.3   4.86e-13 ****   
+#> 15 dose:supp 2:OJ   1:VC            0  -9.29     -14.1   -4.49  6.91e- 6 ****   
+#> 16 dose:supp 2:OJ   2:VC            0   0.0800    -4.72   4.88  1   e+ 0 ns     
+#> 17 dose:supp 0.5:VC 1:VC            0   8.79       3.99  13.6   2.1 e- 5 ****   
+#> 18 dose:supp 0.5:VC 2:VC            0  18.2       13.4   23.0   4.82e-13 ****   
+#> 19 dose:supp 1:VC   2:VC            0   9.37       4.57  14.2   5.77e- 6 ****   
+#> # … with abbreviated variable names ¹​conf.high, ²​p.adj.signif
+
+# Tukey HSD from lm() results
+lm(len ~ dose, data = df) %>% tukey_hsd()
+#> # A tibble: 3 × 9
+#>   term  group1 group2 null.value estimate conf.low conf.high    p.adj p.adj.si…¹
+#> * <chr> <chr>  <chr>       <dbl>    <dbl>    <dbl>     <dbl>    <dbl> <chr>     
+#> 1 dose  0.5    1               0     9.13     5.90     12.4  2   e- 8 ****      
+#> 2 dose  0.5    2               0    15.5     12.3      18.7  1.12e-11 ****      
+#> 3 dose  1      2               0     6.36     3.14      9.59 4.25e- 5 ****      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+# Tukey HSD from data frame and formula
+tukey_hsd(df, len ~ dose)
+#> # A tibble: 3 × 9
+#>   term  group1 group2 null.value estimate conf.low conf.high    p.adj p.adj.si…¹
+#> * <chr> <chr>  <chr>       <dbl>    <dbl>    <dbl>     <dbl>    <dbl> <chr>     
+#> 1 dose  0.5    1               0     9.13     5.90     12.4  2   e- 8 ****      
+#> 2 dose  0.5    2               0    15.5     12.3      18.7  1.12e-11 ****      
+#> 3 dose  1      2               0     6.36     3.14      9.59 4.25e- 5 ****      
+#> # … with abbreviated variable name ¹​p.adj.signif
+
+# Tukey HSD using grouped data
+df %>%
+  group_by(supp) %>%
+  tukey_hsd(len ~ dose)
+#> # A tibble: 6 × 10
+#>   supp  term  group1 group2 null.value estimate conf.…¹ conf.…²    p.adj p.adj…³
+#> * <fct> <chr> <chr>  <chr>       <dbl>    <dbl>   <dbl>   <dbl>    <dbl> <chr>  
+#> 1 OJ    dose  0.5    1               0     9.47   5.31    13.6  1.58e- 5 ****   
+#> 2 OJ    dose  0.5    2               0    12.8    8.67    17.0  9.39e- 8 ****   
+#> 3 OJ    dose  1      2               0     3.36  -0.800    7.52 1.31e- 1 ns     
+#> 4 VC    dose  0.5    1               0     8.79   4.90    12.7  1.75e- 5 ****   
+#> 5 VC    dose  0.5    2               0    18.2   14.3     22.0  1.66e-11 ****   
+#> 6 VC    dose  1      2               0     9.37   5.48    13.3  6.61e- 6 ****   
+#> # … with abbreviated variable names ¹​conf.low, ²​conf.high, ³​p.adj.signif
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/welch_anova_test.html b/docs/reference/welch_anova_test.html index 330dfb1..1785f7f 100644 --- a/docs/reference/welch_anova_test.html +++ b/docs/reference/welch_anova_test.html @@ -1,73 +1,16 @@ - - - - - - - -Welch One-Way ANOVA Test — welch_anova_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Welch One-Way ANOVA Test — welch_anova_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Tests for equal means in a one-way design (not assuming equal variance). A wrapper around the base function - oneway.test(). This is is an alternative to the + oneway.test(). This is is an alternative to the standard one-way ANOVA in the situation where the homogeneity of variance assumption is violated.

-
welch_anova_test(data, formula)
- -

Arguments

- - - - - - - - - - -
data

a data frame containing the variables in the formula.

formula

a formula specifying the ANOVA model similar to aov. Can be of +

+
welch_anova_test(data, formula)
+
+ +
+

Arguments

+
data
+

a data frame containing the variables in the formula.

+ + +
formula
+

a formula specifying the ANOVA model similar to aov. Can be of the form y ~ group where y is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding -groups. For example, formula = TP53 ~ cancer_group.

+groups. For example, formula = TP53 ~ cancer_group.

-

Value

+
+
+

Value

+ -

return a data frame with the following columns:

    -
  • .y.: the y variable used in the test.

  • +

    return a data frame with the following columns:

    • .y.: the y variable used in the test.

    • n: sample count.

    • statistic: the value of the test statistic.

    • p: p-value.

    • method: the statistical test used to compare groups.

    • -
    - - -

    Examples

    -
    # Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth -df$dose <- as.factor(df$dose) - -# Welch one-way ANOVA test (not assuming equal variance) -#::::::::::::::::::::::::::::::::::::::::: -df %>% welch_anova_test(len ~ dose)
    #> # A tibble: 1 x 7 -#> .y. n statistic DFn DFd p method -#> * <chr> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 len 60 68.4 2 37.7 2.81e-13 Welch ANOVA
    -# Grouped data -#::::::::::::::::::::::::::::::::::::::::: -df %>% - group_by(supp) %>% - welch_anova_test(len ~ dose)
    #> # A tibble: 2 x 8 -#> supp .y. n statistic DFn DFd p method -#> * <fct> <chr> <int> <dbl> <dbl> <dbl> <dbl> <chr> -#> 1 OJ len 30 29.4 2 17.1 0.00000295 Welch ANOVA -#> 2 VC len 30 59.4 2 17.2 0.0000000194 Welch ANOVA
    +
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+df$dose <- as.factor(df$dose)
+
+# Welch one-way ANOVA test (not assuming equal variance)
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% welch_anova_test(len ~ dose)
+#> # A tibble: 1 × 7
+#>   .y.       n statistic   DFn   DFd        p method     
+#> * <chr> <int>     <dbl> <dbl> <dbl>    <dbl> <chr>      
+#> 1 len      60      68.4     2  37.7 2.81e-13 Welch ANOVA
+
+# Grouped data
+#:::::::::::::::::::::::::::::::::::::::::
+df %>%
+  group_by(supp) %>%
+  welch_anova_test(len ~ dose)
+#> # A tibble: 2 × 8
+#>   supp  .y.       n statistic   DFn   DFd            p method     
+#> * <fct> <chr> <int>     <dbl> <dbl> <dbl>        <dbl> <chr>      
+#> 1 OJ    len      30      29.4     2  17.1 0.00000295   Welch ANOVA
+#> 2 VC    len      30      59.4     2  17.2 0.0000000194 Welch ANOVA
+
+
+
-
- +
- - + + diff --git a/docs/reference/wilcox_effsize.html b/docs/reference/wilcox_effsize.html index 9da9110..bad34f0 100644 --- a/docs/reference/wilcox_effsize.html +++ b/docs/reference/wilcox_effsize.html @@ -1,48 +1,5 @@ - - - - - - - -Wilcoxon Effect Size — wilcox_effsize • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Wilcoxon Effect Size — wilcox_effsize • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+
-

Compute Wilcoxon effect size (r) for:

    -
  • one-sample test (Wilcoxon one-sample signed-rank test);

  • +

    Compute Wilcoxon effect size (r) for:

    • one-sample test (Wilcoxon one-sample signed-rank test);

    • paired two-samples test (Wilcoxon two-sample paired signed-rank test) and

    • independent two-samples test ( Mann-Whitney, two-sample rank-sum test).

    • -
    - -

    It can also returns confidence intervals by bootstap.

    +

It can also returns confidence intervals by bootstap.

The effect size r is calculated as Z statistic divided by square root of the sample size (N) (\(Z/\sqrt{N}\)). The Z value is - extracted from either coin::wilcoxsign_test() (case of one- or - paired-samples test) or coin::wilcox_test() (case of independent + extracted from either coin::wilcoxsign_test() (case of one- or + paired-samples test) or coin::wilcox_test() (case of independent two-samples test).

Note that N corresponds to total sample size for independent samples test and to total number of pairs for paired samples test.

@@ -158,95 +85,95 @@

Wilcoxon Effect Size

0.5 (large effect).

-
wilcox_effsize(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  paired = FALSE,
-  alternative = "two.sided",
-  mu = 0,
-  ci = FALSE,
-  conf.level = 0.95,
-  ci.type = "perc",
-  nboot = 1000,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
wilcox_effsize(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  paired = FALSE,
+  alternative = "two.sided",
+  mu = 0,
+  ci = FALSE,
+  conf.level = 0.95,
+  ci.type = "perc",
+  nboot = 1000,
+  ...
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

comparisons

A list of length-2 vectors specifying the groups of +formula = TP53 ~ cancer_group.

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

ref.group

a character string specifying the reference group. If +"C"))

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).

If ref.group = "all", pairwise two sample tests are performed for - comparing each grouping variable levels against all (i.e. basemean).

paired

a logical indicating whether you want a paired test.

alternative

a character string specifying the alternative + comparing each grouping variable levels against all (i.e. basemean).

+ + +
paired
+

a logical indicating whether you want a paired test.

+ + +
alternative
+

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial - letter.

mu

a number specifying an optional parameter used to form the null -hypothesis.

ci

If TRUE, returns confidence intervals by bootstrap. May be slow.

conf.level

The level for the confidence interval.

ci.type

The type of confidence interval to use. Can be any of "norm", -"basic", "perc", or "bca". Passed to boot::boot.ci.

nboot

The number of replications to use for bootstrap.

...

Additional arguments passed to the functions -coin::wilcoxsign_test() (case of one- or paired-samples test) or -coin::wilcox_test() (case of independent two-samples test).

- -

Value

- -

return a data frame with some of the following columns:

    -
  • .y.: the y variable used in the test.

  • + letter.

    + + +
    mu
    +

    a number specifying an optional parameter used to form the null +hypothesis.

    + + +
    ci
    +

    If TRUE, returns confidence intervals by bootstrap. May be slow.

    + + +
    conf.level
    +

    The level for the confidence interval.

    + + +
    ci.type
    +

    The type of confidence interval to use. Can be any of "norm", +"basic", "perc", or "bca". Passed to boot::boot.ci.

    + + +
    nboot
    +

    The number of replications to use for bootstrap.

    + + +
    ...
    +

    Additional arguments passed to the functions +coin::wilcoxsign_test() (case of one- or paired-samples test) or +coin::wilcox_test() (case of independent two-samples test).

    + +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n,n1,n2: Sample counts.

  • effsize: estimate of the effect @@ -254,72 +181,76 @@

    Value

  • magnitude: magnitude of effect size.

  • conf.low,conf.high: lower and upper bound of the effect size confidence interval.

  • -
- -

References

- +
+
+

References

Maciej Tomczak and Ewa Tomczak. The need to report effect size estimates revisited. An overview of some recommended measures of effect size. Trends in Sport Sciences. 2014; 1(21):19-25.

+
-

Examples

-
if(require("coin")){ - -# One-sample Wilcoxon test effect size -ToothGrowth %>% wilcox_effsize(len ~ 1, mu = 0) - -# Independent two-samples wilcoxon effect size -ToothGrowth %>% wilcox_effsize(len ~ supp) - - -# Paired-samples wilcoxon effect size -ToothGrowth %>% wilcox_effsize(len ~ supp, paired = TRUE) - -# Pairwise comparisons -ToothGrowth %>% wilcox_effsize(len ~ dose) - -# Grouped data -ToothGrowth %>% - group_by(supp) %>% - wilcox_effsize(len ~ dose) - -}
#> Le chargement a nécessité le package : coin
#> Le chargement a nécessité le package : survival
#> -#> Attachement du package : ‘coin’
#> The following objects are masked from ‘package:rstatix’: -#> -#> chisq_test, friedman_test, kruskal_test, sign_test, wilcox_test
#> # A tibble: 6 x 8 -#> .y. group1 group2 effsize supp n1 n2 magnitude -#> * <chr> <chr> <chr> <dbl> <fct> <int> <int> <ord> -#> 1 len 0.5 1 0.719 OJ 10 10 large -#> 2 len 0.5 2 0.846 OJ 10 10 large -#> 3 len 1 2 0.398 OJ 10 10 moderate -#> 4 len 0.5 1 0.846 VC 10 10 large -#> 5 len 0.5 2 0.845 VC 10 10 large -#> 6 len 1 2 0.795 VC 10 10 large
+
+

Examples

+
if(require("coin")){
+
+# One-sample Wilcoxon test effect size
+ToothGrowth %>% wilcox_effsize(len ~ 1, mu = 0)
+
+# Independent two-samples wilcoxon effect size
+ToothGrowth %>% wilcox_effsize(len ~ supp)
+
+
+# Paired-samples wilcoxon effect size
+ToothGrowth %>% wilcox_effsize(len ~ supp, paired = TRUE)
+
+# Pairwise comparisons
+ToothGrowth %>% wilcox_effsize(len ~ dose)
+
+# Grouped data
+ToothGrowth %>%
+  group_by(supp) %>%
+  wilcox_effsize(len ~ dose)
+
+}
+#> Loading required package: coin
+#> Loading required package: survival
+#> 
+#> Attaching package: ‘coin’
+#> The following objects are masked from ‘package:rstatix’:
+#> 
+#>     chisq_test, friedman_test, kruskal_test, sign_test, wilcox_test
+#> # A tibble: 6 × 8
+#>   .y.   group1 group2 effsize supp     n1    n2 magnitude
+#> * <chr> <chr>  <chr>    <dbl> <fct> <int> <int> <ord>    
+#> 1 len   0.5    1        0.719 OJ       10    10 large    
+#> 2 len   0.5    2        0.846 OJ       10    10 large    
+#> 3 len   1      2        0.398 OJ       10    10 moderate 
+#> 4 len   0.5    1        0.846 VC       10    10 large    
+#> 5 len   0.5    2        0.845 VC       10    10 large    
+#> 6 len   1      2        0.795 VC       10    10 large    
+
+
+
-
- +
- - + + diff --git a/docs/reference/wilcox_test.html b/docs/reference/wilcox_test.html index 80f8668..eebbc89 100644 --- a/docs/reference/wilcox_test.html +++ b/docs/reference/wilcox_test.html @@ -1,72 +1,15 @@ - - - - - - - -Wilcoxon Tests — wilcox_test • rstatix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Wilcoxon Tests — wilcox_test • rstatix - - - - - - - - - - - - - + + -
-
- -
- -
+

Provides a pipe-friendly framework to performs one and two sample Wilcoxon tests. Read more: - Wilcoxon in + Wilcoxon in R.

-
wilcox_test(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  p.adjust.method = "holm",
-  paired = FALSE,
-  exact = NULL,
-  alternative = "two.sided",
-  mu = 0,
-  conf.level = 0.95,
-  detailed = FALSE
-)
-
-pairwise_wilcox_test(
-  data,
-  formula,
-  comparisons = NULL,
-  ref.group = NULL,
-  p.adjust.method = "holm",
-  detailed = FALSE,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a +

+
wilcox_test(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  p.adjust.method = "holm",
+  paired = FALSE,
+  exact = NULL,
+  alternative = "two.sided",
+  mu = 0,
+  conf.level = 0.95,
+  detailed = FALSE
+)
+
+pairwise_wilcox_test(
+  data,
+  formula,
+  comparisons = NULL,
+  ref.group = NULL,
+  p.adjust.method = "holm",
+  detailed = FALSE,
+  ...
+)
+
+ +
+

Arguments

+
data
+

a data.frame containing the variables in the formula.

+ + +
formula
+

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, -formula = TP53 ~ cancer_group.

comparisons

A list of length-2 vectors specifying the groups of +formula = TP53 ~ cancer_group.

+ + +
comparisons
+

A list of length-2 vectors specifying the groups of interest to be compared. For example to compare groups "A" vs "B" and "B" vs "C", the argument is as follow: comparisons = list(c("A", "B"), c("B", -"C"))

ref.group

a character string specifying the reference group. If +"C"))

+ + +
ref.group
+

a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).

If ref.group = "all", pairwise two sample tests are performed for - comparing each grouping variable levels against all (i.e. basemean).

p.adjust.method

method to adjust p values for multiple comparisons. + comparing each grouping variable levels against all (i.e. basemean).

+ + +
p.adjust.method
+

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't -want to adjust the p value (not recommended), use p.adjust.method = "none".

paired

a logical indicating whether you want a paired test.

exact

a logical indicating whether an exact p-value - should be computed.

alternative

a character string specifying the alternative +want to adjust the p value (not recommended), use p.adjust.method = "none".

+ + +
paired
+

a logical indicating whether you want a paired test.

+ + +
exact
+

a logical indicating whether an exact p-value + should be computed.

+ + +
alternative
+

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial - letter.

mu

a number specifying an optional parameter used to form the null -hypothesis.

conf.level

confidence level of the interval.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is -shown.

...

other arguments to be passed to the function -wilcox.test.

- -

Value

- -

return a data frame with some of the following columns:

    -
  • .y.: the y variable used in the test.

  • + letter.

    + + +
    mu
    +

    a number specifying an optional parameter used to form the null +hypothesis.

    + + +
    conf.level
    +

    confidence level of the interval.

    + + +
    detailed
    +

    logical value. Default is FALSE. If TRUE, a detailed result is +shown.

    + + +
    ...
    +

    other arguments to be passed to the function +wilcox.test.

    + +
+
+

Value

+ + +

return a data frame with some of the following columns:

  • .y.: the y variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n,n1,n2: Sample counts.

  • statistic: Test statistic used @@ -243,8 +173,7 @@

    Value

  • estimate: an estimate of the location parameter (Only present if argument detailed = TRUE). This corresponds to the pseudomedian (for one-sample case) or to - the difference of the location parameter (for two-samples case).

      -
    • The pseudomedian of a distribution F is the median of the + the difference of the location parameter (for two-samples case).

      • The pseudomedian of a distribution F is the median of the distribution of (u+v)/2, where u and v are independent, each with distribution F. If F is symmetric, then the pseudomedian and median coincide.

      • @@ -256,15 +185,14 @@

        Value

      • conf.low, conf.high: a confidence interval for the location parameter. (Only present if argument conf.int = TRUE.)

      • -
      - -

      The returned object has an attribute called args, which is a list +

    The returned object has an attribute called args, which is a list holding the test arguments.

    -

    Details

    - +
+
+

Details

- pairwise_wilcox_test() applies the standard two sample Wilcoxon test to all possible pairs of groups. This method calls the - wilcox.test(), so extra arguments are accepted.

+ wilcox.test(), so extra arguments are accepted.

- If a list of comparisons is specified, the result of the pairwise tests is filtered to keep only the comparisons of interest.The p-value is adjusted @@ -279,77 +207,89 @@

Details test result when the option detailed = TRUE is specified in the wilcox_test() and pairwise_wilcox_test() functions. Read more about the calculation of the estimate in the details section of the R base - function wilcox.test() documentation by typing ?wilcox.test in + function wilcox.test() documentation by typing ?wilcox.test in the R console.

-

Functions

- +
+
+

Functions

-
    -
  • wilcox_test: Wilcoxon test

  • -
  • pairwise_wilcox_test: performs pairwise two sample Wilcoxon test.

  • -
- -

Examples

-
# Load data -#::::::::::::::::::::::::::::::::::::::: -data("ToothGrowth") -df <- ToothGrowth - -# One-sample test -#::::::::::::::::::::::::::::::::::::::::: -df %>% wilcox_test(len ~ 1, mu = 0)
#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
- -# Two-samples unpaired test -#::::::::::::::::::::::::::::::::::::::::: -df %>% wilcox_test(len ~ supp)
#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
-# Two-samples paired test -#::::::::::::::::::::::::::::::::::::::::: -df %>% wilcox_test (len ~ supp, paired = TRUE)
#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
-# Compare supp levels after grouping the data by "dose" -#:::::::::::::::::::::::::::::::::::::::: -df %>% - group_by(dose) %>% - wilcox_test(data =., len ~ supp) %>% - adjust_pvalue(method = "bonferroni") %>% - add_significance("p.adj")
#> Error in add_significance(., "p.adj"): The column p.adj does not exist in the data
-# pairwise comparisons -#:::::::::::::::::::::::::::::::::::::::: -# As dose contains more than two levels ==> -# pairwise test is automatically performed. -df %>% wilcox_test(len ~ dose)
#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
-# Comparison against reference group -#:::::::::::::::::::::::::::::::::::::::: -# each level is compared to the ref group -df %>% wilcox_test(len ~ dose, ref.group = "0.5")
#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
-# Comparison against all -#:::::::::::::::::::::::::::::::::::::::: -df %>% wilcox_test(len ~ dose, ref.group = "all")
#> Error in UseMethod("wilcox_test"): pas de méthode pour 'wilcox_test' applicable pour un objet de classe "data.frame"
-
+
  • wilcox_test(): Wilcoxon test

  • +
  • pairwise_wilcox_test(): performs pairwise two sample Wilcoxon test.

  • +
+ +
+

Examples

+
# Load data
+#:::::::::::::::::::::::::::::::::::::::
+data("ToothGrowth")
+df <- ToothGrowth
+
+# One-sample test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% wilcox_test(len ~ 1, mu = 0)
+#> Error in UseMethod("wilcox_test"): no applicable method for 'wilcox_test' applied to an object of class "data.frame"
+
+
+# Two-samples unpaired test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% wilcox_test(len ~ supp)
+#> Error in UseMethod("wilcox_test"): no applicable method for 'wilcox_test' applied to an object of class "data.frame"
+
+# Two-samples paired test
+#:::::::::::::::::::::::::::::::::::::::::
+df %>% wilcox_test (len ~ supp, paired = TRUE)
+#> Error in UseMethod("wilcox_test"): no applicable method for 'wilcox_test' applied to an object of class "data.frame"
+
+# Compare supp levels after grouping the data by "dose"
+#::::::::::::::::::::::::::::::::::::::::
+df %>%
+  group_by(dose) %>%
+  wilcox_test(data =., len ~ supp) %>%
+  adjust_pvalue(method = "bonferroni") %>%
+  add_significance("p.adj")
+#> Error in add_significance(., "p.adj"): The column p.adj does not exist in the data
+
+# pairwise comparisons
+#::::::::::::::::::::::::::::::::::::::::
+# As dose contains more than two levels ==>
+# pairwise test is automatically performed.
+df %>% wilcox_test(len ~ dose)
+#> Error in UseMethod("wilcox_test"): no applicable method for 'wilcox_test' applied to an object of class "data.frame"
+
+# Comparison against reference group
+#::::::::::::::::::::::::::::::::::::::::
+# each level is compared to the ref group
+df %>% wilcox_test(len ~ dose, ref.group = "0.5")
+#> Error in UseMethod("wilcox_test"): no applicable method for 'wilcox_test' applied to an object of class "data.frame"
+
+# Comparison against all
+#::::::::::::::::::::::::::::::::::::::::
+df %>% wilcox_test(len ~ dose, ref.group = "all")
+#> Error in UseMethod("wilcox_test"): no applicable method for 'wilcox_test' applied to an object of class "data.frame"
+
+
+
+
-
- +
- - + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml new file mode 100644 index 0000000..64d9235 --- /dev/null +++ b/docs/sitemap.xml @@ -0,0 +1,234 @@ + + + + /404.html + + + /articles/correlation-analysis.html + + + /articles/index.html + + + /authors.html + + + /index.html + + + /news/index.html + + + /reference/Manova.html + + + /reference/add_significance.html + + + /reference/adjust_pvalue.html + + + /reference/anova_summary.html + + + /reference/anova_test.html + + + /reference/as_cor_mat.html + + + /reference/binom_test.html + + + /reference/box_m.html + + + /reference/chisq_test.html + + + /reference/cochran_qtest.html + + + /reference/cohens_d.html + + + /reference/cor_as_symbols.html + + + /reference/cor_mark_significant.html + + + /reference/cor_mat.html + + + /reference/cor_plot.html + + + /reference/cor_reorder.html + + + /reference/cor_reshape.html + + + /reference/cor_select.html + + + /reference/cor_test.html + + + /reference/counts_to_cases.html + + + /reference/cramer_v.html + + + /reference/df_arrange.html + + + /reference/df_get_var_names.html + + + /reference/df_group_by.html + + + /reference/df_label.html + + + /reference/df_label_value.html + + + /reference/df_nest_by.html + + + /reference/df_select.html + + + /reference/df_split_by.html + + + /reference/df_unite.html + + + /reference/doo.html + + + /reference/dunn_test.html + + + /reference/emmeans_test.html + + + /reference/eta_squared.html + + + /reference/factorial_design.html + + + /reference/factors.html + + + /reference/fisher_test.html + + + /reference/freq_table.html + + + /reference/friedman_effsize.html + + + /reference/friedman_test.html + + + /reference/games_howell_test.html + + + /reference/get_comparisons.html + + + /reference/get_mode.html + + + /reference/get_pvalue_position.html + + + /reference/get_summary_stats.html + + + /reference/get_test_label.html + + + /reference/index.html + + + /reference/kruskal_effsize.html + + + /reference/kruskal_test.html + + + /reference/levene_test.html + + + /reference/mahalanobis_distance.html + + + /reference/make_clean_names.html + + + /reference/mcnemar_test.html + + + /reference/multinom_test.html + + + /reference/outliers.html + + + /reference/p_value.html + + + /reference/pipe.html + + + /reference/prop_test.html + + + /reference/prop_trend_test.html + + + /reference/pull_triangle.html + + + /reference/reexports.html + + + /reference/remove_ns.html + + + /reference/replace_triangle.html + + + /reference/sample_n_by.html + + + /reference/shapiro_test.html + + + /reference/sign_test.html + + + /reference/t_test.html + + + /reference/tukey_hsd.html + + + /reference/welch_anova_test.html + + + /reference/wilcox_effsize.html + + + /reference/wilcox_test.html + + diff --git a/man/anova_test.Rd b/man/anova_test.Rd index a7a937e..d4f16e5 100644 --- a/man/anova_test.Rd +++ b/man/anova_test.Rd @@ -152,13 +152,13 @@ The setting in \code{anova_test()} is done in such a way that it } \section{Functions}{ \itemize{ -\item \code{anova_test}: perform anova test +\item \code{anova_test()}: perform anova test -\item \code{get_anova_table}: extract anova table from an object of class +\item \code{get_anova_table()}: extract anova table from an object of class \code{anova_test}. When within-subject factors are present, either sphericity corrected or uncorrected degrees of freedom can be reported. -}} +}} \examples{ # Load data #::::::::::::::::::::::::::::::::::::::: diff --git a/man/binom_test.Rd b/man/binom_test.Rd index bc7c084..cb034ed 100644 --- a/man/binom_test.Rd +++ b/man/binom_test.Rd @@ -77,17 +77,17 @@ Performs exact binomial test and pairwise comparisons following a } \section{Functions}{ \itemize{ -\item \code{binom_test}: performs exact binomial test. Wrapper around the R +\item \code{binom_test()}: performs exact binomial test. Wrapper around the R base function \code{\link[stats]{binom.test}} that returns a dataframe as a result. -\item \code{pairwise_binom_test}: performs pairwise comparisons (binomial test) +\item \code{pairwise_binom_test()}: performs pairwise comparisons (binomial test) following a significant exact multinomial test. -\item \code{pairwise_binom_test_against_p}: performs pairwise comparisons (binomial test) +\item \code{pairwise_binom_test_against_p()}: performs pairwise comparisons (binomial test) following a significant exact multinomial test for given probabilities. -}} +}} \examples{ # Exact binomial test #\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\% diff --git a/man/chisq_test.Rd b/man/chisq_test.Rd index 89117f3..2778cf2 100644 --- a/man/chisq_test.Rd +++ b/man/chisq_test.Rd @@ -97,30 +97,30 @@ Performs chi-squared tests, including goodness-of-fit, } \section{Functions}{ \itemize{ -\item \code{chisq_test}: performs chi-square tests including goodness-of-fit, +\item \code{chisq_test()}: performs chi-square tests including goodness-of-fit, homogeneity and independence tests. -\item \code{pairwise_chisq_gof_test}: perform pairwise comparisons between groups following a global +\item \code{pairwise_chisq_gof_test()}: perform pairwise comparisons between groups following a global chi-square goodness of fit test. -\item \code{pairwise_chisq_test_against_p}: perform pairwise comparisons after a global +\item \code{pairwise_chisq_test_against_p()}: perform pairwise comparisons after a global chi-squared test for given probabilities. For each group, the observed and the expected proportions are shown. Each group is compared to the sum of all others. -\item \code{chisq_descriptives}: returns the descriptive statistics of the chi-square +\item \code{chisq_descriptives()}: returns the descriptive statistics of the chi-square test. These include, observed and expected frequencies, proportions, residuals and standardized residuals. -\item \code{expected_freq}: returns the expected counts from the chi-square test result. +\item \code{expected_freq()}: returns the expected counts from the chi-square test result. -\item \code{observed_freq}: returns the observed counts from the chi-square test result. +\item \code{observed_freq()}: returns the observed counts from the chi-square test result. -\item \code{pearson_residuals}: returns the Pearson residuals, \code{(observed - expected) / sqrt(expected)}. +\item \code{pearson_residuals()}: returns the Pearson residuals, \code{(observed - expected) / sqrt(expected)}. -\item \code{std_residuals}: returns the standardized residuals -}} +\item \code{std_residuals()}: returns the standardized residuals +}} \examples{ # Chi-square goodness of fit test #\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\% diff --git a/man/cor_mat.Rd b/man/cor_mat.Rd index 46e62a6..8ac5830 100644 --- a/man/cor_mat.Rd +++ b/man/cor_mat.Rd @@ -60,17 +60,17 @@ Compute correlation matrix with p-values. Numeric columns in the } \section{Functions}{ \itemize{ -\item \code{cor_mat}: compute correlation matrix with p-values. Returns a data +\item \code{cor_mat()}: compute correlation matrix with p-values. Returns a data frame containing the matrix of the correlation coefficients. The output has an attribute named "pvalue", which contains the matrix of the correlation test p-values. -\item \code{cor_pmat}: compute the correlation matrix but returns only the p-values of the tests. +\item \code{cor_pmat()}: compute the correlation matrix but returns only the p-values of the tests. -\item \code{cor_get_pval}: extract a correlation matrix p-values from an object of +\item \code{cor_get_pval()}: extract a correlation matrix p-values from an object of class \code{cor_mat()}. P-values are not adjusted. -}} +}} \examples{ # Data preparation #::::::::::::::::::::::::::::::::::::::::::: diff --git a/man/cor_reshape.Rd b/man/cor_reshape.Rd index 5618d11..3a630c4 100644 --- a/man/cor_reshape.Rd +++ b/man/cor_reshape.Rd @@ -25,14 +25,14 @@ Reshape correlation analysis results. Key functions: \itemize{ } \section{Functions}{ \itemize{ -\item \code{cor_gather}: takes a correlation matrix and collapses (or melt) it into long +\item \code{cor_gather()}: takes a correlation matrix and collapses (or melt) it into long format data frame (paired list) -\item \code{cor_spread}: spread a long correlation data frame into wide +\item \code{cor_spread()}: spread a long correlation data frame into wide format. Expects the columns "var1", "var2" and "cor" in the data. (correlation matrix). -}} +}} \examples{ # Data preparation #:::::::::::::::::::::::::::::::::::::::::: diff --git a/man/cor_test.Rd b/man/cor_test.Rd index 383b6d8..189ded7 100644 --- a/man/cor_test.Rd +++ b/man/cor_test.Rd @@ -79,9 +79,9 @@ Provides a pipe-friendly framework to perform correlation test } \section{Functions}{ \itemize{ -\item \code{cor_test}: correlation test between two or more variables. -}} +\item \code{cor_test()}: correlation test between two or more variables. +}} \examples{ # Correlation between the specified variable vs diff --git a/man/df_label_value.Rd b/man/df_label_value.Rd index aa5dadd..1c7651c 100644 --- a/man/df_label_value.Rd +++ b/man/df_label_value.Rd @@ -34,11 +34,11 @@ Functions to label data frame rows by one or multiple grouping } \section{Functions}{ \itemize{ -\item \code{df_label_both}: Displays both the variable name and the factor value. +\item \code{df_label_both()}: Displays both the variable name and the factor value. -\item \code{df_label_value}: Displays only the value of a factor. -}} +\item \code{df_label_value()}: Displays only the value of a factor. +}} \examples{ # Data preparation df <- head(ToothGrowth) diff --git a/man/df_unite.Rd b/man/df_unite.Rd index aebc1a0..b3b6598 100644 --- a/man/df_unite.Rd +++ b/man/df_unite.Rd @@ -41,12 +41,12 @@ Paste together multiple columns into one. Wrapper arround } \section{Functions}{ \itemize{ -\item \code{df_unite}: Unite multiple columns into one. +\item \code{df_unite()}: Unite multiple columns into one. -\item \code{df_unite_factors}: Unite factor columns. First, order factors levels then +\item \code{df_unite_factors()}: Unite factor columns. First, order factors levels then merge them into one column. The output column is a factor. -}} +}} \examples{ # Non standard evaluation head(ToothGrowth) \%>\% diff --git a/man/emmeans_test.Rd b/man/emmeans_test.Rd index 383dee8..39f9658 100644 --- a/man/emmeans_test.Rd +++ b/man/emmeans_test.Rd @@ -83,9 +83,9 @@ Performs pairwise comparisons between groups using the estimated } \section{Functions}{ \itemize{ -\item \code{get_emmeans}: returns the estimated marginal means from an object of class \code{emmeans_test} -}} +\item \code{get_emmeans()}: returns the estimated marginal means from an object of class \code{emmeans_test} +}} \examples{ # Data preparation df <- ToothGrowth diff --git a/man/eta_squared.Rd b/man/eta_squared.Rd index 6400fdd..cb102ea 100644 --- a/man/eta_squared.Rd +++ b/man/eta_squared.Rd @@ -21,11 +21,11 @@ Compute eta-squared and partial eta-squared for all terms in an } \section{Functions}{ \itemize{ -\item \code{eta_squared}: compute eta squared +\item \code{eta_squared()}: compute eta squared -\item \code{partial_eta_squared}: compute partial eta squared. -}} +\item \code{partial_eta_squared()}: compute partial eta squared. +}} \examples{ # Data preparation df <- ToothGrowth diff --git a/man/factors.Rd b/man/factors.Rd index 6af6cd9..efe7984 100644 --- a/man/factors.Rd +++ b/man/factors.Rd @@ -41,13 +41,13 @@ Provides pipe-friendly functions to convert simultaneously } \section{Functions}{ \itemize{ -\item \code{convert_as_factor}: Convert one or multiple variables into factor. +\item \code{convert_as_factor()}: Convert one or multiple variables into factor. -\item \code{set_ref_level}: Change a factor reference level or group. +\item \code{set_ref_level()}: Change a factor reference level or group. -\item \code{reorder_levels}: Change the order of a factor levels -}} +\item \code{reorder_levels()}: Change the order of a factor levels +}} \examples{ # Create a demo data df <- tibble( diff --git a/man/fisher_test.Rd b/man/fisher_test.Rd index a6d61b8..976cda9 100644 --- a/man/fisher_test.Rd +++ b/man/fisher_test.Rd @@ -89,18 +89,18 @@ Performs Fisher's exact test for testing the null of independence } \section{Functions}{ \itemize{ -\item \code{fisher_test}: performs Fisher's exact test for testing the null of +\item \code{fisher_test()}: performs Fisher's exact test for testing the null of independence of rows and columns in a contingency table with fixed marginals. Wrapper around the function \code{\link[stats]{fisher.test}()}. -\item \code{pairwise_fisher_test}: pairwise comparisons between proportions, a post-hoc +\item \code{pairwise_fisher_test()}: pairwise comparisons between proportions, a post-hoc tests following a significant Fisher's exact test of homogeneity for 2xc design. -\item \code{row_wise_fisher_test}: performs row-wise Fisher's exact test of count data, a post-hoc tests following a significant chi-square test +\item \code{row_wise_fisher_test()}: performs row-wise Fisher's exact test of count data, a post-hoc tests following a significant chi-square test of homogeneity for rx2 contingency table. The test is conducted for each category (row). -}} +}} \examples{ # Comparing two proportions diff --git a/man/get_pvalue_position.Rd b/man/get_pvalue_position.Rd index 0a17bab..895e288 100644 --- a/man/get_pvalue_position.Rd +++ b/man/get_pvalue_position.Rd @@ -128,15 +128,15 @@ Compute p-value x and y positions for plotting significance } \section{Functions}{ \itemize{ -\item \code{get_y_position}: compute the p-value y positions +\item \code{get_y_position()}: compute the p-value y positions -\item \code{add_y_position}: add p-value y positions to an object of class \code{rstatix_test} +\item \code{add_y_position()}: add p-value y positions to an object of class \code{rstatix_test} -\item \code{add_x_position}: compute and add p-value x positions. +\item \code{add_x_position()}: compute and add p-value x positions. -\item \code{add_xy_position}: compute and add both x and y positions. -}} +\item \code{add_xy_position()}: compute and add both x and y positions. +}} \examples{ # Data preparation #:::::::::::::::::::::::::::::::::::: diff --git a/man/get_test_label.Rd b/man/get_test_label.Rd index 61a80dd..6c88fa3 100644 --- a/man/get_test_label.Rd +++ b/man/get_test_label.Rd @@ -97,17 +97,17 @@ Extracts label information from statistical tests. Useful for } \section{Functions}{ \itemize{ -\item \code{get_pwc_label}: Extract label from pairwise comparisons. +\item \code{get_pwc_label()}: Extract label from pairwise comparisons. -\item \code{get_test_label}: Extract labels for statistical tests. +\item \code{get_test_label()}: Extract labels for statistical tests. -\item \code{create_test_label}: Create labels from user specified test results. +\item \code{create_test_label()}: Create labels from user specified test results. -\item \code{get_n}: Extracts sample counts (n) from an rstatix test outputs. Returns a numeric vector. +\item \code{get_n()}: Extracts sample counts (n) from an rstatix test outputs. Returns a numeric vector. -\item \code{get_description}: Extracts the description of an rstatix test outputs. Returns a character vector. -}} +\item \code{get_description()}: Extracts the description of an rstatix test outputs. Returns a character vector. +}} \examples{ # Load data #::::::::::::::::::::::::::::::::::::::: diff --git a/man/mcnemar_test.Rd b/man/mcnemar_test.Rd index 91efecc..9adccc4 100644 --- a/man/mcnemar_test.Rd +++ b/man/mcnemar_test.Rd @@ -59,13 +59,13 @@ Performs McNemar chi-squared test to compare paired proportions. } \section{Functions}{ \itemize{ -\item \code{mcnemar_test}: performs McNemar's chi-squared test for comparing two +\item \code{mcnemar_test()}: performs McNemar's chi-squared test for comparing two paired proportions -\item \code{pairwise_mcnemar_test}: performs pairwise McNemar's chi-squared test between +\item \code{pairwise_mcnemar_test()}: performs pairwise McNemar's chi-squared test between multiple groups. Could be used for post-hoc tests following a significant Cochran's Q test. -}} +}} \examples{ # Comparing two paired proportions diff --git a/man/outliers.Rd b/man/outliers.Rd index 0f14071..405420c 100644 --- a/man/outliers.Rd +++ b/man/outliers.Rd @@ -51,16 +51,16 @@ Detect outliers using boxplot methods. Boxplots are a popular and } \section{Functions}{ \itemize{ -\item \code{identify_outliers}: takes a data frame and extract rows suspected as outliers +\item \code{identify_outliers()}: takes a data frame and extract rows suspected as outliers according to a numeric column. The following columns are added "is.outlier" and "is.extreme". -\item \code{is_outlier}: detect outliers in a numeric vector. Returns logical vector. +\item \code{is_outlier()}: detect outliers in a numeric vector. Returns logical vector. -\item \code{is_extreme}: detect extreme points in a numeric vector. An alias of +\item \code{is_extreme()}: detect extreme points in a numeric vector. An alias of \code{is_outlier()}, where coef = 3. Returns logical vector. -}} +}} \examples{ # Generate a demo data set.seed(123) diff --git a/man/p_value.Rd b/man/p_value.Rd index f705799..95e8763 100644 --- a/man/p_value.Rd +++ b/man/p_value.Rd @@ -87,19 +87,19 @@ Round and format p-values. Can also mark significant p-values with stars. } \section{Functions}{ \itemize{ -\item \code{p_round}: round p-values +\item \code{p_round()}: round p-values -\item \code{p_format}: format p-values. Add a symbol "<" for small p-values. +\item \code{p_format()}: format p-values. Add a symbol "<" for small p-values. -\item \code{p_mark_significant}: mark p-values with significance levels +\item \code{p_mark_significant()}: mark p-values with significance levels -\item \code{p_detect}: detects and returns p-value column names in a data frame. +\item \code{p_detect()}: detects and returns p-value column names in a data frame. -\item \code{p_names}: returns known p-value column names +\item \code{p_names()}: returns known p-value column names -\item \code{p_adj_names}: returns known adjust p-value column names -}} +\item \code{p_adj_names()}: returns known adjust p-value column names +}} \examples{ # Round and format a vector of p-values diff --git a/man/prop_test.Rd b/man/prop_test.Rd index f77a6f9..4174989 100644 --- a/man/prop_test.Rd +++ b/man/prop_test.Rd @@ -96,17 +96,17 @@ Performs proportion tests to either evaluate the homogeneity of } \section{Functions}{ \itemize{ -\item \code{prop_test}: performs one-sample and two-samples z-test of +\item \code{prop_test()}: performs one-sample and two-samples z-test of proportions. Wrapper around the function \code{\link[stats]{prop.test}()}. -\item \code{pairwise_prop_test}: pairwise comparisons between proportions, a post-hoc +\item \code{pairwise_prop_test()}: pairwise comparisons between proportions, a post-hoc tests following a significant chi-square test of homogeneity for 2xc design. Wrapper around \code{\link[stats]{pairwise.prop.test}()} -\item \code{row_wise_prop_test}: performs row-wise z-test of two proportions, a post-hoc tests following a significant chi-square test +\item \code{row_wise_prop_test()}: performs row-wise z-test of two proportions, a post-hoc tests following a significant chi-square test of homogeneity for rx2 contingency table. The z-test of two proportions is calculated for each category (row). -}} +}} \examples{ # Comparing an observed proportion to an expected proportion #\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\% diff --git a/man/pull_triangle.Rd b/man/pull_triangle.Rd index abbe1b7..7f5ac2a 100644 --- a/man/pull_triangle.Rd +++ b/man/pull_triangle.Rd @@ -30,15 +30,15 @@ Returns the lower or the upper triangular part of a } \section{Functions}{ \itemize{ -\item \code{pull_triangle}: returns either the lower or upper triangular part of a matrix. +\item \code{pull_triangle()}: returns either the lower or upper triangular part of a matrix. -\item \code{pull_upper_triangle}: returns an object of class \code{upper_tri}, which +\item \code{pull_upper_triangle()}: returns an object of class \code{upper_tri}, which is a data frame containing the upper triangular part of a matrix. -\item \code{pull_lower_triangle}: returns an object of class \code{lower_tri}, which +\item \code{pull_lower_triangle()}: returns an object of class \code{lower_tri}, which is a data frame containing the lower triangular part of a matrix. -}} +}} \examples{ # Data preparation diff --git a/man/replace_triangle.Rd b/man/replace_triangle.Rd index 95344f4..5ff7db3 100644 --- a/man/replace_triangle.Rd +++ b/man/replace_triangle.Rd @@ -33,15 +33,15 @@ Replace the lower or the upper triangular part of a } \section{Functions}{ \itemize{ -\item \code{replace_triangle}: replaces the specified triangle by empty or NA. +\item \code{replace_triangle()}: replaces the specified triangle by empty or NA. -\item \code{replace_upper_triangle}: replaces the upper triangular part of a matrix. +\item \code{replace_upper_triangle()}: replaces the upper triangular part of a matrix. Returns an object of class \code{lower_tri}. -\item \code{replace_lower_triangle}: replaces the lower triangular part of a matrix. +\item \code{replace_lower_triangle()}: replaces the lower triangular part of a matrix. Returns an object of class \code{lower_tri} -}} +}} \examples{ # Compute correlation matrix and pull triangles #:::::::::::::::::::::::::::::::::::::::::: diff --git a/man/shapiro_test.Rd b/man/shapiro_test.Rd index 1ea164e..208de64 100644 --- a/man/shapiro_test.Rd +++ b/man/shapiro_test.Rd @@ -32,13 +32,13 @@ Provides a pipe-friendly framework to performs Shapiro-Wilk test } \section{Functions}{ \itemize{ -\item \code{shapiro_test}: univariate Shapiro-Wilk normality test +\item \code{shapiro_test()}: univariate Shapiro-Wilk normality test -\item \code{mshapiro_test}: multivariate Shapiro-Wilk normality test. This is a +\item \code{mshapiro_test()}: multivariate Shapiro-Wilk normality test. This is a modified copy of the \code{mshapiro.test()} function of the package mvnormtest, for internal convenience. -}} +}} \examples{ # Shapiro Wilk normality test for one variable diff --git a/man/sign_test.Rd b/man/sign_test.Rd index c9c49ce..7ac6989 100644 --- a/man/sign_test.Rd +++ b/man/sign_test.Rd @@ -89,11 +89,11 @@ Performs one-sample and two-sample sign tests. Read more: } \section{Functions}{ \itemize{ -\item \code{sign_test}: Sign test +\item \code{sign_test()}: Sign test -\item \code{pairwise_sign_test}: performs pairwise two sample Wilcoxon test. -}} +\item \code{pairwise_sign_test()}: performs pairwise two sample Wilcoxon test. +}} \note{ This function is a reimplementation of the function \code{SignTest()} from the \code{DescTools} package. diff --git a/man/t_test.Rd b/man/t_test.Rd index cfdc93d..b802c4f 100644 --- a/man/t_test.Rd +++ b/man/t_test.Rd @@ -125,12 +125,12 @@ adjusted for each group level independently. } \section{Functions}{ \itemize{ -\item \code{t_test}: t test +\item \code{t_test()}: t test -\item \code{pairwise_t_test}: performs pairwise two sample t-test. Wrapper around the R +\item \code{pairwise_t_test()}: performs pairwise two sample t-test. Wrapper around the R base function \code{\link[stats]{pairwise.t.test}}. -}} +}} \examples{ # Load data #::::::::::::::::::::::::::::::::::::::: diff --git a/man/tukey_hsd.Rd b/man/tukey_hsd.Rd index 9ee2554..fa4989a 100644 --- a/man/tukey_hsd.Rd +++ b/man/tukey_hsd.Rd @@ -49,15 +49,15 @@ Provides a pipe-friendly framework to performs Tukey post-hoc } \section{Methods (by class)}{ \itemize{ -\item \code{default}: performs tukey post-hoc test from \code{aov()} results. +\item \code{tukey_hsd(default)}: performs tukey post-hoc test from \code{aov()} results. -\item \code{lm}: performs tukey post-hoc test from \code{lm()} model. +\item \code{tukey_hsd(lm)}: performs tukey post-hoc test from \code{lm()} model. -\item \code{data.frame}: performs tukey post-hoc tests using data and formula as +\item \code{tukey_hsd(data.frame)}: performs tukey post-hoc tests using data and formula as inputs. ANOVA will be automatically performed using the function \code{\link[stats]{aov}()} -}} +}} \examples{ # Data preparation df <- ToothGrowth diff --git a/man/wilcox_test.Rd b/man/wilcox_test.Rd index baac3a8..c6d568d 100644 --- a/man/wilcox_test.Rd +++ b/man/wilcox_test.Rd @@ -132,11 +132,11 @@ Provides a pipe-friendly framework to performs one and two sample } \section{Functions}{ \itemize{ -\item \code{wilcox_test}: Wilcoxon test +\item \code{wilcox_test()}: Wilcoxon test -\item \code{pairwise_wilcox_test}: performs pairwise two sample Wilcoxon test. -}} +\item \code{pairwise_wilcox_test()}: performs pairwise two sample Wilcoxon test. +}} \examples{ # Load data #:::::::::::::::::::::::::::::::::::::::