Description Details Author(s) References Examples
The package is built to be embedded within an MCMC algorithm and runs a Portkey two-coin Bernoulli factory to obtain the next step of the Markov chain.
The DESCRIPTION file:
This package was not yet installed at build time.
Index: This package was not yet installed at build time.
Use the package within an MCMC algorithm via a Portkey two-coin Bernoulli factory to obtain the next step of the Markov chain.
Dootika Vats
Maintainer: Dootika Vats <dootika@iitk.ac.in>
~~ Literature or other references for background information ~~
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # The following example implements the portkey-two coin algorithm for a
# Gamma mixture of Weibulls as presented in Vats et. al. (2020)
set.seed(10) # seed is chosen so that example is fast
Cf <- function(value, k)
{
return(k/(exp(1)*value))
}
pf <- function(value, k, lam1, a1, b1)
{
lam1 <- rgamma(1, shape = a1, rate = b1)
dweibull(value, shape = k, scale = lam1)/Cf(value = value, k = k)
}
mcmc <- function(N = 1e3, beta = .95, k = 5, a1 = 2, b1 = 5)
{
out <- numeric(length = N)
loops <- numeric(length = N)
out[1] <- .1
acc <- 0
for(i in 2:N)
{
prop <- rnorm(1, out[i-1], sd = sqrt(.001))
if(prop < 0)
{
out[i] <- out[i-1]
next
}
interim <- portkey(prop = prop, curr = out[i-1], pf = pf, Cprop = Cf(prop, k),
Ccurr = Cf(out[i-1], k), beta = beta, k = k, a1 = a1, b1 = b1)
out[i] <- interim[[1]]
if(out[i] != out[i-1]) acc <- acc+1
loops[i] <- interim[[2]]
}
return(list("mcmc" = out, "loops" = loops, "accept" = acc/N))
}
a1 <- 10
b1 <- 100
k <- 10
bark <- mcmc(N = 5e3, beta = 1, k = 10, a1 = 10, b1 = 100)
port <- mcmc(N = 5e3, beta = .99, k = 10, a1 = 10, b1 = 100)
plot(1:5e3, bark$loops, pch = 3)
points(1:5e3, port$loops, pch = 1, col = "red")
par(mfrow = c(1,2))
acf(bark$mcmc)
acf(port$mcmc)
par(mfrow = c(1,1))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.