View source: R/createContinuousCovariates.R
createContinuousCovariates | R Documentation |
Creates a set of continuous covariates from a multivariate normal distribution and (optionally) a set of constraints.
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 master random seed |
idCol |
(Optional) Name of the subject column. Must be a valid R name
(See |
includeIDCol |
(Optional) Should the subject column be included. |
Romain Francois
createDiscreteCovariates
to create covariates for a
discrete distribution.
# 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.