CBS_ITC {CBSr} | R Documentation |
Fit either a 1-piece or 2-piece CBS latent utility function to binary intertemporal choice data.
CBS_ITC(choice, Amt1, Delay1, Amt2, Delay2, numpiece, numfit = NULL)
choice |
Vector of 0s and 1s. 1 if the choice was option 1, 0 if the choice was option 2. |
Amt1 |
Vector of positive real numbers. Reward amount of choice 1. |
Delay1 |
Vector of positive real numbers. Delay until the reward of choice 1. |
Amt2 |
Vector of positive real numbers. Reward amount of choice 2. |
Delay2 |
Vector of positive real numbers. Delay until the reward of choice 2. |
numpiece |
Either 1 or 2. Number of CBS pieces to use. |
numfit |
Number of model fits to perform from different starting points. If not provided, numfit = 10*numpiece |
The input data has n choices (ideally n > 100) between two reward options.
Option 1 is receiving Amt1
in Delay1
and Option 2 is receiving Amt2
in Delay2
(e.g., $40 in 20 days vs. $20 in 3 days).
One of the two options may be immediate (i.e., delay = 0; e.g., $40 in 20 days vs. $20 today).
choice
should be 1 if option 1 is chosen, 0 if option 2 is chosen.
A list containing the following:
type
: either 'CBS1' or 'CBS2' depending on the number of pieces
LL
: log likelihood of the model
numparam
: number of total parameters in the model
scale
: scaling factor of the logit model
xpos
: x coordinates of the fitted CBS function
ypos
: y coordinates of the fitted CBS function
AUC
: area under the curve of the fitted CBS function. Normalized to be between 0 and 1.
normD
: The domain of CBS function runs from 0 to normD
. Specifically, this is the constant used to normalize all delays between 0 and 1, since CBS is fitted in a unit square first and then scaled up.
# Fit example ITC data with 2-piece CBS function.
# Load example data (included with package).
# Each row is a choice between option 1 (Amt at Delay) vs option 2 (20 now).
Amount1 = ITCdat$Amt1
Delay1 = ITCdat$Delay1
Amount2 = 20
Delay2 = 0
Choice = ITCdat$Choice
# Fit the model
out = CBS_ITC(Choice,Amount1,Delay1,Amount2,Delay2,2)
# Plot the choices (x = Delay, y = relative amount : 20 / delayed amount)
plot(Delay1[Choice==1],20/Amount1[Choice==1],type = 'p',col="blue",xlim=c(0, 180), ylim=c(0, 1))
points(Delay1[Choice==0],20/Amount1[Choice==0],type = 'p',col="red")
# Plot the fitted CBS
x = 0:out$normD
lines(x,CBSfunc(out$xpos,out$ypos,x),col="black")