Created
July 6, 2014 12:22
-
-
Save xccds/f3f68f3e4d94e92a8e9e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
myData=c(1,1,1,1,1,1,1,1,1,1,1,0,0,0) | |
# 尝试1万个不同的参数 | |
tryn = 1e4 | |
Theta = sort(runif(tryn)) | |
pTheta = 1/tryn | |
z = sum( myData==1 ) | |
N = length( myData ) | |
# 似然函数 | |
pDataGivenTheta = Theta^z * (1-Theta)^(N-z) | |
pData = sum( pDataGivenTheta * pTheta ) | |
# 后验概率 | |
pThetaGivenData = pDataGivenTheta * pTheta / pData | |
plot(x=Theta,y=pThetaGivenData,type='l') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment