Skip to content

Instantly share code, notes, and snippets.

@czsheets
Last active September 9, 2018 09:38
Show Gist options
  • Save czsheets/f167b687ea84888f64aa9f2e50e07faf to your computer and use it in GitHub Desktop.
Save czsheets/f167b687ea84888f64aa9f2e50e07faf to your computer and use it in GitHub Desktop.
RShiny simulation to estimate the chances of job offer(s)

How many offers will I get: an interactive simulation using RStudio's Shiny application

As a rapidly growing field, data science programs often work to provide exposure to leading companies in marketing, banking, consulting, research, technology, insurance, and many other areas with a need for analytic services. Students are encouraged to apply to a wide array of companies, to develop relationships with people in the field, get an understanding of different fields in analytics, and increase the chances of getting one or (hopefully) more offers.

During the interview process analytics students are always running the numbers (consciously or not) and calculating the likelihood of an offer. Where should I put my energy? How many interviews are too many? Too few? I wrote an interactive program to allow applicants to estimate their personal numbers using this tool. It includes the following variables and their assumptions:

  • The number of “primary” interviews. The assumption is that while students will put their full effort and attention into every application, there may be companies that are the key focus for a student; the application will provide an estimate of the likelihood of getting an offer from just those companies. The default is 5.
  • The average expected probability of getting an offer from primary interviews. Each person must decide for themselves how likely they are, on average, to get an offer. This can depend on many factors: grades, experience in the industry, specific content knowledge, etc. The default is slightly less than 1/6 (on average).
  • The total number of interviews. The benefits of additional interviews are described above; the default is 10 total interviews.
  • "Decay" rate. Interviews require preparation and focus, and beyond a certain point, and as with any activity, fatigue can have an effect. Preparation and focus will decrease or abolish this decay rate for many people. The default is a decreased probability of 1% for every additional interview beyond the primary group of interviews.
  • Total number of offers (n). The user can select the number of offers they hope to get, up to 10. The default is 3.

The application was built on RStudio's Shiny platform, using sliders to provide immediate feedback:

  • Text describing the likelihood at least one offer based only on the primary interviews.
  • Text describing the likelihood at least one offer based on all interviews.
  • A bar graph providing the probability of getting at least (n) offers based on all interviews.

Screenshot of simulation

image

A note of caution

While the program and math are generally correct, it makes a few assumptions to simplify the calculations, and is in not in any way meant to predict anyone’s actual success. Have fun playing with the options and seeing how well the interactive nature of Shiny supports active simulation.

published: true
library(shiny)
library(formattable)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Projected Number of offers"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("primary", "Number of primary interviews (the ones you're most focused on):", min = 1, max = 10, value = 5),
sliderInput("probability","Average expected probability of offers from primary interviews:", min = .01, max = 1, value = .15),
sliderInput("tot_int", "Total number of interviews:", min = 1, max = 20, value = 10),
sliderInput("decay", "Decay rate for each interview beyond primary (how much do you think your chances will decrease with each interview beyond your primary interviews):", min = 0, max = .1, value = .01),
sliderInput("hoped_jobs", "Number of offers you're hoping for:", min = 1, max = 10, value = 3)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("tab1"),
br(), br(),
textOutput("tab2"),
br(), br(),
plotOutput("jobPlot")
)
)
)
#Define server logic required to draw a histogram
server <- function(input, output) {
output$tab1 <- renderText({
# generate value of at least one job
prim_job = 1 - (1 - input$probability)^input$primary
paste("The chances of getting an offer based on your primary interviews are ", percent(prim_job,0))
})
output$tab2 <- renderText({
# generate value of at least one job
all_job_prob = c(rep(input$probability,input$primary-1), cumsum(c(input$probability, rep(-input$decay, input$tot_int - input$primary))))
all_job_prob = mean(ifelse(all_job_prob < 0,0, all_job_prob))
#all_job_prob = 1 - all_job_prob
one_job = 1 - (choose(input$tot_int, 0) * all_job_prob^0 * (1 - all_job_prob)^(input$tot_int - 0))
#one_job = 1 - cumprod(all_job_prob)[length(all_job_prob)]
#extra_ints = input$total_int - input$primary
print(all_job_prob)
paste("The chances of getting an offer after all interviews are ", percent(one_job,0)[1])
})
output$jobPlot <- renderPlot({
# generate plot with more than one job
all_job_prob = c(rep(input$probability,input$primary-1), cumsum(c(input$probability, rep(-input$decay, input$tot_int - input$primary))))
all_job_prob = mean(ifelse(all_job_prob < 0,0, all_job_prob))
#print(all_job_prob_2)
mult_offers = function(hoped_jobs, tot_int, all_job_prob){
each_level = rep(NA,hoped_jobs)
for (i in 0:hoped_jobs-1){
each_level[i+1] = choose(tot_int, i) * all_job_prob^i * (1 - all_job_prob)^(tot_int - i)
}
return(1- cumsum(each_level)[length(each_level)])
}
bar_offers = rep(NA, length(input$hoped_jobs))
for (i in 1:input$hoped_jobs){
bar_offers[i] = mult_offers(i, input$tot_int, all_job_prob)
print(bar_offers)
}
barplot(bar_offers, names = 1:input$hoped_jobs, ylab = "Likelihood", xlab = 'Number of Offers', ylim = c(0,1),
col = 'dodgerblue', main = "Likelihood of getting at least a certain number of offers \n (based on total number of interviews)")
})
}
# Run the application
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment