##
## Error: Can’t combine name
height
## Run rlang::last_error()
to see where the error occurred.
## In addition: Warning message:
## In is.na(y) : is.na() applied to non-(list or vector) of type ‘language’
Place your data in the data argument ::: {.cell output-location=‘fragment’}
Welch Two Sample t-test
data: mass by gender
t = -2.8744, df = 2.7808, p-value = 0.06986
alternative hypothesis: true difference in means between group feminine and group masculine is not equal to 0
95 percent confidence interval:
-63.417398 4.648771
sample estimates:
mean in group feminine mean in group masculine
56.33333 85.71765
:::
Use the _
placeholder ::: {.cell output-location=‘fragment’}
Welch Two Sample t-test
data: mass by gender
t = -2.8744, df = 2.7808, p-value = 0.06986
alternative hypothesis: true difference in means between group feminine and group masculine is not equal to 0
95 percent confidence interval:
-63.417398 4.648771
sample estimates:
mean in group feminine mean in group masculine
56.33333 85.71765
:::
data =
argumentchisq.test()
expects vectors or tables, not data frames.
Pearson's Chi-squared test
data: starwars$sex and starwars$gender
X-squared = 77.883, df = 3, p-value < 2.2e-16
Pearson's Chi-squared test
data: table(starwars$sex, starwars$gender)
X-squared = 77.883, df = 3, p-value < 2.2e-16
ggstatsplot
An extension of the ggplot2
package for creating graphics with details from statistical tests included in the information-rich plots themselves.
ggstatsplot | ||||||
---|---|---|---|---|---|---|
Summary of of available plots and types of statistical analyses | ||||||
Function | Plot | Description |
type =
|
|||
parametric | nonparametric | robust | bayesian | |||
ggbetweenstats | violin/box/dot plots | Between group/condition comparisons | Yes | Yes | Yes | Yes |
ggwithinstats | violin/box/dot plots | Within group/condition comparisons | Yes | Yes | Yes | Yes |
gghistostats | histograms | Distribution of a numeric variable | Yes | Yes | Yes | Yes |
ggdotplotstats | dot plots/charts | Distribution about labeled numeric variable | Yes | Yes | Yes | Yes |
ggscatterstats | scatterplots | Correlation between two variables | Yes | Yes | Yes | Yes |
ggcorrmat | correlation matrices | Correlations between multiple variables | Yes | Yes | No | Yes |
ggpiestats | pie charts | Categorical data | Yes | Yes | No | Yes |
ggbarstats | bar charts | Categorical data | Yes | Yes | Yes | Yes |
ggcoefstats | dot-and-whisker plots | Random-effects meta-analysis | Yes | No | Yes | Yes |
Read more here: https://indrajeetpatil.github.io/ggstatsplot/index.html |
ggbetweenstats()
- Between group/condition comparisonsggstatsplot
The output is a ggplot object that you can modify further ::: {.cell output-location=‘fragment’}
plot +
labs(
title = "Between gender height differences of Human Starwars characters",
y = "Height",
x = "Gender") +
scale_y_continuous(labels = function(.) paste(.,"cm"))
:::
ggstatsplot
Changing standardized effect size measure to Cohens D. ::: {.cell output-location=‘fragment’}
sw_human |>
ggbetweenstats(
x = gender, y = height,
type = "parametric",
effsize.type = "biased" # <- This lines gives Cohen D
) +
labs(
title = "Between gender height differences of Human Starwars characters",
y = "Height",
x = "Gender") +
scale_y_continuous(labels = function(.) paste(.,"cm"))
:::
ggbetweenstats()
- Between group/condition comparisonsggbetweenstats()
- Between group/condition comparisonsggbarstats()
ggbarstats()
ggcormat()
type = “parametric”ggcormat()
type = “nonparametric”gtsummary
Publication-ready analytical and summary tables
Remember, gtsummary
defaults to nonparametric descriptive statistics and tests.
See section Tables
rstatix
Provides a simple and intuitive pipe-friendly framework, coherent with the ‘tidyverse’ design philosophy, for performing basic statistical tests, including t-test, Wilcoxon test, ANOVA, Kruskal-Wallis and correlation analyses.
Good if you know the test you want to apply.
https://rpkgs.datanovia.com/rstatix/
rstatix
# A tibble: 1 × 6
.y. n statistic df p method
* <chr> <int> <dbl> <int> <dbl> <chr>
1 height 48 10.5 2 0.00519 Kruskal-Wallis
see more tests here: https://rpkgs.datanovia.com/rstatix/
rstatix
# A tibble: 2 × 7
sex .y. n statistic df p method
* <chr> <chr> <int> <dbl> <int> <dbl> <chr>
1 Female heightcm 2056 122. 5 1.33e-24 Kruskal-Wallis
2 Male heightcm 4152 253. 6 7.62e-52 Kruskal-Wallis
see more tests here: https://rpkgs.datanovia.com/rstatix/
statsExpressions
A consistent syntax to do statistical analysis with tidy data (in pipe-friendly manner)
The Workhorse that produces the statistical estimates and expressions for ggstatsplot
https://indrajeetpatil.github.io/statsExpressions/
statsExpressions
one_sample_test()
two_sample_test()
oneway_anova()
corr_test()
contingency_table()
type =
statsExpressions
tibble
# A tibble: 1 × 18
parameter1 parameter2 mean.parameter1 mean.parameter2 statistic df.error
<chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 height gender 164. 182. -3.93 7.81
p.value method alternative effectsize estimate conf.level
<dbl> <chr> <chr> <chr> <dbl> <dbl>
1 0.00460 Welch Two Sample t-test two.sided Hedges' g -1.66 0.95
conf.low conf.high conf.method conf.distribution n.obs expression
<dbl> <dbl> <chr> <chr> <int> <list>
1 -2.80 -0.478 ncp t 30 <language>
statsExpressions
expression
column contains the pre-formatted text with statistical details.list(italic("t")["Welch"] * "(" * 7.81 * ")" == "-3.93", italic(p) ==
"4.60e-03", widehat(italic("g"))["Hedges"] == "-1.66", CI["95%"] ~
"[" * "-2.80", "-0.48" * "]", italic("n")["obs"] == "30")
statsExpressions
pull()
or $
The stat$method
gave us a p.value of stat |> pull(p.value)
Will translate to:
The Welch Two Sample t-test gave us a p.value of 0.004597
::: {.cell output-location=‘column-fragment’}
:::
::: {.cell output-location=‘column-fragment’}
:::
sharpiro_test
from rstatix ::: {.cell output-location=‘column-fragment’}
# A tibble: 1 × 3
variable statistic p
<chr> <dbl> <dbl>
1 height 0.875 0.00000105
:::
::: {.cell output-location=‘column-fragment’}
starwars %>%
ggplot(aes(x = height, fill = gender)) +
geom_histogram(binwidth = 10) +
facet_wrap(vars(gender))
:::
::: {.cell output-location=‘column-fragment’}
starwars %>%
ggplot(aes(x = height, fill = gender)) +
geom_density() +
facet_wrap(vars(gender), scales = "free")
:::