Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. # beta(theta | a, b)
  2. beta_pdf <- function(theta, a, b) {
  3. # Computes p(theta|a,b) = beta(theta|a,b)
  4. pdf = theta^(a - 1) * (1 - theta)^(b - 1)
  5. return(pdf)
  6. }
  7.  
  8. theta = seq(0, 1, by = 0.01)
  9. a = 2
  10. b = 2
  11. plot(theta,beta_pdf(theta,a,b))
  12.  
  13. beta_pde <- function(theta) {
  14. # Computes p(theta|a,b) = beta(theta|a,b)
  15. pdf <- seq(0, 100)
  16. for(i in 1:length(theta)){
  17. if(theta[i]==0.5){
  18. pdf[i] = 1
  19. }
  20. else{
  21. pdf[i]=0
  22. }
  23. }
  24. return(pdf)
  25. }
  26.  
  27. plot(theta,beta_pde(theta))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement