Other use cases
This page collects use cases for each function included in ChannelAttribution Pro.
Load the libray and data
library(ChannelAttributionPro)
#Load Data
data(PathData)
password="yourpassword"
download.file(url="https://channelattribution.net/csv/Data.csv","Data.csv")
heuristic_models
#Perform transaction level attribution from a data.frame
path_attribution=heuristic_models(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", cha_sep=">",
password=password)
print(path_attribution,max=100)
#Return non converting paths in the output data.frame
path_attribution=heuristic_models(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", cha_sep=">",
flg_write_nulls=1, password=password)
print(path_attribution,max=100)
#Return paths in the output data.frame
path_attribution=heuristic_models(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", cha_sep=">",
flg_write_nulls=1, password=password)
print(path_attribution,max=100)
#Perform transaction level attribution from a file and write output to file
res=heuristic_models(Data="Data.csv", var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", cha_sep=">", row_sep=";",
file_output="ouput.csv", password=password)
print(res)
markov_model
#Perform transaction level attribution reading data from a data.frame
res=markov_model(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Return non converting paths in the output data.frame
res=markov_model(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", flg_write_nulls=1, password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Return paths in the output data.frame
res=markov_model(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", flg_write_paths=1, password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Perform transaction level attribution reading data from a file and write output to file
res=markov_model(Data="Data.csv", var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", var_null="total_null",
cha_sep=">", row_sep=";", file_output="ouput.csv", password=password)
print(res)
shapley
#Perform transaction level attribution reading data from a data.frame
res=shapley(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Perform transaction level attribution using
#the classical Shapley value formula instead of fast variation
res=shapley(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", var_null="total_null",
cha_sep=">", flg_simplified=0, flg_write_paths=1, password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Return non converting paths in the output data.frame
res=shapley(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", flg_write_nulls=1, password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Return paths in the output data.frame
res=shapley(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", flg_write_paths=1, password=password)
path_attribution=res$attribution
print(path_attribution,max=100)
#Perform transaction level attribution reading data from a file and write output to file
res=shapley(Data="Data.csv", var_path="path", var_conv="total_conversions",
var_value="total_conversion_value",
var_null="total_null", cha_sep=">", row_sep=";", file_output="ouput.csv",
password=password)
print(res)
new_paths_attribution
#make attribution on new paths after you have trained a Markov model
train=markov_model(Data=Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", cha_sep=">", password=password)
path_attribution=res$attribution
res=new_paths_attribution(Data=Data[1:5], var_path="path", var_conv="total_conversions",
Dparams=train$parameters, var_value="total_conversion_value",
row_sep=";", cha_sep=">", flg_write_nulls=0, flg_write_paths=1,
server="app.channelattribution.pro", password=password)
print(res$attribution)
#Perform transaction level attribution reading data from a file and write output to file
res=new_paths_attribution(Data="Data.csv", var_path="path", var_conv="total_conversions",
Dparams=train$parameters, var_value="total_conversion_value",
row_sep=";", cha_sep=">", flg_write_nulls=0, flg_write_paths=1,
file_output="ouput.csv", server="app.channelattribution.pro",
password=password)
print(res$attribution)
choose_order
#Choose the best Markov model using AUC reading data from a data.frame
res=choose_order(Data, var_path="path", var_conv="total_conversions",var_null="total_null",
plot=0, cha_sep=">",password=password)
print(res$suggested_order)
#Choose the best Markov model using AUC reading data from a file
res=choose_order(Data="Data.csv", var_path="path", var_conv="total_conversions",
var_null="total_null",
cha_sep=">", row_sep=";", plot=0, password=password)
print(res$suggested_order)
#choose the best Markov model using Area under Precision-Recall Curve
res=choose_order(Data="Data.csv", var_path="path", var_conv="total_conversions",
var_null="total_null",
cha_sep=">", row_sep=";", type='auc-prerec', plot=0, password=password)
print(res$suggested_order)
combine_combine_mta_mmm
#perform multi-touch attribution
res=markov_model(Data, var_path="path", var_conv="total_conversions",var_null="total_null",
flg_write_paths=1,password=password)
mta_path_attribution=res$attribution
mta_path_attribution=mta_path_attribution[,c("path_id","path","channel","total_conversions")]
colnames(mta_path_attribution)=c("path_id","path","channel","attribution")
print(mta_path_attribution,max=100)
#load media mix model attribution
mmm_attribution=data.frame(channel=c("alpha","eta","iota","beta","theta","lambda","epsilon","omega"),
attribution=c(4826.18,2757.64,2574.60,1454.74,913.53,418.50,407.34,800.00))
print(mmm_attribution)
#combine MTA and MMM without prior weights
final_path_attribution=combine_mta_mmm(mta_path_attribution, mmm_attribution, password=password)
print(final_path_attribution,max=100)
#combine MTA and MMM with a prior weight on channel alpha
prior_weights_mta=data.frame(channel=c("alpha"),mta_weight=c(0.2))
#prior_weights_mta is a data.frame of subjective prior weights.
#Each weight is a real number between 0 and 1 which indicates,
#for the channel considered, how much weight will receive MTA in the final attribution calculation.
#Hence (1-MTA weight) is the weight of MMM for the channel considered. Since we know that
#channel alpha had some tracking problems than we decided to give it an MTA weight equal to $0.2$
#which implicates that MMM will receive a weight of 0.8 and thus MMM
#will be more important for that channel.
#The channels with no prior weight specified will receive a default of $0.5$ which means that
#MTA and MMM will be equally weighted in the attribution process.
final_path_attribution=combine_mta_mmm(mta_path_attribution, mmm_attribution,
prior_weights_mta=prior_weights_mta, password=password)
print(final_path_attribution,max=100)
markov_budget_allocation
#load data
Data=fread("https://app.channelattribution.pro/data/Data.csv")
#Set the total budget you want to allocate
total_budget_new=100000
#For each channel indicate its marketing spend. This parameter is optional. If you do not know the marketing spends you can set it to NULL
tab_costs=data.frame('channel'=c('alpha','iota','eta','beta','theta','lambda','epsilon','zeta','kappa','gamma','mi','delta'),
'value'=c(41111.43,10387.21,23816.66,6743.46,1650.4,523.52,709.94,288.77,269.46,153.57,0.61,0.43))
#Set the percentage of the budget you want to reallocate from your previous allocation
#The parameter can be set in the range (0,1].
#Setting it to 0.1 means that you will reallocate the 10% of your previous allocation.
#Drastic changes in your previous allocation are not suggested because the allocation algorithm is based on ROI and thus it is a local optimization algorithm.
#We suggest to reallocate a small percentage each time
perc_reall=0.1
#Perform attribution with Markov model. var_value and var_null are optional and can be set to NULL if you do not have this information
res_markov=markov_model(Data, var_path="path", var_conv="total_conversions",
var_value="total_conversion_value", row_sep=";", cha_sep=">", password=password)
res=markov_budget_allocation(res_markov,total_budget_new,tab_costs,
perc_reall,min_perc_budget,server="app.channelattribution.pro",password=password)
print(res)