Bayesian News Feeds

[super]power to X-edit

Xian's Og - Tue, 2012-02-21 18:11

Having reached 2000 reputation credits on Cross Validated, I now have the privilege to edit others’ posts:

We believe in the power of community editing. That means once you’ve generated enough reputation, we trust you to edit anything in the system without it going through the peer review system. Not just your posts—anyone’s posts!

Which I already did in the past with superusers’ supervision. Hopefully, this promotion will not induce spending even more time on the forum… And increase my stress at reading often too often questions written by people obviously too lazy to open a stat manual. (I know, I know, no one forces me to read them!)


Filed under: Kids, Statistics, University life Tagged: cross validated, editor, StackExchange, Statistics
Categories: Bayesian Bloggers

Bayesian Model Selection for Beta Autoregressive Processes

Roberto Casarin, Luciana Dalla Valle and Fabrizio Leisen
Categories: Bayesian Analysis

Mixture Modeling for Marked Poisson Processes

Matthew A. Taddy and Athanasios Kottas
Categories: Bayesian Analysis

Regularization in Regression: Comparing Bayesian and Frequentist Methods in a Poorly Informative Situation

Gilles Celeux, Mohammed El Anbari, Jean-Michel Marin and Christian P. Robert
Categories: Bayesian Analysis

Beta processes, stick-breaking, and power laws

Tamara Broderick, Michael I. Jordan and Jim Pitman
Categories: Bayesian Analysis

On the support of MacEachern's dependent Dirichlet processes and extensions

Andres F. Barrientos, Alejandro Jara and Fernando A. Quintana
Categories: Bayesian Analysis

Bayesian strategies to assess uncertainty in velocity models

Camila C. S. Caiado, Richard W. Hobbs and Michael Goldstein
Categories: Bayesian Analysis

Objective Bayesian Analysis of a Measurement Error Small Area Model

Serena Arima, Gauri S. Datta and Brunero Liseo
Categories: Bayesian Analysis

weird [lack of] control…

Xian's Og - Mon, 2012-02-20 18:12

When I ran

> test=NULL > for (i in 1:10){ + if (i%%2!=0){ + test=c(test,i) + i=i+2}} > test [1] 1 3 5 7 9

I was expecting the same output as

> test=NULL > i=1 > while (i<11){ + if (i%%2!=0){ + test=c(test,i) + i=i+2} + i=i+1} > test [1] 1 5 9

So this means that the dummy index in R “for” loops cannot be tweaked that easily. I seem to remember doing this kind of (dirty) tricks with earlier versions… Now, Alessandra and Robin think this is a good thing that the for loop is robust against this kind of non-sense, so I may be a minority in complaining about this lack of control [for me, if not for for].


Filed under: R, University life Tagged: dummy variable, for loop, loops, R
Categories: Bayesian Bloggers

Château Tayac

Xian's Og - Mon, 2012-02-20 14:20
Categories: Bayesian Bloggers

Cross validated question

Xian's Og - Sun, 2012-02-19 18:00

Another problem generated by X’validated (on which I spent much too much time!): given an unbiased coin that produced M heads in the first M tosses, what is the expected number of additional tosses needed to get N (N>M) consecutive heads?

Consider the preliminary question of getting a sequence of N heads out of k tosses, with probability 1-p(N,k). The complementary probability is given by the recurrence formula

Indeed, my reasoning is that the event of no consecutive N heads out of k tosses can be decomposed according to the first occurrence of a tail out of the first N tosses. Conditioning on whether this first tail occurs at the first, second, …, nth draw leads to this recurrence relation. As I wanted to make sure, I rand the following R code

#no sequence of length N out of k draws pnk=function(N,k){ if (k<N){ p=1} else{ p=0 for (j in 1:N) p=p+pnk(N,k-j)/2^j } return(p) }

and got the following check:

> k=15 > #N=2 > 1-pnk(2,k)-sum(apply(vale[,-1]*vale[,-k],1,max))/10^6 [1] 6.442773e-05 > #N=3 > 1-pnk(3,k)-sum(apply(vale[,-(1:2)]*vale[,-c(1,k)]*vale[,-((k-1):k)],1,max))/10^6 [1] 0.0004090137

Next, the probability of getting the first consecutive N heads in m≥ N tosses is

Both first cases are self-explanatory. the third case corresponds to a tail occurring at the m−N−1th draw, followed by N heads, and prohibiting N consecutive heads prior to the m−N−1th toss. When checking by

Tsim=10^7 S=sample(c(0,1),Tsim,rep=TRUE) SS=S[-Tsim]*S[-1] out=NULL i=2 while (i<=length(SS)){ if ((SS[i]==1)&&(SS[i-1]==1)){ out=c(out,i);i=i+1} i=i+1} dif=diff((1:length(SS[-out]))[SS[-out]==1]) trobs=probs=tabulate(dif+(dif==1))/length(dif)[1:20] for (t in 1:20) trobs[t]=qmn(2,t) barplot(probs,col="orange2",ylim=c(-max(probs),max(probs))) barplot(-trobs[1:20],col="wheat",add=TRUE)

I however get a discrepancy shown in the above graph for the cases m=3,4, and N=2, which is due to the pseudo-clever way I compute the waiting times, removing the extra 1′s… Because the probabilities to wait 3 and 4 times for 2 heads should really be both equal to 1/2³. And things agree after that.

Now, the probability to get M heads first and N heads in m≥ N tosses (and no less) is

The third case is explained by the fact that completions of the first sequence of heads must stop (by a tail) before reaching N heads. Hence the conditional probability of waiting m tosses to get N consecutive heads given the first M consecutive heads is


The expected number can then be derived by

or

for the number of *additional* steps…

Checking for the smallest values of M and N, I got a reasonable agreement with the theoretical value of 2N+1-2M+1(established on Cross validated). (For larger values of M and N, I had to replace the recursive definition of pnk with a matrix computed once for all.)


Filed under: R, Statistics, University life Tagged: conditioning, heads and tails, R, recursion
Categories: Bayesian Bloggers