MyNixOS website logo
Description

Recency, Frequency and Monetary Value Analysis.

Tools for RFM (recency, frequency and monetary value) 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. Includes a 'shiny' app for interactive segmentation. References: i. Blattberg R.C., Kim BD., Neslin S.A (2008) <doi:10.1007/978-0-387-72579-6_12>.

rfm

CRAN_Status_Badge R buildstatus CoverageStatus

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")

Usage

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 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:

  • a unique customer id
  • date of transaction/order
  • transaction/order amount
# 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
#> # A tibble: 995 x 11
#>   customer_id    recency_days transaction_count amount recency_score
#>   <chr>                 <dbl>             <int>  <int>         <int>
#> 1 Abbey O'Reilly          205                 6    472             3
#> 2 Add Senger              140                 3    340             4
#> 3 Aden Lesch              194                 4    405             3
#> 4 Aden Murphy              98                 7    596             5
#> 5 Admiral Senger          132                 5    448             4
#> # i 990 more rows
#> # i 6 more variables: frequency_score <int>, monetary_score <int>,
#> #   rfm_score <dbl>, first_name <chr>, last_name <chr>, email <chr>

# 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
#> # A tibble: 995 x 12
#>   customer_id    segment         rfm_score transaction_count recency_days amount
#>   <chr>          <chr>               <dbl>             <int>        <dbl>  <int>
#> 1 Abbey O'Reilly Potential Loya~       343                 6          205    472
#> 2 Add Senger     New Customers         412                 3          140    340
#> 3 Aden Lesch     Loyal Customers       323                 4          194    405
#> 4 Aden Murphy    Potential Loya~       544                 7           98    596
#> 5 Admiral Senger Potential Loya~       433                 5          132    448
#> # i 990 more rows
#> # i 6 more variables: recency_score <int>, frequency_score <int>,
#> #   monetary_score <int>, first_name <chr>, last_name <chr>, email <chr>

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. Below is a quick demo of the shiny app:

Resources

Getting Help

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

Metadata

Version

0.3.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows