metropolis_step: Metropolis Step

Description Usage Arguments Value Examples

View source: R/samplers.R

Description

Helper function for MCMC-based samplers.Calculates a proposed move from the current position and decides whether the chain should move there based on a Metropolis-Hastings acceptance rule.

Usage

1
metropolis_step(current_x, pdf, proposal_f, beta = 1)

Arguments

current_x

vector. Current position of the chain

pdf

Probability density function of the target distribution

proposal_f

Function from which to draw proposals, given a mean

beta

Temperature of the chain. Acceptance of the proposed state becomes more likely as beta approaches 0.

Value

List with the position for the next step of the chain and a boolean representing whether the proposal has been accepted or not

Examples

1
2
3
4
5
6
# This function is used internally in MCMC based samplers

pdf_function <- function(x){mvtnorm::dmvnorm(x, mean = c(0,1), sigma = diag(2))}
proposal_f <- function(mu){mvtnorm::rmvnorm(1, mean = mu, sigma = diag(2))}
current_position = c(2,3)
metropolis_step(current_position,pdf_function,proposal_f)

lucas-castillo/SampleR documentation built on Jan. 1, 2021, 8:25 a.m.