# How to best visualize one-sample test?

We are currently writing a paper with several one-sample Wilcoxon tests. While visualizing two-sample tests is easy via boxplots, I was wondering whether there is any good way to visualize one-sample test results?

# Example data
pd <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64,
0.73, 1.46, 1.15, 0.88, 0.90, 0.74, 1.21)

wilcox.test(pd, mu = 1.1)

#   Wilcoxon signed rank test
#
# data:  pd
# V = 72, p-value = 0.5245
# alternative hypothesis: true location is not equal to 1.1


...and also:

I would like to get Z-value instead of V-value. I know that if I use coin package instead of basic stats I will have z-values, but coin package seems not to be able perform one-sample Wilcoxon test.

• Hmm... In SPSS, I got with your data V=72.5 (Z=.710) and p=.478. I wonder why R gives 72, not 72.5 value of the test statistic. – ttnphns Oct 30 '13 at 9:55
• Hi @ttnphns, from you comment is to me evident that SPSS gives both V and Z vales. Or not? Or you make some conversion of V to Z value? – Ladislav Naďo Oct 30 '13 at 10:10
• pic.dhe.ibm.com/infocenter/spssstat/v20r0m0/topic/… , also the same in sligthly different notation pic.dhe.ibm.com/infocenter/spssstat/v20r0m0/topic/… . But what I still don't understand is why SPSS and R give not identical results... – ttnphns Oct 30 '13 at 11:11
• When I calculate the test statistic "by hand" in R, I get the same value as R gives. $\quad\quad\quad\quad\quad\quad$ (r=rank(abs(pd-1.1)); s0=(pd>1.1); sum(r*s0)) – Glen_b Oct 30 '13 at 12:46

Something like this? Or were you after some interval for the median, like you get with notched boxplots (but suited to a one sample comparison, naturally)?

Here's an example of that: This uses the interval suggested in McGill et al (the one in the references of ?boxplot.stats). One could actually use notches, but that might increase the chance that it is interpreted instead as an ordinary notched boxplot.

Of course if you need something to more directly replicate the signed rank test, various things can be constructed that do that, which could even include the interval for the pseudo-median (i.e. the one-sample Hodges-Lehmann location estimate, the median of pairwise averages).

Indeed, wilcox.test can generate the necessary information for us, so this is straightforward:

> wilcox.test(pd,mu=1.1,conf.int=TRUE)

Wilcoxon signed rank test

data:  pd
V = 72, p-value = 0.5245
alternative hypothesis: true location is not equal to 1.1
95 percent confidence interval:
0.94 1.42
sample estimates:
(pseudo)median
1.1775


and this can be plotted also: [The reason the boxplot interval is wider is that the standard error of a median at the normal (which is the assumption underlying the calculation based off the IQR) tends to be larger than that for a pseudomedian when the data are reasonably normalish.]

And of course, one might want to add the actual data to the plot: Z-value

R uses the sum of the positive ranks as its test statistic (this is not the same statistic as discussed on the Wikipedia page on the test).

Hollander and Wolfe give the mean of the statistic as $n(n+1)/4$ and the variance as $n(n+1)(2n+1)/24$.

So for your data, this is a mean of 60 and a standard deviation of 17.61 and a z-value of 0.682 (ignoring continuity correction)

The code I used to generate the fourth plot (from which the earlier ones can also be done by omitting unneeded parts) is a bit rough (it's mostly specific to the question, rather than being a general plotting function), but I figured someone might want it:

notch1len <- function(x) {
stats <- stats::fivenum(x, na.rm = TRUE)
iqr <- diff(stats[c(2, 4)])
(1.96*1.253/1.35)*(iqr/sqrt(sum(!is.na(x))))
}

w <- notch1len(pd)
m <- median(pd)

boxplot(pd,horizontal=TRUE,boxwex=.4)

abline(v=1.1,col=8)
points(c(m-w,m+w),c(1,1),col=2,lwd=6,pch="|")

ci=wilcox.test(pd,mu=1.1,conf.int=TRUE)$conf.int #$
est=wilcox.test(pd,mu=1.1,conf.int=TRUE)$estimate stripchart(pd,pch=16,add=TRUE,at=0.7,cex=.7,method="jitter",col=8) points(c(ci,est),c(0.7,0.7,0.7),pch="|",col=4,cex=c(.9,.9,1.5)) lines(ci,c(0.7,0.7),col=4)  I may come back and post more functional code later. • Thank you @Glen_b, it draws away my uncertainty. I hope reviewers will not have any problem with it. – Ladislav Naďo Oct 30 '13 at 10:07 • @Glen_b, the boxplot with median doesn't look to me right for presenting 1-sample Wilcoxon test. The test checks if the population distribution is symmetric about a test value, not if that value is the median (as would be with 1-sample sign test). Well, of course, is it is symmetric, then the value is automatically the median; but it contrary isn't true, it can be the median without symmetricity. Saying all that, I mean that boxplot isn't right to depict Wilcoxon: you must show symmetricity, hence histogram, density, violin plots would be better. – ttnphns Oct 30 '13 at 10:40 • @ttnphns (i) The OP explicitly regards ordinary boxplots as suitable for indicating a two sample comparison (presumably a rank sum test) even though that test is not actually a comparison of medians, and (ii) the signed rank test is a test of location that assumes symmetry. Ordinary notched boxplots have underlying normal assumptions(!). One can check the reasonableness of the symmetry assumption fairly easily, but I think the point of the suggested display was not to explicitly replicate the test but simply to indicate that the middle of the data is close to the hypothesized value. – Glen_b Oct 30 '13 at 11:03 • What do you call pseudomedian here? one-sample Hodges-Lehmann location estimator? – ttnphns Oct 30 '13 at 12:37 • I just did that Friday; that's how I know ;-). – gung Apr 27 '14 at 23:27 If you like boxplots, you can as readily show a single boxplot with a line or other reference showing your hypothesised value. (@Glen_b posted an answer with an excellent simple example precisely as I was first writing this.) It is arguable that boxplots, now very popular, are massively overused for one-sample and two-sample exploration. (Their real value, in my view, is when you are comparing many sets of values, with number of samples or groups or variables more like 10, 30 or 100, and there is a major need to see overall patterns amid a mass of possible detail.) The key point is that with just one or two samples (groups, variables), you have space on a plot to show much more detail, detail that could be interesting or important for comparison. With a good design, such detail need not be distracting in visual comparison. Evidently, in most usual versions the box plot suppresses all detail in its box, showing the middle half of the data, except in so far as the position of the median inside the box conveys some information. Depending on the exact rules used, such as the 1.5 IQR convention of showing data points individually if and only if they are 1.5 IQR or more from the nearer quartile, it is even possible that the box plot suppresses most of the detail about the other half of the data. Often, and perhaps even usually, such detail may be irrelevant to something like a Wilcoxon test, but being prepared to see something illuminating in the data display is always a good idea. A display that remains drastically underused in many fields is the quantile plot, a display of the ordered values against an associated cumulative probability. (For other slightly technical reasons, this cumulative probability is typically not$1/n, \cdots, n/n$for sample size$n$but something like$(i - 0.5)/n$for rank$i\$, 1 being the rank of the smallest value.)

Here are your example data with a reference line added for 1.1. In other examples, key points include

• For two-sample comparisons, there are easy choices between superimposing traces, juxtaposing traces, or using related plots such as quantile-quantile plots.

• The plot performs well over a range of sample sizes.

• Outliers, granularity (lots of ties), gaps, bi- or multimodality will all be shown as or much more clearly than in box plots.

• Quantile plots mesh well with monotonic transformations, which is not so true for box plots.

Some will want to point out that cumulative distribution plots or survival function plots show the same information, and that's fine by me.

See W.S. Cleveland's books (details at http://store.hobart.com/) for restrained but effective advocacy of quantile plots.

Another very useful plot is the dot or strip plot (which goes under many other names too), but I wanted to blow a small trumpet for quantile plots here.

R details I leave for others. I am focusing here on the more general statistical graphics question, which clearly cuts across statistical science and all software possibilities.

Incidentally, I don't know the background story but the name wilcox.test in R seems a poor choice to me. So, you save on typing two characters, but the name encourages confusion, not least because of past and present people in statistical fields called Wilcox. Lack of justice for Mann and Whitney is another detail. The person being honoured was Wilcoxon.

• +1 - In addition to the many groups notes - with only 15 values box-plots (while still useful in general) can be misleading (e.g. bimodal data). Super-imposing the points on the box plot can show such discrepancies (examples here and here). – Andy W Oct 30 '13 at 12:07
• There's much to be said for such displays. – Glen_b Oct 30 '13 at 12:51