Skip to content

Commit f9a9916

Browse files
committed
fix plot in Survey
1 parent 6b5c674 commit f9a9916

File tree

1 file changed

+10
-11
lines changed
  • Bayesian_Cognitive_Modeling/ParameterEstimation/Binomial

1 file changed

+10
-11
lines changed

Bayesian_Cognitive_Modeling/ParameterEstimation/Binomial/Survey_Stan.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ ind <- 0
3636

3737
for (i in 1:length(n)) {
3838
logL <- 0
39-
for(j in 1:m) {
40-
logL <- logL+lgamma(n[i]+1)-lgamma(k[j]+1)-lgamma(n[i]-k[j]+1)
41-
logL <- logL+k[j]*log(theta[i])+(n[i]-k[j])*log(1-theta[i])
39+
for(j in 1:data$m) {
40+
logL <- logL+lgamma(n[i]+1)-lgamma(data$k[j]+1)-lgamma(n[i]-data$k[j]+1)
41+
logL <- logL+data$k[j]*log(theta[i])+(n[i]-data$k[j])*log(1-theta[i])
4242
}
4343
if (logL>cc) {
4444
ind <- i
@@ -52,24 +52,23 @@ layout(matrix(c(2,0,1,3),2,2,byrow=T), width=c(2/3, 1/3), heights=c(1/3, 2/3))
5252
xhist <- hist(n, plot=F)
5353
yhist <- hist(theta, plot=F)
5454
top <- max(c(xhist$counts, yhist$counts))
55-
xrange <- c(0, nmax)
55+
xrange <- c(0, data$nmax)
5656
yrange <- c(0, 1)
5757

58-
par(mar=c(5,5,1,1))
59-
plot(n,theta,xlim=xrange, ylim=yrange,ylab="", xlab="")
58+
par(mar=c(5, 5, 1, 1))
59+
plot(n, theta, xlim=xrange, ylim=yrange,ylab="", xlab="")
6060
axis(1)
6161
mtext("Number of Surveys", side=1,line=2.25, cex=1.2)
6262
axis(2, cex=1.2)
6363
las=0
6464
mtext("Rate of Return", side=2 ,line=2.25, cex=1.2)
6565
las=1
66-
points(mean(n),mean(theta), col="red", lwd=3, pch=4) #expectation
67-
points(n[ind],theta[ind], col="green", lwd=3, pch=10) #Maximum Likelihood
66+
points(mean(n), mean(theta), col="red", lwd=3, pch=4) #expectation
67+
points(n[ind], theta[ind], col="green", lwd=3, pch=10) #Maximum Likelihood
6868

69-
par(mar=c(0,4,1,1))
69+
par(mar=c(0, 4, 1, 1))
7070
barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0,col="lightblue")
7171

72-
par(mar=c(4,0,1,3))
72+
par(mar=c(4, 0, 1, 3))
7373
barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE,
7474
col="lightblue")
75-

0 commit comments

Comments
 (0)