This function is based on the standard normal distribution and creates confidence intervals and tests hypotheses for both one and two sample problems based on summarized information the user passes to the function. Output is identical to that produced with z.test.

zsum.test(
  mean.x,
  sigma.x = NULL,
  n.x = NULL,
  mean.y = NULL,
  sigma.y = NULL,
  n.y = NULL,
  alternative = c("two.sided", "less", "greater"),
  mu = 0,
  conf.level = 0.95,
  ...
)

Arguments

mean.x

a single number representing the sample mean of x

sigma.x

a single number representing the population standard deviation for x

n.x

a single number representing the sample size for y

mean.y

a single number representing the sample mean of y

sigma.y

a single number representing the population 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 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.

mu

a single number representing the value of the mean or difference in means specified by the null hypothesis

conf.level

confidence level for the returned confidence interval, restricted to lie between zero and one

...

Other arguments passed onto z.test()

Value

A list of class htest, containing the following components:

statistic

the z-statistic, with names attribute z

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.

Details

If y is NULL , a one-sample z-test is carried out with x provided sigma.x is finite. If y is not NULL, a standard two-sample z-test is performed provided both sigma.x and sigma.y are finite.

Null Hypothesis

For the one-sample z-test, the null hypothesis is that the mean of the population from which x is drawn is mu. For the standard two-sample z-test, 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 normality for the underlying distribution or a sufficiently large sample size is required along with the population standard deviation to use Z procedures.

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.

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

Author

Alan T. Arnholt <arnholtat@appstate.edu>

Examples


zsum.test(mean.x = 56/30,sigma.x = 2, n.x = 30, alternative="greater", mu = 1.8)
#> 
#> 	One Sample z-test
#> 
#> data:  User input summarized values for x
#> z = 0.18257, p-value = 0.4276
#> alternative hypothesis: true mean is greater than 1.8
#> 95 percent confidence interval:
#>  1.266051      Inf
#> sample estimates:
#> mean of x 
#>  1.866667 
#> 
# Example 9.7 part a. from PASWR.
x <- rnorm(12)
zsum.test(mean(x), sigma.x = 1, n.x = 12)
#> 
#> 	One Sample z-test
#> 
#> data:  User input summarized values for x
#> z = 0.16255, p-value = 0.8709
#> alternative hypothesis: true mean is not equal to 0
#> 95 percent confidence interval:
#>  -0.5188684  0.6127174
#> sample estimates:
#> mean of x 
#> 0.0469245 
#> 
# Two-sided one-sample z-test 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.
# Note: returns same answer as: 
z.test(x, sigma.x = 1)
#> 
#> 	One Sample z-test
#> 
#> data:  x
#> z = 0.16255, p-value = 0.8709
#> alternative hypothesis: true mean is not equal to 0
#> 95 percent confidence interval:
#>  -0.5188684  0.6127174
#> sample estimates:
#> mean of x 
#> 0.0469245 
#> 

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)
zsum.test(mean(x), sigma.x = 0.5, n.x = 11 ,mean(y), sigma.y = 0.5, n.y = 8, mu = 2)
#> 
#> 	Two Sample z-test
#> 
#> data:  User input summarized values for x and y
#> z = -1.0516, p-value = 0.293
#> alternative hypothesis: true difference in means is not equal to 2
#> 95 percent confidence interval:
#>  1.300323 2.211040
#> sample estimates:
#> mean of x mean of y 
#>  7.018182  5.262500 
#> 
# Two-sided standard two-sample z-test 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.
# Note: returns same answer as: 
z.test(x, sigma.x = 0.5, y, sigma.y = 0.5)
#> 
#> 	Two Sample z-test
#> 
#> data:  x and y
#> z = 7.5568, p-value = 4.13e-14
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  1.300323 2.211040
#> sample estimates:
#> mean of x mean of y 
#>  7.018182  5.262500 
#> 
#
zsum.test(mean(x), sigma.x = 0.5, n.x = 11, mean(y), sigma.y = 0.5, n.y = 8, 
conf.level=0.90)
#> 
#> 	Two Sample z-test
#> 
#> data:  User input summarized values for x and y
#> z = 7.5568, p-value = 4.13e-14
#> alternative hypothesis: true difference in means is not equal to 0
#> 90 percent confidence interval:
#>  1.373533 2.137831
#> sample estimates:
#> mean of x mean of y 
#>  7.018182  5.262500 
#> 
# Two-sided standard two-sample z-test 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.  Note: returns same answer as:
z.test(x, sigma.x=0.5, y, sigma.y=0.5, conf.level=0.90)
#> 
#> 	Two Sample z-test
#> 
#> data:  x and y
#> z = 7.5568, p-value = 4.13e-14
#> alternative hypothesis: true difference in means is not equal to 0
#> 90 percent confidence interval:
#>  1.373533 2.137831
#> sample estimates:
#> mean of x mean of y 
#>  7.018182  5.262500 
#> 
rm(x, y)