signTest: Exact Sign Test with Confidence Intervals

View source: R/signTest.R

signTestR Documentation

Exact Sign Test with Confidence Intervals


Uses link{binom.exact} or mcnemarExactDP to create sign test with confidence intervals on different parameters. Mid-p versions are available for some parameterizations (see details).


signTest(x, stat=c("cd","cpp","ud"), nullparm=NULL, 
   alternative=c("two.sided","less","greater"), conf.level=0.95,...)



numeric vector


statistic for estimates and confidence intervals, "cd"= conditional difference: proportion positive - proportion negative, "cpp"= conditional proportion positive, and "ud"= unconditional difference: proportion positive-proportion negative (conditional proportions are out of non-zero values, unconditional are out of all values)


null parameter value associated with stat, NULL value defaults to the exact sign test (i.e., stat="cd" and codestat="ud" gives 0, and stat="cpp" gives 0.5).


a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.


confidence level of the interval


arguments passed to binom.exact or mcnemarExactDP


The sign test is a conditional test, conditioning on the total number of non-zero observations testing that the proportion positive is different (or less, or greater) than the proportion negative. When the responses are differences in paired binary observations this is the same as a McNemar test.

This function gives estimates and confidence intervals compatible with the exact sign test for three different parameterizations. Let n.pos, n.neg, and n.nonzero be the number of positive, negative, and non-zero observations respectively out of n=length(x). The conditional proportion positive are n.pos/n.nonzero, and the unconditional proportion positive are n.pos/n. Similarly, the conditional proportion negative are n.neg/n.nonzero and the unconditional proportion negative are n.neg/n. When stat='cd' the parameterization is the conditional difference in proportions (pos-neg), and when stat='ud' the parameterization is the uncondtional difference in proportions (pos-neg). The third parameterization is stat='cpp' the conditional proportion positive. The argument nullparm gives the null value of the test when alternative='two.sided'. When nullparm=NULL, this gives the traditional sign test, where nullparm=0 for stat='cd' and stat='ud' and nullparm=0.5 for stat='cpp'.

Conditioning on m=n.nonzero, Y is binomial with parameters m and beta. So when stat='cpp' the parameter we are estimating is beta, and when stat='cd' the parameter we are estimating is beta - (1-beta) = 2*beta-1. We use binom.exact to do the p-value and confidence interval calculations. Thus, midp versions and different two-sided methods (given by tsmethod) can be calculated.

Unconditionally, we treat M (the number non-zero) as a random variable, and assume M is binomial with parameters n and theta. When stat='ud' the parameter we are estimating is delta = theta*(2*beta-1), which is the unconditional difference: (proportion positive out of the total) - (proprtion negative out of the total). We use mcnemarExactDP to do the the p-value and confidence interval calculations. The methods associated with that function are described in Fay and Lumbard (2020). As of now, when stat='ud' a midp version is not available, and the only two-sided method available is a 'central' one, meaning the error for the 95% confidence interval is bounded by 2.5% on each side.


A list of class 'htest' (use str to see elements)


vector of number of positive, negative, zero, and non-zero


vector of estimates related to stat argument


p.value associated with alternative

confidence interval


null parameter value




description of method

name of x argument


The sign test can be interpreted as a test that the median is zero assuming continuous data. If you want to test on the median without making continuity assumptions use medianTest.

Previous versions of signTest had stat='pos-neg' and stat='prop pos', which are now referred to as stat='cd' and stat='cpp', respectively. The old names give a warning, but may be removed in future versions.


Michael P. Fay


Fay MP, and Lumbard, K (2020). Confidence Intervals for Difference in Proportions for Matched Pairs Compatible with Exact McNemar's or Sign Tests. (unpublished manuscript).


signTest(x, stat='cd')
signTest(x, stat='cpp')
signTest(x, stat='ud')
# sample median is zero, 
# and not surprisingly the median test 
# properly gives a large p-value

asht documentation built on Aug. 24, 2023, 5:08 p.m.