
# OccupancyRatios
# Lasse Leskelä 2011-11-04
#
# Input:
# X (N-vector) sample path of a random process with values in [1,k]
# k (integer) number of states 
#
# Output:
# Y (kxN matrix) Y[i,n] is the fraction of time indices i <= n such that X[n] = i
#

OccupancyRatios <- function (X,k) {
  N <- length(X)
  Y <- matrix(0,k,N)
  for (i in 1:k) {
    Y[i,] <- cumsum(X==i)/(1:N)
  }
  Y
}

