Package 'rquest'

Title: Hypothesis Tests for Quantiles and Quantile-Based Measures
Description: Functions to conduct hypothesis tests and derive confidence intervals for quantiles, linear combinations of quantiles, ratios of dependent linear combinations and differences and ratios of all of the above for comparisons between independent samples. Additionally, quantile-based measures of inequality are also considered.
Authors: Shenal Dedduwakumara [aut, cre], Luke Prendergast [aut], Robert Staudte [aut]
Maintainer: Shenal Dedduwakumara <[email protected]>
License: GPL (>= 3)
Version: 1.0.3
Built: 2025-03-10 05:04:26 UTC
Source: https://github.com/shenal-dkumara/rquest

Help Index


q.test

Description

carry out hypothesis tests and obtain associated confidence intervals for linear combinations of quantiles, and ratios of such linear combinations.

Usage

q.test(
  x,
  y = NULL,
  measure = "median",
  u = NULL,
  coef = NULL,
  u2 = NULL,
  coef2 = NULL,
  quantile.type = 8,
  var.method = "qor",
  alternative = c("two.sided", "less", "greater"),
  conf.level = 0.95,
  true.q = 0,
  log.transf = FALSE,
  back.transf = FALSE,
  min.q = -Inf,
  p = NULL
)

Arguments

x

a numeric vector of data values.

y

an optional second vector of data values for two-sample testing.

measure

a character string specifying the quantile measure to be estimated (See details).

u

a numeric vector of probability values in [0, 1] indicating all quantiles to be estimated.

coef

a vector or matrix with two rows specifying the coefficients that define the linear combinations (coefficients must match the corresponding probability values in u). If coef is a vector then a single linear combination (LC) is computed. If it is a matrix, then first row defines the numerator LS and the second the denominator LC.

u2

a numeric vector of probability values in [0, 1] indicating all quantiles to be estimated for the denominator.

coef2

a vector specifying the coefficients that define the linear combination for the denominator. This is can be used as an alternative to defining coef as matrix for ratios of linear combinations.

quantile.type

argument for the quantile function. Default is set to 8 so that output is consistent with default quantile function use and other functions such as IQR (see help file for quantile() for more details)

var.method

approach use to estimate the quantile density function. Either "qor"(default) or "density" (See details).

alternative

a character string for alternative hypothesis equal to one of "two.sided", "greater" or "less".

conf.level

coverage for the estimated confidence interval.

true.q

a numeric value for the true value under the null hypothesis test.

log.transf

boolean indicating whether the a log transformation of the measure is to be used (i.e., estimates of the log of the measure are computed).

back.transf

boolean indicating whether the measure and estimates should be back-transformed to the original scale using exp.

min.q

the lower bound for a one-sided confidence interval when alternative argument if "less".

p

optional value in (0, 1) for Bowley's generalized skewness coefficient.

Details

This function q.test performs hypothesis tests and calculates confidence intervals for linear combinations of quantiles. The quantile measures that can be estimated are specified in the measure argument and are listed below.

  • median: The default choice.

  • iqr: The interquartile range.

  • rCViqr: The robust Coefficient of Variation measure (Arachchige et al.,2022)

  • bowley, groenR and groenL: These choices are for Bowley's skew coefficient, for the generalized measure, and the right and left skew measures by Groeneveld and Meeden (Groeneveld & Meeden, 1984, 2009). For each of these measures, the user may specify the choice of p using argument p. If this is not used, then the default is p=0.25.

  • moors: This Moors kurtosis measure (Moors, 1988).

  • lqw and rqw: These are for the robust left and right tail weights (Brys et al., 2006).

  • qrxxyy: A character string consisting of the first two characters "qr" and followed by four numbers will request a ratio of dependents quantiles (i.e. different quantiles from the same sample).The first two number digits (in place of "xx") will indicate the quantile for the numerator, and the second two numerical digits "yy" for the denominator. For example, qr9010 will estimate and test the ratio Q(0.9)/Q(0.1).

The default var.method="qor" is to estimate the probability density function directly using the lognormal Quantile Optimality Ratio (QOR) for choosing a suitable bandwidth (Prendergast & Staudte,2016). Alternatively, the variances can be estimated by inverting a density estimator evaluated at the quantiles and this can be done using var.method = "density".

Additional to using a text string with argument measure to indicate which quantile-based measure is to be used (of those included for the q.test function), users can also define and request their own. For example, while the median is the default for a single quantile, other quantiles can also be requested (e.g., u = 0.25 will request the first quartile). This option is also included for linear combinations of quantiles and ratios of linear combinations, which can be done in two ways. For a single linear combination, argument u is the vector of probability values defining the quantiles to be used, and argument coef is a vector of coefficients for the linear combination. If a ratio is needed, then u and coef are used for the numerator and u2 and coef2 for the denominator linear combination. Alternatively, a single u can be used to identify all quantiles for the ratio, and then coef can be a matrix (2 rows) whose first row specifies the coefficients for the numerator and the second row for the denominator. For more information and further examples, see Prendergast, Dedduwakumara & Staudte (2024), and the example code below shows how to obtain results for the robust CVs using all three approaches (to achieve identical results).

Further details on confidence intervals, including coverage properties of, can be found for ratios of dependent quantiles (Prendergast & Staudte, 2017), ratios of independent quantiles and IQRs (Arachchige et al., 2021) and for robust CVs (Arachchige et al., 2022).

Value

hypothesis test results and associated confidence interval (a list with class "htest")

References

Arachchige, C. N., Cairns, M., & Prendergast, L. A. (2021). Interval estimators for ratios of independent quantiles and interquantile ranges. Communications in Statistics-Simulation and Computation, 50(12), 3914-3930.

Arachchige, C.N.P.G., Prendergast, L.A., & Staudte, R.G. (2022). Robust Analogs to the Coefficient of Variation. Journal of Applied Statistics, 49(2), 268–290.

Brys, G., Hubert, M., & Struyf, A. (2006). Robust measures of tail weight. Computational Statistics & Data Analysis, 50(3), 733–759.

Groeneveld, R. A., & Meeden, G. (1984). Measuring skewness and kurtosis. Journal of the Royal Statistical Society Series D: The Statistician, 33(4), 391–399.

Groeneveld, R. A., & Meeden, G. (2009). An improved skewness measure. Metron, 67(3), 325.

Hyndman, R.J., & Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician, 50(4), 361–365.

Moors, J. J. A. (1988). A quantile alternative for kurtosis. Journal of the Royal Statistical Society: Series D (The Statistician), 37(1), 25–32.

Prendergast, L. A., & Staudte, R. G. (2016). Exploiting the quantile optimality ratio in finding confidence intervals for quantiles. Stat, 5(1), 70-81

Prendergast, L. A., & Staudte, R. G. (2017). When large n is not enough–distribution-free interval estimators for ratios of quantiles. The Journal of Economic Inequality, 15, 277-293.

Prendergast, L. A., Dedduwakumara, D.S. & Staudte, R.G. (2024) rquest: An R package for hypothesis tests and confidence intervals for quantiles and summary measures based on quantiles, preprint, pages 1-13

Examples

#  Create some data
x <- c(8.43,7.08,8.79,8.88,7.87,5.94,8.79,5.46,8.11,7.08)
y <- c(13.44,13.65,14.77,9.51,14.07,10.92,11.59,13.42,8.93,10.88)

# One sample hypothesis test for the IQR
q.test(x, measure = "iqr")

# Two samples hypothesis test for robust coefficient variations (0.75*IQR/median)
# with log transformation and back-transformation to the ratio scale,.
q.test(x, y, measure = "rCViqr", log.transf = TRUE, back.transf = TRUE)

# The same two samples hypothesis test for robust coefficient variations (0.75*IQR/median)
# by using 'u',''u2','coef' and 'coef2' arguments.
u<-c(0.25,0.75)
coef<-0.75*c(-1,1)
u2<-0.5
coef2<-1
q.test(x,y,u=u,u2=u2,coef=coef,coef2=coef2,log.transf=TRUE,back.transf=TRUE)

# The same two samples hypothesis test for robust coefficient variations (0.75*IQR/median)
# by using only 'u' and 'coef' arguments.
u<-c(0.25,0.5,0.75)
num <- 0.75*c(-1,0,1)
den <- c(0,1,0)
coef <- rbind(num, den)
q.test(x,y,u=u,coef=coef,log.transf=TRUE,back.transf=TRUE)

qcov

Description

compute a covariance matrix consisting of variances (on the diagonal) for quantile estimates and covariances (off-diagonal) between different quantile estimates

Usage

qcov(x, u, method = "qor", FUN = qor.ln, quantile.type = 8, bw.correct = TRUE)

