Overview

Synopsis

The goal of this analysis is to explore potential cross-selling opportunities within the Regork national grocery chain, leveraging the completejourney dataset. Our objective is to identify product pairs that are frequently purchased together, with a particular focus on demographic groups that exhibit these behaviors. This analysis aims to provide actionable insights that can be used to inform targeted marketing strategies, ultimately driving increased revenue and customer engagement.

By examining purchasing patterns and identifying complementary product pairs, we can tailor promotions and product placements to encourage increased sales of these item pairs. The insights derived from this analysis will be presented to the CEO and relevant stakeholders to support data-driven decision-making in marketing and sales strategies.

Packages Required

The completejourney dataset provides access to data sets characterizing household level transactions over one year from a group of 2,469 households who are frequent shoppers at a grocery store.

It contains all of each household’s purchases, not just those from a limited number of categories. For certain households, demographic information as well as direct marketing contact history are captured.

The following packages are all being used in some capacity or another within this Markdown file.

completejourney: Loading the transactions, products, promotions, and other datasets necessary for analysis.

dplyr: Filtering transactions to focus on specific product categories or demographic groups, calculating summary statistics (average basket size, etc.), and creating new variables to flag transactions meeting certain criteria.

tidyr: Reshaping data if necessary. For example, pivoting to analyze purchase frequency of different items for a single customer over time.

ggplot2: Creating visualizations like bar charts to compare co-purchase rates, scatterplots to investigate purchase amounts, or histograms to examine purchase frequency distributions.

readr: Efficiently loading the large CompleteJourney transaction and product datasets.

tidyverse: A powerful meta-package, providing the foundations for the core data manipulation, exploration, and visualization tasks you will perform.

lubridate: Extracting the day of the week or month from transaction dates to explore purchasing patterns across time.

library(dplyr)      
library(tidyr)     
library(ggplot2)   
library(readr)   
library(tidyverse)
library(lubridate)
library(completejourney)
library(kableExtra)

Data Preparation

Loading and Cleaning Data

After loading the transaction and product datasets, the focus will be on filtering the data to include only transactions involving Deli Meat and Bread Items. This involves identifying the product IDs or categories corresponding to these items and ensuring the data is clean and well-structured for analysis.

transactions <- get_transactions()
promotions <- get_promotions()

bread_products <- products %>%
  filter(product_category %in% c("BAKED BREAD/BUNS/ROLLS", "BREAD"))

deli_meat_products <- products %>%
  filter(product_category == "DELI MEATS")

bread_transactions <- transactions %>%
  inner_join(bread_products, by = "product_id")

deli_meat_transactions <- transactions %>%
  inner_join(deli_meat_products, by = "product_id")


deli_baskets <- unique(deli_meat_transactions$basket_id)
bread_baskets <- unique(bread_transactions$basket_id)

common_baskets <- intersect(deli_baskets, bread_baskets)

co_purchase_transactions <- transactions %>%
  filter(basket_id %in% common_baskets) %>%
  inner_join(products, by = "product_id") %>%
  filter(product_category %in% c("BAKED BREAD/BUNS/ROLLS", "BREAD", "DELI MEATS"))

final_data <- co_purchase_transactions %>%
  select(basket_id, product_id, quantity, sales_value, product_category, product_type, transaction_timestamp) %>%
  distinct() %>%
  mutate(
    transaction_timestamp = as.Date(transaction_timestamp, format = "%Y-%m-%d"),
    quantity = as.integer(quantity)
  )

Two main datasets were used for the analysis. These datasets include transactions and product datasets.

Transaction Dataset Definition’s and Data Types

Variable.type <- lapply(transactions, class)
Variable.desc <- c("Uniquely identifies each household",
    "Uniquely identifies each store",
    "Uniquely identifies each purchase occasion", 
    "Uniquely identifies each product",
    "Number of the product purchased during the trip",
    "Amount of dollars the retailer receives from sale",
    "Discount applied due to the retailer's loyalty card program",
    "Discount applied due to a manufacturer coupon",
    "Discount applied due to retailer's match of manufacturer coupon",
    "Week of the transaction; Ranges 1-53",
    "Date and time of day when the transaction occurred"
    )
