Function to create covariates. Discrete, continuous and/or from an external
file. This function acts as a wrapper for the functions :
createContinuousCovariates,
createDiscreteCovariates,
createDiscreteCovariates and
createTimeVaryingCovariates
Usage
createCovariates(
subjects,
conNames = NULL,
conMean,
conCov,
conRange = NULL,
conDigits,
conMaxDraws = 100,
disNames = NULL,
disValues,
disProbs,
disProbArray,
extNames = NULL,
extFile,
extSubset,
extRefCol,
extSameRow = TRUE,
extDataId = idCol,
workingPath = getwd(),
timeNames = NULL,
timeMean,
timeCov,
timeRange = NULL,
timeCol = getEctdColName("Time"),
timePeriod,
idCol = getEctdColName("Subject"),
seed = .deriveFromMasterSeed()
)Arguments
- subjects
(Required) Subjects for which to create covariates
- conNames, conMean, conCov, conRange, conDigits, conMaxDraws
(Optional) Arguments for the
createContinuousCovariatesfunction. ThecreateContinuousCovariatesfunction is not called if these arguments are not provided- disNames, disValues, disProbs, disProbArray
(Optional) Arguments for the
createDiscreteCovariatesfunction. ThecreateDiscreteCovariatesfunction is not called if these arguments are not provided- extNames, extFile, extSubset, extRefCol, extSameRow, extDataId
(Optional) Arguments for the
createExternalCovariatesfunction. ThecreateExternalCovariatesfunction is not called if these arguments are not provided- workingPath
(Optional) Working directory from which to import covariate data. By default, the current working directory is used
- timeNames, timeMean, timeCov, timeRange, timeCol, timePeriod
(Optional) Arguments for the
createTimeVaryingCovariatesfunction. ThecreateTimeVaryingCovariatesfunction is not called if these arguments are not provided- idCol
(Optional) Name of the subject column. Must be a valid R name (See
validNames) and not be found in anyone ofconNames,extNamesordisNames. "SUBJ" is used by default- seed
(Optional) Random seed to use by all the lower-level functions. By default, this is derived from the current random seed
Value
Data frame merging the results from the lower-level functions :
createContinuousCovariates,
createDiscreteCovariates,
createExternalCovariates and
createTimeVaryingCovariates
Details
According to the presence of each "names" argument, the function calls
lower-level functions to generate covariates. For example, if
conNames is given, the function will attempt to generate covariates
from a continuous distribution using the
createContinuousCovariates function.
If no names is given, a data frame containing only the subject column will be created.
If createTimeVaryingCovariates is invoked, the additional TIME
column will be included in the output data.
Arguments are systematically passed to lower-level function according to a
name convention. For example, the conRange argument is passed to
createContinuousCovariates as the range argument, the
extFile is passed to the createExternalCovariates as
the file argument, ...
Warning
The function will generate an error if there is any
duplicated names between conNames, extNames, disNames,
timeNames and idCol.
See also
createContinuousCovariates,
createDiscreteCovariates,
createTimeVaryingCovariates and
createExternalCovariates for details about each source of
covariate and examples.
Author
Mike K Smith mstoolkit@googlemail.com
Examples
## unit tests for the covariates component of the MSToolkit package
if (FALSE) {
file.show( system.file( "Runit", "runit.data.covariates.R", package = "MSToolkit") )
wPath <- system.file( "Runit", "data", "createCovariates", package = "MSToolkit")
dAll <- createCovariates( 30,
conNames = "X,Y", conMean = "0,0" , conCov = "1,0,1", conRange = "-1<X<1", # continuous
disNames = "P1,P2", disValues = "1,2#3,5,6" , disProbs = ".5,.5#.3,.3,.4", # discrete
extNames = "X1", extFile = "testCovariates.csv", workingPath = wPath ) # external
dAllwithtime <- createCovariates( 30,
conNames = "X,Y", conMean = "0,0" , conCov = "1,0,1", conRange = "-1<X<1", # continuous
disNames = "P1,P2", disValues = "1,2#3,5,6" , disProbs = ".5,.5#.3,.3,.4", # discrete
timeNames = "T1,T2", timeMean = list(1:3, 1:3), timeCov = list(1, 1:3), # time-varying
timePeriod = 1:3, extNames = "X1", extFile = "testCovariates.csv", # external
workingPath = wPath )
}