library(ChannelAttributionPro)
options(max.print=100)
token="yourtoken"
Data = read.csv("https://app.channelattribution.io/data/Data.csv",sep=";")
print(Data)
total_budget_new=100000
perc_reall=0.1
res_attr=heuristic_models(Data=Data, var_path="path", var_conv="total_conversions", var_value="total_conversion_value")
res_attr=res_attr[,c('path_id','channel','channel_position','last_touch_conversions','last_touch_value')]
colnames(res_attr)=c('path_id','channel','channel_position','total_conversions','total_conversion_value')
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))
res=budget_allocation(tab_attribution=res_attr,tab_costs=tab_costs,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Costs are available")
print(res)
res=budget_allocation(tab_attribution=res_attr,tab_costs=NULL,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Costs are not available")
print(res)
res_attr=subset(res_attr, select = -total_conversion_value)
res=budget_allocation(tab_attribution=res_attr,tab_costs=NULL,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Conversion Value is not available")
print(res)
res_attr=markov_model(Data=Data, var_path="path", var_conv="total_conversions", var_value="total_conversion_value", var_null="total_null")
tab_attribution=res_attr$attribution
tab_index=res_attr$parameters
colnames(tab_index)=c('channel','value')
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))
res=budget_allocation(tab_attribution=tab_attribution,tab_costs=tab_costs,tab_index=tab_index,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Costs are available")
print(res)
res=budget_allocation(tab_attribution=tab_attribution,tab_costs=NULL,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Costs are not available")
print(res)
tab_attribution=subset(tab_attribution, select = -total_conversion_value)
res=budget_allocation(tab_attribution=tab_attribution,tab_costs=NULL,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Allocate budget when Conversion Value is not available")
print(res)
df_paths = read.csv("https://app.channelattribution.io/data/data_paths.csv",sep=";")
df_aggr = read.csv("https://app.channelattribution.io/data/data_aggregated_w_value.csv",sep=";")
df_ctr = read.csv("https://app.channelattribution.io/data/data_ctr.csv",sep=";")
channels = setdiff(names(df_aggr), c('timestamp_from','timestamp_to','conversions','value'))
res_attr=uam(df_aggr=df_aggr[,c(c('timestamp_from','timestamp_to','conversions'),channels)],df_ctr=df_ctr,df_paths=NULL,channel_conv_name="((CONV))",order=1,nsim_start=1e5,max_step=NULL,ncore=1,nfold=10,seed=1234567,conv_par=0.05,rate_step_sim=1.5,verbose=1)
res_attr = reshape(res_attr$attribution,
varying = list(names(res_attr$attribution)[!(names(res_attr$attribution) %in% c("timestamp_from", "timestamp_to", "conversions"))]),
v.names = "attribution",
timevar = "channel",
times = names(res_attr$attribution)[!(names(res_attr$attribution) %in% c("timestamp_from", "timestamp_to", "conversions"))],
idvar = c("timestamp_from", "timestamp_to", "conversions"),
direction = "long")
res_attr = merge(res_attr, df_aggr[c("timestamp_from", "timestamp_to", "value")],
by = c("timestamp_from", "timestamp_to"),
all = FALSE)
res_attr$total_conversion_value = res_attr$value * res_attr$attribution / res_attr$conversions
names(res_attr)[names(res_attr) == "attribution"] = "total_conversions"
res_attr = res_attr[c("timestamp_from", "timestamp_to", "conversions", "value", "channel", "total_conversions", "total_conversion_value")]
tab_costs = data.frame(channel = c('A', 'B', 'C', 'D', 'E', 'F'),
value = c(1345, 1456, 987, 1121, 879, 124))
res=budget_allocation(tab_attribution=res_attr,tab_costs=tab_costs,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Costs are available")
print(res)
res=budget_allocation(tab_attribution=res_attr,tab_costs=NULL,tab_index=NULL,total_budget_new=total_budget_new,perc_reall=perc_reall,min_perc_budget=0.01)
print("Budget Allocation when Costs are not available")
print(res)