How to run same model multiple times with different set.seed() in R?
问题 I would like to run the following model three times with a different seed. For example, the following model is run with seed 314159 set.seed(314159) x <- c(11, 5, 2, -5, 7, 2, -11, 9, -5, -5, -4, 17, 2, -10, -11, -10, -4, 2, 1, 13) a <- 0.1 b <- 0.1 c <- 0 d <- 100^2 M <- 1e3 sample <- array(NA, dim=c(M,2)) mu <- mean(x) sig2 <- var(x) for( m in 1:M ){ mu <- rnorm(1, (length(x) + 1/d)^(-1) * (sum(x) + c/d), sqrt( sig2/(length(x) + 1/d) )) sig2 <- rigamma(1, .5*length(x)+a+.5, .5*sum( (x-mu)^2