Using R Shiny to Build A Wedding Risk Model and Web Application
By: Matt Dancho, Data Science Instructor At Bsu
Tags: Data Science, Tutorial, R, Risk, Risk Management

Libraries & Theme Setup

These are the libraries used for the analysis.

# libraries used in report

library(knitr)

library(kableExtra)

library(tidyverse)

library(glue) # set theme for plots

theme_set(theme_minimal(base_family = "Avenir")) # The palette with grey:

cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442","#0072B2", "#D55E00", "#CC79A7")

Understand

1. View Business as Machine

Phase 1 — View the Business As a Machine

1.1 Isolate the Business Unit

The “business unit” here is the coupe and their guests. While the costs associated with each guest is based on the wedding vendors, the costs of the wedding are impacted based on the number of guests that are invited and the guests that RSVP yes by the final guest-count cutoff. Inviting too many guests could lead the costs to increase last-minute due to an unexpected amount saying yes, which then creates a risk of going over budget to the couple.

Example Business Case

For the sake of the business case, let’s assume that 150 people are on the initial guest invitation list. when taking all the wedding vendors into account, there is a fixed cost of $22,000 for 50 guests , and then there is a variable cost of $125 per guest above 50. This will be charged at a cutoff point 45 days prior to the date of the wedding, so at this point, the total cost will be known. The couple's budget is $30,000 and they have a risk tolerance of 25%. In other words, they can stomach a 20% chance of going over budget and ideally do not want to exceed $32,000 at the very most.

# number of people invited

invites <- 150 # total budget

budget <- 30000 # risk tolerance

risk_tolerance <- .20 # inputs for total cost calculation

fixed_cost <- 22000

guest_base <- 50

variable_guest_cost <- 125

1.2 Define Objectives

The main objective is to quantify the risk of going over a couple of faces based on how many people they send invitations to.

1.3 Collect Outcomes

In doing initial research, the main outcomes of going over budget is underestimating how quickly the costs can climb.

2. Understand the Drivers

Phase 2 — Understand the Drivers

2.1 Investigate Objectives

The objective at the time invites are sent out are to make sure that all the right people are invited, but at the same time ensure that unexpected costs do not pop up because too many people RSVP yes.

There are a few drivers that lead to the uncertainty of guest attendance. These factors are the distance to the wedding, cost of attendance (e.g. hotel & travel), availability of the guest based on the time of year, and the strength of the relationship between the guest and the couple.

2.2 Synthesize Outcomes

However, there is no historical data to analyze in this instance as the wedding has never happened before. Therefore, it is unknown if the outcomes align with the objective. Other weddings see a variable amount of response rates (guests with a RSVP of yes). This leads to increased uncertainty in the estimates.

2.3 Hypothesize Drivers

The variability of estimates is likely due to the variability in the factors mentioned above. Additionally, even with historical data to use as a guide, there is a natural deviation from an expected response rate as the response rate is the expected long-run average. The result we see for the actual event is only a single experiment.

3. Measure the Drivers

Phase 3 — Measure the Drivers

3.1 Collect Data

Some initial research states 10–20% of invited guests will not attend while another source shows 60–75% of invited guests will share in the day. In other words, guest attendance rates could be anywhere from 60–90% based on a variety of factors.

We can use this data to help solve the problem analytically.

3.2 Develop KPIs

To develop a baseline, we have to figure out how to quantify our risk based on a hypothesis and statistics. The KPIs we focus on will be likelihood of risk, the expected total cost, and the expected value of risk.

We can use the data from our research to calculate baseline KPIs analytically.

To do so, we will make an assumption that there is a universal probability of each guest RVSPing yes. This then turns the concept of guests saying yes or no into a Bernoulli process. With the law of large numbers, we can then estimate our baseline KPIs based on the expected total number of guests.

Recommendation using expected guests, costs, and risk

Using this approach, we see the couple should plan for 113 guests to respond and will be under budget by $125. Using this method, the couple should Invite All.

Explore

4. Uncover Problems and Opportunities

Phase 4 — Uncover Problems and Opportunities

4.1 Evaluate Baseline Performance

While the baseline method is favorable for the couple, it fails to account for the couple’s wedding being only a single experiment or trial of the Bernoulli process. The total cost may sometimes be lower, sometimes be higher, or sometimes the same as our analytical calculations.

4.2 Highlight Potential Problem Areas

The biggest opportunity will be to use simulation to replicate the experiment thousands of times and then analyze the frequency of outcomes. We also can add flexibility to the process by allowing a distribution of probabilities to be sampled for each replication. In other words, we can account for the 60–90% uncertainty range. Another option would be to have different categories of guests and assign each group a different probability.

4.3 Review Process

To summarize, we will attempt to model a Bernoulli process to generate data to simulate wedding guest invites. We will use a uniform distribution to sample guest probabilities provided from the research. This assumes that the expert guess for probability is accurate enough, so the biggest opportunity for improvement lies in using real data to improve the inputs.

This method is a simplified version of the real-world process, but should provide added value over the analytically calculated alternative.

5. Encode Algorithms

Phase 5 — Encode Algorithms

5.1 Develop Algorithms

We need a few additional functions to piece together our data generating process.

We need a function to sample a guest count based on n invitations with p probability to respond.

We also need a function to simulate k weddings and return outputs for total guests, total cost and risk results. These outputs are creating using our functions from above and their respective inputs. This function will also accept an argument for n and a range for p .

5.2 Quantify Financial Value Potential

Our simulation will return to us the results of k trials, which we can use to analyze the outcomes. Each of these trials will capture whether the guest count caused the wedding to go over budget as well as the specific amount over budget it went.

5.3 Improve Decision-Making via Recommendation Algorithm

Each trial also converts the outcome into a recommendation. If the outcome was under budget, the recommendation is to Invite All , otherwise it is Invite Less . For the final recommendation, we will summarize the outcomes and, if the proportion of outcomes over budget is less than the risk tolerance, we will recommend inviting all guests.

Operationalize

6. Measure Results

Phase 6 — Measure Results

6.1 Capture Outcomes

We then load up our simulator with the inputs from above. Only this time, we have 90 invites for in-town guests (with an estimated 90% chance of responding yes) and 60 invites for out-of-town guests (with an estimated 50% chance of responding yes).

Simulation — Calculate expected costs & risk from random guest counts

6.2 Synthesize Results

Ultimately, we are concerned with if we have invited too many people. Applying our summary function, we see that we should invite less people.

It is worth noting that the weighted average of our response probability is a little lower (74%) than the analytical method (75%), but that is part of the flexibility of the solution design. So even with the slightly lower probability of response, we see that the risk threshold is too great to move forward with this many invites.

6.3 Visualize Outcomes

To better understand the outcomes of the simulation, we will visualize four plots (these will go into the final web application):