[R] Fwd: exact trend test (enumerate all possible contingency tables with fixed row and column margins)

Bert Gunter bgunter.4567 at gmail.com
Thu Jan 7 19:39:31 CET 2016


Sorry -- neglected to reply to the list. -- Bert



---------- Forwarded message ----------
From: Bert Gunter <bgunter.4567 at gmail.com>
Date: Thu, Jan 7, 2016 at 10:38 AM
Subject: Re: [R] exact trend test (enumerate all possible contingency
tables with fixed row and column margins)
To: li li <hannah.hlx at gmail.com>


I do not know whether there is any package to do what you want.

I **do** know that the algorithms required to do this are very
sophisticated and that with more than a few groups, all possible
enumerations are out of the question so that approximating shortcuts
must be used. See http://www.cytel.com/software-solutions/statxact for
some background.

I **suspect** that you have no need to do what you have requested and
**suggest** that you consult a local statistician or
stats.stackexchange.com for another approach to whatever your
underlying issue is.

Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jan 7, 2016 at 10:18 AM, li li <hannah.hlx at gmail.com> wrote:
> I did check the coin package before. I did not see a function in that
> package that can be used to list all the possible contingency tables with
> fixed margins.
> Of course I googled "exact trend test using R". There is not enough help
> there.
> For up to three groups, I can easily enumerate all the contingency table
> with fixed margins, but with 5 groups it is not that easy.
> But as mentioned before, this is done implicitly and routinely in
> fisher.test function in R. So if anyone who have done this in R before,
> please help.
> Thanks.
>    Hanna
>
>
> 2016-01-07 12:20 GMT-05:00 Michael Dewey <lists at dewey.myzen.co.uk>:
>
>> You received a number of suggestions about where to look and packages that
>> might be suitable. Did you do that? If you did which ones did you look at
>> and why did you reject them?
>>
>>
>> On 07/01/2016 16:29, li li wrote:
>>
>>> Thanks for all the reply. Below is the data in a better format.
>>>
>>> addmargins(dat)
>>>>
>>>
>>>      dose 0 dose 0.15 dose 0.5 dose 1.5 dose 5 Sum
>>>
>>> yes      4         3        4        5      8  24
>>>
>>> no       4         5        4        3      0  16
>>>
>>> Sum      8         8        8        8      8  40
>>>
>>> I think it is easier and better that I rephrase my question. I would like
>>> to enumerate all possible
>>> contingency tables with the row margins and column margins fixed as in the
>>> above table. Yes. In fisher's exact test, this should have been done
>>> internally. But I need explicitly find all such tables. Need some help on
>>> this and thanks very much in advance.
>>>
>>>      Hanna
>>>
>>>
>>> 2016-01-07 7:15 GMT-05:00 peter dalgaard <pdalgd at gmail.com>:
>>>
>>>
>>>> On 07 Jan 2016, at 08:31 , David Winsemius <dwinsemius at comcast.net>
>>>> 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.
>>>>
>>>>>
>>>>> 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.
>>>>
>>>> I'd expect that there is such a beast as a noncentral multivariate
>>>> hypergeometric (for the 2x2 case that is what we use to get the CI for
>>>> the
>>>> odds ratio), but usually, one just wants the null distribution of the
>>>> test
>>>> statistic.
>>>>
>>>>
>>>>
>>>>>
>>>>>> 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.
>>>>
>>>>>
>>>>>
>>>> Or, more to the point, there is prop.trend.test(). Neither are exact
>>>> tests, though.
>>>>
>>>> I think package "coin" may something relevant.
>>>>
>>>> -pd
>>>>
>>>>
>>>> --
>>>>> David.
>>>>>
>>>>>>
>>>>>> Thanks very much!!
>>>>>>
>>>>>>   Hanna
>>>>>>
>>>>>>       [[alternative HTML version deleted]]
>>>>>>
>>>>>> ______________________________________________
>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>>> PLEASE do read the posting guide
>>>>>>
>>>>> http://www.R-project.org/posting-guide.html
>>>>
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>>
>>>>>
>>>>> David Winsemius
>>>>> Alameda, CA, USA
>>>>>
>>>>> ______________________________________________
>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide
>>>>>
>>>> http://www.R-project.org/posting-guide.html
>>>>
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>
>>>> --
>>>> Peter Dalgaard, Professor,
>>>> Center for Statistics, Copenhagen Business School
>>>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>>>> Phone: (+45)38153501
>>>> Office: A 4.23
>>>> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>>>>
>>>>
>>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> --
>> Michael
>> http://www.dewey.myzen.co.uk/home.html
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list