## Auto-generated Hui-Walter model created by runjags version 2.2.2-4 on 2024-03-10 model{ ## Observation layer: # Complete observations (N=600): for(p in PopulationsUsing){ Tally_RRR[1:8,p] ~ dmulti(prob_RRR[1:8,p], N_RRR[p]) prob_RRR[1:8,p] <- (prev[p] * se_prob[1:8,p]) + ((1-prev[p]) * sp_prob[1:8,p]) sim_RRR[1:8,p] ~ dmulti(prob_RRR[1:8,p], N_RRR[p]) check_outcome_RRR[1:8,p] <- Tally_RRR[1:8,p] - sim_RRR[1:8,p] } ## Observation probabilities: for(p in PopulationsUsing){ # Probability of observing Test1- Test2- Test3- from a true positive: se_prob[1,p] <- (1-se[1])*(1-se[2])*(1-se[3]) +covse_1_2 +covse_1_3 +covse_2_3 # Probability of observing Test1- Test2- Test3- from a true negative: sp_prob[1,p] <- sp[1]*sp[2]*sp[3] +covsp_1_2 +covsp_1_3 +covsp_2_3 # Probability of observing Test1+ Test2- Test3- from a true positive: se_prob[2,p] <- se[1]*(1-se[2])*(1-se[3]) -covse_1_2 -covse_1_3 +covse_2_3 # Probability of observing Test1+ Test2- Test3- from a true negative: sp_prob[2,p] <- (1-sp[1])*sp[2]*sp[3] -covsp_1_2 -covsp_1_3 +covsp_2_3 # Probability of observing Test1- Test2+ Test3- from a true positive: se_prob[3,p] <- (1-se[1])*se[2]*(1-se[3]) -covse_1_2 +covse_1_3 -covse_2_3 # Probability of observing Test1- Test2+ Test3- from a true negative: sp_prob[3,p] <- sp[1]*(1-sp[2])*sp[3] -covsp_1_2 +covsp_1_3 -covsp_2_3 # Probability of observing Test1+ Test2+ Test3- from a true positive: se_prob[4,p] <- se[1]*se[2]*(1-se[3]) +covse_1_2 -covse_1_3 -covse_2_3 # Probability of observing Test1+ Test2+ Test3- from a true negative: sp_prob[4,p] <- (1-sp[1])*(1-sp[2])*sp[3] +covsp_1_2 -covsp_1_3 -covsp_2_3 # Probability of observing Test1- Test2- Test3+ from a true positive: se_prob[5,p] <- (1-se[1])*(1-se[2])*se[3] +covse_1_2 -covse_1_3 -covse_2_3 # Probability of observing Test1- Test2- Test3+ from a true negative: sp_prob[5,p] <- sp[1]*sp[2]*(1-sp[3]) +covsp_1_2 -covsp_1_3 -covsp_2_3 # Probability of observing Test1+ Test2- Test3+ from a true positive: se_prob[6,p] <- se[1]*(1-se[2])*se[3] -covse_1_2 +covse_1_3 -covse_2_3 # Probability of observing Test1+ Test2- Test3+ from a true negative: sp_prob[6,p] <- (1-sp[1])*sp[2]*(1-sp[3]) -covsp_1_2 +covsp_1_3 -covsp_2_3 # Probability of observing Test1- Test2+ Test3+ from a true positive: se_prob[7,p] <- (1-se[1])*se[2]*se[3] -covse_1_2 -covse_1_3 +covse_2_3 # Probability of observing Test1- Test2+ Test3+ from a true negative: sp_prob[7,p] <- sp[1]*(1-sp[2])*(1-sp[3]) -covsp_1_2 -covsp_1_3 +covsp_2_3 # Probability of observing Test1+ Test2+ Test3+ from a true positive: se_prob[8,p] <- se[1]*se[2]*se[3] +covse_1_2 +covse_1_3 +covse_2_3 # Probability of observing Test1+ Test2+ Test3+ from a true negative: sp_prob[8,p] <- (1-sp[1])*(1-sp[2])*(1-sp[3]) +covsp_1_2 +covsp_1_3 +covsp_2_3 # Ensure that the covariance terms do not result in an invalid probability: for(c in 1:8){ AcceptProb[c,p] ~ dbern(ifelse(se_prob[c,p] >= 0 && se_prob[c,p] <= 1 && sp_prob[c,p] >= 0 && sp_prob[c,p], 1, 0)) } } ## Priors: # Prevalence in population 1: prev[1] ~ dbeta(1,1) # Prevalence in population 2: prev[2] ~ dbeta(1,1) # Prevalence in population 3: prev[3] ~ dbeta(1,1) # Sensitivity of Test1 test: se[1] ~ dbeta(1,1) # Specificity of Test1 test: sp[1] ~ dbeta(1,1) # Sensitivity of Test2 test: se[2] ~ dbeta(1,1) # Specificity of Test2 test: sp[2] ~ dbeta(1,1) # Sensitivity of Test3 test: se[3] ~ dbeta(1,1) # Specificity of Test3 test: sp[3] ~ dbeta(1,1) # Ensure that label switching does not occur for any test: for(t in 1:3){ AcceptTest[t] ~ dbern(ifelse((se[t]+sp[t]) >= 1.0, 1, 0)) } # Conditional dependence between 1 and 2 (sensitivity): # covse_1_2 ~ dunif(-1, 1) ## if the sensitivity of these tests may be correlated # covse_1_2 ~ dunif( (se[1]-1)*(1-se[2]) , min(se[1],se[2]) - se[1]*se[2]) ## alternative prior (may require setting initial values) covse_1_2 <- 0 ## if the sensitivity of these tests can be assumed to be independent # Calculated relative to the pairwise min/max: corse_1_2 <- ifelse(covse_1_2 < 0, -covse_1_2 / ((se[1]-1)*(1-se[2])), covse_1_2 / (min(se[1],se[2]) - se[1]*se[2])) # Conditional dependence between 1 and 2 (specificity): # covsp_1_2 ~ dunif(-1, 1) ## if the specificity of these tests may be correlated # covsp_1_2 ~ dunif( (sp[1]-1)*(1-sp[2]) , min(sp[1],sp[2]) - sp[1]*sp[2]) ## alternative prior (may require setting initial values) covsp_1_2 <- 0 ## if the specificity of these tests can be assumed to be independent # Calculated relative to the pairwise min/max: corsp_1_2 <- ifelse(covsp_1_2 < 0, -covsp_1_2 / ((sp[1]-1)*(1-sp[2])), covsp_1_2 / (min(sp[1],sp[2]) - sp[1]*sp[2])) # Conditional dependence between 1 and 3 (sensitivity): # covse_1_3 ~ dunif(-1, 1) ## if the sensitivity of these tests may be correlated # covse_1_3 ~ dunif( (se[1]-1)*(1-se[3]) , min(se[1],se[3]) - se[1]*se[3]) ## alternative prior (may require setting initial values) covse_1_3 <- 0 ## if the sensitivity of these tests can be assumed to be independent # Calculated relative to the pairwise min/max: corse_1_3 <- ifelse(covse_1_3 < 0, -covse_1_3 / ((se[1]-1)*(1-se[3])), covse_1_3 / (min(se[1],se[3]) - se[1]*se[3])) # Conditional dependence between 1 and 3 (specificity): # covsp_1_3 ~ dunif(-1, 1) ## if the specificity of these tests may be correlated # covsp_1_3 ~ dunif( (sp[1]-1)*(1-sp[3]) , min(sp[1],sp[3]) - sp[1]*sp[3]) ## alternative prior (may require setting initial values) covsp_1_3 <- 0 ## if the specificity of these tests can be assumed to be independent # Calculated relative to the pairwise min/max: corsp_1_3 <- ifelse(covsp_1_3 < 0, -covsp_1_3 / ((sp[1]-1)*(1-sp[3])), covsp_1_3 / (min(sp[1],sp[3]) - sp[1]*sp[3])) # Conditional dependence between 2 and 3 (sensitivity): # covse_2_3 ~ dunif(-1, 1) ## if the sensitivity of these tests may be correlated # covse_2_3 ~ dunif( (se[2]-1)*(1-se[3]) , min(se[2],se[3]) - se[2]*se[3]) ## alternative prior (may require setting initial values) covse_2_3 <- 0 ## if the sensitivity of these tests can be assumed to be independent # Calculated relative to the pairwise min/max: corse_2_3 <- ifelse(covse_2_3 < 0, -covse_2_3 / ((se[2]-1)*(1-se[3])), covse_2_3 / (min(se[2],se[3]) - se[2]*se[3])) # Conditional dependence between 2 and 3 (specificity): # covsp_2_3 ~ dunif(-1, 1) ## if the specificity of these tests may be correlated # covsp_2_3 ~ dunif( (sp[2]-1)*(1-sp[3]) , min(sp[2],sp[3]) - sp[2]*sp[3]) ## alternative prior (may require setting initial values) covsp_2_3 <- 0 ## if the specificity of these tests can be assumed to be independent # Calculated relative to the pairwise min/max: corsp_2_3 <- ifelse(covsp_2_3 < 0, -covsp_2_3 / ((sp[2]-1)*(1-sp[3])), covsp_2_3 / (min(sp[2],sp[3]) - sp[2]*sp[3])) } #monitor# se, sp, prev, covse_1_2, covse_1_3, covse_2_3, corse_1_2, corse_1_3, corse_2_3, covsp_1_2, covsp_1_3, covsp_2_3, corsp_1_2, corsp_1_3, corsp_2_3, check_outcome_RRR ## Inits: inits{ "se" <- c(0.5, 0.99, 0.5) "sp" <- c(0.99, 0.75, 0.99) "prev" <- c(0.05, 0.95, 0.05) } inits{ "se" <- c(0.99, 0.5, 0.99) "sp" <- c(0.75, 0.99, 0.75) "prev" <- c(0.95, 0.05, 0.95) } ## Data: data{ "PopulationsUsing" <- c(1, 2, 3) "AcceptTest" <- c(1, 1, 1) "AcceptProb" <- structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), .Dim = c(8, 3)) "N_RRR" <- c(200, 200, 200) "Tally_RRR" <- structure(c(135, 6, 5, 8, 8, 5, 13, 20, 97, 14, 11, 13, 11, 12, 12, 30, 46, 8, 8, 22, 12, 28, 20, 56), .Dim = c(8, 3)) }