-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
112 lines (78 loc) · 3.64 KB
/
README.Rmd
File metadata and controls
112 lines (78 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```
# PhaseTypeR: general-purpose phase-type functions
<!-- badges: start -->
[](https://doi.org/10.21105/joss.05054)
[](https://github.com/rivasiker/PhaseTypeR/actions/workflows/check-standard.yaml)
[](https://CRAN.R-project.org/package=PhaseTypeR)
[](https://github.com/rivasiker/PhaseTypeR)
[](https://CRAN.R-project.org/package=PhaseTypeR)
[](https://app.codecov.io/gh/rivasiker/PhaseTypeR?branch=master)
<!-- badges: end -->
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:
``` r
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:
``` r
devtools::install_github("rivasiker/PhaseTypeR")
```
These installations should handle the missing dependencies, but you can manually install them by running the following:
``` r
install.packages("expm")
install.packages("igraph")
```
## Basic example
This is a basic example for the univariate continuous phase-type distribution.
```{r warning=FALSE, message=FALSE}
# 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:
```{r}
summary(ph)
```
Density function:
```{r}
dPH(1:5, ph)
```
Cumulative density function:
```{r}
pPH(1:5, ph)
```
Quantile function:
```{r}
qPH(c(0.25, 0.5, 0.75), ph)
```
Random sampling:
```{r}
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:
- [Getting Started](https://rivasiker.github.io/PhaseTypeR/articles/PhaseTypeR.html)
- [Using PhaseTypeR for population genetics](https://rivasiker.github.io/PhaseTypeR/articles/a2_pop_gen_iker.html)
- [Using PhaseTypeR for the site frequency spectrum](https://rivasiker.github.io/PhaseTypeR/articles/a3_phasetypeR_SFS.html)
## 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](.github/CONTRIBUTING.md) and the [code of conduct](.github/CODE_OF_CONDUCT.md) before making any changes.