title: Product of likelihood too small - R only gives 0
body: <p>I am trying to compute this posterior distribution in R. The problem is that the numerator, which is the product of a bunch of dbern(p_i, y_i) &lt; 1, is too small. (My n is about 1500). Hence, R spits out 0, and the posterior values for all \theta are also 0.</p>
  
  <p>To clarify, each y_i has its own p_i, together these p_i's make a vector of n elements for n y's. Each theta has its own n-element vector of p_i.</p>
  
  <p><img src="https://i.stack.imgur.com/fmEY6.png" alt="enter image description here"></p>
  
  <p>A reproducible example (of the numerator)</p>
  
  <pre><code>p &lt;- sample(seq(0.001,0.999,by=0.01), 1500, replace=T)
  y &lt;- sample(c(0,1), 1500, replace=T)
  dbern(y, p) # 1500-element vector, each element &lt; 1
  prod(dbern(y, p)) # produces 0
  exp(sum(log(dbern(y, p)))) # produces 0
  </code></pre>
  
  <p>EDIT (context): I am doing a Bayesian change point analysis (jstor.org/stable/25791783 - Western and Kleykamp 2004). Unlike the continuous y in the paper, my y is binary, so I'm using the data augmentation method in Albert and Chib (1993). With that method, the likelihood of y is Bernoulli, with p = cdf-normal(x'B). </p>
  
  <p>So how does p depends on theta? It's because theta is the change point. One of the x's is a time dummy -- if theta=10, for example, then the time dummy = 1 for all observations after day 10, and = 0 for all observations before day 10.</p>
  
  <p>Thus, p depends on x, x depends on theta -- thus, p depends on theta.</p>
  
  <p>I need the above quantity because is the full conditional of theta in Gibbs sampling.</p>