metrop_flip: Metroplis flipping to improve mixing

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Metroplis flipping to improve mixing

Usage

1
metrop_flip(x, curr_prob)

Arguments

x

current value, 0 or 1

curr_prob

current probability of being 1

Value

a binary value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
metrop_flip(1,0.2)


p = 0.3
x <- rep(NA,1000)
x[1] <- 0
for (iter in 2:1000){
  x[iter] <- metrop_flip(x[iter-1],p)
}

plot(x,type="l",main=mean(x))

zhenkewu/rewind documentation built on Sept. 9, 2020, 3:40 p.m.