- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 35677 个
- 通用积分
- 468.0871
- 学术水平
- 49 点
- 热心指数
- 75 点
- 信用等级
- 44 点
- 经验
- 40221 点
- 帖子
- 4164
- 精华
- 0
- 在线时间
- 1286 小时
- 注册时间
- 2006-6-25
- 最后登录
- 2023-11-28
- 毕业学校
- 南京农业大学
|
Chapter 3 Computations and Figures
- # gamma prior density to STM study
- # plot posterior density and normal approximating
- # based on first 10 children
- attach(dmft)
- objects(2)
- par(mfrow=c(1,1))
- par(pty="m")
- dmft <- V1[1:10]
- mdmft <- mean(dmft)
- n <- length(dmft)
- sdmft <- sum(dmft)
- n;sdmft
- x <- seq(1,4.5,0.001)
- alphap <- 3+sdmft
- betap <- 1+n
- y <- dgamma(x, shape=alphap, rate = betap)
- plot(x,y,xlab=expression(theta),ylab="",type="n",bty="l",
- cex.lab=1.8,cex=1.2,cex.axis=1.3)
- lines(x,y,lwd=2)
- text(locator(1),"Posterior",adj=0,cex=1.5)
- postmode <- (alphap-1)/betap
- postmean <- alphap/betap
- postvar <- alphap/betap^2
- postmedian <- qgamma(0.5,alphap,betap)
- postmode;postmean;postmedian;postvar;sqrt(postvar)
- #Bayesian CLT
- bmean <- mdmft
- bvar <- mdmft/n
- bsd <- sqrt(bvar)
- w <- dnorm(x, bmean, bsd)
- lines(x,w,lwd=3,lty=8,col="red")
- text(locator(1),"BCLT",col= "red",cex=1.5,adj=1)
- # based on all children
- dmft <- V1
- mdmft <- mean(dmft)
- n <- length(dmft)
- x <- seq(2.15,2.35,0.001)
- alphap <- 9761
- betap <- 4352
- y <- dgamma(x, shape=alphap, rate = betap)
- par(mfrow=c(1,1))
- par(pty="m")
- plot(x,y,xlab=expression(theta),ylab="",type="n",bty="l",
- cex.lab=1.8,cex=1.2,cex.axis=1.3)
- lines(x,y,lwd=2)
- text(locator(1),"Posterior",adj=0,cex=1.5)
- postmode <- (alphap-1)/betap
- postmean <- alphap/betap
- postvar <- alphap/betap^2
- postmedian <- qgamma(0.5,alphap,betap)
- postmode;postmean;postmedian;postvar;sqrt(postvar)
- #Bayesian CLT
- bmean <- mdmft
- bvar <- mdmft/n
- bsd <- sqrt(bvar)
- w <- dnorm(x, bmean, bsd)
- lines(x,w,lwd=3,lty=8,col="red")
- text(locator(1),"BCLT",col= "red",cex=1.5,adj=1)
复制代码
|
|