Open Side Menu Go to the Top
Register
coupon collector simulator need help coupon collector simulator need help

10-20-2014 , 09:36 AM
write a program in R statistic program, which will simulate the process of n coupon collector(the popular problem)

The program must record the number of the boxes of a product, that someone bought until (s)he collects all the coupons. Do an application for n=15 repeating the process for 1000 times.

If X_i is the number of the boxes which had to be purchased until the 15 coupons to be completed during the i-th iterataion of the process, calculate the average of X_1,,...,X_1000.

Can anyone tell me what the above code does? every command of it!..Is it what I need ?

Here is what I found!

Code:
nbought <- function(N) {
coupons <- matrix(0,1,N) # initially have no coupons
for (k in 1:1000) { # collect until complete collection
x <- sample.int(N, 1, replace = TRUE)
coupons[x] <- 1 # mark that coupon type as collected
ifelse(sum(coupons)==N,return(k),-1)
} }
N <- 15 # set to desired number of different coupons
y <- sapply(matrix(N,100,1),nbought)
average<- mean(y) #added by me
another one :

Code:
Tmax = 1000
coupons = 72
prob = rep(0,Tmax)

prob[1:(coupons - 1)] = 1 
prob[coupons:Tmax]= 0
for (T in coupons:Tmax) {
  for (k in 1:(coupons - 1)) {
    prob[T] = prob[T] + (-1)^(k+1)*choose(coupons,k)*((coupons - k)/coupons)^T
  }
}

prob[1:Tmax] = 1 - prob[1:Tmax]

prob
and finally this:

Code:
x<-1:5
if.true<-FALSE
reps<-rep(0,1000)

for (j in 1:1000){
  i<-1
  repeat{
    sample<-sample(x,5,replace=TRUE)

    check<-x %in% sample

    if.true<-all.equal(check, rep(TRUE,5))

    if(if.true==TRUE){break}
    i<-i+1
  }
  reps[j]<-i
}
Coupon collector's problem

http://www.math.uni.wroc.pl/~debicki...lekcjonera.pdf

thanks
coupon collector simulator need help Quote
10-21-2014 , 11:01 PM
Unfortunately, BruceZ would have answered this by now. We worked on these sorts of problems for some time, but he retained the information better than I did and I would have to relearn it all to answer it.

I suggest sending your question directly to Mason.
coupon collector simulator need help Quote
10-24-2014 , 05:31 PM
Quote:
Originally Posted by Sherman
Unfortunately, BruceZ would have answered this by now. We worked on these sorts of problems for some time, but he retained the information better than I did and I would have to relearn it all to answer it.

I suggest sending your question directly to Mason.
who is that?
coupon collector simulator need help Quote
10-25-2014 , 12:32 PM
Quote:
Originally Posted by mathstacker
who is that?
Mason Malmuth. Just ask him if he can help you with your question. And if not, if he would reinstate BruceZ a moderator of the probability forum so that he will come back and help you.
coupon collector simulator need help Quote
10-29-2014 , 07:25 AM
^ LOL, the "coupon collector" in the title attracted the spammer?!

Juk
coupon collector simulator need help Quote

      
m