| t.test2 | R Documentation |
The basic t-test function in R, t.test, does not report
the observed difference of means, does not stipulate which mean
is subtracted from which (i.e., whether it computed A-B or B-A), and
presents the test results on the console in a verbose unorganized
paragraph of text. t.test2 improves on all those counts, and
in addition, it reports the number of observations per group and if any observations
are missing it issues a warning. It returns a dataframe instead of a list.
The function is also registered as t.test2 for the t
generic to satisfy S3 registration checks while keeping direct calls to
t.test2(...) unchanged.
x |
The first data argument passed to |
... |
Arguments passed to |
A data frame with class c("t.test2", "data.frame") containing
a single row with the following columns:
One or two columns containing group means, named after
the input variables (e.g., men, women) or Group 1,
Group 2 for long names.
For two-sample tests, the difference between means
(e.g., men-women).
The confidence level as a string (e.g., "95 percent").
Lower and upper bounds of the confidence interval.
The t-statistic.
Degrees of freedom.
The p-value.
Sample sizes, named N(group1), N(group2) or
N1, N2. For paired tests, a single N column.
For paired tests only, the correlation between pairs.
Attributes store additional information including missing value counts and test type (one-sample, two-sample, paired, Welch vs. Student).
# Two-sample t-test
men <- rnorm(100, mean = 5, sd = 1)
women <- rnorm(100, mean = 4.8, sd = 1)
t.test2(men, women)
# Paired t-test
x <- rnorm(50, mean = 5, sd = 1)
y <- rnorm(50, mean = 5.2, sd = 1)
t.test2(x, y, paired = TRUE)
# One-sample t-test
data <- rnorm(100, mean = 5, sd = 1)
t.test2(data, mu = 0)
# Formula syntax
data <- data.frame(y = rnorm(100), group = rep(c("A", "B"), 50))
t.test2(y ~ group, data = data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.