Skip to contents

Use RE_cor to generate the random effects correlation matrix, under the assumption of common heterogeneity variance (i.e. all within-study correlations are 0.5). Use which_RE to return a vector of IDs for the RE deltas (0 means no RE delta on this arm).

Usage

RE_cor(study, trt, contrast, type = c("reftrt", "blshift"))

which_RE(study, trt, contrast, type = c("reftrt", "blshift"))

Arguments

study

A vector of study IDs (integer, character, or factor)

trt

A factor vector of treatment codes (or coercible as such), with first level indicating the reference treatment

contrast

A logical vector, of the same length as study and trt, indicating whether the corresponding data are in contrast rather than arm format.

type

Character string, whether to generate RE structure under the "reference treatment" parameterisation, or the "baseline shift" parameterisation.

Value

For RE_cor(), a correlation matrix of dimension equal to the number of random effects deltas (excluding those that are set equal to zero).

For which_RE(), an integer vector of IDs indexing the rows and columns of the correlation matrix returned by RE_cor().

Examples

RE_cor(smoking$studyn, smoking$trtn, contrast = rep(FALSE, nrow(smoking)))
#> Coerced `trt` to factor.
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]  1.0  0.5  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#>  [2,]  0.5  1.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#>  [3,]  0.0  0.0  1.0  0.5  0.5    0    0    0    0     0     0     0     0
#>  [4,]  0.0  0.0  0.5  1.0  0.5    0    0    0    0     0     0     0     0
#>  [5,]  0.0  0.0  0.5  0.5  1.0    0    0    0    0     0     0     0     0
#>  [6,]  0.0  0.0  0.0  0.0  0.0    1    0    0    0     0     0     0     0
#>  [7,]  0.0  0.0  0.0  0.0  0.0    0    1    0    0     0     0     0     0
#>  [8,]  0.0  0.0  0.0  0.0  0.0    0    0    1    0     0     0     0     0
#>  [9,]  0.0  0.0  0.0  0.0  0.0    0    0    0    1     0     0     0     0
#> [10,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     1     0     0     0
#> [11,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     1     0     0
#> [12,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     1     0
#> [13,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     1
#> [14,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [15,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [16,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [17,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [18,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [19,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [20,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [21,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [22,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [23,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [24,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [25,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [26,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [27,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [28,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [29,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [30,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#> [31,]  0.0  0.0  0.0  0.0  0.0    0    0    0    0     0     0     0     0
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#>  [1,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [2,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [3,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [4,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [5,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [6,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [7,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [8,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>  [9,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [10,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [11,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [12,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [13,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [14,]     1     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [15,]     0     1     0     0     0     0     0     0     0     0   0.0   0.0
#> [16,]     0     0     1     0     0     0     0     0     0     0   0.0   0.0
#> [17,]     0     0     0     1     0     0     0     0     0     0   0.0   0.0
#> [18,]     0     0     0     0     1     0     0     0     0     0   0.0   0.0
#> [19,]     0     0     0     0     0     1     0     0     0     0   0.0   0.0
#> [20,]     0     0     0     0     0     0     1     0     0     0   0.0   0.0
#> [21,]     0     0     0     0     0     0     0     1     0     0   0.0   0.0
#> [22,]     0     0     0     0     0     0     0     0     1     0   0.0   0.0
#> [23,]     0     0     0     0     0     0     0     0     0     1   0.0   0.0
#> [24,]     0     0     0     0     0     0     0     0     0     0   1.0   0.5
#> [25,]     0     0     0     0     0     0     0     0     0     0   0.5   1.0
#> [26,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [27,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [28,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [29,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [30,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#> [31,]     0     0     0     0     0     0     0     0     0     0   0.0   0.0
#>       [,26] [,27] [,28] [,29] [,30] [,31]
#>  [1,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [2,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [3,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [4,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [5,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [6,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [7,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [8,]   0.0   0.0   0.0   0.0   0.0   0.0
#>  [9,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [10,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [11,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [12,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [13,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [14,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [15,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [16,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [17,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [18,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [19,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [20,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [21,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [22,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [23,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [24,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [25,]   0.0   0.0   0.0   0.0   0.0   0.0
#> [26,]   1.0   0.5   0.0   0.0   0.0   0.0
#> [27,]   0.5   1.0   0.0   0.0   0.0   0.0
#> [28,]   0.0   0.0   1.0   0.5   0.0   0.0
#> [29,]   0.0   0.0   0.5   1.0   0.0   0.0
#> [30,]   0.0   0.0   0.0   0.0   1.0   0.5
#> [31,]   0.0   0.0   0.0   0.0   0.5   1.0
RE_cor(smoking$studyn, smoking$trtn, contrast = rep(FALSE, nrow(smoking)), type = "blshift")
#> Coerced `trt` to factor.
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]  1.0  0.5  0.0  0.0    0    0    0    0    0     0     0     0     0
#>  [2,]  0.5  1.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#>  [3,]  0.0  0.0  1.0  0.5    0    0    0    0    0     0     0     0     0
#>  [4,]  0.0  0.0  0.5  1.0    0    0    0    0    0     0     0     0     0
#>  [5,]  0.0  0.0  0.0  0.0    1    0    0    0    0     0     0     0     0
#>  [6,]  0.0  0.0  0.0  0.0    0    1    0    0    0     0     0     0     0
#>  [7,]  0.0  0.0  0.0  0.0    0    0    1    0    0     0     0     0     0
#>  [8,]  0.0  0.0  0.0  0.0    0    0    0    1    0     0     0     0     0
#>  [9,]  0.0  0.0  0.0  0.0    0    0    0    0    1     0     0     0     0
#> [10,]  0.0  0.0  0.0  0.0    0    0    0    0    0     1     0     0     0
#> [11,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     1     0     0
#> [12,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     1     0
#> [13,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     1
#> [14,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [15,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [16,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [17,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [18,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [19,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [20,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [21,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [22,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [23,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [24,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [25,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#> [26,]  0.0  0.0  0.0  0.0    0    0    0    0    0     0     0     0     0
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#>  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [10,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [11,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [12,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [13,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [14,]     1     0     0     0     0     0     0     0     0     0     0     0
#> [15,]     0     1     0     0     0     0     0     0     0     0     0     0
#> [16,]     0     0     1     0     0     0     0     0     0     0     0     0
#> [17,]     0     0     0     1     0     0     0     0     0     0     0     0
#> [18,]     0     0     0     0     1     0     0     0     0     0     0     0
#> [19,]     0     0     0     0     0     1     0     0     0     0     0     0
#> [20,]     0     0     0     0     0     0     1     0     0     0     0     0
#> [21,]     0     0     0     0     0     0     0     1     0     0     0     0
#> [22,]     0     0     0     0     0     0     0     0     1     0     0     0
#> [23,]     0     0     0     0     0     0     0     0     0     1     0     0
#> [24,]     0     0     0     0     0     0     0     0     0     0     1     0
#> [25,]     0     0     0     0     0     0     0     0     0     0     0     1
#> [26,]     0     0     0     0     0     0     0     0     0     0     0     0
#>       [,26]
#>  [1,]     0
#>  [2,]     0
#>  [3,]     0
#>  [4,]     0
#>  [5,]     0
#>  [6,]     0
#>  [7,]     0
#>  [8,]     0
#>  [9,]     0
#> [10,]     0
#> [11,]     0
#> [12,]     0
#> [13,]     0
#> [14,]     0
#> [15,]     0
#> [16,]     0
#> [17,]     0
#> [18,]     0
#> [19,]     0
#> [20,]     0
#> [21,]     0
#> [22,]     0
#> [23,]     0
#> [24,]     0
#> [25,]     0
#> [26,]     1
which_RE(smoking$studyn, smoking$trtn, contrast = rep(FALSE, nrow(smoking)))
#> Coerced `trt` to factor.
#>  [1]  0  1  2  3  4  5  0  6  0  7  0  8  0  9  0 10  0 11  0 12  0 13  0 14  0
#> [26] 15  0 16  0 17  0 18  0 19  0 20  0 21  0 22  0 23 24 25 26 27 28 29 30 31
which_RE(smoking$studyn, smoking$trtn, contrast = rep(FALSE, nrow(smoking)), type = "blshift")
#> Coerced `trt` to factor.
#>  [1]  0  1  2  0  3  4  0  5  0  6  0  7  0  8  0  9  0 10  0 11  0 12  0 13  0
#> [26] 14  0 15  0 16  0 17  0 18  0 19  0 20  0 21  0 22  0 23  0 24  0 25  0 26