{"id":3321,"date":"2018-05-23T18:22:26","date_gmt":"2018-05-23T16:22:26","guid":{"rendered":"https:\/\/geekosas.com\/?p=3321"},"modified":"2026-05-23T18:25:55","modified_gmt":"2026-05-23T16:25:55","slug":"separate-effects-and-cohort-analysis","status":"publish","type":"post","link":"https:\/\/geekosas.com\/index.php\/2018\/05\/23\/separate-effects-and-cohort-analysis\/","title":{"rendered":"Separate Effects and Cohort Analysis"},"content":{"rendered":"<p>In subscription businesses (Newspapers, Cell Phones, Insurance, etc&#8230;), the business is always the same: acquire a customer and then receive cash flows associated with a service provided by the company. The day the customer cancels the service is called CHURN, and the customer becomes inactive, suspending both revenue and service.<\/p>\n<p>In general, there is a cost to acquire a new customer, so the present value of the acquisition will depend on how long the customer takes to CHURN. In the following image, we show in red the present value of a customer for each number of survival months, while in blue the cash flows, where the first flow is negative, representing for example: sales commissions, service installation, equipment subsidies, etc. Clearly, if the customer does not last at least 15 months, the business was bad and represented a loss for the company.<\/p>\n<pre><code class=\"language-r\">library(ggplot2)\nperiods = 36\ndiscount_rate = 1.06\ncashflows = data.frame(period = 0:periods, cashflow = c(-10,rep(1,periods) )) %&gt;%\n  mutate(cashflow_present_value = cashflow\/(discount_rate^period),\n         present_value = cumsum(cashflow_present_value))\nggplot(cashflows) +\n  geom_bar(aes(period,cashflow),stat = &quot;identity&quot;,fill = &quot;blue&quot;) +\n  geom_line(aes(period,present_value),color = &quot;red&quot;, size = 1.5)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2386\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/pressent-value\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/pressent-value.png?fit=700%2C432&amp;ssl=1\" data-orig-size=\"700,432\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pressent value\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/pressent-value.png?fit=700%2C432&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/pressent-value.png?resize=700%2C432\" alt=\"\" width=\"700\" height=\"432\" class=\"alignnone size-full wp-image-2386\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/pressent-value.png?w=700&amp;ssl=1 700w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/pressent-value.png?resize=300%2C185&amp;ssl=1 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>To monitor and project customer behavior, what is called a cohort analysis is performed. Broadly speaking, it consists of grouping all customers acquired in a time window (usually monthly) and using it as a statistically significant representative of the group&#8217;s behavior. In this way, you can compare the average behavior of acquisitions from different months and make some projection models or simply compare the performance of one month versus other months.<\/p>\n<p>The KPIs monitored month by month throughout the life of a cohort are the following:<\/p>\n<ul>\n<li>Activations: Number of new customers acquired in the month<\/li>\n<li>Average Revenue: Average revenue generated by a customer who is still subscribed to the service<\/li>\n<li>Survival Rate: Percentage of customers who have not yet CHURNed<\/li>\n<\/ul>\n<p>The interesting thing is that by multiplying the 3 above indicators, you obtain the total revenue of the cohort for a month. Therefore, if a good model is achieved to estimate them, future cash flows of a company or the present value of a new customer can be accurately estimated.<\/p>\n<p>In this case, we will see a cohort analysis carried out for the donors of <a href=\"http:\/\/www.techo.org\/paises\/chile\/\">Techo para Chile<\/a> in which we analyzed these 3 KPIs and decomposed them into factors. In this case, because I must maintain the anonymity of the donors and company data, I will share only the codes and the graphs without scale, but not the dataset.<\/p>\n<p>First, let&#8217;s initialize the working environment by setting some variables, loading libraries, and creating functions.<\/p>\n<pre><code class=\"language-r\">options(stringsAsFactors = FALSE)\noptions(dplyr.width = Inf)\noptions(dplyr.print_max = 100)\nSys.setenv(TZ=&#039;GMT&#039;)\nlibrary(compiler)\nlibrary(tidyverse)\nlibrary(lubridate)\nlibrary(broom)\nlibrary(plotly)\nmoda = function(x){\n  names(which.max(table(x)))\n}\nisnull = function(x,reemplazo,Nulos = c(NA,Inf,-Inf,NULL,NaN)){\n  ifelse(x %in% Nulos,reemplazo,x)\n}\ndatasetRaw = readRDS(&quot;..\/3. dataset\/dataset_cohort.rds&quot;)<\/code><\/pre>\n<p>The received dataset is a table with the cash flows from 2016 and 2017. The trick to make this analysis easier is to make the months in which donors do not make their contribution appear and fill them with a 0. On the other hand, we will keep only the contributions from the first 36 months of the donors&#8217; life.<\/p>\n<pre><code class=\"language-r\">grilla = group_by(datasetRaw,nro_contrato,mes_activacion,monto_inicial,banco_t0,region,banco_t0, origen_pago_t0, hombre) %&gt;%\n  summarise() %&gt;%\n  crossing(meses = 1:36) %&gt;%\n  mutate(periodo = months(meses-1) + mes_activacion) %&gt;%\n  filter(periodo &gt;= as.Date(&quot;2016-01-01&quot;) &amp;  periodo &lt;= as.Date(&quot;2017-12-01&quot;))\n\ndataset = grilla %&gt;%  \n  left_join(datasetRaw) %&gt;%\n  mutate(hombre = as.numeric(hombre),\n         monto = replace_na(monto,0)) %&gt;%\n  group_by(nro_contrato) %&gt;%\n  arrange(meses) %&gt;%\n  mutate(meses_activo = meses - min(c(meses[monto&gt;0],9999))[1],\n         meses_activo = replace(meses_activo,meses_activo &lt;= 1,NA))<\/code><\/pre>\n<p><strong>KPI Activations<\/strong><br \/>\nThe activations or donor acquisitions are not very constant; they can be seen by region and bank respectively:<\/p>\n<pre><code class=\"language-r\">tmp = filter(dataset, meses == 1)\ngr = ggplot(tmp,aes(mes_activacion,fill = region)) + geom_bar()\nggplotly(gr,width = 800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2392\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/activaciones_reg\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"activaciones_reg\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2392\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_reg.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<pre><code class=\"language-r\">tmp = filter(dataset, meses == 1)\ngr = ggplot(tmp,aes(mes_activacion,fill = banco_t0)) + geom_bar()\nggplotly(gr,width = 800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2393\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/activaciones_banco\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"activaciones_banco\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2393\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/activaciones_banco.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p><strong>KPI Average Revenue<\/strong><br \/>\nThe natural thing is to see a histogram of the initial donation for the time window and extract some statistics such as mean ($4,569) and median ($5,000).<\/p>\n<pre><code class=\"language-r\">dataset_t0 = dataset  %&gt;%\n    group_by(nro_contrato,mes_activacion,region,hombre, banco_t0) %&gt;%  \n    summarise(monto_inicial = mean(monto_inicial)) %&gt;%\n    filter(dataset_t0, monto_inicial &lt;= 20000) # Remove some outliers\ngr = ggplot(dataset_t0,aes(monto_inicial)) + geom_histogram(bins = 30)\nggplotly(gr,width = 800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2401\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/aporte\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"aporte\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/aporte-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2401\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>What is really interesting is to understand why the donations are different and separate the factors, in order to target better donors in the future. In this case, we will analyze with the attributes we have: gender, region, and bank.<br \/>\nThe decomposition will be done with a linear regression with dummy variables, where the betas will represent the contribution of each attribute to the average donation.<br \/>\nDue to correlation, for each of the dimensions or attributes, the first category will disappear, which is interpreted as the weights being relative to the value of the missing attribute. On the other hand, we will omit the significance analysis.<\/p>\n<p>We can see that those who donate using the BICE bank have an average contribution $1,500 higher than the reference level, so it should be prioritized against Movistar and Presto which are $3,000 below the reference level. On the other hand, it is convenient to run fundraising campaigns in the 2nd and 11th regions where donors give more.<\/p>\n<pre><code class=\"language-r\">tmp = dataset %&gt;% filter(monto&gt;0 &amp; monto &lt;=20000)\nfit_monto_t0 = lm(monto_inicial ~ region + hombre + origen_pago_t0, tmp)\ngr_data = tidy(fit_monto_t0)[-1,]\ngr = ggplot(gr_data,aes(term,estimate)) +\n  geom_bar(stat=&quot;identity&quot;)+  \n  theme(axis.text.x = element_text(angle = 45,hjust = 1))\nggplotly(gr,width = 800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2405\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/aporte_descompuesto\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"aporte_descompuesto\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2405\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/aporte_descompuesto.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p><strong>KPI Survival Rate<\/strong><br \/>\nThis is the most complex KPI because it evolves over time.<br \/>\nThe equivalent of the average donation histogram is the average survival rate graph, which looks like this for the first 15 months:<\/p>\n<pre><code class=\"language-r\">tmp = dataset %&gt;%\n  filter(mes_activacion &gt;= as.Date(&quot;2016-01-01&quot;) &amp; meses &lt; 15) %&gt;%\n  filter(!is.na(meses_activo)) %&gt;%\n  group_by(meses) %&gt;%\n  summarise(supervivencia = mean(monto &gt;0))\ngr = ggplot(tmp,aes(meses,supervivencia)) +geom_line()\nggplotly(gr,wifth=800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2407\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/conversion\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"conversion\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/conversion-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2407\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>The graph above speaks for itself. Up to month 15, customer loss is more or less linear, but we would like to separate that graph into factors: in this case, seasonality and number of months.<br \/>\nTo achieve the decomposition, we will do a regression with dummy variables for each month and period, thus not assuming any shape for the curve. The betas associated with the period will represent the seasonality.<\/p>\n<p>The graph by deseasonalized number of month is almost identical to the previous case, only the level changes, but I cannot show it:<\/p>\n<pre><code class=\"language-r\">tmp = dataset %&gt;%\n  filter(mes_activacion &gt;= as.Date(&quot;2016-01-01&quot;) &amp; meses &lt; 15) %&gt;%\n  filter(!is.na(meses_activo)) %&gt;%\n  mutate(periodo = as.character(periodo),\n         meses = as.character(meses),\n         supervivencia = monto&gt;0,\n         meses_activo = as.character(meses_activo))\nfit = lm(supervivencia ~ meses + periodo - 1, tmp)\nfit_tidy = tidy(fit)\nfit_meses = fit_tidy %&gt;%\n  filter(!grepl(&quot;periodo&quot;,term)) %&gt;%\n  # mutate(estimate = estimate+estimate[1]) %&gt;%\n  filter(grepl(&quot;meses&quot;,term)) %&gt;%\n  mutate(meses = as.numeric(str_remove(term,&quot;meses&quot;)))\ngr = ggplot(fit_meses,aes(meses, estimate)) + geom_line()\nggplotly(gr,wifth=800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2408\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/conversion_desestacionalizada\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"conversion_desestacionalizada\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2408\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_desestacionalizada.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>On the other hand, the seasonality graph shows that there are better months than others. In particular, the end of 2016 and beginning of 2017 were very bad, then there was a recovery that was lost in 2017\/10.<\/p>\n<pre><code class=\"language-r\">fit_periodo = fit_tidy %&gt;%\n  filter(grepl(&quot;periodo&quot;,term)) %&gt;%\n  mutate(periodo = as.Date(str_remove(term,&quot;periodo&quot;)))\ngr = ggplot(fit_periodo,aes(periodo, estimate)) + geom_line()\nggplotly(gr,wifth=800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2409\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/conversion_mensual\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"conversion_mensual\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2409\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_mensual.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>Finally, like in the decomposition of average donation, we will perform a decomposition of survival. To do this, we must assume a shape for the survival curve, which in this case will be a straight line.<br \/>\nWe are going to estimate the contribution to the slope of the survival curve of each of the factors we have to analyze. The trick is to reflect the shape of the curve in the dummy variables of the model; in this case, since it is linear, we will put the month number.<\/p>\n<p>The banks Security, Itau, and BICE are those with the best survival rate, while Estado, Falabella, and Retail Cards are the customers who last the least. On the other hand, regions 11 and 15 are where donors last the longest.<\/p>\n<pre><code class=\"language-r\">tmp = dataset %&gt;%\n  filter(mes_activacion &gt;= as.Date(&quot;2016-01-01&quot;) &amp; meses &lt; 15) %&gt;%\n  filter(!is.na(meses_activo)) %&gt;%\n  group_by(meses,periodo,region,hombre,banco_t0) %&gt;%\n  summarise(tasa_supervivencia = mean(monto&gt;0), casos = n()) %&gt;%\n  filter(casos &gt; 25) %&gt;%\n  ungroup() %&gt;%\n  mutate(periodo = as.character(periodo),\n         supervivencia  = (monto &gt; 0)*1)\nmat = model.matrix(~supervivencia+  meses + periodo + region + hombre + banco_t0-1,tmp) %&gt;% data.frame()\nmat[,!grepl(&quot;periodo|supervivencia&quot;,colnames(mat))] = mat[,!grepl(&quot;periodo|supervivencia&quot;,colnames(mat))] *mat$meses\nmat = select(mat,-meses)\nfit = lm(supervivencia ~ . -1, as.data.frame(mat))\ndata_fit = tidy(fit) %&gt;%\n  filter(!str_detect(term,&quot;periodo&quot;))\ngr = ggplot(data_fit,aes(term,estimate)) +\n  geom_bar(stat=&quot;identity&quot;) +\n  theme(axis.text.x = element_text(angle = 45,hjust = 1))+\n  ylab(&quot;contribution to survival rate&quot;)+\n  xlab(&quot;dimension&quot;)\nggplotly(gr,width = 800)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2415\" data-permalink=\"https:\/\/geekosas.com\/index.php\/es\/2018\/06\/18\/separar-efectos-y-analisis-de-camada\/conversion_descompuest2\/\" data-orig-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?fit=3000%2C1800&amp;ssl=1\" data-orig-size=\"3000,1800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"conversion_descompuest2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?fit=1024%2C614&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2-1024x614.png?resize=810%2C486\" alt=\"\" width=\"810\" height=\"486\" class=\"alignnone size-large wp-image-2415\" srcset=\"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?resize=768%2C461&amp;ssl=1 768w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/conversion_descompuest2.png?w=3000&amp;ssl=1 3000w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p><strong>Conclusions<\/strong><br \/>\nMore than a conclusion, now what must be done is a model that uses the calculated parameters and values the average acquisition for the product cross of each of the modeled attributes. This will allow optimizing the location of people seeking donors. For example, clients of BICE bank appear to be good ones, so it may be a good idea to place a volunteer at the entrance of BICE bank.<\/p>\n<p>Greetings!<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>In subscription businesses (Newspapers, Cell Phones, Insurance, etc&#8230;), the business is always the same: acquire a customer and then receive cash flows associated with a <a class=\"mh-excerpt-more\" href=\"https:\/\/geekosas.com\/index.php\/2018\/05\/23\/separate-effects-and-cohort-analysis\/\" title=\"Separate Effects and Cohort Analysis\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2390,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-3321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sin-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/06\/techo.png?fit=348%2C180&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8vjqF-Rz","jetpack-related-posts":[{"id":3269,"url":"https:\/\/geekosas.com\/index.php\/2016\/05\/23\/playing-with-neural-networks\/","url_meta":{"origin":3321,"position":0},"title":"Playing with Neural Networks","author":"Daniel Fischer","date":"2016-05-23","format":false,"excerpt":"A few days ago I wrote about neural networks, trying to explain in a simple way how they work and why this type of technology is called \"artificial intelligence.\" The important thing about this technique and what makes it so revolutionary is the concept of training, but it is often\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/04\/tensorflow.png?fit=1200%2C715&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/04\/tensorflow.png?fit=1200%2C715&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/04\/tensorflow.png?fit=1200%2C715&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/04\/tensorflow.png?fit=1200%2C715&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/04\/tensorflow.png?fit=1200%2C715&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3296,"url":"https:\/\/geekosas.com\/index.php\/2017\/05\/23\/i-will-teach-an-r-course\/","url_meta":{"origin":3321,"position":1},"title":"I will teach an R course.","author":"Daniel Fischer","date":"2017-05-23","format":false,"excerpt":"The course will be at Microsoft Chile on September 22: The R Intensive is an event designed for those who have data analysis and modeling needs in their work and want to gain in 1 day the theoretical and practical knowledge to start solving their analytical challenges with this tool.\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/11\/RStudio-Ball.png?fit=1000%2C1000&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/11\/RStudio-Ball.png?fit=1000%2C1000&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/11\/RStudio-Ball.png?fit=1000%2C1000&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/11\/RStudio-Ball.png?fit=1000%2C1000&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3274,"url":"https:\/\/geekosas.com\/index.php\/2016\/05\/23\/segment-customers-step-by-step\/","url_meta":{"origin":3321,"position":2},"title":"Segment customers step by step","author":"Daniel Fischer","date":"2016-05-23","format":false,"excerpt":"Previously I wrote about neural networks (click here to see it). Neural networks and all other \"supervised methods\" are used when you have a sample of values to predict. But when you know what you want to achieve but do not have a sample of the value to predict, the\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/05\/kmenas6.png?fit=620%2C539&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/05\/kmenas6.png?fit=620%2C539&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/05\/kmenas6.png?fit=620%2C539&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3314,"url":"https:\/\/geekosas.com\/index.php\/2017\/05\/23\/estimation-of-vote-distribution-in-the-second-round-of-the-chilean-presidential-elections-2017\/","url_meta":{"origin":3321,"position":3},"title":"Estimation of vote distribution in the second round of the Chilean presidential elections 2017","author":"Daniel Fischer","date":"2017-05-23","format":false,"excerpt":"This article was made in a hurry and with little data; the definitive one is at Who voted for each candidate? After the first round of the Chilean presidential elections, it is traditional for each candidate to begin \"auctioning off\" the votes of their followers to the candidate they feel\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2017\/12\/segunda-vuelta.jpg?fit=710%2C399&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2017\/12\/segunda-vuelta.jpg?fit=710%2C399&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2017\/12\/segunda-vuelta.jpg?fit=710%2C399&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2017\/12\/segunda-vuelta.jpg?fit=710%2C399&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3216,"url":"https:\/\/geekosas.com\/index.php\/2026\/05\/16\/3216\/","url_meta":{"origin":3321,"position":4},"title":"Sudoku","author":"Daniel Fischer","date":"2026-05-16","format":false,"excerpt":"The first question on my first optimization exam was to formulate a mathematical model for solving a Sudoku puzzle. Well, at that moment I made a huge mistake: I included nonlinear constraints, which resulted in a score of 0. And since this was one of my favorite subjects, I\u2019ve always\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3302,"url":"https:\/\/geekosas.com\/index.php\/2017\/05\/23\/sparse-matrix-in-r\/","url_meta":{"origin":3321,"position":5},"title":"Sparse Matrix in R","author":"Daniel Fischer","date":"2017-05-23","format":false,"excerpt":"The values 0 in matrices are very frequent, especially in dummy variables, so in R there is a package called Matrix which allows creating sparse matrices, in other words, matrices that do not use memory when an element's value is 0. But skipping the zeros is computationally complex, so it\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/mb-1024x1024.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/mb-1024x1024.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/mb-1024x1024.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/mb-1024x1024.png?resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts\/3321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/comments?post=3321"}],"version-history":[{"count":1,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts\/3321\/revisions"}],"predecessor-version":[{"id":3322,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts\/3321\/revisions\/3322"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/media\/2390"}],"wp:attachment":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/media?parent=3321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/categories?post=3321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/tags?post=3321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}