简体   繁体   English

R中的通用马尔可夫链

[英]generic markov chain in r

I need construct a generic markov chain from the following data for the weather patterns in newyork. 我需要从以下数据构建通用的马尔可夫链,以了解纽约的天气模式。 There are three regions- manhattan, bronx and queens- I need to have a overall markov chain graph that describes the average transition probabilities for the whole region. 一共有三个区域-曼哈顿,布朗克斯区和皇后区-我需要有一个整体的马尔可夫链图来描述整个区域的平均过渡概率。

state<- c('rainy', 'sunny', 'rainy', 'sunny', 'cold' ,'rainy', 'cold')
region<- c('manhttan', 'manhattan', 'bronx', 'bronx', 'queens', 'queens', 'queens')
df<- data.frame(region, state)

 library(markovchain)
 mcFit <- markovchainFit(data=df$state)
 print(mcFit)
 plot(mcFit$estimate, edge.arrow.size=.89)

any ideas? 有任何想法吗?

The following gives a list of transition matrices by region: 以下列出了按地区列出的转换矩阵:

M <- tapply(state, region, function(s) 
  markovchainFit(data = s)$estimate@transitionMatrix)

Hence, the average one then is 因此,平均数为

Reduce("+", M) / length(M)

In this case it doesn't really work though, because there is too little data to estimate a decent matrix for each region. 在这种情况下,它实际上并不起作用,因为数据太少,无法估计每个区域的体面矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM