0
$\begingroup$

I want to perform a posterior predictive check on some simple logistic regression models that I fitted in JAGS. I found a function in the R package jagsUI called pp.check (see doc here: (pp.check function) with an example that will calculate the Bayesian P value from the sum of residuals of the actual data and simulated data. The example is for a linear regression, so I am trying to extend it to my logistic regression model. Below I have my code that I am trying, but am not sure I'm calculating the sum of residuals correctly? Could someone please check it?

    # Logistic regression:
logistic_model <- "model{

   # Likelihood

   for(i in 1:n){
    Y[i] ~ dbin(q[i], 1)
    logit(q[i]) <- beta[1] + beta[2]*X[i,1] + beta[3]*X[i,2] + 
                   beta[4]*X[i,3] + beta[5]*X[i,4] + beta[6]*X[i,5]

#calculate the residuals
    res[i] <- Y[i] - q[i]  
    emp.new[i] ~ dbin(q[i], 1)
    res.new[i] <- emp.new[i] - q[i]
   }

   #Priors

   for(j in 1:6){
    beta[j] ~ dnorm(0,0.1)
   }
    #Derived parameters
    fit <- sum(regression_residual[])
    fit.new <- sum(res.new[])
  }"

If fit and fit.new are valid, can I then use pp.check as described in the function's documentation example?

$\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.