0
$\begingroup$

Suppose that among $P$ (population size) individuals in a certain social group, a police officer decides to search $S$ (sample size) of them; $H$ (number of "hits") are found to commit a crime (e.g., carrying contraband).

Under an intuitive sense of justice, the rate at which the officer checks members from this group ("check rate", $\mu$) should be equal to the observed hit rate ($\theta$). However, the officer may be biased towards oversampling or undersampling for reasons unknown (i.e., $\mu = \alpha \cdot \theta$; $\alpha > 1$ suggests oversampling whereas $\alpha < 1$ suggests undersampling).

I wrote the BUGS and R code below to infer $\theta$ (theta), $\mu$ (mu), and $\alpha$ (re-parameterized by the mean and the precision lambda) based on $P$ (pop), $S$ (samp), and $H$ (hit).

modelString = "
model{
  # priors
  theta ~ dbeta(1,1)
  mean ~ dnorm(0,.001)
  sigma ~ dunif(0,10)
  lambda <- 1/pow(sigma,2)
  alpha ~ dnorm(mean, lambda)
  # data
  samp ~ dbin(mu, pop)
  hit ~ dbin(theta, samp)
  # relationship between hit rate & sample rate
  mu <- alpha * theta
}
"
writeLines(modelString, con="bias.txt")

# model input
pop <- 100
samp <- 25
hit <- 20

data <- list("pop", "samp", "hit")

parameters <- c("theta", "mu", "mean", "sigma")

myinits <-  list(
  list(theta = 0.5, mean = 0, sigma = 1))

samples <- jags(data, inits=myinits, parameters,
                model.file ="bias.txt", n.chains=1, n.iter=10000, 
                n.burnin=1, n.thin=1, DIC=T)

Running the model above returns the error below:

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains,  : 
  Error in node samp
Node inconsistent with parents

I'm thinking this is because mu <- alpha * theta should be between 0 and 1 yet there's no such constraint in the model. I was wondering if this is actually the cause of the issue. If so, how can I build in this constraint?

Any help would be greatly appreciated!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.