Skip to contents

Computes the Log-likelihood for given data and parameters in the IRM and PCRM with or without time-scaled confidence measure. It is a wrapped version of the respective densities dIRM and dPCRM, where one can find more information about the parameters. It restricts the rates of accumulation to be the negative of each other, though (a common assumption in perceptual decision tasks). The function is mainly used inside fitRTConf for race models but exported for individual usage in other contexts.

Usage

LogLikRM(data, paramDf, model = "IRM", time_scaled = FALSE,
  data_names = list(), ...)

Arguments

data

a dataframe where each row is one trial. Containing following variables:

  • condition (not necessary; convertible to integer (e.g. factor); for different levels of stimulus quality),

  • rating (convertible to integer (e.g. factor); discrete confidence judgments),

  • rt (numeric; giving reaction times for decision task),

  • stimulus (values at least convertible to c(1,2), i.e. integer or factor; stimulus category (index of accumulator with higher drift))

  • response (values at least convertible to c(1,2); direction of decision; (index of accumulator reaching the boundary first))

paramDf

a list or data frame with one row. Column names should match the names of RaceModels parameter names (only mu1 and mu2 are not used in this context but replaced by the parameter v). For different stimulus quality/mean drift rates, names should be v1, v2, v3,.... Different s parameters are possible with s1, s2, s3,... with equally many steps as for drift rates. Additionally, the confidence thresholds should be given by names with thetaUpper1, thetaUpper2,..., thetaLower1,... or, for symmetric thresholds only by theta1, theta2,.... (see Details for the correspondence to the data)

model

character scalar. One of "IRM" or "PCRM". ("IRMt" and "PCRMt" will also be accepted. In that case, time_scaled is set to TRUE.)

time_scaled

logical. Whether the confidence measure should be scaled by 1/sqrt(rt). Default: TRUE.

data_names

list. Possibility of giving alternative column names for the variables in the data. By default column names are identical to the ones given in the data argument description.

...

Another possibility of giving alternative variable names in data frame (in the form condition = "SOA").

Value

Numeric scalar. The summed Log-likelihood of the data given the parameters in the respective model. If one or more row-wise probabilities is <=0, the function returns -1e+12.

Details

Note, that the requirements on the format of the columns for the likelihood functions are much stricter, than in fitRTConf. This is because the function is very frequently called in the optimization routines of the fitting process and the preprocessing steps are therefore included in the other function.

rating, condition. If integer, values should range from 1 to number of possible ratings/conditions. If factor, the number of levels should be equal to number of possible ratings/conditions. This should be consistent with the parameter vector. The confidence thresholds should be named as thetaUpper1, thetaLower1,.... (or theta1,... for symmetric thresholds), with the number of ratings -1 and the mean drift rates (and possibly the standard deviation in drift rates) should be denoted as v1, v2,... (and s1, s2,...) with the number equal to the number of conditions. If only one condition is used v will be accepted as well as v1.

stimulus, response. stimulus and response should always be given in numerical format with values 1 and 2. Stimulus determines which of two accumulators has positive drift. The other has negative drift with the same absolute value. Response gives the index of the accumulator that reaches the boundary first.

Author

Sebastian Hellmann.

Examples

# 1. Generate data from an artificial participants
# Get random index for accumulator with positive
# drift (i.e. stimulus category) and
# stimulus discriminability (two steps: hard, easy)
stimulus <- sample(c(1, 2), 200, replace=TRUE)
discriminability <- sample(c(1, 2), 200, replace=TRUE)
# generate data for participant 1
data <- rPCRM(200, mu1=ifelse(stimulus==1, 1, -1)*discriminability*0.5,
              mu2=ifelse(stimulus==1, -1, 1)*discriminability*0.5,
             a=2, b=1.8, t0=0.2, st0=0, wx=0.7, wint=0.3, wrt=0)
# discretize confidence ratings (only 2 steps: unsure vs. sure)
data$rating <- as.numeric(cut(data$conf, breaks = c(0, 3, Inf), include.lowest = TRUE))
data$participant = 1
data$stimulus <- stimulus
data$discriminability <- discriminability
data <- data[data$response!=0, ] # drop not finished decision processes
data <- data[,-c(3,4)] # drop xl and conf measure (unobservable variable)
head(data)
#>     rt response rating participant stimulus discriminability
#> 1 1.18        1      2           1        1                2
#> 2 6.15        1      2           1        1                2
#> 3 2.23        2      2           1        2                1
#> 4 1.08        1      1           1        1                2
#> 5 2.81        1      2           1        1                2
#> 6 2.36        2      1           1        2                1

# 2. Define some parameter set in a data.frame
paramDf <- data.frame(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)

# 3. Compute log likelihood for parameter and data
LogLikRM(data, paramDf, model="PCRMt", condition="discriminability")
#> [1] -645.0707
# same result
LogLikRM(data, paramDf, model="PCRM", time_scaled=TRUE,condition="discriminability")
#> [1] -645.0707
# different
LogLikRM(data, paramDf, model="PCRM", condition="discriminability")
#> [1] -525.5195

# same parameters used for IRM model
LogLikRM(data, paramDf, model="IRMt", condition="discriminability")
#> [1] -667.6278