% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convertFx.R
\name{convertFx}
\alias{convertFx}
\title{Convert Life Table Indicators}
\usage{
convertFx(x, data, from, to, ...)
}
\arguments{
\item{x}{Numeric vector of ages at the beginning of each age interval. 
For a full life table, use single-year ages (e.g., \code{0:110}). 
For an abridged life table, use the lower bound of each interval 
(e.g., \code{c(0, 1, 5, 10, ..., 110)}).}

\item{data}{A numeric \code{vector}, \code{matrix}, or \code{data.frame} 
containing the mortality indicator to be converted. Each row should 
correspond to an age, each column to a separate population or time 
period.}

\item{from}{The type of indicator supplied in \code{data}. One of:
\code{"mx"}, \code{"qx"}, \code{"dx"}, or \code{"lx"}.}

\item{to}{The desired output indicator. One of:
\code{"mx"}, \code{"qx"}, \code{"dx"}, \code{"lx"}, \code{"Lx"}, 
\code{"Tx"}, or \code{"ex"}.}

\item{...}{Further arguments passed to \code{\link{LifeTable}} that may 
affect the results, such as \code{sex}, \code{lx0}, or \code{ax}.}
}
\value{
A numeric vector or matrix containing the converted life table 
  indicator. If the input was a named object, the output retains those 
  names.
}
\description{
Easily convert between different life table indicators (e.g., from death 
rates \code{mx} to death probabilities \code{qx}, or from survivorship 
\code{lx} to life expectancy \code{ex}). The function wraps 
\code{\link{LifeTable}} internally, so the conversion relies on the 
same constant-force-of-mortality (CFM) assumption and life-table 
methodology used throughout the package.
}
\details{
This function provides a convenient interface for converting a single 
mortality indicator into another, without having to call 
\code{\link{LifeTable}} directly and extract the desired column.

The supported \strong{input} types (\code{from}) are:
\code{mx}, \code{qx}, \code{dx}, and \code{lx}.

The supported \strong{output} types (\code{to}) are:
\code{mx}, \code{qx}, \code{dx}, \code{lx}, \code{Lx}, \code{Tx}, and 
\code{ex}.

There are 28 possible \code{from}-\code{to} combinations (4 inputs 
\eqn{\times} 7 outputs). All conversions pass through the full life-table 
computation; for example, converting \code{mx} to \code{ex} will 
internally compute \code{qx}, \code{lx}, \code{dx}, \code{Lx}, and 
\code{Tx} in sequence.

When \code{data} is a \code{vector}, the function returns a named vector. 
When \code{data} is a \code{matrix} or \code{data.frame} with multiple 
columns, the function applies the conversion column-wise and returns a 
matrix with the same row and column names as the input.
}
\examples{
# ---- Basic conversions ----

x  <- 0:110
mx <- ahmd$mx

# Convert death rates to death probabilities
qx <- convertFx(x, data = mx, from = "mx", to = "qx")

# Convert death rates to death distribution
dx <- convertFx(x, data = mx, from = "mx", to = "dx")

# Convert death rates to survivorship
lx <- convertFx(x, data = mx, from = "mx", to = "lx")

# ---- All 28 possible conversions ----

from <- c("mx", "qx", "dx", "lx")
to   <- c("mx", "qx", "dx", "lx", "Lx", "Tx", "ex")
K    <- expand.grid(from = from, to = to)

for (i in 1:nrow(K)) {
  In  <- as.character(K[i, "from"])
  Out <- as.character(K[i, "to"])
  N   <- paste0(Out, "_from_", In)
  cat(i, " Create", N, "\n")
  assign(N, convertFx(x = x, data = get(In), from = In, to = Out))
}

}
\seealso{
\code{\link{LifeTable}} for the underlying life-table construction; 
\code{\link{LawTable}} for generating life tables from parametric 
  mortality laws.
}
\author{
Marius D. Pascariu
}
