Logistic regression when the response is proportional (using JAGS)

I am trying to find a logistic regression model in JAGS, but I have data in the form (# success y, # attempts n), and not a binary variable. In R, you can map the model to such data using glm (y / n ~) with the "weight" argument, but I don't know how to do this in JAGS.

Here is a simple example that, I hope, addresses what I'm trying to ask. Please note that I am using the rjags package. Thanks for any help!

y <- rbinom(10, 500, 0.2) n <- sample(500:600, 10) p <- y/n x <- sample(0:100, 10) # some covariate data <- data.frame(y, n, p, x) model <- "model{ # Specify likelihood for(i in 1:10){ y[i] ~ dbin(p[i], n[i]) logit(p[i]) <- b0 + b1*x } # Specify priors b0 ~ dnorm(0, 0.0001) b1 ~ dnorm(0, 0.0001) }" 
+8
r logistic-regression jags
source share
1 answer

You do not need to compute p in your dataset at all. Just let it be a logical node in your model. I prefer the R2jags interface, which allows you to specify the BUGS model as an R function ...

 jagsdata <- data.frame(y=rbinom(10, 500, 0.2), n=sample(500:600, 10), x=sample(0:100, 10)) model <- function() { ## Specify likelihood for(i in 1:10){ y[i] ~ dbin(p[i], n[i]) logit(p[i]) <- b0 + b1*x[i] } ## Specify priors b0 ~ dnorm(0, 0.0001) b1 ~ dnorm(0, 0.0001) } 

Now run it:

 library("R2jags") jags(model.file=model,data=jagsdata, parameters.to.save=c("b0","b1")) 
+8
source share

All Articles