Variable.name1 <- colnames(transactions)
TransactionsDataDictionary <- as.data.frame(cbind(Variable.name1, Variable.type, Variable.desc))
colnames(TransactionsDataDictionary) <- c("Variable Name","Data Type","Variable Description")

row.names(TransactionsDataDictionary) <- NULL

TransactionsDataDictionary %>% 
  kbl() %>%
  kable_material(c("striped", "hover")) %>% 
    add_footnote("Source: https://cran.r-project.org/web/packages/completejourney/vignettes/completejourney.html")
Variable Name Data Type Variable Description
household_id character Uniquely identifies each household
store_id character Uniquely identifies each store
basket_id character Uniquely identifies each purchase occasion
product_id character Uniquely identifies each product
quantity numeric Number of the product purchased during the trip
sales_value numeric Amount of dollars the retailer receives from sale
retail_disc numeric Discount applied due to the retailer’s loyalty card program
coupon_disc numeric Discount applied due to a manufacturer coupon
coupon_match_disc numeric Discount applied due to retailer’s match of manufacturer coupon
week integer Week of the transaction; Ranges 1-53
transaction_timestamp POSIXct, POSIXt Date and time of day when the transaction occurred
a Source: https://cran.r-project.org/web/packages/completejourney/vignettes/completejourney.html

Product Dataset Definition’s and Data Types

Variable.type <- lapply(products, class)
Variable.desc <- c("Uniquely identifies each product",
    "Uniquely identifies each manufacturer",
    "Groups similar products together",
    "Indicates private or national label brand",
    "Groups similar products together at lower level",
    "Groups similar products together at lowest level",
    "Indicates package size (not available for all products)"
    )
Variable.name1 <- colnames(products)
ProductsDataDictionary <- as.data.frame(cbind(Variable.name1, Variable.type, Variable.desc))
colnames(ProductsDataDictionary) <- c("Variable Name","Data Type","Variable Description")

row.names(ProductsDataDictionary) <- NULL

ProductsDataDictionary %>% 
  kbl() %>%
  kable_material(c("striped", "hover")) %>% 
    add_footnote("Source: https://cran.r-project.org/web/packages/completejourney/vignettes/completejourney.html")
Variable Name Data Type Variable Description
product_id character Uniquely identifies each product
manufacturer_id character Uniquely identifies each manufacturer
department character Groups similar products together
brand factor Indicates private or national label brand
product_category character Groups similar products together at lower level
product_type character Groups similar products together at lowest level
package_size character Indicates package size (not available for all products)
a Source: https://cran.r-project.org/web/packages/completejourney/vignettes/completejourney.html

Exploratory Data Analysis

Average Basket Sales Value

transactions_with_products <- transactions %>%
  inner_join(products, by = "product_id")

deli_meat_baskets <- transactions_with_products %>%
  filter(product_category == "DELI MEATS") %>%
  pull(basket_id) %>%
  unique()

bread_baskets <- transactions_with_products %>%
  filter(product_category %in% c("BAKED BREAD/BUNS/ROLLS", "BREAD")) %>%
  pull(basket_id) %>%
  unique()

both_baskets <- intersect(deli_meat_baskets, bread_baskets)

avg_sales <- transactions_with_products %>%
  mutate(
    Category = case_when(
      basket_id %in% both_baskets ~ "Both",
      basket_id %in% deli_meat_baskets ~ "Deli Meat Only",
      basket_id %in% bread_baskets ~ "Bread Only",
      TRUE ~ "Other"
    )
  ) %>%
  group_by(Category) %>%
  summarise(AverageSalesValue = mean(sales_value, na.rm = TRUE)) %>%
  filter(Category %in% c("Deli Meat Only", "Bread Only", "Both"))

ggplot(avg_sales, aes(x = Category, y = AverageSalesValue)) +
  geom_point(aes(color = Category), size = 4, position = position_dodge(width = 0.5)) + 
  scale_y_continuous(labels = scales::dollar_format(), limits = c(2.50, 3.25)) +
  labs(
    title = "Average Basket Sales Value",
    subtitle = "Data compares average basket sales value that match critera",
    caption = "Data Source R Package: completejourney",
    x = "",
    y = "Average Sales Value"
  ) +
  theme_minimal() +
  theme(
    plot.subtitle = element_text(face = "italic"),
    plot.caption = element_text(hjust = 1, size = 7),
    legend.title = element_text(size = 9),
    legend.text = element_text(size = 7),
    legend.position = "none",
    axis.text.x = element_text(angle = 45, hjust = 1)
  ) +
  scale_color_manual(values = c("Deli Meat Only" = "red", "Bread Only" = "blue", "Both" = "green")) +
  geom_text(aes(label = sprintf("%.2f", AverageSalesValue)), position = position_dodge(width = 0.5), vjust = -1, size = 3)

