Skip to main content
Statistics LibreTexts

15.2: Simulating the Maximum Finishing Time

  • Page ID
    8800
  • Let’s simulate 150 samples, collecting the maximum value from each sample, and then plotting the distribution of maxima.

    # sample maximum value 5000 times and compute 99th percentile
    nRuns <- 5000
    sampSize <- 150
    
    sampleMax <- function(sampSize = 150) {
      samp <- rnorm(sampSize, mean = 5, sd = 1)
      return(tibble(max=max(samp)))
    }
    
    input_df <- tibble(id=seq(nRuns)) %>%
      group_by(id)
    
    maxTime <- input_df %>% do(sampleMax())
    
    cutoff <- quantile(maxTime$max, 0.99)
    
    
    ggplot(maxTime,aes(max)) +
      geom_histogram(bins = 100) +
      geom_vline(xintercept = cutoff, color = "red")

    file77.png