<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/attribution-model-with-r-part-1-markov-chains-concept/"></div></div><div><a data-url="https://www.r-bloggers.com/attribution-model-with-r-part-1-markov-chains-concept/" data-counturl="https://www.r-bloggers.com/attribution-model-with-r-part-1-markov-chains-concept/" data-count="horizontal" data-text="Attribution model with R (part 1: Markov chains concept)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://analyzecore.com/2016/08/03/attribution-model-r-part-1/"> R language – AnalyzeCore – data are beautiful, data are a story</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div></div>
<p>As we know, a customer usually goes through a path/sequence of different channels/touchpoints before a purchase in e-commerce or conversion in other areas. In Google Analytics we can find some touchpoints more likely to assist to conversion than others that more likely to be last-click touchpoint. As most of the channels are paid for (in terms of money or time spent), it is vital to have an algorithm for distributing conversions and the value between those channels and compare with their costs instead of crediting e.g. last non-direct channel only. This is a <strong>Multi-Channel Attribution Model</strong> problem.</p>
<p>A definition by Google Analytics helps: <em>an Attribution Model is a rule, or set of rules, that determines how credit for sales and conversions is assigned to touchpoints in conversion paths.</em></p>
<p>Nowadays, Google Analytics provides seven (!) predefined attribution models and even a custom model that you can adapt to your case. However, there are some aspects that I don’t like about the Google Analytics approach, which is why I started research on this area. I’m sure this is a very interesting field for analysts and marketers. I’m going to publish a sequence of posts about alternative (relatively to Google Analytics) Attribution Model concepts, some ideas for solving issues that you would face in practice when implementing them, and R code for computing them (as always).</p>
<p>What I don’t like about the GA approach:</p>
<ul>
<li>You have to make a choice or managerial decision regarding which model to use and why. You can see different results with different models but which one is more correct? In other words, GA provides heuristic models with their pros and cons,</li>
<li>The data are aggregated and anonymized and you can’t mine deeper if you want,</li>
<li>You can’t take into account paths without conversions but this would be interesting.</li>
</ul>
<p>Pros of GA:</p>
<ul>
<li>You don’t need to organize a storage and infrastructure for collecting data,</li>
<li>You are provided with a range of heuristic models,</li>
<li>It is pretty easy and free to use.</li>
</ul>
<p><span>Therefore, if you are relatively small company it would be logical to use the GA’s approach but if you see the results of attribution would have a significant impact on marketing budgets, product prices, understanding customer journeys, etc. or you have the necessary data collected, you can explore ideas that I’m going to share.</span></p>
<p>I focused on the Markov chains concept for attribution in this article mainly. In the second post of the series, we will study practical aspects of its implementation.</p>
<h3><strong>Attribution Model based on Markov chains concept</strong></h3>
<p>Using Markov chains allow us to switch from heuristic models to probabilistic ones. We can represent every customer journey (sequence of channels/touchpoints) as a chain in a directed Markov graph where each vertex is a possible state (channel/touchpoint) and the edges represent the probability of transition between the states (including conversion.) By computing the model and estimating transition probabilities we can attribute every channel/touchpoint.</p>
<p>Let’s start with a simple example of the first-order or “memory-free” Markov graph for better understanding the concept. It is called “memory-free” because the probability of reaching one state depends only on the previous state visited.</p>
<p>For instance, customer journeys contain three unique channels C1, C2, and C3. In addition, we should manually add three special states to each graph: (start), (conversion) and (null). These additional states represent starting point, purchase or conversion, and unsuccessful conversion. Transitions from identical channels are possible (e.g. C1 -> C1) but can be omitted for different reasons.</p>
<p><span>Let’s assume we have three customer journeys:</span></p>
<p><em><span>C1 -> C2 -> C3 -> purchase</span></em></p>
<p><em><span>C1 -> unsuccessful conversion</span></em></p>
<p><em><span>C2 -> C3 -> unsuccessful conversion</span></em></p>
<p><span>Due to the approach, we will add extra states (see column 2 of the following table) and split for pairs (see column 3):</span></p>
<p>
<table>
<thead>
<tr>
<th>1 – Customer journey</th>
<th>2 – Transformation</th>
<th>3 – Splitting for pairs</th>
</tr>
</thead>
<tbody>
<tr>
<td>C1 -> C2 -> C3 -> purchase</td>
<td>(start) -> C1 -> C2 -> C3 -> (conversion)</td>
<td>(start) -> C1, C1 -> C2, C2 -> C3, C3 -> (conversion)</td>
</tr>
<tr>
<td>C1</td>
<td>(start) -> C1 -> (null)</td>
<td>(start) -> C1, C1 -> (null)</td>
</tr>
<tr>
<td>C2 -> C3</td>
<td>(start) -> C2 -> C3 -> (null)</td>
<td>(start) -> C2, C2 -> C3, C3 -> (null)</td>
</tr>
</tbody>
</table>
<p></p>
<p><span>After this, we need to calculate the probabilities of the transition from state to state:</span></p>
<p><span>
<table>
<thead>
<tr>
<th>from</th>
<th>to</th>
<th>probability</th>
<th>total probability</th>
</tr>
</thead>
<tbody>
<tr>
<td>(start)</td>
<td>C1</td>
<td>1/3</td>
<td rowspan="2">66.7%</td>
</tr>
<tr>
<td>(start)</td>
<td>C1</td>
<td>1/3</td>
</tr>
<tr>
<td>(start)</td>
<td>C2</td>
<td>1/3</td>
<td>33.3%</td>
</tr>
<tr>
<td colspan="2">total from (start)</td>
<td colspan="2">3/3</td>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>1/2</td>
<td>50%</td>
</tr>
<tr>
<td>C1</td>
<td>(null)</td>
<td>1/2</td>
<td>50%</td>
</tr>
<tr>
<td colspan="2">total from C1</td>
<td colspan="2">2/2</td>
</tr>
<tr>
<td>C2</td>
<td>C3</td>
<td>1/2</td>
<td rowspan="2">100%</td>
</tr>
<tr>
<td>C2</td>
<td>C3</td>
<td>1/2</td>
</tr>
<tr>
<td colspan="2">total from C2</td>
<td colspan="2">2/2</td>
</tr>
<tr>
<td>C3</td>
<td>(conversion)</td>
<td>1/2</td>
<td>50%</td>
</tr>
<tr>
<td>C3</td>
<td>(null)</td>
<td>1/2</td>
<td>50%</td>
</tr>
<tr>
<td colspan="2">total from C3</td>
<td colspan="2">2/2</td>
</tr>
</tbody>
</table>
<p><a target="_blank" href="http://analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-22-14.26.50.png"><br>
</a></p></span>
<p><span>Finally, we can plot the model:</span></p>
<p><a target="_blank" href="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-22-14.26.50.png"><img sizes="(max-width: 648px) 100vw, 648px" srcset="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-22-14.26.50.png?w=938 938w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-22-14.26.50.png?resize=300%2C121 300w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-22-14.26.50.png?resize=768%2C309 768w" alt="Screenshot 2016-07-22 14.26.50" class="wp-image-1633" src="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-22-14.26.50.png?resize=648%2C260" data-recalc-dims="1"></a></p>
<p><span>The last step is to estimate every channel/touchpoint. It is pretty easy to do this by using the principle of <strong>Removal Effect</strong>.<span>  </span>The core of Removal Effect is to remove each channel from the graph consecutively and measure how many conversions (or how much value) could be made (earned) without the one. The logic is the following: if we obtain N conversions without a certain channel/touchpoint compared to total conversions T of the complete model, that means the channel reflects the change in total conversions (or value). After all, channels/touchpoints are estimated: we have to weight them because the total sum of (T – Ni) would be bigger than T and normally it is. </span></p>
<p><span>Another effective way to measure the Removal Effect is in percentages e.g. the channel affected conversion probabilities by X %.</span></p>
<p><span>Let’s see how this works in our simplified example. Removing a channel/touchpoint from the graph means we should replace it in channel pairs. In case the channel exists in a «from» state, we will replace it with NA (and then omit this pair) and we will replace the channel with (null) if it is in a «to» state. In other words, we will not have paths from the channel and will transit from the other channels to (null) state when the channel is in a «to» part.</span></p>
<p><span>Removal Effect for C1 channel looks like the following:</span></p>
<p><a target="_blank" href="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-25-21.26.57.png"><img sizes="(max-width: 648px) 100vw, 648px" srcset="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-25-21.26.57.png?resize=1024%2C387 1024w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-25-21.26.57.png?resize=300%2C113 300w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-25-21.26.57.png?resize=768%2C290 768w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-25-21.26.57.png?w=1080 1080w" alt="Screenshot 2016-07-25 21.26.57" class="wp-image-1652" src="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/07/Screenshot-2016-07-25-21.26.57.png?resize=648%2C245" data-recalc-dims="1"></a></p>
<p><span>Therefore, the probability of conversion of the complete model is 33.3% (0.667 * 0.5 * 1 * 0.5 + 0.333 * 1 * 0.5.) The probability of conversion after removing the C1 channel is 16.7% (0.333 * 1 * 0.5.) Therefore, the channel C1 removal effect is 0.5 (0.167 / 0.333.) In other words, if we didn’t have the channel C1 in customer journeys we would lose 50% of conversions.</span></p>
<p><span>The removal effect of both C2 and C3 is 1 because we would lose all 100% conversion.</span></p>
<p><span>In addition, we need to weight the indexes and multiply them by total number of conversions (1 in our case):</span></p>
<ul>
<li><span>C1: 0.5 / (0.5 + 1 + 1) = 0.2 * 1 conversion = 0.2</span></li>
<li><span>C2: 1 / (0.5 + 1 + 1) = 0.4 * 1 conversion = 0.4</span></li>
<li><span>C3: 1 / (0.5 + 1 + 1) = 0.4 * 1 conversion = 0.4</span></li>
</ul>
<p><span>Therefore, we distributed 1 conversion for all channels.</span></p>
<p><span>I think the method is clear for you now. Let’s do this with R language. We will create the simplified example as above and simulate a dataset that looks like real data of customer journeys in addition.</span></p>
<p><strong>Hint:</strong> there is a great R-package (<a target="_blank" href="https://cran.r-project.org/web/packages/ChannelAttribution/index.html">ChannelAttribution</a>) available on CRAN. It is really nice because of its simplicity and speed but I found some issues in the early stages of my investigation. That is why I’ve done all the work manually. Luckily, the author of the package (Davide Altomare) replied to my comments and fixed the bugs. Therefore, I’ve obtained the equal results of my manual approach and the package from the 1.8 version. Thus, please be sure that you have the latest version of the package installed.</p>
<p><span>The following is the R code for simple example that we reviewed above:</span></p>
<p><strong title="click to expand R code" tabindex="0">click to expand R code</strong>
<div>
<pre>
library(dplyr)
library(reshape2)
library(ggplot2)
library(ChannelAttribution)
library(markovchain)

