Guest User

Untitled

a guest
Jan 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. n_sims <- 1e5
  2.  
  3. breaking_convention <- "all_at_once" # or stick_breaking
  4.  
  5. if (breaking_convention == "stick_breaking"){
  6. break_locations <- matrix(runif(n = n_sims), ncol=1)
  7. sorted_break_locations <- cbind(break_locations, matrix(runif(n = n_sims, min = break_locations, max=1), ncol=1))
  8. } else {
  9. break_locations <- matrix(runif(n = 2*n_sims), ncol=2)
  10. sorted_break_locations <- t(apply(break_locations, 1, sort))
  11. }
  12.  
  13. segment_lengths <- cbind(sorted_break_locations[,1],
  14. sorted_break_locations[,2] - sorted_break_locations[,1],
  15. 1 - sorted_break_locations[,2])
  16.  
  17. sorted_segment_lengths <- t(apply(segment_lengths, 1, sort))
  18.  
  19. head(sorted_segment_lengths)
  20.  
  21. is_triangle <- function(x){
  22. as.logical(x[3] < (x[2] + x[1]))
  23. }
  24.  
  25. triangles <- apply(sorted_segment_lengths, 1, is_triangle)
  26.  
  27. binom.test(x = rev(table(triangles)))
Add Comment
Please, Sign In to add comment