construct_CovMat: Construct a Covariance Matrix

View source: R/construct_CovMat.R

construct_CovMatR Documentation

Construct a Covariance Matrix

Description

constructs a (block diagonal) covariance matrix. This function calls 'construct_CovBlk' (or 'construct_CovSubMat' in case of repeated observations of the same individuals) for each block.

Usage

construct_CovMat(
  sumCl = NULL,
  timepoints = NULL,
  sigma,
  tau,
  eta = NULL,
  AR = NULL,
  rho = NULL,
  gamma = NULL,
  trtMat = NULL,
  N = NULL,
  CovBlk = NULL,
  psi = NULL,
  INDIV_LVL = FALSE
)

Arguments

sumCl

total number of clusters

timepoints

numeric (scalar or vector), number of timepoints (periods). If design is swd, timepoints defaults to length(Cl)+1. Defaults to 1 for parallel designs.

sigma

numeric, residual error of cluster means if no N given.

tau

numeric, standard deviation of random intercepts

eta

numeric (scalar or matrix), standard deviation of random slopes. If 'eta' is given as scalar, 'trtMat' is needed as well.

AR

numeric, vector containing up to three values, each between 0 and 1. Defaults to NULL. It defines the AR(1)-correlation of random effects. The first element corresponds to the cluster intercept, the second to the treatment effect and the third to subject specific intercept. If only one element is provided, autocorrelation of all random effects is assumed to be the same. *Currently not compatible with 'rho'!=0 !*

rho

numeric (scalar), correlation of 'tau' and 'eta'. The default is no correlation.

gamma

numeric (scalar), random time effect

trtMat

a matrix of dimension *#Cluster* x *timepoints* as produced by the function 'construct_trtMat', indicating the cluster-periods that receive interventional treatment. Defaults to NULL. If trtMat is given, the arguments 'sumCl' and 'timepoints' are ignored (!).

N

numeric, number of individuals per cluster. Either a scalar, vector of length #Clusters or a matrix of dimension #Clusters x timepoints. Defaults to 1 if not passed.

CovBlk

a matrix of dimension *timepoints* x *timepoints*.

psi

numeric (scalar), random subject specific intercept. Leads to a closed cohort setting

INDIV_LVL

logical, should the computation be conducted on an individual level? This leads to longer run time and is mainly for diagnostic purposes.

Value

a covariance matrix

Examples


## Two clusters, three timepoints,
## residual standard error sd=3, random slope sd=1.
construct_CovMat(sumCl=2, timepoints=3, sigma=3, tau=1)
##
##
## ... with random slope as AR-1 process
construct_CovMat(sumCl=2, timepoints=3, sigma=3, tau=1, AR=.8)
##
##
## ... with sigma and tau variing over time and between clusters:
construct_CovMat(sumCl=2,timepoints=3,
                 sigma=matrix(c(1,2,2,1,1,2),nrow=2, byrow=TRUE),
                 tau=matrix(c(.2,.1,.1,.2,.2,.1),nrow=2, byrow=TRUE),
                 N=c(3,4))

PMildenb/SteppedPower documentation built on Sept. 20, 2023, 4:57 a.m.