if (FALSE) {
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 parameter
tau = 1,
# Extra parameters
alpha,
beta
){
if (!(LR %in% c("L", "R"))) {
stop("LR = 'L' or 'R'")
}
############################### [ value-based ] #############################
else if (try == 0 & LR == "L") {
prob <- 1 / (1 + exp(-(L_value - R_value) * tau))
}
else if (try == 0 & LR == "R") {
prob <- 1 / (1 + exp(-(R_value - L_value) * tau))
}
################################# [ random ] ################################
else if (try == 1) {
prob <- 0.5
}
else {
prob <- "ERROR" # Error check
}
return(prob)
}
}
Run the code above in your browser using DataLab