Suppose both hotels have 100 reservations on the books for an upcoming weekend. Should their managers expect about the same number of guests to show up? The answer matters when deciding how many rooms may still be available to sell. It also depends on what those 100 reservations look like. A group that booked six months ago and a guest who booked yesterday both count as one reservation today.
We used historical bookings to answer three questions. How often did reservations cancel at each hotel? How did that rate change with the number of days booked in advance? Which market segments accounted for the most cancellations within each hotel? For the last question we looked at both the percentage canceled and the number canceled. A manager estimating how many bookings might fall through needs both pieces of information.
We used dplyr to prepare the booking records and calculate group totals, ggplot2 to plot the comparisons, scales to label percentages and counts, and knitr to format tables. rmarkdown renders this file as an HTML report. Keep the accompanying CSV and cover photo in the same folder as this R Markdown file.
library(rmarkdown)
library(dplyr)
library(ggplot2)
library(scales)
library(knitr)
opts_chunk$set(echo = TRUE, fig.width = 8, fig.height = 4.4,
fig.align = "center", out.width = "95%")
theme_set(theme_minimal(base_size = 12) +
theme(panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
plot.title = element_text(face = "bold", color = "#17494c", size = 14),
axis.title = element_text(color = "#365451")))
hotel_colors <- c("City Hotel" = "#167278", "Resort Hotel" = "#B75A35")
pct <- label_percent(accuracy = 0.1)
The records came from the property management systems of two hotels in Portugal. The original authors released anonymized booking data so researchers could study hotel demand. Each row represents one reservation scheduled to arrive between July 2015 and August 2017. Each original hotel file had 31 variables. We used the combined TidyTuesday file, which adds a hotel label and contains 119,390 rows and 32 columns. February 2020 was the TidyTuesday release date. TidyTuesday release and data dictionary
raw <- read.csv("hotels.csv",
na.strings = c("", "NA", "NULL"), stringsAsFactors = FALSE)
missing_counts <- colSums(is.na(raw))
kable(data.frame(Variable = names(missing_counts[missing_counts > 0]),
Missing = unname(missing_counts[missing_counts > 0])),
caption = "Columns with missing entries in the original file")
| Variable | Missing |
|---|---|
| children | 4 |
| country | 488 |
| agent | 16340 |
| company | 112593 |
repeated <- sum(duplicated(raw))
bookings <- select(raw, hotel, is_canceled, lead_time, market_segment)
stopifnot(!anyNA(bookings), all(bookings$is_canceled %in% 0:1),
setequal(bookings$hotel, c("City Hotel", "Resort Hotel")),
all(is.finite(bookings$lead_time)), all(bookings$lead_time >= 0))
A blank agent or company field can mean that no intermediary was involved. Dropping every row with a missing entry would discard usable bookings. Our four selected fields were complete, so we kept those records without filling in any values. Across all 32 columns, 31,994 rows matched an earlier row exactly. Two different reservations can have the same recorded details, and the file has no unique booking ID to tell them apart. We kept the matching rows. An accidental duplicate would therefore receive the same weight as a separate reservation.
# Preserve the two bookings whose segment was recorded as Undefined.
bookings <- bookings %>%
mutate(market_segment = recode(market_segment, Undefined = "Unknown"),
lead_band = cut(lead_time, breaks = c(-Inf, 7, 30, 90, 180, Inf),
labels = c("0–7", "8–30", "31–90", "91–180", "181+"),
ordered_result = TRUE))
stopifnot(nrow(bookings) == nrow(raw), !anyNA(bookings$lead_band))
kable(head(bookings, 5), caption = "First five prepared bookings")
| hotel | is_canceled | lead_time | market_segment | lead_band |
|---|---|---|---|---|
| Resort Hotel | 0 | 342 | Direct | 181+ |
| Resort Hotel | 0 | 737 | Direct | 181+ |
| Resort Hotel | 0 | 7 | Direct | 0–7 |
| Resort Hotel | 0 | 13 | Corporate | 8–30 |
| Resort Hotel | 0 | 14 | Online TA | 8–30 |
The final data have 119,390 reservations and five fields. Hotel identifies the property. Cancellation status is 1 for canceled and 0 otherwise, with 44,224 cancellations overall. Lead time measures days from entry of the reservation to scheduled arrival. It runs from 0 to 737 days, with a median of 69. We retained the long lead times because advance bookings are part of our question. Lead band groups these days into five ordered intervals, from bookings made within a week of arrival to bookings made more than 180 days ahead. Market segment has 8 categories, including the two bookings marked Unknown. TA means travel agent and TO means tour operator.
We started with a measure that uses the same denominator rule throughout the report. Within each group, we divided canceled reservations by all reservations in that group.
# Apply the same rate calculation at each level of detail.
count_cancellations <- function(grouped_bookings) {
grouped_bookings %>%
summarise(booked = n(), canceled = sum(is_canceled),
rate = canceled / booked, .groups = "drop")
}
by_hotel <- bookings %>% group_by(hotel) %>% count_cancellations()
kable(transmute(by_hotel, Hotel = hotel, Bookings = comma(booked),
Canceled = comma(canceled), `Cancellation rate` = pct(rate)),
align = "lrrr", caption = "Booking outcomes by hotel")
| Hotel | Bookings | Canceled | Cancellation rate |
|---|---|---|---|
| City Hotel | 79,330 | 33,102 | 41.7% |
| Resort Hotel | 40,060 | 11,122 | 27.8% |
City Hotel lost about 42 of every 100 reservations, compared with 28 at Resort Hotel. The cancellation rate at City Hotel was about 14 percentage points higher than at Resort Hotel. City Hotel handled nearly twice as many reservations, so the raw cancellation counts alone would have made the two properties look even further apart. The next question was whether this gap looked similar for guests who booked around the same time.
by_lead <- bookings %>% group_by(hotel, lead_band) %>% count_cancellations()
# Put both hotels on the same row for each advance-booking interval.
lead_table <- reshape(as.data.frame(select(by_lead, lead_band, hotel, booked, rate)),
idvar = "lead_band", timevar = "hotel", direction = "wide")
lead_table <- arrange(lead_table, lead_band)
kable(transmute(lead_table, Days = lead_band, City = comma(`booked.City Hotel`),
`City rate` = pct(`rate.City Hotel`), Resort = comma(`booked.Resort Hotel`),
`Resort rate` = pct(`rate.Resort Hotel`)),
align = "lrrrr", caption = "Bookings and cancellation rates within each lead-time band")
| Days | City | City rate | Resort | Resort rate |
|---|---|---|---|---|
| 0–7 | 10,808 | 12.2% | 8,938 | 6.5% |
| 8–30 | 12,554 | 30.9% | 6,406 | 21.9% |
| 31–90 | 20,797 | 39.9% | 8,756 | 32.4% |
| 91–180 | 18,223 | 48.0% | 8,216 | 37.4% |
| 181+ | 16,948 | 64.1% | 7,744 | 41.6% |
ggplot(by_lead, aes(lead_band, rate, color = hotel, group = hotel, shape = hotel)) +
geom_line() + geom_point(size = 3) +
scale_color_manual(values = hotel_colors) +
scale_y_continuous(labels = label_percent(), limits = c(0, 0.7)) +
labs(title = "The hotel gap was widest for bookings made over 180 days ahead",
x = "Days booked before arrival (ordered intervals)", y = "Bookings canceled",
color = NULL, shape = NULL) +
theme(legend.position = "bottom")
For reservations made within a week of arrival, the rates were 12.2% at City Hotel and 6.5% at Resort Hotel, a gap of about six points. In the 181+ day band the gap reached about 22 points, and close to two-thirds of City Hotel bookings canceled. Both hotels showed an increase at every step. The intervals have different widths, so the lines show the order of the groups. They do not measure the effect of waiting one more day to book.
by_segment <- bookings %>%
group_by(hotel, market_segment) %>% count_cancellations()
# A missing hotel/segment combination has no rate; leave it as a dash.
segment_table <- reshape(as.data.frame(by_segment), idvar = "market_segment",
timevar = "hotel", direction = "wide")
segment_table <- arrange(segment_table, desc(`canceled.City Hotel`))
display_value <- function(x, formatter) ifelse(is.na(x), "—", formatter(x))
kable(transmute(segment_table, Segment = market_segment,
`City booked` = comma(`booked.City Hotel`),
`City canceled` = comma(`canceled.City Hotel`),
`City rate` = pct(`rate.City Hotel`),
`Resort booked` = display_value(`booked.Resort Hotel`, comma),
`Resort canceled` = display_value(`canceled.Resort Hotel`, comma),
`Resort rate` = display_value(`rate.Resort Hotel`, pct)),
align = "lrrrrrr", caption = "Segments ordered by number of City Hotel cancellations")
| Segment | City booked | City canceled | City rate | Resort booked | Resort canceled | Resort rate |
|---|---|---|---|---|---|---|
| Online TA | 38,748 | 14,491 | 37.4% | 17,729 | 6,248 | 35.2% |
| Groups | 13,975 | 9,623 | 68.9% | 5,836 | 2,474 | 42.4% |
| Offline TA/TO | 16,747 | 7,173 | 42.8% | 7,472 | 1,138 | 15.2% |
| Direct | 6,093 | 1,056 | 17.3% | 6,513 | 878 | 13.5% |
| Corporate | 2,986 | 641 | 21.5% | 2,309 | 351 | 15.2% |
| Complementary | 542 | 64 | 11.8% | 201 | 33 | 16.4% |
| Aviation | 237 | 52 | 21.9% | — | — | — |
| Unknown | 2 | 2 | 100.0% | — | — | — |
# Compare the two largest sources of cancellations at both hotels.
drivers <- by_segment %>% filter(market_segment %in% c("Online TA", "Groups")) %>%
left_join(select(by_hotel, hotel, total_canceled = canceled), by = "hotel") %>%
mutate(share = canceled / total_canceled)
ggplot(drivers, aes(market_segment, share, fill = hotel)) +
geom_col(position = "dodge", width = 0.65) +
scale_fill_manual(values = hotel_colors) +
scale_y_continuous(labels = label_percent(), limits = c(0, 0.6)) +
labs(title = "Online travel agents accounted for the most cancellations",
x = NULL, y = "Share of all cancellations at that hotel", fill = NULL) +
theme(legend.position = "bottom")
At City Hotel, Groups had the highest cancellation rate among identified segments. About 69 of every 100 group bookings canceled, compared with 37 of every 100 Online TA bookings. Yet Online TA produced 14,491 cancellations, nearly 4,900 more than Groups, because it handled 38,748 reservations. Resort Hotel showed the same distinction. Groups had the higher rate (42.4%), while Online TA accounted for 6,248 of its 11,122 cancellations, or 56.2%. The table’s rate uses all bookings in that segment. The chart answers a different question: out of all cancellations at that hotel, what fraction came from each of its two largest contributors?
Two City Hotel bookings had an unknown segment, and both canceled. A 100% rate for two records tells us little about other guests. Resort Hotel had no Aviation or Unknown bookings, shown as dashes in the table.
The previous results point toward two different priorities. To see whether they still made sense for a manager looking six months ahead, we compared Groups and Online TA again using only bookings made more than 180 days in advance.
advance <- bookings %>%
filter(lead_time > 180, market_segment %in% c("Groups", "Online TA")) %>%
group_by(hotel, market_segment) %>% count_cancellations()
kable(transmute(advance, Hotel = hotel, Segment = market_segment,
Bookings = comma(booked), Canceled = comma(canceled), Rate = pct(rate)),
align = "llrrr", caption = "Groups and Online TA among bookings made 181+ days ahead")
| Hotel | Segment | Bookings | Canceled | Rate |
|---|---|---|---|---|
| City Hotel | Groups | 6,493 | 5,372 | 82.7% |
| City Hotel | Online TA | 4,894 | 2,541 | 51.9% |
| Resort Hotel | Groups | 2,582 | 1,113 | 43.1% |
| Resort Hotel | Online TA | 2,603 | 1,475 | 56.7% |
At City Hotel, 5,372 of 6,493 advance group reservations canceled (82.7%). Groups even overtook Online TA in the number of cancellations in this window. At Resort Hotel, Online TA bookings in the same window canceled more often than Groups (56.7% versus 43.1%). We would lose that difference if we gave both properties the same rule for advance group bookings.
Our starting question was how much confidence a manager could place in the reservation count. Using 119,390 bookings, we compared the observed share canceled by hotel, days booked ahead and market segment. The city property had the higher overall rate, but the size of the gap depended on how far ahead the guest booked.
For City Hotel, we would start a forecast review with group reservations booked more than 180 days ahead. For Resort Hotel, we would start with online travel agents: they contributed more than half of all cancellations, and their long-lead bookings canceled more often than long-lead group bookings. One practical trial would be to keep the current forecast alongside a second forecast that uses separate historical rates for these booking groups, then compare both with actual arrivals over the next season.
There are limits to what that trial can borrow from this report. These are two properties over a historical period, and the records do not say why a guest canceled. We counted reservations, so the results alone cannot tell a manager how many room-nights or how much revenue was lost. We also grouped lead times into broad intervals and retained records with identical values. Before using the rates for staffing, we would check them against more recent bookings, split the busiest segments by arrival season, and test the forecast on later months held out from the analysis.