Obtain posterior draws of the pseudo type 1 receiver operating characteristic (ROC) curve.
Source:R/roc_draws.R
roc1_draws.RdGiven a data frame and a meta-d' model, adds estimates of the
cumulative probability over joint_responses.
For roc1_draws and add_roc1_draws, estimates are returned in a tidy
tibble with one row per posterior draw and per joint response.
For roc1_rvars and add_roc1_rvars, parameters are returned as
posterior::rvars, with one row per row in newdata and per joint response.
Usage
roc1_draws(object, newdata, ..., bounds = FALSE)
add_roc1_draws(newdata, object, ...)
roc1_rvars(object, newdata, ..., bounds = FALSE)
add_roc1_rvars(newdata, object, ...)Arguments
- object
The
brmsmodel with themetadfamily- newdata
A data frame from which to generate posterior predictions
- ...
Additional parameters passed to tidybayes::epred_draws or tidybayes::epred_rvars
- bounds
If
TRUE, include the endpoints of the ROC at \((0, 0)\) and \((1, 1)\). Otherwise, the endpoints are excluded.
Value
a tibble containing posterior draws of the pseudo type 1 ROC with the following columns:
.row: the row ofnewdata.chain,.iteration,.draw: forroc1_drawsandadd_roc1_draws, identifiers for the posterior samplejoint_response: the combined type 1 / type 2 response (\(J \in [1, 2K]\)) for \(K\) confidence levels)response: the type 1 response for perceived stimulus presence (\(R \in \{0, 1\}\))confidence: the type 2 confidence response (\(C \in [1, K]\))p_fa: the cumulative probability of a 'present'/'old' response forstimulus==0(\(P(J \ge j \;\vert\; S=0)\))p_hit: the cumulative probability of a 'present'/'old' response forstimulus==1(\(P(J \ge j \;\vert\; S=1)\))
Examples
# \donttest{
newdata <- tidyr::tibble(.row = 1)
# compute pseudo-type 1 ROC curve
# equivalent to ``
roc1_draws(example_model(), newdata)
#> # A tibble: 7,000 × 9
#> # Groups: .row, joint_response, response, confidence [7]
#> .row joint_response response confidence .chain .iteration .draw p_fa p_hit
#> <int> <int> <int> <dbl> <int> <int> <int> <dbl> <dbl>
#> 1 1 1 0 4 NA NA 1 0.836 0.982
#> 2 1 1 0 4 NA NA 2 0.874 0.987
#> 3 1 1 0 4 NA NA 3 0.881 0.985
#> 4 1 1 0 4 NA NA 4 0.871 0.984
#> 5 1 1 0 4 NA NA 5 0.867 0.985
#> 6 1 1 0 4 NA NA 6 0.847 0.984
#> 7 1 1 0 4 NA NA 7 0.856 0.985
#> 8 1 1 0 4 NA NA 8 0.847 0.982
#> 9 1 1 0 4 NA NA 9 0.876 0.985
#> 10 1 1 0 4 NA NA 10 0.835 0.983
#> # ℹ 6,990 more rows
add_roc1_draws(newdata, example_model())
#> # A tibble: 7,000 × 9
#> # Groups: .row, joint_response, response, confidence [7]
#> .row joint_response response confidence .chain .iteration .draw p_fa p_hit
#> <int> <int> <int> <dbl> <int> <int> <int> <dbl> <dbl>
#> 1 1 1 0 4 NA NA 1 0.836 0.982
#> 2 1 1 0 4 NA NA 2 0.874 0.987
#> 3 1 1 0 4 NA NA 3 0.881 0.985
#> 4 1 1 0 4 NA NA 4 0.871 0.984
#> 5 1 1 0 4 NA NA 5 0.867 0.985
#> 6 1 1 0 4 NA NA 6 0.847 0.984
#> 7 1 1 0 4 NA NA 7 0.856 0.985
#> 8 1 1 0 4 NA NA 8 0.847 0.982
#> 9 1 1 0 4 NA NA 9 0.876 0.985
#> 10 1 1 0 4 NA NA 10 0.835 0.983
#> # ℹ 6,990 more rows
# use posterior::rvar for additional efficiency
# equivalent to `add_roc1_draws(newdata, example_model())`
roc1_rvars(example_model(), newdata)
#> # A tibble: 7 × 6
#> # Groups: .row, joint_response, response, confidence [7]
#> .row joint_response response confidence p_fa p_hit
#> <int> <int> <int> <dbl> <rvar[1d]> <rvar[1d]>
#> 1 1 1 0 4 0.855 ± 0.0150 0.98 ± 0.0036
#> 2 1 2 0 3 0.667 ± 0.0197 0.93 ± 0.0089
#> 3 1 3 0 2 0.470 ± 0.0210 0.84 ± 0.0143
#> 4 1 4 0 1 0.296 ± 0.0201 0.69 ± 0.0206
#> 5 1 5 1 1 0.153 ± 0.0132 0.51 ± 0.0201
#> 6 1 6 1 2 0.058 ± 0.0079 0.31 ± 0.0183
#> 7 1 7 1 3 0.017 ± 0.0036 0.15 ± 0.0147
# include the ROC bounds
# equivalent to `add_roc1_draws(newdata, example_model(), bounds = TRUE)`
roc1_draws(example_model(), newdata, bounds = TRUE)
#> # A tibble: 9,000 × 9
#> # Groups: .row, joint_response, response, confidence [9]
#> .row joint_response response confidence .chain .iteration .draw p_fa p_hit
#> <int> <dbl> <dbl> <dbl> <int> <int> <int> <dbl> <dbl>
#> 1 1 0 0 5 NA NA 1 1 1
#> 2 1 0 0 5 NA NA 2 1 1
#> 3 1 0 0 5 NA NA 3 1 1
#> 4 1 0 0 5 NA NA 4 1 1
#> 5 1 0 0 5 NA NA 5 1 1
#> 6 1 0 0 5 NA NA 6 1 1
#> 7 1 0 0 5 NA NA 7 1 1
#> 8 1 0 0 5 NA NA 8 1 1
#> 9 1 0 0 5 NA NA 9 1 1
#> 10 1 0 0 5 NA NA 10 1 1
#> # ℹ 8,990 more rows
# }