# npStochinUnpaired: A test of a stochastic inequality given two independent... In npExact: Exact Nonparametric Hypothesis Tests for the Mean, Variance and Stochastic Inequality

## Description

The data input consists of a sequence of independent realizations observations of each random variable, observations of the different sequences also being independent.

## Usage

 ```1 2 3``` ```npStochinUnpaired(x1, x2, d = 0, alternative = "two.sided", iterations = 5000, alpha = 0.05, epsilon = 1 * 10^(-6), ignoreNA = FALSE, max.iterations = 100000) ```

## Arguments

 `x1, x2` the (non-empty) numerical data vectors which contain the variables to be tested. `d` the maximal difference in probabilities assumed H_0 : P(X_2 > X_1) - P(X_2 < X_1) <= d. Default is 0. `alternative` a character string describing the alternative hypothesis. Default is "greater". If "less" is given, `x1` and `x2` are switched for each other. `iterations` the number of iterations used, should not be changed if the exact solution should be derived. `alpha` the type I error. `epsilon` the tolerance in terms of probability of the Monte Carlo simulations. `ignoreNA` if `TRUE`, NA values will be omitted. Default: `FALSE` `max.iterations` the maximum number of iterations that should be carried out. This number could be increased to achieve greater accuracy in cases where the difference between the threshold probability and theta is small. Default: `10000`

## Details

Given -1 < d < 1 it is a test of the null hypothesis H_0 : P(X_2 > X_1) ≤ P(X_2 < X_1) + d against the alternative hypothesis H_1 : P(X_2 > X_1) > P(X_2 < X_1) + d.

The data is randomly matched into pairs and then treats them as matched pairs. The number of pairs is equal to the number of observations in the smaller sequence. The exact randomized test is then used to determine if sufficiently many occurrences of x_2 > x_1 occur when compared to how often x_2 < x_1 occurs, using level `theta`*`alpha`. The matching into pairs is repeated `iterations` times. The test gives a rejection of the average rejection probability in these iterations lies above `theta`. If the average rejection probability lies too close to theta then the number of iterations is increased.

`theta` is determined to maximize the set of differences P(X_2>X_1) - P(X_2<X_1) belonging to the alternative hypothesis in which the type II error probability lies below 0.5. For more details see the paper.

## Value

A list with class "nphtest" containing the following components:

 `method` a character string indicating the name and type of the test that was performed. `data.name` a character string giving the name(s) of the data. `alternative` a character string describing the alternative hypothesis. `estimate` an estimate of P(x_2 > x_1) - P(x_2 < x_1). `probrej` numerical estimate of the rejection probability of the randomized test, derived by taking an average of `iterations` realizations of the rejection probability. `bounds` the lower and upper bounds of the variables. `null.value` the specified hypothesized value of the correlation between the variables. `alpha` the type I error. `theta` the parameter that minimizes the type II error. `pseudoalpha` `theta`*`alpha`, this is the level used when calculating the average rejection probability during the iterations. `rejection` logical indicator for whether or not the null hypothesis can be rejected. `iterations` the number of iterations that were performed.

## Author(s)

Karl Schlag, Peter Saffert and Oliver Reiter

## References

Schlag, Karl H. 2008, A New Method for Constructing Exact Tests without Making any Assumptions, Department of Economics and Business Working Paper 1109, Universitat Pompeu Fabra. Available at https://ideas.repec.org/p/upf/upfgen/1109.html.

 ```1 2 3 4``` ```data(french) origin <- french\$french.origin rest <- french\$rest.of.civil npStochinUnpaired(origin, rest, ignoreNA = TRUE) ```