Define Transition Matrix for Markov Model

Description

Define a matrix of transition probabilities. Probability can depend on parameters defined with define_parameters, and can thus be time-dependent.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
define_matrix(...)

define_matrix_(...)

define_transition(..., state_names)

define_transition_(.dots, state_names)

## S3 method for class 'uneval_matrix'
modify(.OBJECT, ...)

## S3 method for class 'uneval_matrix'
plot(x, relsize = 0.75, shadow.size = 0,
  latex = TRUE, ...)

Arguments

...

Name-value pairs of expressions definig matrix cells. Can refer to parameters defined with define_parameters. For plot, additional arguments passed to digram::plotmat.

state_names

character vector, optional. State names.

.dots

Used to work around non-standard evaluation.

.OBJECT

An object of class uneval_matrix.

x

An uneval_matrix to plot.

relsize

Argument passed to plotmat.

shadow.size

Argument passed to plotmat.

latex

Argument passed to plotmat.

Details

Parameters names are searched first in a parameter object defined with define_parameters and linked with the matrix through define_strategy; then in the environment where the matrix was defined.

Matric cells are listed by row.

The completary probability of all other row probabilities can be conveniently reffered as C.

Only matrix size is checked during this step (the matrix must be square). Other conditions (such as row sums being equal to 1) are tested later, during model evaluation.

For the modify function existing matrix cells are replaced with the new expression. Cells are referenced by name. Cell naming follows the cell_x_y convention, with x being the row number and y the column number.

Value

An object of class uneval_matrix (actually a named list of lazy expressions).

Examples

 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
# simple 3x3 transition matrix

mat_1 <- define_transition(
  .2, 0, .8,
  0, .1, .9,
  0, 0, 1
)
mat_1

plot(mat_1)

# referencing parameters
# rr must be present in a parameter object
# that must later be linked with define_strategy

define_transition(
  .5 - rr, rr,
  .4, .6
)

# can also use C

define_transition(
  C, rr,
  .4, .6
)

# updating cells from mat_1

modify(
  mat_1,
  cell_2_1 = .2,
  cell_2_3 = .7
)

# only matrix size is check, it is thus possible
# to define an incorrect matrix

# this matrix will generate an error later,
# during model evaluation

define_transition(
  .5, 3,
  -1, 2
)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.