With regards to z-test, there is NO z.test()
function in the original R package, unfortunately. However, the package TeachingDemos
contains a z.test()
function which will be helpful. We therefore start with installing and loading TeachingDemos
:
install.packages("TeachingDemos")
library(TeachingDemos)
Assuming that you have stored your sample data in the variable scores
, the command to use is z.test(scores, mu = Y, stdev = W, alternative="ALT")
where:
ALT
shall be replaced by either greater
or less
or two.sided
depending on your alternative hypothesis Ha
. The null hypothesis H0
states that the sample mean is NOT different from the population mean. Your alternative hypothesis Ha
is one of the following:
greater
),less
)two.sided
). More info about TeachingDemos
is available here.Considering our previous example, this would look like:
z.test(scores, alternative="greater", mu=120, stdev=UNKNOWN)
However, as stated in the code, the standard deviation is unknown. Therefore, a z.test cannot be used.
IF the standand deviation was previously know and equal to 15, this would have been the code and the corresponding output:
z.test(scores, alternative="greater", mu=120, stdev=15)
##
## One Sample z-test
##
## data: scores
## z = 2.6774, n = 40.0000, Std. Dev. = 15.0000, Std. Dev. of the
## sample mean = 2.3717, p-value = 0.00371
## alternative hypothesis: true mean is greater than 120
## 95 percent confidence interval:
## 122.4489 Inf
## sample estimates:
## mean of scores
## 126.35
R returns several lines of text. One of them provides a p-value while the next line states the alternative hypothesis which depends on the parameter alternative
that you have entered in the z.test()
. This alternative hypothesis Ha
is considered valid when the p-value is less than 0.05.
Read more about z.test()
by simply typing ?z.test
in the R console.