R/InterceptupdateAR.R

########################################
InterceptupdateAR = function(Intercept,llikAll,
                             MuBeta,VarBeta,
                             tune,acc,
                             Y,Z,TT,nn,dd)
{
    #propose new value for intercept
    IntNew = Intercept + tune*rnorm(1,0,1)
    #compute loglikelihood at proposed value
    llikNew = sum(sapply(1:TT,function(xx){
        FullLogLik(Y[[xx]],Z[[xx]],IntNew,nn[xx],dd)}))
#    llikNew = sum(mcmapply( FullLogLik,YY=Y,ZZ=Z,intercept=IntNew,nn=nn,dd=dd,mc.cores=3))
    #log prior at current value
    priorOld = betaprior(Intercept, MuBeta, VarBeta)
    #log prior at new value
    priorNew = betaprior(IntNew,MuBeta,VarBeta)
    #logratio
    logratio = llikNew - llikAll + priorNew - priorOld
    if(!is.nan(logratio)){
        if(logratio > log(runif(1,0,1))){
            Intercept = IntNew
            acc = acc + 1
            llikAll = llikNew
        }
    }
    return(list(Intercept=Intercept,
                acc=acc,
                llikAll = llikAll))
}
SAcmu/LLSM documentation built on May 9, 2019, 11:06 a.m.