nice_t_test {rempsyc} | R Documentation |
Easy t-tests
Description
Easily compute t-test analyses, with effect sizes,
and format in publication-ready format. The 95% confidence interval
is for the effect size, Cohen's d, both provided by the effectsize
package.
Usage
nice_t_test(
data,
response,
group = NULL,
correction = "none",
paired = FALSE,
verbose = TRUE,
...
)
Arguments
data |
The data frame. |
response |
The dependent variable. |
group |
The group for the comparison. |
correction |
What correction for multiple comparison to apply, if any. Default is "none" and the only other option (for now) is "bonferroni". |
paired |
Whether to use a paired t-test. |
verbose |
Whether to display the Welch test warning or not. |
... |
Further arguments to be passed to the |
Details
This function relies on the base R t.test()
function, which
uses the Welch t-test per default (see why here:
https://daniellakens.blogspot.com/2015/01/always-use-welchs-t-test-instead-of.html).
To use the Student t-test, simply add the following
argument: var.equal = TRUE
.
Note that for paired t tests, you need to use paired = TRUE
, and
you also need data in "long" format rather than wide format (like for
the ToothGrowth
data set). In this case, the group
argument refers
to the participant ID for example, so the same group/participant is
measured several times, and thus has several rows. Note also that R >= 4.4.0
has stopped supporting the paired
argument for the formula method used
internally here.
For the easystats equivalent, use: report::report()
on the
t.test()
object.
Value
A formatted dataframe of the specified model, with DV, degrees of freedom, t-value, p-value, the effect size, Cohen's d, and its 95% confidence interval lower and upper bounds.
See Also
Tutorial: https://rempsyc.remi-theriault.com/articles/t-test
Examples
# Make the basic table
nice_t_test(
data = mtcars,
response = "mpg",
group = "am"
)
# Multiple dependent variables at once
nice_t_test(
data = mtcars,
response = names(mtcars)[1:7],
group = "am"
)
# Can be passed some of the regular arguments
# of base [t.test()]
# Student t-test (instead of Welch)
nice_t_test(
data = mtcars,
response = "mpg",
group = "am",
var.equal = TRUE
)
# One-sided instead of two-sided
nice_t_test(
data = mtcars,
response = "mpg",
group = "am",
alternative = "less"
)
# One-sample t-test
nice_t_test(
data = mtcars,
response = "mpg",
mu = 10
)
# Make sure cases appear in the same order for
# both levels of the grouping factor