MH.framework: M-H framework

Description Usage Arguments Examples

View source: R/MH.framework.R

Description

M-H framework

Usage

1
MH.framework(dproposalfunction, rproposalfunction, dtarget, ITER = 10000, p = 50, x.initial = 1:p, buinin = 5000, ...)

Arguments

dproposalfunction
rproposalfunction
dtarget
ITER
p
x.initial
buinin
...

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (dproposalfunction, rproposalfunction, dtarget, ITER = 10000, 
    p = 50, x.initial = 1:p, buinin = 5000, ...) 
{
    X.flow = matrix(0, nrow = ITER, ncol = p)
    X.flow[1, ] = x.initial
    pb <- txtProgressBar(min = 0, max = ITER, style = 3)
    for (iter in 1:(ITER - 1)) {
        X.t = X.flow[iter, ]
        X.t1 <- rproposalfunction(X.t)
        if (log(runif(1)) < (dtarget(X.t1) + dproposalfunction(X.t, 
            X.t1) - dtarget(X.t) - dproposalfunction(X.t1, X.t))) {
            X.flow[iter + 1, ] = X.t1
        }
        else {
            X.flow[iter + 1, ] = X.t
        }
        setTxtProgressBar(pb, iter)
    }
    close(pb)
    return(X.flow)
  }

yfyang86/hamimc documentation built on Aug. 10, 2017, 8:42 a.m.