I am new to sampling rear distributions (therefore, therefore, a Bayesian approach) using the MCMC method based on the Metropolis-Hastings algorithm. For this, I use the mcmc library in R. My distribution is multidimensional. To check if this meter algorithm works for multi-currency distribution, I successfully dealt with the multidimensional distribution of student-t (package mvtnorm, function dmvt). Now I want to apply the same thing to my multidimensional distribution (2 vars x and y), but this will not work; I get the error message: Error in X [, 1]: Incorrect number of measurements
Here is my code:
library(mcmc)
library(mvtnorm)
my.seed <- 123
logprior<-function(X,...)
{
ifelse( (-50.0 <= X[,1] & X[,1]<=50.0) & (-50.0 <= X[,2] & X[,2]<=50.0), return(0), return(-Inf))
}
logpost<-function(X,...)
{
log.like <- log( exp(-((X[,1]^2 + X[,2]^2 - 4)/10 )^2) * sin(4*atan(X[,2]/X[,1])) )
log.prior<-logprior(X)
log.post<-log.like + log.prior
return (log.post)
}
x <- seq(-5,5,0.15)
y <- seq(-5,5,0.15)
X<-cbind(x,y)
out <- metrop(function(X) logpost(X), c(0,0), blen=100, nbatch=100)
out <- metrop(out)
out$accept
, MWE, , .
, logpost X .
,