2015-09-23 1 views
1

J'essaye de créer un graphique de Markov en utilisant le paquet markovchain. Le code est le suivantMarkov Graphique de la matrice de transition

library(ChannelAttribution) 
library(markovchain) 
data(PathData) 
m<-markov_model(Dy, "channel_path", "total_conversions", "total_conversion_value",out_more = 1) 

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)") 


finalmatrix<-as.matrix(transition_frame, dimnames = list(transition_frame$channel_from, colnames(transition_frame)[-1])) 

plot(finalmatrix) 

Cependant, je continue à obtenir l'erreur suivante

> plot(finalmatrix) 
Error in plot.window(...) : need finite 'xlim' values 
In addition: Warning messages: 
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 
2: In min(x) : no non-missing arguments to min; returning Inf 
3: In max(x) : no non-missing arguments to max; returning -Inf 

Toute aide à cet égard serait grandement apprécié.

+0

Eh bien, la première chose qui vient à l'esprit est la suivante: avez-vous vérifié la variable 'finalmatrix'? A-t-il des valeurs non finies? – tguzella

Répondre

1

Vous devez créer un objet markovchain avant le traçage. J'ai trouvé l'exemple ci-dessous ici de https://cran.r-project.org/web/packages/markovchain/vignettes/an_introduction_to_markovchain_package.pdf

weatherStates <- c("sunny", "cloudy", "rain") 
byRow <- TRUE 
weatherMatrix <- matrix(data = c(0.70, 0.2, 0.1, 
           0.3, 0.4, 0.3, 
           0.2, 0.45, 0.35), 
         byrow = byRow, nrow = 3, 
         dimnames = list(weatherStates, weatherStates)) 
mcWeather <- new("markovchain", states = weatherStates, byrow = byRow, 
transitionMatrix = weatherMatrix, name = "Weather")