I am trying to recreate code from this article: http://datafeedtoolbox.com/attribution-theory-the-two-best-models-for-algorithmic-marketing-attribution-implemented-in-apache-spark-and-r/ but additionaly, I'd like to count conversion value, not only number of conversions. Here is the code from article:
shap_vals = as.data.frame(coalitions(number_of_channels)$Binary)
names(shap_vals) = c("Email","Natural_Search","Affiliates",
"Paid_Search","Display","Social_Media")
coalition_mat = shap_vals
shap_vals[2^number_of_channels,] = Shapley_value(touch_combo_conv_rate$conv_rate, game="profit")
for(i in 2:(2^number_of_channels-1)){
if(sum(coalition_mat[i,]) == 1){
shap_vals[i,which(shap_vals[i,]==1)] = touch_combo_conv_rate[i,"conv_rate"]
}else if(sum(coalition_mat[i,]) > 1){
if(sum(coalition_mat[i,]) < number_of_channels){
channels_of_interest = which(coalition_mat[i,] == 1)
char_func = data.frame(rates = touch_combo_conv_rate[1,"conv_rate"])
for(j in 2:i){
if(sum(coalition_mat[j,channels_of_interest])>0 &
sum(coalition_mat[j,-channels_of_interest])==0)
char_func = rbind(char_func,touch_combo_conv_rate[j,"conv_rate"])
}
shap_vals[i,channels_of_interest] =
Shapley_value(char_func$rates, game="profit")
}
}
}
Do you have some ideas what approach should I take on, to calculate conversion value properly? When I tried I had a lot of negative values. My data frame looks like this: