t_test | R Documentation |
Performs one and two sample t-tests.
The mosaic t.test
provides wrapper functions around the function
of the same name in stats.
These wrappers provide an extended interface that allows for a more systematic
use of the formula interface.
t_test(x, ...)
t.test(x, ...)
## S3 method for class 'formula'
t_test(formula, data, ..., groups = NULL)
## Default S3 method:
t_test(
x,
y = NULL,
alternative = c("two.sided", "less", "greater"),
mu = 0,
paired = FALSE,
var.equal = FALSE,
conf.level = 0.95,
...
)
x |
a (non-empty) numeric vector of data values. |
... |
further arguments to be passed to or from methods. |
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
groups |
When |
y |
an optional (non-empty) numeric vector of data values. |
alternative |
a character string specifying the alternative
hypothesis, must be one of |
mu |
a number indicating the true value of the mean (or difference in means if you are performing a two sample test). |
paired |
a logical indicating whether you want a paired t-test. |
var.equal |
a logical variable indicating whether to treat the
two variances as being equal. If |
conf.level |
confidence level of the interval. |
This is a wrapper around stats::t.test()
from the stats package
to extend the functionality of the formula interface. In particular, one can
now use the formula interface for a 1-sample t-test. Before, the formula interface
was only permitted for a 2-sample test. The type of formula that can be used
for the 2-sample test has also be broadened. See the examples.
an object of class htest
prop.test()
, binom.test()
,
stats::t.test()
t.test(HELPrct$age)
# We can now do this with a formula
t.test(~ age, data = HELPrct)
# data = can be omitted, but it is better to use it
t.test(~ age, HELPrct)
# the original 2-sample formula
t.test(age ~ sex, data = HELPrct)
# alternative 2-sample formulas
t.test(~ age | sex, data = HELPrct)
t.test(~ age, groups = sex, data = HELPrct)
# 2-sample t from vectors
with(HELPrct, t.test(age[sex == "male"], age[sex == "female"]))
# just the means
mean(age ~ sex, data = HELPrct)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.