Elements of transition probability matrices are multiplied by relative risks and the transition probability matrices are adjusted so that rows sum to 1. Operations are vectorized and each relative risk is multiplied by every transition matrix (stored in 3-dimensional arrays).

apply_rr(x, rr, index, complement = NULL)

## Arguments

x A 3-dimensional array where each slice is a square transition probability matrix. A 2-dimensional tabular object such as a matrix or data frame where each column is a vector of relative risks to apply to each transition matrix in x. The indices of the transition probability matrices that rr is applied to. Should either be a matrix where the first column denotes a transition probability matrix row and the second column denotes a transition probability matrix column or a list where each element is a vector of length 2 with the first element denoting a transition probability matrix row and the second column denoting a transition probability matrix column. Denotes indices of transition probability matrices that are "complements" (i.e., computed as $$1$$ less the sum of all other elements in that row). Should be in the same format as index. There can be at most one complementary column in each row of a transition probability matrix. If NULL, then the diagonals are assumed to be the complements.

## Value

A 3-dimensional array where each slice contains matrices of the same dimension as each matrix in x and the number of slices is equal to the number of rows in rr.

## Details

This function is useful for applying relative treatment effects measured using relative risks to an existing transition probability matrix. For example, a transition probability matrix for the reference treatment strategy may exist or have been estimated from the data. Relative risks estimated from a meta-analysis or network meta-analysis can then be applied to the reference transition probability matrix. If the number of rows in rr exceeds x, then the arrays in x are recycled to the number of rows in rr, which facilitates the application of relative risks from multiple treatment strategies to a reference treatment.

## Examples

p_12 <- c(.7, .5)
p_23 <- c(.1, .2)
x <- as_array3(tpmatrix(
C, p_12, .1,
0, C,     p_23,
0, 0,     1
))

# There are the same number of relative risk rows and transition probability matrices
rr_12 <- runif(2, .8, 1)
rr_13 <- runif(2, .9, 1)
rr <- cbind(rr_12, rr_13)
apply_rr(x, rr,
index = list(c(1, 2), c(1, 3)),
complement = list(c(1, 1), c(2, 2)))
#> , , 1
#>
#>           [,1]      [,2]       [,3]
#> [1,] 0.3386645 0.5666854 0.09465006
#> [2,] 0.0000000 0.9000000 0.10000000
#> [3,] 0.0000000 0.0000000 1.00000000
#>
#> , , 2
#>
#>           [,1]      [,2]       [,3]
#> [1,] 0.4746589 0.4334211 0.09192002
#> [2,] 0.0000000 0.8000000 0.20000000
#> [3,] 0.0000000 0.0000000 1.00000000
#>
# There are more relative risk rows than transition probability matrices
rr_12 <- runif(4, .8, 1)
rr_13 <- runif(4, .9, 1)
rr <- cbind(rr_12, rr_13)
apply_rr(x, rr,
index = list(c(1, 2), c(1, 3)),
complement = list(c(1, 1), c(2, 2)))
#> , , 1
#>
#>          [,1]      [,2]       [,3]
#> [1,] 0.229426 0.6775661 0.09300792
#> [2,] 0.000000 0.9000000 0.10000000
#> [3,] 0.000000 0.0000000 1.00000000
#>
#> , , 2
#>
#>           [,1]      [,2]       [,3]
#> [1,] 0.4913376 0.4131538 0.09550863
#> [2,] 0.0000000 0.8000000 0.20000000
#> [3,] 0.0000000 0.0000000 1.00000000
#>
#> , , 3
#>
#>           [,1]      [,2]       [,3]
#> [1,] 0.2692874 0.6366466 0.09406603
#> [2,] 0.0000000 0.9000000 0.10000000
#> [3,] 0.0000000 0.0000000 1.00000000
#>
#> , , 4
#>
#>           [,1]      [,2]       [,3]
#> [1,] 0.4310175 0.4778724 0.09111017
#> [2,] 0.0000000 0.8000000 0.20000000
#> [3,] 0.0000000 0.0000000 1.00000000
#>