Description Usage Arguments Details Value Author(s) See Also Examples
Implements Markov Chain Monte Carlo for continuous random vectors using Directional Metropolis Hasting Algorithm
1 2 |
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 |
... |
any arguments to be passed to obj and dobj. |
Runs a “Directional Metropolis Hastings” algorithm, with multivariate normal proposal
producing a Markov chain with equilibrium distribution having a specified
unnormalized density. Distribution must be continuous. Support of the
distribution is the support of the density specified by argument obj
.
Returns the following objects in a list:
accept. acceptance rate.
batch. resulting chain.
Abhirup Mallik, malli066@umn.edu
metropdir.adapt
for adapting 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(obj = logf, dobj = gr.logf, initial = c(1,1),
lchain = 1e4,sd.prop=1,steplen=0,s=1, mu = mu,
Sig.Inv = Sig.Inv))
#acceptance rate
out$accept
#density plot
plot(density(out$batch[,1]))
## End(Not run)
|
user system elapsed
1.170 0.004 1.187
[1] 0.5405
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.