R/get_potential_outcomes.R
get_potential_outcomes.Rd
An instance of PatientSample
, or one of its subclasses like
CorrelatedPatientSample
, reflects one particular state of the
world, where patient i would reliably experience a toxicity or efficacy
event if treated at a particular dose. This function, given true toxicity and
efficacy probabilities at doses 1, ..., num_doses, calculates 0/1 matrices to
reflect whether the patients in those samples would have experienced toxicity
and efficacy at the doses, had they been dosed as such. Using the
vernacular of causal inference, these are _potential outcomes_. At any single
instant, a patient can only be dosed at one dose, so only one of the
outcomes for a patient would in reality have been observed; the rest are
counterfactual.
get_potential_outcomes(patient_samples, true_prob_tox, true_prob_eff)
list of PatientSample
objects, or
subclass thereof.
vector of probabilities of toxicity outcomes at doses
vector of probabilities of efficacy outcomes at doses
a list of lists, with names tox and eff, each mapping to a matrix of the potential outcomes.
num_sims <- 10
ps <- lapply(1:num_sims, function(x) PatientSample$new())
# Set tox_u and eff_u for each simulation
set.seed(2024)
lapply(1:num_sims, function(x) {
tox_u_new <- runif(n = 20)
eff_u_new <- runif(n = 20)
ps[[x]]$set_eff_and_tox(tox_u = tox_u_new, eff_u = eff_u_new)
})
#> [[1]]
#> [1] FALSE
#>
#> [[2]]
#> [1] FALSE
#>
#> [[3]]
#> [1] FALSE
#>
#> [[4]]
#> [1] FALSE
#>
#> [[5]]
#> [1] FALSE
#>
#> [[6]]
#> [1] FALSE
#>
#> [[7]]
#> [1] FALSE
#>
#> [[8]]
#> [1] FALSE
#>
#> [[9]]
#> [1] FALSE
#>
#> [[10]]
#> [1] FALSE
#>
true_prob_tox <- c(0.05, 0.10, 0.15, 0.18, 0.45)
true_prob_eff <- c(0.40, 0.50, 0.52, 0.53, 0.53)
get_potential_outcomes(
patient_samples = ps,
true_prob_tox = true_prob_tox,
true_prob_eff = true_prob_eff
)
#> [[1]]
#> [[1]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 0 0 0 0 1
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 0
#> [6,] 0 0 0 0 0
#> [7,] 0 0 0 0 1
#> [8,] 0 0 0 0 1
#> [9,] 0 0 0 0 0
#> [10,] 0 0 1 1 1
#> [11,] 0 0 0 0 0
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 0
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 1
#> [16,] 0 0 0 0 0
#> [17,] 0 0 1 1 1
#> [18,] 0 0 0 0 0
#> [19,] 0 0 1 1 1
#> [20,] 0 0 0 0 1
#>
#> [[1]]$eff
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 1 1 1 1 1
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 0
#> [6,] 1 1 1 1 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 1 1 1 1 1
#> [10,] 1 1 1 1 1
#> [11,] 0 1 1 1 1
#> [12,] 1 1 1 1 1
#> [13,] 1 1 1 1 1
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 0
#> [16,] 0 0 0 0 0
#> [17,] 1 1 1 1 1
#> [18,] 0 0 0 0 0
#> [19,] 1 1 1 1 1
#> [20,] 0 0 0 0 0
#>
#>
#> [[2]]
#> [[2]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 0 0 0 0 0
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 0 1
#> [5,] 0 0 0 0 0
#> [6,] 0 0 0 0 1
#> [7,] 0 0 0 0 1
#> [8,] 0 0 0 0 1
#> [9,] 0 0 0 0 0
#> [10,] 0 0 0 0 0
#> [11,] 0 1 1 1 1
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 0
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 0
#> [16,] 0 0 0 0 0
#> [17,] 1 1 1 1 1
#> [18,] 0 0 0 0 1
#> [19,] 0 0 0 0 0
#> [20,] 0 0 0 0 1
#>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14,] 1 1 1 1 1
#> [15,] 0 1 1 1 1
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 0
#> [18,] 1 1 1 1 1
#> [19,] 0 1 1 1 1
#> [20,] 1 1 1 1 1
#>
#>
#> [[4]]
#> [[4]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 0 1 1 1 1
#> [3,] 0 0 0 0 0
#> [4,] 0 0 1 1 1
#> [5,] 0 0 0 0 0
#> [6,] 1 1 1 1 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 0
#> [10,] 0 0 0 0 0
#> [11,] 0 0 0 0 1
#> [12,] 1 1 1 1 1
#> [13,] 1 1 1 1 1
#> [14,] 0 0 0 0 1
#> [15,] 0 0 0 0 0
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 0
#> [18,] 0 1 1 1 1
#> [19,] 1 1 1 1 1
#> [20,] 0 0 0 0 0
#>
#> [[4]]$eff
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 1 1 1 1 1
#> [3,] 1 1 1 1 1
#> [4,] 0 1 1 1 1
#> [5,] 0 0 0 0 0
#> [6,] 0 0 0 0 0
#> [7,] 0 0 0 1 1
#> [8,] 1 1 1 1 1
#> [9,] 0 0 0 0 0
#> [10,] 1 1 1 1 1
#> [11,] 1 1 1 1 1
#> [12,] 0 1 1 1 1
#> [13,] 0 0 0 0 0
#> [14,] 1 1 1 1 1
#> [15,] 0 0 0 0 0
#> [16,] 0 1 1 1 1
#> [17,] 1 1 1 1 1
#> [18,] 1 1 1 1 1
#> [19,] 0 0 1 1 1
#> [20,] 1 1 1 1 1
#>
#>
#> [[5]]
#> [[5]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 1 1 1
#> [2,] 0 0 0 0 0
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 1 1
#> [5,] 0 0 0 0 0
#> [6,] 0 0 0 0 0
#> [7,] 1 1 1 1 1
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 0
#> [10,] 0 0 0 0 1
#> [11,] 0 0 0 0 0
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 1
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 1
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 1
#> [18,] 1 1 1 1 1
#> [19,] 0 0 0 0 0
#> [20,] 0 0 0 0 0
#>
#> [[5]]$eff
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 0 0 0 0 0
#> [3,] 1 1 1 1 1
#> [4,] 0 0 0 0 0
#> [5,] 1 1 1 1 1
#> [6,] 0 0 0 0 0
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 0
#> [10,] 1 1 1 1 1
#> [11,] 1 1 1 1 1
#> [12,] 1 1 1 1 1
#> [13,] 1 1 1 1 1
#> [14,] 1 1 1 1 1
#> [15,] 1 1 1 1 1
#> [16,] 1 1 1 1 1
#> [17,] 0 1 1 1 1
#> [18,] 0 1 1 1 1
#> [19,] 0 0 0 0 0
#> [20,] 0 0 0 0 0
#>
#>
#> [[6]]
#> [[6]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 1 1 1 1 1
#> [3,] 0 0 0 0 0
#> [4,] 0 0 1 1 1
#> [5,] 0 0 0 0 0
#> [6,] 1 1 1 1 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 1
#> [9,] 0 0 1 1 1
#> [10,] 0 0 0 0 0
#> [11,] 0 0 0 0 0
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 1
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 0
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 1
#> [18,] 0 0 0 0 0
#> [19,] 0 0 1 1 1
#> [20,] 0 0 1 1 1
#>
#> [[6]]$eff
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1
#> [15,] 0 0 0 0 0
#> [16,] 0 1 1 1 1
#> [17,] 0 0 0 0 0
#> [18,] 1 1 1 1 1
#> [19,] 1 1 1 1 1
#> [20,] 0 0 0 0 0
#>
#>
#> [[8]]
#> [[8]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 0 0 0 0 0
#> [3,] 0 0 1 1 1
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 1
#> [6,] 0 0 0 0 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 0
#> [10,] 1 1 1 1 1
#> [11,] 0 0 0 0 0
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 0
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 0
#> [16,] 0 0 0 0 1
#> [17,] 0 0 0 0 0
#> [18,] 0 0 0 0 0
#> [19,] 0 0 0 0 0
#> [20,] 0 0 0 0 1
#>
#> [[8]]$eff
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 0 0 0 0 0
#> [3,] 0 1 1 1 1
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 0
#> [6,] 1 1 1 1 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 1 1 1 1 1
#> [10,] 0 0 0 0 0
#> [11,] 1 1 1 1 1
#> [12,] 1 1 1 1 1
#> [13,] 0 0 0 0 0
#> [14,] 1 1 1 1 1
#> [15,] 1 1 1 1 1
#> [16,] 1 1 1 1 1
#> [17,] 1 1 1 1 1
#> [18,] 0 0 0 0 0
#> [19,] 0 0 0 0 0
#> [20,] 1 1 1 1 1
#>
#>
#> [[9]]
#> [[9]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 0 0 0 0 0
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 0
#> [6,] 0 0 0 0 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 1
#> [10,] 0 0 0 0 1
#> [11,] 0 0 0 0 1
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 0
#> [14,] 0 0 0 0 0
#> [15,] 1 1 1 1 1
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 0
#> [18,] 0 0 0 0 0
#> [19,] 0 0 0 0 0
#> [20,] 0 0 0 0 0
#>
#> [[9]]$eff
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 0 0 0 0 0
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 0 0
#> [5,] 1 1 1 1 1
#> [6,] 1 1 1 1 1
#> [7,] 0 0 0 0 0
#> [8,] 1 1 1 1 1
#> [9,] 0 0 0 0 0
#> [10,] 0 0 0 0 0
#> [11,] 0 0 0 0 0
#> [12,] 0 0 0 1 1
#> [13,] 0 0 0 0 0
#> [14,] 0 0 0 0 0
#> [15,] 0 0 0 0 0
#> [16,] 1 1 1 1 1
#> [17,] 0 0 0 0 0
#> [18,] 0 0 0 0 0
#> [19,] 1 1 1 1 1
#> [20,] 0 0 0 0 0
#>
#>
#> [[10]]
#> [[10]]$tox
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 0 0 0 0
#> [2,] 0 1 1 1 1
#> [3,] 0 0 0 0 0
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 0
#> [6,] 0 0 0 0 0
#> [7,] 0 0 0 0 1
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 1
#> [10,] 0 0 0 0 0
#> [11,] 0 0 0 0 0
#> [12,] 0 0 0 0 0
#> [13,] 0 0 0 0 0
#> [14,] 1 1 1 1 1
#> [15,] 0 0 0 0 1
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 1
#> [18,] 0 1 1 1 1
#> [19,] 0 0 0 0 0
#> [20,] 0 0 1 1 1
#>
#> [[10]]$eff
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 1 1 1 1 1
#> [3,] 1 1 1 1 1
#> [4,] 0 0 0 0 0
#> [5,] 0 0 0 0 0
#> [6,] 0 1 1 1 1
#> [7,] 0 0 0 0 0
#> [8,] 0 0 0 0 0
#> [9,] 0 0 0 0 0
#> [10,] 1 1 1 1 1
#> [11,] 0 0 0 0 0
#> [12,] 1 1 1 1 1
#> [13,] 0 0 0 0 0
#> [14,] 1 1 1 1 1
#> [15,] 0 0 0 0 0
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 0
#> [18,] 0 0 0 0 0
#> [19,] 1 1 1 1 1
#> [20,] 0 0 0 0 0
#>
#>