Consider an urn that contains 10 tickets, labelled: 1,1,1,1,2,5,5,10,10,10
I want to draw with replacement n=40 tickets. I am interested in the sum,
Y, of the 40 ticket values that I draw
Write an R function named urn.model that simulates this experiement. What
I have below is not working.
flip.n = function(p,n) {
return(runif(n,0,1) < p)
}
ticket.ns<-c(1,1,1,1,2,5,5,10,10,10)
urn.model = function(ticket.ns) {
draws.per.sim = 1
prob = .1
urn.results = rep(-1, ticket.ns)
for (i in 1:ticket.ns) {
draws = flip.n(prob,draws.per.sim)
num =sum(draws,ticket.ns)
urn.results[i] = num
}
return(urn.results)
}
urn.25.samples =urn.model(25)
urn.25.samples
Follow up question:
Use urn.model to generate a sample y={y1,...,y25) of n=25 observed sums.