Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. library(partitions)
  2. library(BiasedUrn)
  3. # Sum probabilities for all combinations of two groups.
  4. # Only works when length(x) = 3. We wish to merge x[1] and x[2].
  5. sum.mFNCH<-function(x, m, s, w, prec = 1e-07){
  6. rr <- restrictedparts(sum(x[1:2]),(length(x)-1))
  7. ss <- 0
  8. for(i in 1:ncol(rr)){
  9. ss <- sum(ss, dMFNCHypergeo(c(rr[,i],x[3]),m,s,w, precision=prec) )
  10. ss <- sum(ss, dMFNCHypergeo(c(rev(rr[,i]),x[3]),m,s,w, precision=prec) )
  11. }
  12. return(ss)
  13. }
  14.  
  15. # Multi-variate probability for 3 ball groups with:
  16. # 22, 47, and 139 balls and weights 0.1, 0.2, and 0.3.
  17. # Sample a total of 7 balls for the first two groups and 15 for the third.
  18. x <- c(2,5,15)
  19. m <- c(22,47,139)
  20. w <- c(0.1,0.2,0.3)
  21. sum.mFNCH(x, m, sum(x), w, prec=1e-8)
  22. [1] 0.1108098
  23.  
  24. # Univariate equivalent using average weight.
  25. wr <- ((22/69)*0.1+(47/69)*0.2)
  26. # Scale odds relative to third group which now constitute the white balls:
  27. wr <- wr/0.3
  28.  
  29. dFNCHypergeo(7, 69, 139, sum(c(7,15)), wr)
  30. [1] 0.1120066
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement