The function genBlockMat() generates correlation matrices that can accommodate clustered observations over time where the within-cluster between-individual correlation in the same time period can be different from the within-cluster between-individual correlation across time periods.The matrix generated here can be used in function addCorGen().

blockDecayMat(ninds, nperiods, rho_w, r, pattern = "xsection", nclusters = 1)

Arguments

ninds

The number of units (individuals) in each cluster in each period.

nperiods

The number periods that data are observed.

rho_w

The within-period/between-individual correlation coefficient between -1 and 1.

r

The decay parameter if correlation declines over time, and can have values of "exp" or "prop". See details.

pattern

A string argument with options "xsection" (default) or "cohort".

nclusters

An integer that indicates the number of matrices that will be generated.

Value

A single correlation matrix of size nvars x nvars, or a list of matrices of potentially different sizes with length indicated by nclusters.

A single correlation matrix or a list of matrices of potentially different sizes with length indicated by nclusters.

Details

Two general decay correlation structures are currently supported: a *cross-sectional* exchangeable structure and a *closed cohort* exchangeable structure. In the *cross-sectional* case, individuals or units in each time period are distinct. In the *closed cohort* structure, individuals or units are repeated in each time period. The desired structure is specified using pattern, which defaults to "xsection" if not specified.

This function can generate correlation matrices of different sizes, depending on the combination of arguments provided. A single matrix will be generated when nclusters == 1 (the default), and a list of matrices of matrices will be generated when nclusters > 1.

If nclusters > 1, the length of ninds will depend on if sample sizes will vary by cluster and/or period. There are three scenarios, and function evaluates the length of ninds to determine which approach to take:

  • if the sample size is the same for all clusters in all periods, ninds will be a single value (i.e., length = 1).

  • if the sample size differs by cluster but is the same for each period within each cluster each period, then ninds will have a value for each cluster (i.e., length = nclusters).

  • if the sample size differs across clusters and across periods within clusters, ninds will have a value for each cluster-period combination (i.e., length = nclusters x nperiods). This option is only valid when pattern = "xsection".

In addition, rho_w and r can be specified as a single value (in which case they are consistent across all clusters) or as a vector of length nclusters, in which case either one or both of these parameters can vary by cluster.

See vignettes for more details.

References

Li et al. Mixed-effects models for the design and analysis of stepped wedge cluster randomized trials: An overview. Statistical Methods in Medical Research. 2021;30(2):612-639. doi:10.1177/0962280220932962

Examples

blockDecayMat(ninds = 4, nperiods = 3, rho_w = .8, r = .9)
#>        [,1]  [,2]  [,3]  [,4] [,5] [,6] [,7] [,8]  [,9] [,10] [,11] [,12]
#>  [1,] 1.000 0.800 0.800 0.800 0.72 0.72 0.72 0.72 0.648 0.648 0.648 0.648
#>  [2,] 0.800 1.000 0.800 0.800 0.72 0.72 0.72 0.72 0.648 0.648 0.648 0.648
#>  [3,] 0.800 0.800 1.000 0.800 0.72 0.72 0.72 0.72 0.648 0.648 0.648 0.648
#>  [4,] 0.800 0.800 0.800 1.000 0.72 0.72 0.72 0.72 0.648 0.648 0.648 0.648
#>  [5,] 0.720 0.720 0.720 0.720 1.00 0.80 0.80 0.80 0.720 0.720 0.720 0.720
#>  [6,] 0.720 0.720 0.720 0.720 0.80 1.00 0.80 0.80 0.720 0.720 0.720 0.720
#>  [7,] 0.720 0.720 0.720 0.720 0.80 0.80 1.00 0.80 0.720 0.720 0.720 0.720
#>  [8,] 0.720 0.720 0.720 0.720 0.80 0.80 0.80 1.00 0.720 0.720 0.720 0.720
#>  [9,] 0.648 0.648 0.648 0.648 0.72 0.72 0.72 0.72 1.000 0.800 0.800 0.800
#> [10,] 0.648 0.648 0.648 0.648 0.72 0.72 0.72 0.72 0.800 1.000 0.800 0.800
#> [11,] 0.648 0.648 0.648 0.648 0.72 0.72 0.72 0.72 0.800 0.800 1.000 0.800
#> [12,] 0.648 0.648 0.648 0.648 0.72 0.72 0.72 0.72 0.800 0.800 0.800 1.000
blockDecayMat(ninds = 4, nperiods = 3, rho_w = .8, r = .9, pattern = "cohort")
#>        [,1]  [,2]  [,3]  [,4] [,5] [,6] [,7] [,8]  [,9] [,10] [,11] [,12]
#>  [1,] 1.000 0.800 0.800 0.800 0.90 0.72 0.72 0.72 0.810 0.648 0.648 0.648
#>  [2,] 0.800 1.000 0.800 0.800 0.72 0.90 0.72 0.72 0.648 0.810 0.648 0.648
#>  [3,] 0.800 0.800 1.000 0.800 0.72 0.72 0.90 0.72 0.648 0.648 0.810 0.648
#>  [4,] 0.800 0.800 0.800 1.000 0.72 0.72 0.72 0.90 0.648 0.648 0.648 0.810
#>  [5,] 0.900 0.720 0.720 0.720 1.00 0.80 0.80 0.80 0.900 0.720 0.720 0.720
#>  [6,] 0.720 0.900 0.720 0.720 0.80 1.00 0.80 0.80 0.720 0.900 0.720 0.720
#>  [7,] 0.720 0.720 0.900 0.720 0.80 0.80 1.00 0.80 0.720 0.720 0.900 0.720
#>  [8,] 0.720 0.720 0.720 0.900 0.80 0.80 0.80 1.00 0.720 0.720 0.720 0.900
#>  [9,] 0.810 0.648 0.648 0.648 0.90 0.72 0.72 0.72 1.000 0.800 0.800 0.800
#> [10,] 0.648 0.810 0.648 0.648 0.72 0.90 0.72 0.72 0.800 1.000 0.800 0.800
#> [11,] 0.648 0.648 0.810 0.648 0.72 0.72 0.90 0.72 0.800 0.800 1.000 0.800
#> [12,] 0.648 0.648 0.648 0.810 0.72 0.72 0.72 0.90 0.800 0.800 0.800 1.000

