Bin functionk100 k50 theta05 ifk k k 0

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ad.bin <- function(k=100, K=50, theta=0.5){ if(K > k | k <= 0 | K <= 0) stop("Error: K > k or k < 0 or K < 0") X=0 while(k <= K) { i=trunc(1+k*theta) v <- rbeta(1, i, k+1-i) if (theta < v){ theta <- theta/v k=i-1 } else { X <- X + i theta <- (theta-v)/(1-v) k <- k - i k=k+1 }} u <- runif(k) return(X+length(u[u<theta])) } Second, I write code to generate multiple binomial random variables. > > + + + + + + # Generate several replicates r.bin <...
View Full Document

This document was uploaded on 01/28/2014.

Ask a homework question - tutors are online