public
Created

Binomial Proportion Post Gists 2

  • Download Gist
likelihood.R
R
1 2 3 4 5 6 7 8
### Function: Likelihood Plot Values
likelihood <- function(N,Y){
a <- Y + 1
b <- N - Y + 1
dom <- seq(0,1,0.005)
val <- dbeta(dom,a,b)
return(data.frame('x'=dom, 'y'=val))
}
mean_of_posterior.R
R
1 2 3 4 5 6 7
### Function: Mean of Posterior Beta
mean_of_posterior <- function(m,n,N,Y){
a <- Y + (n*m) -1
b <- N - Y + (n*(1-m)) - 1
E_posterior <- a / (a + b)
return(E_posterior)
}
mode_of_posterior.R
R
1 2 3 4 5 6 7
### Function: Mode of Posterior Beta
mode_of_posterior <- function(m,n,N,Y){
a <- Y + (n*m) -1
b <- N - Y + (n*(1-m)) - 1
mode_posterior <- (a-1)/(a+b-2)
return(mode_posterior)
}
posterior.R
R
1 2 3 4 5 6 7 8
### Function: Posterior Plot Values
posterior <- function(m,n,N,Y){
a <- Y + (n*m) -1
b <- N - Y + (n*(1-m)) - 1
dom <- seq(0,1,0.005)
val <- dbeta(dom,a,b)
return(data.frame('x'=dom, 'y'=val))
}
prior.R
R
1 2 3 4 5 6 7 8
### Function: Prior Plot Values
prior <- function(m,n){
a = n * m
b = n * (1 - m)
dom <- seq(0,1,0.005)
val <- dbeta(dom,a,b)
return(data.frame('x'=dom, 'y'=val))
}
sd_of_posterior.R
R
1 2 3 4 5 6 7
### Function: Std Dev of Posterior Beta
sd_of_posterior <- function(m,n,N,Y){
a <- Y + (n*m) -1
b <- N - Y + (n*(1-m)) - 1
sigma_posterior <- sqrt((a*b)/(((a+b)^2)*(a+b+1)))
return(sigma_posterior)
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.