Question
Describe the steps of metropolis hasting drawing a sample from beta (1.5, 5) distribution with a normal jumping distribution with standard deviation of 2. Got
Describe the steps of "metropolis hasting" drawing a sample from beta (1.5, 5) distribution with a normal jumping distribution with standard deviation of 2.
Got some wrror in accept.prob? How can Solve it?
mh.gamma <- function(n.sims, start, burnin, cand.sd, shape1, rate) {
theta.cur <- start
draws <- c()
theta.update <- function(theta.cur, shape, rate) {
theta.can <- rnorm(1, mean = theta.cur, sd = cand.sd)
accept.prob <- dbeta(theta.can, shape = shape, rate = rate)/dbeta(theta.cur,
shape = shape, rate = rate)
if (runif(1) <= accept.prob)
theta.can
else theta.cur
}
for (i in 1:n.sims) {
draws[i] <- theta.cur <- theta.update(theta.cur, shape = shape,
rate = rate)
}
return(draws[(burnin + 1):n.sims])
}
mh.draws<- mh.gamma (10000, start=1, burn=1000, cand.sd = 2, shape = 1.5, rate = 5)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started