knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/"
)

PhaseTypeR: general-purpose phase-type functions

DOI R-CMD-check CRAN devel Version downloads Codecov test coverage

This package implements core functions from phase-type theory. Its general functions are useful for a wide-ranging variety of contexts. PhaseTypeR can be used to model continuous and discrete phase-type distributions, both univariate and multivariate. The package includes functions for outputting the mean and (co)variance of phase-type distributions; their density, probability and quantile functions; functions for random draws; functions for reward-transformation; and functions for plotting the distributions as networks.

Installation

You can install PhaseTypeR from CRAN via:

install.packages("PhaseTypeR")

If you install devtools in your R environment with install.packages("devtools"), the development version of the package can be installed with the following command:

devtools::install_github("rivasiker/PhaseTypeR")

These installations should handle the missing dependencies, but you can manually install them by running the following:

install.packages("expm")
install.packages("igraph")

Basic example

This is a basic example for the univariate continuous phase-type distribution.

# Load the package
library(PhaseTypeR)

# Define the sub-intensity rate matrix
subintensity_matrix <- matrix(c(-1.5,  0,  0,
                                 1.5, -1,  0,
                                  0,   1, -0.5), ncol = 3)
# Define the initial probabilities
initial_probabilities <- c(0.9, 0.1, 0)

# Create continuous phase-type object
ph <- PH(subintensity_matrix, initial_probabilities)

Summary of the object:

summary(ph)

Density function:

dPH(1:5, ph)

Cumulative density function:

pPH(1:5, ph)

Quantile function:

qPH(c(0.25, 0.5, 0.75), ph)

Random sampling:

set.seed(0)
rPH(6, ph)

Learn more

You can check out the full functionality of PhaseTypeR and its application to population genetics in the following guides:

Report an issue

If you have found a bug, you can file an issue at https://github.com/rivasiker/PhaseTypeR/issues. Please, make sure to read the contribution guidelines and the code of conduct before making any changes.



rivasiker/PhaseTypeR documentation built on April 27, 2023, 2:50 p.m.