Skip to content

Commit a8c0031

Browse files
committed
replaced vignettes with articles
1 parent 12241e1 commit a8c0031

File tree

8 files changed

+191
-150
lines changed

8 files changed

+191
-150
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
^test.R
2020
^test_script.R
2121
non_standard_calendar.R
22+
^vignettes/articles$

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Imports:
2323
janitor,
2424
stringr
2525
LazyData: true
26-
VignetteBuilder: quarto, knitr
2726
Suggests:
2827
testthat (>= 3.0.0),
2928
cohorts,

vignettes/abc.qmd

Lines changed: 0 additions & 127 deletions
This file was deleted.

vignettes/articles/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.html
2+
*.R

vignettes/articles/abc.qmd

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
---
2+
title: "ABC Segmentation"
3+
subtitle: "How to use segmentation strategies to simplify your analysis"
4+
5+
---
6+
7+
```{r}
8+
#| echo: false
9+
quarto::write_yaml_metadata_block(
10+
date=format(Sys.Date())
11+
)
12+
```
13+
14+
15+
### Introduction
16+
17+
In business and financial analytics, the **ABC classification** method is widely used to categorize items, customers, or other groups according to their relative contribution to a total metric.
18+
19+
The `abc()` function provides a flexible and robust way to perform ABC segmentation, either based on **transaction counts** or the sum of a **numeric variable** such as sales margin or revenue.
20+
21+
### Function Purpose
22+
23+
`abc()`:
24+
25+
- Segments a dataset into categories (A, B, C, etc.) based on cumulative contribution.
26+
- Allows for **custom break points** (e.g., top 10% = A, next 40% = B, etc.).
27+
- Works on both **grouped tibbles** and **database-backed objects**.
28+
- Returns a **segment object**, which is processed by `calculate()` to produce a table of results.
29+
30+
### How It Works
31+
32+
> `fpaR::abc()` requires a grouped tibble or lazy DBI object using `dplyr::group_by()` to specify the groups that drive the contribution
33+
34+
**Value Capture**
35+
36+
- If `.value` is provided, the the column is aggregate per group; otherwise, it counts rows.
37+
38+
**Category Values**
39+
40+
- Provide the break points break points that are used to set the cumulative categories. Each break point will get a letter category starting with 'A'
41+
- If you want to see the stores that make up the top 40% of revenue follow by top 70% and then 90% you should put in `c(0.4,.7,.9,1)`
42+
43+
44+
```{r}
45+
#| label: tbl-abc-args
46+
#| echo: false
47+
#| eval: true
48+
49+
tibble::tibble(
50+
Argument = c(".data", "category_values", ".value"),
51+
Description = c(
52+
"A grouped tibble or DBI object (using dplyr::group_by())",
53+
"A numeric vector of breakpoints between 0 and 1, representing cumulative proportions for ABC categories.",
54+
"Optional. A column to sum for categorization. If not provided, the function counts the number of rows per group."
55+
)
56+
) |> tinytable::tt()
57+
58+
```
59+
60+
61+
62+
```{r}
63+
#| label: abc-example
64+
#| echo: true
65+
#| eval: true
66+
67+
# Example
68+
69+
contoso::sales |>
70+
dplyr::group_by(store_key) |>
71+
fpaR::abc(
72+
category_values = c(0.4,.7,.9,1),
73+
.value = margin
74+
)
75+
```
76+
77+
The function returns a **segment object**. Use `calculate()` to generate the ABC classification table:
78+
79+
```{r}
80+
#| label: var
81+
#| echo: true
82+
#| eval: false
83+
#| warning: false
84+
#| message: false
85+
#| include: true
86+
contoso::sales |>
87+
dplyr::group_by(store_key) |>
88+
fpaR::abc(
89+
category_values = c(0.4,.7,.9,1),
90+
.value = margin
91+
) |>
92+
fpaR::calculate()
93+
```
94+
95+
```{r}
96+
#| label: tbl-output-no-echo
97+
#| echo: false
98+
#| eval: true
99+
#| warning: false
100+
#| message: false
101+
#| include: true
102+
#| column: screen
103+
104+
contoso::sales |>
105+
dplyr::filter(
106+
store_key!="999999"
107+
) |>
108+
dplyr::group_by(store_key) |>
109+
fpaR::abc(
110+
category_values = c( 0.4,.7,.9,1),
111+
.value = margin
112+
) |>
113+
fpaR::calculate() |>
114+
dplyr::collect() |>
115+
dplyr::arrange(row_id) |>
116+
head(10) |>
117+
tinytable::tt()
118+
```
119+
120+
121+
This table contains grouped data with various metrics, highlighting the contribution of each group in terms of both value and transaction count. Below is an explanation of the key columns and how to interpret the results:
122+
123+
### Understanding the Results
124+
125+
- Store 540 has a margin of $7,812.11 ("ABC Margin"), which accounts for about 4% ("prop_total") of the total margin across all stores
126+
127+
- The "cum_sum" column tracks the running total of values (e.g., revenue or count) for each store, showing the cumulative sum up to that row
128+
129+
- The "cum_prop_total" column shows each store's contribution as a percentage of the total margin as you move down the table
130+
131+
- The store with the highest contribution has a "row_id" of 1 and is assigned to the first category segment ('A') via the "category_name" column
132+
133+
- The "max_row_id" shows that there are 57 additional stores in the same category ('A')
134+
135+
- The "cum_unit_prop" column tracks the cumulative contribution from a transaction count perspective, similar to cum_prop_total but at the unit level
136+
137+
- The category_value and category_name columns define the breakpoints you provided, assigning stores to categories (e.g., 'A', 'B', 'C') based on their cumulative contribution
138+
139+
This is summarized in @tbl-output below
140+
141+
142+
```{r}
143+
#| label: tbl-output
144+
#| echo: false
145+
#| eval: true
146+
#| warning: false
147+
#| message: false
148+
#| column: screen
149+
#| include: true
150+
151+
tibble::tibble(
152+
Column_Name = c("cum_sum", "prop_total", "cum_prop_total", "row_id", "max_row_id", "cum_unit_prop", "category_value", "category_name"),
153+
Description = c(
154+
"The cumulative sum of the specified values (e.g., revenue, count, etc.), aggregated per group. Represents the total value up to that row.",
155+
"The proportion of the total for each row's value. Shows the percentage of the total represented by the current row's contribution.",
156+
"The cumulative proportion of the total, showing the running total percentage of the entire dataset as you move through the rows.",
157+
"The unique identifier for the row, often used to track or identify specific rows in the dataset. Typically sequential ID or index.",
158+
"The maximum row ID in the current group (if grouping is applied), representing the total number of rows in the group.",
159+
"The cumulative proportion of the unit values, similar to cum_prop_total, but typically used when the unit is treated as aggregate.",
160+
"The category value that corresponds to the cumulative proportion break points (e.g., top 10%, top 40%, etc.). Based on the break points provided.",
161+
"The name of the category assigned to each row based on the cumulative contribution. Categories are represented by letters (A, B, C, etc.)."
162+
),
163+
Example_Values = c(
164+
"1000, 2500, 4000",
165+
"0.10, 0.25, 0.40",
166+
"0.10, 0.35, 0.75",
167+
"1, 2, 3",
168+
"5, 5, 5",
169+
"0.10, 0.30, 0.70",
170+
"0.4, 0.7, 0.9",
171+
"\"A\", \"B\", \"C\""
172+
)
173+
) |>
174+
tinytable::tt()
175+
176+
177+
```
178+
179+
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ title: "Standard vs. 5-5-4 Calendar"
33
subtitle: "What do we mean by standard and non-standard calendar?"
44
format: html
55
author: "Alejandro Hagan"
6-
vignette: >
7-
%\VignetteIndexEntry{Standard vs. 5-5-4 Calendar}
8-
%\VignetteEngine{quarto::html}
9-
%\VignetteEncoding{UTF-8}
106
---
117

