One of the examples online is about how to write the Metropolis-Hastings algorithm from scratch. This tutorial uses a linear regression model as an example. Estimate three parameters: an intercept, a slope, and a standard deviation.
The code in that tutorial
- proposes three candidate samples (
theta_star) from proposal distribution (normal distribution),
- calculates posterior (a number):
sd_prior(all on log scale),
- calculates the acceptance probability (a number) and compares it with a random number.
- accepts all the three elements or rejects them all.
Can I use the alternative way below? Say, if I calculate the posterior respectively like
`sum(loglikelihoods)` + `b0_prior` `sum(loglikelihoods)` + `b1_prior` `sum(loglikelihoods)` + `sd_prior`
where the three
sum(loglikelihoods) above are same in value. Only calculated once, not re-calculated three times.
Then I get the posterior (3 by 1 vector), calculate acceptance probability (3 by 1 vector), and compare them with three random numbers. So the three elements are updated respectively. Not accept all or reject all.
Is this modified procedure still a valid Metropolis-Hastings algorithm? I feel my question is related with this post, but not sure the above is correct in principle and theory.