Prediction of confidence and RT distributions for several sequential sampling confidence models and parameter constellations in parallel
Source:R/predictRTConfModels.R
      predictRTConfModels.RdThis function is a wrapper around the functions predictRTConf (see
there for more information). It calls the respective function for predicting the
response distribution (discrete decision and rating outcomes) and the rt density
(density for decision, rating and response time) for every model and
participant/subject combination in paramDf.
Also, see ddynaViTE, d2DSD, dMTLNR,
and dRM for more information about the parameters.
Usage
predictConfModels(paramDf, maxrt = Inf, subdivisions = 100L,
  simult_conf = FALSE, stop.on.error = FALSE, .progress = TRUE,
  parallel = FALSE, n.cores = NULL)
predictRTModels(paramDf, maxrt = 9, subdivisions = 100L, minrt = NULL,
  simult_conf = FALSE, scaled = FALSE, DistConf = NULL,
  .progress = TRUE, parallel = FALSE, n.cores = NULL)Arguments
- paramDf
- a dataframe with one row per combination of model and participant/parameter set. Columns may include a - participant(- sbj, or- subject) column, and must include a- modelcolumn and the names of the model parameters. For different stimulus quality/mean drift rates, names should be- v1,- v2,- v3,.... Different- sparameters are possible with- s1,- s2,- s3... with equally many steps as for drift rates (same for- svparameter in dynWEV and 2DSD), except for MTLNR. Additionally, the confidence thresholds should be given by names with- thetaUpper1,- thetaUpper2,...,- thetaLower1,... or, for symmetric thresholds only by- theta1,- theta2,....
- maxrt
- numeric. The maximum RT for the integration/density computation. Default: 15 (for - predictConfModels(integration)) and 9 (for- predictRTModels).
- subdivisions
- integer(default: 100). For- predictConfModelsit is used as argument for the inner integral routine. For- predictRTModelsit is the number of points for which the density is computed.
- simult_conf
- logical, only relevant for dynWEV and 2DSD. Whether in the experiment confidence was reported simultaneously with the decision, as then decision and confidence judgment are assumed to have happened subsequent before response and computations are different, when there is an observable interjudgment time (then - simult_confshould be FALSE).
- stop.on.error
- logical. Argument directly passed on to integrate. Default is FALSE, since the densities invoked may lead to slow convergence of the integrals (which are still quite accurate) which causes R to throw an error. 
- .progress
- logical. If TRUE (default) a progress bar is drawn to the console. (Works for some OS only when - parallel=FALSE.)
- parallel
- logical. If TRUE, prediction is parallelized over participants and models (i.e. over the calls for the respective - predictRTConffunctions).
- n.cores
- integer. If - parallelis TRUE, the number of cores used for parallelization is required. If- NULL(default) the number of available cores -1 is used.
- minrt
- numeric or - NULL(default). The minimum rt for the density computation. If- NULL, the minimal possible response time possible with given parameters will be used (min(t0)).
- scaled
- logical. Whether the computed density should be scaled to integrate to one (additional column - densscaled). Otherwise the output contains only the defective density (i.e. its integral is equal to the probability of a response and not 1). If- TRUE, the argument- DistConfshould be given, if available. Default:- FALSE.
- DistConf
- NULLor- data.frame. A- data.framewith participant and model columns and columns, giving the distribution of response and rating choices for different conditions and stimulus categories in the form of the output of- predictConfModels. It is only necessary if- scaled=TRUE, because these probabilities are used for scaling. If- scaled=TRUEand- DistConf=NULL, it will be computed with the function- predictConfModels, which takes some time and the function will throw a message. Default:- NULL
Value
predictConfModels returns a data.frame/tibble with columns: participant (or sbj,
subject depending on the input), model, condition, stimulus,
response, rating, correct, p, info, err. p is the predicted probability of a response
and rating, given the stimulus category and condition. info and err refer to the
respective outputs of the integration routine used for the computation.
predictRTModels returns a data.frame/tibble with columns: participant (or sbj/subject
depending on the input), model, condition, stimulus,
response, rating, correct, rt and dens (and densscaled, if scaled=TRUE).
Details
These functions merely split the input data frame by model participants combinations,
call the equivalent predictRTConf functions for the individual parameter sets
and bind the outputs together. They are included for convenience and the easy parallelization,
which facilitates speeding up computations considerably. For the argument
paramDf, the output of the fitting function fitRTConfModels with the
respective models and participants may be used.
The function predictConf (called by predictConfModels)
consists merely of an integration of the reaction time density or the given model,
{d*model*}, over the reaction time in a reasonable interval (0 to maxrt).
The function predictRT (called by predictRTModels) wraps these
density functions to a parameter set input and a data.frame output. '
Note, that the encoding for stimulus identity is different between diffusion based models
(2DSD, dynWEV) and race models (IRM(t), PCRM(t), and MTLNR). Therefore, in the columns stimulus and
response there will be a mix of encodings: -1/1 for diffusion based models and 1/2 for
race models. This, usually is not important, since for further aggregation models will
not be mixed.
Note
Different parameters for different conditions are only allowed for drift rate
v, drift rate variability sv (only dynWEV and 2DSD), and process variability
s (not for MTLNR). All other parameters are used for all conditions.
Examples
# First example for 2 participant and the "dynWEV" model
# (equivalent applicable for
# all other models (with different parameters!))
# 1. Define two parameter sets from different participants
paramDf <- data.frame(participant = c(1,2), model="dynWEV",
                      a=c(1.5, 2),v1=c(0.2,0.1), v2=c(1, 1.5),
                      t0=c(0.1, 0.2),z=c(0.52,0.45),
                      sz=c(0.0,0.3),sv=c(0.4,0.7), st0=c(0,0.01),
                      tau=c(2,3), w=c(0.5,0.2),
                      theta1=c(1,1.5), svis=c(0.5,0.1), sigvis=c(0.8, 1.2))
