np.loc.test | R Documentation |
Performs one and two sample nonparametric (randomization) tests of location parameters, i.e., means and medians. Implements univariate and multivariate tests using eight different test statistics: Student's one-sample t-test, Johnson's modified t-test, Wilcoxon's Signed Rank test, Fisher's Sign test, Student's two-sample t-test, Welch's t-test, Wilcoxon's Rank Sum test (i.e., Mann-Whitney's U
test), and a studentized Wilcoxon test for unequal variances.
np.loc.test(x, y = NULL,
alternative = c("two.sided", "less", "greater"),
mu = 0, paired = FALSE, var.equal = FALSE,
median.test = FALSE, symmetric = TRUE,
R = 9999, parallel = FALSE, cl = NULL,
perm.dist = TRUE, na.rm = TRUE)
x |
Numeric vector (or matrix) of data values. |
y |
Optional numeric vector (or matrix) of data values. |
alternative |
Alternative hypothesis. Must be either "two.sided" ( |
mu |
Null hypothesis value |
paired |
Logical indicating whether you want a paired location test. |
var.equal |
Logical indicating whether to treat the two variances as being equal. |
median.test |
Logical indicating whether the location test is for the median. Default is |
symmetric |
Logical indicating if the distribution of |
R |
Number of resamples for the permutation test (positive integer). |
parallel |
Logical indicating if the |
cl |
Cluster for parallel computing, which is used when |
perm.dist |
Logical indicating if the permutation distribution should be returned. |
na.rm |
If |
One sample | \mu is the mean (or median) of X |
Paired | \mu is the mean (or median) of X - Y |
Two sample | \mu is the mean difference E(X) - E(Y) |
or the median of the differences X - Y |
|
For one (or paired) sample tests, the different test statistics can be obtained using
median.test = F | median.test = T |
|
symmetric = F | Johnson t test | Fisher sign test |
symmetric = T | Student t test | Wilcoxon signed rank test |
For two sample tests, the different test statistics can be obtained using
median.test = F | median.test = T |
|
var.equal = F | Welch t test | Studentized Wilcoxon test |
var.equal = T | Student t test | Wilcoxon rank sum test |
statistic |
Test statistic value. |
p.value |
p-value for testing |
perm.dist |
Permutation distribution of |
alternative |
Alternative hypothesis. |
null.value |
Null hypothesis value for |
var.equal |
Assuming equal variances? Only for two sample tests. |
median.test |
Testing the median? |
symmetric |
Assuming symmetry? Only for one sample and paired tests. |
R |
Number of resamples. |
exact |
Exact permutation test? See Note. |
estimate |
Estimate of parameter |
univariate |
Univariate test statistic value for |
adj.p.value |
Adjusted p-value for testing significance of |
method |
Method used for permutation test. See Details. |
If the input x
(and possibly y
) is a matrix with m > 1
columns, the multivariate test statistic is defined as
alternative | statistic |
two.sided | max(abs(univariate)) |
less | min(univariate) |
greater | max(univariate) |
The global null hypothesis (across all m
variables) is tested by comparing the observed statistic
to the permutation distribution perm.dist
. This produces the p.value
for testing the global null hypothesis.
The local null hypothesis (separately for each variable) is tested by comparing the univariate
test statistic to perm.dist
. This produces the adjusted p-values (adj.p.values
), which control the familywise Type I error rate across the m
tests.
For one sample (or paired) tests, the permutation test will be exact when the requested number of resamples R
is greater than 2^n
minus one. In this case, the permutation distribution perm.dist
contains all 2^n
possible values of the test statistic.
For two sample tests, the permutation test will be exact when the requested number of resamples R
is greater than choose(N, n)
minus one, where m = length(x)
, n = length(y)
, and N = m + n
. In this case, the permutation distribution perm.dist
contains all choose(N, n)
possible values of the test statistic.
Nathaniel E. Helwig <helwig@umn.edu>
Blair, R. C., Higgins, J. J., Karniski, W., & Kromrey, J. D. (1994). A study of multivariate permutation tests which may replace Hotelling's T2 test in prescribed circumstances. Multivariate Behavioral Research, 29(2), 141-163. doi: 10.1207/s15327906mbr2902_2
Chung, E., & Romano, J. P. (2016). Asymptotically valid and exact permutation tests based on two-sample U-statistics. Journal of Statistical Planning and Inference, 168, 97-105. doi: 10.1016/j.jspi.2015.07.004
Fisher, R. A. (1925). Statistical methods for research workers. Edinburgh: Oliver and Boyd.
Helwig, N. E. (2019). Statistical nonparametric mapping: Multivariate permutation tests for location, correlation, and regression problems in neuroimaging. WIREs Computational Statistics, 11(2), e1457. doi: 10.1002/wics.1457
Janssen, A. (1997). Studentized permutation tests for non-i.i.d. hypotheses and the generalized Behrens-Fisher problem. Statistics & Probability Letters , 36 (1), 9-21. doi: 10.1016/S0167-7152(97)00043-6
Johnson, N. J. (1978). Modified t tests and confidence intervals for asymmetrical populations. Journal of the American Statistical Association, 73 (363), 536-544. doi: 10.2307/2286597
Mann, H. B., & Whitney, D. R. (1947). On a test of whether one of two random variables is stochastically larger than the other. Annals Of Mathematical Statistics, 18(1), 50-60. doi: 10.1214/aoms/1177730491
Pitman, E. J. G. (1937a). Significance tests which may be applied to samples from any populations. Supplement to the Journal of the Royal Statistical Society, 4(1), 119-130. doi: 10.2307/2984124
Romano, J. P. (1990). On the behavior of randomization tests without a group invariance assumption. Journal of the American Statistical Association, 85(411), 686-692. doi: 10.1080/01621459.1990.10474928
Student. (1908). The probable error of a mean. Biometrika, 6(1), 1-25. doi: 10.2307/2331554
Welch, B. L. (1938). The significance of the difference between two means when the population variances are unequal. Biometrika, 39(3/4), 350-362. doi: 10.2307/2332010
Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin, 1(6), 80-83. doi: 10.2307/3001968
plot.np.loc.test
S3 plotting method for visualizing the results
######******###### UNIVARIATE ######******######
###***### ONE SAMPLE ###***###
# generate data
set.seed(1)
n <- 10
x <- rnorm(n, mean = 0.5)
# one sample t-test
set.seed(0)
np.loc.test(x)
# Johnson t-test
set.seed(0)
np.loc.test(x, symmetric = FALSE)
# Wilcoxon signed rank test
set.seed(0)
np.loc.test(x, median.test = TRUE)
# Fisher sign test
set.seed(0)
np.loc.test(x, median.test = TRUE, symmetric = FALSE)
###***### PAIRED SAMPLE ###***###
# generate data
set.seed(1)
n <- 10
x <- rnorm(n, mean = 0.5)
y <- rnorm(n)
# paired t-test
set.seed(0)
np.loc.test(x, y, paired = TRUE)
# paired Johnson t-test
set.seed(0)
np.loc.test(x, y, paired = TRUE, symmetric = FALSE)
# paired Wilcoxon signed rank test
set.seed(0)
np.loc.test(x, y, paired = TRUE, median.test = TRUE)
# paired Fisher sign test
set.seed(0)
np.loc.test(x, y, paired = TRUE, median.test = TRUE, symmetric = FALSE)
###***### TWO SAMPLE ###***###
# generate data
set.seed(1)
m <- 7
n <- 8
x <- rnorm(m, mean = 0.5)
y <- rnorm(n)
# Welch t-test
set.seed(0)
np.loc.test(x, y)
# Student t-test
set.seed(0)
np.loc.test(x, y, var.equal = TRUE)
# Studentized Wilcoxon test
set.seed(0)
np.loc.test(x, y, median.test = TRUE)
# Wilcoxon rank sum test
set.seed(0)
np.loc.test(x, y, var.equal = TRUE, median.test = TRUE)
## Not run:
######******###### MULTIVARIATE ######******######
###***### ONE SAMPLE ###***###
# generate data
set.seed(1)
n <- 10
x <- cbind(rnorm(n, mean = 0.5),
rnorm(n, mean = 1),
rnorm(n, mean = 1.5))
# multivariate one sample t-test
set.seed(0)
ptest <- np.loc.test(x)
ptest
ptest$univariate
ptest$adj.p.values
###***### PAIRED SAMPLE ###***###
# generate data
set.seed(1)
n <- 10
x <- cbind(rnorm(n, mean = 0.5),
rnorm(n, mean = 1),
rnorm(n, mean = 1.5))
y <- matrix(rnorm(n * 3), nrow = n, ncol = 3)
# multivariate paired t-test
set.seed(0)
ptest <- np.loc.test(x, y, paired = TRUE)
ptest
ptest$univariate
ptest$adj.p.values
###***### TWO SAMPLE ###***###
# generate data
set.seed(1)
m <- 7
n <- 8
x <- cbind(rnorm(m, mean = 0.5),
rnorm(m, mean = 1),
rnorm(m, mean = 1.5))
y <- matrix(rnorm(n * 3), nrow = n, ncol = 3)
# multivariate Welch t-test
set.seed(0)
ptest <- np.loc.test(x, y)
ptest
ptest$univariate
ptest$adj.p.values
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.