Creates a longitudinal dataset in the format that rbmi was
designed to analyse.
Arguments
- n
the number of subjects to sample. Total number of observations returned is thus
n * length(sd)- sd
the standard deviations for the outcome at each visit. i.e. the square root of the diagonal of the covariance matrix for the outcome
- cor
the correlation coefficients between the outcome values at each visit. See details.
- mu
the coefficients to use to construct the mean outcome value at each visit. Must be a named list with elements
int,age,sex,trt&visit. See details.
Value
as_vcov() returns a symmetric positive-definite covariance matrix (a numeric
matrix) constructed from the vector of standard deviations sd and the
correlation entries cor.
Details
The number of visits is determined by the size of the variance covariance matrix. i.e. if 3 standard deviation values are provided then 3 visits per patient will be created.
The covariates in the simulated dataset are produced as follows:
Patients age is sampled at random from a N(0,1) distribution
Patients sex is sampled at random with a 50/50 split
Patients group is sampled at random but fixed so that each group has
n/2patientsThe outcome variable is sampled from a multivariate normal distribution, see below for details
The mean for the outcome variable is derived as:
The coefficients for the intercept, age and sex are taken from mu$int,
mu$age and mu$sex respectively, all of which must be a length 1 numeric.
Treatment and visit coefficients are taken from mu$trt and mu$visit respectively
and must either be of length 1 (i.e. a constant affect across all visits) or equal to the
number of visits (as determined by the length of sd). I.e. if you wanted a treatment
slope of 5 and a visit slope of 1 you could specify:
The correlation matrix is constructed from cor as follows.
Let cor = c(a, b, c, d, e, f) then the correlation matrix would be:
Examples
# Construct a 3x3 covariance matrix from standard deviations and correlations.
# `cor` gives the upper-triangular correlations in row-major order:
# cor(1,2), cor(1,3), cor(2,3).
as_vcov(
sd = c(1, 3, 2),
cor = c(0.4, 0.5, 0.45)
)
#> [,1] [,2] [,3]
#> [1,] 1.0 1.2 1.0
#> [2,] 1.2 9.0 2.7
#> [3,] 1.0 2.7 4.0
