View source: R/likelihood_RM.R
LogLikRM  R Documentation 
Computes the Loglikelihood for given data and parameters in the IRM and PCRM with or without timescaled
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.
LogLikRM(data, paramDf, model = "IRM", time_scaled = FALSE,
data_names = list(), ...)
data 
a dataframe where each row is one trial. Containing following variables:

paramDf 
a list or data frame with one row. Column names should match the names of
RaceModels parameter names (only 
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 
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.
Numeric scalar. The summed Loglikelihood of the data given the parameters in the respective model. If one or more rowwise probabilities is <=0, the function returns 1e+12.
Sebastian Hellmann.
# 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)
# 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")
# same result
LogLikRM(data, paramDf, model="PCRM", time_scaled=TRUE,condition="discriminability")
# different
LogLikRM(data, paramDf, model="PCRM", condition="discriminability")
# same parameters used for IRM model
LogLikRM(data, paramDf, model="IRMt", condition="discriminability")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.