Skip to contents

Extracting dataframes with statistical details from {ggstatsplot}

Usage

extract_stats(p, ...)

Arguments

p

A plot from {ggstatsplot} package

...

Ignored

Value

A list of tibbles containing statistical analysis summaries.

Details

This is a convenience function to extract dataframes with statistical details that are used to create expressions displayed in {ggstatsplot} plots as subtitle and/or as caption. Note that all of this analysis is carried out by the {statsExpressions} package.

For more details about underlying tests and effect size estimates, see the following vignette: https://indrajeetpatil.github.io/statsExpressions/articles/stats_details.html

Examples

# \donttest{
if (require("PMCMRplus")) {
  set.seed(123)
  library(ggstatsplot)

  # in case of group comparisons
  p <- ggbetweenstats(mtcars, cyl, mpg)
  extract_stats(p)

  # the exact details depend on the function
  extract_stats(ggbarstats(mtcars, cyl, am))
}
#> Loading required package: PMCMRplus
#> $subtitle_data
#> # A tibble: 1 × 13
#>   statistic    df p.value method       effectsize   estimate conf.level conf.low
#>       <dbl> <int>   <dbl> <chr>        <chr>           <dbl>      <dbl>    <dbl>
#> 1      8.74     2  0.0126 Pearson's C… Cramer's V …    0.464       0.95        0
#> # … with 5 more variables: conf.high <dbl>, conf.method <chr>,
#> #   conf.distribution <chr>, n.obs <int>, expression <list>
#> 
#> $caption_data
#> # A tibble: 1 × 14
#>   term  conf.level effectsize estimate conf.low conf.high prior.distribution    
#>   <chr>      <dbl> <chr>         <dbl>    <dbl>     <dbl> <chr>                 
#> 1 Ratio       0.95 Cramers_v     0.476    0.205     0.703 independent multinomi…
#> # … with 7 more variables: prior.location <dbl>, prior.scale <dbl>, bf10 <dbl>,
#> #   method <chr>, log_e_bf10 <dbl>, n.obs <int>, expression <list>
#> 
#> $pairwise_comparisons_data
#> NULL
#> 
#> $descriptive_data
#> # A tibble: 6 × 5
#>   am    cyl   counts  perc .label
#>   <fct> <fct>  <int> <dbl> <chr> 
#> 1 0     8         12  63.2 63%   
#> 2 1     8          2  15.4 15%   
#> 3 0     6          4  21.1 21%   
#> 4 1     6          3  23.1 23%   
#> 5 0     4          3  15.8 16%   
#> 6 1     4          8  61.5 62%   
#> 
#> $one_sample_data
#> # A tibble: 2 × 10
#>   am    counts  perc N        statistic    df p.value method   .label   .p.label
#>   <fct>  <int> <dbl> <chr>        <dbl> <dbl>   <dbl> <chr>    <chr>    <chr>   
#> 1 1         13  40.6 (n = 13)      4.77     2  0.0921 Chi-squ… list(~c… list(~i…
#> 2 0         19  59.4 (n = 19)      7.68     2  0.0214 Chi-squ… list(~c… list(~i…
#> 
# }