Description Usage Arguments Author(s) See Also Examples
View source: R/createContinuousCovariates.R
Creates a set of conntinuous covariates from a multivariate normal distribution and (optionally) a set of constraints.
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)
|
subjects |
(Required) Subjects for which to create covariates |
names |
(Required) Names for the continuous covariates. They should be valid R names
(See |
mean |
(Required) Vector of means. Must be of same length than |
covariance |
(Optional) Lower triangle of covariance matrix. See
|
range |
(Optional) Ranges of acceptable values for each covariates. See
|
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
|
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
|
includeIDCol |
(Optional) Should the subject column be included. Typically only set to
FALSE when called from |
Mike K Smith mstoolkit@googlemail.com
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.
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" )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.