signTest¶
Performs a sign test.
Synopsis¶
signTest (x)
Required Arguments¶
- float
x[](Input) - Array of length
nObservationscontaining the input data.
Return Value¶
Binomial probability of nPositiveDeviations or more positive differences
in nObservations − nZeroDeviation trials. Call this value
probability. If no option is chosen, the null hypothesis is that the
median equals 0.0.
Optional Arguments¶
percentage, float (Input)Value in the range (0, 1). Argument
percentileis the 100 ×percentagepercentile of the population.Default:
percentage= 0.5percentile, float (Input)Hypothesized percentile of the population from which
xwas drawn.Default:
percentile= 0.0nPositiveDeviations(Output)- Number of positive differences
x[j − 1] −percentilefor j = 1, 2, …,nObservations. nZeroDeviations(Output)- Number of zero differences (ties)
x[j − 1] −percentilefor j = 1, 2, …,nObservations.
Description¶
Function signTest tests hypotheses about the proportion p of a
population that lies below a value q, where p corresponds to argument
percentage and q corresponds to argument percentile. In continuous
distributions, this can be a test that q is the 100 p-th percentile of
the population from which x was obtained. To carry out testing,
signTest tallies the number of values above q in
nPositiveDeviations. The binomial probability of nPositiveDeviations
or more values above q is then computed using the proportion p and the
sample size nObservations (adjusted for the missing observations and
ties).
Hypothesis testing is performed as follows for the usual null and alternative hypotheses:
\(H_0\): Pr(
x≤ q) ≥ p (the p-th quantile is at least q)\(H_1\): Pr(
x≤ q) < pReject \(H_0\) if probability is less than or equal to the significance level\(H_0\): Pr(
x≤ q) ≤ p (the p-th quantile is at least q)\(H_1\): Pr(
x≤ q) > pReject \(H_0\) if probability is greater than or equal to 1 minus the significance level\(H_0\): Pr (
x= q) = p (the p-th quantile is q)\(H_1\): Pr((
x≤ q) < p) or Pr((x≤ q) > p)Reject \(H_0\) if probability is less than or equal to half the significance level or greater than or equal to 1 minus half the significance level
The assumptions are as follows:
- They are independent and identically distributed.
- Measurement scale is at least ordinal; i.e., an ordering less than, greater than, and equal to exists in the observations.
Many uses for the sign test are possible with various values of p and q. For example, to perform a matched sample test that the difference of the medians of y and z is 0.0, let \(p=0.5\), \(q=0.0\), and \(x_i=y_i-z_i\) in matched observations y and z. To test that the median difference is c, let \(q=c\).
Examples¶
Example 1¶
This example tests the hypothesis that at least 50 percent of a population is negative. Because 0.18 < 0.95, the null hypothesis at the 5-percent level of significance is not rejected.
from __future__ import print_function
from numpy import *
from pyimsl.stat.signTest import signTest
n_observations = 19
x = [92.0, 139.0, -6.0, 10.0, 81.0, -11.0, 45.0,
-25.0, -4.0, 22.0, 2.0, 41.0, 13.0, 8.0, 33.0,
45.0, -33.0, -45.0, -12.0]
probability = signTest(x)
print("probability = %10.6f" % (probability))
Output¶
probability = 0.179642
Example 2¶
This example tests the null hypothesis that at least 75 percent of a population is negative. Because 0.923 < 0.95, the null hypothesis at the 5-percent level of significance is rejected.
from __future__ import print_function
from numpy import *
from pyimsl.stat.signTest import signTest
per = 0.75
tile = 0.0
n_positive_deviations = []
n_zero_deviations = []
x = array([92.0, 139.0, -6.0, 10.0, 81.0, -11.0, 45.0,
-25.0, -4.0, 22.0, 2.0, 41.0, 13.0, 8.0, 33.0,
45.0, -33.0, -45.0, -12.0])
probability = signTest(x, percentage=per, percentile=tile,
nPositiveDeviations=n_positive_deviations,
nZeroDeviations=n_zero_deviations)
print("probability = %10.6f." % probability)
print("Number of positive deviations is %d." % n_positive_deviations[0])
print("Number of ties is %d." % n_zero_deviations[0])
Output¶
probability = 0.922543.
Number of positive deviations is 12.
Number of ties is 0.