3
$\begingroup$

The problem involves trying to characterize the probability:

P.f = Pd*Pr{t1 < t2}

using jags or WinBUGS. The issue is the last term where both t1 and t2 are random variables. A sample, stripped down, model using this is given below and hopefully provides insight into what I am trying to do. As expected, I get an error indicating that I am redefining the variable 'y'. Searching for a trick to get past this is proving difficult.

Any insight would be appreciated!

FWIW, I've also posted a similar question on the WinBUGS list, but cross-posted here with the hope of reaching a wider audience.


model {         
    for(j in 1:N) {
        t.1[j] ~ dweib(alpha.1,lambda.1) 
        t.2[j] ~ dweib(alpha.2, lambda.2);
        p.det[j] ~ dbeta(a,b);
        y[j] <- step(t.2[j]-t.1[j]);            
        y[j] ~ dbern(py);
    }   
    alpha.1 ~ dgamma(0.3,0.0001); 
    lambda.1 ~ dnorm(0., 10000.);
    alpha.2 ~ dgamma(0.3,0.0001); 
    lambda.2 ~ dnorm(0., 10000.);   
    py ~ dbeta(0.3,0.3);
    a ~ dgamma(1, 0.01) 
    b ~ dgamma(1, 0.01) 
    pd ~ dbeta(a,b) 
    p.f<- pd*py
}
$\endgroup$
3
  • $\begingroup$ 1) What is your data? p.det? If so, why do you even need to include y[j] in the code? 2) You appear to just be estimating $a$ and $b$, then generating a random number from a $\beta(a,b)$ distribution, and multiplying that by a random number drawn from a $\beta(0.3,0.3)$ distribution... is this right? $\endgroup$
    – jbowman
    Commented Dec 22, 2011 at 21:01
  • $\begingroup$ @ jbowman: I may have over simplified the original problem in the example and was little too sloppy on the prior definitions. The data available are t.1, t.2, and p.det. The intent is to estimate py = Pr{t.1 < t.2 }. Data looks like: "t.1" <- c(10,5, 20, 40) "t.2" <- c(3,6,15,70) "p.det" <- c(0.1,0.2,0.3) $\endgroup$
    – Aengus
    Commented Dec 22, 2011 at 21:21
  • $\begingroup$ @whuber - thanks! I couldn't get the formatting to work and it seemed to delete the code completely. $\endgroup$
    – Aengus
    Commented Dec 22, 2011 at 23:29

1 Answer 1

3
$\begingroup$

In JAGS, you can't reuse, in your case, y[j] as you sometimes can in WinBUGS. Instead, you create "new" data out of the data that you pass to JAGS in a data block at the top of the code (i.e., before the model step):

data {
  for (j in 1:N) {
    y[j] <- step(t.2[j] - t.1[j]) 
  }
}

You can then use y[j] on the left hand side of distributions in the model step:

model {
  for (j in 1:N) {
    ...
    y[j] ~ dbern(py)
    ...
  }
}

This can't be done in WinBUGS, however, as there's no data block; instead, you should just pass a precalculated variable y to WinBUGS.

$\endgroup$
2
  • $\begingroup$ Very cool! I vaguely recall this type of thing being mentioned with data blocks, but I always thought the data block concept was a bit of a nuisance. No more! Thanks much. $\endgroup$
    – Aengus
    Commented Dec 22, 2011 at 23:34
  • $\begingroup$ For reference, this type of issue is specifically mentioned in section 7.0.4 in the JAGS 3.0 User Manual. $\endgroup$
    – Aengus
    Commented Dec 22, 2011 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.