Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将后验分布叠加在均值上,如cat#x27;卡明的人眼可视化_R_Plot_Ggplot2_Bayesian_Confidence Interval - Fatal编程技术网

R 将后验分布叠加在均值上,如cat#x27;卡明的人眼可视化

R 将后验分布叠加在均值上,如cat#x27;卡明的人眼可视化,r,plot,ggplot2,bayesian,confidence-interval,R,Plot,Ggplot2,Bayesian,Confidence Interval,我个人喜欢卡明的猫眼可视化,它将采样分布叠加在点估计上: 我还想通过Kruschke(2015)脚本获得的后验分布来实现这一点: plotMCMC(mcmcCoda,data=myData, compValMu=100.0,ropeMu=c(99.0101.0), compValSigma=15.0,ropeSigma=c(14,16), compValEff=0.0,ropeEff=c(-0.1,0.1), pairsPlot=TRUE,showCurve=FALSE, saveName=fi

我个人喜欢卡明的猫眼可视化,它将采样分布叠加在点估计上:

我还想通过Kruschke(2015)脚本获得的后验分布来实现这一点:

plotMCMC(mcmcCoda,data=myData,
compValMu=100.0,ropeMu=c(99.0101.0),
compValSigma=15.0,ropeSigma=c(14,16),
compValEff=0.0,ropeEff=c(-0.1,0.1),
pairsPlot=TRUE,showCurve=FALSE,
saveName=fileNameRoot,saveType=graphFileType)
#设置窗口和布局:
openGraph(宽度=6.0,高度=8.0*3/5)
布局(矩阵(c(2,3,5,1,4,6),nrow=3,byrow=FALSE))
par(mar=c(3.5,3.5,2.5,0.5),mgp=c(2.25,0.7,0))
#选择链中的细化步骤以绘制后验预测曲线:
nCurvesToPlot=20
stepIdxVec=序号(1,链长,楼层(链长/nCurvesToPlot))
#使用后验pred计算数据图的限制。分配
y=数据
xLim=c(最小值(y)-0.1*(最大值(y)-最小值(y)),最大值(y)+0.1*(最大值(y)-最小值(y)))
xBreaks=seq(xLim[1],xLim[2],
长度=天花板((xLim[2]-xLim[1])/(sd(y)/4)))
histInfo=hist(y,中断=xBreaks,绘图=FALSE)
yMax=1.2*最大值(histInfo$密度)
xVec=seq(xLim[1],xLim[2],长度=501)
#-----------------------------------------------------------------------------
#绘制数据y和后预测曲线的细微差别:
histInfo=hist(y,prob=TRUE,xlim=xlim,ylim=c(0,yMax),breaks=xBreaks,
col=“red2”,border=“white”,xlab=“y”,ylab=“”,
yaxt=“n”,cex.lab=1.5,main=“数据w.Post.Pred.”
用于(stepIdx in 1:长度(stepIdxVec)){
行(xVec,dt((xVec mu[stepIdxVec[stepIdx]])/sigma[stepIdxVec[stepIdx]],
df=nu[stepIdxVec[stepIdx]])/sigma[stepIdxVec[stepIdx]],
type=“l”,col=“天蓝”,lwd=1)
}
文本(max(xVec),yMax,bquote(N==(长度(y)),adj=c(1.1,1.1))
#-----------------------------------------------------------------------------
histInfo=plotPost(μ,cex.lab=1.75,showCurve=showCurve,
compVal=compValMu,ROPE=ropeMu,
xlab=bquote(μ),main=paste(“平均值”),
col=“天蓝色”)
#-----------------------------------------------------------------------------
histInfo=plotPost(sigma,cex.lab=1.75,showCurve=showCurve,
compVal=compValSigma,ROPE=ropeSgma,cenTend=“mode”,
xlab=bquote(西格玛),main=paste(“刻度”),
col=“天蓝色”)
#-----------------------------------------------------------------------------
效应大小=(μ-compValMu)/sigma
histInfo=plotPost(效应尺寸,compVal=compValEff,ROPE=ropeEff,
showCurve=showCurve,cenTend=“mode”,
xlab=bquote((μ-(compValMu))/sigma),
cex.lab=1.75,main=“效果大小”,
col=“天蓝色”)
#-----------------------------------------------------------------------------  
postInfo=plotPost(log10(nu),col=“skyblue”,#breaks=30,
showCurve=showCurve,
xlab=bquote(“log10”(*nu*)),cex.lab=1.75,
cenTend=“mode”,

main=“常态”)#(我为另一个应用程序创建了一个名为
plotviole
的函数,该函数可以做您想要的事情,或者至少可以根据您的应用程序的具体情况轻松修改。您可以在此处链接的R脚本的一半找到该函数:

与此答案一致,
ggplot2
有一个
geom_violen
,它将哦,这个。
plotMCMC( mcmcCoda , data=myData , 
      compValMu=100.0 , ropeMu=c(99.0,101.0) ,
      compValSigma=15.0 , ropeSigma=c(14,16) ,
      compValEff=0.0 , ropeEff=c(-0.1,0.1) ,
      pairsPlot=TRUE , showCurve=FALSE ,
      saveName=fileNameRoot , saveType=graphFileType )

 # Set up window and layout:


openGraph(width=6.0,height=8.0*3/5)
  layout( matrix( c(2,3,5, 1,4,6) , nrow=3, byrow=FALSE ) )
  par( mar=c(3.5,3.5,2.5,0.5) , mgp=c(2.25,0.7,0) )
  # Select thinned steps in chain for plotting of posterior predictive     curves:
  nCurvesToPlot = 20
  stepIdxVec = seq( 1 , chainLength , floor(chainLength/nCurvesToPlot) )
  # Compute limits for plots of data with posterior pred. distributions
  y = data
  xLim = c( min(y)-0.1*(max(y)-min(y)) , max(y)+0.1*(max(y)-min(y)) )
  xBreaks = seq( xLim[1] , xLim[2] , 
                 length=ceiling((xLim[2]-xLim[1])/(sd(y)/4)) )
  histInfo = hist(y,breaks=xBreaks,plot=FALSE)
  yMax = 1.2 * max( histInfo$density )
  xVec = seq( xLim[1] , xLim[2] , length=501 )
  #-----------------------------------------------------------------------------
  # Plot data y and smattering of posterior predictive curves:
  histInfo = hist( y , prob=TRUE , xlim=xLim , ylim=c(0,yMax) , breaks=xBreaks,
                   col="red2" , border="white" , xlab="y" , ylab="" , 
                   yaxt="n" , cex.lab=1.5 , main="Data w. Post. Pred." )
  for ( stepIdx in 1:length(stepIdxVec) ) {
    lines(xVec, dt( (xVec-mu[stepIdxVec[stepIdx]])/sigma[stepIdxVec[stepIdx]], 
                    df=nu[stepIdxVec[stepIdx]] )/sigma[stepIdxVec[stepIdx]] , 
          type="l" , col="skyblue" , lwd=1 )
  }
  text( max(xVec) , yMax , bquote(N==.(length(y))) , adj=c(1.1,1.1) )
  #-----------------------------------------------------------------------------
  histInfo = plotPost( mu , cex.lab = 1.75 , showCurve=showCurve ,
                       compVal=compValMu , ROPE=ropeMu ,
                       xlab=bquote(mu) , main=paste("Mean") , 
                       col="skyblue" )
  #-----------------------------------------------------------------------------
  histInfo = plotPost( sigma , cex.lab=1.75 , showCurve=showCurve ,
                       compVal=compValSigma , ROPE=ropeSigma , cenTend="mode" ,
                       xlab=bquote(sigma) , main=paste("Scale") , 
                       col="skyblue" )
  #-----------------------------------------------------------------------------
  effectSize = ( mu - compValMu ) / sigma
  histInfo = plotPost( effectSize , compVal=compValEff ,  ROPE=ropeEff ,
                       showCurve=showCurve , cenTend="mode" ,
                       xlab=bquote( ( mu - .(compValMu) ) / sigma ),
                       cex.lab=1.75 , main="Effect Size" ,
                       col="skyblue" )
  #-----------------------------------------------------------------------------  
  postInfo = plotPost( log10(nu) , col="skyblue" , # breaks=30 ,
                       showCurve=showCurve ,
                       xlab=bquote("log10("*nu*")") , cex.lab = 1.75 , 
                       cenTend="mode" ,
                       main="Normality" ) #  (<0.7 suggests kurtosis)