Created
January 24, 2022 17:04
-
-
Save CnrLwlss/fc4392e1e7b6336aa94b8bc1a9590f0e to your computer and use it in GitHub Desktop.
Trying to visualise Beta prior predictives.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prior1 = function(n=1) { | |
runif(n,min=0.0,max=2.0) | |
} | |
prior2 = function(n=1) { | |
15 | |
} | |
sampleprior = function(n=1){ | |
return(replicate(n,rbeta(n=1,shape1=prior1(),shape2=prior2()))) | |
} | |
plotprior = function(){ | |
return(dbeta(seq(0,1,0.01),prior1(),prior2())) | |
} | |
op = par(mfrow=c(1,2)) | |
plot(NULL,xlim=c(0,1),ylim=c(0,5),xlab="Value",ylab="Density",cex.lab=1.55,main="PDFs sampled from priors") | |
for(i in 1:2000) points(seq(0,1,0.01),plotprior(),type="l",lwd=3,col=rgb(0,0,0,0.005)) | |
priorpred = sampleprior(100000) | |
d = density(priorpred) | |
h=hist(priorpred,breaks=seq(0,1,0.001),plot=FALSE) | |
plot(h$mids,h$density,xlim=c(0,1),lwd=3,type="l",xlab="Value",ylab="Density",main="Prior predictive distribution",cex.lab=1.55,ylim=c(0,5)) | |
par(op) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment