Anonymous Anonymous - 4 months ago
980 0

transition_matrix

Other

transition_matrix.csv

channel_from,channel_to,transition_probability
(start),(start),0.0
(start),GenericPaidSearch,0.376931847
(start),OrganicSearch,0.1583607803
(start),Direct,0.1617304282
(start),Affiliates,0.06141373195
(start),BrandedPaidSearch,0.09394476818
(start),NewsletterEmail,0.08080820877
(start),Social,0.01664555359
(start),Referral,0.02351152774
(start),Marketplaces,0.01268051685
(start),OtherEmail,0.006169242463
(start),Display,0.007803394984
GenericPaidSearch,(conversion),0.02651812072
GenericPaidSearch,(null),0.2476859187
GenericPaidSearch,OrganicSearch,0.2285895362
GenericPaidSearch,Direct,0.2588602212
GenericPaidSearch,Affiliates,0.0969996164
GenericPaidSearch,BrandedPaidSearch,0.06868026485
GenericPaidSearch,Display,0.02521723178
GenericPaidSearch,NewsletterEmail,0.02054737404
GenericPaidSearch,Referral,0.009589886422
GenericPaidSearch,OtherEmail,0.01099084374
GenericPaidSearch,Social,0.002601777882
GenericPaidSearch,Marketplaces,0.003719208126
OrganicSearch,(conversion),0.02078346335
OrganicSearch,(null),0.1832774789
OrganicSearch,GenericPaidSearch,0.3098087809
OrganicSearch,Direct,0.2380804866
OrganicSearch,Affiliates,0.1181390633
OrganicSearch,BrandedPaidSearch,0.05074769777
OrganicSearch,Display,0.01765749528
OrganicSearch,Referral,0.02190993833
OrganicSearch,NewsletterEmail,0.01774198091
OrganicSearch,OtherEmail,0.0102509223
OrganicSearch,Marketplaces,0.009406066068
OrganicSearch,Social,0.002196626207
Direct,(conversion),0.02450243414
Direct,(null),0.4800257732
Direct,GenericPaidSearch,0.1784972795
Direct,OrganicSearch,0.05675472509
Direct,NewsletterEmail,0.08523052692
Direct,Affiliates,0.05566294387
Direct,BrandedPaidSearch,0.0754760882
Direct,Referral,0.0139604811
Direct,OtherEmail,0.01299398625
Direct,Display,0.00911010882
Direct,Social,0.005709478809
Direct,Marketplaces,0.002076174112
Affiliates,(conversion),0.02438903239
Affiliates,(null),0.4040830519
Affiliates,Direct,0.1892509438
Affiliates,GenericPaidSearch,0.1748460163
Affiliates,OrganicSearch,0.1359527121
Affiliates,Referral,0.01082853169
Affiliates,BrandedPaidSearch,0.02021657063
Affiliates,Display,0.01192131929
Affiliates,NewsletterEmail,0.01241804093
Affiliates,Marketplaces,0.009040333797
Affiliates,Social,0.00213590304
Affiliates,OtherEmail,0.004917544208
BrandedPaidSearch,(conversion),0.02266020236
BrandedPaidSearch,(null),0.2972702361
BrandedPaidSearch,Direct,0.2903667791
BrandedPaidSearch,GenericPaidSearch,0.138806914
BrandedPaidSearch,OrganicSearch,0.1208368465
BrandedPaidSearch,Affiliates,0.07172217538
BrandedPaidSearch,NewsletterEmail,0.03014333895
BrandedPaidSearch,OtherEmail,0.01001264755
BrandedPaidSearch,Display,0.01032883642
BrandedPaidSearch,Referral,0.007641231029
BrandedPaidSearch,Social,0.0002107925801
NewsletterEmail,(conversion),0.006875954994
NewsletterEmail,(null),0.3729684678
NewsletterEmail,Direct,0.4032504515
NewsletterEmail,GenericPaidSearch,0.0902903181
NewsletterEmail,BrandedPaidSearch,0.04847895541
NewsletterEmail,OrganicSearch,0.02312821225
NewsletterEmail,Referral,0.01125156272
NewsletterEmail,Affiliates,0.0151409918
NewsletterEmail,OtherEmail,0.01090429226
NewsletterEmail,Display,0.01416863453
NewsletterEmail,Marketplaces,0.002986525906
NewsletterEmail,Social,0.0005556327268
Social,(conversion),0.005744375299
Social,(null),0.3834370512
Social,Direct,0.3011010053
Social,Display,0.07802776448
Social,NewsletterEmail,0.04930588798
Social,GenericPaidSearch,0.1196744854
Social,Affiliates,0.01914791766
Social,BrandedPaidSearch,0.02202010531
Social,OrganicSearch,0.02058401149
Social,OtherEmail,0.0004786979416
Social,Marketplaces,0.0004786979416
Referral,(conversion),0.01395039858
Referral,(null),0.3492028344
Referral,Direct,0.2843224092
Referral,GenericPaidSearch,0.1051815766
Referral,Affiliates,0.08414526129
Referral,OrganicSearch,0.06753764393
Referral,BrandedPaidSearch,0.02701505757
Referral,NewsletterEmail,0.05823737821
Referral,OtherEmail,0.009743135518
Referral,Social,0.0004428697963
Referral,Marketplaces,0.0002214348981
Marketplaces,(conversion),0.009984235418
Marketplaces,(null),0.3657383079
Marketplaces,Direct,0.2548607462
Marketplaces,GenericPaidSearch,0.1397792958
Marketplaces,OrganicSearch,0.09353652128
Marketplaces,Display,0.05570152391
Marketplaces,Affiliates,0.07409353652
Marketplaces,Social,0.0005254860746
Marketplaces,NewsletterEmail,0.001050972149
Marketplaces,OtherEmail,0.002627430373
Marketplaces,BrandedPaidSearch,0.002101944298
OtherEmail,(conversion),0.005845816588
OtherEmail,(null),0.4607234198
OtherEmail,Direct,0.3704786262
OtherEmail,GenericPaidSearch,0.0686883449
OtherEmail,OrganicSearch,0.02922908294
OtherEmail,NewsletterEmail,0.04128607965
OtherEmail,BrandedPaidSearch,0.02046035806
OtherEmail,Affiliates,0.002922908294
OtherEmail,Referral,0.0003653635367
Display,(conversion),0.004073807812
Display,(null),0.5837526959
Display,GenericPaidSearch,0.1430625449
Display,Direct,0.1418643662
Display,Social,0.0393002636
Display,OrganicSearch,0.03882099209
Display,NewsletterEmail,0.02204648934
Display,BrandedPaidSearch,0.02156721783
Display,Affiliates,0.003594536305
Display,OtherEmail,0.001198178768
Display,Marketplaces,0.0004792715073
Display,Referral,0.0002396357537
(conversion), (conversion), 1.0
(null), (null), 1.0
R

R code

> library(ChannelAttribution)
> library(dplyr)
> library(reshape2)
> library(ggplot2)
> df_trans <- read.csv("transition_matrix.csv")
> df_trans$channel_from <- factor(df_trans$channel_from, levels = c('(start)', '(conversion)', '(null)', 'GenericPaidSearch', 'OrganicSearch', 'Direct', 'Affiliates', 'BrandedPaidSearch', 'NewsletterEmail', 'Social', 'Referral', 'Marketplaces', 'OtherEmail', 'Display'))
> df_trans$channel_to <- factor(df_trans$channel_to, levels = c('(start)', '(conversion)', '(null)', 'GenericPaidSearch', 'OrganicSearch', 'Direct', 'Affiliates', 'BrandedPaidSearch', 'NewsletterEmail', 'Social', 'Referral', 'Marketplaces', 'OtherEmail', 'Display'))
> df_trans <- dcast(df_trans, channel_from ~ channel_to, value.var = 'transition_probability')

> trans_matrix <- 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)] <- 0

> trans_matrix1 <- new("markovchain", transitionMatrix = trans_matrix)