g6tr.brand starts from a respondent-by-brand panel and
lets you attach tidy, user-prepared modules on top of it. This vignette
focuses on the current constructor, funnel stages, and attributes.
Create A Brand Object
brand <- brand_create(
respondents = c("r2", "r1"),
brands = factor(
c("Nike", "Adidas"),
levels = c("Nike", "Adidas")
)
)
#> ✔ Created brand analysis object: 2 respondents x 2 brands = 4 panel rows.
brand
#>
#> ── Brand Analysis ──────────────────────────────────────────────────────────────
#> Respondents: 2
#> Brands: 2 ("Nike" and "Adidas")
#> Funnel stages: 0 (use `brand_add_funnel_stage()` to add them)
#> NPS attached: FALSE (use `brand_add_nps()` to add NPS data)
#> Attributes: 0 (use `brand_add_attributes()` to attach them)
#> Weights: all 1
#> Data: 0 additional columns attached
#> Effect models: 0
#> Performance models: 0The brand order comes from the factor levels you pass to
brand_create(), the base panel always starts with
weight = 1, and printing the object now shows a simple flow
map for the stored funnel graph.
Add A Stage Without Warnings
The first funnel stage usually covers the full respondent-brand panel, so a clean stage can be attached with no warnings.
awareness <- tibble::tibble(
response_id = c("r1", "r1", "r2", "r2"),
brand = c("Nike", "Adidas", "Nike", "Adidas"),
response = c(1, 0, 1, 1)
)
brand <- brand_add_funnel_stage(
brand = brand,
stage_data = awareness,
stage_name = "awareness"
)
#> ✔ Funnel stage [root -> awareness] supplied 4 rows (2 respondents x 2 brands).
#> • root -> 1: 3 rows (75.0%) across 2 respondents.
#> • root -> 0: 1 rows (25.0%) across 1 respondents.
brand$funnel$awareness
#> # A tibble: 4 × 3
#> response_id brand response
#> <chr> <fct> <dbl>
#> 1 r1 Nike 1
#> 2 r1 Adidas 0
#> 3 r2 Nike 1
#> 4 r2 Adidas 1
brand$data
#> # A tibble: 4 × 4
#> response_id brand weight funnel$awareness
#> <chr> <fct> <dbl> <dbl>
#> 1 r1 Nike 1 1
#> 2 r1 Adidas 1 0
#> 3 r2 Nike 1 1
#> 4 r2 Adidas 1 1Add A Downstream Stage Without Warnings
For a downstream stage, the quietest path is to provide the full
respondent-brand panel and keep rows outside the parent stage as
NA.
consideration_full <- tibble::tibble(
response_id = c("r1", "r1", "r2", "r2"),
brand = c("Nike", "Adidas", "Nike", "Adidas"),
response = c(1, NA_real_, 0, 1)
)
brand <- brand_add_funnel_stage(
brand = brand,
stage_data = consideration_full,
stage_name = "consideration",
parent_stage = "awareness"
)
#> ✔ Funnel stage [awareness -> consideration] supplied 4 rows (2 respondents x 2 brands).
#> • 1 -> 1: 2 rows (66.7%) across 2 respondents.
#> • 1 -> 0: 1 rows (33.3%) across 1 respondents.
#> • 0 -> NA: 1 rows (100.0%) across 1 respondents.
brand$funnel$consideration
#> # A tibble: 4 × 3
#> response_id brand response
#> <chr> <fct> <dbl>
#> 1 r1 Nike 1
#> 2 r1 Adidas NA
#> 3 r2 Nike 0
#> 4 r2 Adidas 1
brand$data
#> # A tibble: 4 × 4
#> response_id brand weight funnel$awareness $consideration
#> <chr> <fct> <dbl> <dbl> <dbl>
#> 1 r1 Nike 1 1 1
#> 2 r1 Adidas 1 0 NA
#> 3 r2 Nike 1 1 0
#> 4 r2 Adidas 1 1 1This call stays quiet because:
- every
response_id/brandpair from the base panel is present - rows outside the parent stage are kept as
NArather than forced to0or1
Re-Attach The Same Stage
Re-running the same stage is allowed. The package warns before replacing the stored stage.
brand <- brand_add_funnel_stage(
brand = brand,
stage_data = awareness,
stage_name = "awareness"
)
#> Warning: awareness is already attached and will be overwritten.
#> ✔ Funnel stage [root -> awareness] supplied 4 rows (2 respondents x 2 brands).
#> • root -> 1: 3 rows (75.0%) across 2 respondents.
#> • root -> 0: 1 rows (25.0%) across 1 respondents.The same overwrite workflow also works for downstream stages. Here
parent_stage is omitted on purpose. Because
consideration already exists, the function reuses the
stored parent definition for that stage.
brand <- brand_add_funnel_stage(
brand = brand,
stage_data = consideration_full,
stage_name = "consideration"
)
#> Warning: consideration is already attached and will be
#> overwritten.
#> ✔ Funnel stage [root -> consideration] supplied 4 rows (2 respondents x 2 brands).
#> • root -> 1: 2 rows (50.0%) across 2 respondents.
#> • root -> 0: 1 rows (25.0%) across 1 respondents.
#> • root -> NA: 1 rows (25.0%) across 1 respondents. Use `repair = TRUE` to convert NA -> 0.When Warnings Happen
Warnings are expected when the supplied stage data does not match the current panel or the parent-stage split.
This example is intentionally imperfect:
- one positive
awarenesscase is missing entirely - one row has a downstream response even though
awareness == 0 - one valid downstream row has a missing response
- the stage is not supplied for the full respondent-brand panel
brand_warning <- brand_create(
respondents = c("r1", "r2"),
brands = factor(
c("Nike", "Adidas"),
levels = c("Nike", "Adidas")
)
)
#> ✔ Created brand analysis object: 2 respondents x 2 brands = 4 panel rows.
brand_warning <- brand_add_funnel_stage(
brand = brand_warning,
stage_data = awareness,
stage_name = "awareness"
)
#> ✔ Funnel stage [root -> awareness] supplied 4 rows (2 respondents x 2 brands).
#> • root -> 1: 3 rows (75.0%) across 2 respondents.
#> • root -> 0: 1 rows (25.0%) across 1 respondents.
consideration_bad <- tibble::tibble(
response_id = c("r1", "r1", "r2"),
brand = c("Nike", "Adidas", "Nike"),
response = c(1, 1, NA_real_)
)
brand_warning <- brand_add_funnel_stage(
brand = brand_warning,
stage_data = consideration_bad,
stage_name = "consideration",
parent_stage = "awareness"
)
#> ✔ Funnel stage [awareness -> consideration] supplied 3 rows (2 respondents x 2 brands).
#> • 1 -> 1: 1 rows (33.3%) across 1 respondents.
#> • 1 -> NA: 2 rows (66.7%) across 1 respondents. Use `repair = TRUE` to convert NA -> 0.
#> • 0 -> 1: 1 rows (100.0%) across 1 respondents. No automatic fix recommended, review source data!brand_add_funnel_stage() only reports issues. It does
not rewrite the supplied values. The printed funnel graph and
brand_funnel_status() both flag the affected downstream
stage as needing a fix.
brand_warning
#>
#> ── Brand Analysis ──────────────────────────────────────────────────────────────
#> Respondents: 2
#> Brands: 2 ("Nike" and "Adidas")
#> Funnel stages: 2
#> awareness [OK]
#> └──▶ consideration [DANGER + WARN]
#> NPS attached: FALSE (use `brand_add_nps()` to add NPS data)
#> Attributes: 0 (use `brand_add_attributes()` to attach them)
#> Weights: all 1
#> Data: 0 additional columns attached
#> Effect models: 0
#> Performance models: 0
brand_funnel_status(brand_warning)
#> # A tibble: 2 × 9
#> stage_name parent_stage status warning_rows danger_rows absent_stage_rows
#> <chr> <chr> <chr> <int> <int> <int>
#> 1 awareness "" ok 0 0 0
#> 2 consideration "awareness" warning… 2 1 0
#> # ℹ 3 more variables: absent_stage_rows_when_parent_1 <int>,
#> # missing_response_rows_when_parent_1 <int>,
#> # response_rows_when_parent_not_1 <int>
brand_warning$funnel$consideration
#> # A tibble: 3 × 3
#> response_id brand response
#> <chr> <fct> <dbl>
#> 1 r1 Nike 1
#> 2 r1 Adidas 1
#> 3 r2 Nike NA
brand_warning$data
#> # A tibble: 4 × 4
#> response_id brand weight funnel$awareness $consideration
#> <chr> <fct> <dbl> <dbl> <dbl>
#> 1 r1 Nike 1 1 1
#> 2 r1 Adidas 1 0 1
#> 3 r2 Nike 1 1 NA
#> 4 r2 Adidas 1 1 NARepairs happen inline by passing repair = TRUE when you
add the stage.
brand_fix <- brand_create(
respondents = c("r1", "r2"),
brands = factor(
c("Nike", "Adidas"),
levels = c("Nike", "Adidas")
)
)
#> ✔ Created brand analysis object: 2 respondents x 2 brands = 4 panel rows.
brand_fix <- brand_add_funnel_stage(
brand = brand_fix,
stage_data = awareness,
stage_name = "awareness"
)
#> ✔ Funnel stage [root -> awareness] supplied 4 rows (2 respondents x 2 brands).
#> • root -> 1: 3 rows (75.0%) across 2 respondents.
#> • root -> 0: 1 rows (25.0%) across 1 respondents.
brand_fix <- brand_add_funnel_stage(
brand = brand_fix,
stage_data = consideration_bad,
stage_name = "consideration",
parent_stage = "awareness",
repair = TRUE
)
#> ✔ Funnel stage [awareness -> consideration] supplied 3 rows (2 respondents x 2 brands).
#> • 1 -> 1: 1 rows (33.3%) across 1 respondents.
#> • 1 -> 0 (repaired from NA): 2 rows (66.7%) across 1 respondents.
#> • 0 -> 1: 1 rows (100.0%) across 1 respondents. No automatic fix recommended, review source data!
brand_fix
#>
#> ── Brand Analysis ──────────────────────────────────────────────────────────────
#> Respondents: 2
#> Brands: 2 ("Nike" and "Adidas")
#> Funnel stages: 2
#> awareness [OK]
#> └──▶ consideration [DANGER + WARN]
#> NPS attached: FALSE (use `brand_add_nps()` to add NPS data)
#> Attributes: 0 (use `brand_add_attributes()` to attach them)
#> Weights: all 1
#> Data: 0 additional columns attached
#> Effect models: 0
#> Performance models: 0
brand_funnel_status(brand_fix)
#> # A tibble: 2 × 9
#> stage_name parent_stage status warning_rows danger_rows absent_stage_rows
#> <chr> <chr> <chr> <int> <int> <int>
#> 1 awareness "" ok 0 0 0
#> 2 consideration "awareness" warning… 1 1 0
#> # ℹ 3 more variables: absent_stage_rows_when_parent_1 <int>,
#> # missing_response_rows_when_parent_1 <int>,
#> # response_rows_when_parent_not_1 <int>
brand_fix$funnel$consideration
#> # A tibble: 3 × 3
#> response_id brand response
#> <chr> <fct> <dbl>
#> 1 r1 Nike 1
#> 2 r1 Adidas 1
#> 3 r2 Nike 0
brand_fix$data
#> # A tibble: 4 × 4
#> response_id brand weight funnel$awareness $consideration
#> <chr> <fct> <dbl> <dbl> <dbl>
#> 1 r1 Nike 1 1 1
#> 2 r1 Adidas 1 0 1
#> 3 r2 Nike 1 1 0
#> 4 r2 Adidas 1 1 0In this case the function:
- fills valid parent-stage rows with missing responses as
0 - sets invalid downstream responses to
NA - backfills missing parent-stage rows with
0
After repair, the printed graph and
brand_funnel_status() both show the stage as
[OK].
Multiple Roots And Shared Parents
Funnels do not have to be a single straight line. You can keep multiple root stages, and several downstream stages can share the same parent.
brand_graph <- brand_create(
respondents = c("r1", "r2"),
brands = factor(
c("Nike", "Adidas"),
levels = c("Nike", "Adidas")
)
)
#> ✔ Created brand analysis object: 2 respondents x 2 brands = 4 panel rows.
salience <- tibble::tibble(
response_id = c("r1", "r1", "r2", "r2"),
brand = c("Nike", "Adidas", "Nike", "Adidas"),
response = c(1, 1, 0, 1)
)
purchase <- tibble::tibble(
response_id = c("r1", "r1", "r2", "r2"),
brand = c("Nike", "Adidas", "Nike", "Adidas"),
response = c(1, 0, 0, 1)
)
preference <- tibble::tibble(
response_id = c("r1", "r1", "r2", "r2"),
brand = c("Nike", "Adidas", "Nike", "Adidas"),
response = c(1, NA_real_, 0, 1)
)
brand_graph <- brand_add_funnel_stage(
brand = brand_graph,
stage_data = awareness,
stage_name = "awareness",
verbose = FALSE
)
brand_graph <- brand_add_funnel_stage(
brand = brand_graph,
stage_data = salience,
stage_name = "salience",
verbose = FALSE
)
brand_graph <- brand_add_funnel_stage(
brand = brand_graph,
stage_data = purchase,
stage_name = "purchase",
parent_stage = "awareness",
verbose = FALSE
)
brand_graph <- brand_add_funnel_stage(
brand = brand_graph,
stage_data = preference,
stage_name = "preference",
parent_stage = "awareness",
verbose = FALSE
)
brand_graph
#>
#> ── Brand Analysis ──────────────────────────────────────────────────────────────
#> Respondents: 2
#> Brands: 2 ("Nike" and "Adidas")
#> Funnel stages: 4
#> awareness [OK]
#> ├──▶ purchase [DANGER]
#> └──▶ preference [OK]
#> salience [OK]
#> NPS attached: FALSE (use `brand_add_nps()` to add NPS data)
#> Attributes: 0 (use `brand_add_attributes()` to attach them)
#> Weights: all 1
#> Data: 0 additional columns attached
#> Effect models: 0
#> Performance models: 0Attach Attributes
Attributes are stored in long form in
brand$attributes[[set_name]], each mapped to a stable
attribute_col model name. Scores are added in a separate
step with brand_score_attributes().
attributes <- tibble::tibble(
response_id = rep(c("r1", "r2"), each = 4),
brand = rep(c("Nike", "Nike", "Adidas", "Adidas"), times = 2),
attribute = factor(
rep(c("Style", "Quality"), times = 4),
levels = c("Style", "Quality")
),
response = factor(
c("Poor", "Average", "Good", "Poor", "Good", "Poor", "Average", "Good"),
levels = c("Poor", "Average", "Good")
)
)
brand <- brand_add_attributes(
brand = brand,
attribute_data = attributes
)
#> ✔ Attributes [default] supplied 8 rows (2 attributes x 2 respondents x 2 brands).
#> ✔ [default] all 2 brands have all 2 attributes.
#> ℹ Summary by attribute [default]
#> • Style: 4 rows (2 respondents x 2 brands)
#> • Quality: 4 rows (2 respondents x 2 brands)
brand$attributes[["default"]] <- brand$attributes[["default"]] |>
dplyr::mutate(score = brand_score_attributes(response))
#> ℹ [attributes / centered] converting attribute responses to numeric scores:
#> -1 <- Poor
#> 0 <- Average
#> 1 <- Good
brand$attributes[["default"]]
#> # A tibble: 8 × 6
#> response_id brand attribute response attribute_col score
#> <chr> <fct> <fct> <fct> <chr> <dbl>
#> 1 r1 Nike Style Poor style -1
#> 2 r1 Nike Quality Average quality 0
#> 3 r1 Adidas Style Good style 1
#> 4 r1 Adidas Quality Poor quality -1
#> 5 r2 Nike Style Good style 1
#> 6 r2 Nike Quality Poor quality -1
#> 7 r2 Adidas Style Average style 0
#> 8 r2 Adidas Quality Good quality 1
brand$data
#> # A tibble: 4 × 4
#> response_id brand weight funnel$awareness $consideration
#> <chr> <fct> <dbl> <dbl> <dbl>
#> 1 r1 Nike 1 1 1
#> 2 r1 Adidas 1 0 NA
#> 3 r2 Nike 1 1 0
#> 4 r2 Adidas 1 1 1That is the minimal current workflow:
- create the base panel
- add funnel stages one by one
- re-run stages when the scripted input changes
- use warnings to catch missing rows or parent-stage mismatches
- pass
repair = TRUEtobrand_add_funnel_stage()to repair stages as you add them - attach attributes once the panel is ready