1500 links in the chain
#initialize the data
p<-c(.01,.07,.07,.85)
A1<-matrix(c(0,0,0,.16),2)
A2<-matrix(c(.2,.23,-.26,.22),2)
A3<-matrix(c(-.15,.26,.28,.24),2)
A4<-matrix(c(.85,-.04,.04,.85),2)
A<-list(A1,A2,A3,A4)
b1<-c(0,0)
b2<-c(0,1.6)
b3<-c(0,.44)
b4<-c(0,1.6)
b<-list(b1,b2,b3,b4)
theta<-c(1,2,3,4)
#set the initial state
X.old<-c(0,0)
X.coord<-X.old[1]
Y.coord<-X.old[2]
#create a sample path with 15000 states
for (i in 1:15000) {
theta.t<-sample(theta,1,,p)
X.new<-A[[theta.t]] %*% X.old + b[[theta.t]]
X.coord<-cbind(X.coord,X.new[1])
Y.coord<-cbind(Y.coord,X.new[2])
X.old<-X.new
}
#plot
plot(X.coord,Y.coord,main="Something Beautiful", cex = .8)
Trace path
d <- data.frame(x = c(X.coord),
y = c(Y.coord),
time = 1:length(X.coord))
library(ggplot2)
ggplot(d, aes(x, y)) +
geom_path(aes(colour = as.numeric(time)))