Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract_stats from grouped_* plots #815

Closed
andreifoldes opened this issue Nov 21, 2022 · 2 comments · Fixed by #955
Closed

extract_stats from grouped_* plots #815

andreifoldes opened this issue Nov 21, 2022 · 2 comments · Fixed by #955
Labels
enhancement 🔥 New feature or request

Comments

@andreifoldes
Copy link

Greetings,

Could the extract_stats function be extended such that it can extract statistics according the grouping.var when used on grouped_* plots?

@IndrajeetPatil
Copy link
Owner

Yes, this is something I want to implement.

For now, have a look at the examples to see how this can be done, one plot at a time.

@IndrajeetPatil
Copy link
Owner

library(ggstatsplot)

p <- grouped_ggpiestats(mtcars, x = cyl, grouping.var = am)
extract_stats(p)
#> [[1]]
#> $subtitle_data
#> # A tibble: 1 × 13
#>   statistic    df p.value method                                   effectsize 
#>       <dbl> <dbl>   <dbl> <chr>                                    <chr>      
#> 1      7.68     2  0.0214 Chi-squared test for given probabilities Pearson's C
#>   estimate conf.level conf.low conf.high conf.method conf.distribution n.obs
#>      <dbl>      <dbl>    <dbl>     <dbl> <chr>       <chr>             <int>
#> 1    0.537       0.95   0.0666     0.725 ncp         chisq                19
#>   expression
#>   <list>    
#> 1 <language>
#> 
#> $caption_data
#> # A tibble: 1 × 4
#>    bf10 prior.scale method                                      expression
#>   <dbl>       <dbl> <chr>                                       <list>    
#> 1  1.15           1 Bayesian one-way contingency table analysis <language>
#> 
#> $pairwise_comparisons_data
#> NULL
#> 
#> $descriptive_data
#> # A tibble: 3 × 4
#>   cyl   counts  perc .label
#>   <fct>  <int> <dbl> <chr> 
#> 1 8         12  63.2 63%   
#> 2 6          4  21.1 21%   
#> 3 4          3  15.8 16%   
#> 
#> $one_sample_data
#> NULL
#> 
#> $tidy_data
#> NULL
#> 
#> $glance_data
#> NULL
#> 
#> attr(,"class")
#> [1] "ggstatsplot_stats" "list"             
#> 
#> [[2]]
#> $subtitle_data
#> # A tibble: 1 × 13
#>   statistic    df p.value method                                   effectsize 
#>       <dbl> <dbl>   <dbl> <chr>                                    <chr>      
#> 1      4.77     2  0.0921 Chi-squared test for given probabilities Pearson's C
#>   estimate conf.level conf.low conf.high conf.method conf.distribution n.obs
#>      <dbl>      <dbl>    <dbl>     <dbl> <chr>       <chr>             <int>
#> 1    0.518       0.95        0     0.741 ncp         chisq                13
#>   expression
#>   <list>    
#> 1 <language>
#> 
#> $caption_data
#> # A tibble: 1 × 4
#>    bf10 prior.scale method                                      expression
#>   <dbl>       <dbl> <chr>                                       <list>    
#> 1 0.434           1 Bayesian one-way contingency table analysis <language>
#> 
#> $pairwise_comparisons_data
#> NULL
#> 
#> $descriptive_data
#> # A tibble: 3 × 4
#>   cyl   counts  perc .label
#>   <fct>  <int> <dbl> <chr> 
#> 1 8          2  15.4 15%   
#> 2 6          3  23.1 23%   
#> 3 4          8  61.5 62%   
#> 
#> $one_sample_data
#> NULL
#> 
#> $tidy_data
#> NULL
#> 
#> $glance_data
#> NULL
#> 
#> attr(,"class")
#> [1] "ggstatsplot_stats" "list"
extract_subtitle(p)
#> [[1]]
#> list(chi["gof"]^2 * "(" * 2 * ")" == "7.68", italic(p) == "0.02", 
#>     widehat(italic("C"))["Pearson"] == "0.54", CI["95%"] ~ "[" * 
#>         "0.07", "0.73" * "]", italic("n")["obs"] == "19")
#> 
#> [[2]]
#> list(chi["gof"]^2 * "(" * 2 * ")" == "4.77", italic(p) == "0.09", 
#>     widehat(italic("C"))["Pearson"] == "0.52", CI["95%"] ~ "[" * 
#>         "0.00", "0.74" * "]", italic("n")["obs"] == "13")
extract_caption(p)
#> [[1]]
#> list(log[e] * (BF["01"]) == "-0.14", italic("a")["Gunel-Dickey"] == 
#>     "1.00")
#> 
#> [[2]]
#> list(log[e] * (BF["01"]) == "0.83", italic("a")["Gunel-Dickey"] == 
#>     "1.00")

Created on 2024-07-27 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🔥 New feature or request
Projects
None yet
2 participants