func_tau | R Documentation |
The softmax function describes a probabilistic choice rule. It implies
that options with higher subjective values are chosen with a greater
probability, rather than deterministic. This probability of choosing
the higher-valued option increases with the parameter tau
.
A higher tau
indicates greater sensitivity to value differences, making
choices more deterministic.
func_tau(
i,
L_freq,
R_freq,
L_pick,
R_pick,
L_value,
R_value,
var1 = NA,
var2 = NA,
LR,
try,
tau,
lapse,
alpha,
beta
)
i |
[numeric] The current row number. |
L_freq |
[numeric] The frequency of left option appearance |
R_freq |
[numeric] The frequency of right option appearance |
L_pick |
[numeric] The number of times left option was picked |
R_pick |
[numeric] The number of times left option was picked |
L_value |
[numeric] The value of the left option with bias (if pi != 0) |
R_value |
[numeric] The value of the right option with bias (if pi != 0) |
var1 |
[character] Column name of extra variable 1. If your model uses more than just reward and expected value, and you need other information, such as whether the choice frame is Gain or Loss, then you can input the 'Frame' column as var1 into the model.
|
var2 |
[character] Column name of extra variable 2. If one additional variable, var1, does not meet your needs, you can add another additional variable, var2, into your model. default: |
LR |
[character] Are you calculating the probability for the left option or the right option?
|
try |
[numeric] If the choice was random, the value is 1; If the choice was based on value, the value is 0. |
tau |
[vector] Parameters used in the Soft-Max Function.
|
lapse |
[numeric] A numeric value between 0 and 1, representing the lapse rate. You can interpret this parameter as the probability of the agent "slipping" or making a random choice, irrespective of the learned action values. This accounts for moments of inattention or motor errors. In this sense, it represents the minimum probability with which any given option will be selected. It is a free parameter that acknowledges that individuals do not always make decisions with full concentration throughout an experiment. From a modeling perspective, the lapse rate is crucial for preventing the
log-likelihood calculation from returning
This ensures each option has a minimum selection probability of 1 percent in TAFC tasks. |
alpha |
[vector] Extra parameters that may be used in functions. |
beta |
[vector] Extra parameters that may be used in functions. |
The probability of choosing this option
When customizing these functions, please ensure that you do not modify
the arguments. Instead, only modify the if-else
statements or
the internal logic to adapt the function to your needs.
## Not run:
func_tau <- function(
# Trial number
i,
# Number of times this option has appeared
L_freq,
R_freq,
# Number of times this option has been chosen
L_pick,
R_pick,
# Current value of this option
L_value,
R_value,
# Extra variables
var1 = NA,
var2 = NA,
# Whether calculating probability for left or right choice
LR,
# Is it a random choosing trial?
try,
# Free parameters
tau,
# Extra parameters
alpha,
beta
){
############################### [ random ] ##################################
if (try == 1) {
prob <- 0.5
}
############################# [ greedy-max ] ################################
else if (try == 0 & LR == "L" & is.na(tau)) {
if (L_value == R_value) {
prob <- 0.5
}
else if (L_value > R_value) {
prob <- 1
}
else if (L_value < R_value) {
prob <- 0
}
}
else if (try == 0 & LR == "R" & is.na(tau)) {
if (L_value == R_value) {
prob <- 0.5
}
else if (R_value > L_value) {
prob <- 1
}
else if (R_value < L_value) {
prob <- 0
}
}
############################### [ soft-max ] ################################
else if (try == 0 & LR == "L" & !(is.na(tau))) {
prob <- 1 / (1 + exp(-(L_value - R_value) * tau))
}
else if (try == 0 & LR == "R" & !(is.na(tau))) {
prob <- 1 / (1 + exp(-(R_value - L_value) * tau))
}
################################ [ error ] ##################################
else {
prob <- "ERROR"
}
################################ [ lapse ] ##################################
prob <- (1 - lapse) * prob + (lapse / 2)
return(prob)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.