Learn R Programming

robnptests

The R package robnptests contains different robust and nonparametric tests for the two-sample location problem. The tests allow for comparisons of either the location or the scale parameters of two random samples.

Installation

The released version of robnptests can be installed from CRAN with

install.packages("robnptests")

To install the development version, the devtools package is required:

if (!require("devtools")) {
  install.packages("devtools")
}

devtools::install_github("s-abbas/robnptests")

library(robnptests)

Scope and Usage

The robust and nonparametric tests in this R package follow the construction principle of the popular t-test: A robust estimate for the location difference of the two samples is divided by a robust estimate of scale. The p-values can either be computed using the permutation principle, the randomization principle, or the asymptotic distribution of the estimators. If the principle to compute the p-value is not specified by the user, it will be selected automatically depending on the sample size. The functions used to compute the location and scale estimates are also made available to the user.

The following list shows the currently implemented tests in the package:

  • tests based on the median (med_test), the one-sample Hodges-Lehmann estimator (hl1_test), and the two-sample Hodges-Lehmann estimator (hl2_test), scaled by robust estimators
  • Yuen's t-test (trimmed_test)
  • tests based on the Huber-, Hampel- or Bisquare-M-estimator (m_test).

Even though the test statistics compare location estimates of the samples, they can be used to identify scale differences. This is achieved by setting the argument scale.test = TRUE, with which the observations in the samples are log-transformed so that scale differences between the original samples correspond to location differences in the transformed samples.

Details on the tests and references can be found on the help pages of the functions and the vignette vignette("robnptests").

Example 1: Asymptotic test for location difference using the two-sample Hodges-Lehmann estimator

set.seed(121)
x <- rnorm(50); y <- rnorm(50)

hl2_test(x, y, method = "asymptotic")

# 
# 	Asymptotic test based on HL2-estimator
# 
# data:  x and y
# D = 1.0916, p-value = 0.275
# alternative hypothesis: true location shift is not equal to 0
# sample estimates:
# HL2 of x and y 
#      0.2048249

Example 2: Asymptotic test for scale difference using the two-sample Hodges-Lehmann estimator

hl2_test(x, y, method = "asymptotic", scale.test = TRUE)

# 	Asymptotic test based on HL2-estimator
# 
# data:  x and y
# S = -0.24094, p-value = 0.8096
# alternative hypothesis: true ratio of variances is not equal to 1
# sample estimates:
# HL2 of log(x^2) and log(y^2) 
#                   -0.1040422 

Contributions

We are grateful for any contribution to the further development of the R package. If you experience any problems using the package or have suggestions for new features, please open an issue in the issue tracker. Please consult our contribution guidelines before submitting a pull request.

Copy Link

Version

Install

install.packages('robnptests')

Monthly Downloads

192

Version

1.1.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Sermad Abbas

Last Published

February 13th, 2023

Functions in robnptests (1.1.0)

m_est

M-estimator of location
calc_perm_p_value

Calculation of permutation p-value
hl1_test

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

Two-sample location tests based on two-sample Hodges-Lehmann estimator.
hodges_lehmann

One-sample Hodges-Lehmann estimator
hodges_lehmann_2sample

Two-sample Hodges-Lehmann estimator
compute_results_finite

Finite-sample test decision for HL1-, HL2-, and MED-tests
m_est_perm_distribution

Permutation distribution for M-statistics
compute_results_asymptotic

Test decision for asymptotic versions of HL1-, HL2-, and MED-tests
check_test_input

Checks for input arguments
trimmed_t

Test statistic for the two-sample trimmed t-test (Yuen's t-test)
trim_mean

Trimmed mean
med_test

Two-sample location tests based on the sample median
select_method

Select principle for computing null distribution
trimmed_test

Two-sample trimmed t-test (Yuen's t-Test)
m_test_statistic

Test statistics for the M-tests
rob_perm_statistic

Robust test statistics based on robust location estimators
win_var

Winsorized variance
wobble

Add random noise to remove ties
rob_scale

Robust scale estimators based on median absolute deviation
m_test

Two sample location test based on M-estimators
perm_distribution

Permutation distribution for robust test statistics
preprocess_data

Preprocess data for the robust two sample tests
win_mean

Winsorized mean