ci_2pop_norm {statBasics}R Documentation

Confidence Interval for the normal distribution parameters - 2 populations

Description

Computes the confidence interval for the difference in two population means or computes the confidence interval for the ratio of two population variances according to the parameter argument.

Usage

ci_2pop_norm(
  x,
  y,
  sd_pop_1 = NULL,
  sd_pop_2 = NULL,
  var_equal = FALSE,
  parameter = "mean",
  conf_level = 0.95,
  type = "two.sided",
  na.rm = F
)

Arguments

x

a (non-empty) numeric vector.

y

a (non-empty) numeric vector.

sd_pop_1

a number specifying the known standard deviation of the first population. Default value is NULL.

sd_pop_2

a number specifying the known standard deviation of the second population. Default value is NULL.

var_equal

a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation to the degrees of freedom is used.

parameter

a character string specifying the parameter in the normal distribution. Must be one of "mean" (confidence interval for mean difference) or "variance" (confidence interval for variance ratio). Default value is "mean".

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) when parameter is "mean" or "variance". If type is "left", the returned confidence interval is (lower_ci, Inf) when parameter is "mean" or "variance". And, finally, is type is "right", the returned confidence interval is (-Inf, upper_ci)) when parameter is "mean", and the returned confidence interval is (0, upper_ci) when parameter is "variance".

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 <- rnorm(1000, mean = 0, sd = 2)
y <- rnorm(1000, mean = 0, sd = 1)
# confidence interval for difference in two means, unknown variances
ci_2pop_norm(x, y)

x <- rnorm(1000, mean = 0, sd = 2)
y <- rnorm(1000, mean = 0, sd = 3)
# confidence interval for difference in two means, known variances
ci_2pop_norm(x, y, sd_pop_1 = 2, sd_pop_2 = 3)

x <- rnorm(1000, mean = 0, sd = 2)
y <- rnorm(1000, mean = 0, sd = 3)
# confidence interval for the ratoi of two population variance
ci_2pop_norm(x, y, parameter = "variance")


[Package statBasics version 0.2.2 Index]