set.seed(2023)
m <- 10000
x <- c()
for(i in 1:m){
v <- runif(1) # proposal
# rejection step
u <- runif(1)
if(u <= dbeta(v, alpha, beta) / (3 * dunif(v))){
x <- c(x, v)
}
}
hist(x, freq = FALSE, xlim = c(0,1))
curve(dbeta(x, alpha, beta), col = "red", lwd = 2, add = TRUE)
text(0.1, 2, substitute("accept. rate" == a,
list(a = round(length(x)/m, 2))))