Andrew
I commented before but perhaps you didn't receive it.
You have a Poisson nested inside a binomial, which simplifies to another Poisson.
If X~Poisson(L) and Y~Binomial(p,X) then Y~Poisson(L*p)
This is a more efficient formulation of the problem and avoids any issues of matches between # trials and # successes.
Regards
David Vose
-----Original Message-----
From: (The BUGS software mailing list) [mailto:[log in to unmask]] On Behalf Of MILLARD A.R.
Sent: 19 March 2015 18:15
To: [log in to unmask]
Subject: Re: [BUGS] problem fitting binomial mixture model OpenBUGS
As y[i,j,k] ~dbin(p[k],N[i,k]) this suggests something is wrong with N[3,1]. Is N[3,1]> y[3,3,1] or does it have a typo in it like l for 1 or O for 0?
Best wishes
Andrew
--
Dr. Andrew Millard
e: [log in to unmask] | t: +44 191 334 1147
w: http://www.dur.ac.uk/archaeology/staff/?id=160
Senior Lecturer in Archaeology, Durham University, UK
> -----Original Message-----
> From: Curtis Burkhalter [mailto:[log in to unmask]]
> Sent: 18 March 2015 17:59
> To: MILLARD A.R.
> Cc: [log in to unmask]
> Subject: Re: [BUGS] problem fitting binomial mixture model OpenBUGS
>
> I'm sorry to have to post again, but I've taken everyone's suggestions
> into account, but I still can't seem to get things going. I created a
> separate matrix for the missing y's, replacing the data with NA and
> the NAs with 1. I then used a reduced model structure that eliminated
> the covariate. This allowed me to get a model running using a
> simulated data set and obtain posterior estimates of the parameters,
> but when I used the actual data with the simplified model structure
> and adapted initial values, I get the original error message of 'error
> for node y[3,3,1] of type GraphBinomial.Node second argument invalid
> integer value given'. I know that the data set if formatted properly,
> so I don't think that would be the issue so right now I'm at a loss of
> how to get the model up and running. Any further suggestions??
>
>
> Thanks in advance
>
> On Tue, Mar 17, 2015 at 3:16 AM, MILLARD A.R.
> <[log in to unmask]> wrote:
>
>
> Curtis,
>
> You have missing values (NA) in your data for y, so initial values
> are needed for these. The NAs you see in the save state are for the
> parts of y where there are data, as no initial value is required for
> them. The prior for the missing values is given by the model which has
> a vague prior and so WinBUGS geninits function can quite easily
> generate extreme values.
>
> I suggest you create a separate matrix to initialise the missing
> values of y by replacing all the numbers in the data with NA and all
> the NAs with a small integer.
>
>
> Best wishes
>
> Andrew
> --
> Dr. Andrew Millard
> e: [log in to unmask] | t: +44 191 334 1147
> <tel:%2B44%20191%20334%201147>
> w: http://www.dur.ac.uk/archaeology/staff/?id=160
> Senior Lecturer in Archaeology, Durham University, UK
>
>
> > -----Original Message-----
> > From: (The BUGS software mailing list) [mailto:[log in to unmask]]
> On
> > Behalf Of Curtis Burkhalter
>
> > Sent: 16 March 2015 22:59
> > To: [log in to unmask]
> > Subject: Re: [BUGS] problem fitting binomial mixture model OpenBUGS
> >
> > Megan,
> >
> > Thanks for the suggestion, I provide initial values for everything
> I
> > think needs to be specified, but when I use the 'uninitialized
> nodes'
> > under 'Info' which shows that OpenBUGS expects initial values for
> y,
> > which is my data. When I look at 'Save State' there is are a lot of
> > NAs for the initial values of y that OpenBUGS generates for some
> > reason. I guess my question is why does OpenBUGS expect there to be
> > initial values for y (I know that y, which are repeated annual
> counts,
> > are specified as a stochastic node)?? I can't specify initial
> values
> > for data so I don't why it's expecting an initial value for y.
> >
> > Thanks
> >
> > On Mon, Mar 16, 2015 at 4:45 PM, Megan Pledger
> > <[log in to unmask]> wrote:
> >
> >
> > I haven't looked at your model closely but I would guess
> that
> > your priors are very uninformative so bugs generates an initial
> value
> > for a variable that is so large that bugs can't handle the
> > arithmetic. I find it's best to generate the initial values
> myself
> > even if they are really trivial, do a long run and click "save
> state"
> > under the "model" in the ribbon (for winbugs) to get some
> "official"
> > initial values. (If you feel you need over-dispersed initial
> values
> > than you can adjust the "save state" values.)
> >
> > cheers,
> > Megan
> > ________________________________________
> > From: (The BUGS software mailing list)
> [[log in to unmask]] on
> > behalf of Curtis Burkhalter [[log in to unmask]]
> > Sent: 17 March 2015 09:38
> > To: [log in to unmask]
> > Subject: [BUGS] problem fitting binomial mixture model
> OpenBUGS
> >
> >
> > Hello everyone,
> >
> > I'm having a problem trying to get my binomial mixture
> model to
> > update. I'm able to compile the model, but I reach a problem when I
> > load initial values. I load the initial values for my regression
> > parameters, the abundance estimates(N) and the detection
> > probability(p), but OpenBUGS states that I still have uninitialized
> > parameters so I hit the 'gen inits' button provided on the model
> > specification tab and I get the error message 'error for node
> y[3,3,1]
> > of type GraphBinomial.Node second argument invalid integer value
> > given'.
> >
> > I'm unsure of why this is happening or what to do to fix
> this
> > error so any help would be greatly appreciated. I've pasted my code
> > and the data structures below. Thank you in advance.
> >
> > model {
> >
> > #Priors
> >
> > for (k in 1:7) {
> > p[k]~dunif(0,1)
> > }
> >
> > alpha0~dunif(-10,10)
> > alpha1~dunif(-10,10)
> >
> >
> > #Likelihood
> > #Ecological model for true abundance (process model)
> > for (k in 1:7) {
> > #Loop over years
> > for (i in 1:R) {
> > #Loop over R sites
> > N[i,k]~dpois(lambda[i,k])
> > #Abundance
> > log(lambda[i,k])<-alpha0+alpha1*well[i,k]
> >
> > #Observation model for replicated counts
> > for (j in 1:T) {
> > #Loop over repeated counts
> > y[i,j,k] ~dbin(p[k],N[i,k])
> > #Detection
> >
> >
> > #Assess model fit using Chi-
> squared
> > discrepancy
> > #Compute fit statistic "E" for
> observed
> > data
> > eval[i,j,k]<-p[k]*N[i,k]
> > #Expected values
> > E[i,j,k]<-pow((y[i,j,k]-
> > eval[i,j,k]),2)/(eval[i,j,k]+0.5)
> >
> > #Generate replicate data and
> compute fit
> > stats for them
> > y.new[i,j,k]~dbin(p[k],N[i,k])
> > E.new[i,j,k]<-pow((y.new[i,j,k]-
> > eval[i,j,k]),2)/(eval[i,j,k]+0.5)
> >
> > }#j
> >
> > }#i
> >
> > }#k
> >
> > #Derived and other quantities
> >
> > #for(k in 1:7) {
> >
> > #totalN[k]<-sum(N[,k])
> > #Total pop. size across all sites
> > #mean.abundance[k]<-exp(alpha.lam[k])
> >
> > #}
> >
> >
> > fit<-sum(E[,,])
> > fit.new<-sum(E.new[,,])
> > }
> >
> > #Data
> > list(R=669,T=3)
> >
> >
> > #inits
> > list(alpha0=0.92,alpha1=-0.57)
> >
> > str(y)
> > 'data.frame': 669 obs. of 21 variables:
> > $ y..1.1.: int 8 5 0 14 21 6 4 5 18 0 ...
> > $ y..1.2.: int 23 0 0 15 32 4 8 5 35 0 ...
> > $ y..1.3.: int 14 0 0 10 30 18 19 2 19 2 ...
> > $ y..1.4.: int 8 2 5 21 32 0 6 0 21 0 ...
> > $ y..1.5.: int 9 0 23 15 20 0 0 0 19 0 ...
> > $ y..1.6.: int 0 0 0 5 1 9 10 3 19 0 ...
> > $ y..1.7.: int 6 0 0 2 18 0 10 0 11 0 ...
> > $ y..2.1.: int 20 6 0 21 30 12 15 8 5 0 ...
> > $ y..2.2.: int 21 0 0 16 34 5 0 3 NA 0 ...
> > $ y..2.3.: int 14 0 0 NA 12 23 7 0 16 0 ...
> > $ y..2.4.: int 9 0 5 18 30 4 16 5 11 0 ...
> > $ y..2.5.: int 1 0 4 24 40 2 15 4 13 0 ...
> > $ y..2.6.: int 6 0 NA 2 10 0 12 NA 11 0 ...
> > $ y..2.7.: int 17 NA 0 14 18 4 22 1 5 0 ...
> > $ y..3.1.: int 10 5 NA 7 13 10 0 0 18 2 ...
> > $ y..3.2.: int 19 NA 1 9 22 2 NA NA NA 0 ...
> > $ y..3.3.: int 12 NA 0 NA 5 8 12 0 20 0 ...
> > $ y..3.4.: int 7 1 5 16 10 2 29 8 11 0 ...
> > $ y..3.5.: int 6 0 2 21 6 0 16 8 16 0 ...
> > $ y..3.6.: int 0 0 NA NA 0 12 NA NA 12 0 ...
> > $ y..3.7.: int 17 NA 0 12 36 8 13 0 7 0 ...
> > > str(wells)
> > 'data.frame': 669 obs. of 7 variables:
> > $ well..1.: num 0 0 0 0 0 ...
> > $ well..2.: num 0 0 0 0 0 ...
> > $ well..3.: num 0 0 0 0 0 ...
> > $ well..4.: num 0 0 0 0 0 ...
> > $ well..5.: num 0 0 0 0 0 ...
> > $ well..6.: num 0 0 0 0 0 ...
> > $ well..7.: num 0 0 0 0 0 ...
> > str(initialN)
> > 'data.frame': 669 obs. of 7 variables:
> > $ N..1.: int 13 5 0 14 21 9 6 4 14 1 ...
> > $ N..2.: int 21 0 0 13 29 4 3 3 12 0 ...
> > $ N..3.: int 13 0 0 3 16 16 13 1 18 1 ...
> > $ N..4.: int 8 1 5 18 24 2 17 4 14 0 ...
> > $ N..5.: int 5 0 10 20 22 1 10 4 16 0 ...
> > $ N..6.: int 2 0 0 2 4 7 7 1 14 0 ...
> > $ N..7.: int 13 0 0 9 24 4 15 0 8 0 ...
> > > str(initialp)
> > $ p..: num 0.694 0.663 0.807 0.455 0.798 ...
> >
> >
> > ---------------------------------------------------------
> --------
> > --
> > This list is for discussion of modelling issues and the
> BUGS
> > software.
> > For help with crashes and error messages, first mail
> bugs@mrc-
> > bsu.cam.ac.uk
> > To mail the BUGS list, mail to [log in to unmask]
> > Before mailing, please check the archive at
> > www.jiscmail.ac.uk/lists/bugs.html
> > Please do not mail attachments to the list.
> > To leave the BUGS list, send LEAVE BUGS to
> > [log in to unmask]
> > If this fails, mail [log in to unmask], NOT the
> whole
> > list
> >
> >
> >
> >
> >
> > --
> >
> > Curtis Burkhalter
> >
> > https://sites.google.com/site/curtisburkhalter/
> >
> > ---------------------------------------------------------------
> ----
> > This list is for discussion of modelling issues and the BUGS
> software.
> > For help with crashes and error messages, first mail bugs@mrc-
>
> > bsu.cam.ac.uk To mail the BUGS list, mail to [log in to unmask]
>
> > Before mailing, please check the archive at
> > www.jiscmail.ac.uk/lists/bugs.html Please do not mail attachments
> to
> > the list. To leave the BUGS list, send LEAVE BUGS to
> > [log in to unmask] If this fails, mail bugs-
> > [log in to unmask], NOT the whole list
>
>
>
>
>
> --
>
> Curtis Burkhalter
>
> https://sites.google.com/site/curtisburkhalter/
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask] To mail the BUGS list, mail to [log in to unmask] Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask] If this fails, mail [log in to unmask], NOT the whole list
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|