##### simple example #####
# creating a data sample
df1 &lt;- data.frame(path = c('c1 > c2 > c3', 'c1', 'c2 > c3'), conv = c(1, 0, 0), conv_null = c(0, 1, 1))

# calculating the models
mod1 &lt;- markov_model(df1,
var_path = 'path',
var_conv = 'conv',
var_null = 'conv_null',
out_more = TRUE)

# extracting the results of attribution
df_res1 &lt;- mod1$result

# extracting a transition matrix
df_trans1 &lt;- mod1$transition_matrix
df_trans1 &lt;- dcast(df_trans1, channel_from ~ channel_to, value.var = 'transition_probability')

### plotting the Markov graph ###
df_trans &lt;- mod1$transition_matrix

# adding dummies in order to plot the graph
df_dummy &lt;- data.frame(channel_from = c('(start)', '(conversion)', '(null)'),
channel_to = c('(start)', '(conversion)', '(null)'),
transition_probability = c(0, 1, 1))
df_trans &lt;- rbind(df_trans, df_dummy)

# ordering channels
df_trans$channel_from &lt;- factor(df_trans$channel_from,
levels = c('(start)', '(conversion)', '(null)', 'c1', 'c2', 'c3'))
df_trans$channel_to &lt;- factor(df_trans$channel_to,
levels = c('(start)', '(conversion)', '(null)', 'c1', 'c2', 'c3'))
df_trans &lt;- dcast(df_trans, channel_from ~ channel_to, value.var = 'transition_probability')

