Skip to content

Commit

Permalink
NMS: renaming trial to reach
Browse files Browse the repository at this point in the history
  • Loading branch information
max-alletsee committed Feb 24, 2024
1 parent de52f0b commit c293fea
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions R/psm_weighted_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ psm_analysis_weighted <- function(toocheap, cheap, expensive, tooexpensive, desi


if (any(pi_calibrated < 0)) {
warning("Some of the purchase intent calibration values are smaller than 0. It seems that this is not a probability between 0 and 1. The interpretation of the trial/revenue values is not recommended.")
warning("Some of the purchase intent calibration values are smaller than 0. It seems that this is not a probability between 0 and 1. The interpretation of the reach/revenue values is not recommended.")
}

if (any(pi_calibrated > 1)) {
warning("Some of the purchase intent calibration values are larger than 1. It seems that this is not a probability between 0 and 1. The interpretation of the trial/revenue values is not recommended.")
warning("Some of the purchase intent calibration values are larger than 1. It seems that this is not a probability between 0 and 1. The interpretation of the reach/revenue values is not recommended.")
}
}

Expand Down Expand Up @@ -382,17 +382,17 @@ psm_analysis_weighted <- function(toocheap, cheap, expensive, tooexpensive, desi
# extract weights from survey design
nms_weights <- weights(psm_data_w)

# analysis of trial and revenue (mean trial for each price)
# analysis of reach and revenue (mean reach for each price)
# ... via weighted.mean() from base R
data_nms <- data.frame(
price = nms_prices,
trial = apply(nms_matrix, 2, stats::weighted.mean, w = nms_weights, na.rm = TRUE),
reach = apply(nms_matrix, 2, stats::weighted.mean, w = nms_weights, na.rm = TRUE),
row.names = seq_len(length(nms_prices))
)

data_nms$revenue <- data_nms$price * data_nms$trial
data_nms$revenue <- data_nms$price * data_nms$reach

price_optimal_trial <- data_nms$price[which.max(data_nms$trial)]
price_optimal_reach <- data_nms$price[which.max(data_nms$reach)]
price_optimal_revenue <- data_nms$price[which.max(data_nms$revenue)]
}

Expand Down Expand Up @@ -420,7 +420,7 @@ psm_analysis_weighted <- function(toocheap, cheap, expensive, tooexpensive, desi
if (isTRUE(nms)) {
output_psm$data_nms <- data_nms
output_psm$pi_scale <- data.frame(pi_scale, pi_calibrated)
output_psm$price_optimal_trial <- price_optimal_trial
output_psm$price_optimal_reach <- price_optimal_reach
output_psm$price_optimal_revenue <- price_optimal_revenue
}

Expand Down

0 comments on commit c293fea

Please sign in to comment.