# [R] exact trend test

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jan 7 12:24:59 CET 2016

```On 07/01/2016 2:31 AM, David Winsemius wrote:
>
>> On Jan 6, 2016, at 8:16 PM, li li <hannah.hlx at gmail.com> wrote:
>>
>> Hi all,
>>   Is there an R function that does exact randomization trend test?
>>   For example, consider the 2 by 5 contingency table below:
>>
>>             dose0    dose 0.15    dose 0.5    dose 1.5    dose 5       row
>> margin
>> Yes          4                3                  4               5
>>      8                   24
>>   No          4                5                   4               3
>>        0                  16
>> col sum    8                8                   8               8
>>    8                   40
>
> Your data presentation has been distorted by your failure to post in plain text. Surely you have been asked in the past to correct this issue?
>
>>
>> To do the exact trend test, we need to enumerate all the contingency table
>> with the
>> row and column margins fixed.
>
> Er, how should that be done? A trend test? What is described above would be a general test of no association rather than a trend test. Please use clear language and be as specific as possible if you choose to respond.

Under (one version of) the null hypothesis of no trend, the distribution
should show no association.  The difference from the Fisher's test is in
the statistic:  rather than a measure of lack of association, you want a
measure of trend.  It's been a long time since I worked on this kind of
thing, but I believe Tarone's test gives an appropriate statistic.  I
don't know which package calculates its permutation distribution with
fixed margins, but there's probably one out there somewhere.

Duncan Murdoch

>> Find the probability corresponding to
>> obtaining
>> the corresponding contingency tables based on the multivariate
>> hypergeometric distribution. Finally the pvalue is obtained by adding
>> relevant probabilities.
>
> If there is a trend under consideration, then I do not understand such a trend would be modeled under a hypergeometric distribution? A hypergeometic distribution would suggest no trend, at least to my current understanding.
>
>>
>> Is there an R function that does this? if not, I am wondering whether it is
>> possible to
>> enumerate all possible contingency tables that has column sun and row sum
>> fixed?
>
> Wel, yes, that is possible and routinely done with `fisher.test`, but it is up to you to describe how that activity leads to a trend test.
>
> If you assume Poisson distributed errors a trend test is fairly easy to construct with glm.
>

```