# [R] help with winbugs glm

ilai keren at math.montana.edu
Thu Feb 23 20:19:53 CET 2012

```Adan,
How many levels does Depth have? my wild guess: 3 and your bugs model
is not identifiable.

Second, I think you may have a critical error in the way you formatted
the data for the bugs model. From your code it looks like you are just
using the factor Depth and not a design matrix of dummy variables.

I may be wrong with respect to WinBugs (I use JAGS), but if Depth is
denoted as, for e.g., "low","med","high" wouldn't your multiply
operation "...*Depth[i] " on line 5 fail ?

More likely Depth is denoted "1","2","3" and WinBugs thinks it's
numerical. Well, in that case clearly coefficients for this model
don't make any sense (you'll only need one b for the slope). You can
use model.matrix(~Depth) to get the proper format for your data.

Hope this solves it. Next time, knowing n.chains n.iter and if they
achieved convergence (with different starting values) can help sort
through these sort of issues.

Cheers

Elai

On Thu, Feb 23, 2012 at 9:57 AM, Adan Jordan-Garza
<ajordangarza2009 at my.fit.edu> wrote:
> Hi,
> I am running a model with count data and one categorical predictor (simple
> model for me to understand it fully), I did in R a glm like this:
> glm(Recruitment~Depth, family=poisson). I get the coefficientes and
> confidence intervals and all is ok. But then I want to do the same model
> with Bayesian stats, here is my code:
>
> model
> { for (i in 1:232)
> {
> Recruitment[i]~dpois(lambda[i])
> log(lambda[i])<-a+b[Depth[i]]*Depth[i]
> }
> a~dnorm(0,0.000001)
> b[1]~dnorm(0,0.000001)
> b[2]~dnorm(0,0.000001)
> b[3]~dnorm(0,0.0000001)
> }
> list(a=0, b=c(0,0,0))
>
> I have two problems: 1) the resulting credible intervals for the
> coefficients (a, b1, b2 and b3) are HUGE don t make any reasonable sense;
> 2) Using OpenBugs and Winbugs I get different results,
>
> if anyone can help me I appreciate a lot your time,
>
> thanks
>
> Guillermo
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

```