0

I want to define a distribution in my model of the form: P(x=10)=0.10, P(x=15)=0.20, P(x=20)=0.70

The WinBUGS FAQ says it is possible construct my own discrete uniform distribution as a categorical variable with a uniform prior and which can take on the necessary integer values. See the blockerht example in the first part of the manual.

I looked the example up, I think it is this one: "A hierarchical t-distribution with unknown degrees of freedom"

At the model specification they do something like:

for (n in 1:Nbins) {
   prior[n] <- 1/Nbins;   # Uniform prior on v
}
 k ~ dcat(prior[]);

Which does define a discrete uniform. But I don't know how to get to the form I need. Can anyone help me?

JEquihua
  • 1,217
  • 3
  • 20
  • 40
  • you should define what you mean with "stepwise uniform distribution". Without this, it is a bad question which we cannot answer. Downvoting your question till you fix it. – Tomas Jun 09 '13 at 09:53

2 Answers2

3

If I understand your question correctly, you do not need the loop...

#BUGS script to obtain distribution
m1<-"model{
  ind ~ dcat(p[])
  pmix <- x[ind]
}"
writeLines(m1,"m1.txt")

#simulate from the distribution    
library("R2OpenBUGS")
m1.bug<-bugs(data = list(x=c(10, 15, 20), p=c(0.1,0.2,0.7)),
             inits = NULL,
             param = "pmix",
             model = "m1.txt", 
             n.iter = 1100, n.burnin = 100, n.chains = 1, n.thin=1, DIC=FALSE)

hist(m1.bug$sims.list$pmix)

should work...

enter image description here

guyabel
  • 8,014
  • 6
  • 57
  • 86
  • I would inface like to sample from this custom uniform distribution. How would I come around to doing this? Is that how you built this histogram? – JEquihua Mar 22 '13 at 17:09
  • @JEquihua, he already sampled from the distribution he shows by defining `pmix <- x[ind]`. `pmix` is the variable which histogram are you looking at. It gives you 10, 15, or 20 based on the probabilities you defined. But be careful with the terms you use; this is not [uniform distribution](http://en.wikipedia.org/wiki/Uniform_distribution)! This one is discrete, while uniform distribution is continuous. – Tomas Jun 09 '13 at 09:51
1

I am learning how to do this myself. I wonder if you can do this:

prior[10] <- .1
prior[15] <- .2
prior[20] <- .7
x ~ dcat(prior[])