View source: R/print_wilcoxon_rs.R
print_wilcoxon_rs | R Documentation |
Print the results of a Wilcoxon rank sum test (Mann-Whitney-U test)
print_wilcoxon_rs(
wc_object,
decimals_p = 3,
consistent = NULL,
group1 = NULL,
group2 = NULL,
groupvar = NULL,
effsize = NULL,
neg = FALSE,
N = NULL,
decimals_eff = NULL
)
wc_object |
an object returned by |
decimals_p |
how many decimals should be printed for the p-value (defaults to 3) |
consistent |
an optional parameter determining for which group the test statistic U should be reported. Can be set to 'min' or 'max'. See details. |
group1 |
a vector containing the cases of the first group |
group2 |
a vector containing the cases of the second group |
groupvar |
a vector containing a grouping variable |
effsize |
a character indicating which effect size should be reported, if any. Possible values are: 'r', 'rsqu' and 'd'. By default, no effect size will be reported. See details. |
neg |
a logical indicating whether the effect size should
be reported with a negative sign. Defaults to |
N |
an integer passing information about the total N of the sample. Needed when effect sizes should be calculated, but N cannot be inferred because neither of group1, group2 or groupvar have been provided. Should groups or a grouping variable have been provided, N must not be used. |
decimals_eff |
an integer specifying how many digits the effect size should be printed with, if an effect size is desired. Defaults to 2. r and r squared will be printed without a leading zero, d will be printed with a leading zero because it is possible for d to take values larger than one. |
In order to calculate a Wilcoxon rank sum test, the argument
paired
in wilcox.test
needs to be FALSE
.
Otherwise, a Wilcoxon signed rank test will be computed instead and
the statistics printed by print_wilcoxon_rs
will be
misleading.
Note that the test statistic W calculated in wilcox.test
that is printed as test statistic U in print_wilcoxon_rs
will correspond to the U of the first of the two groups compared in
wilcox.test
. In the default method of
wilcox.test
, this is the vector assigned to x. In the
formula method, this is the first group as identified by the grouping
variable. Some software, like SPSS, consistently reports the smaller or
larger U. If you wish to mimic this, you can specify the desired
behaviour by providing the consistent
argument. Setting
consistent
to 'min' will print the smaller of the two U, setting
it to 'max' will print the larger U. In order to do so, you need to
provide the n for both groups.
You can either do that by passing the data of both groups to the
arguments group1
and group2
, respectively. From those,
print_wilcoxon_rs
will calculate the group sizes. Any
vector with the length of the corresponding group size will produce
the desired result. This is the recommended option if your
wc_object
has been created using the default version of
wilcox.test
, i.e. if groups were passed as x
and
y
. The order in which you pass group1
and group2
to print_wilcoxon_rs
does not have to correspond to the
order in which x
and y
were passed to
wilcox.test
.
Alternatively, you can pass a grouping variable to the argument
groupvar
. From this, print_wilcoxon_rs
will
calculate group sizes. This is the recommended option if your
wc_object
has been created using the formula version of
wilcox.test
, i.e. if a grouping variable was passed after
the ~
. To prevent mistakes, you can either use group1
and
group2
or groupvar
.
By default, when consistent
is not provided,
print_wilcoxon_rs
will print U using W as taken from
wilcox.test
.
There are three options available for calculating an effect size via
the argument effsize
:
the point biserial correlation r (effsize = 'r'
), which
is calculated by dividing Z-score by the square root of N. According
to Cohen (1988) a small, medium and large effect correspond to r = .1,
.3 and .5, respectively. Currently, print_wilcoxon_rs
infers the Z-score from the p-value.
r squared (identical to eta squared; effsize = 'rsqu'
),
which is the ratio of variability associated with an effect compared
to the ratio of overall variance
d (effsize = 'd'
), which is calculated from r as follows:
2*r/(sqrt(1-r^2))
According to Cohen (1988), a small, medium and large effect correspond to r = .2, .5 and .8, respectively.
Information on the direction of the effect (as indicated in the sign
of the Z-score) or in which order the groups have been compared is
not included in the output of wilcox.test
. Hence, only
absolute effect sizes can be calculated. It is advised to report
absolute effect sizes unless there is a meaningful for the two groups
tested (e.g. Fritz et al, 2012). In some cases, it might be desired to
specify the direction of an effect by including the sign of the effect.
To that end, it is possible to print the negative effect size with
neg = TRUE
, but caution is advised: You should always check if
the sign of the effect size you report is the correct one, especially
in the case of one-sided testing.
A string describing the results of the Wilcoxon test; to be included in an R markdown document.
Juliane Nagel juliane.nagel@zi-mannheim.de
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale, NJ: Erlbaum.
Fritz, C. O., Morris, P. E., & Richler, J. J. (2012). Effect size estimates: Current use, calculations, and interpretation. Journal of Experimental Psychology: General, 141(1), 2-18. http://dx.doi.org/10.1037/a0024338
data(iris)
dat <- subset(iris, Species %in% c("setosa", "versicolor"))
wc_iris <- wilcox.test(dat$Sepal.Length ~ dat$Species, correct = FALSE)
# include this call in Rmd inline code
print_wilcoxon_rs(wc_iris)
wc_iris2 <- wilcox.test(dat$Sepal.Width ~ dat$Species, correct = FALSE)
print_wilcoxon_rs(wc_iris2, consistent = "min",
group1 = dat$Sepal.Width[dat$Species == "setosa"],
group2 = dat$Sepal.Width[dat$Species == "versicolor"])
print_wilcoxon_rs(wc_iris2, consistent = "max",
groupvar = dat$Species)
print_wilcoxon_rs(wc_iris2, consistent = "max",
groupvar = dat$Species, effsize = "rsqu")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.