0

I have built the matrix below (sim1) with the following function.

MarkovCohort <- function(P, z0, ncycles, costs, qolw, discount){
      # Calculates quantities for cost-effectiveness analysis using a markov
      # cohort model.
      #
      # Args:
      #   P: State transition matrix.
      #   z0: Initial values of z
      #   ncycles: number of cycles
      #   costs: vector containing costs in each state. May be a time 
      #         constant vector or time varying list of vectors.
      #   qolw: vector containing quality of life weight in each state.
      #           May be a time constant vector or time varying list of
      #           vectors
      #   discount: cycle discount rate
      #
      # Returns:
      #   List containing proportion in each state by cycle, costs, and effects.
      if (is.list(P)){
        nc <- ncol(P[[1]])
      } else {
        nc <- ncol(P)
      }
      z <- rbind(z0, matrix(NA, nrow = ncycles, ncol = nc))
      c <- e <- rep(NA, ncycles)
      delta <- 1/(1 + discount)^(seq(0, ncycles))
      for (t in 2:(ncycles+1)){
        # z
        if (is.list(P) == TRUE) {
          z[t, ] <- z[t-1, , drop = FALSE] %*%  P[[t-1]] 
        } else{
          z[t, ] <- z[t-1, , drop = FALSE] %*%  P
        }
        
        # costs
        if (is.list(costs)){
          c[t] <- delta[t] * z[t, ] %*% costs[[t-1]]/sum(z0)
        } else{
          c[t] <- delta[t] * z[t, ] %*% costs/sum(z0)
        }
        
        # effectiveness
        if (is.list(effects)){
          e[t] <- z[t, ] %*% qolw[[t-1]]/sum(z0)
        } else{
          e[t] <- z[t, ] %*% qolw/sum(z0)
        }
      }
      return(list(z = z, c = c[-1], e = e[-1]))
    }



    sim1 <- MarkovCohort(P = c(replicate(2, P.1, simplify = FALSE), 
                               replicate(ncycles - 2, P.0, simplify = FALSE)),
                         z0 = c(1, 0, 0, 0), ncycles = ncycles,
                         costs = c(replicate(2, c.1, simplify = FALSE),
                                   replicate(ncycles - 2, c.0, simplify = FALSE)),
                         qolw = qolw, discount = 0.06)

If you a look at it:

[,1]        [,2]       [,3]       [,4]
z0 1.000000000 0.000000000 0.00000000 0.00000000
   0.858000000 0.103000000 0.03400000 0.00500000
   0.736164000 0.169435000 0.08017500 0.01422600
   0.530774244 0.247146863 0.17841428 0.04366461
   0.382688230 0.250808725 0.26996136 0.09654169
   0.275918214 0.223022891 0.33019028 0.17086861
   0.198937032 0.185311779 0.35689955 0.25885164
   0.143433600 0.147851424 0.35642534 0.35228964
   0.103415626 0.114875265 0.33710458 0.44460453
   0.074562666 0.087632485 0.30651152 0.53129333
   0.053759682 0.065976132 0.27054576 0.60971843
   0.038760731 0.049191589 0.23336350 0.67868418
   0.027946487 0.036409981 0.19764057 0.73800296
   0.020149417 0.026799389 0.16492171 0.78812949
   0.014527730 0.019640627 0.13594864 0.82988300
   0.010474493 0.014345806 0.11092857 0.86425113
   0.007552110 0.010450761 0.08973697 0.89226016
   0.005445071 0.007597418 0.07206217 0.91489534
   0.003925896 0.005514004 0.05750360 0.93305650
   0.002830571 0.003996668 0.04563493 0.94753783
   0.002040842 0.002893839 0.03604249 0.95902283

I know that it is built according to some criteria. Could you please suggest which is it, if you have experience with the Markov model? It is for figuring out cells in an Excel spreadsheet. I have read some tutorials around the web, but cannot figure out exactly the intimate building criteria.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
12666727b9
  • 1,133
  • 1
  • 8
  • 22

0 Answers0