Hello there!

Remmy is my name and I came across an interesting code in R on this web https://stat.ethz.ch/pipermail/r-help/2004-May/050424.html , there are some parts that I have not followed and I would like to get some comments if you may!

Please comment on the highlighted  two parts of the code below in color blue!

I create a rotine for a problem like this, I hope this is useful for you
------------
#############################################
##            MARKOV CHAIN                 ## 
##                                         ##
## ini- initial state                      ## 
## trans- transition matrix                ##
## n - number of transitions               ##
## f - ini%*%trans                         ##  
## fase - f consolidate                    ##
##                                         ## 
#############################################



#          initial state

ini<-matrix(c(10,0,0,0,0,0,0,0,0),nrow=3,ncol=3)

#          transition matrix
#
#      [,1] [,2] [,3]
# [1,] 0.85  0.1  0.05
# [2,] 0.00  0.7  0.3
# [3,] 0.00  0.0  1.0
#
# In R the command is

trans<-matrix(c(.85,0,0,.1,.7,0,0.05,0.3,1),ncol=3)

markov<-function(ini,trans,n){
  l<-ncol(ini)
  fase<-matrix(0,nrow=l,ncol=l)
  fases<-array(0,dim=c(nrow(ini),ncol(ini),n))
  for (i in 1:n){
    f<-ini%*%trans
 for (w in 1:l){fase[w,w]<-sum(f[,w])}  

  ini<-fase

 fases[,,i]<-fase

# print(fase)
# 
# Fase allow calcule de value for transition:
# If sate 1 value 0,95, state 2 value 0,3 and  state 3
# value 0 QALY. 
# I´m calculate de value of any transition if
#  print(sum(fase%*%c(.95,.3,0)))
#
# 

  }
  return(fases)
}

	[[alternative HTML version deleted]]