# creating the markovchain object
trans_matrix &lt;- matrix(data = as.matrix(df_trans[, -1]),
nrow = nrow(df_trans[, -1]), ncol = ncol(df_trans[, -1]),
dimnames = list(c(as.character(df_trans[, 1])), c(colnames(df_trans[, -1]))))
trans_matrix[is.na(trans_matrix)] &lt;- 0
trans_matrix1 &lt;- new(&quot;markovchain&quot;, transitionMatrix = trans_matrix)

# plotting the graph
plot(trans_matrix1, edge.arrow.size = 0.35)
</pre>
</div>
<p><span>We have obtained the visualization of Markov graph, transition matrix (<em>df_trans1 </em>data frame) and the attribution results that look pretty the same with our calculations (<em>df_res1</em> data frame):</span></p>
<p><a target="_blank" href="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/transition_probs_1.png"><img sizes="(max-width: 310px) 100vw, 310px" srcset="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/transition_probs_1.png?w=900 900w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/transition_probs_1.png?resize=300%2C297 300w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/transition_probs_1.png?resize=768%2C759 768w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/transition_probs_1.png?resize=60%2C60 60w" alt="transition_probs_1" class="wp-image-1676" src="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/transition_probs_1.png?resize=310%2C306" data-recalc-dims="1"></a></p>
<p><a target="_blank" href="http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-00.57.52.png"><img sizes="(max-width: 305px) 100vw, 305px" srcset="http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-00.57.52.png?w=564 564w, http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-00.57.52.png?resize=300%2C95 300w" alt="Screenshot 2016-08-03 00.57.52" class="wp-image-1677" src="http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-00.57.52.png?resize=305%2C96" data-recalc-dims="1"></a></p>
<p>Let’s simulate a dataset that looks like real data of customer journeys. W<span>e assume that all paths were finished with the purchase/conversion.</span></p>
<p><strong title="click to expand R code" tabindex="0">click to expand R code</strong>
<div>
<pre>
# simulating the &quot;real&quot; data
set.seed(354)
df2 &lt;- data.frame(client_id = sample(c(1:1000), 5000, replace = TRUE),
date = sample(c(1:32), 5000, replace = TRUE),
channel = sample(c(0:9), 5000, replace = TRUE,
prob = c(0.1, 0.15, 0.05, 0.07, 0.11, 0.07, 0.13, 0.1, 0.06, 0.16)))
df2$date &lt;- as.Date(df2$date, origin = &quot;2015-01-01&quot;)
df2$channel &lt;- paste0('channel_', df2$channel)

