

On 13Apr11 17:40:53, Jim Silverton wrote:
> I have a matrix say,
>
> 1 4
> 23 30
>
> and I want to find the previously attainable fisher's exact test
> pvalue. Is there a way to do this in R?
> 
> Thanks,
> Jim.
I do not understand what you mean by "previously attainable".
As far as that particular matrix is concerned, the fisher.test()
function will yield its exact Fisher Pvalue:
M < matrix(c(1, 4, 23, 30), byrow=TRUE, nrow=2)
M
# [,1] [,2]
# [1,] 1 4
# [2,] 23 30
fisher.test(M)
# Fisher's Exact Test for Count Data
# data: M
# pvalue = 0.3918
# alternative hypothesis: true odds ratio is not equal to 1
# 95 percent confidence interval:
# 0.006355278 3.653391412
# sample estimates:
# odds ratio
# 0.3316483
So the Pvalue is 0.3918 (as attained now, and as attainable
at any time previously if you had done the above ... !).
Ted.

EMail: (Ted Harding) < [hidden email]>
Faxtoemail: +44 (0)870 094 0861
Date: 14Apr11 Time: 00:28:59
 XFMail 
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Apr 14, 2011, at 01:29 , (Ted Harding) wrote:
> On 13Apr11 17:40:53, Jim Silverton wrote:
>> I have a matrix say,
>>
>> 1 4
>> 23 30
>>
>> and I want to find the previously attainable fisher's exact test
>> pvalue. Is there a way to do this in R?
>> 
>> Thanks,
>> Jim.
>
> I do not understand what you mean by "previously attainable".
>
> As far as that particular matrix is concerned, the fisher.test()
> function will yield its exact Fisher Pvalue:
>
> M < matrix(c(1, 4, 23, 30), byrow=TRUE, nrow=2)
> M
> # [,1] [,2]
> # [1,] 1 4
> # [2,] 23 30
> fisher.test(M)
> # Fisher's Exact Test for Count Data
> # data: M
> # pvalue = 0.3918
> # alternative hypothesis: true odds ratio is not equal to 1
> # 95 percent confidence interval:
> # 0.006355278 3.653391412
> # sample estimates:
> # odds ratio
> # 0.3316483
>
> So the Pvalue is 0.3918 (as attained now, and as attainable
> at any time previously if you had done the above ... !).
>
What Ted said, plus
f < fisher.test(M)
f$p.value
# [1] 0.3917553

Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email] Priv: [hidden email]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


What Ted and Peter did were Fisher's exact test, To get the previous
attainable pvalue, what you do is the the fisher exact test pvalues of
ALL the possible tables with margins fixed and choose the pvalue that is
just below the one for fisher's exact test of the original table.
n Thu, Apr 14, 2011 at 3:01 AM, peter dalgaard < [hidden email]> wrote:
>
> On Apr 14, 2011, at 01:29 , (Ted Harding) wrote:
>
> > On 13Apr11 17:40:53, Jim Silverton wrote:
> >> I have a matrix say,
> >>
> >> 1 4
> >> 23 30
> >>
> >> and I want to find the previously attainable fisher's exact test
> >> pvalue. Is there a way to do this in R?
> >> 
> >> Thanks,
> >> Jim.
> >
> > I do not understand what you mean by "previously attainable".
> >
> > As far as that particular matrix is concerned, the fisher.test()
> > function will yield its exact Fisher Pvalue:
> >
> > M < matrix(c(1, 4, 23, 30), byrow=TRUE, nrow=2)
> > M
> > # [,1] [,2]
> > # [1,] 1 4
> > # [2,] 23 30
> > fisher.test(M)
> > # Fisher's Exact Test for Count Data
> > # data: M
> > # pvalue = 0.3918
> > # alternative hypothesis: true odds ratio is not equal to 1
> > # 95 percent confidence interval:
> > # 0.006355278 3.653391412
> > # sample estimates:
> > # odds ratio
> > # 0.3316483
> >
> > So the Pvalue is 0.3918 (as attained now, and as attainable
> > at any time previously if you had done the above ... !).
> >
>
> What Ted said, plus
>
> f < fisher.test(M)
> f$p.value
> # [1] 0.3917553
>
>
> 
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: [hidden email] Priv: [hidden email]
>
>

