createContinuousCovariates: Create a set of continuous covariates

Description Usage Arguments Author(s) See Also Examples

View source: R/createContinuousCovariates.R

Description

Creates a set of conntinuous covariates from a multivariate normal distribution and (optionally) a set of constraints.

Usage

1
2
3
4
5
6
7
8
9
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 parseCovMatrix for details. 1 by default

range

(Optional) Ranges of acceptable values for each covariates. See parseRangeCode for 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 parseCharInput so it can either be a character vector or a numeric vector. See parseCharInput. If the parsed digits vector does not have length one or length equal to the number of covariates, an error is generated by the ectdStop function. 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 current random seed

idCol

(Optional) Name of the subject column. Must be a valid R name (See validNames) and not equal to one entry of names. "SUBJ" by default

includeIDCol

(Optional) Should the subject column be included. Typically only set to FALSE when called from createCovariates. Defaults to TRUE

Author(s)

Mike K Smith mstoolkit@googlemail.com

See Also

createDiscreteCovariates to create covariates for a discrete distribution.

createExternalCovariates to create covariates by sampling data from an external file.

createTimeVaryingCovariates to create time-varying covariates.

createCovariates that wraps createContinuousCovariates and the two other described above.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  # 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"  )

MSToolkit documentation built on May 2, 2019, 6:30 p.m.