Description Public fields Methods Examples
An R6 Class encapsulating the data and functionality for a sequential experimental design. This class takes care of data intialization and sequential assignments. The class object should be saved securely after each assignment e.g. on an encrypted cloud server.
t
The current number of subjects in this sequential experiment (begins at zero).
design
The type of sequential experimental design (see constructor's documentation).
X
A numeric matrix of subject data with number of rows n (the number of subjects) and number of columns p (the number of characteristics measured for each subject). This matrix is filled in sequentially and thus will have data present for rows 1...t (i.e. the number of subjects in the experiment currently) but otherwise will be missing.
y
A numeric vector of subject responses with number of entries n (the number of subjects). During the KK21 designs this must be filled in sequentially (similar to X) and will have data present for entries 1...t (i.e. the number of subjects in the experiment currently) but otherwise will be missing. For non-KK21 designs, this vector can be set at anytime (but must be set before inference is desired).
w
A binary vector of subject assignments with number of entries n (the number of subjects). This vector is filled in sequentially (similar to X) and will have assignments present for entries 1...t (i.e. the number of subjects in the experiment currently) but otherwise will be missing.
verbose
A flag that indicates whether messages should be displayed to the user
new()
Initialize a sequential experimental design
SeqDesign$new(n, p, design, verbose = TRUE, ...)
n
Number of subjects fixed beforehand. A future version of this software will allow for sequential stopping and thus n will not need to be prespecified.
p
Number of characteristics measured for each subject. If measurement j are categorical with L_j levels, you must select a reference level and convert this information to L_j-1 dummies. Thus p := # of numeric variables + sum_j (L_j - 1).
design
The type of sequential experimental design. This must be one of the following "CRD" for the completely randomized design / Bernoulli design, "BCRD" for the balanaced completely randomized design with n/2 T's and n/2 C's, "Efron" for Efron's (1971) Biased Coin Design "Atkinson" for Atkinson's (1982) Covariate-Adjusted Biased Coin Design "KK14" for Kapelner and Krieger's (2014) Covariate-Adjusted Matching on the Fly Design "KK21" for Kapelner and Krieger's (2021) CARA Matching on the Fly with Differential Covariate Weights Design "KK21stepwise" for Kapelner and Krieger's (2021) CARA Matching on the Fly with Differential Covariate Weights Stepwise Design
verbose
A flag indicating whether messages should be displayed to the user. Default is TRUE
.
...
Design-specific parameters: "Efron" requires "weighted_coin_prob" which is the probability of the weighted coin for assignment. If unspecified, default is 2/3. All "KK" designs require "lambda", the quantile cutoff of the subject distance distribution for determining matches. If unspecified, default is 10 All "KK" designs require "t_0_pct", the percentage of total sample size n where matching begins. If unspecified, default is 35 All "KK21" designs further require "num_boot" which is the number of bootstrap samples taken to approximate the subject-distance distribution. If unspecified, default is 500.
A new 'SeqDesign' object.
seq_des = SeqDesign$new(n = 100, p = 10, design = "KK21stepwise")
add_subject_to_experiment()
Add subject-specific measurements for the next subject entrant
SeqDesign$add_subject_to_experiment(x_vec)
x_vec
A p-length numeric vector
seq_des = SeqDesign$new(n = 100, p = 10, design = "CRD") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
print_current_subject_assignment()
Prints the current assignment to screen. Should be called after add_subject_to_experiment
.
SeqDesign$print_current_subject_assignment()
seq_des = SeqDesign$new(n = 100, p = 10, design = "CRD") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0)) seq_des$print_current_subject_assignment()
add_current_subject_response()
For CARA designs, add subject response for the current subject entrant
SeqDesign$add_current_subject_response(y)
y
The response as a numeric scalar
seq_des = SeqDesign$new(n = 100, p = 10, design = "KK21") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0)) seq_des$add_current_subject_response(4.71)
add_all_subject_responses()
For non-CARA designs, add all subject responses
SeqDesign$add_all_subject_responses(y)
y
The responses as a numeric vector of length n
seq_des = SeqDesign$new(n = 6, p = 10, design = "CRD") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0)) seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0)) seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1)) seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43))
matching_statistics()
For KK designs only, this returns a list with useful matching statistics.
SeqDesign$matching_statistics()
A list with the following data: num_matches
, prop_subjects_matched
,
num_subjects_remaining_in_reservoir
, prop_subjects_remaining_in_reservoir
.
seq_des = SeqDesign$new(n = 6, p = 10, design = "KK14") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0)) seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0)) seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1)) seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43)) seq_des$matching_statistics()
assert_experiment_completed()
Asserts if the experiment is completed (all n assignments are assigned in the w vector and all n responses in the y vector are recorded), i.e. throws descriptive error if the experiment is incomplete.
SeqDesign$assert_experiment_completed()
seq_des = SeqDesign$new(n = 6, p = 10, design = "CRD") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0)) #if run, it would throw an error since all of the covariate vectors are not yet recorded #seq_des$assert_experiment_completed() seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0)) seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0)) seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1)) #if run, it would throw an error since the responses are not yet recorded #seq_des$assert_experiment_completed() seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43)) seq_des$assert_experiment_completed() #no response means the assert is true
check_experiment_completed()
Checks if the experiment is completed (all n assignments are assigned in the w vector and all n responses in the y vector are recorded).
SeqDesign$check_experiment_completed()
TRUE
if experiment is complete, FALSE
otherwise.
seq_des = SeqDesign$new(n = 6, p = 10, design = "CRD") seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0)) #returns FALSE since all of the covariate vectors are not yet recorded seq_des$check_experiment_completed() seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0)) seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0)) seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0)) seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1)) #returns FALSE since the responses are not yet recorded seq_des$check_experiment_completed() seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43)) seq_des$check_experiment_completed() #returns TRUE
clone()
The objects of this class are cloneable with this method.
SeqDesign$clone(deep = FALSE)
deep
Whether to make a deep clone.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | ## ------------------------------------------------
## Method `SeqDesign$new`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 100, p = 10, design = "KK21stepwise")
## ------------------------------------------------
## Method `SeqDesign$add_subject_to_experiment`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 100, p = 10, design = "CRD")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
## ------------------------------------------------
## Method `SeqDesign$print_current_subject_assignment`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 100, p = 10, design = "CRD")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
seq_des$print_current_subject_assignment()
## ------------------------------------------------
## Method `SeqDesign$add_current_subject_response`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 100, p = 10, design = "KK21")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
seq_des$add_current_subject_response(4.71)
## ------------------------------------------------
## Method `SeqDesign$add_all_subject_responses`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 6, p = 10, design = "CRD")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0))
seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0))
seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1))
seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43))
## ------------------------------------------------
## Method `SeqDesign$matching_statistics`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 6, p = 10, design = "KK14")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0))
seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0))
seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1))
seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43))
seq_des$matching_statistics()
## ------------------------------------------------
## Method `SeqDesign$assert_experiment_completed`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 6, p = 10, design = "CRD")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
#if run, it would throw an error since all of the covariate vectors are not yet recorded
#seq_des$assert_experiment_completed()
seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0))
seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0))
seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1))
#if run, it would throw an error since the responses are not yet recorded
#seq_des$assert_experiment_completed()
seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43))
seq_des$assert_experiment_completed() #no response means the assert is true
## ------------------------------------------------
## Method `SeqDesign$check_experiment_completed`
## ------------------------------------------------
seq_des = SeqDesign$new(n = 6, p = 10, design = "CRD")
seq_des$add_subject_to_experiment(c(1, 38, 142, 71, 5.3, 0, 0, 0, 1, 0))
#returns FALSE since all of the covariate vectors are not yet recorded
seq_des$check_experiment_completed()
seq_des$add_subject_to_experiment(c(0, 27, 127, 60, 5.5, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 42, 169, 74, 5.1, 0, 1, 0, 0, 0))
seq_des$add_subject_to_experiment(c(0, 59, 105, 62, 5.9, 0, 0, 0, 1, 0))
seq_des$add_subject_to_experiment(c(1, 32, 186, 66, 5.6, 1, 0, 0, 0, 0))
seq_des$add_subject_to_experiment(c(1, 37, 178, 75, 6.5, 0, 0, 0, 0, 1))
#returns FALSE since the responses are not yet recorded
seq_des$check_experiment_completed()
seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43))
seq_des$check_experiment_completed() #returns TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.