paramDf
#>   participant  model   a  v1  v2  t0    z  sz  sv  st0 tau   w theta1 svis
#> 1           1 dynWEV 1.5 0.2 1.0 0.1 0.52 0.0 0.4 0.00   2 0.5    1.0  0.5
#> 2           2 dynWEV 2.0 0.1 1.5 0.2 0.45 0.3 0.7 0.01   3 0.2    1.5  0.1
#>   sigvis
#> 1    0.8
#> 2    1.2
# 2. Predict discrete Choice x Confidence distribution:
# model is not an extra argument but must be a column of paramDf
preds_Conf <- predictConfModels(paramDf, maxrt = 15, simult_conf=TRUE,
                                .progress=TRUE, parallel = FALSE)
# 3. Compute RT density
preds_RT <- predictRTModels(paramDf, maxrt=6, subdivisions=100,
                      scaled=TRUE, DistConf = preds_Conf,
                      parallel=FALSE, .progress = TRUE)
head(preds_RT)
#>   condition stimulus response correct rating        rt      dens densscaled
#> 1         1        1        1       1      1 0.1000000 0.0000000  0.0000000
#> 2         1        1        1       1      1 0.1595960 0.1645173  0.5293651
#> 3         1        1        1       1      1 0.2191919 0.5064871  1.6297166
#> 4         1        1        1       1      1 0.2787879 0.5633260  1.8126064
#> 5         1        1        1       1      1 0.3383838 0.5203048  1.6741774
#> 6         1        1        1       1      1 0.3979798 0.4576166  1.4724665
#>    model participant
#> 1 dynWEV           1
#> 2 dynWEV           1
#> 3 dynWEV           1
#> 4 dynWEV           1
#> 5 dynWEV           1
#> 6 dynWEV           1
# \donttest{
  # produces a warning, if scaled=TRUE and DistConf missing
  preds_RT <- predictRTModels(paramDf, scaled=TRUE)
#> scaled is TRUE and DistConf is NULL.
#> Confidence distribution is calculated before computing the RT densities,
#> this takes considerable additional time...
#> ...finished computation of confidence distribution.
# }
# Use PDFtoQuantiles to get predicted RT quantiles
head(PDFtoQuantiles(preds_RT, scaled = FALSE))
#> # A tibble: 6 × 9
#>   condition stimulus response correct rating model  participant     p     q
#>       <int>    <dbl>    <dbl>   <dbl>  <int> <chr>        <dbl> <dbl> <dbl>
#> 1         1       -1       -1       1      1 dynWEV           1   0.1 0.280
#> 2         1       -1       -1       1      1 dynWEV           1   0.3 0.370
#> 3         1       -1       -1       1      1 dynWEV           1   0.5 0.549
#> 4         1       -1       -1       1      1 dynWEV           1   0.7 0.729
#> 5         1       -1       -1       1      1 dynWEV           1   0.9 1.18 
#> 6         1       -1       -1       1      1 dynWEV           2   0.1 0.370
# Second Example: only one parameter set but for two different models
# \donttest{
  paramDf1 <- data.frame(model="dynWEV", a=1.5,v1=0.2, v2=1, t0=0.1,z=0.52,
                        sz=0.3,sv=0.4, st0=0,  tau=3, w=0.5,
                        theta1=1, svis=0.5, sigvis=0.8)
  paramDf2 <- data.frame(model="PCRMt", a=2,b=2, v1=0.5, v2=1, t0=0.1,st0=0,
                        wx=0.6, wint=0.2, wrt=0.2, theta1=4)
  paramDf <- dplyr::full_join(paramDf1, paramDf2)
