zero_matrix_trans: Create a structural zero matrix representing general...

Description Usage Arguments Details Value See Also Examples

View source: R/zero_matrix_trans.R

Description

Create a structural zero matrix representing showing, permissible transitions between states, where, typically, many transitions are prohibited. Examples include transitions between marital statuses or between health statuses.

Usage

1
zero_matrix_trans(trans, basename = "state")

Arguments

trans

A named list.

basename

Prefix used to construct dimension names. Defaults to "state".

Details

trans is a named list. The names of the list give the origin states, and the elements of the list are character vectors with the destination states: see below for examples.

If an origin state has no destination states (ie it is an "absorbing" state), then the list element for that origin can be a zero-length character vector, or NULL.

Transitions from a state to itself are allowed: a an element of trans can include its own name.

Value

A square matrix of TRUEs and FALSEs, with dimnames constructed from nest.

See Also

zero_matrix_diag deals with a common special case.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
trans <- list(Single = c("Married", "Separated"),
              Married = "Separated",
              Separated = "Married")
zero_matrix_trans(trans)
zero_matrix_trans(trans, basename = "marital_status")


trans <- list(Primary = c("Primary", "Secondary"), # transition to self
              Secondary = c("Secondary", "Tertiary"), # transition to self
              Tertiary = "Tertiary") # transition to self
zero_matrix_trans(trans)

trans <- list(Healthy = c("Sick", "Dead"),
              Sick = c("Healthy", "Dead"),
              Dead = NULL) # absorbing state
zero_matrix_trans(trans)

trans <- list(Healthy = c("Sick", "Dead"),
              Sick = c("Healthy", "Dead"),
              Dead = character()) # character rather than NULL
zero_matrix_trans(trans)

johnrbryant/demzero documentation built on June 15, 2020, 11:39 p.m.