## introduce

In this article, we look at what channel attribution is and how it relates to the concept of Markov chains. We will also use a case study of an e-commerce company to understand how this concept works in theory and practice (using R).

Google Analytics provides a standard set of rules for attribution modeling. According to Google, “An attribution model is a rule or set of rules that determine how sales and transformations are assigned to touchpoints in the transformation path. For example, the last interaction model in Google Analytics assigns 100% credit to the final touch point (i.e. clicks) immediately before a sale or conversion. In contrast, the first interaction model assigns 100 percent credit to the touchpoints that initiate the transformation path. “

We’ll see the final interaction model and the first interaction model later in this article. Before we do that, let’s take a small example to understand channel attribution further. Suppose we have a transformation diagram that looks like this:

In the above case, customers can start their journey through channel ‘C1’ or channel ‘C2’. The probability of starting with C1 or C2 is 50% (or 0.5). We first calculate the overall probability of conversion and then look further at the impact of each channel.

P (conversion) = P (C1→C2→C3→ conversion) + P (C2→C3→ conversion)

= 0.5 * 0.5 * 1 * 0.6 + 0.5 * 1 * 0.6

= 0.15 + 0.3

= 0.45

## Markov chain

A Markov chain is a process that maps activities and gives probability distributions, moving from one state to another. A Markov chain is defined by three properties:

State space – Handles the set of all possible states

Transition operation – The probability of moving from one state to another

Current State Probability distribution – The probability distribution of being in any of the states at the beginning of the process

We know the stages we can go through, the probability of moving from each path and the probability that we know the current state. This looks similar to a Markov chain.

In fact, this is an application of markov chains. If we want to figure out channel 1’s contribution to our customers’ conversion process from start to finish, we will use the principle of removal effects. The removal effect principle says that if we want to find the contribution of each channel in the customer process, we can do this by deleting each channel and looking at how many transformations took place without that channel.

For example, let’s assume that we have to calculate the contribution of channel C1. We will remove channel C1 from the model and look at how many conversions took place without C1 in the picture, the total number of conversions when all channels were intact. We calculate channel C1:

P (transformation after removing C1) = P (C2→C3→ transformation)

= 0.5 * 1 * 0.6

= 0.3

30% of customer interactions can be converted without C1 channels; While C1 remains intact, 45% of interactions can be converted. So the removal effect of C1 is 1

0.3/0.45 = 0.666.

C2 and C3 have a removal effect of 1 (you can try to calculate, but intuitively, if we were to remove or C2 or C3, we would be able to do any conversion?). .

This is a very useful application of Markov chains. In the above case, all channels –C1, C2, C3 (at different stages) are called transition states; The probability of moving from one channel to another is called transition probability.

The customer journey is a series of channels, which can be thought of as a chain in a directed Markov diagram, where each vertex is a state (channel/point of contact) and each edge represents the transition probability of moving from one state to another. Since the probability of reaching a state depends only on the previous state, it can be considered a memoryless Markov chain.

## Case studies of e-commerce companies

Let’s do a real case study to see how we implement channel attribution modeling.

An e-commerce company conducted a survey and collected customer data. This can be considered representative of the population. In the survey, the company collected data about customers’ visits to various touchpoints and ultimately purchased the product on its website.

There are a total of 19 channels through which customers can encounter products or product advertisements. After 19 channels, there are three more scenarios:

# 20 – Customer decides which equipment to buy;

# 21 – The customer has made the final purchase;

# 22 – Customer undecided.

The overall classification of channels is as follows:

category channel
Website (1,2,3) The company’s website or a competitor’s website
Research report (4,5,6,7,8) Industry consulting research report
Online/reviews (9,10) Natural search, forum
Price Comparison (11) Aggregate channels
Friends (12,13) The social network
Specialist (14) Online or offline expert
Retail outlets (15,16,17) A physical store
Others (18,19) Others, such as promotional activities in various places

Now, we need to help e-commerce companies determine the right strategy to invest in marketing channels. What channels should we focus on? What channels should companies invest in? We will use R to solve this problem in the next section.

# Implementation using R

We read the data, try to implement it in R and check the results.

``````> head(channel)
Copy the code``````

Output:

``R05a.01 R05a.02 R05a.03 r05A.04... . R05A.18 R05A.19 R05A.20 16 4 3 5 NA NA NA 2 1 9 10 NA NA NA 9 13 20 16 NA NA NA 8 15 20 21 NA NA NA 16 9 13 20 NA NA NA 1 11 8 4 NA NA NACopy the code``

