createDiscreteCovariates: Create covariates from a discrete distribution

View source: R/createDiscreteCovariates.R

createDiscreteCovariatesR Documentation

Create covariates from a discrete distribution

Description

The values and probs argument are parsed using the parseHashString helper function. They could be either :

  • a vector giving the values for each variable. c("1,2", "1,2,3") would mean that the first variable takes values 1 and 2, and the second variable takes values 1, 2 and 3.

  • a list giving the values for each variable. list(c(1,2), c(1,2,3)) would mean that the first variable takes values 1 and 2, and the second variable takes values 1, 2 and 3.

  • a compact notation using the hash symbol to separate variables "1,2#1,2,3"

Usage

createDiscreteCovariates(
  subjects,
  names,
  values,
  probs,
  probArray,
  seed = .deriveFromMasterSeed(),
  idCol = getEctdColName("Subject"),
  includeIDCol = TRUE
)

Arguments

subjects

(Required) Vector of subjects (or number of subjects) for which to create covariates

names

(Required) Names of the discrete covariates to be created. All the names should be valid R names. See link{validNames}.

values

(Required) Values that the covariates can take. See details section.

probs

(Optional) Probabilities for each covariates. See details section.

probArray

(Optional) Probability array for uneven sampling. See details section.

seed

(Optional) Random seed to use.By default, it is based on the current random seed

idCol

(Optional) Name of the subject column. Must be a valid R name (see validNames) and not be duplicated with any names. "SUBJ" by default

includeIDCol

(Optional) A logical value. Should the subject column be

Details

Additionally for the probs argument, a check is performed to make sure that each variable probability sums to 1.

Alternatively, a probArray argument can be given. This should be a data frame containing one more column (named "prob") than the number of variables to create. Each variable has a column which contains the values it can take. The prob column gives the probability for each combination. See examples. The prob column should sum up to one.

Value

A data frame.

See Also

createContinuousCovariates,

Examples



  # 10 samples of X and Y where:
  # P[ X = 1 ] = .1
  # P[ X = 2 ] = .9
  # -
  # P[ Y = 7 ] = .5
  # P[ Y = 8 ] = .4
  # P[ Y = 9 ] = .1
  createDiscreteCovariates( 10 ,
                            names = "X, Y",
                            probs = ".1,.9#.5,.4,.1",
                            values = "1,2#7,8,9")
  # using the probArray version
  pa <- data.frame( F1 = rep(0:1, 3),
                    F2 = rep(1:3, each = 2),
                    PROB = c(.1,.2,.1,.2,.2,.2) )

  createDiscreteCovariates( 100 , probArray = pa )


MikeKSmith/MSToolkit documentation built on Feb. 15, 2024, 5:32 p.m.