Description Usage Arguments Details Value Null Hypothesis Test Assumptions Confidence Intervals Author(s) References See Also Examples
This function is based on the standard normal distribution and creates confidence intervals and tests hypotheses for both one and two sample problems.
1 2 3 4 5 6 7 8 9 10 11 12 
x 
a (nonempty) numeric vector of data values 
sigma.x 
a single number representing the population standard deviation for 
y 
an optional (nonempty) numeric vector of data values 
sigma.y 
a single number representing the population standard deviation for 
sigma.d 
a single number representing the population standard deviation for the paired differences 
alternative 
character string, one of 
mu 
a single number representing the value of the mean or difference in means specified by the null hypothesis 
paired 
a logical indicating whether you want a paired ztest 
conf.level 
confidence level for the returned confidence interval, restricted to lie between zero and one 
... 
Other arguments passed onto 
If y
is NULL
, a onesample ztest is carried out with x
provided sigma.x
is not NULL
. If y is not NULL
, a standard twosample ztest is performed provided both sigma.x
and sigma.y
are finite. If paired = TRUE
, a paired ztest where the differences are defined as x  y
is performed when the user enters a finite value for sigma.d
(the population standard deviation for the differences).
A list of class htest
, containing the following components:

the zstatistic, with names attribute 

the pvalue for the test 

is a confidence interval (vector of length 2) for the true mean or difference in means. The confidence level is recorded in the attribute 

vector of length 1 or 2, giving the sample mean(s) or mean of differences; these estimate the corresponding population parameters. Component 

the value of the mean or difference of means specified by the null hypothesis. This equals the input argument 
alternative 
records the value of the input argument alternative: 
data.name 
a character string (vector of length 1) containing the actual names of the input vectors 
For the onesample ztest, the null hypothesis is that the mean of the population from which x
is drawn is mu
. For the standard twosample ztest, the null hypothesis is that the population mean for x
less that for y
is mu
. For the paired ztest, the null hypothesis is that the mean difference between x
and 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"
).
The assumption of normality for the underlying distribution or a sufficiently large sample size is required along with the population standard deviation to use Z procedures.
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 halfinfinite when alternative is not "two.sided"
; infinity will be represented by Inf
.
Alan T. Arnholt <arnholtat@appstate.edu>
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: McGrawHill.
Snedecor, G. W. and Cochran, W. G. 1980. Statistical Methods, 7th ed. Ames, Iowa: Iowa State University Press.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  with(data = GROCERY, z.test(x = amount, sigma.x = 30, conf.level = 0.97)$conf)
# Example 8.3 from PASWR.
x < rnorm(12)
z.test(x, sigma.x = 1)
# Twosided onesample ztest where the assumed value for
# sigma.x is one. 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.
x < c(7.8, 6.6, 6.5, 7.4, 7.3, 7., 6.4, 7.1, 6.7, 7.6, 6.8)
y < c(4.5, 5.4, 6.1, 6.1, 5.4, 5., 4.1, 5.5)
z.test(x, sigma.x=0.5, y, sigma.y=0.5, mu=2)
# Twosided standard twosample ztest where both sigma.x
# and sigma.y are both assumed to equal 0.5. 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.
z.test(x, sigma.x = 0.5, y, sigma.y = 0.5, conf.level = 0.90)
# Twosided standard twosample ztest where both sigma.x and
# sigma.y are both assumed to equal 0.5. 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.
rm(x, y)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.