Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(pracma) #for fzero
- N_loops <- 100000
- N_trials <- 25
- xz <- numeric()
- # set.seed(1)
- for (k in 3:30){
- store <- numeric()
- for (i in 1:N_loops){
- y <- runif(n = k)
- best_idx <- which(y==max(y),arr.ind=TRUE)
- do_keep <- FALSE
- my_keep <- 0
- for (j in 1:k){
- #draw one
- yi <- y[j]
- #find in rank
- all_ranks <- rank(y[1:j])
- this_rank <- tail(all_ranks,1)
- #compare with acceptance value
- if (j/exp(1) <1){
- can_keep = FALSE
- } else {
- can_keep = TRUE
- }
- #do you keep
- if (can_keep ==TRUE & do_keep == FALSE){
- if (this_rank >3){
- do_keep <- TRUE
- my_keep <- yi
- }
- }
- }
- store[i] <- my_keep
- }
- store <<- store
- myfit <- function(phi){
- if (phi > 1){
- phi <- 1
- } else if (phi < 0){
- phi <- 0
- }
- err <- quantile(x = store,probs = phi)-0.5
- return(err)
- }
- temp <- fzero(myfit,0.1)
- xz[k] <- unlist(temp)
- print(xz[k])
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement