【问题标题】:Markov Graph from transition matrix来自转移矩阵的马尔可夫图
【发布时间】:2015-12-20 09:43:45
【问题描述】:

我正在尝试使用包 markovchain 创建一个马尔可夫图。代码如下

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)

但是我不断收到以下错误

> 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

在这方面的任何帮助将不胜感激。

【问题讨论】:

  • 嗯,首先想到的是:您检查了finalmatrix 变量吗?它有任何非限定值吗?

标签: r igraph markov-chains


【解决方案1】:

您需要在绘图之前创建一个马尔可夫链对象。我从下面找到了这个例子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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-01
    • 2013-01-02
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多