inst/resources/scripts/MCEstimation.r

# program spuRs/resources/scripts/MCEstimation.R
# loadable spuRs function

# This function estimates the transition matrix for a discrete MC
# with known state space {0,1,..,n}
# based on observations of the chain stored in statehist.

MCEstimation <- function(statehist, n) {
  ntrans <- length(statehist) - 1
  TC <- matrix(0, nrow = n+1, ncol = n+1)
  for (trans in 2:ntrans) {
    TC[statehist[trans - 1] + 1, statehist[trans] + 1] <-
      TC[statehist[trans - 1] + 1, statehist[trans] + 1] + 1
  }
  return(TC/rowSums(TC))
}

Try the spuRs package in your browser

Any scripts or data that you put into this service are public.

spuRs documentation built on May 2, 2019, 12:44 p.m.