-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeta_to_log.R
53 lines (33 loc) · 1021 Bytes
/
beta_to_log.R
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
49
50
51
52
53
library(tidyverse)
library(patchwork)
shape1 <- 1.3
shape2 <- 1.3
logit <- function(x){
log(x/(1-x))
}
beta_dat <-
tibble(x = seq(0.01,0.99, 0.01),
p = dbeta(seq(0.01,0.99, 0.01), shape1, shape2)
)
logit_dat <-
tibble(
logit = logit(rbeta(n = 4000, shape1 = shape1, shape2 = shape2)),
)
beta <-
ggplot()+
stat_function(fun = dbeta, n=101, args = list(shape1 = shape1, shape2 = shape2))
log <-
ggplot(logit_dat, aes(x = logit))+
geom_density()
log_prior <- MASS::fitdistr(logit_dat$logit, dnorm, start = list(mean = 0, sd = 1))
prior_dist <-
ggplot()+
stat_function(fun = dnorm,
n = 101,
args = list(mean = log_prior$estimate[[1]], sd = log_prior$estimate[[2]]),
xlim = c(-5, 5),
color = 'red'
)
cat(paste0("mean = ", log_prior$estimate[[1]], '\n',
"sd = ", log_prior$estimate[[2]]))
beta / log / prior_dist