#> Joining with `by = join_by(model, a, v1, v2, t0, st0, theta1)`
  paramDf  # each model parameters sets hat its relevant parameters
#>    model   a  v1 v2  t0    z  sz  sv st0 tau   w theta1 svis sigvis  b  wx wint
#> 1 dynWEV 1.5 0.2  1 0.1 0.52 0.3 0.4   0   3 0.5      1  0.5    0.8 NA  NA   NA
#> 2  PCRMt 2.0 0.5  1 0.1   NA  NA  NA   0  NA  NA      4   NA     NA  2 0.6  0.2
#>   wrt
#> 1  NA
#> 2 0.2
  predictConfModels(paramDf, parallel=FALSE, .progress=TRUE)
#>    condition stimulus response correct rating            p info          err
#> 1          1        1        1       1      1 2.753724e-01   OK 2.295258e-05
#> 2          2        1        1       1      1 5.679751e-02   OK 6.160096e-06
#> 3          1       -1        1       0      1 2.681096e-01   OK 2.300382e-05
#> 4          2       -1        1       0      1 1.194353e-01   OK 1.140607e-05
#> 5          1        1       -1       0      1 2.415522e-01   OK 1.297594e-05
#> 6          2        1       -1       0      1 1.011203e-01   OK 1.020735e-04
#> 7          1       -1       -1       1      1 2.525716e-01   OK 1.371182e-05
#> 8          2       -1       -1       1      1 5.262161e-02   OK 3.489823e-05
#> 9          1        1        1       1      2 3.103598e-01   OK 2.172831e-05
#> 10         2        1        1       1      2 7.521661e-01   OK 6.074326e-05
#> 11         1       -1        1       0      2 1.837505e-01   OK 9.683325e-06
#> 12         2       -1        1       0      2 1.004053e-01   OK 1.279651e-05
#> 13         1        1       -1       0      2 1.727156e-01   OK 7.955309e-05
#> 14         2        1       -1       0      2 8.991603e-02   OK 5.907873e-05
#> 15         1       -1       -1       1      2 2.955683e-01   OK 1.358866e-05
#> 16         2       -1       -1       1      2 7.275378e-01   OK 3.705280e-05
#> 17         1        1        1       1      1 7.443159e-01   OK 4.685177e-05
#> 18         2        1        1       1      1 8.157293e-01   OK 4.983466e-05
#> 19         1        2        1       0      1 9.342758e-02   OK 6.084905e-05
#> 20         2        2        1       0      1 1.477360e-02   OK 4.904424e-05
#> 21         1        1        2       0      1 9.342758e-02   OK 6.084905e-05
#> 22         2        1        2       0      1 1.477360e-02   OK 4.904424e-05
#> 23         1        2        2       1      1 7.443159e-01   OK 4.685177e-05
#> 24         2        2        2       1      1 8.157293e-01   OK 4.983466e-05
#> 25         1        1        1       1      2 1.600872e-01   OK 2.708790e-05
#> 26         2        1        1       1      2 1.694080e-01   OK 8.276688e-06
#> 27         1        2        1       0      2 2.169329e-03   OK 9.443649e-06
#> 28         2        2        1       0      2 8.921261e-05   OK 3.114930e-06
#> 29         1        1        2       0      2 2.169329e-03   OK 9.443649e-06
#> 30         2        1        2       0      2 8.921261e-05   OK 3.114930e-06
#> 31         1        2        2       1      2 1.600872e-01   OK 2.708790e-05
#> 32         2        2        2       1      2 1.694080e-01   OK 8.276688e-06
#>     model sbj
#> 1  dynWEV   1
#> 2  dynWEV   1
#> 3  dynWEV   1
#> 4  dynWEV   1
#> 5  dynWEV   1
#> 6  dynWEV   1
#> 7  dynWEV   1
#> 8  dynWEV   1
#> 9  dynWEV   1
#> 10 dynWEV   1
#> 11 dynWEV   1
#> 12 dynWEV   1
#> 13 dynWEV   1
#> 14 dynWEV   1
#> 15 dynWEV   1
#> 16 dynWEV   1
#> 17  PCRMt   1
#> 18  PCRMt   1
#> 19  PCRMt   1
#> 20  PCRMt   1
#> 21  PCRMt   1
#> 22  PCRMt   1
#> 23  PCRMt   1
#> 24  PCRMt   1
#> 25  PCRMt   1
#> 26  PCRMt   1
#> 27  PCRMt   1
#> 28  PCRMt   1
#> 29  PCRMt   1
#> 30  PCRMt   1
#> 31  PCRMt   1
#> 32  PCRMt   1
# }