turf | R Documentation |
Runs Total Unduplicated Reach & Frequency with options for case weights, constraints on combinations, item weights, and three methods of a greedy algorithm.
turf(
data,
items,
case_weights,
item_weights,
k = 1,
depth = 1,
force_in,
force_in_together,
force_out,
force_out_together,
greedy_begin = Inf,
greedy_entry = "shapley",
progress = FALSE
)
data |
A data frame. |
items |
Columns on which to run TURF. Must contain only ones, zeros, or
|
case_weights |
An optional column of case weights to use in reach
calculations. Rows with |
item_weights |
An optional named vector of non-zero weights to associate with each item. Items not specified will be given a default weight of 1. Common examples are profit, revenue, or simply relative importance weights. |
k |
Set size, number of |
depth |
Number of |
force_in, force_in_together, force_out, force_out_together |
Options for reducing the number of combinations by adding constraints.
Use |
greedy_begin |
Set size at which the greedy algorithm will kick in. Default
is |
greedy_entry |
Method for entering variables into greedy algorithm.
Options are |
progress |
Display progress? Default is |
Need some dang details here.
library(dplyr)
# Simple 10-item TURF
x <- turf(FoodSample, Bisque:Ribeye, k = 1:10)
# With items forced in and out
# Forcing in "Ribeye"
# Forcing out items with an individual reach of < 10%
turf(
data = FoodSample,
items = Bisque:Ribeye,
k = 1:10,
force_in = Ribeye,
force_out = where(~mean(.x, na.rm = TRUE) < 0.1)
)
# Forcing items in and out together
turf(
data = FoodSample,
items = Bisque:Ribeye,
case_weights = weight,
k = c(1:4, 6:10),
force_in_together = together(
c(Chicken, Salmon),
c(Chili, Tofu, Turkey)
),
force_out_together = together(
matches("eye"),
c(2, 10)
),
greedy_begin = 10,
greedy_entry = "reach"
)
# Item weights
turf(
data = FoodSample,
items = 2:6,
k = 1:6,
item_weights = c(
Bisque = 1.2,
Chicken = 2.5,
Tofu = 2.9,
Chili = 1.7,
PorkChop = 3.0
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.