文書の過去の版を表示しています。


markovchain

markovchainパッケージは、離散状態離散時間マルコフ過程(通称は離散マルコフ過程、あるいはマルコフ連鎖)をRで扱うのに便利な機能を提供する。以下の説明は、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")
mcList <- new("markovchainList", markovchains = list(mcWeather, defaultMc),
 name = "A list of Markov chains")

markovchainのメソッド

MethodPurpose
*Direct multiplication for transition matrices.
[Direct access to the elements of the transition matrix.
==

as Operator to convert markovchain objects into data.frame and table object.|

dimDimension of the transition matrix.
namesEqual to states.
names←Change the states name.
nameGet the name of markovchain object.
name←Change the name of markovchain object.
plotplot method for markovchain objects.
printprint method for markovchain objects.
showshow method for markovchain objects.
sortsort method for markovchain objects.
statesName of the transition states.
tTransposition operator (which switches byrow slot value and modifies the transition matrix coherently).