tests/testthat/test_alpha2crit.R

#' ---
#' title: "Test: alpha2crit"
#' author: "Ivan Jacob Agaloos Pesigan"
#' date: "`r Sys.Date()`"
#' output: rmarkdown::html_vignette
#' vignette: >
#'   %\VignetteIndexEntry{Test: alpha2crit}
#'   %\VignetteEngine{knitr::rmarkdown}
#'   %\VignetteEncoding{UTF-8}
#' ---
#'
#+ knitr_options, include=FALSE, cache=FALSE
knitr::opts_chunk$set(
  error = TRUE,
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)
#'
#+ setup
library(testthat)
library(jeksterslabRboot)
context("Test alpha2crit.")
#'
#' ## Standard Normal Distribution
#'
#' ### Two-Tailed
#'
#+ testthat_01
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
    )
  )
})
#'
#+ testthat_02
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
#'
#+ testthat_03
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
    )
  )
})
#'
#+ testthat_04
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
#'
#+ testthat_05
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
    )
  )
})
#'
#+ testthat_06
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
#'
#+ testthat_07
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
    )
  )
})
#'
#+ testthat_08
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
#'
#+ testthat_09
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
    )
  )
})
#'
#+ testthat_10
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
#'
#+ testthat_11
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
    )
  )
})
#'
#+ testthat_12
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
#'
#+ testthat_13
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
#'
#+ testthat_14
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
    )
  )
})
jeksterslabds/jeksterslabRboot documentation built on July 20, 2020, 12:56 p.m.