独立抽样(MCMC方法)

本文详细介绍了MCMC(Markov Chain Monte Carlo)方法中的独立抽样技术,分为两部分进行阐述,涵盖了独立抽样的基本概念、原理及应用。
摘要由CSDN通过智能技术生成

独立抽样(一)

# simulations
wais<-read.csv("wais.csv",head=T)
y<-wais[,2]
x<-wais[,1]
m<-55000
mu.beta<-c(0,0)
sigma.beta<-c(100,100)
prop.s<-c(.1,.1)
beta<-matrix(nrow=m,ncol=2)
acc.prob<-0
current.beta<-c(0,0)
for(t in 1:m){
  prop.beta<-rnorm(2,current.beta,prop.s)
 cur.eta<-current.beta[1]+current.beta[2]*x
  prop.eta<-prop.beta[1]+prop.beta[2]*x
 loga<-(sum(y*prop.eta-log(1+exp(prop.eta))))-sum(y*cur.eta-log(1+exp(cur.eta)))+sum(dnorm(prop.beta,mu.beta,prop.s,log=T))-sum(dnorm(current.beta,mu.beta,prop.s,log=T))
  u<-runif(1)
  u<-log(u)
  if(u<=loga){
   current.beta<-prop.beta
   acc.prob<-acc.prob+1
  }
  beta[t,]<-current.beta
}
    #convergence diagnostic plot
erg.mean<-function(x){
  n<-length(x)
  result<-cumsum(x)/cumsum(rep(1,n))
}
burnin<-15000
idx<-seq(1,m,50
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值