The arguments of the binomial in
y[k]~dbin(p[k],n[k]);
are p[k] and n[k]. The first is p[k], which is the probability. My guess
is that sum(alfa_2[]) > m[1], which is not surprising as you're summing
over all of the alpha_2's. Does
p[k]<-sum(alfa_2[offset[k]:(offset[k+1]-1])/m[k]
help?
I'm also not sure if this is the right way of aggregating the outcome,
as it can still make p be greater than 1. But I haven't worked with that
sort of ecological modelling a lot, so it might make sense.
Bob
On 08/03/2018 01:15 PM, Andrea Araujo wrote:
> Hi all! I will really appreciate your help in my model, I am relatively new in Bugs. I am working with binomial data. My model aims to account for the ecological fallacy issue by modelling the aggregated outcome in function of individual based extracted covariates (environemntal variables). The probability p[k] is the summation over a function alfa_2[]. I used the complete expression for logistic regression (1/(1+exp(-alfa_1[]))).
>
> My model is syntactically correct, data is loaded, model is compiled but then I guess there are problems with the inits, or the model or I do not know where but I receive this error:
>
> "error for node y[1] of type GraphBinomial.Node first argument must be a proportion error pos 136"
>
> My data y is composed of 0's (cero successes) and integer numbers (successes), so I do not now why this should be a proportion. I am working with the package R2OpenBugs.
>
> Here is my model as input for bugs:
>
> model{
> #likelihood
> for(k in 1:108){
> y[k]~dbin(p[k],n[k]);
>
> for(j in offset[k]:(offset[k+1]-1)){
>
> alfa_1[j]<-beta0+beta1*ndvi[j]+beta2*ndwi[j]+beta3*lstd[j]+beta4*lstn[j]+beta5*e[j]+beta6*ndwb[j]
>
> alfa_2[j]<-1/(1+exp(-alfa_1[j]))
>
> }
> p[k]<-sum(alfa_2[])/m[k]
>
> }
>
>
> #PRIORS FOR FIXED EFFECTS BETAS
>
> beta0~dnorm(0.0,0.0001)
> beta1~dnorm(0.0,0.0001)
> beta2~dnorm(0.0,0.0001)
> beta3~dnorm(0.0,0.0001)
> beta4~dnorm(0.0,0.0001)
> beta5~dnorm(0.0,0.0001)
> beta6~dnorm(0.0,0.0001)
>
> }
>
> Here is my code in R:
>
> rm(list=ls()) # Clear the workspace
>
> library("R2OpenBUGS")
>
>
> #Open data
> #---------
>
> covariates<-read.table("C:/PhDAndrea/Objective3/Data/citylevel_dwb.txt", head=TRUE)
> data<-read.table("C:/PhDAndrea/Objective3/Data/survbarangay.txt", head=TRUE)
>
> unik<-!duplicated(covariates$IDBarangay)
> offset<-seq(covariates$IDBarangay)[unik]
> offset[109]<-369
>
> m<-data$m
>
> #Prepare the values for model inputs
> #-----------------------------------
>
> #survey info
> y<-data$y
> n<-data$n
>
> #environmental information
> ndvi<-covariates$NDVI
> ndwi<-covariates$NDWI
> lstd<-covariates$LSTD
> lstn<-covariates$LSTN
> e<-covariates$E
> ndwb<-covariates$NDWB
>
>
> #prepare the data inputs the function bug() needs
> #------------------------------------------------
>
> data.bugs<-list("y","n","ndvi","ndwi","lstd","lstn","ndwb","e","m","offset")
>
>
> #Prepare init values for the chains
> #----------------------------------
>
> #get initial parameter values from MLE
> #-------------------------------------
>
> inits<-function(){list(beta0=0,beta1=0,beta2=0,beta3=0,beta4=0,beta5=0,beta6=0)}
>
>
> parameters<-c("beta0","beta1","beta2","beta3","beta4","beta5","beta6")
>
> o.dir<-'C:/Program Files (x86)/OpenBUGS/OpenBUGS323/OpenBUGS.exe'
> Modelv4<-bugs(data.bugs,inits,parameters,"C:/PhDAndrea/Objective3/Data/Modelv4aa.txt",n.chains=1,n.iter=100,n.burnin=50,OpenBUGS.pgm=o.dir,debug=TRUE)
>
> Thank you very much.
>
> Andrea.
>
> -------------------------------------------------------------------
> This list is for BUGS users to support each other, ask questions or share ideas.
> 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
--
Bob O'Hara
Institutt for matematiske fag
NTNU
7491 Trondheim
Norway
Mobile: +47 915 54 416
Journal of Negative Results - EEB: www.jnr-eeb.org
-------------------------------------------------------------------
This list is for BUGS users to support each other, ask questions or share ideas.
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
|