knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "tools/README-"
)
options(tibble.print_min = 5, tibble.print_max = 5)

rfm

CRAN_Status_Badge R build status Coverage Status

Overview

Tools for customer segmentation using RFM (recency, frequency and monetary) analysis.

Installation

# Install rfm from CRAN
install.packages("rfm")

# Or the development version from GitHub
# install.packages("pak")
pak::pak("rsquaredacademy/rfm")
library(rfm)

Usage

RFM (recency, frequency, monetary) analysis is a behavior based technique used to segment customers by examining their transaction history such as:

It is based on the marketing axiom that 80% of your business comes from 20% of your customers. RFM analysis helps to identify customers who are more likely to respond to promotions by segmenting them into various categories.

To calculate the RFM score we need the following info for each customer:

# analysis date
analysis_date <- as.Date('2006-12-31')

# generate rfm score
rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date,
revenue, analysis_date)

# rfm score
rfm_result

# segment names
segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers",
                   "Promising", "New Customers", "Can't Lose Them",
                   "At Risk", "Need Attention", "About To Sleep", "Lost")

# segment intervals
recency_lower <-   c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1)
recency_upper <-   c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1)
frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1)
frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5)
monetary_lower <-  c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1)
monetary_upper <-  c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5)

# generate segments
segments <- rfm_segment(rfm_result, segment_names, recency_lower,
recency_upper, frequency_lower, frequency_upper, monetary_lower,
monetary_upper)

segments

Plotting Engines

rfm supports the following plotting engines:

Shiny App

rfm includes a shiny app for interactive RFM analysis. In the latest release, we have added project management features to allow users to save/clone their projects.

Resources

Getting Help

If you encounter a bug, please file a minimal reproducible example using reprex on github. For questions and clarifications, use StackOverflow.



rsquaredacademy/rfm documentation built on Feb. 29, 2024, 2:43 a.m.