ci_2pop_bern {statBasics}R Documentation

Confidence interval for the difference in two population proportions

Description

Computes the interval for different in two proportions from two distinct and independent population.

Usage

ci_2pop_bern(
  x,
  y,
  n_x = NULL,
  n_y = NULL,
  conf_level = 0.95,
  type = "two.sided",
  na.rm = F
)

Arguments

x

a (non-empty) numeric vector of 0 and 1 or a non-negative number representing number of successes.

y

a (non-empty) numeric vector of 0 and 1 or a non-negative number representing number of successes.

n_x

non-negative number of cases.

n_y

non-negative number of cases.

conf_level

confidence level of the returned confidence interval. Must be a single number between 0 and 1.

type

a character string specifying the type of confidence interval. Must be one of "two.sided" (default), "right" or "left".

na.rm

a logical value indicating whether NA values should be removed before the computation proceeds.

Details

type specifies the type of confidence interval. If type is "two.sided", the returned confidence interval is (lower_ci, upper_ci). If type is "left", the returned confidence interval is (lower_ci, Inf). And, finally, is type is "right", the returned confidence interval is (-Inf, upper_ci)).

If is.null(n_x) == T and is.null(n_y) == T, then x and y must be a numeric value of 0 and 1 and the proportions are computed using x and y. If is.null(n_x) == F and is.null(n_y) == F, then x, y, n_x and n_y must be non-negative integer scalar and x <= n_x and y <= n_y.

Value

A 1 x 3 tibble with 'lower_ci', 'upper_ci', and 'conf_level' columns. Values correspond to the lower and upper bounds of the confidence interval, and to the confidence level, respectively.

Examples

x <- 3
n_x <- 100
y <- 50
n_y <- 333
ci_2pop_bern(x, y, n_x, n_y)

x <- rbinom(100, 1, 0.75)
y <- rbinom(500, 1, 0.75)
ci_2pop_bern(x, y)


[Package statBasics version 0.2.0 Index]