Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. prob <- 0.1
  2. len_z <- 1000
  3. z <- rbinom(n = len_z, 1, prob)
  4. n <- 1000
  5.  
  6. z_mat <- matrix(nrow = n, ncol = len_z)
  7.  
  8. for(i in 1:n){
  9. for(s in 1:len_z){
  10. oldz <- z[s]
  11. newz <- rbinom(1, 1, 0.5)
  12.  
  13. alpha <- min(1, (prob^newz * (1 - prob)^(1 - newz))/(prob^oldz * (1 - prob)^(1 - oldz)))
  14.  
  15. if(rbinom(1, 1, alpha) == 1){
  16. z[s] <- newz
  17. }
  18. }
  19. z_mat[i,] <- z
  20. }
  21.  
  22. x = apply(z_mat, 1, mean)
  23. mean(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement