0

I need to calculate the mean of each state. In R, I did this by using

tapply(y,state,mean).

Here is an example:

state <- rbinom(10,4,0.6)
y <- rnorm(10)
tapply(y,x,mean)

where y represent the vector of the fitted values and state represent the dependent variable which is a factor.

I am wondering how I could do this in Winbugs. Any one any idea on that?

Günal
  • 751
  • 1
  • 14
  • 29
  • Could you provide a reproducible example? – Paul Hiemstra Jan 12 '13 at 17:58
  • @Paul, I have added an example to the question. – Günal Jan 12 '13 at 18:10
  • I think you're just going to have to do this by brute force with `for` loops ... – Ben Bolker Jan 12 '13 at 18:31
  • you should add an example of what you are trying to do in the WinBUGS model. If it is an operation on input data, do it in R before passing the data to WinBUGS. If this cannot be done, I smell something dirty :-) – Tomas Jan 12 '13 at 18:32
  • @Ben, exactly, but only if he actually knows what he's doing.. – Tomas Jan 12 '13 at 18:33
  • Here is what I want to do. I calculated fitted values by running winbugs from R. There are states corresponding to the fitted values and there are more than one fitted value for each state. For example the state labeled 11123 correspond to the fitted values 0.4,0.3,0.7,0.8. I need to calculate the mean of these fitted values in winbugs. I can calculate them after using the out in R, (`tapply(out$mean$y,state,mean)`),but cannot use them to produce plots in winbugs, which is the main point. – Günal Jan 12 '13 at 18:54
  • Don't produce the plots in winbugs, produce them in R! – Tomas Jan 15 '13 at 19:46
  • @Tomas, you are definitely right. Winbugs sucks at plots – Günal Jan 16 '13 at 08:35

0 Answers0