% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tpm_functions.R
\name{generator_g}
\alias{generator_g}
\title{Build generator matrices of a continuous-time Markov chain}
\usage{
generator_g(Z, beta, Eta = NULL, byrow = FALSE, report = TRUE)
}
\arguments{
\item{Z}{Covariate design matrix with or without intercept column, i.e. of dimension \code{c(nObs, p)} or \code{c(nObs, p+1)}. If not provided, intercept column is added automatically.}

\item{beta}{Matrix of coefficients for the off-diagonal elements of the generator matrix 
of dimension \code{c(nStates * (nStates-1), p+1)}. First columns contains the intercepts.}

\item{Eta}{optional pre-calculated matrix of linear predictors of dimension \code{c(nObs, nStates * (nStates-1))}.
If provided, no \code{Z} and \code{beta} are necessary and will be ignored.}

\item{byrow}{logical indicating if the generator matrices should be filled by row}

\item{report}{logical, indicating whether the generator matrices \code{Q} should be reported from the fitted model. Defaults to \code{TRUE}, but only works if when automatic differentiation with \code{RTMB} is used.}
}
\value{
array of infinitesimal generator matrices of dimension \code{c(nStates, nStates, nObs)}
}
\description{
This function builds \strong{infinitesimal generator matrices} for a \strong{continuous-time Markov chain} based on a design matrix and coefficient matrix.
}
\details{
Off-diagonal entries are calculated as \eqn{\exp(Z \beta_i)} to ensure positivity. The diagonal entries are then set to the negative row sums, which is required for generator matrices.
}
\examples{
# 2 states: 2 free off-diagonal elements
generator(rep(-1, 2))
# 3 states: 6 free off-diagonal elements
generator(rep(-2, 6))
}
\seealso{
Other transition probability matrix functions: 
\code{\link{generator}()},
\code{\link{tpm}()},
\code{\link{tpm_ct}()},
\code{\link{tpm_emb}()},
\code{\link{tpm_emb_g}()},
\code{\link{tpm_g}()},
\code{\link{tpm_g2}()},
\code{\link{tpm_p}()}
}
\concept{transition probability matrix functions}
