-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathREADME.Rmd
More file actions
147 lines (96 loc) · 4.7 KB
/
README.Rmd
File metadata and controls
147 lines (96 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "tools/README-"
)
```
# rfm
> Tools for RFM Analysis
[](https://cran.r-project.org/package=rfm) [](https://cran.r-project.org/web/checks/check_results_rfm.html)
[](https://travis-ci.org/rsquaredacademy/rfm) [](https://ci.appveyor.com/project/rsquaredacademy/rfm) [](https://codecov.io/github/rsquaredacademy/rfm?branch=master) [](https://cran.r-project.org/package=rfm) 
## 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
```{r gh-installation, eval = FALSE}
# Install rfm from CRAN
install.packages("rfm")
# Or the development version from GitHub
# install.packages("devtools")
devtools::install_github("rsquaredacademy/rfm")
```
```{r, echo=FALSE, message=FALSE}
library(rfm)
options(tibble.width = Inf)
```
## Articles
- [RFM Customer Data](https://rfm.rsquaredacademy.com/articles/rfm-customer-level-data.html)
- [RFM Transaction Data](https://rfm.rsquaredacademy.com/articles/rfm-transaction-level-data.html)
## 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.
```{r rfm_table_order}
analysis_date <- lubridate::as_date('2006-12-31')
rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date)
rfm_result
```
### 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.
```{r heatmap, fig.align='center', fig.width=8, fig.height=6}
rfm_heatmap(rfm_result)
```
### Bar Chart
Use `rfm_bar_chart()` to generate the distribution of monetary scores for the different combinations of frequency and recency scores.
```{r barchart, fig.align='center', fig.width=8, fig.height=6}
rfm_bar_chart(rfm_result)
```
### Histogram
Use `rfm_histograms()` 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)
```{r rfmhist, fig.align='center', fig.width=8, fig.height=6}
rfm_histograms(rfm_result)
```
### Customers by Orders
Visualize the distribution of customers across orders.
```{r rfmorders, fig.align='center', fig.width=8, fig.height=6}
rfm_order_dist(rfm_result)
```
### Scatter Plots
The best customers are those who:
- bought most recently
- most often
- and spend the most
Now let us examine the relationship between the above.
#### Recency vs Monetary Value
```{r mr, fig.align='center', fig.width=7, fig.height=7}
rfm_rm_plot(rfm_result)
```
#### Frequency vs Monetary Value
```{r fm, fig.align='center', fig.width=7, fig.height=7}
rfm_fm_plot(rfm_result)
```
#### Recency vs Frequency
```{r fr, fig.align='center', fig.width=7, fig.height=7}
rfm_rf_plot(rfm_result)
```
## Getting Help
If you encounter a bug, please file a minimal reproducible example using
[reprex](https://reprex.tidyverse.org/index.html) on github. For questions and
clarifications, use [StackOverflow](https://stackoverflow.com/).