rfm
Tools for RFM Analysis
Overview
Tools for RFM (recency, frequency and monetary) analysis. Generate RFM score from both transaction and customer level data. Visualize the relationship between recency, frequency and monetary value using heatmap, histograms, bar charts and scatter plots.
Installation
# Install rfm from CRAN
install.packages("rfm")
# Or the development version from GitHub
# install.packages("devtools")
devtools::install_github("rsquaredacademy/rfm")
Articles
Usage
Introduction
RFM (recency, frequency, monetary) analysis is a behavior based technique used to segment customers by examining their transaction history such as
- how recently a customer has purchased (recency)
- how often they purchase (frequency)
- how much the customer spends (monetary)
It is based on the marketing axiom that 80% of your business comes from 20% of your customers. RFM helps to identify customers who are more likely to respond to promotions by segmenting them into various categories.
Data
To calculate the RFM score for each customer we need transaction data which should include the following:
- a unique customer id
- date of transaction/order
- transaction/order amount
RFM Table
rfm uses consistent prefix rfm_
for easy tab completion. Use
rfm_table_order()
to generate the RFM score.
analysis_date <- as.Date('2006-12-31')
rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date)
rfm_result
#> # A tibble: 995 x 8
#> customer_id recency_days transaction_count amount recency_score
#> <chr> <dbl> <int> <dbl> <int>
#> 1 Abbey O'Reilly DVM 205 6 472 3
#> 2 Add Senger 140 3 340 4
#> 3 Aden Lesch Sr. 194 4 405 3
#> 4 Admiral Senger 132 5 448 4
#> 5 Agness O'Keefe 90 9 843 5
#> 6 Aileen Barton 84 9 763 5
#> 7 Ailene Hermann 281 8 699 3
#> 8 Aiyanna Bruen PhD 246 4 157 3
#> 9 Ala Schmidt DDS 349 3 363 2
#> 10 Alannah Borer 619 4 196 1
#> # i 985 more rows
#> # i 3 more variables: frequency_score <int>, monetary_score <int>,
#> # rfm_score <dbl>
Heat Map
The heat map shows the average monetary value for different categories of recency and frequency scores. Higher scores of frequency and recency are characterized by higher average monetary value as indicated by the darker areas in the heatmap.
rfm_plot_heatmap(rfm_result)
Bar Chart
Use rfm_plot_bar_chart()
to generate the distribution of monetary
scores for the different combinations of frequency and recency scores.
rfm_plot_bar_chart(rfm_result)
Histogram
Use rfm_plot_histogram()
to examine the relative distribution of
- monetary value (total revenue generated by each customer)
- recency days (days since the most recent visit for each customer)
- frequency (transaction count for each customer)
rfm_plot_histogram(rfm_result)
Customers by Orders
Visualize the distribution of customers across orders.
rfm_plot_order_dist(rfm_result)
Getting Help
If you encounter a bug, please file a minimal reproducible example using reprex on github. For questions and clarifications, use StackOverflow.