Performs the Ansari-Bradley two-sample test for a difference in scale
parameters.
Usage
ansari.test(x, ...)
## Default S3 method:
ansari.test(x, y,
alternative = c("two.sided", "less", "greater"),
exact = NULL, conf.int = FALSE, conf.level = 0.95,
...)
## S3 method for class 'formula'
ansari.test(formula, data, subset, na.action, ...)
Arguments
x
numeric vector of data values.
y
numeric vector of data values.
alternative
indicates the alternative hypothesis and must be
one of "two.sided", "greater" or "less". You
can specify just the initial letter.
exact
a logical indicating whether an exact p-value
should be computed.
conf.int
a logical,indicating whether a confidence interval
should be computed.
conf.level
confidence level of the interval.
formula
a formula of the form lhs ~ rhs where lhs
is a numeric variable giving the data values and rhs a factor
with two levels giving the corresponding groups.
data
an optional matrix or data frame (or similar: see
model.frame) containing the variables in the
formula formula. By default the variables are taken from
environment(formula).
subset
an optional vector specifying a subset of observations
to be used.
na.action
a function which indicates what should happen when
the data contain NAs. Defaults to
getOption("na.action").
...
further arguments to be passed to or from methods.
Details
Suppose that x and y are independent samples from
distributions with densities f((t-m)/s)/s and f(t-m),
respectively, where m is an unknown nuisance parameter and
s, the ratio of scales, is the parameter of interest. The
Ansari-Bradley test is used for testing the null that s equals
1, the two-sided alternative being that s != 1 (the
distributions differ only in variance), and the one-sided alternatives
being s > 1 (the distribution underlying x has a larger
variance, "greater") or s < 1 ("less").
By default (if exact is not specified), an exact p-value
is computed if both samples contain less than 50 finite values and
there are no ties. Otherwise, a normal approximation is used.
Optionally, a nonparametric confidence interval and an estimator for
s are computed. If exact p-values are available, an exact
confidence interval is obtained by the algorithm described in Bauer
(1972), and the Hodges-Lehmann estimator is employed. Otherwise, the
returned confidence interval and point estimate are based on normal
approximations.
Note that mid-ranks are used in the case of ties rather than average
scores as employed in Hollander & Wolfe (1973). See, e.g., Hajek,
Sidak and Sen (1999), pages 131ff, for more information.
Value
A list with class "htest" containing the following components:
statistic
the value of the Ansari-Bradley test statistic.
p.value
the p-value of the test.
null.value
the ratio of scales s under the null, 1.
alternative
a character string describing the alternative
hypothesis.
method
the string "Ansari-Bradley test".
data.name
a character string giving the names of the data.
conf.int
a confidence interval for the scale parameter.
(Only present if argument conf.int = TRUE.)
estimate
an estimate of the ratio of scales.
(Only present if argument conf.int = TRUE.)
Note
To compare results of the Ansari-Bradley test to those of the F test
to compare two variances (under the assumption of normality), observe
that s is the ratio of scales and hence s^2 is the ratio
of variances (provided they exist), whereas for the F test the ratio
of variances itself is the parameter of interest. In particular,
confidence intervals are for s in the Ansari-Bradley test but
for s^2 in the F test.
References
David F. Bauer (1972),
Constructing confidence sets using rank statistics.
Journal of the American Statistical Association67, 687–690.
Jaroslav Hajek, Zbynek Sidak and Pranab K. Sen (1999),
Theory of Rank Tests.
San Diego, London: Academic Press.
Myles Hollander and Douglas A. Wolfe (1973),
Nonparametric Statistical Methods.
New York: John Wiley & Sons.
Pages 83–92.
See Also
fligner.test for a rank-based (nonparametric)
k-sample test for homogeneity of variances;
mood.test for another rank-based two-sample test for a
difference in scale parameters;
var.test and bartlett.test for parametric
tests for the homogeneity in variance.
ansari_test in package coin
for exact and approximate conditional p-values for the
Ansari-Bradley test, as well as different methods for handling ties.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(stats)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/stats/ansari.test.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ansari.test
> ### Title: Ansari-Bradley Test
> ### Aliases: ansari.test ansari.test.default ansari.test.formula
> ### Keywords: htest
>
> ### ** Examples
>
> ## Hollander & Wolfe (1973, p. 86f):
> ## Serum iron determination using Hyland control sera
> ramsay <- c(111, 107, 100, 99, 102, 106, 109, 108, 104, 99,
+ 101, 96, 97, 102, 107, 113, 116, 113, 110, 98)
> jung.parekh <- c(107, 108, 106, 98, 105, 103, 110, 105, 104,
+ 100, 96, 108, 103, 104, 114, 114, 113, 108, 106, 99)
> ansari.test(ramsay, jung.parekh)
Ansari-Bradley test
data: ramsay and jung.parekh
AB = 185.5, p-value = 0.1815
alternative hypothesis: true ratio of scales is not equal to 1
Warning message:
In ansari.test.default(ramsay, jung.parekh) :
cannot compute exact p-value with ties
>
> ansari.test(rnorm(10), rnorm(10, 0, 2), conf.int = TRUE)
Ansari-Bradley test
data: rnorm(10) and rnorm(10, 0, 2)
AB = 62, p-value = 0.3312
alternative hypothesis: true ratio of scales is not equal to 1
95 percent confidence interval:
0.2413606 1.5342374
sample estimates:
ratio of scales
0.6437064
>
> ## try more points - failed in 2.4.1
> ansari.test(rnorm(100), rnorm(100, 0, 2), conf.int = TRUE)
Ansari-Bradley test
data: rnorm(100) and rnorm(100, 0, 2)
AB = 5987, p-value = 4.67e-06
alternative hypothesis: true ratio of scales is not equal to 1
95 percent confidence interval:
0.4304239 0.7100265
sample estimates:
ratio of scales
0.5537989
>
>
>
>
>
> dev.off()
null device
1
>