Since the "standard" z-test is not available in R as in most real-world scenarios you're only ever going to use a t-test, this function fills that gap for teaching purposes. The function is basically a carbon-copy of stats::t.test, but with user-supplied variances for x and y and p-value and related calculations use a standard normal distribution.
z.test( x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, sigma_x, sigma_y = NULL, paired = FALSE, conf.level = 0.95 )
A (non-empty) numeric vector of data values
An optional (non-empty) numeric vector of data values. If omitted, a one-sample test is conducted.
A character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.
A number indicating the true value of the mean (or difference in means if you are performing a two sample test).
The assumed known variance of
A logical indicating whether you want a paired t-test.
Confidence level of the interval.
An object of class
htest, see stats::t.test
x <- rnorm(10, 5, 1) y <- 1:10 + rnorm(10, 3, 1.5) # Two sample z.test(x, y, sigma_x = 1, sigma_y = 1.5)#> #> Two Sample z-test #> #> data: x and y #> z = -6.9144, df = 18, p-value = 4.698e-12 #> alternative hypothesis: true difference in means is not equal to 0 #> 95 percent confidence interval: #> -4.437182 -2.477218 #> sample estimates: #> mean of x mean of y #> 5.110855 8.568055 #># One sample z.test(x, sigma_x = 1, mu = 5)#> #> One Sample z-test #> #> data: x #> z = 0.35055, df = 9, p-value = 0.7259 #> alternative hypothesis: true mean is not equal to 5 #> 95 percent confidence interval: #> 4.49106 5.73065 #> sample estimates: #> mean of x #> 5.110855 #>