Create a set of continuous covariates
Source:R/createContinuousCovariates.R
      createContinuousCovariates.RdCreates a set of continuous covariates from a multivariate normal distribution and (optionally) a set of constraints.
Usage
createContinuousCovariates(
  subjects,
  names,
  mean,
  covariance = 1,
  range = NULL,
  digits,
  maxDraws = 100,
  seed = .deriveFromMasterSeed(),
  idCol = getEctdColName("Subject"),
  includeIDCol = TRUE
)Arguments
- subjects
 (Required) Subjects for which to create covariates
- names
 (Required) Names for the continuous covariates. They should be valid R names (See
validNames) and no duplicate name should be given- mean
 (Required) Vector of means. Must be of same length than
names- covariance
 (Optional) Lower triangle of covariance matrix. See
parseCovMatrixfor details. 1 by default- range
 (Optional) Ranges of acceptable values for each covariates. See
parseRangeCodefor details. This is missing by default, resulting in no "range" limitation being applied- digits
 (Optional) Number of digits used to round the values. This argument can be either missing (the default), so no rounding is done, of length one and all variables are rounded at the same digits, of same length than the number of covariates so that each covariate is rounded according to its value. This argument is first parsed by
parseCharInputso it can either be a character vector or a numeric vector. SeeparseCharInput. If the parseddigitsvector does not have length one or length equal to the number of covariates, an error is generated by theectdStopfunction. This is missing by default, resulting in no rounding being performed- maxDraws
 (Optional) Maximum number of attempts allowed if initial data not in range (100 by default)
- seed
 (Optional) Random seed to use. By default, this is derived from the master random seed
- idCol
 (Optional) Name of the subject column. Must be a valid R name (See
validNames) and not equal to one entry ofnames. "SUBJ" by default- includeIDCol
 (Optional) Should the subject column be included.
See also
createDiscreteCovariates to create covariates for a
discrete distribution.
Examples
  # 30 samples from a :      [ 0 ]   [ 1, 0, 0 ]
  #                      N ( [ 0 ] , [ 0, 1, 0 ] )
  #                          [ 1 ]   [ 0, 0, 1 ]
  dat <- createContinuousCovariates( 30,
                                     mean = "0,0,1",
                                     names = c("X", "Y", "Z")  )
  # 30 samples from a :      [ 0 ]   [ 1, 0, 0 ]
  #                      N ( [ 0 ] , [ 0, 1, 0 ] )
  #                          [ 1 ]   [ 0, 0, 1 ]
  # truncated at X > 0
  dat <- createContinuousCovariates( 30,
                                     mean = "0,0,1",
                                     names = c("X", "Y", "Z"),
     range= "X > 0"  )
  # 30 samples from a :      [ 0 ]   [ 1, 0, 0 ]
  #                      N ( [ 0 ] , [ 0, 1, 0 ] )
  #                          [ 1 ]   [ 0, 0, 1 ]
  # truncated at X = 0, and X < Y  < 1
  dat <- createContinuousCovariates( 30,
                                     mean = "0,0,1",
                                     names = c("X", "Y", "Z"),
                                     range= c("X > 0", "X< Y<1")  )
  stopifnot( all( dat$X < dat$Y ) )
  stopifnot( all( dat$X > 0 ) )
  # 30 samples from a :      [ 0 ]   [ 1 , .5, 0 ]
  #                      N ( [ 0 ] , [ .5, 1 , 0 ] )
  #                          [ 1 ]   [ 0 , 0 , 1 ]
  dat1 <- createContinuousCovariates( 30,
                                      mean = "0,0,1",
                                      names = c("X", "Y", "Z"),
                                      covariance = "1,.5,1,0,0,1",
                                      seed = 30  )
  # same
  dat2 <- createContinuousCovariates( 30,
                                      mean = "0,0,1",
                                      names = c("X", "Y", "Z"),
                                      covariance = cbind(c(1,.5,0),
                                                         c(.5,1,0),
                                                         c(0,0,1)) ,
                                      seed = 30  )
  stopifnot( all(dat1 == dat2 ))
  # use of the digits argument
  # X will be rounded at 2 digits
  # Y will be rounded at 3 digits
  # Z will be rounded at 2 digits
  createContinuousCovariates( 10,
                              mean = "100,100,100",
                              names = c("X", "Y", "Z"),
                              digits = "2,3,2"  )
#>    SUBJ      X       Y      Z
#> 1     1  99.53  99.822  99.08
#> 2     2  98.03 101.550 100.27
#> 3     3 100.12  98.669  99.43
#> 4     4  99.72  99.267 100.07
#> 5     5 100.67  98.519  98.98
#> 6     6  98.96 100.178 101.68
#> 7     7  99.97  99.585  99.25
#> 8     8 100.58 102.139 100.42
#> 9     9  99.80 100.712 100.00
#> 10   10 101.07  99.521  99.54