Skip to main content

A package for fitting intertemporal choice data to models

Project description

A package for fitting intertemporal choice data to models.

Available models for fitting:

  • Exponential: $U=A·exp(−kD)$
  • Hyperbolic: $U=A·(1+kD)^{−1}$
  • Generalized Hyperbolic: $U=A·(1+kD)^{−s}$
  • Quasi-hyperbolic: $U=A·βexp(−kD)$

The constructor takes a model type and data (choices, payoffs, and delays) for two options and instantiates a util-itc object, fitting the data during instantiation.

The resulting object stores the fitted parameters (k, inverse temperature, and an extra parameter s or b for generalized hyperbolic or quasi-hyperbolic models, respectively) in an instance variable, output.

Warnings will be issued if all choices in the input data are one-sided (all 0 or 1), or if the fitted model predicts all one-sided choices.

Dependencies: numpy version >= 1.26.4, scipy version >= 1.12.0

To install using pip and import the package, copy the following code into your terminal:

pip install util-itc
from util_itc import util_itc

To fit after importing, construct a util_itc object for each set of data you would like to fit, in the following format:

x = util_itc(modeltype, choice, amt1, delay1, amt2, delay2)

where x is the variable that results will be stored in. Modeltype should be a 1-length string ('E', 'H', 'GH', or 'Q') that will determine the model used for fitting. All other parameters should be arraylike objects (numpy arrays, lists, etc.).

To obtain fitted parameters, view the output instance variable:

y = x.output
print(y)

where y will store the fitted results in the following format: [[k, inverse temperature, optional parameter s/b], 'modeltype', number of data points]

Example of use:

>>> example = util_itc("E", [0, 1, 0], [9, 9, 9], [1, 4, 3], [1, 7, 4], [4, 0, 0])
>>> example.output
[[0.1428602660107752, 0.36787944117144233], 'E', 3]

For queries regarding package maintenance, please contact chanyoungchung@berkeley.edu

To view additional information about the class or functions, use python's help function (with package installed):

help(util_itc)
help(util_itc.fun)

To exit the help window in terminal, press q.

Help function documentation:

class util_itc(builtins.object)
 |  util_itc(modeltype, choice, amt1, delay1, amt2, delay2)
 |  
 |  Takes intertemporal choice data for n >= 3 decisions and returns estimated parameters k, inverse temperature, and an extra parameter where relevant for the model.
 |  
 |  Args:
 |  modeltype: string describing the model used to fit data: 'E' for exponential, 'H' for hyperbolic, 'GH' for generalized hyperbolic, or 'Q' for quasi-hyperbolic.
 |  choice: array-like of size n containing only the values 1 and 0, where 1 represents option 1 in the choice data and 0 represents option 2.
 |  amt1: array-like of size n containing nonnegative numbers, where each value represents a payoff from option 1
 |  delay1: array-like of size n containing nonnegative numbers, where each value represents a delay before receiving a payoff from option 1
 |  amt2: array-like of size n containing nonnegative numbers, where each value represents a payoff from option 2
 |  delay2: array-like of size n containing nonnegative numbers, where each value represents a delay before receiving a payoff from option 2
 |  
 |  Validates inputs, then runs the fit method to fit intertemporal choice data to a model of the type given.
 |  Stores parameters in instance variable named output, formatted as: [[est. k, est. inverse temperature, est. extra parameter (s for GH, b for Q)], "model", number of choices]
 |  
 |  Methods defined here:
 |  
 |  __init__(self, modeltype, choice, amt1, delay1, amt2, delay2)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  calculate_dv(self, params)
 |  
 |  fit(self)
 |      Uses scipy.optimize.minimize to fit intertemporal choice data to a model specified during object initialization.
 |  
 |  fun(self, params)
 |      Defines the objective function to be minimized, calculating utility differences based on model type and given parameters.
 |      
 |      Args:
 |      params: a size 2 or 3 list containing initial parameter starting points for k, inverse temperature, and an optional second parameter s or b.
 |      
 |      Returns:
 |      float: negative average log likelihood of choices

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

util_itc-0.1.13.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

util_itc-0.1.13-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file util_itc-0.1.13.tar.gz.

File metadata

  • Download URL: util_itc-0.1.13.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for util_itc-0.1.13.tar.gz
Algorithm Hash digest
SHA256 e8e1a11f39ead65689fee9f46d3de2ef869a5be75f23dbd9fc565e2690ab3c06
MD5 3939ee92e90e1e17081954db016db46c
BLAKE2b-256 4c95aec40110e53df7fa31444dfed140fb43999f8507193a8383817098dd0ee7

See more details on using hashes here.

File details

Details for the file util_itc-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: util_itc-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for util_itc-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 9b55a20b59883ce549027eb97c6b8710174f7eecd61f71ee7f9da559c5a1016b
MD5 d5a37bc1ad743e6d0a6745c0d80f3495
BLAKE2b-256 4b670fc31e752a4625878385471aacb232c0bf7026c6360bf1da311b07f042fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page