To do each example, just click the "Submit" button. You do not have to type in any R instructions or specify a dataset. That's already done for you.
1 - pbinom(b - 1, n, 1 / 2) pbinom(n - b, n, 1 / 2)the first line here does exactly the same as line five in the example, but is less accurate for very small P-values. The second does exactly the same as line five of the example because of the symmetry of the binomial distribution with
p = 1 / 2
.
pbinom(b, n, 1 / 2)
1 - 2 * pbinom(k - 1, n, 1 / 2)for different values of
k
. The vectorwise operation of R
functions can give them all at once
k <- seq(1, 100) k <- k[1 - 2 * pbinom(k - 1, n, 1 / 2) > 0.5] 1 - 2 * pbinom(k - 1, n, 1 / 2)If one adds these lines to the form above, one sees that there's not much choice, only three achieved levels
k
to be any integer between
zero and n / 2
just before the second to last line in the form
(cat . . .
). A confidence interval with some
achieved confidence level will be produced.
alpha
rather than
alpha / 2
in the fifth line of the form. Then make either
the lower limit minus infinity or the upper limit plus infinity, as desired.
Many authorities recommend (at least lukewarmly) the following procedure
for dealing with zero differences (differences equal to the hypothesized
value μ if not zero) in the sign test. After defining the
vector z
of differences, do
z <- z[z != mu] n <- length(z)
which treates zero differences as if they were not part of the data (and the sample size is reduced accordingly).
The best that can be said for this is
But these hypotheses are not what you want to test! What you want to test is the hypotheses described on p. 60 in Hollander and Wolfe: that the medians are the same or different.
Modify the data for our example above for the sign test adding a million zero differences to the data set. The zero fudge says we throw out those zeros and do exactly the same analysis getting P = 0.00046, a highly statistically significant result.
But the whole data set says we get exactly the same response in the treatment and control situations in 1,000,000 cases and a different response in only 25 cases. This is overwhelming evidence in favor of the null hypothesis (3.37) in Hollander and Wolfe. It is highly significant evidence against the tricky null hypothesis of the zero fudge test.
The moral of the story: In interpreting a test of significance it's not enough that P < 0.05. It's even more important what the null hypothesis is. Rejecting a null hypothesis of no scientific interest whatsoever is worthless.
The alternative to the zero fudge, what Hollander and Wolfe call the conservative approach is to count the zero differences as evidence in favor of the null hypothesis. This is a bit tricky, since no matter how you do it, the recipe for the test must be altered.
For the lower tailed test, assuming the vector of differences z
,
the sample size n
, and the hypothesisized value of the median
mu
have already been defined,
b <- sum(z >= mu) pbinom(b, n, 1 / 2)
calculates the P-value for the lower-tailed test. Note that we need
the weak inequality (>=
) to include the zero differences
in the tail area calculated by the following statement.
Reversing the inquality gives the conservative upper-tailed test.
blow <- sum(z <= mu) pbinom(blow, n, 1 / 2)
Note that this isn't the test statistic described in the book, but obviously does the right thing by symmetry.
A recent paper by your humble instructor and another member of this department resurrected an old idea, randomized tests, and gave it a new spin as fuzzy tests, taking some terminology from fuzzy set theory.
In a simple situation where there are no ties, a fuzzy P-value for for a sign test (or other rank tests we will meet in a few weeks) can be thought of as a P-value smeared out over an interval. If t is the observed value of the test statistic and T is a random variable having the distribution of the test statistic assuming the null hypothesis is true, then
Note that the fuzzy P-value gives more information. The upper end point of the fuzzy P-value interval is the conventional P-value. Hence fans of conventional P-values cannot object to fuzzy P-values. The fuzzy P-value tells you more than a conventional P-value, but it does not tell you less.
The interpretation of a fuzzy P-value is just like the interpretation of a conventional P-value.
The only difference is that what is now low, high, or intermediate is a range of values. So long as the range isn't too wide, this makes little difference to the interpretation. Anyone who thinks there is an important difference between P = 0.051 and P = 0.049 understands neither science nor statistics. A fuzzy P-value smeared out over the interval (0.049, 0.051) isn't different in any practical sense.
alternative
to "less"
.
To do a two-tailed test, change the value of alternative
to "two.sided"
. You may abbreviate.
alt = "g"
and alt = "two"
work too.
(You only need enough of the argument name or value to specify it
unambiguously.)
Theoretically, a fuzzy P-value is a random variable whose randomness comes not from the sampling process that generated the data but is artificial, introduced by the theoretical statistician. We can say here that the fuzzy P-value is a random variable uniformly distributed on the interval (0.000078, 0.000455), which is what the summary says.
If there are ties, then the fuzzy.sign.test
automatically
does the right thing (or at least a right thing). Then the
probability distribution of the fuzzy P-value becomes non-uniform.
Details are given in the paper cited above and also on the
fuzzy P-values and confidence intervals page.
If one likes the decision theoretic view of hypothesis testing
(pick an alpha level, say 0.05, and accept
or reject
the null hypothesis at that level, ignoring all other levels),
then the fuzzy analog is to report the probability that the fuzzy
test rejects (which is the same as the probability that the randomized
test rejects), which is the probability that the fuzzy P-value is less
than alpha.
Not much difference between rejecting the null hypothesis (that the true population median is zero) with probability 0.94 and with probability 1.00. In either case, moderately strong, but not extremely strong, evidence against the null hypothesis.
The fuzzy confidence interval is a function that gives a number between
zero and one for each parameter value.
The values for which it is one
(the core of the interval) are the ones for which it gets
full credit
if the true unknown parameter value is among them.
The values for which it is nonzero
(the support of the interval) are the ones for which it gets
partial credit
if the true unknown parameter value is among them.
The reported confidence level (here 95%) is the expected amount of credit
it gets (full or partial) averaged over samples from the population.
In most cases (and here) fuzzy and conventional confidence intervals are not so different. The core of the fuzzy confidence interval, which is (7.5, 23.8) in the example, counts in 9 from each end, which would be an 89.22% confidence interval by itself, what
n <- length(x) k <- 9 1 - 2 * pbinom(k - 1, n, 1 / 2)
would calculate.
The core of the fuzzy confidence interval,
which is (7.1, 24.7) in the example,
counts in 8 from each end, which would be a 95.67% confidence interval
by itself, what the above code would calculate if we set
k <- 8
instead. The partial credit is carefully arranged
to give exactly 95% coverage regardless of what the true parameter value
may be.
More details are given in the paper cited above and also on the fuzzy P-values and confidence intervals page.