# aggregating channels to the paths for each customer
df2 &lt;- df2 %>%
group_by(client_id) %>%
summarise(path = paste(channel, collapse = ' > '),
# assume that all paths were finished with conversion
conv = 1,
conv_null = 0) %>%
ungroup()

# calculating the models (Markov and heuristics)
mod2 &lt;- markov_model(df2,
var_path = 'path',
var_conv = 'conv',
var_null = 'conv_null',
out_more = TRUE)

# heuristic_models() function doesn't work for me, therefore I used the manual calculations
# instead of:
#h_mod2 &lt;- heuristic_models(df2, var_path = 'path', var_conv = 'conv')

df_hm &lt;- df2 %>%
mutate(channel_name_ft = sub('>.*', '', path),
channel_name_ft = sub(' ', '', channel_name_ft),
channel_name_lt = sub('.*>', '', path),
channel_name_lt = sub(' ', '', channel_name_lt))
# first-touch conversions
df_ft &lt;- df_hm %>%
group_by(channel_name_ft) %>%
summarise(first_touch_conversions = sum(conv)) %>%
ungroup()
# last-touch conversions
df_lt &lt;- df_hm %>%
group_by(channel_name_lt) %>%
summarise(last_touch_conversions = sum(conv)) %>%
ungroup()

h_mod2 &lt;- merge(df_ft, df_lt, by.x = 'channel_name_ft', by.y = 'channel_name_lt')

# merging all models
all_models &lt;- merge(h_mod2, mod2$result, by.x = 'channel_name_ft', by.y = 'channel_name')
colnames(all_models)[c(1, 4)] &lt;- c('channel_name', 'attrib_model_conversions')
</pre>
</div>
<p>The results are the following (<em>all_models</em> data frame):</p>
<p><a target="_blank" href="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-02.15.54.png"><img sizes="(max-width: 648px) 100vw, 648px" srcset="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-02.15.54.png?resize=1024%2C403 1024w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-02.15.54.png?resize=300%2C118 300w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-02.15.54.png?resize=768%2C303 768w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-02.15.54.png?w=1274 1274w" alt="Screenshot 2016-08-03 02.15.54" class="wp-image-1687" src="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/Screenshot-2016-08-03-02.15.54.png?resize=648%2C255" data-recalc-dims="1"></a></p>
<p><span>In addition, let’s create some visualizations for transition matrix and the difference between heuristic models and attribution model with the following code:</span></p>
<p><strong title="click to expand R code" tabindex="0">click to expand R code</strong>
<div>
<pre>
############## visualizations ##############
# transition matrix heatmap for &quot;real&quot; data
df_plot_trans &lt;- mod2$transition_matrix

