Learn R Programming

MADtests (version 0.1.1)

madci: Test for a single the median absolute deviation (MAD)

Description

Calculates a confidence interval and test the null hypothesis for the median absolute deviation (MAD) for a single sample.

Usage

madci(
  x,
  constant = 1.4826,
  alternative = c("two.sided", "less", "greater"),
  conf.level = 0.95,
  true.mad = 1,
  use.gld = FALSE,
  gld.est = "TM",
  ...
)

Value

Hypothesis test results comparing two mads from independent samples and associated confidence interval for the ratio of mads (a list with class "htest"). This list includes values

statistic

the value of the Z-statistic.

p.value

the p-value for the test.

conf.int

a confidence interval for the MAD that is appropriate for the alternative hypothesis.

estimate

the estimated MAD.

null.value

the specified hypothesized value of the MAD under the null hypothesis.

alternative

a character string describing the alternative hypothesis.

data.name

a character string giving the names of the data.

Arguments

x

a numeric vector of data values.

constant

a scale factor. Default choice ensures population mad is equal to sd for normal distributions.

alternative

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

conf.level

confidence level for the confidence interval. The default is 0.95 (for a 95% confidence interval).

true.mad

a number which is the nominated value for the population mad under the null hypothesis. Default is 1.

use.gld

a logical indicating whether the Generalised Lambda Distribution (GLD) should be used to estimate the density of the data. Default is FALSE in which case the function density is used.

gld.est

a character string indicating which gld estimator to use if use.gld = TRUE. See details below.

...

additional arguments, if desired, to be passed to function density for density estimation (see help file for density() for more details).

Details

This function calculates an approximate confidence interval and conducts a hypothesis test for a single mad. The approximate variance used in the construction of the confidence interval and the test statistic is calculated using the varmad() function (see Arachchige and Prendergast (2024) and the help file for varmad() for further details). Note that the interval and test statistic are approximate and may be unreliable for small sample sizes. Arachchige and Prendergast (2024) showed that reliable results can be achieved for sample sizes of 50 or more when simulating data from various distributions. Additionally, the confidence interval is a Wald-type interval (estimate +/- crit*SE) and so it may be possible that the domain of the interval contains negative values. Since negative values are not possible for the mad, thought could be given to truncation (setting the lower bound to zero), although this may undermine interval coverage.

References

Arachchige, C.N.P.G., & Prendergast, L.A. (2026) Confidence intervals for median absolute deviations. Communications in Statistics-Simulation and Computation, 55(1), 13-22.

Examples

Run this code
# Create some data
set.seed(1234)
x <- rlnorm(100)

# Calculate the mad, 95% confidence interval and test the hypothesis
mad.est <- madci(x)
mad.est

Run the code above in your browser using DataLab