blockDecayMat(ninds = 2, nperiods = 3, rho_w = .8, r = .9, pattern = "cohort", nclusters=2)
#> [[1]]
#>       [,1]  [,2] [,3] [,4]  [,5]  [,6]
#> [1,] 1.000 0.800 0.90 0.72 0.810 0.648
#> [2,] 0.800 1.000 0.72 0.90 0.648 0.810
#> [3,] 0.900 0.720 1.00 0.80 0.900 0.720
#> [4,] 0.720 0.900 0.80 1.00 0.720 0.900
#> [5,] 0.810 0.648 0.90 0.72 1.000 0.800
#> [6,] 0.648 0.810 0.72 0.90 0.800 1.000
#> 
#> [[2]]
#>       [,1]  [,2] [,3] [,4]  [,5]  [,6]
#> [1,] 1.000 0.800 0.90 0.72 0.810 0.648
#> [2,] 0.800 1.000 0.72 0.90 0.648 0.810
#> [3,] 0.900 0.720 1.00 0.80 0.900 0.720
#> [4,] 0.720 0.900 0.80 1.00 0.720 0.900
#> [5,] 0.810 0.648 0.90 0.72 1.000 0.800
#> [6,] 0.648 0.810 0.72 0.90 0.800 1.000
#> 
blockDecayMat(ninds = c(2, 3), nperiods = 3, rho_w = c(.8,0.7), r = c(.9,.8), 
  pattern = "cohort", nclusters=2)
#> [[1]]
#>       [,1]  [,2] [,3] [,4]  [,5]  [,6]
#> [1,] 1.000 0.800 0.90 0.72 0.810 0.648
#> [2,] 0.800 1.000 0.72 0.90 0.648 0.810
#> [3,] 0.900 0.720 1.00 0.80 0.900 0.720
#> [4,] 0.720 0.900 0.80 1.00 0.720 0.900
#> [5,] 0.810 0.648 0.90 0.72 1.000 0.800
#> [6,] 0.648 0.810 0.72 0.90 0.800 1.000
#> 
#> [[2]]
#>        [,1]  [,2]  [,3] [,4] [,5] [,6]  [,7]  [,8]  [,9]
#>  [1,] 1.000 0.700 0.700 0.80 0.56 0.56 0.640 0.448 0.448
#>  [2,] 0.700 1.000 0.700 0.56 0.80 0.56 0.448 0.640 0.448
#>  [3,] 0.700 0.700 1.000 0.56 0.56 0.80 0.448 0.448 0.640
#>  [4,] 0.800 0.560 0.560 1.00 0.70 0.70 0.800 0.560 0.560
#>  [5,] 0.560 0.800 0.560 0.70 1.00 0.70 0.560 0.800 0.560
#>  [6,] 0.560 0.560 0.800 0.70 0.70 1.00 0.560 0.560 0.800
#>  [7,] 0.640 0.448 0.448 0.80 0.56 0.56 1.000 0.700 0.700
#>  [8,] 0.448 0.640 0.448 0.56 0.80 0.56 0.700 1.000 0.700
#>  [9,] 0.448 0.448 0.640 0.56 0.56 0.80 0.700 0.700 1.000
#> 
blockDecayMat(ninds = c(2, 3, 4, 4, 2, 1), nperiods = 3, rho_w = .8, r = .9, nclusters=2)
#> [[1]]
#>        [,1]  [,2] [,3] [,4] [,5]  [,6]  [,7]  [,8]  [,9]
#>  [1,] 1.000 0.800 0.72 0.72 0.72 0.648 0.648 0.648 0.648
#>  [2,] 0.800 1.000 0.72 0.72 0.72 0.648 0.648 0.648 0.648
#>  [3,] 0.720 0.720 1.00 0.80 0.80 0.720 0.720 0.720 0.720
#>  [4,] 0.720 0.720 0.80 1.00 0.80 0.720 0.720 0.720 0.720
#>  [5,] 0.720 0.720 0.80 0.80 1.00 0.720 0.720 0.720 0.720
#>  [6,] 0.648 0.648 0.72 0.72 0.72 1.000 0.800 0.800 0.800
#>  [7,] 0.648 0.648 0.72 0.72 0.72 0.800 1.000 0.800 0.800
#>  [8,] 0.648 0.648 0.72 0.72 0.72 0.800 0.800 1.000 0.800
#>  [9,] 0.648 0.648 0.72 0.72 0.72 0.800 0.800 0.800 1.000
#> 
#> [[2]]
#>       [,1]  [,2]  [,3]  [,4] [,5] [,6]  [,7]
#> [1,] 1.000 0.800 0.800 0.800 0.72 0.72 0.648
#> [2,] 0.800 1.000 0.800 0.800 0.72 0.72 0.648
#> [3,] 0.800 0.800 1.000 0.800 0.72 0.72 0.648
#> [4,] 0.800 0.800 0.800 1.000 0.72 0.72 0.648
#> [5,] 0.720 0.720 0.720 0.720 1.00 0.80 0.720
#> [6,] 0.720 0.720 0.720 0.720 0.80 1.00 0.720
#> [7,] 0.648 0.648 0.648 0.648 0.72 0.72 1.000
#>