[R] Generating data from Null Distribution

Robin Hankin rksh1 at cam.ac.uk
Wed Jan 6 10:06:38 CET 2010


Jim

the 2x2 case is reasonably straightforward because the support
is quite a small set. 

With the aylmer package you could do this:

 > a <- matrix(c(1,5,7,8),2,2)
 > sample(seq_along(allprobs(a)),100,replace=TRUE,prob=allprobs(a))
  [1] 3 2 4 1 3 4 4 4 4 3 3 4 4 2 3 4 5 4 3 3 4 4 2 1 4 3 3 3 4 2 3 4 3 
4 4 2 3
 [38] 3 4 3 4 4 3 4 3 2 3 4 2 3 3 4 2 3 2 3 1 3 5 1 3 2 3 3 4 5 2 5 1 3 
3 4 3 5
 [75] 4 2 3 4 5 2 3 4 4 3 3 3 4 3 4 6 3 3 4 2 4 4 2 3 2 3
 >

For bigger tables the matter becomes quite complicated but you
can use randomboards() of the aylmer package, which generates
random samples using the Metropolis-Hastings algorithm.

HTH

Robin




Jim Silverton wrote:
> Hello everyone,
>
> Can someone tell me exactly how to generate data from a null distribution
> for the fisher exact test? I know I have to use the hypergrometric but
> exactly what commands do I use?
>
> Jim
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>   


-- 
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877



More information about the R-help mailing list