We’re going to do some data processing to bring it to a stage where we can use it as input in the model. We will then determine which customers have made the final conversion.

Create a variable ‘path’ of a specific format that can be used as input to the model. In addition, we’ll use the “dplyr” package to find out the total number of occurrences for each path.

## The path transformation

The path conversion
1 > 1 > 1 > 20 1
1 > 1 > 12 > 12 1
1 > 1 > 14 > 13 > 12 > 20 1
1 > 1 > 3 > 13 > 3 > 20 1
1 > 1 > 3 > 17 > 17 1
> 1 > 6 > 1 > 12 > 20 > 12 1

``````> channel_fin = ddply(channel_fin,~path,summarise, conversion= sum(convert))
Copy the code``````

Output:

## The path transformation

The path conversion
1 > 1 > 1 > 20 1
1 > 1 > 12 > 12 1
1 > 1 > 14 > 13 > 12 > 20 1
1 > 1 > 3 > 13 > 3 > 20 1
1 > 1 > 3 > 17 > 17 1
1 > 1 > 6 > 1 > 12 > 20 > 12 1

Now, we will create a heuristic model and a Markov model, combine the two, and then examine the final result.

Output:

Output:

Channel name First contact conversion … . Linear contact conversion Linear contact value
1 130   73.773661 73.773661
20 0   473.998171 473.998171
12 75   76.127863 76.127863
14 34   56.335744 56.335744
13 320   204.039552 204.039552
3 168   117.609677 117.609677
17 31   76.583847 76.583847
6 50   54.707124 54.707124
8 56   53.677862 53.677862
10 547   211.822393 211.822393
11 66   107.109048 107.109048
16 111   156.049086 156.049086
2 199   94.111668 94.111668
4 231   250.784033 250.784033
7 26   33.435991 33.435991
5 62   74.900402 74.900402
9 250   194.07169 194.07169
15 22   65.159225 65.159225
18 4   5.026587 5.026587
19 10   12.676375 12.676375

Output:

:

Channel name   The overall conversion Total conversion value
1   82.482961 82.482961
20   432.40615 432.40615
12   83.942587 83.942587
14   63.08676 63.08676
13   195.751556 195.751556
3   122.973752 122.973752
17   83.866724 83.866724
6   63.280828 63.280828
8   61.016115 61.016115
10   209.035208 209.035208
11   118.563707 118.563707
16   158.692238 158.692238
2   98.067199 98.067199
4   223.709091 223.709091
7   41.919248 41.919248
5   81.865473 81.865473
9   179.483376 179.483376
15   70.360777 70.360777
18   5.950827 5.950827
19   15.545424 15.545424

Before we go any further, let’s understand what some of the terms we’ve seen above mean.

First contact conversion: conversion through a channel when the channel is the customer’s first contact point. Take 100% credit for the first touch.

Last Contact Conversion: The conversion that occurs through a channel when the channel is the last point of contact for the customer. 100% credit is given to the final touch point.

Going back to the R code, let’s merge the two models and visually represent the output.

``Ggplot (R1, AES (channel_name, value, fill = variable)) + geom_bar(stat='identity', position='dodge') +Copy the code``

The result can be clearly seen in the figure above. From a first contact conversion perspective, channels 10, 13, 2, 4 and 9 are very important; Channel 20 is the most important from a last-touch point of view (because in our example the customer decides which product to buy). Channels 20, 4, and 9 are important in terms of linear contact conversion. From a total conversion perspective, channels 10,13,20,4, and 9 are very important.

## The end of the

In the chart above, we’ve been able to figure out which are important channels of our attention and which can be ignored or ignored. This situation gives us a good understanding of the application of markov chain models in the field of customer analysis. E-commerce companies can now create their marketing strategies more accurately and allocate their marketing budgets using data-driven insights.

Most welcome insight

1. Use R language to simulate the mixed queuing random service queuing system

2. Queuing theory is used in R language to predict waiting time

3. Realize markov chain Monte Carlo MCMC model in R language

4. Markov regime switching model in R language

5. Matlab Bayesian hidden Markov HMM model

6. Use R language to simulate the mixed queuing random service queuing system

7. Portfolio optimization in Python based on particle swarm optimization

8. Research on accident prediction of traffic casualties by R Language Markov Transformation model

9. Identifying changing Stock Market Conditions with Machine learning: Application of Hidden Markov Models