# Failure to replicate simulation in a recent Hot Hands article

Recently, I've seen several news articles (e.g., New York Times) referring to the article Surprised by the Gamber's and Hot Hand Fallacies? A Truth in the Law of Small Numbers by Miller and Sanjurjo. In it the authors write

Jack takes a coin from his pocket and decides that he will flip it 4 times in a row, writing down the outcome of each flip on a scrap of paper. After he is done flipping, he will look at the flips that immediately followed an outcome of heads, and compute the relative frequency of heads on those flips. Because the coin is fair, Jack of course expects this empirical probability of heads to be equal to the true probability of flipping a heads: 0.5. Shockingly, Jack is wrong. If he were to sample one million fair coins and flip each coin 4 times, observing the conditional relative frequency for each coin, on average the relative frequency would be approximately 0.4.

I do not understand how they arrive at 0.4. Per the experiment below, 0.5 appears correct. I've also posted the code on github. I suspect my confusion is more about intrepreting what "Jack" is measuring than my code. My code represents my understanding of what they are trying to simulate Any help clearing this up would be appreciated.

    ncoins<-1000000
nflips<-4
flips<-matrix(rbinom(ncoins*nflips,1,0.5),nrow=ncoins,ncol=nflips)
results<-matrix(NA,nrow=nflips,ncol=3)
row.names(results)=paste("Flip ",seq(1,nflips))
row.names(results)[nflips]="Total"
colnames(results)<-c("NSuccess","NConsecSuccess","Percent")

eval_flips<-function(flips,i){
out<-list()
idx<-flips[,i]==1
out$nsuccess<-sum(idx) out$nconsecsuccess<-sum(flips[idx,i+1])
return(out)
}

for (i in 1:(nflips-1)){
flip.result<-eval_flips(flips,i)
results[i,"NSuccess"]<-flip.result$nsuccess results[i,"NConsecSuccess"]<-flip.result$nconsecsuccess
}
results<-data.frame(results)
results[nflips,1]<-sum(results[1:(nflips-1),1])
results[nflips,2]<-sum(results[1:(nflips-1),2])