turf_calc_reach_one(): Computes the weighted reach and frequency for a
selected item portfolio using the compact matrix generated by
turf_prepare_reach_data(). Reach is the weighted proportion of respondents
who have at least one "hit" in the portfolio; frequency is the weighted
average number of hits among those reached.
turf_prepare_reach_data(): Transforms a binary threshold matrix (e.g.,
item-by-respondent) and optional respondent weights into a compact structure
of unique response patterns and their weighted frequencies. Intended for
downstream reach and frequency estimation.
Usage
turf_calc_reach_one(turf_data, portfolio)
turf_prepare_reach_data(threshold_matrix, weights = NULL)Arguments
- turf_data
A list of class
"turf_reach_data"as returned byturf_prepare_reach_data().- portfolio
A character vector of column names (i.e., item names) specifying the portfolio to evaluate.
- threshold_matrix
A binary matrix (values of 0/1) with respondents as rows and items as columns. Row names must uniquely identify each respondent.
- weights
Optional
data.framewith columnsidandweight, representing respondent IDs and their corresponding weights. IfNULL, equal weights of 1 are used.
Value
A named list with two numeric elements:
- reach
Weighted proportion of respondents with at least one positive hit among the portfolio attributes.
- frequency
Weighted mean number of positive hits among only those respondents counted as "reached."
A named list of class "turf_reach_data" with the following
components:
- matrix
A binary matrix where each row represents a unique respondent pattern across items.
- weights
A numeric vector indicating the weighted count (or frequency) for each pattern in the matrix.
Examples
# Create a sample probability matrix
turf_info <- prepare_turf_data(
example_md_turf_data,
id = "id",
attribute = "item",
utilities = "pwu",
probability = "probability"
)
prob_matrix <- turf_info$probabilities
# Define a portfolio
portfolio <- 1:3
threshold <- 1 / ncol(prob_matrix) * 2
## Convert probability matrix to binary based on threshold
threshold_matrix <- (prob_matrix >= threshold) * 1
turf_reach_data <- turf_prepare_reach_data(threshold_matrix, turf_info$weights)
#> ℹ Processed 213 respondents into 13 unique patterns.
## Calculate reach and frequency
turf_calc_reach_one(turf_reach_data, portfolio)
#> $reach
#> [1] 0.5352113
#>
#> $frequency
#> [1] 1.052632
#>