@@ -36,9 +36,9 @@ ind <- 0
36
36
37
37
for (i in 1 : length(n )) {
38
38
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 ])
42
42
}
43
43
if (logL > cc ) {
44
44
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))
52
52
xhist <- hist(n , plot = F )
53
53
yhist <- hist(theta , plot = F )
54
54
top <- max(c(xhist $ counts , yhist $ counts ))
55
- xrange <- c(0 , nmax )
55
+ xrange <- c(0 , data $ nmax )
56
56
yrange <- c(0 , 1 )
57
57
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 = " " )
60
60
axis(1 )
61
61
mtext(" Number of Surveys" , side = 1 ,line = 2.25 , cex = 1.2 )
62
62
axis(2 , cex = 1.2 )
63
63
las = 0
64
64
mtext(" Rate of Return" , side = 2 ,line = 2.25 , cex = 1.2 )
65
65
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
68
68
69
- par(mar = c(0 ,4 , 1 , 1 ))
69
+ par(mar = c(0 , 4 , 1 , 1 ))
70
70
barplot(xhist $ counts , axes = FALSE , ylim = c(0 , top ), space = 0 ,col = " lightblue" )
71
71
72
- par(mar = c(4 ,0 , 1 , 3 ))
72
+ par(mar = c(4 , 0 , 1 , 3 ))
73
73
barplot(yhist $ counts , axes = FALSE , xlim = c(0 , top ), space = 0 , horiz = TRUE ,
74
74
col = " lightblue" )
75
-
0 commit comments