TABLE OF CONTENTS


MetropolisHastings/mh [ Functions ]

NAME

    mh --- prototype Metropolis-Hastings

FUNCTION

Metropolis-Hastings step for general parameters and likelihood functions, for which the candidates are generated as multivariate normal.

SYNOPSIS

2582 mh <- function(par, fun, candcov, tun, ...)

INPUTS

    par        base model parameters
    fun        likelihood function to use
    candcov    covariance matrix for candidate generation
    tun        tuning parameter for candidate generation

OUTPUTS

    par        new parameters after MH step
    acc        boolean, whether the step was accepted

SOURCE

2585 {
2586     # base likelihood
2587     baselik <- fun(par, ...)
2588     # generate candidate
2589     cand <- MYmvrnorm(1, par, candcov * tun)
2590     # candidate likelihood
2591     candlik <- fun(cand, ...)
2592     # accept-reject and update parameters
2593     acc <- acceptreject(baselik, candlik)
2594     if(acc) out <- cand else out <- par
2595     return(list(par = out, acc = acc))    
2596 }