Thanks,
Jim.
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks for the clarification, Jim. The terminology "previous"
was not selfexplanatory!
The following implements (in a somewhat crude way, but explicit)
a solution to your question:
M < matrix(c(1, 4, 23, 30), byrow=TRUE, ncol=2)
M
# [,1] [,2]
# [1,] 1 4
# [2,] 23 30
fisher.test(M)$p.value
# [1] 0.3917553
mina < (1) ; maxa < 4
As < (mina:maxa)
Ps < numeric(length(As))
for(i in (1:length(As))){
a < As[i]
dM < matrix(c(a,a,a,a),nrow=2)
Ps[i] < fisher.test(M+dM)$p.value
}
Ps
# [1] 0.070002593 0.391755250 1.000000000 0.639558667
# [5] 0.148849134 0.009276064
So, amongst the Pvalues, the one below the attained one (0.3917553)
which is greatest is Ps[5] = 0.148849134. This could be identified
by the expression
max(Ps[Ps < fisher.test(M)$p.value])
# [1] 0.1488491
If fisher.test(M)$p.value were already the smallest possible value,
then this expression would return Inf.
Ted.
On 14Apr11 14:55:36, Jim Silverton wrote:
> What Ted and Peter did were Fisher's exact test, To get the previous
> attainable pvalue, what you do is the the fisher exact test pvalues
> of
> ALL the possible tables with margins fixed and choose the pvalue that
> is
> just below the one for fisher's exact test of the original table.
>
> n Thu, Apr 14, 2011 at 3:01 AM, peter dalgaard < [hidden email]>
> wrote:
>
>>
>> On Apr 14, 2011, at 01:29 , (Ted Harding) wrote:
>>
>> > On 13Apr11 17:40:53, Jim Silverton wrote:
>> >> I have a matrix say,
>> >>
>> >> 1 4
>> >> 23 30
>> >>
>> >> and I want to find the previously attainable fisher's exact test
>> >> pvalue. Is there a way to do this in R?
>> >> 
>> >> Thanks,
>> >> Jim.
>> >
>> > I do not understand what you mean by "previously attainable".
>> >
>> > As far as that particular matrix is concerned, the fisher.test()
>> > function will yield its exact Fisher Pvalue:
>> >
>> > M < matrix(c(1, 4, 23, 30), byrow=TRUE, nrow=2)
>> > M
>> > # [,1] [,2]
>> > # [1,] 1 4
>> > # [2,] 23 30
>> > fisher.test(M)
>> > # Fisher's Exact Test for Count Data
>> > # data: M
>> > # pvalue = 0.3918
>> > # alternative hypothesis: true odds ratio is not equal to 1
>> > # 95 percent confidence interval:
>> > # 0.006355278 3.653391412
>> > # sample estimates:
>> > # odds ratio
>> > # 0.3316483
>> >
>> > So the Pvalue is 0.3918 (as attained now, and as attainable
>> > at any time previously if you had done the above ... !).
>> >
>>
>> What Ted said, plus
>>
>> f < fisher.test(M)
>> f$p.value
>> # [1] 0.3917553
>>
>>
>> 
>> Peter Dalgaard
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Email: [hidden email] Priv: [hidden email]
>>
>>
>
>
> 
> Thanks,
> Jim.

EMail: (Ted Harding) < [hidden email]>
Faxtoemail: +44 (0)870 094 0861
Date: 14Apr11 Time: 16:37:44
 XFMail 
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Apr 14, 2011, at 16:55 , Jim Silverton wrote:
> What Ted and Peter did were Fisher's exact test, To get the previous attainable pvalue, what you do is the the fisher exact test pvalues of ALL the possible tables with margins fixed and choose the pvalue that is just below the one for fisher's exact test of the original table.
Well, you might have said so...
For onesided tests, just add/subtract matrix(c(1,1,1,1),2) and recompute. Otherwise, I guess that you get to play with dhyper and phyper because you need to know where the opposite tail starts. Check the internals of fisher.test.
>
> n Thu, Apr 14, 2011 at 3:01 AM, peter dalgaard < [hidden email]> wrote:
>
> On Apr 14, 2011, at 01:29 , (Ted Harding) wrote:
>
> > On 13Apr11 17:40:53, Jim Silverton wrote:
> >> I have a matrix say,
> >>
> >> 1 4
> >> 23 30
> >>
> >> and I want to find the previously attainable fisher's exact test
> >> pvalue. Is there a way to do this in R?
> >> 
> >> Thanks,
> >> Jim.
> >
> > I do not understand what you mean by "previously attainable".
> >
> > As far as that particular matrix is concerned, the fisher.test()
> > function will yield its exact Fisher Pvalue:
> >
> > M < matrix(c(1, 4, 23, 30), byrow=TRUE, nrow=2)
> > M
> > # [,1] [,2]
> > # [1,] 1 4
> > # [2,] 23 30
> > fisher.test(M)
> > # Fisher's Exact Test for Count Data
> > # data: M
> > # pvalue = 0.3918
> > # alternative hypothesis: true odds ratio is not equal to 1
> > # 95 percent confidence interval:
> > # 0.006355278 3.653391412
> > # sample estimates:
> > # odds ratio
> > # 0.3316483
> >
> > So the Pvalue is 0.3918 (as attained now, and as attainable
> > at any time previously if you had done the above ... !).
> >
>
> What Ted said, plus
>
> f < fisher.test(M)
> f$p.value
> # [1] 0.3917553
>
>
> 
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: [hidden email] Priv: [hidden email]
>
>
>
>
> 
> Thanks,
> Jim.
>

Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email] Priv: [hidden email]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