cols &lt;- c(&quot;#e7f0fa&quot;, &quot;#c9e2f6&quot;, &quot;#95cbee&quot;, &quot;#0099dc&quot;, &quot;#4ab04a&quot;, &quot;#ffd73e&quot;, &quot;#eec73a&quot;,
 &quot;#e29421&quot;, &quot;#e29421&quot;, &quot;#f05336&quot;, &quot;#ce472e&quot;)
t &lt;- max(df_plot_trans$transition_probability)

ggplot(df_plot_trans, aes(y = channel_from, x = channel_to, fill = transition_probability)) +
 theme_minimal() +
 geom_tile(colour = &quot;white&quot;, width = .9, height = .9) +
 scale_fill_gradientn(colours = cols, limits = c(0, t),
 breaks = seq(0, t, by = t/4),
 labels = c(&quot;0&quot;, round(t/4*1, 2), round(t/4*2, 2), round(t/4*3, 2), round(t/4*4, 2)),
 guide = guide_colourbar(ticks = T, nbin = 50, barheight = .5, label = T, barwidth = 10)) +
 geom_text(aes(label = round(transition_probability, 2)), fontface = &quot;bold&quot;, size = 4) +
 theme(legend.position = 'bottom',
 legend.direction = &quot;horizontal&quot;,
 panel.grid.major = element_blank(),
 panel.grid.minor = element_blank(),
 plot.title = element_text(size = 20, face = &quot;bold&quot;, vjust = 2, color = 'black', lineheight = 0.8),
 axis.title.x = element_text(size = 24, face = &quot;bold&quot;),
 axis.title.y = element_text(size = 24, face = &quot;bold&quot;),
 axis.text.y = element_text(size = 8, face = &quot;bold&quot;, color = 'black'),
 axis.text.x = element_text(size = 8, angle = 90, hjust = 0.5, vjust = 0.5, face = &quot;plain&quot;)) +
 ggtitle(&quot;Transition matrix heatmap&quot;)

# models comparison
all_mod_plot &lt;- melt(all_models, id.vars = 'channel_name', variable.name = 'conv_type')
all_mod_plot$value &lt;- round(all_mod_plot$value)
# slope chart
pal &lt;- colorRampPalette(brewer.pal(10, &quot;Set1&quot;))
ggplot(all_mod_plot, aes(x = conv_type, y = value, group = channel_name)) +
 theme_solarized(base_size = 18, base_family = &quot;&quot;, light = TRUE) +
 scale_color_manual(values = pal(10)) +
 scale_fill_manual(values = pal(10)) +
 geom_line(aes(color = channel_name), size = 2.5, alpha = 0.8) +
 geom_point(aes(color = channel_name), size = 5) +
 geom_label_repel(aes(label = paste0(channel_name, ': ', value), fill = factor(channel_name)),
 alpha = 0.7,
 fontface = 'bold', color = 'white', size = 5,
 box.padding = unit(0.25, 'lines'), point.padding = unit(0.5, 'lines'),
 max.iter = 100) +
 theme(legend.position = 'none',
 legend.title = element_text(size = 16, color = 'black'),
 legend.text = element_text(size = 16, vjust = 2, color = 'black'),
 plot.title = element_text(size = 20, face = &quot;bold&quot;, vjust = 2, color = 'black', lineheight = 0.8),
 axis.title.x = element_text(size = 24, face = &quot;bold&quot;),
 axis.title.y = element_text(size = 16, face = &quot;bold&quot;),
 axis.text.x = element_text(size = 16, face = &quot;bold&quot;, color = 'black'),
 axis.text.y = element_blank(),
 axis.ticks.x = element_blank(),
 axis.ticks.y = element_blank(),
 panel.border = element_blank(),
 panel.grid.major = element_line(colour = &quot;grey&quot;, linetype = &quot;dotted&quot;),
 panel.grid.minor = element_blank(),
 strip.text = element_text(size = 16, hjust = 0.5, vjust = 0.5, face = &quot;bold&quot;, color = 'black'),
 strip.background = element_rect(fill = &quot;#f0b35f&quot;)) +
 labs(x = 'Model', y = 'Conversions') +
 ggtitle('Models comparison') +
 guides(colour = guide_legend(override.aes = list(size = 4)))
</pre>
</div>
<p>We obtained the heatmap of the transition matrix:</p>
<p><a target="_blank" href="http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png"><img sizes="(max-width: 648px) 100vw, 648px" srcset="http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png?resize=1024%2C512 1024w, http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png?resize=300%2C150 300w, http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png?resize=768%2C384 768w, http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png?w=1296 1296w, http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png?w=1944 1944w" alt="trans_matrix_heatmap" class="wp-image-1692" src="http://i2.wp.com/analyzecore.com/wp-content/uploads/2016/08/trans_matrix_heatmap.png?resize=648%2C324" data-recalc-dims="1"></a></p>
<p>And models comparison <span>indicates substantial differences to existing heuristics such as «first-click» and «last-click» as well as alternative attribution approach:</span></p>
<p><a target="_blank" href="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png"><img sizes="(max-width: 648px) 100vw, 648px" srcset="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png?resize=1024%2C512 1024w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png?resize=300%2C150 300w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png?resize=768%2C384 768w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png?w=1296 1296w, http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png?w=1944 1944w" alt="slope_chart" class="wp-image-1693" src="http://i0.wp.com/analyzecore.com/wp-content/uploads/2016/08/slope_chart.png?resize=648%2C324" data-recalc-dims="1"></a></p>
<p><span>In the next post, we will study how to do attribution based on the first-order Markov chains in practice. We will see that while the method is pretty simple, there will be a lot of questions that we need to answer and, therefore, apply to the R script. Specifically, we will study how to: </span></p>
<ul>
<li><span>define the retrospective period for analysis,</span></li>
<li><span>manage several purchases per reporting period,</span></li>
<li><span>deal with paths without purchase,</span></li>
<li><span>replace «direct» (or any other unknown) channel with a non-direct or known one,</span></li>
<li><span>calculate both conversions and revenue,</span></li>
<li><span>etc.</span></li>
</ul>
<p><span>Therefore, the next post will be practical oriented, don’t miss it <img alt="🙂" class="wp-smiley" src="https://i2.wp.com/s.w.org/images/core/emoji/72x72/1f642.png?w=456&ssl=1" data-recalc-dims="1"></span></p>
<p><span>Useful links:</span></p>
<ul>
<li><a target="_blank" href="http://www.slideshare.net/adavide1982/markov-model-for-the-multichannel-attribution-problem">Slides of Channel Attribution package</a>,</li>
<li>
<p><a target="_blank" data-href="http://d-nb.info/1064147364/34" href="http://d-nb.info/1064147364/34">Three Essays on Analyzing and Managing Online Consumer Behavior</a>,</p>
</li>
<li><a target="_blank" href="https://aaltodoc.aalto.fi/bitstream/handle/123456789/13898/master_Rentola_Olli_2014.pdf?sequence=1">Analyses of Online Advertising Performance Using Attribution Modeling</a>.</li>
</ul>
<p>P.S.: just found that Lunametrics also has published the <a target="_blank" href="http://www.lunametrics.com/blog/2016/06/30/marketing-channel-attribution-markov-models-r/">post</a> about.</p>
<div></div>
<p>The post <a target="_blank" rel="nofollow" href="http://analyzecore.com/2016/08/03/attribution-model-r-part-1/">Attribution model with R (part 1: Markov chains concept)</a> appeared first on <a target="_blank" rel="nofollow" href="http://analyzecore.com/">AnalyzeCore – data are beautiful, data are a story</a>.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/attribution-model-with-r-part-1-markov-chains-concept/"></div></div><div><a data-url="https://www.r-bloggers.com/attribution-model-with-r-part-1-markov-chains-concept/" data-counturl="https://www.r-bloggers.com/attribution-model-with-r-part-1-markov-chains-concept/" data-count="vertical" data-text="Attribution model with R (part 1: Markov chains concept)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://analyzecore.com/2016/08/03/attribution-model-r-part-1/"> R language – AnalyzeCore – data are beautiful, data are a story</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/7EruxlculxA"></a></div>