由大都市hastings建模的mcmc

时间:2017-09-30 08:42:50

标签: r mcmc

我正在尝试使用R中的mhadaptive包对mcmc进行建模。但是会出现一个错误。我该怎么办?

#importing data from excel
q<-as.matrix(dataset1)  #input data from spread price
F1<-as.matrix(F_1_)     #input data from F

li_reg<-function(pars,data)  #defining function
{
a01<-pars[1]           #defining parameters
a11<-pars[2]
epsilon<-pars[3]
b11<-pars[4]
 a02<-pars[5]
a12<-pars[6]
 b12<-pars[7]
 v<-pars[8]

pred<-((a01+a11*epsilon^2+b11)+F1[,2]*(a02+a12*epsilon^2+b12))   #parametes which exist here should be optimize by cinsidering this formula
log_likelihood<-sum(dnorm(data[,2],pred,log = TRUE))
prior<-prior_reg(pars)
return(log_likelihood+prior)
}

prior_reg<-function(pars)                #here there is prior values
{
epsilon<-pars[3]
v<-pars[8]

prior_epsilon<-pt(0.85,5,lower.tail = TRUE,log.p = FALSE)
}

mcmc_r<-Metro_Hastings(li_func = li_reg,pars =NULL,prop_sigma = NULL,par_names =  c('a01','a11','epsilon','b11','a02','a12','b12'),data=q,iterations = 2000,burn_in = 1000,adapt_par = c(100,20,0.5,0.75),quiet = FALSE)    
mcmc_r<-mcmc_thin(mcmc_r)

我使用mhadaptive包来计算优化参数。 但这个错误很明显

Error in optim(pars, li_func, control = list(fnscale = -1), hessian = TRUE,  : 
function cannot be evaluated at initial parameters

0 个答案:

没有答案