Skip to content

Instantly share code, notes, and snippets.

@Harshit1694
Last active July 12, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Harshit1694/38af7616e9da59bcec83606058e5d4ab to your computer and use it in GitHub Desktop.
Save Harshit1694/38af7616e9da59bcec83606058e5d4ab to your computer and use it in GitHub Desktop.
install.packages("markovchain")
install.packages("diagram")
library(markovchain)
library(diagram)
# Creating a transition matrix
trans_mat <- matrix(c(0.7,0.3,0.1,0.9),nrow = 2, byrow = TRUE)
trans_mat
# create the Discrete Time Markov Chain
disc_trans <- new("markovchain",transitionMatrix=trans_mat, states=c("Pepsi","Coke"), name="MC 1")
disc_trans
plot(disc_trans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment