hl1_test {robnptests}R Documentation

Two-sample location tests based on one-sample Hodges-Lehmann estimator

Description

hl1_test performs a two-sample location test based on the difference of the one-sample Hodges-Lehmann estimators of both samples.

Usage

hl1_test(
  x,
  y,
  alternative = c("two.sided", "greater", "less"),
  delta = ifelse(scale.test, 1, 0),
  method = c("asymptotic", "permutation", "randomization"),
  scale = c("S1", "S2"),
  n.rep = 10000,
  na.rm = FALSE,
  scale.test = FALSE,
  wobble = FALSE,
  wobble.seed = NULL
)

Arguments

x

a (non-empty) numeric vector of data values.

y

a (non-empty) numeric vector of data values.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater", or "less".

delta

a numeric value indicating the true difference in the location or scale parameter, depending on whether the test should be performed for a difference in location or in scale. The default is delta = 0 for a location test and delta = 1 for a scale test. In case of scale.test = TRUE, delta represents the ratio of the squared scale parameters.

method

a character string specifying how the p-value is computed with possible values "asymptotic" for an asymptotic test based on a normal approximation, "permutation" for a permutation test, and "randomization" for a randomization test. The permutation test uses all splits of the joint sample into two samples of sizes m and n, while the randomization test draws n.rep random splits with replacement. The values m and n denote the sample sizes. If not specified explicitly, defaults to "permutation" if m < 30, n < 30 and n.rep >= choose(m + n, m), "randomization" if m < 30, n < 30 and n.rep < choose(m + n, m), and "asymptotic" if m >= 30 and n >= 30.

scale

a character string specifying the scale estimator used for standardization of the test statistic; must be one of "S1" and "S2". The default is "S1". Ignored if method = "asymptotic"; see details for the definition of the scale estimators.

n.rep

an integer value specifying the number of random splits used to calculate the randomization distribution if method = "randomization". This argument is ignored if method = "permutation" or method = "asymptotic". The default is n.rep = 10000.

na.rm

a logical value indicating whether NA values in x and y should be stripped before the computation proceeds. The default is na.rm = FALSE.

scale.test

a logical value to specify if the samples should be compared for a difference in scale. The default is scale.test = FALSE.

wobble

a logical value indicating whether the sample should be checked for duplicated values that can cause the scale estimate to be zero. If such values are present, uniform noise is added to the sample, see wobble. Only necessary for the permutation and randomization version of the test. The default is wobble = FALSE.

wobble.seed

an integer value used as a seed for the random number generation in case of wobble = TRUE or when scale.test = TRUE with one of the vectors x and y containing zeros. When no seed is specified, it is chosen randomly and printed in a message. The argument is ignored if scale.test = FALSE and/or wobble = FALSE.

Details

The test statistic for this test is based on the difference of the one-sample Hodges-Lehmann estimators of x and y, see hodges_lehmann. Three versions of the test are implemented: randomization, permutation, and asymptotic.

The test statistic for the permutation and randomization version of the test is standardized using a robust scale estimator, see (Fried and Dehling 2011).

With scale = "S1", the scale is estimated by

S = med(|x_i - x_j|: 1 \le i < j \le m, |y_i - y_j|, 1 \le i < j \le n),

whereas scale = "S2" uses

S = med(|z_i - z_j|: 1 \le i < j \le m + n).

Here, z = (z_1, ..., z_{m + n}) = (x_1 - med(x), ..., x_m - med(x), y_1 - med(y), ..., y_n - med(y)) is the median-corrected sample.

The randomization distribution is based on randomly drawn splits with replacement. The function permp (Phipson and Smyth 2010) is used to calculate the p-value. For the asymptotic test, a transformed version of the difference of the HL1-estimators, which asymptotically follows a normal distribution, is used. For more details on the asymptotic test, see Fried and Dehling (2011).

For scale.test = TRUE, the test compares the two samples for a difference in scale. This is achieved by log-transforming the original squared observations, i.e. x is replaced by log(x^2) and y by log(y^2). A potential scale difference then appears as a location difference between the transformed samples, see Fried (2012). Note that the samples need to have equal locations. The sample should not contain zeros to prevent problems with the necessary log-transformation. If it contains zeros, uniform noise is added to all variables in order to remove zeros and a message is printed.

If the sample has been modified (either because of zeros if scale.test = TRUE or wobble = TRUE), the modified samples can be retrieved using

set.seed(wobble.seed); wobble(x, y).

Both samples need to contain at least 5 non-missing values.

Value

A named list with class "htest" containing the following components:

statistic

the value of the test statistic.

p.value

the p-value for the test.

estimate

the one-sample Hodges-Lehmann estimates of x and y (if scale.test = FALSE) or of log(x^2) and log(y^2) (if scale.test = TRUE).

null.value

the specified hypothesized value of the mean difference/squared scale ratio.

alternative

a character string describing the alternative hypothesis.

method

a character string indicating how the p-value was computed.

data.name

a character string giving the names of the data.

References

Phipson B, Smyth GK (2010). “Permutation p-values should never be zero: Calculating exact p-values when permutations are randomly drawn.” Statistical Applications in Genetics and Molecular Biology, 9(1), Article 39. doi:10.2202/1544-6115.1585.

Fried R, Dehling H (2011). “Robust nonparametric tests for the two-sample location problem.” Statistical Methods & Applications, 20(4), 409–422. doi:10.1007/s10260-011-0164-1.

Fried R (2012). “On the online estimation of piecewise constant volatilities.” Computational Statistics & Data Analysis, 56(11), 3080–3090. doi:10.1016/j.csda.2011.02.012.

Examples

# Generate random samples
set.seed(108)
x <- rnorm(20); y <- rnorm(20)

# Asymptotic HL1 test
hl1_test(x, y, method = "asymptotic", scale = "S1")

## Not run: 
# HL12 test using randomization principle by drawing 1000 random permutations
# with replacement

hl1_test(x, y, method = "randomization", n.rep = 1000, scale = "S2")

## End(Not run)


[Package robnptests version 1.1.0 Index]