Performs a one-sample, two-sample, or a Welch modified two-sample
t-test based on user supplied summary information. Output is identical to that
produced with t.test.
a single number representing the sample standard deviation for x
n.x
a single number representing the sample size for x
mean.y
a single number representing the sample mean of y
s.y
a single number representing the sample standard deviation for y
n.y
a single number representing the sample size for y
alternative
is a character string, one of "greater", "less" or
"two.sided", or just the initial letter of each, indicating the specification
of the alternative hypothesis. For one-sample tests, alternative refers to the true
mean of the parent population in relation to the hypothesized value mu.
For the standard two-sample tests, alternative refers to the difference between
the true population mean for x and that for y, in relation to mu.
For the one-sample and paired t-tests, alternative refers to the true mean of the
parent population in relation to the hypothesized value mu. For the standard
and Welch modified two-sample t-tests, alternative refers to the difference between
the true population mean for x and that for y, in relation to mu.
For the one-sample t-tests, alternative refers to the true mean of the parent population
in relation to the hypothesized value mu. For the standard and Welch modified
two-sample t-tests, alternative refers to the difference between the true population
mean for x and that for y, in relation to mu.
mu
is a single number representing the value of the mean or difference in means
specified by the null hypothesis.
var.equal
logical flag: if TRUE, the variances of the parent populations
of x and y are assumed equal. Argument var.equal should be supplied
only for the two-sample tests.
conf.level
is the confidence level for the returned confidence
interval; it must lie between zero and one.
Details
If y is NULL, a one-sample t-test is
carried out with x. If y is not NULL, either a standard or
Welch modified two-sample t-test is performed, depending on whether var.equal is TRUE
or FALSE.
Value
A list of class htest, containing the following components:
statistic
the t-statistic, with names attribute "t"
parameters
is the degrees of freedom of the t-distribution
associated with statistic.
Component parameters has names attribute "df".
p.value
the p-value for the test.
conf.int
is a confidence interval (vector of length 2)
for the true mean or difference in means. The confidence level
is recorded in the attribute conf.level. When alternative
is not "two.sided", the confidence interval will be half-infinite,
to reflect the interpretation of a confidence interval as the set of all
values k for which one would not reject the null hypothesis that
the true mean or difference in means is k . Here infinity will be
represented by Inf.
estimate
vector of length 1 or 2, giving the sample mean(s)
or mean of differences; these estimate the corresponding population
parameters. Component estimate has a names attribute describing its elements.
null.value
the value of the mean or difference in means specified by
the null hypothesis. This equals the input argument mu. Component
null.value has a names attribute describing its elements.
alternative
records the value of the input argument alternative:
"greater" , "less" or "two.sided".
data.name
a character string (vector of length 1) containing
the names x and y for the two summarized samples.
Null Hypothesis
For the one-sample t-test, the null hypothesis is that the mean of
the population from which x is drawn is mu. For the standard and Welch modified
two-sample t-tests, the null hypothesis is that the population mean for x less that for
y is mu.
The alternative hypothesis in each case indicates the direction of divergence of the population
mean for x (or difference of means for x and y) from mu
(i.e., "greater", "less", or "two.sided").
Test Assumptions
The assumption of equal population variances is central to the
standard two-sample t-test. This test can be misleading when population variances are not
equal, as the null distribution of the test statistic is no longer a t-distribution. If
the assumption of equal variances is doubtful with respect to a particular dataset, the
Welch modification of the t-test should be used.
The t-test and the associated confidence interval are quite robust with respect to level
toward heavy-tailed non-Gaussian distributions (e.g., data with outliers). However, the
t-test is non-robust with respect to power, and the confidence interval is
non-robust with respect to average length, toward these same types of distributions.
Confidence Intervals
For each of the above tests, an expression for the
related confidence interval (returned component conf.int) can be obtained in the usual
way by inverting the expression for the test statistic. Note that, as explained
under the description of conf.int, the confidence interval will be half-infinite when
alternative is not "two.sided" ; infinity will be represented by Inf.
Author(s)
Alan T. Arnholt
References
Kitchens, L.J. (2003). Basic Statistics and Data Analysis. Duxbury.
Hogg, R. V. and Craig, A. T. (1970). Introduction to Mathematical Statistics, 3rd ed. Toronto, Canada: Macmillan.
Mood, A. M., Graybill, F. A. and Boes, D. C. (1974). Introduction to the Theory of Statistics, 3rd ed. New York: McGraw-Hill.
Snedecor, G. W. and Cochran, W. G. (1980). Statistical Methods, 7th ed. Ames, Iowa: Iowa State University Press.
See Also
z.test, zsum.test
Examples
tsum.test(mean.x=5.6, s.x=2.1, n.x=16, mu=4.9, alternative="greater")
# Problem 6.31 on page 324 of BSDA states: The chamber of commerce
# of a particular city claims that the mean carbon dioxide
# level of air polution is no greater than 4.9 ppm. A random
# sample of 16 readings resulted in a sample mean of 5.6 ppm,
# and s=2.1 ppm. One-sided one-sample t-test. The null
# hypothesis is that the population mean for 'x' is 4.9.
# The alternative hypothesis states that it is greater than 4.9.
x <- rnorm(12)
tsum.test(mean(x), sd(x), n.x=12)
# Two-sided one-sample t-test. The null hypothesis is that
# the population mean for 'x' is zero. The alternative
# hypothesis states that it is either greater or less
# than zero. A confidence interval for the population mean
# will be computed. Note: above returns same answer as:
t.test(x)
x <- c(7.8, 6.6, 6.5, 7.4, 7.3, 7.0, 6.4, 7.1, 6.7, 7.6, 6.8)
y <- c(4.5, 5.4, 6.1, 6.1, 5.4, 5.0, 4.1, 5.5)
tsum.test(mean(x), s.x=sd(x), n.x=11 ,mean(y), s.y=sd(y), n.y=8, mu=2)
# Two-sided standard two-sample t-test. The null hypothesis
# is that the population mean for 'x' less that for 'y' is 2.
# The alternative hypothesis is that this difference is not 2.
# A confidence interval for the true difference will be computed.
# Note: above returns same answer as:
t.test(x, y)
tsum.test(mean(x), s.x=sd(x), n.x=11, mean(y), s.y=sd(y), n.y=8, conf.level=0.90)
# Two-sided standard two-sample t-test. The null hypothesis
# is that the population mean for 'x' less that for 'y' is zero.
# The alternative hypothesis is that this difference is not
# zero. A 90% confidence interval for the true difference will
# be computed. Note: above returns same answer as:
t.test(x, y, conf.level=0.90)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(BSDA)
Loading required package: e1071
Loading required package: lattice
Attaching package: 'BSDA'
The following object is masked from 'package:datasets':
Orange
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BSDA/tsum.test.Rd_%03d_medium.png", width=480, height=480)
> ### Name: tsum.test
> ### Title: Summarized t-test
> ### Aliases: tsum.test
> ### Keywords: htest
>
> ### ** Examples
>
> tsum.test(mean.x=5.6, s.x=2.1, n.x=16, mu=4.9, alternative="greater")
One-sample t-Test
data: Summarized x
t = 1.3333, df = 15, p-value = 0.1012
alternative hypothesis: true mean is greater than 4.9
95 percent confidence interval:
4.679649 NA
sample estimates:
mean of x
5.6
Warning message:
In tsum.test(mean.x = 5.6, s.x = 2.1, n.x = 16, mu = 4.9, alternative = "greater") :
argument 'var.equal' ignored for one-sample test.
> # Problem 6.31 on page 324 of BSDA states: The chamber of commerce
> # of a particular city claims that the mean carbon dioxide
> # level of air polution is no greater than 4.9 ppm. A random
> # sample of 16 readings resulted in a sample mean of 5.6 ppm,
> # and s=2.1 ppm. One-sided one-sample t-test. The null
> # hypothesis is that the population mean for 'x' is 4.9.
> # The alternative hypothesis states that it is greater than 4.9.
>
> x <- rnorm(12)
> tsum.test(mean(x), sd(x), n.x=12)
One-sample t-Test
data: Summarized x
t = 0.8864, df = 11, p-value = 0.3944
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.3244271 0.7619346
sample estimates:
mean of x
0.2187537
Warning message:
In tsum.test(mean(x), sd(x), n.x = 12) :
argument 'var.equal' ignored for one-sample test.
> # Two-sided one-sample t-test. The null hypothesis is that
> # the population mean for 'x' is zero. The alternative
> # hypothesis states that it is either greater or less
> # than zero. A confidence interval for the population mean
> # will be computed. Note: above returns same answer as:
> t.test(x)
One Sample t-test
data: x
t = 0.8864, df = 11, p-value = 0.3944
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.3244271 0.7619346
sample estimates:
mean of x
0.2187537
>
> x <- c(7.8, 6.6, 6.5, 7.4, 7.3, 7.0, 6.4, 7.1, 6.7, 7.6, 6.8)
> y <- c(4.5, 5.4, 6.1, 6.1, 5.4, 5.0, 4.1, 5.5)
> tsum.test(mean(x), s.x=sd(x), n.x=11 ,mean(y), s.y=sd(y), n.y=8, mu=2)
Welch Modified Two-Sample t-Test
data: Summarized x and y
t = -0.85278, df = 11.303, p-value = 0.4115
alternative hypothesis: true difference in means is not equal to 2
95 percent confidence interval:
1.127160 2.384203
sample estimates:
mean of x mean of y
7.018182 5.262500
> # Two-sided standard two-sample t-test. The null hypothesis
> # is that the population mean for 'x' less that for 'y' is 2.
> # The alternative hypothesis is that this difference is not 2.
> # A confidence interval for the true difference will be computed.
> # Note: above returns same answer as:
> t.test(x, y)
Welch Two Sample t-test
data: x and y
t = 6.1281, df = 11.303, p-value = 6.617e-05
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
1.127160 2.384203
sample estimates:
mean of x mean of y
7.018182 5.262500
>
> tsum.test(mean(x), s.x=sd(x), n.x=11, mean(y), s.y=sd(y), n.y=8, conf.level=0.90)
Welch Modified Two-Sample t-Test
data: Summarized x and y
t = 6.1281, df = 11.303, p-value = 6.617e-05
alternative hypothesis: true difference in means is not equal to 0
90 percent confidence interval:
1.242424 2.268940
sample estimates:
mean of x mean of y
7.018182 5.262500
> # Two-sided standard two-sample t-test. The null hypothesis
> # is that the population mean for 'x' less that for 'y' is zero.
> # The alternative hypothesis is that this difference is not
> # zero. A 90% confidence interval for the true difference will
> # be computed. Note: above returns same answer as:
> t.test(x, y, conf.level=0.90)
Welch Two Sample t-test
data: x and y
t = 6.1281, df = 11.303, p-value = 6.617e-05
alternative hypothesis: true difference in means is not equal to 0
90 percent confidence interval:
1.242424 2.268940
sample estimates:
mean of x mean of y
7.018182 5.262500
>
>
>
>
>
>
> dev.off()
null device
1
>