How to pass control to previous iteration in for loop in R -


i running loop in r (as part of power analysis model ran r2jags). @ point want know if mcmc chains have converged, if not want skip iteration of loop. however, don't want skip next iteration, want loop start same iteration again. using command 'next', skipping iteration. how tell loop iteration? below whole code, little bit worried about:

  if(up1 > 1.1 | up2 > 1.1 | up3 > 1.1 | up4 > 1.1)    next  

and whole code:

g.vec <- rep(na, 1000) #-----model------  model1 <- function(){      # likelihood   (c in 1:16){     d.diff[c] ~ dnorm(mu, tau)   }    # priors   mu ~ dnorm(0, 10)   tau <- 1/(sd*sd)   sd ~ dunif(0, 10) }  #---- loop--------  (i in 1:1000){   #--- data simulation --------- # paired data sim_bf <- rtnorm(16, mean = 0.4949, sd = 0.12, lower = 0.1) sim_af <- rtnorm(16, mean = 0.3959, sd = 0.12, lower = 0.1) diff = sim_bf - sim_af   #------setting jags--------------  data <- list(d.diff = diff) params <- c("mu", "tau", "sd") inits <- function(){   list(mu = rnorm(1),        sd = rlnorm(1))  }  #-------run jags----------------  output <- jags(data=data,                 # inits=inits,                 parameters.to.save=params,                n.iter=1000,                 n.burn=100,                 n.chains=2,                 n.thin=1,                model.file=model1,                progress.bar = "gui")  #-------convergence checker---------------- output.mcmc <- as.mcmc(output) x <- gelman.diag(output.mcmc) up1 <- x$psrf[1,2]        # approximate convergence diagnosed when upper limit close 1 up2 <- x$psrf[2,2]  up3 <- x$psrf[3,2]  up4 <- x$psrf[4,2]      if(up1 > 1.1 | up2 > 1.1 | up3 > 1.1 | up4 > 1.1)    next                   # 1 sided t-test   lo = output$bugsoutput$summary[2,4]   g.vec[i] <- ifelse((lo < 0), 0, 1) }  <- table(g.vec) g <- a[2]/1000 g 

instead of

for(i in 1:1000){...     ...     if(...         next 

do

i <- 0 while(i <=1000){...     <- i+1     ...     if(...         <- i-1         break 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -