https://github.com/cran/LearnBayes
Revision b553a7cb264fcb8105230731348533fa03ca7e23 authored by Jim Albert on 16 April 2008, 00:00:00 UTC, committed by Gabor Csardi on 16 April 2008, 00:00:00 UTC
1 parent ee024f1
Raw File
Tip revision: b553a7cb264fcb8105230731348533fa03ca7e23 authored by Jim Albert on 16 April 2008, 00:00:00 UTC
version 1.2
Tip revision: b553a7c
gibbs.R
gibbs=function(logpost,start,m,scale,data)
{ 
p=length(start)
vth=array(0,dim=c(m,p))
f0=logpost(start,data)
arate=array(0,dim=c(1,p))

th0=start
th1=th0
for (i in 1:m)
{
  for (j in 1:p)
  {
  th1[j]=th0[j]+rnorm(1)*scale[j]
  f1=logpost(th1,data)
  u=runif(1)<exp(f1-f0)
  th0[j]=th1[j]*(u==1)+th0[j]*(u==0)
  f0=f1*(u==1)+f0*(u==0)
  vth[i,j]=th0[j]; 
  arate[j]=arate[j]+u
  }
}
arate=arate/m
stuff=list(par=vth,accept=arate)
return(stuff)
}


back to top