Nothing
# Function to compute the value of \eqn{\psi}
.get.psi <- function(q) {
k <- dim(q)[3] - 1
psi <- array(data = 0, dim = c(nrow(q), ncol(q), k + 1)) # (S, S, k + 1)
psi[, , 1] <- diag(x = 1, nrow = nrow(q), ncol = ncol(q)) # k = 0
for (j in 1:k) {
psi[, , j + 1] <-
-Reduce('+', lapply(
X = 0:(j - 1),
FUN = function(l)
psi[, , l + 1] %*% (-q[, , j - l + 1])
))
}
return(psi)
}
#' Markov renewal function \ifelse{html}{\out{ψ}}{psi} of a semi-Markov kernel
#'
#' @description Computes, from a semi-Markov kernel \eqn{q}, the matrix-valued
#' function \eqn{\psi}{psi} (Barbu and Limnios, 2008, Proposition 3.4,
#' Equations (3.14)-(3.16), p. 53):
#' \deqn{\psi(k) = \sum_{n = 0}^{k} q^{(n)}(k), \quad k \in \mathbb{N},}{psi(k) = sum_{n = 0}^{k} q^(n)(k), k in N,}
#' where \eqn{q^{(n)}}{q^(n)} is the \eqn{n}-fold matrix convolution of
#' \eqn{q} (see [matrixConvolution]) and \eqn{q^{(0)} = \delta I}{q^(0) = delta I}.
#'
#' @details Notation (see [smmR-package] for the complete description of the
#' models): \eqn{(J_n)_{n \in \mathbb{N}}}{(J_n), n in N} is the embedded Markov
#' chain, \eqn{(S_n)_{n \in \mathbb{N}}}{(S_n), n in N} the jump times, \eqn{q}
#' the semi-Markov kernel and \eqn{s = \textrm{card}(E)}{s = card(E)}.
#'
#' \eqn{\psi_{ij}(k)}{psi_ij(k)} is the probability that the
#' semi-Markov chain enters state \eqn{j} at time \eqn{k} (i.e. that a jump
#' to \eqn{j} occurs at time \eqn{k}), given that it entered state \eqn{i}
#' at time 0 (Equation (3.19), p. 54):
#' \deqn{\psi_{ij}(k) = P\left(\bigcup_{n = 0}^{k} \{J_n = j, S_n = k\} \,\middle|\, J_0 = i\right).}{psi_ij(k) = P(union_{n = 0}^{k} {J_n = j, S_n = k} | J_0 = i).}
#' Since there are no instantaneous transitions (\eqn{q(0) = 0}), the sum is
#' finite and \eqn{\psi}{psi} is computed exactly by the recursion
#' \deqn{\psi(0) = I, \quad \psi(k) = \sum_{l = 0}^{k - 1} \psi(l)\, q(k - l), \quad k \ge 1,}{psi(0) = I, psi(k) = sum_{l = 0}^{k-1} psi(l) q(k - l), k >= 1,}
#' which is the solution of the Markov renewal equation
#' \eqn{\psi = \delta I + \psi * q}{psi = delta I + psi * q}. \eqn{\psi}{psi}
#' is the inverse of \eqn{\delta I - q}{delta I - q} for the matrix
#' convolution product, and the transition function of the semi-Markov chain
#' is \eqn{P = \psi * (I - H)}{P = psi * (I - H)} (see [get.P]).
#'
#' @param q A numeric array of dimension \eqn{(s, s, k + 1)}, where
#' \eqn{s = \textrm{card}(E)}{s = card(E)}, giving the values of a
#' semi-Markov kernel at times \eqn{0, \dots, k}{0, ..., k}, typically the
#' output of [get.kernel] (or of [get.qy]).
#'
#' @return A numeric array of dimension \eqn{(s, s, k + 1)} whose slice
#' \eqn{l + 1} is the matrix \eqn{\psi(l)}{psi(l)}, for
#' \eqn{l = 0, \dots, k}{l = 0, ..., k}.
#'
#' @references
#' V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov
#' Models Toward Applications - Their Use in Reliability and DNA Analysis.
#' New York: Lecture Notes in Statistics, vol. 191, Springer.
#'
#' @seealso [get.kernel], [matrixConvolution], [get.H], [get.P]
#'
#' @examples
#' states <- c("a", "b", "c")
#' ptrans <- matrix(c(0, 0.6, 0.4,
#' 0.5, 0, 0.5,
#' 0.7, 0.3, 0), nrow = 3, byrow = TRUE)
#' param <- matrix(c(0.3, 2, 0.6,
#' NA, NA, 0.8), nrow = 3)
#' x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
#' ptrans = ptrans, type.sojourn = "fi",
#' distr = c("geom", "pois", "dweibull"), param = param)
#'
#' q <- get.kernel(x, k = 20)
#' psi <- get.psi(q)
#' psi[, , 4] # psi(3)
#'
#' # psi is the sum of the n-fold convolutions of q
#' qn <- q
#' s <- array(0, dim(q)); s[, , 1] <- diag(3) # q^(0)
#' for (n in 1:20) {
#' s <- s + qn
#' qn <- matrixConvolution(qn, q)
#' }
#' all.equal(s, psi)
#'
#' @export
#'
get.psi <- function(q) {
.is.kernel(q)
psi <- .get.psi(q)
return(psi)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.