DescTools (version 0.99.15)

ZTest: Z Test for Known Population Standard Deviation

Description

Compute the test of hypothesis and compute confidence interval on the mean of a population when the standard deviation of the population is known.

Usage

ZTest(x, ...)

## S3 method for class 'default':
ZTest(x, y = NULL, alternative = c("two.sided", "less", "greater"), 
      paired = FALSE, mu = 0, sd_pop, conf.level = 0.95, ...)

## S3 method for class 'formula':
ZTest(formula, data, subset, na.action, \dots)

Arguments

x
numeric vector of data values. Non-finite (e.g. infinite or missing) values will be omitted.
y
an optional numeric vector of data values: as with x non-finite values will be omitted.
mu
a number specifying the hypothesized mean of the population.
sd_pop
known standard deviation of the population.
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 refe
paired
a logical indicating whether you want a paired z-test.
conf.level
confidence level for the interval computation.
formula
a formula of the form lhs ~ rhs where lhs gives the data values and rhs the corresponding groups.
data
an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula)
subset
an optional vector specifying a subset of observations to be used.
na.action
a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").
...
further arguments to be passed to or from methods.

Value

  • A list with class "htest" containing the following components:
  • statisticthe value of the z-statistic.
  • p.valuethe p-value for the test
  • conf.inta confidence interval for the mean appropriate to the specified alternative hypothesis.
  • estimatethe estimated mean or difference in means depending on whether it was a one-sample test or a two-sample test.
  • null.valuethe specified hypothesized value of the mean or mean difference depending on whether it was a one-sample test or a two-sample test.
  • alternativea character string describing the alternative hypothesis.
  • methoda character string indicating what type of test was performed.
  • data.namea character string giving the name(s) of the data.

Details

Most introductory statistical texts introduce inference by using the z-test and z-based confidence intervals based on knowing the population standard deviation. However statistical packages often do not include functions to do z-tests since the t-test is usually more appropriate for real world situations. This function is meant to be used during that short period of learning when the student is learning about inference using z-procedures, but has not learned the t-based procedures yet. Once the student has learned about the t-distribution the t.test function should be used instead of this one (but the syntax is very similar, so this function should be an appropriate introductory step to learning t.test).

References

Stahel, W. (2002) Statistische Datenanalyse, 4th ed, vieweg

See Also

t.test, print.htest

Examples

Run this code
x <- rnorm(25, 100, 5)
ZTest(x, mu=99, sd_pop=5)

# the classic interface
with(sleep, ZTest(extra[group == 1], extra[group == 2], sd_pop=2))

# the formula interface
ZTest(extra ~ group, data = sleep, sd_pop=2)


# Stahel (2002), pp. 186, 196  

d.tyres <- data.frame(A=c(44.5,55,52.5,50.2,45.3,46.1,52.1,50.5,50.6,49.2),
                      B=c(44.9,54.8,55.6,55.2,55.6,47.7,53,49.1,52.3,50.7))
with(d.tyres, ZTest(A, B, sd_pop=3, paired=TRUE))


d.oxen <- data.frame(ext=c(2.7,2.7,1.1,3.0,1.9,3.0,3.8,3.8,0.3,1.9,1.9),
                     int=c(6.5,5.4,8.1,3.5,0.5,3.8,6.8,4.9,9.5,6.2,4.1))
with(d.oxen, ZTest(int, ext, sd_pop=1.8, paired=FALSE))

Run the code above in your browser using DataCamp Workspace