-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.R
More file actions
48 lines (31 loc) · 792 Bytes
/
map.R
File metadata and controls
48 lines (31 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# http://www.mi.fu-berlin.de/wiki/pub/ABI/Genomics12/MLvsMAP.pdf slide 26
# argmax mu = argmax mu sum_x log(P(x | mu)) + log(P(mu))
# where P(mu) is the prior
# data
x <- c(1, 0, 1, 1, 1, 1, 0)
# beta prior
a <- 1
b <- 1
bern <- function(xi, mu) {
return(mu ** xi * (1 - mu) ** (1 - xi))
}
bern(1, .5)
logpostdata <- c()
museq <- seq(0.01, .99, .01)
best <- -99999999999999
# loop over parameter
for (mu in museq) {
logpost <- 0
# loop over data
for (xi in x) {
# mu <- a / (a + b)
logpost <- logpost + log(dbinom(xi, 1, mu)) + log(dbeta(mu, a, b))
# logpost <- logpost + log(bern(xi, a / (a + b))) + log(dbeta(mu, a, b))
}
logpostdata <- c(logpostdata, logpost)
if (logpost > best) {
best <- logpost
cat(mu, logpost, '\n')
}
}
plot(museq, logpostdata)