text: [un]solved riddles
  
  Posted in Books, Kids, R with tags , , on July 4, 2017 by xi'an
  
  On the Riddler of last week, first a birthday puzzle:
  
  Given a group of 23 persons, what is the probability of observing three pairs of identical birthdays?
  
  which can be found by a quick simulation as
  
  ave=0
  for (t in 1:1e6){
  dupz=dates[duplicated(sample(1:365,23,rep=TRUE))]
  ave=ave+as.integer((length(dupz)==3)&
  (length(unique(dupz))==3))}}
  ave/M
  
  
  returning a value of 0.0183, but which combinatoric resolution I could not fully fathom without a little help from a friend (-ly blog). I had the multinomial coefficient
  
  ${23\choose 2\ 2\ 2}$
  
  for the allocation of the 23 persons to one of the three pairs or none, as well as the probability
  
  $\dfrac{365\times\cdots\times(365-(23-4)+1)}{365^{23}}$
  
  but I had forgotten the 3! in the denominator for the permutations of the three pairs, which leads again to
  
  ${23 \choose 2\ 2\ 2}\dfrac{365\times\cdots\times(365-(23-4)+1)}{3!\times365^{23}} = 0.0183$
  
  A question that also led to an unsolved question: in the even this probability was much smaller, what is an easy way into constructing a more efficient importance sampler?
  
  The second riddle was just as easy to code in R:
  
  A game of tag goes by the following rules: (i) anyone untagged can tag anyone untagged; (ii) anyone tagged by a player tagged gets untagged; (iii) the winner is the last untagged player. What is the expected number of runs for N players?
  
  The outcome of
  
  game=function(N=12){
  a=rep(0,N);T=0
  while (sum(a==0)>1){
  ij=sample((1:N)[a==0],2)
  a[ij[2]]=ij[1];a[a==ij[2]]=0
  T=T+1}
  return(T)}
  
  
  leads to an average value of
  
  $2^{N-1}-1$
  
  but I had no clear quick explanation for the doubling phenomenon. Until I picked a pen and a sheet of paper and drew the last steps of the game: to decrease down to 1, the size of the untagged survivors has to get through …,3,2 and each time the eliminated player needs to have tagged no other player since otherwise the population grows again. This has to apply all the way to the second round, where N-1 players remain and the one tagged needs to be anyone but the one who tagged the first one. And so on…
  
  sampling by exhaustion
  
  Posted in Books, Kids, R, Statistics with tags , , , , on November 25, 2016 by xi'an
  
  The riddle set by The Riddler of last week sums up as follows:
  
  Within a population of size N, each individual in the population independently selects another individual. All individuals selected at least once are removed and the process iterates until one or zero individual is left. What is the probability that there is zero individual left?
  
  While I cannot see a clean analytical solution to this problem, it reminds me of an enveloppe-versus-letter (matches) problem I saw in graduate school. Indeed, the expected number of removed (or selected) individuals is given by
  
  $N\left\{1-\frac{N-2}{N-1}\right\}^{N-1}$
  
  which is equivalent to (1-e⁻¹)N for N large, meaning that the population decreases by an average factor of e⁻¹ at each round. And that it takes on average approximately log(N) iterations to reach a single individual. A simulation of the first probabilities of ending with one individual led me to the above curve, which wiggles in an almost periodic way around the probability ½, equal to the average of those probabilities. Using the R code
  
  rad=function(N){#next population size
  ut=sample(rep(2:N,2),1)
  for (i in 2:N)#sampling
  ut=c(ut,sample(rep((1:N)[-i],2),1))
  return(N-length(unique(ut))}
  sal=rep(0,m);sal[1]=1
  for (N in 3:M){
  prop=0;
  for (t in 1:T){#one single step
  if (i>0) prop=prop+sal[i]}
  sal[N]=prop/T}
  
  
  which exploits the previously computed probabilities. The variability is most interesting if unexpected, but looking back at Feller‘s sections and exercises on the classical occupancy problem, I could not find a connection with this problem. If it exists. Still, if N is large enough, the exclusion of one index from the selection becomes negligible and the probability of moving from n to m individuals should be approximately [Feller, eqn (2.4), p.102]
  
  $p_n(m)={n\choose m}\sum_{v=}^{n-m} (-1)^v {n-m\choose v} \left(1-\frac{m+v}{n}\right)^n$
  
  This formula approximates quite well the exact probability, but as in a previous post about the birthday problem, it proves quite delicate to compute. As already noticed by Feller.
  
  a closed-form but intractable birthday
  
  Posted in Books, Kids, pictures, Statistics with tags , , , , , on November 7, 2016 by xi'an
  
  An interesting [at least for me!] question found on X Validated yesterday, namely how to simulate efficiently from the generalised birthday problem (or paradox) distribution, which provides the probability of finding exactly k different birthday dates as
  
  $\mathbb{P}(V = k) = \binom{n}{k}\displaystyle\sum_{i=0}^k (-1)^i \binom{k}{i} \left(\frac{k-i}{n}\right)^m$
  
  where m is the number of individuals with a random birthday and n the number of days (e.g., n=365). The paradox with this closed-form formula (found by the inclusion-exclusion rule) is that it is too unstable to use per se. While it is always possible to run m draws from a uniform over {1,…,n} and count the number of different values, e.g.,
  
  x=length(unique(sample(1:n,m,rep=TRUE)))
  
  
  this takes much more time than using the exact distribution, if available:
  
  sample(1:m,1e6,rep=TRUE,prob=eff[-1])
  
  
  I played a little bit with the notion of using an unbiased estimator of the said probability, but the alternating series means that the unbiased estimator may end up being negative, which is an issue met in recent related papers like the famous Russian Roulette.
  
  contemporary issues in hypothesis testing
  
  Posted in Statistics with tags , , , , , , , , , , , , , , , , , , on September 26, 2016 by xi'an
  
  This week [at Warwick], among other things, I attended the CRiSM workshop on hypothesis testing, giving the same talk as at ISBA last June. There was a most interesting and unusual talk by Nick Chater (from Warwick) about the psychological aspects of hypothesis testing, namely about the unnatural features of an hypothesis in everyday life, i.e., how far this formalism stands from human psychological functioning.  Or what we know about it. And then my Warwick colleague Tom Nichols explained how his recent work on permutation tests for fMRIs, published in PNAS, testing hypotheses on what should be null if real data and getting a high rate of false positives, got the medical imaging community all up in arms due to over-simplified reports in the media questioning the validity of 15 years of research on fMRI and the related 40,000 papers! For instance, some of the headings questioned the entire research in the area. Or transformed a software bug missing the boundary effects into a major flaw.  (See this podcast on Not So Standard Deviations for a thoughtful discussion on the issue.) One conclusion of this story is to be wary of assertions when submitting a hot story to journals with a substantial non-scientific readership! The afternoon talks were equally exciting, with Andrew explaining to us live from New York why he hates hypothesis testing and prefers model building. With the birthday model as an example. And David Draper gave an encompassing talk about the distinctions between inference and decision, proposing a Jaynes information criterion and illustrating it on Mendel‘s historical [and massaged!] pea dataset. The next morning, Jim Berger gave an overview on the frequentist properties of the Bayes factor, with in particular a novel [to me] upper bound on the Bayes factor associated with a p-value (Sellke, Bayarri and Berger, 2001)
  
  B¹⁰(p) ≤ 1/-e p log p
  
  with the specificity that B¹⁰(p) is not testing the original hypothesis [problem] but a substitute where the null is the hypothesis that p is uniformly distributed, versus a non-parametric alternative that p is more concentrated near zero. This reminded me of our PNAS paper on the impact of summary statistics upon Bayes factors. And of some forgotten reference studying Bayesian inference based solely on the p-value… It is too bad I had to rush back to Paris, as this made me miss the last talks of this fantastic workshop centred on maybe the most important aspect of statistics!
  
  Unusual timing shows how random mass murder can be (or even less)
  
  Posted in Books, R, Statistics, Travel with tags , , , , , , , , on November 29, 2013 by xi'an
  
  This post follows the original one on the headline of the USA Today I read during my flight to Toronto last month. I remind you that the unusual pattern was about observing four U.S. mass murders happening within four days, “for the first time in at least seven years”. Which means that the difference between the four dates is at most 3, not 4!
  
  I asked my friend Anirban Das Gupta from Purdue University are the exact value of this probability and the first thing he pointed out was that I used a different meaning of “within 4”. He then went into an elaborate calculation to find an upper bound on this probability, upper bound that was way above my Monte Carlo approximation and my rough calculation of last post. I rechecked my R code and found it was not achieving the right approximation since one date was within 3 days of three other days, at least… I thus rewrote the following R code
  
  T=10^6
  four=rep(0,T)
  for (t in 1:T){
  day=sort(sample(1:365,30,rep=TRUE)) #30 random days
  day=c(day,day[day>363]-365) #account for toric difference
  tem=outer(day,day,"-")
  four[t]=(max(apply(((tem>-1)&(tem<4)),1,sum)>3))
  }
  mean(four)
  
  
  [checked it was ok for two dates within 1 day, resulting in the birthday problem probability] and found 0.070214, which is much larger than the earlier value and shows it takes an average 14 years for the “unlikely” event to happen! And the chances that it happens within seven years is 40%.
  
  Another coincidence relates to this evaluation, namely the fact that two elderly couples in France committed couple suicide within three days, last week. I however could not find the figures for the number of couple suicides per year. Maybe because it is extremely rare. Or undetected…
  
  Unusual timing shows how random mass murder can be (or not)
  
  Posted in Books, R, Statistics, Travel with tags , , , , , , , , on November 4, 2013 by xi'an
  
  This was one headline in the USA Today I picked from the hotel lobby on my way to Pittsburgh airport and then Toronto this morning. The unusual pattern was about observing four U.S. mass murders happening within four days, “for the first time in at least seven years”. The article did not explain why this was unusual. And reported one mass murder expert’s opinion instead of a statistician’s…
  
  Now, there are about 30 mass murders in the U.S. each year (!), so the probability of finding at least four of those 30 events within 4 days of one another should be related to von Mises‘ birthday problem. For instance, Abramson and Moser derived in 1970 that the probability that at least two people (among n) have birthday within k days of one another (for an m days year) is
  
  $p(n,k,m) = 1 - \dfrac{(m-nk-1)!}{m^{n-1}(m-nk-n)!}$
  
  but I did not find an extension to the case of the four (to borrow from Conan Doyle!)… A quick approximation would be to turn the problem into a birthday problem with 364/4=91 days and count the probability that four share the same birthday
  
  ${30 \choose 4} \frac{90^{26}}{91^{29}}=0.0273$
  
  which is surprisingly large. So I checked with a R code in the plane:
  
  T=10^5
  four=rep(0,T)
  for (t in 1:T){
  day=sample(1:365,30,rep=TRUE)
  four[t]=(max(apply((abs(outer(day,day,"-"))<4),1,sum))>4)}
  mean(four)
  
  
  and found 0.0278, which means the above approximation is far from terrible! I think it may actually be “exact” in the sense that observing exactly four murders within four days of one another is given by this probability. The cases of five, six, &tc. murders are omitted but they are also highly negligible. And from this number, we can see that there is a 18% probability that the case of the four occurs within seven years. Not so unlikely, then.
metadata: {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 9, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}