z.test: One- and Two-Sample z-Test

Description Usage Arguments Value Source Examples

View source: R/z_test.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
z.test(
  x,
  y = NULL,
  alternative = c("two.sided", "less", "greater"),
  mu = 0,
  sigma_x,
  sigma_y = NULL,
  paired = FALSE,
  conf.level = 0.95
)

Arguments

x

A (non-empty) numeric vector of data values

y

An optional (non-empty) numeric vector of data values. If omitted, a one-sample test is conducted.

alternative

A character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.

mu

A number indicating the true value of the mean (or difference in means if you are performing a two sample test).

sigma_x, sigma_y

The assumed known variance of x and y. Must be numeric.

paired

A logical indicating whether you want a paired t-test.

conf.level

Confidence level of the interval.

Value

An object of class htest, see stats::t.test

Source

stats::t.test

Examples

1
2
3
4
5
6
7
8
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)

# One sample
z.test(x, sigma_x = 1, mu = 5)

tadaatoolbox documentation built on July 2, 2020, 2:30 a.m.