Simulates a randomized treatment based on an urn model.

rud(n, alpha = c(1, 1), beta = 1, labels = seq(1, length(alpha)),
  data.frame = FALSE, startid = 1)

Arguments

n

the number of individuals to randomize

alpha

a non-negative integer vector of weights for each treatment group. The length of the vector corresponds to the number of treatment groups.

beta

a non-negative integer of weights added to the groups that were not given treatment

labels

a vector of treatment labels. Must be the same length as the length of alpha.

data.frame

A logical that determines if the function should return a vector of group indices (the default, if FALSE) or a data frame (if TRUE).

startid

margin paramaters; vector of length 4 (see par)

Value

A vector with group indices. If the argument data.frame=TRUE is used then a data frame with three variables is returned: id, group, and treatment (the group label).

Details

The urn model can be described as follows: For k different treatments, the urn design is initiated with a number of balls in an urn corresponding to the start weight (the alpha argument), where each treatment has a specific colour. Whenever a patient arrives, a random ball is drawn from the urn and the colour decides the treatment for the patient. For each of the treatments that weren't chosen we add beta balls of the corresponding colour(s) to the urn to update the probabilities for the next patient.

Examples

rud(5)
#> [1] 2 2 1 1 1
rud(5, alpha=c(1,1,10), beta=5)
#> [1] 3 3 1 3 1