Learn R Programming

flipr (version 0.2.1)

two_sample_ci: Two-Sample Permutation Confidence Interval

Description

This function calculates permutation confidence intervals for two-sample problems. This is done through the specification a point estimate of the parameter to be estimated and of a set of null hypotheses of the form F_X = F_{g(Y, parameters)} where g is a user-supplied function.

Usage

two_sample_ci(
  null_specification,
  x,
  y,
  alpha = 0.05,
  statistic = stat_hotelling,
  B = 1000L,
  alternative = "right_tail",
  type = "exact",
  point_estimate = NULL,
  lower_bound = 0,
  upper_bound = 1,
  seed = NULL
)

Arguments

null_specification

A function with two arguments y and parameters such that F_X = F_{null_specification(Y, parameters)} under the null hypothesis.

x

A list or matrix representing the 1st sample.

y

A list or matrix representing the 2nd sample.

alpha

A scalar specifying the desired significance level. Default is 0.05.

statistic

A character vector specifying the chosen test statistic(s). These can be stat_hotelling or user-specified functions that define desired statistics. See the section User-supplied statistic function for more information on how these user-supplied functions should be structured for compatibility with the flipr framwork. Default is stat_hotelling.

B

The number of sampled permutation. Default is 1000L.

alternative

A string specifying whether the p-value is right-tailed, left-tailed or two-tailed. Choices are "right_tail", "left_tail" and "two_tail". Default is "right_tail". Obviously, if the test statistic used in argument statistic is positive, all alternatives will lead to the two-tailed p-value.

type

A string specifying if performing an exact test through the use of Phipson-Smyth estimate of the p-value or an approximate test through a Monte-Carlo estimate of the p-value. Default is "exact".

point_estimate

A scalar providing a point estimate of the parameter under investigation. Default is NULL, in which case the point estimate is computed by maximizing the p-value function via the two_sample_pe function.

lower_bound

A scalar value specifying a rough lower bound of the interval over which searching the maximum of the p-value function. Default is 0.

upper_bound

A scalar value specifying a rough upper bound of the interval over which searching the maximum of the p-value function. Default is 1.

seed

An integer specifying the seed of the random generator useful for result reproducibility or method comparisons. Default is NULL.

Value

A length-2 vector providing the confidence interval at the required level.

Examples

Run this code
# NOT RUN {
x1 <- rnorm(10)
x2 <- rnorm(10, 3)
null_spec <- function(y, parameters) {y - parameters[1]}
two_sample_ci(
  null_specification = null_spec,
  x = x1,
  y = x2,
  statistic = stat_t,
  alternative = "two_tail",
  lower_bound = 2,
  upper_bound = 4,
  B = 100L
)
# }

Run the code above in your browser using DataLab