2019年1月31日星期四

A Gibbles sampler for Hierarchical Bayes

hieracrh1<-function(nsims,x,tau,kstart){
bold<-1
clambda<-rep(0,(nsims+kstart))
cb<-rep(0,(nsims+kstart))
for(i in 1: (nsims+kstart))
{clambda[i]<-rgamma(1,shape=(x+1),scale=(bold/(bold+1)))
newy<-rgamma(1,shape=2,scale=(tau/(clambda[i]*tau+1)))
cb[i] <-1/newy
bold<-1/newy
}
gibbslambda<-clambda[(kstart+1):(nsims+kstart)]
gibbsb<-cb[(kstart+1):(nsims+kstart)]
out<-list(clambda=clambda, cb=cb,gibbslambda=gibbslambda,gibbsb= gibbsb)
return(out)
}

mean(hieracrh1(4000,6,0.04,1000)$gibbslambda)
mean(hieracrh1(4000,6,0.045,1000)$gibbslambda)
mean(hieracrh1(4000,6,0.05,1000)$gibbslambda)
mean(hieracrh1(4000,6,0.055,1000)$gibbslambda)
mean(hieracrh1(4000,6,0.06,1000)$gibbslambda)

2019年1月1日星期二

Install R package from the source

install.packages("path\file", repos = NULL, type="source")
Where path_to_file would represent the full path and file name:
  • On Windows it will look something like this: "C:\\RJSONIO_0.2-3.tar.gz".
  • On UNIX it will look like this: "/home/blah/RJSONIO_0.2-3.tar.gz"