Displaying 1 result from an estimated 1 matches for "newlogalpha".
2007 Jun 01
0
Metropolis code help
...count <- length(start)
sims <- matrix(NA, nrow=R, ncol = parmcount)
colnames(sims) <- names(start)
sims[1,] <- start
oldlogalpha <- logtarget(start)
accepts <- 0
for (i in 2:R) {
jump <- rnorm(parmcount, mean=0, sd=sd)
y <- sims[i-1,] + jump
newlogalpha <- logtarget(y)
if (log(runif(1)) < newlogalpha - oldlogalpha) {
sims[i,] <- y
oldlogalpha <- newlogalpha
accepts <- accepts + 1
} else {
sims[i,] <- sims[i-1,]
}
}
cat('Accepted ',100*accepts/(R-1),'%\n')
sims
}
# Use the binomi...