Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n_sims <- 1e5
- breaking_convention <- "all_at_once" # or stick_breaking
- if (breaking_convention == "stick_breaking"){
- break_locations <- matrix(runif(n = n_sims), ncol=1)
- sorted_break_locations <- cbind(break_locations, matrix(runif(n = n_sims, min = break_locations, max=1), ncol=1))
- } else {
- break_locations <- matrix(runif(n = 2*n_sims), ncol=2)
- sorted_break_locations <- t(apply(break_locations, 1, sort))
- }
- segment_lengths <- cbind(sorted_break_locations[,1],
- sorted_break_locations[,2] - sorted_break_locations[,1],
- 1 - sorted_break_locations[,2])
- sorted_segment_lengths <- t(apply(segment_lengths, 1, sort))
- head(sorted_segment_lengths)
- is_triangle <- function(x){
- as.logical(x[3] < (x[2] + x[1]))
- }
- triangles <- apply(sorted_segment_lengths, 1, is_triangle)
- binom.test(x = rev(table(triangles)))
Add Comment
Please, Sign In to add comment