# Perform a drop-1 validation study for a simple model:
themodel <- "model{
for(i in 1:N){
Y[i] ~ dnorm(true.y[i], precision)
true.y[i] <- (m * X[i]) + c
}
m ~ dunif(-1000,1000)
c ~ dunif(-1000,1000)
precision ~ dexp(1)
#data# N, X
#inits# m, c, precision, .RNG.seed, .RNG.name
}"
# Simulate the data
set.seed(1)
N <- 20
X <- 1:N
Y <- rnorm(length(X), 2*X + 1, 1)
# Some initial values to use for 2 chains:
m <- list(-10,10)
c <- list(10,-10)
precision <- list(0.01,100)
.RNG.seed <- function(chain){
return(switch(chain, "1"= 1, "2"= 2))
}
.RNG.name <- function(chain){
return(switch(chain, "1"= "base::Super-Duper", "2"= "base::Wichmann-Hill"))
}
# A simple function that removes (over-writes with NA) one datapoint at a time:
datafun <- function(s){
simdata <- Y
simdata[s] <- NA
return(list(Y=simdata))
}
# Set up a cluster to use with the parLapply method:
library(parallel)
cl <- makeCluster(20)
# Call the 20 simulations over the snow cluster:
results <- run.jags.study(simulations=20, model=themodel, datafunction=datafun,
targets=list(Y=Y, m=2, c=1), runjags.options=list(n.chains=2), cl=cl)
# Examine the results:
resultsRun the code above in your browser using DataLab