Perform Frequentist and Bayesian t-tests with Effect Size Estimation from Tidy Data
Source:R/t_test_all_tidy.r
t_test_all_tidy.RdA wrapper around t_test_all that accepts tidy-format data frames
with exactly three columns (participant ID, independent variable, dependent variable)
or two columns only for one-sample design (participant ID, dependent variable).
The function automatically reshapes the data (long \(\rightarrow\) wide for paired designs),
checks for consistency, and then calls t_test_all() with the extracted vectors.
Usage
t_test_all_tidy(
dataset,
paired = F,
var.equal = FALSE,
onesample = FALSE,
mu = 0,
ci = c("freq", "bayes_central", "bayes_hdi"),
alternative = c("two.sided", "less", "greater"),
conf.level = 0.95,
alpha = 0.05,
pd = FALSE,
bf = FALSE,
cor = TRUE,
mean_x_EAP = FALSE,
mean_x_MAP = FALSE,
mean_x_MED = FALSE,
diff_EAP = FALSE,
diff_MAP = FALSE,
diff_MED = FALSE,
cohens_d = NULL,
cohens_d_EAP = FALSE,
cohens_d_MAP = FALSE,
cohens_d_MED = FALSE,
cohens_dz = TRUE,
cohens_dz_EAP = FALSE,
cohens_dz_MAP = FALSE,
cohens_dz_MED = FALSE,
rscale_est = Inf,
rscale_bf = "medium",
iterations = 10000,
map_density_n = 512,
verbose = FALSE,
show_design = TRUE,
detailed = FALSE,
fullbayes = FALSE
)Arguments
- dataset
A data frame with exactly three columns, in this order:
Participant ID
Independent variable (must have exactly two levels)
Dependent variable (numeric)
- paired
Logical. If
TRUE, a paired t-test is performed (defaultFALSE).- var.equal
Logical. If
TRUE, the two-sample t-test assumes equal variances (defaultFALSE).- onesample
Logical. If
TRUE, a one-sample t-test is performed (defaultFALSE).- mu
Numeric. Null hypothesis value for the mean difference (default
0).- ci
Character vector specifying interval type(s):
"freq","bayes_central", or"bayes_hdi". Default isc("freq","bayes_central","bayes_hdi"). Passed tot_test_all.- alternative
Character. Alternative hypothesis:
"two.sided","less", or"greater". Default is"two.sided". Passed tot_test_all.- conf.level
Numeric. Confidence/credibility level (default
0.95). Passed tot_test_all.- alpha
Numeric. Significance level. Defaults to 0.05.
- pd, bf, cor
Logical flags. Whether to compute probability of direction (pd), Bayes factors, or correlation (for paired samples). Passed to
t_test_all.- mean_x_EAP, mean_x_MAP, mean_x_MED
Logical. Report posterior summaries for group means. Passed to
t_test_all.- diff_EAP, diff_MAP, diff_MED
Logical. Report posterior summaries for the mean difference. Passed to
t_test_all.- cohens_d
Logical or character. Type/request for Cohen's d in independent samples. Passed to
t_test_all.- cohens_d_EAP, cohens_d_MAP, cohens_d_MED
Logical. Posterior summaries for Cohen's d. Passed to
t_test_all.- cohens_dz
Logical. Request Cohen's dz for paired samples. Passed to
t_test_all.- cohens_dz_EAP, cohens_dz_MAP, cohens_dz_MED
Logical. Posterior summaries for Cohen's dz. Passed to
t_test_all.- rscale_est, rscale_bf
Numeric or character. Cauchy prior scales for estimation and Bayes factors (e.g.,
"ultrawide","wide","medium", or a positive number). Defaults areInfand"medium", respectively. Passed tot_test_all.- iterations, map_density_n
Integer. MCMC iterations and grid size for MAP density. Passed to
t_test_all.- verbose
Logical. If
TRUE, print additional messages (defaultFALSE).- show_design
Logical. If
TRUE, show message of design (defaultTRUE).- detailed
Logical. Whether to return detailed results (
TRUE) or minimal output (FALSE, default).- fullbayes
Logical. Whether to show only Bayesian results (
TRUE) or both frequentist and Bayesian results (FALSE, default).
Value
The object returned by t_test_all (test statistics, effect sizes,
confidence/credible intervals, and Bayesian estimates).
Details
This function enforces the following:
datasetmust have exactly three columns in the order: ID, independent variable, dependent variable.The independent variable must have exactly two levels.
The dependent variable must be numeric.
If
paired = TRUE, each participant must contribute exactly one observation in each condition.
If any requirement is violated, an informative error is raised.
Examples
set.seed(610)
dat <- data.frame(
id = rep(1:10, each = 2),
cond = rep(c("A","B"), times = 10),
y = rnorm(20)
)
# Independent-samples t-test
t_test_all_tidy(dat, paired = FALSE)
#> design: two samples (unequal variance)
#> diff t df p alpha sig cohens_d
#> 1 0.5569292 1.14 16.71 0.27 0.05 ns 0.51
# Paired-samples t-test
t_test_all_tidy(dat, paired = TRUE)
#> design: paired
#> diff t df p alpha sig cohens_dz
#> 1 0.5569292 1.21 9 0.256 0.05 ns 0.384