| Title: | Temporal Discounting Models |
|---|---|
| Description: | Tools for working with temporal discounting data, designed for behavioural researchers to simplify data cleaning/scoring and model fitting. The package implements widely used methods such as computing indifference points from adjusting amount task (Frye et al., 2016, <doi:10.3791/53584>), testing for non-systematic discounting per the criteria of Johnson & Bickel (2008, <doi:10.1037/1064-1297.16.3.264>), scoring questionnaires according to the methods of Kirby et al. (1999, <doi:10.1037//0096-3445.128.1.78>) and Wileyto et al (2004, <doi:10.3758/BF03195548>), Bayesian model selection using a range of discount functions (Franck et al., 2015, <doi:10.1002/jeab.128>), drift diffusion models of discounting (Peters & D'Esposito, 2020, <doi:10.1371/journal.pcbi.1007615>), and model-agnostic measures of discounting such as area under the curve (Myerson et al., 2001, <doi:10.1901/jeab.2001.76-235>) and ED50 (Yoon & Higgins, 2008, <doi:10.1016/j.drugalcdep.2007.12.011>). |
| Authors: | Isaac Kinley [aut, cre] |
| Maintainer: | Isaac Kinley <[email protected]> |
| License: | GPL-3 |
| Version: | 2.2.0 |
| Built: | 2026-05-14 05:35:19 UTC |
| Source: | https://github.com/kinleyid/tempodisco |
Compute indifference points for data from an adjusting amount procedure (also called a "titrating procedure").
adj_amt_indiffs(data, block_indic = "del", order_indic = NULL)adj_amt_indiffs(data, block_indic = "del", order_indic = NULL)
data |
A dataframe where each row corresponds to a binary choice, with at least columns |
block_indic |
Column name of the block indicator—i.e., the column that will identify a block of trials for which an indifference point should be computed. If unspecified, defaults to |
order_indic |
Column name of the order indicator—i.e., the column that specifies the order in which trials were completed. Sorting by this column within a block should sort the rows in chronological order. If unspecified, the rows are assumed to already be in chronological order. |
A dataframe with two columns: one for the block indicator and another for the corresponding indifference point.
data("adj_amt_sim") adj_amt_indiffs(adj_amt_sim) adj_amt_indiffs(adj_amt_sim, block_indic = 'del', order_indic = 'trial_idx')data("adj_amt_sim") adj_amt_indiffs(adj_amt_sim) adj_amt_indiffs(adj_amt_sim, block_indic = 'del', order_indic = 'trial_idx')
A minimal example of data from a single participant for an adjusting amount procedure.
Isaac Kinley [email protected]
Check whether participants failed attention checks, either choosing an immediate reward of 0 or choosing a delayed reward equal in face value to an immediate reward. If the participant was never offered either choice, a warning is given.
attention_checks(data, warn = FALSE, ppn = FALSE)attention_checks(data, warn = FALSE, ppn = FALSE)
data |
A |
warn |
Logical: give a warning for failed attention checks? |
ppn |
Logical: return proportions of attention checks participant failed, versus absolute numbers? |
Named vector counting the number of times the participant chose an immediate reward of 0 (imm_0) or chose a delayed reward equal in face value to an immediate reward (del_eq_imm).
# On a model data("td_bc_single_ptpt") attention_checks(td_bc_single_ptpt)# On a model data("td_bc_single_ptpt") attention_checks(td_bc_single_ptpt)
Compute either the model-based or model-free area under the curve.
AUC( obj, min_del = 0, max_del = NULL, val_del = NULL, del_transform = c("none", "log", "ordinal-scaling"), ... )AUC( obj, min_del = 0, max_del = NULL, val_del = NULL, del_transform = c("none", "log", "ordinal-scaling"), ... )
obj |
A temporal discounting model or a dataframe with columns |
min_del |
Lower limit to use for integration. Defaults to 0. |
max_del |
Upper limit to use for integration. Defaults to the maximum delay in the data. |
val_del |
Delayed value to use for computing the indifference curve, if applicable. Defaults to the average |
del_transform |
String specifying transformation to apply to the delays (e.g., log10 + 1 transform or ordinal scaling transform; Borges et al., 2016, doi:10.1002/jeab.219). Default is no transform. |
... |
Further arguments passed to 'integrate()'. |
AUC value.
An indifference point of 1 is assumed at delay 0.
data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "exponential") print(AUC(mod))data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "exponential") print(AUC(mod))
Get coefficients of a temporal discounting binary choice linear model.
## S3 method for class 'td_bclm' coef(object, df_par = TRUE, ...)## S3 method for class 'td_bclm' coef(object, df_par = TRUE, ...)
object |
An object of class |
df_par |
Boolean specifying whether the coefficients returned should be the parameters of a discount function (versus the beta parameters from the regression). |
... |
Additional arguments currently not used. |
A named vector of coefficients.
Get coefficients of a temporal discounting binary choice nonlinear model.
## S3 method for class 'td_bcnm' coef(object, ...)## S3 method for class 'td_bcnm' coef(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
A named vector of coefficients.
Other nonlinear binary choice model functions:
deviance.td_bcnm(),
fitted.td_bcnm(),
logLik.td_bcnm(),
predict.td_bcnm(),
residuals.td_bcnm(),
td_bcnm()
Get coefficients of a temporal discounting drift diffusion model.
## S3 method for class 'td_ddm' coef(object, type = "all", ...)## S3 method for class 'td_ddm' coef(object, type = "all", ...)
object |
An object of class |
type |
A string specifying which coefficients to extract. |
... |
Additional arguments currently not used. |
A named vector of coefficients.
Other drift diffusion model functions:
deviance.td_ddm(),
fitted.td_ddm(),
logLik.td_ddm(),
predict.td_ddm(),
td_ddm()
Get coefficients of a temporal discounting indifference point model.
## S3 method for class 'td_ipm' coef(object, ...)## S3 method for class 'td_ipm' coef(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
A named vector of coefficients.
Other indifference point model functions:
fitted.td_ipm(),
logLik.td_ipm(),
predict.td_ipm(),
residuals.td_ipm()
Compute deviance for a temporal discounting binary choice model.
## S3 method for class 'td_bcnm' deviance(object, ...)## S3 method for class 'td_bcnm' deviance(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
The value of the deviance extracted from the model
Other nonlinear binary choice model functions:
coef.td_bcnm(),
fitted.td_bcnm(),
logLik.td_bcnm(),
predict.td_bcnm(),
residuals.td_bcnm(),
td_bcnm()
Compute deviance for a temporal discounting drift diffusion model.
## S3 method for class 'td_ddm' deviance(object, ...)## S3 method for class 'td_ddm' deviance(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
The value of the deviance extracted from the model
Other drift diffusion model functions:
coef.td_ddm(),
fitted.td_ddm(),
logLik.td_ddm(),
predict.td_ddm(),
td_ddm()
Access the name of the discount function of a model.
discount_function(mod)discount_function(mod)
mod |
A temporal discounting model. |
The name of the discount function.
data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "exponential") discount_function(mod)data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "exponential") discount_function(mod)
Compute the median effective delay.
ED50(mod, val_del = NULL)ED50(mod, val_del = NULL)
mod |
A temporal discounting model. |
val_del |
Delayed value, if applicable (i.e., if magnitude effects are accounted for). |
Median effective delay value.
data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "exponential") print(ED50(mod))data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "exponential") print(ED50(mod))
Get fitted values of a temporal discounting binary choice model.
## S3 method for class 'td_bcnm' fitted(object, ...)## S3 method for class 'td_bcnm' fitted(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
A named vector of fitted values.
Other nonlinear binary choice model functions:
coef.td_bcnm(),
deviance.td_bcnm(),
logLik.td_bcnm(),
predict.td_bcnm(),
residuals.td_bcnm(),
td_bcnm()
Get fitted values of a temporal discounting drift diffusion model.
## S3 method for class 'td_ddm' fitted(object, ...)## S3 method for class 'td_ddm' fitted(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
A named vector of fitted values.
Other drift diffusion model functions:
coef.td_ddm(),
deviance.td_ddm(),
logLik.td_ddm(),
predict.td_ddm(),
td_ddm()
Get fitted values of a temporal discounting indifference point model.
## S3 method for class 'td_ipm' fitted(object, ...)## S3 method for class 'td_ipm' fitted(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
A named vector of fitted values.
Other indifference point model functions:
coef.td_ipm(),
logLik.td_ipm(),
predict.td_ipm(),
residuals.td_ipm()
Get a list of all of the available pre-defined discount functions.
get_available_discount_functions()get_available_discount_functions()
A character vector containing the names of the avialable pre-defined discount functions.
get_available_discount_functions()get_available_discount_functions()
Create a dataframe of delays and the corresponding indifference points predicted by a model.
indiffs(mod)indiffs(mod)
mod |
A dataframe with columns del (delay) and indiff (indifference point).
data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = 'model-free') indiff_data <- indiffs(mod)data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = 'model-free') indiff_data <- indiffs(mod)
Check whether participants always chose the immediate reward or always chose the delayed reward.
invariance_checks(data, warn = FALSE)invariance_checks(data, warn = FALSE)
data |
A |
warn |
Logical: give a warning for invariant responding? |
Named vector specifying whether the participant chose only immediate rewards (all_imm) or chose all delayed rewards (all_del).
# On a model data("td_bc_single_ptpt") attention_checks(td_bc_single_ptpt)# On a model data("td_bc_single_ptpt") attention_checks(td_bc_single_ptpt)
Compute the consistency score per the method of Kirby et al. (1999, doi:10.1037//0096-3445.128.1.78). This is described in detail in Kaplan et al. (2016, doi:10.1007/s40614-016-0070-9), where it's suggested that a consistency score below 0.75 might be a sign of inattentive responding.
kirby_consistency( data, discount_function = c("hyperbolic", "exponential", "power", "arithmetic") )kirby_consistency( data, discount_function = c("hyperbolic", "exponential", "power", "arithmetic") )
data |
Responses to score. |
discount_function |
Should |
A consistency score between 0 and 1.
data("td_bc_single_ptpt") mod <- kirby_consistency(td_bc_single_ptpt)data("td_bc_single_ptpt") mod <- kirby_consistency(td_bc_single_ptpt)
Score a set of responses according to the method of Kirby et al. (1999, doi:10.1037//0096-3445.128.1.78). This is described in detail in Kaplan et al. (2016, doi:10.1007/s40614-016-0070-9).
kirby_score( data, discount_function = c("hyperbolic", "exponential", "power", "arithmetic") )kirby_score( data, discount_function = c("hyperbolic", "exponential", "power", "arithmetic") )
data |
Responses to score. |
discount_function |
Should |
An object of class td_ipm.
data("td_bc_single_ptpt") mod <- kirby_score(td_bc_single_ptpt)data("td_bc_single_ptpt") mod <- kirby_score(td_bc_single_ptpt)
Compute log-likelihood for a temporal discounting binary choice nonlinear model.
## S3 method for class 'td_bcnm' logLik(object, ...)## S3 method for class 'td_bcnm' logLik(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
Returns an object of class logLik with attributed df and nobs
Other nonlinear binary choice model functions:
coef.td_bcnm(),
deviance.td_bcnm(),
fitted.td_bcnm(),
predict.td_bcnm(),
residuals.td_bcnm(),
td_bcnm()
Compute log-likelihood for a temporal discounting drift diffusion model.
## S3 method for class 'td_ddm' logLik(object, type = c("resp_rt", "resp", "rt"), ...)## S3 method for class 'td_ddm' logLik(object, type = c("resp_rt", "resp", "rt"), ...)
object |
An object of class |
type |
Should probabilities /probability densities be computed for responses and RTs ( |
... |
Additional arguments currently not used. |
Returns an object of class logLik with attributed df and nobs
Other drift diffusion model functions:
coef.td_ddm(),
deviance.td_ddm(),
fitted.td_ddm(),
predict.td_ddm(),
td_ddm()
Compute log-likelihood for a temporal discounting indifference point model.
## S3 method for class 'td_ipm' logLik(object, ...)## S3 method for class 'td_ipm' logLik(object, ...)
object |
An object of class |
... |
Additional arguments currently not used. |
Returns an object of class logLik with attributed df and nobs
Other indifference point model functions:
coef.td_ipm(),
fitted.td_ipm(),
predict.td_ipm(),
residuals.td_ipm()
Experimental method for computing indifference points
most_consistent_indiffs(data)most_consistent_indiffs(data)
data |
Responses to score. |
A dataframe with two columns: one for the block indicator and another for the corresponding indifference point.
Check for non-systematic discounting, per the Johnson & Bickel (2008) criteria. These are:
C1: No indifference point can exceed the previous by more than 0.2
C2: Last indifference point must be lower than first by at least 0.1
nonsys(obj)nonsys(obj)
obj |
Either a |
Named logical vector specifying whether nonsystematic discounting is exhibited according to C1/C2.
# On a model data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = 'model-free') any(nonsys(mod)) # On a dataframe data("td_ip_simulated_ptpt") any(nonsys(td_ip_simulated_ptpt)) # Artificial case of nonsystematic discounting nonsys(data.frame(del = 1:3, indiff = c(0.5, 0.8, 0.6))) # Both TRUE# On a model data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = 'model-free') any(nonsys(mod)) # On a dataframe data("td_ip_simulated_ptpt") any(nonsys(td_ip_simulated_ptpt)) # Artificial case of nonsystematic discounting nonsys(data.frame(del = 1:3, indiff = c(0.5, 0.8, 0.6))) # Both TRUE
Create a plot that displays binary choices at each delay
plot_choices(data, legend = TRUE, ...)plot_choices(data, legend = TRUE, ...)
data |
A data frame with columns |
legend |
Logical: display a legend? |
... |
Additional arguments to |
No return value (called to produce a plot)
data('td_bc_single_ptpt') plot_choices(td_bc_single_ptpt)data('td_bc_single_ptpt') plot_choices(td_bc_single_ptpt)
Plot delay discounting models.
## S3 method for class 'td_um' plot( x, type = c("summary", "endpoints", "link", "rt"), legend = TRUE, p_lines = NULL, p_tol = 0.001, verbose = TRUE, del = NULL, val_del = NULL, q_lines = c(0.025, 0.975), ... )## S3 method for class 'td_um' plot( x, type = c("summary", "endpoints", "link", "rt"), legend = TRUE, p_lines = NULL, p_tol = 0.001, verbose = TRUE, del = NULL, val_del = NULL, q_lines = c(0.025, 0.975), ... )
x |
A delay discounting model. See |
type |
Type of plot to generate. |
legend |
Logical: display a legend? Only relevant for |
p_lines |
Numerical vector. When |
p_tol |
If |
verbose |
Whether to print info about, e.g., setting del = ED50 when |
del |
Plots data for a particular delay. |
val_del |
Plots data for a particular delayed value. |
q_lines |
When |
... |
Additional arguments to |
No return value (called to produce a plot)
data("td_bc_single_ptpt") mod <- td_bclm(td_bc_single_ptpt, model = 'hyperbolic.1') plot(mod, type = 'summary', p_lines = c(0.25, 0.75), log = 'x') plot(mod, type = 'endpoints')data("td_bc_single_ptpt") mod <- td_bclm(td_bc_single_ptpt, model = 'hyperbolic.1') plot(mod, type = 'summary', p_lines = c(0.25, 0.75), log = 'x') plot(mod, type = 'endpoints')
Generate predictions from a temporal discounting binary choice linear model.
## S3 method for class 'td_bclm' predict( object, newdata = NULL, type = c("indiff", "link", "response", "terms"), ... )## S3 method for class 'td_bclm' predict( object, newdata = NULL, type = c("indiff", "link", "response", "terms"), ... )
object |
A temporal discounting binary choice linear model. See |
newdata |
Optionally, a data frame to use for prediction. If omitted, the data used to fit the model will be used for prediction. |
type |
The type of prediction required. For |
... |
Additional arguments passed to predict.glm if type != |
A vector of predictions.
Other linear binary choice model functions:
td_bclm()
data("td_bc_single_ptpt") mod <- td_bclm(td_bc_single_ptpt, model = 'hyperbolic.1') indiffs <- predict(mod, newdata = data.frame(del = 1:100), type = 'indiff')data("td_bc_single_ptpt") mod <- td_bclm(td_bc_single_ptpt, model = 'hyperbolic.1') indiffs <- predict(mod, newdata = data.frame(del = 1:100), type = 'indiff')
Generate predictions from a temporal discounting binary choice model.
## S3 method for class 'td_bcnm' predict(object, newdata = NULL, type = c("link", "response", "indiff"), ...)## S3 method for class 'td_bcnm' predict(object, newdata = NULL, type = c("link", "response", "indiff"), ...)
object |
A temporal discounting binary choice model. See |
newdata |
Optionally, a data frame to use for prediction. If omitted, the data used to fit the model will be used for prediction. |
type |
The type of prediction required. As in predict.glm, |
... |
Additional arguments currently not used. |
A vector of predictions.
Other nonlinear binary choice model functions:
coef.td_bcnm(),
deviance.td_bcnm(),
fitted.td_bcnm(),
logLik.td_bcnm(),
residuals.td_bcnm(),
td_bcnm()
data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = 'hyperbolic') indiffs <- predict(mod, newdata = data.frame(del = 1:100), type = 'indiff')data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = 'hyperbolic') indiffs <- predict(mod, newdata = data.frame(del = 1:100), type = 'indiff')
Generate predictions from a temporal discounting drift diffusion model.
## S3 method for class 'td_ddm' predict( object, newdata = NULL, type = c("indiff", "link", "response", "rt"), ... )## S3 method for class 'td_ddm' predict( object, newdata = NULL, type = c("indiff", "link", "response", "rt"), ... )
object |
A temporal discounting drift diffusion model. See |
newdata |
Optionally, a data frame to use for prediction. If omitted, the data used to fit the model will be used for prediction. |
type |
The type of prediction required. As in predict.glm, |
... |
Additional arguments currently not used. |
A vector of predictions.
When type = 'rt', expected RTs are computed irrespective of which reward was selected, per equation 5 in Grasman, Wagenmakers, & van der Maas (2009, doi:10.1016/j.jmp.2009.01.006).
Other drift diffusion model functions:
coef.td_ddm(),
deviance.td_ddm(),
fitted.td_ddm(),
logLik.td_ddm(),
td_ddm()
data("td_bc_single_ptpt") ddm <- td_ddm(td_bc_single_ptpt, discount_function = 'exponential', gamma_par_starts = 0.01, beta_par_starts = 0.5, alpha_par_starts = 3.5, tau_par_starts = 0.9) pred_rts <- predict(ddm, type = 'rt')data("td_bc_single_ptpt") ddm <- td_ddm(td_bc_single_ptpt, discount_function = 'exponential', gamma_par_starts = 0.01, beta_par_starts = 0.5, alpha_par_starts = 3.5, tau_par_starts = 0.9) pred_rts <- predict(ddm, type = 'rt')
Generate predictions from a temporal discounting indifference point model
## S3 method for class 'td_ipm' predict(object, newdata = NULL, type = c("indiff", "response"), ...)## S3 method for class 'td_ipm' predict(object, newdata = NULL, type = c("indiff", "response"), ...)
object |
A temporal discounting indifference point model. See |
newdata |
A data frame to use for prediction. If omitted, the data used to fit the model will be used for prediction. |
type |
Type of prediction, either |
... |
Additional arguments currently not used. |
A vector of predictions.
Other indifference point model functions:
coef.td_ipm(),
fitted.td_ipm(),
logLik.td_ipm(),
residuals.td_ipm()
data("td_ip_simulated_ptpt") mod <- td_ipm(td_ip_simulated_ptpt, discount_function = 'hyperbolic') indiffs <- predict(mod, del = 1:100) indiffs <- predict(mod, newdata = data.frame(del = 1:100))data("td_ip_simulated_ptpt") mod <- td_ipm(td_ip_simulated_ptpt, discount_function = 'hyperbolic') indiffs <- predict(mod, del = 1:100) indiffs <- predict(mod, newdata = data.frame(del = 1:100))
Get residuals from a temporal discounting binary choice nonlinear model.
## S3 method for class 'td_bcnm' residuals(object, type = c("deviance", "pearson", "response"), ...)## S3 method for class 'td_bcnm' residuals(object, type = c("deviance", "pearson", "response"), ...)
object |
A temporal discounting binary choice model. See |
type |
The type of residuals to be returned. See |
... |
Additional arguments currently not used. |
A vector of residuals.
Other nonlinear binary choice model functions:
coef.td_bcnm(),
deviance.td_bcnm(),
fitted.td_bcnm(),
logLik.td_bcnm(),
predict.td_bcnm(),
td_bcnm()
Get residuals from a temporal discounting indifference point model.
## S3 method for class 'td_ipm' residuals(object, type = c("response", "pearson"), ...)## S3 method for class 'td_ipm' residuals(object, type = c("response", "pearson"), ...)
object |
A temporal discounting model. See |
type |
The type of residuals to be returned. See |
... |
Additional arguments currently not used. |
A vector of residuals.
Other indifference point model functions:
coef.td_ipm(),
fitted.td_ipm(),
logLik.td_ipm(),
predict.td_ipm()
70 binary choices made by a single participant. Along with the columns required by td_bcnm, the reaction time (rt) is recorded.
Isaac Kinley [email protected]
Data from 421 participants, who each made 70 binary choices. Along with the columns required by td_bcnm, the reaction time (rt) in seconds is recorded. Participants are identified by the alphnumeric code in the id column.
Isaac Kinley [email protected]
Compute a binary choice linear model for a single subject. In these models, we can recover the parameters of a discount function from the weights of a standard logistic regression.
td_bclm( data, model = c("all", "hyperbolic.1", "hyperbolic.2", "exponential.1", "exponential.2", "scaled-exponential", "nonlinear-time-hyperbolic", "power", "nonlinear-time-exponential", "arithmetic.1", "arithmetic.2"), ... )td_bclm( data, model = c("all", "hyperbolic.1", "hyperbolic.2", "exponential.1", "exponential.2", "scaled-exponential", "nonlinear-time-hyperbolic", "power", "nonlinear-time-exponential", "arithmetic.1", "arithmetic.2"), ... )
data |
A data frame with columns |
model |
A string specifying which model to use. Below is a list of these models' linear predictors and the means by which we can recover discount function parameters. |
... |
Additional arguments passed to |
An object of class td_bclm, nearly identical to a glm but with an additional config component.
Other linear binary choice model functions:
predict.td_bclm()
data("td_bc_single_ptpt") mod <- td_bclm(td_bc_single_ptpt, model = 'hyperbolic.1') print(coef(mod))data("td_bc_single_ptpt") mod <- td_bclm(td_bc_single_ptpt, model = 'hyperbolic.1') print(coef(mod))
Compute a binary choice model for a single subject
td_bcnm( data, discount_function = "franck-2015", choice_rule = c("logistic", "probit", "power"), fixed_ends = FALSE, fit_err_rate = FALSE, gamma_par_starts = c(0.01, 1, 100), eps_par_starts = c(0.01, 0.25), silent = TRUE, optim_args = list(), ... )td_bcnm( data, discount_function = "franck-2015", choice_rule = c("logistic", "probit", "power"), fixed_ends = FALSE, fit_err_rate = FALSE, gamma_par_starts = c(0.01, 1, 100), eps_par_starts = c(0.01, 0.25), silent = TRUE, optim_args = list(), ... )
data |
A data frame with columns |
discount_function |
A string specifying the name of the discount functions to use, or an object of class |
choice_rule |
A string specifying whether the |
fixed_ends |
A Boolean (false by default) specifying whether the model should satisfy the desiderata that subjects should always prefer something over nothing (i.e., nonzero delayed reward over nothing) and the same reward sooner rather than later. See here: https://doi.org/10.1016/j.jmp.2025.102902 |
fit_err_rate |
A Boolean (false by default) specifying whether the model should include an error rate (parameterized by "eps"). See Eq. 5 here: https://doi.org/10.3758/s13428-015-0672-2. |
gamma_par_starts |
A vector of starting values to try for the "gamma" parameter (which controls the steepness of the choice rule) during optimization. |
eps_par_starts |
A vector of starting values to try for the "eps" parameter (which controls the error rate) during optimization. Ignored if 'fit_err_rate = FALSE'. |
silent |
Boolean (true by default). The call to |
optim_args |
Additional arguments to pass to |
... |
Additional arguments to provide finer-grained control over the choice rule. Note that using a custom choice rule causes the |
An object of class td_bcnm with components data (containing the data used for fitting), config (containing the internal configuration of the model, including the discount_function), and optim (the output of optim()).
Other nonlinear binary choice model functions:
coef.td_bcnm(),
deviance.td_bcnm(),
fitted.td_bcnm(),
logLik.td_bcnm(),
predict.td_bcnm(),
residuals.td_bcnm()
data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "hyperbolic", fixed_ends = TRUE) # Custom discount function custom_discount_function <- td_fn( name = 'custom', fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'], par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)), par_lims = list(k = c(0, Inf), b = c(0, 1)), ED50 = function(...) 'non-analytic' ) mod <- td_bcnm(td_bc_single_ptpt, discount_function = custom_discount_function, fit_err_rate = TRUE)data("td_bc_single_ptpt") mod <- td_bcnm(td_bc_single_ptpt, discount_function = "hyperbolic", fixed_ends = TRUE) # Custom discount function custom_discount_function <- td_fn( name = 'custom', fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'], par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)), par_lims = list(k = c(0, Inf), b = c(0, 1)), ED50 = function(...) 'non-analytic' ) mod <- td_bcnm(td_bc_single_ptpt, discount_function = custom_discount_function, fit_err_rate = TRUE)
Fit a drift diffusion model for a single subject using maximum likelihood estimation.
td_ddm( data, discount_function, gamma_par_starts = c(0.01, 0.1, 1), beta_par_starts = c(0.25, 0.5, 0.75), alpha_par_starts = c(0.5, 1, 10), tau_par_starts = c(0.2, 0.8), drift_transform = c("none", "logis"), bias_adjust = FALSE, silent = TRUE, optim_args = list() )td_ddm( data, discount_function, gamma_par_starts = c(0.01, 0.1, 1), beta_par_starts = c(0.25, 0.5, 0.75), alpha_par_starts = c(0.5, 1, 10), tau_par_starts = c(0.2, 0.8), drift_transform = c("none", "logis"), bias_adjust = FALSE, silent = TRUE, optim_args = list() )
data |
A data frame with columns |
discount_function |
A string specifying the name of the discount functions to use, or an object of class |
gamma_par_starts |
A vector of starting values to try for the "gamma" parameter (drift rate multiplier or sharpness parameter) during optimization. |
beta_par_starts |
A vector of starting values to try for the "beta" parameter (bias) during optimization. |
alpha_par_starts |
A vector of starting values to try for the "alpha" parameter (boundary separation) during optimization. |
tau_par_starts |
A vector of starting values to try for the "tau" parameter (non-decision time) during optimization. |
drift_transform |
A transform to apply to drift rates. Either |
bias_adjust |
Experimental feature. See not below. |
silent |
Boolean (true by default). The call to |
optim_args |
Additional arguments to pass to |
An object of class td_bcnm with components data (containing the data used for fitting), config (containing the internal configuration of the model, including the discount_function), and optim (the output of optim()).
Drift rates are computed based on the difference in subjective values between the immediate and delayed rewards. In theory, when they are equally valued, they should have equal probability of being chosen. However, this is only true when the bias parameter of the drift diffusion model (beta) is 0.5 (i.e., no bias). To make sure the immediate and delayed reward have equal probability of being chosen when they are equally valued, we can set bias_adjust = TRUE to add a bias correction factor to the drift rate. However, this feature is experimental and its effects on model fit etc. have not been tested.
Other drift diffusion model functions:
coef.td_ddm(),
deviance.td_ddm(),
fitted.td_ddm(),
logLik.td_ddm(),
predict.td_ddm()
data("td_bc_single_ptpt") ddm <- td_ddm(td_bc_single_ptpt, discount_function = 'exponential', gamma_par_starts = 0.01, beta_par_starts = 0.5, alpha_par_starts = 3.5, tau_par_starts = 0.9)data("td_bc_single_ptpt") ddm <- td_ddm(td_bc_single_ptpt, discount_function = 'exponential', gamma_par_starts = 0.01, beta_par_starts = 0.5, alpha_par_starts = 3.5, tau_par_starts = 0.9)
Get a predefined discount function or create a custom discount function.
td_fn( predefined = c("hyperbolic", "nonlinear-time-hyperbolic", "exponential", "nonlinear-time-exponential", "absolute-stationarity", "relative-stationarity", "power", "nonlinear-time-power", "arithmetic", "nonlinear-time-arithmetic", "inverse-q-exponential", "scaled-exponential", "scaled-hyperbolic", "fixed-cost", "dual-systems-exponential", "additive-utility", "model-free", "constant"), name = "unnamed", fn = NULL, par_starts = NULL, par_lims = NULL, init = NULL, ED50 = NULL, par_chk = NULL )td_fn( predefined = c("hyperbolic", "nonlinear-time-hyperbolic", "exponential", "nonlinear-time-exponential", "absolute-stationarity", "relative-stationarity", "power", "nonlinear-time-power", "arithmetic", "nonlinear-time-arithmetic", "inverse-q-exponential", "scaled-exponential", "scaled-hyperbolic", "fixed-cost", "dual-systems-exponential", "additive-utility", "model-free", "constant"), name = "unnamed", fn = NULL, par_starts = NULL, par_lims = NULL, init = NULL, ED50 = NULL, par_chk = NULL )
predefined |
A string specifying one of the pre-defined discount functions. |
name |
Name of custom discount function. |
fn |
Function that takes a data.frame called |
par_starts |
A named list of vectors, each specifying possible starting values for a parameter to try when running optimization. |
par_lims |
A named list of vectors, each specifying the bounds to impose of a parameters. Any parameter for which bounds are unspecified are assumed to be unbounded. |
init |
A function to initialize the td_fn object. It should take 2 arguments: "self" (the td_fn object being initialized) and "data" (the data used for initialization). |
ED50 |
A function which, given a named vector of parameters |
par_chk |
Optionally, this is a function that checks the parameters to ensure they meet some criteria. E.g., for the dual-systems-exponential discount function, we require k1 < k2. |
An object of class td_fn.
data("td_bc_single_ptpt") # Custom discount function custom_discount_function <- td_fn( name = 'custom', fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'], par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)), par_lims = list(k = c(0, Inf), b = c(0, 1)), ED50 = 'non-analytic' ) mod <- td_bcnm(td_bc_single_ptpt, discount_function = custom_discount_function, fit_err_rate = TRUE)data("td_bc_single_ptpt") # Custom discount function custom_discount_function <- td_fn( name = 'custom', fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'], par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)), par_lims = list(k = c(0, Inf), b = c(0, 1)), ED50 = 'non-analytic' ) mod <- td_bcnm(td_bc_single_ptpt, discount_function = custom_discount_function, fit_err_rate = TRUE)
A dataframe containing simulated indifference points from a single participant exhibiting approximately hyperbolic discounting.
Isaac Kinley [email protected]
Compute a model of a single subject's indifference points.
td_ipm( data, discount_function = "franck-2015", optim_args = list(), silent = TRUE )td_ipm( data, discount_function = "franck-2015", optim_args = list(), silent = TRUE )
data |
A data frame with columns |
discount_function |
A vector of strings specifying the name of the discount functions to use, or an object of class |
optim_args |
A list of additional args to pass to |
silent |
A Boolean specifying whether the call to |
An object of class td_ipm with components data (containing the data used for fitting), config (containing the internal configuration of the model, including the discount_function), and optim (the output of optim()).
# Basic usage data("td_ip_simulated_ptpt") mod <- td_ipm(td_ip_simulated_ptpt, discount_function = "hyperbolic") # Custom discount function custom_discount_function <- td_fn( name = 'custom', fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'], par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)), par_lims = list(k = c(0, Inf), b = c(0, 1)), ED50 = function(p) 'non-analytic' ) mod <- td_ipm(td_ip_simulated_ptpt, discount_function = custom_discount_function)# Basic usage data("td_ip_simulated_ptpt") mod <- td_ipm(td_ip_simulated_ptpt, discount_function = "hyperbolic") # Custom discount function custom_discount_function <- td_fn( name = 'custom', fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'], par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)), par_lims = list(k = c(0, Inf), b = c(0, 1)), ED50 = function(p) 'non-analytic' ) mod <- td_ipm(td_ip_simulated_ptpt, discount_function = custom_discount_function)
Score a set of responses according to the method of Wileyto et al. (2004, doi:10.3758/BF03195548). This function is a thin wrapper to td_bclm.
wileyto_score(data)wileyto_score(data)
data |
Responses to score. |
An object of class td_bclm.
data("td_bc_single_ptpt") mod <- wileyto_score(td_bc_single_ptpt)data("td_bc_single_ptpt") mod <- wileyto_score(td_bc_single_ptpt)