Arguments

x

a numeric vector of data values.

u

a numeric vector of probability values in [0, 1]) specifying the quantiles to be estimate.

method

approach use to estimate the quantile density function. Either "qor" or "density".

FUN

QOR function for the log-normal

quantile.type

argument for the quantile function. Default is set to 8 so that output is consistent with default quantile function use and other functions such as IQR (see help file for quantile() for more details)

bw.correct

replace bw by the values of v when v<=bw (see Prendergast & Staudte (2016b) for more details)

Details

This function computes a covariance matrix for a vector of quantile estimators. This is done via estimating the inverted density function evaluated at the respective quantiles. The default for this is to use the quantile optimality ratio (QOR) approach (Prendergast & Staudte, 2016) which computes an optimal bandwidth. Alternatively, using method = "density" will use the generic density function to estimate the density.

Value

a covariance matrix consisting of variances (on the diagonal) for quantile estimates and covariances (off-diagonal) between different quantile estimates

References

Prendergast, L. A., & Staudte, R. G. (2016). Exploiting the quantile optimality ratio in finding confidence intervals for quantiles. Stat, 5(1), 70-81

Prendergast, L. A., Dedduwakumara, D.S. & Staudte, R.G. (2024) rquest: An R package for hypothesis tests and confidence intervals for quantiles and summary measures based on quantiles, preprint, pages 1-13

Examples

# Create some data
set.seed(1234)
x <- rnorm(100)

# Compute the variance-covariance matrix for sample quartiles.
qcov(x, c(0.25, 0.5, 0.75))

qineq

Description

carry out hypothesis tests and obtain associated confidence intervals for quantile based inequality measures

Usage

qineq(
  x,
  y = NULL,
  J = 100,
  measure = "QRI",
  alternative = c("two.sided", "less", "greater"),
  quantile.type = 8,
  var.method = "qor",
  conf.level = 0.95,
  true.ineq = 0.5
)

Arguments

x

a numeric vector of data values.

y

an optional second vector of data values for two-sample testing.

J

number of grid points

measure

quantile based inequality measure to be used. Either "QRI" (default) or "G2".(See details).

alternative

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

quantile.type

argument for the quantile function. Default is set to 8 so that output is consistent with default quantile function use and other functions such as IQR (see help file for quantile() for more details)

var.method

approach use to estimate the quantile density function. Either "qor"(default) or "density".(See details).

conf.level

coverage for the estimated confidence interval.

true.ineq

the specified hypothesized value of the inequality measure or the difference of the inequality depending on whether it was a one-sample test or a two-sample test.

Details

This function performs hypothesis testing and calculates the corresponding confidence intervals for inequality measures based on quantiles. The available options for quantile based measures in argument measure are shown below.

  • QRI: Quantile Ratio Index (Prendergast & Staudte, 2018). This is the default choice.

  • G2: Quantile variant of the Gini index (Prendergast & Staudte, 2016a).

The default var.method="qor" is to estimate the probability density function directly using the lognormal Quantile Optimality Ratio (QOR) for choosing a suitable bandwidth (Prendergast & Staudte,2016b). Alternatively, the variances can be estimated by inverting a density estimator evaluated at the quantiles and this can be done using var.method = "density".

For more information and further examples, see Prendergast, Dedduwakumara & Staudte (2024)

Value

hypothesis test results and associated confidence interval (a list with class "htest")

References

Prendergast, L.A., & Staudte, R.G. (2016a). Quantile versions of the Lorenz curve. Electronic Journal of Statistics, 10(2), 1896 – 1926.

Prendergast, L. A., & Staudte, R. G. (2016b). Exploiting the quantile optimality ratio in finding confidence intervals for quantiles. Stat, 5(1), 70-81

Prendergast, L. A., & Staudte, R. G. (2018). A simple and effective inequality measure. The American Statistician, 72(4), 328-343.

Prendergast, L. A., Dedduwakumara, D.S. & Staudte, R.G. (2024) rquest: An R package for hypothesis tests and confidence intervals for quantiles and summary measures based on quantiles, preprint, pages 1-13

Examples

# Create some data
x <- c(8.43,7.08,8.79,8.88,7.87,5.94,8.79,5.46,8.11,7.08)
y <- c(13.44,13.65,14.77,9.51,14.07,10.92,11.59,13.42,8.93,10.88)

# Two sample hypothesis test for the QRI measure
qineq(x,y)