Experiment:'X is a binomial of five trials and p = 0.5, where X is the number of heads. Ysample is a binomial of X trials and p=0.5, where Ysample is the number of heads.' T is the number of times the experiment is repeated until the value of Ysample>=3. This is the code:
while (Ysample[i]<3){
length(X)=n
length(Y)=n
X=c(1:n)
Y=c(1:n)
i=1
X[i]=sum(rbinom(5,1,0.5))
Ysample[i]=sum(rbinom(X[i],1,0.5))
i=i+1
}
T=n
I am unsure why it is not working and why no matter how many times I run it I always get T=10000?