Description Usage Arguments Details Author(s) See Also Examples
View source: R/metropdir.adapt.R
Implements adaptive version of directional Metropolis Hastings.
1 2 | metropdir.adapt(obj, dobj, initial, lchain, sd.prop = 1, steplen = 0,
s = 0.95, batchlen = 100, targetacc = 0.234, ...)
|
obj |
an R function that evaluates the log unnormalized probability
density of the desired equilibrium distribution of the Markov chain.
First argument is the state vector of the Markov chain. Other arguments
arbitrary and taken from the |
dobj |
an R function that evaluates the derivative of the log unnormalized probability density at the current state of the markov chain. |
initial |
Initial state of the markov chain. |
lchain |
length of the chain |
sd.prop |
scale to use for the proposal |
steplen |
tuning parameter in mean of proposal |
s |
tuning parameter in the covariance of proposal |
batchlen |
length of batch used for update. Default is 100. |
targetacc |
Target acceptance ratio |
... |
any arguments to be passed to obj and dobj. |
This function is for automatically select a scaling factor for the directional Metropolis Hastings algorithm. This function uses batch wise update of the scale parameter to produce a adaptive chain. The user is required to supply a target acceptance ratio. The adaptive scheme modifies the scale parameter to achieve the target acceptance ratio. It is recommended that to check the output of the adaptation history as returned by the function.
Abhirup Mallik, malli066@umn.edu
metropdir
for DMH, iact
for integrated auto correlation times, mcmcdiag
, msjd
for mean squared jump distance.
for summary of diagnostic measures of a chain, multiESS
for Multivariate effective sample size.
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 | ## Not run:
Sigma <- matrix(c(1,0.2,0.2,1),2,2)
mu <- c(1,1)
Sig.Inv <- solve(Sigma)
Sig.det.sqrt <- sqrt(det(Sigma))
logf <- function(x,mu,Sig.Inv){
x.center <- as.numeric((x-mu))
out <- crossprod(x.center,Sig.Inv)
out <- sum(out*x.center)
-out/2
}
gr.logf <- function(x,mu,Sig.Inv){
x.center <- as.numeric((x-mu))
out <- crossprod(x.center,Sig.Inv)
-as.numeric(out)
}
set.seed(1234)
system.time(out <- metropdir.adapt(obj = logf, dobj = gr.logf, initial = c(1,1),
lchain = 1e4,sd.prop=1,steplen=0,s=1, mu = mu,
Sig.Inv = Sig.Inv,targetacc=0.44))
#acceptance rate
out$accept
#density plot
plot(density(out$batch[,1]))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.