Nothing
# Function to compute the value of \eqn{H}
.get.H <- function(q) {
k <- dim(q)[3] - 1
hik <- apply(X = q, MARGIN = c(1, 3), sum)
Hik <- t(apply(X = hik, MARGIN = 1, cumsum))
H <- array(data = 0, dim = c(nrow(q), ncol(q), k + 1))
for (j in 1:(k + 1)) {
H[, , j] <- diag(Hik[, j])
}
return(H)
}
#' Cumulative distribution functions of the sojourn times in each state
#'
#' @description Computes, from a semi-Markov kernel \eqn{q}, the diagonal
#' matrix-valued function
#' \eqn{H(k) = \textrm{diag}(H_i(k);\ i \in E)}{H(k) = diag(H_i(k), i in E)}
#' (Barbu and Limnios, 2008, Definition 3.4, p. 47, and p. 51), where
#' \eqn{H_i} is the cumulative distribution function of the sojourn time in
#' state \eqn{i}:
#' \deqn{H_i(k) = P(X_{n + 1} \le k \mid J_n = i) = \sum_{l = 1}^{k} \sum_{j \in E} q_{ij}(l).}{H_i(k) = P(X_{n+1} <= k | J_n = i) = sum_{l = 1}^{k} sum_{j in E} q_ij(l).}
#'
#' @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{(X_n)_{n \in \mathbb{N}^*}}{(X_n), n in N*} the sojourn times,
#' \eqn{q} the semi-Markov kernel and \eqn{s = \textrm{card}(E)}{s = card(E)}.
#'
#' The function \eqn{I - H(k)}, where \eqn{I} is the identity matrix,
#' gives the survival functions
#' \eqn{\overline{H}_i(k) = P(X_{n + 1} > k \mid J_n = i)}{bar H_i(k) = P(X_{n+1} > k | J_n = i)}
#' of the sojourn times; it is used to compute the transition function
#' \eqn{P = \psi * (I - H)}{P = psi * (I - H)} (see [get.P]).
#'
#' \eqn{H_i(k)} tends to 1 as \eqn{k} tends to infinity. When the sojourn
#' times have a finite support, \eqn{H_i(k) = 1} for \eqn{k} larger than the
#' maximal sojourn time.
#'
#' @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 diagonal matrix \eqn{H(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], [get.psi], [get.P], [meanSojournTimes]
#'
#' @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)
#' H <- get.H(q)
#' H[, , 6] # H(5)
#' t(apply(H, 3, diag))[1:6, ] # H_i(l), l = 0, ..., 5
#'
#' @export
#'
get.H <- function(q) {
#############################
# checking parameters q
#############################
.is.kernel(q)
H <- .get.H(q)
return(H)
}
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.