Created
March 5, 2023 09:21
-
-
Save tetlabo/d5254cf6769ff869168d59e4cdc3677c to your computer and use it in GitHub Desktop.
マーケティングにおけるアトリビューションモデルのデモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ChannelAttribution) | |
library(markovchain) | |
library(igraph) | |
library(ggplot2) | |
data(PathData) | |
H<-heuristic_models(Data,"path","total_conversions",var_value="total_conversion_value") | |
H | |
M<-markov_model(Data,"path","total_conversions",var_value="total_conversion_value",out_more=T) | |
M | |
transition_matrix<-M$transition_matrix | |
trans_conversion<-data.frame(channel_from="(conversion)",channel_to=unique(as.vector(transition_matrix$channel_to)),transition_probability=0) | |
trans_start<-data.frame(channel_from="(start)",channel_to=("start"),transition_probability=0) | |
final_transition<-rbind(rbind(transition_matrix,trans_conversion),trans_start) | |
transition_frame<-reshape(transition_matrix,direction = "wide", idvar="channel_from", timevar="channel_to") | |
transition_frame[is.na(transition_frame)]<-0 | |
colnames(transition_frame)<-c("channel_from",as.vector(transition_frame$channel_from)[-1],"(start)") | |
rownames(transition_frame)<-transition_frame[,1] | |
transition_frame<-transition_frame[,-1] | |
finalmatrix<-as.matrix(transition_frame, dimnames = list(transition_frame$channel_from, colnames(transition_frame)[-1])) | |
final_obj<-new("markovchain",states=colnames(transition_frame),byrow=T,transitionMatrix=finalmatrix,name="ConversionPath") | |
plot(final_obj,edge.arrow.mode="<",vertex.size=10,vertex.color="skyblue",layout=layout.fruchterman.reingold,asp=0) | |
library(ChannelAttributionApp) | |
CAapp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment