library(testthat)
library(jeksterslabRboot)
context("Test alpha2crit.")

Standard Normal Distribution

Two-Tailed

test_that("z two-tailed vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        )
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        )
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        )
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        )
      ),
      digits = 3
    ),
    round(
      c(
        -3.290527,
        -2.575829,
        -1.959964,
        1.959964,
        2.575829,
        3.290527
      ),
      digits = 3
    )
  )
})
test_that("z two-tailed single value", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = 0.05
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = 0.95
      ),
      digits = 3
    ),
    round(
      c(
        -1.959964,
        1.959964
      ),
      digits = 3
    )
  )
})

Student’s t Distribution (\(\nu = 1000\))

Two-Tailed

test_that("t two-tailed vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        dist = "t",
        df = 1000
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        dist = "t",
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        dist = "t",
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        dist = "t",
        df = 1000
      ),
      digits = 3
    ),
    round(
      c(
        -3.290527,
        -2.575829,
        -1.959964,
        1.959964,
        2.575829,
        3.290527
      ),
      digits = 3
    )
  )
})
test_that("t two-tailed single value", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = 0.05,
        dist = "t",
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = 0.95,
        dist = "t",
        df = 1000
      ),
      digits = 3
    ),
    round(
      c(
        -1.959964,
        1.959964
      ),
      digits = 3
    )
  )
})

Standard Normal Distribution

One-Tailed

Right Tail

test_that("z one-tailed right vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        two.tailed = FALSE
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        two.tailed = FALSE
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        two.tailed = FALSE
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        two.tailed = FALSE
      ),
      digits = 3
    ),
    round(
      c(
        1.644854,
        2.326348,
        3.090232
      ),
      digits = 3
    )
  )
})
test_that("z one-tailed right single value", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = 0.05,
        two.tailed = FALSE
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = 0.95,
        two.tailed = FALSE
      ),
      digits = 3
    ),
    round(
      1.644854,
      digits = 3
    )
  )
})

Student’s t Distribution

One-Tailed

Right Tail

test_that("t one-tailed right vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        dist = "t",
        two.tailed = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        dist = "t",
        two.tailed = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        dist = "t",
        two.tailed = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        dist = "t",
        two.tailed = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      c(
        1.644854,
        2.326348,
        3.090232
      ),
      digits = 3
    )
  )
})
test_that("t one-tailed right single value", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = 0.05,
        dist = "t",
        two.tailed = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = 0.95,
        dist = "t",
        two.tailed = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      1.644854,
      digits = 3
    )
  )
})

Standard Normal Distribution

One-Tailed

Left Tail

test_that("z one-tailed left vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        two.tailed = FALSE,
        right.tail = FALSE
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        two.tailed = FALSE,
        right.tail = FALSE
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        two.tailed = FALSE,
        right.tail = FALSE
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        two.tailed = FALSE,
        right.tail = FALSE
      ),
      digits = 3
    ),
    round(
      c(
        -3.090232,
        -2.326348,
        -1.644854
      ),
      digits = 3
    )
  )
})
test_that("z one-tailed left single value", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = 0.05,
        two.tailed = FALSE,
        right.tail = FALSE
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = 0.95,
        two.tailed = FALSE,
        right.tail = FALSE
      ),
      digits = 3
    ),
    round(
      -1.644854,
      digits = 3
    )
  )
})

Student’s t Distribution

One-Tailed

Left Tail

test_that("t one-tailed left vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        dist = "t",
        two.tailed = FALSE,
        right.tail = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        dist = "t",
        two.tailed = FALSE,
        right.tail = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        dist = "t",
        two.tailed = FALSE,
        right.tail = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        dist = "t",
        two.tailed = FALSE,
        right.tail = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      c(
        -3.090232,
        -2.326348,
        -1.644854
      ),
      digits = 3
    )
  )
})
test_that("t one-tailed left single value", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = 0.05,
        dist = "t",
        two.tailed = FALSE,
        right.tail = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = 0.95,
        dist = "t",
        two.tailed = FALSE,
        right.tail = FALSE,
        df = 1000
      ),
      digits = 3
    ),
    round(
      -1.644854,
      digits = 3
    )
  )
})

F Distribution

One-Tailed

Right Tail

test_that("F one-tailed right vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        dist = "F",
        df1 = 2,
        df2 = 2
      ),
      digits = 0
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        dist = "F",
        df1 = 2,
        df2 = 2
      ),
      digits = 0
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        dist = "F",
        df1 = 2,
        df2 = 2
      ),
      digits = 0
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        dist = "F",
        df1 = 2,
        df2 = 2
      ),
      digits = 0
    ),
    round(
      c(
        19,
        99,
        999
      ),
      digits = 0
    )
  )
})

\(\chi^2\) Distribution

One-Tailed

Right Tail

test_that("chisq one-tailed right vector", {
  expect_equivalent(
    round(
      alpha2crit(
        alpha = c(
          0.001,
          0.01,
          0.05
        ),
        dist = "chisq",
        df = 1
      ),
      digits = 3
    ),
    round(
      alpha2crit(
        alpha = c(
          0.05,
          0.01,
          0.001
        ),
        dist = "chisq",
        df = 1
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.999,
          0.99,
          0.95
        ),
        dist = "chisq",
        df = 2
      ),
      digits = 3
    ),
    round(
      ci2crit(
        ci = c(
          0.95,
          0.99,
          0.999
        ),
        dist = "chisq",
        df = 2
      ),
      digits = 3
    ),
    round(
      c(
        3.841459,
        6.634897,
        10.827566
      ),
      digits = 3
    )
  )
})