Skip to main content
Version: 3.15

shapley

R

#Load library and data

library(ChannelAttributionPro)

Data=read.csv("https://app.channelattribution.io/data/Data.csv",sep=";")

#Set your token

token="yourtoken"

#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=">")
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)
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)
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)
path_attribution=res$attribution
print(path_attribution,max=100)

#Perform transaction level attribution reading data from a file and write output to file

download.file(url="https://app.channelattribution.io/data/Data.csv","Data.csv")

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")
print(res)