128
```{r}
@@ -84,4 +80,3 @@ The **5-5-4 calendar** is a retail accounting calendar designed to simplify peri
8480

8581
Understanding the difference between standard and 5-5-4 calendars helps organizations choose the right system for their reporting needs. While standard calendars are common for financial statements and general business operations, the 5-5-4 calendar is preferred in retail for more consistent period comparisons and operational planning.
8682

87-
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
2-
title: "Cohort"
3-
vignette: >
4-
%\VignetteIndexEntry{Cohort}
5-
%\VignetteEngine{quarto::html}
6-
%\VignetteEncoding{UTF-8}
2+
title: "cohort"
73
---
4+
85
# Introduction
96

107
Cohort analysis is a common method for tracking groups of users, customers, or entities over time to understand retention, behavior, or trends.
@@ -54,18 +51,17 @@ The `cohort()` function in **fpaR** provides a **database-friendly implementatio
5451

5552
The function returns a **segment object**. Use `calculate()` to retrieve the cohort table:
5653

57-
```r
54+
```{r}
55+
#|eval: false
5856
library(dplyr)
5957
6058
# Example cohort analysis
61-
seg_obj <- cohort(.data = contoso::sales,
59+
fpaR::cohort(.data = contoso::sales,
6260
.date = order_date,
6361
.value = customer_key,
6462
calendar_type = "standard",
6563
time_unit = "month",
66-
period_label = FALSE)
64+
period_label = FALSE
65+
)
6766
68-
# Calculate the cohort table
69-
cohort_tbl <- calculate(seg_obj)
70-
cohort_tbl <- dplyr::collect(cohort_tbl) # if using a DBI objec
7167
```

0 commit comments

Comments
 (0)