Documentation

signtest

Description

example

p = signtest(x) returns the p-value for a two-sided sign test.

signtest tests the hypothesis that data in x has a continuous distribution with zero median against the alternative that the distribution does not have zero median at the 5% significance level.

example

p = signtest(x,y) returns the p-value of a two-sided sign test. Here,signtest tests for the hypothesis that the data in xy has a distribution with zero median against the alternative that the distribution does not have zero median. Note that a hypothesis of zero median for xy is not equivalent to a hypothesis of equal median for x and y.

example

p = signtest(x,y,Name,Value) returns the p-value for the sign test with additional options specified by one or more Name,Value pair arguments.

[p,h] = signtest(___) also returns a logical value indicating the test decision. The value h = 1 indicates a rejection of the null hypothesis, and h = 0 indicates a failure to reject the null hypothesis at the 5% significance level. You can use any of the input arguments in the previous syntaxes.

example

[p,h,stats] = signtest(___) also returns the structure stats containing information about the test statistic.

example

[___] = signtest(x,m) returns any of the output arguments in the previous syntaxes for the test whether the data in x are observations from a distribution with median m against the alternative that the median is different from m.

example

[___] = signtest(x,m,Name,Value) returns any of the output arguments in the previous syntaxes for the sign test with additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Test the hypothesis of zero median.

Generate the sample data.

rng('default') % for reproducibility
x = randn(1,25);

The sampling distribution of x is symmetric with zero median.

Test the null hypothesis that x comes from a distribution with a median different from zero median.

[p,h,stats] = signtest(x,0)
p = 0.1078
h = logical
0

stats = struct with fields:
zval: NaN
sign: 17

At the default 5% significance level, the result h = 0 indicates that signtest fails to reject to the null hypothesis of zero median. signtest calculates the p-value using the exact method, hence it does not calculate zval and returns it as a NaN.

Test the hypothesis of zero median for the difference between paired samples.

Generate the sample data.

rng('default') % for reproducibility
before = lognrnd(2,.25,10,1);
after = before + (lognrnd(0,.5,10,1) - 1);

The sampling distribution of the difference between before and after is symmetric with zero median.

Test the null hypothesis that the difference of before and after has zero median.

[p,h] = signtest(before,after)
p = 0.7539
h = logical
0

At the default 5% significance level, the value h = 0 indicates that signtest fails to reject to the null hypothesis of zero median in the difference.

Test the hypothesis of zero median for the difference between two paired samples using the exact and approximate methods.

Generate the sample data.

rng('default') % for reproducibility
x = lognrnd(2,.25,15,1);
y = x + trnd(2,15,1);
display([x y])
8.4521    7.8047
11.6869   11.4094
4.2009    5.1133
9.1664   12.1655
8.0020   10.0300
5.3285    6.0153
6.6300    5.1235
8.0499    8.6737
18.0763   19.2164
14.7665   15.3380
5.2726    8.4187
15.7798   16.2093
8.8583    8.5575
7.2735    7.4783
8.8347    7.8894

Test the hypothesis that xy has zero median.

[p,h,stats] = signtest(x,y)
p = 0.3018
h = logical
0

stats = struct with fields:
zval: NaN
sign: 5

At the default 5% significance level, the value h = 0 indicates that the test fails to reject the null hypothesis of zero median in the difference.

Repeat the test using the approximate method.

[p,h,stats] = signtest(x,y,'Method','approximate')
p = 0.3017
h = logical
0

stats = struct with fields:
zval: -1.0328
sign: 5

The approximate $p$-value, which signtest obtains using the z-statistic, is really close to the exact $p$-value.

Perform a left-sided sign test for large samples.

Load the sample data.

Test the null hypothesis that the median of the grade differences before and after the tutoring program is 0 against the alternate that it is less than 0.

p = 0.0013
h = logical
1

stats = struct with fields:
zval: -3.0110
sign: 37

Because the sample size is large (greater than 100), signtest uses an approximate method to calculate the $p$-value and also returns the value of the $z$-statistic. The test rejects the null hypothesis that there is no difference between the grade medians at the 5% significance level.

Test the hypothesis that the population median is different from a specified value.

Load the sample data.

The data set has 15 observations for variables gpa and lsat.

Test the hypothesis that the median lsat score is higher than 570.

[p,h,stats] = signtest(lsat,570,'Tail','right')
p = 0.0176
h = logical
1

stats = struct with fields:
zval: NaN
sign: 12

Both the $p$-value, 0.0176, and h = 1 indicate that at the 5% significance level the test concludes in favor of the alternate hypothesis.

Input Arguments

collapse all

Sample data, specified as a vector.

Data Types: single | double

Sample data, specified as a vector. y must be the same length as x.

Data Types: single | double

Hypothesized value of the median, specified as a scalar.

Example: signtest(x,35)

Data Types: single | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Alpha',0.01,'Method','approximate','Tail','right' specifies a right-tailed sign test with 1% significance level, which returns the approximate p-value.

Significance level of the hypothesis test, specified as the comma-separated pair consisting of 'Alpha' and a scalar value in the range 0 to 1. The default value of Alpha is 0.05. Significance level of h is 100 * Alpha%.

Example: 'Alpha', 0.01

Data Types: double | single

p-value computation method, specified as the comma-separated pair consisting of 'Method' and one of the following:

 'exact' Exact computation of the p-value, p. 'approximate' Normal approximation for computing the p-value, p.

The default computation method is 'exact', if there are fewer than 100 observations and 'approximate' if there are 100 observations or more.

Example: 'Method','exact'

Type of test, specified as the comma-separated pair consisting of 'Tail' and one of the following:

 'both' Two-sided hypothesis test, which is the default test type. For a one-sample test, the alternate hypothesis states that the data in x come from a continuous distribution with median different than zero (or m).For a two-sample test, the alternate hypothesis states that the data in x-y come from a distribution with median different than zero. 'right' Right-tailed hypothesis test. For a one-sample test, the alternate hypothesis states that the data in x come from a continuous distribution with median greater than zero (or m).For a two-sample test, the alternate hypothesis states the data in x-y come from a distribution with median greater than zero. 'left' Left-tailed hypothesis test. For a one-sample test, the alternate hypothesis states that the data in x come from a continuous distribution with median less than zero (or m).For a two-sample test, the alternative hypothesis states the data in x-y come from a distribution with median less than zero.

Example: 'Tail','left'

Output Arguments

collapse all

p-value of the test, returned as a nonnegative scalar from 0 to 1. p is the probability of observing a test statistic as or more extreme than the observed value under the null hypothesis. signtest computes the two-sided p-value by doubling the most significant one-sided value.

Result of the hypothesis test, returned as a logical value.

• If h = 1, this indicates rejection of the null hypothesis at the 100 * Alpha% significance level.

• If h = 0, this indicates a failure to reject the null hypothesis at the 100 * Alpha% significance level.

Test statistics, returned as a structure. The test statistics stored in stats are:

• sign: Value of the sign test statistic.

• zval: Value of the z-statistic (computed only for large samples).

collapse all

Sign Test

The sign test is a nonparametric test for the median of a population or median of the difference of two populations.

For example, for tests on a single population median:

• If the test is two-sided, then the test statistic, S, is the minimum of the number of observations that are smaller or larger than the hypothesized median value, M0.

• If the test is right-sided, then S is the number of observations that are larger than the hypothesized median value M0.

• If the test is left-sided, then S is the number of observations that are smaller than the hypothesized median value M0.

z-Statistic

For a large sample, signtest uses the z-statistic to approximate the p-value.

The signtest test statistic is the number of elements that are greater than 0 (for signtest(x) or signtest(x-y)), or m (for signtest(x,m)). Hence, the z-statistic of the sign test, with the continuity correction, is:

$z=\frac{\left(S-E\left(S\right)\right)}{\sqrt{V\left(S\right)}}=\frac{\left(S-\left(0.5\right)n-0.5sign\left(npos-nneg\right)\right)}{\sqrt{\left(0.5\right)\left(0.5\right)n}},$

where npos and nneg are the number of positive and negative differences from the hypothesized median value, respectively.

Algorithms

For a one-sample test, signtest omits values in x that are zero or NaN.

For a two-sample test, signtest omits values in xy that are zero or NaN.

 Gibbons, J. D., and S. Chakraborti. Nonparametric Statistical Inference, 5th Ed. Boca Raton, FL: Chapman & Hall/CRC Press, Taylor & Francis Group, 2011.

 Hollander, M., and D. A. Wolfe. Nonparametric Statistical Methods. Hoboken, NJ: John Wiley & Sons, Inc., 1999.