Build data and AI skills | 50% off

Last chance! 50% off unlimited learning

Sale ends in


afex (version 0.6-82)

compare.2.vectors: Compare two vectors using various tests.

Description

Compares two vectors x and y using t-test, Welch-test (also known as Satterthwaite), Wilcoxon-test, and a permutation test implemented in coin.

Usage

compare.2.vectors(x, y, paired = FALSE, na.rm = FALSE,
    tests = c("parametric", "nonparametric"), coin = TRUE,
    alternative = "two.sided", perm.distribution =
    approximate(100000), wilcox.exact = NULL,
    wilcox.correct = TRUE)

Arguments

x
a (non-empty) numeric vector of data values.
y
a (non-empty) numeric vector of data values.
paired
a logical whether the data is paired. Default is FALSE.
na.rm
logical. Should NA be removed? Default is FALSE.
tests
Which tests to report, parametric or nonparamteric? The default c("parametric", "nonparametric") reports both. See details. (Arguments may be abbreviated).
alternative
a character, the alternative hypothesis must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter, will be passed to all functions.
coin
logical or character. Should (permutation) tests from the coin package be reported? Default is TRUE corresponding to all implemented tests. FALSE calculates no tests from coin. A character vector
perm.distribution
distribution argument to coin, see Distribution or , IndependenceTest. Defaults to approximate(1
wilcox.exact
exact argument to wilcox.test.
wilcox.correct
correct argument to wilcox.test.

Value

  • a list with up to two elements (i.e., paramteric and/or nonparamteric) each containing a data.frame with the following columns: test, test.statistic, test.value, test.df, p.

Details

The parametric tests (currently) only contain the t-test and Welch/Statterwaithe/Smith/unequal variance t-test implemented in t.test. The latter one is only displayed if paired = FALSE. The nonparametric tests (currently) contain the Wilcoxon test implemented in wilcox.test (stats::Wilcoxon) and (if coin = TRUE) the following tests implemented in coin:
  • apermutationtestoneway_test(the only test in this selction not using a rank transformation),
  • theWilcoxontestwilcox_test(coin::Wilcoxon), and
  • themediantestmedian_test.
Note that the two implementations of the Wilcoxon test probably differ. This is due to differences in the calculation of the Null distributions.

Examples

Run this code
with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2]))

# gives:
## $parametric
##    test test.statistic test.value test.df       p
## 1     t              t     -1.861   18.00 0.07919
## 2 Welch              t     -1.861   17.78 0.07939
## 
## $nonparametric
##              test test.statistic test.value test.df       p
## 1 stats::Wilcoxon              W     25.500      NA 0.06933
## 2     permutation              Z     -1.751      NA 0.08154
## 3  coin::Wilcoxon              Z     -1.854      NA 0.06487
## 4          median              Z      1.744      NA 0.17867

# compare with:
with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], alternative = "less"))

with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], alternative = "greater"))

# doesn't make much sense as the data is not paired, but whatever:
with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], paired = TRUE))

# from ?t.test:
compare.2.vectors(1:10,y=c(7:20, 200))

Run the code above in your browser using DataLab