Hi, I'm currently working on the below codes however whenever I run it in
openbugs it gives an error message saying: unknown type of logical function
error pos 76.  Any help would be appreciated. 

## bugs code
library(R2OpenBUGS)
sink("C:/Users/CCF/Documents/Suzie Work/PTY Project/Waterhole
Correction/ungulate.txt")
cat("
model{

# hyperparameters
# habitat effects for each functional group
g <- length(table(G))
for(i in 1:g){  # number of functional group
for(j in 1:3){  # number of habitat type
        mu.h[i,j] ~ dnorm(0,0.0001) I(-5,5)
        sigma.h[i,j] ~ dunif(0,5)
        tau.h[i,j] <- 1/(sigma.h[i,j]*sigma.h[i,j])
        }
        }

# detectability
mu.r ~ dnorm(0,0.0001) I(-5,5)
sigma.r ~ dunif(0,5)
tau.r <- 1/(sigma.r*sigma.r)

psi ~ dunif(0,1)        # inclusion rate that generates wi

# proportion of number of species among groups
for(i in 1:g){
        prop[i] ~ dgamma(1,1)
        prob[i] <- prop[i]/sum(prop[])
        }

for(i in 1:(S+m)){
        r[i] ~ dnorm(mu.r,tau.r) I(-5,5)                # generating parameters 
related to
detectability
        p[i] <- 1/(1+exp(-(r[i])))              # individual-level detection 
probability
        w[i] ~ dbern(psi)                               # indicator variable 
whether each species is exposed
to sampling or not
        G[i] ~ dcat(prob[1:g])                  # group identity
for(h in 1:3){  # habitat effects
        habitat.eff[i,h] ~ dnorm(mu.h[G[i],h],tau.h[G[i],h]) I(-5,5)
        }
for(j in 1:20){ # fitting process
        # ecological process model
        lambda[i,j] <-  exp(habitat.eff[i,habitat[j]])
        Z[i,j] ~ dpois(lambda[i,j])     # latent abundance of each species at 
each site
at each visit
        A[i,j] <- Z[i,j]*w[i]           # latent abundance only for species 
exposed to
sampling
for(v in 1:7){
        # detection process model
        AY[i,j,v] ~ dbin(p[i],A[i,j])
        }
        }
# group identity (indicator variable)
G1[i] <- equals(G[i],1)
G2[i] <- equals(G[i],2)
        }

for(i in 1:(S+m)){
for(j in 1:20){
        A1[i,j] <- A[i,j]*G1[i]
        A2[i,j] <- A[i,j]*G2[i]
        O[i,j] <- step(A[i,j]-1)                # latent occupancy of each 
species for each site
        O1[i,j] <- O[i,j]*G1[i]
        O2[i,j] <- O[i,j]*G2[i]
        }
        }

for(j in 1:20){
        AB0[j] <- sum(A[,j])
        AB1[j] <- sum(A1[,j])
        AB2[j] <- sum(A2[,j])
        SpR0[j] <- sum(O[,j])
        SpR1[j] <- sum(O1[,j])
        SpR2[j] <- sum(O2[,j])
        }

for(i in 1:3){
for(j in 1:7){
        HabAB0[i,j] <- AB0[hab[i,j]]
        HabAB1[i,j] <- AB1[hab[i,j]]
        HabAB2[i,j] <- AB2[hab[i,j]]
        HabSpR0[i,j] <- SpR0[hab[i,j]]
        HabSpR1[i,j] <- SpR1[hab[i,j]]
        HabSpR2[i,j] <- SpR2[hab[i,j]]
        }
        HAB0[i] <- mean(HabAB0[i,])
        HAB1[i] <- mean(HabAB1[i,])
        HAB2[i] <- mean(HabAB2[i,])
        HSpR0[i] <- mean(HabSpR0[i,])
        HSpR1[i] <- mean(HabSpR1[i,])
        HSpR2[i] <- mean(HabSpR2[i,])
        }

R <- sum(w[1:(S+m)])    # estimating unknown number of species that occupy any
sites

}
",fill=TRUE)
sink()

data <- list("m","S",
        "habitat",
        "G","g",
#       "date",
        "hab",
        "AY")
g <- length(table(G))   
inits <- function()list(
        mu.h=matrix(rnorm(6),nrow=2),sigma.h=matrix(runif(6),nrow=2),
        mu.r=rnorm(1),sigma.r=runif(1),
        r=rnorm(S+m),
        prop=runif(n=g,min=0,max=7),
        Z=array(rpois(n=(S+m)*20,lambda=20),dim=c((S+m),20)),
        w=rep(1,(S+m)),psi=runif(1))
parameters <- c(
        "mu.h","sigma.h",
        "habitat.eff",
        "mu.r","sigma.r",
        "r",
        "R","psi",
        "A",
        "O",
        "HAB0","HAB1","HAB2",
        "HSpR0","HSpR1","HSpR2"
        )

out <- bugs (data, inits, parameters,
model.file="C:/Users/CCF/Documents/Suzie Work/PTY Project/Waterhole
Correction/ungulate.txt",
OpenBUGS.pgm="C:/Users/CCF/Desktop/OpenBUGS/OpenBUGS321/OpenBUGS.exe",
n.thin=10, n.burnin=100, n.chains=3,n.iter=1000, debug=TRUE)

--
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-R2-OpenBUGs-tp4636412.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to