The scatter plot depicts the average sales value of baskets with different product combinations, revealing that baskets containing only deli meats has the highest average sales value at $3.01. Baskets with only bread or both deli meats and bread show lower average values, $2.87 and $2.73 respectively. This suggests that when combined, these items contribute to higher overall sales, reinforcing the value of cross-merchandising strategies in grocery retail.

Probability of Bread Purchase Given Deli Meat Purchase

total_baskets <- length(unique(transactions$basket_id))
p_deli <- length(deli_baskets) / total_baskets
p_bread <- length(bread_baskets) / total_baskets
p_deli_and_bread <- length(common_baskets) / total_baskets
p_bread_given_deli <- p_deli_and_bread / p_deli

prob_data_revised <- data.frame(
  Category = c("P(Bread Only)", "P(Deli Meat Only)", "P(Bread given Deli Meat)"),
  Probability = c(p_bread, p_deli, p_bread_given_deli)
)

ggplot(prob_data_revised, aes(x = Category, y = Probability, color = Category)) +
  geom_point(size = 4, position = position_dodge(width = 0.5)) +  
  geom_text(aes(label = sprintf("%.2f", Probability)), position = position_dodge(width = 0.5), vjust = -1, size = 3) +  
  labs(
    title = "Impact of Deli Meats on Bread Purchases",
    subtitle = "Comparing overall bread purchases to the probability of purchasing bread when deli meats are present",
    caption = "Data Source R Package: completejourney",
    x = "Category",
    y = "Probability"
  ) +
  theme_minimal() +
  theme(
    plot.subtitle = element_text(face = "italic"),
    plot.caption = element_text(hjust = 1, size = 7),
    legend.title = element_text(size = 9),
    legend.text = element_text(size = 7),
    legend.position = "none",
    axis.text.x = element_text(angle = 45, hjust = 1)
  ) +
  scale_color_brewer(palette = "Set1") +
  ylim(0.00, 1.00)

Lastly, this graphs showcases the probability of a basket containing only Bread, only Deli Meat, and Bread when Deli Meats are present. As we can see from the data, the highest probability is when a basket contains Bread because it also contains Deli meat.

Summary

In this analysis, we explored the purchasing patterns within a retail dataset, focusing on the relationships between different product categories, particularly Deli Meats and various bakery items. Our findings reveal several key insights that can inform strategic decisions for retail marketing, inventory management, and store layout optimization.

Firstly, we identified the top 5 items that are frequently co-purchased with Deli Meats. This information not only highlights consumer preferences but also suggests potential product pairings that could be leveraged in marketing campaigns or store displays to enhance the shopping experience and increase sales.

When examining the average sales value of baskets containing only Deli Meats, only Bread, or both, it became evident that baskets with both items tend to have a higher average sales value. This suggests that Deli Meats and Bread are complementary products, and promoting them together could encourage consumers to purchase both, thereby increasing the overall basket size and value.

Furthermore, our analysis on the probability of purchasing Bread when Deli Meats are present in the basket revealed a significant increase compared to the overall probability of purchasing Bread. This indicates a strong correlation between these two product categories, highlighting an opportunity for retailers to capitalize on this relationship through targeted promotions and product placements.

Based on these insights, we recommend retailers consider creating promotional bundles that combine Deli Meats with popular bakery items to encourage higher basket values. Optimizing store layouts to place these complementary items in close proximity can facilitate co-purchases and enhance the shopping experience. Additionally, leveraging data on popular product combinations to tailor marketing messages and promotions, especially through loyalty programs, can resonate with consumer habits and drive increased sales in these categories.

In conclusion, this analysis underscores the importance of understanding consumer purchasing patterns and the relationships between product categories. By leveraging these insights, retailers can make informed decisions that align with consumer preferences and behaviors, ultimately driving sales and improving the overall shopping experience.