Title: | Hierarchical Bayesian Modeling of Decision-Making Tasks |
---|---|
Description: | Fit an array of decision-making tasks with computational models in a hierarchical Bayesian framework. Can perform hierarchical Bayesian analysis of various computational models with a single line of coding (Ahn et al., 2017) <doi:10.1162/CPSY_a_00002>. |
Authors: | Woo-Young Ahn [aut, cre], Nate Haines [aut], Lei Zhang [aut], Harhim Park [ctb], Jaeyeong Yang [ctb], Jethro Lee [ctb] |
Maintainer: | Woo-Young Ahn <[email protected]> |
License: | GPL-3 |
Version: | 1.3.0.9000 |
Built: | 2025-03-12 06:03:49 UTC |
Source: | https://github.com/ccs-lab/hbayesdm |
Hierarchical Bayesian Modeling of the Aversive Learning Task using Rescorla-Wagner (Delta) Model.
It has the following parameters: A
(learning rate), beta
(inverse temperature), gamma
(risk preference).
Task: Aversive Learning Task (Browning et al., 2015)
Model: Rescorla-Wagner (Delta) Model
alt_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
alt_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Aversive Learning Task, there should be 5 columns of data with the
labels "subjID", "choice", "outcome", "bluePunish", "orangePunish". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial (blue == 1, orange == 2).
Integer value representing the outcome of the given trial (punishment == 1, and non-punishment == 0).
Floating point value representing the magnitude of punishment for blue on that trial (e.g., 10, 97)
Floating point value representing the magnitude of punishment for orange on that trial (e.g., 23, 45)
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Lili Zhang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"alt_delta").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Browning, M., Behrens, T. E., Jocham, G., O'reilly, J. X., & Bishop, S. J. (2015). Anxious individuals have difficulty learning the causal statistics of aversive environments. Nature neuroscience, 18(4), 590.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- alt_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- alt_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- alt_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- alt_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Aversive Learning Task using Rescorla-Wagner (Gamma) Model.
It has the following parameters: A
(learning rate), beta
(inverse temperature), gamma
(risk preference).
Task: Aversive Learning Task (Browning et al., 2015)
Model: Rescorla-Wagner (Gamma) Model
alt_gamma( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
alt_gamma( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Aversive Learning Task, there should be 5 columns of data with the
labels "subjID", "choice", "outcome", "bluePunish", "orangePunish". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial (blue == 1, orange == 2).
Integer value representing the outcome of the given trial (punishment == 1, and non-punishment == 0).
Floating point value representing the magnitude of punishment for blue on that trial (e.g., 10, 97)
Floating point value representing the magnitude of punishment for orange on that trial (e.g., 23, 45)
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Lili Zhang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"alt_gamma").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Browning, M., Behrens, T. E., Jocham, G., O'reilly, J. X., & Bishop, S. J. (2015). Anxious individuals have difficulty learning the causal statistics of aversive environments. Nature neuroscience, 18(4), 590.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- alt_gamma( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- alt_gamma( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- alt_gamma( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- alt_gamma( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 2-Armed Bandit Task using Rescorla-Wagner (Delta) Model.
It has the following parameters: A
(learning rate), tau
(inverse temperature).
Task: 2-Armed Bandit Task (Erev et al., 2010; Hertwig et al., 2004)
Model: Rescorla-Wagner (Delta) Model
bandit2arm_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit2arm_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 2-Armed Bandit Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1 or 2.
Integer value representing the outcome of the given trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit2arm_delta").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Erev, I., Ert, E., Roth, A. E., Haruvy, E., Herzog, S. M., Hau, R., et al. (2010). A choice prediction competition: Choices from experience and from description. Journal of Behavioral Decision Making, 23(1), 15-47. https://doi.org/10.1002/bdm.683
Hertwig, R., Barron, G., Weber, E. U., & Erev, I. (2004). Decisions From Experience and the Effect of Rare Events in Risky Choice. Psychological Science, 15(8), 534-539. https://doi.org/10.1111/j.0956-7976.2004.00715.x
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit2arm_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit2arm_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit2arm_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit2arm_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 4-Armed Bandit Task using 3 Parameter Model, without C (choice perseveration), R (reward sensitivity), and P (punishment sensitivity). But with xi (noise).
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), xi
(noise).
Task: 4-Armed Bandit Task
Model: 3 Parameter Model, without C (choice perseveration), R (reward sensitivity), and P (punishment sensitivity). But with xi (noise) (Aylward et al., 2018)
bandit4arm_2par_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit4arm_2par_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 4-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, or 4.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit4arm_2par_lapse").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Aylward, Valton, Ahn, Bond, Dayan, Roiser, & Robinson (2018) Altered decision-making under uncertainty in unmedicated mood and anxiety disorders. PsyArxiv. 10.31234/osf.io/k5b8m
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_2par_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_2par_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_2par_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_2par_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 4-Armed Bandit Task using 4 Parameter Model, without C (choice perseveration).
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), R
(reward sensitivity), P
(punishment sensitivity).
Task: 4-Armed Bandit Task
Model: 4 Parameter Model, without C (choice perseveration) (Seymour et al., 2012)
bandit4arm_4par( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit4arm_4par( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 4-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, or 4.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit4arm_4par").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Seymour, Daw, Roiser, Dayan, & Dolan (2012). Serotonin Selectively Modulates Reward Value in Human Decision-Making. J Neuro, 32(17), 5833-5842.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_4par( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_4par( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_4par( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_4par( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 4-Armed Bandit Task using 5 Parameter Model, without C (choice perseveration) but with xi (noise).
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), R
(reward sensitivity), P
(punishment sensitivity), xi
(noise).
Task: 4-Armed Bandit Task
Model: 5 Parameter Model, without C (choice perseveration) but with xi (noise) (Seymour et al., 2012)
bandit4arm_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit4arm_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 4-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, or 4.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit4arm_lapse").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Seymour, Daw, Roiser, Dayan, & Dolan (2012). Serotonin Selectively Modulates Reward Value in Human Decision-Making. J Neuro, 32(17), 5833-5842.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 4-Armed Bandit Task using 5 Parameter Model, without C (choice perseveration) but with xi (noise). Added decay rate (Niv et al., 2015, J. Neuro)..
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), R
(reward sensitivity), P
(punishment sensitivity), xi
(noise), d
(decay rate).
Task: 4-Armed Bandit Task
Model: 5 Parameter Model, without C (choice perseveration) but with xi (noise). Added decay rate (Niv et al., 2015, J. Neuro). (Aylward et al., 2018)
bandit4arm_lapse_decay( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit4arm_lapse_decay( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 4-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, or 4.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit4arm_lapse_decay").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Aylward, Valton, Ahn, Bond, Dayan, Roiser, & Robinson (2018) Altered decision-making under uncertainty in unmedicated mood and anxiety disorders. PsyArxiv. 10.31234/osf.io/k5b8m
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_lapse_decay( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_lapse_decay( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_lapse_decay( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_lapse_decay( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 4-Armed Bandit Task using 4 Parameter Model, without C (choice perseveration) but with xi (noise). Single learning rate both for R and P..
It has the following parameters: A
(learning rate), R
(reward sensitivity), P
(punishment sensitivity), xi
(noise).
Task: 4-Armed Bandit Task
Model: 4 Parameter Model, without C (choice perseveration) but with xi (noise). Single learning rate both for R and P. (Aylward et al., 2018)
bandit4arm_singleA_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit4arm_singleA_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 4-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, or 4.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit4arm_singleA_lapse").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Aylward, Valton, Ahn, Bond, Dayan, Roiser, & Robinson (2018) Altered decision-making under uncertainty in unmedicated mood and anxiety disorders. PsyArxiv. 10.31234/osf.io/k5b8m
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_singleA_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_singleA_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit4arm_singleA_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm_singleA_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the 4-Armed Bandit Task (modified) using Kalman Filter.
It has the following parameters: lambda
(decay factor), theta
(decay center), beta
(inverse softmax temperature), mu0
(anticipated initial mean of all 4 options), s0
(anticipated initial sd (uncertainty factor) of all 4 options), sD
(sd of diffusion noise).
Task: 4-Armed Bandit Task (modified)
Model: Kalman Filter (Daw et al., 2006)
bandit4arm2_kalman_filter( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bandit4arm2_kalman_filter( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 4-Armed Bandit Task (modified), there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, or 4.
Integer value representing the outcome of the given trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Yoonseo Zoh <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bandit4arm2_kalman_filter").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Daw, N. D., O'Doherty, J. P., Dayan, P., Seymour, B., & Dolan, R. J. (2006). Cortical substrates for exploratory decisions in humans. Nature, 441(7095), 876-879.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bandit4arm2_kalman_filter( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm2_kalman_filter( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bandit4arm2_kalman_filter( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bandit4arm2_kalman_filter( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task using 3 Parameter Model, without C (choice perseveration), R (reward sensitivity), and P (punishment sensitivity). But with xi (noise).
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), xi
(noise).
Task: N-Armed Bandit Task
Model: 3 Parameter Model, without C (choice perseveration), R (reward sensitivity), and P (punishment sensitivity). But with xi (noise) (Aylward et al., 2018)
banditNarm_2par_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_2par_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_2par_lapse").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Aylward, Valton, Ahn, Bond, Dayan, Roiser, & Robinson (2018) Altered decision-making under uncertainty in unmedicated mood and anxiety disorders. PsyArxiv. 10.31234/osf.io/k5b8m
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_2par_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_2par_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_2par_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_2par_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task using 4 Parameter Model, without C (choice perseveration).
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), R
(reward sensitivity), P
(punishment sensitivity).
Task: N-Armed Bandit Task
Model: 4 Parameter Model, without C (choice perseveration) (Seymour et al., 2012)
banditNarm_4par( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_4par( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_4par").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Seymour, Daw, Roiser, Dayan, & Dolan (2012). Serotonin Selectively Modulates Reward Value in Human Decision-Making. J Neuro, 32(17), 5833-5842.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_4par( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_4par( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_4par( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_4par( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task using Rescorla-Wagner (Delta) Model.
It has the following parameters: A
(learning rate), tau
(inverse temperature).
Task: N-Armed Bandit Task (Erev et al., 2010; Hertwig et al., 2004)
Model: Rescorla-Wagner (Delta) Model
banditNarm_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_delta").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Erev, I., Ert, E., Roth, A. E., Haruvy, E., Herzog, S. M., Hau, R., et al. (2010). A choice prediction competition: Choices from experience and from description. Journal of Behavioral Decision Making, 23(1), 15-47. https://doi.org/10.1002/bdm.683
Hertwig, R., Barron, G., Weber, E. U., & Erev, I. (2004). Decisions From Experience and the Effect of Rare Events in Risky Choice. Psychological Science, 15(8), 534-539. https://doi.org/10.1111/j.0956-7976.2004.00715.x
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task (modified) using Kalman Filter.
It has the following parameters: lambda
(decay factor), theta
(decay center), beta
(inverse softmax temperature), mu0
(anticipated initial mean of all 4 options), s0
(anticipated initial sd (uncertainty factor) of all 4 options), sD
(sd of diffusion noise).
Task: N-Armed Bandit Task (modified)
Model: Kalman Filter (Daw et al., 2006)
banditNarm_kalman_filter( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_kalman_filter( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task (modified), there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Yoonseo Zoh <[email protected]>, Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_kalman_filter").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Daw, N. D., O'Doherty, J. P., Dayan, P., Seymour, B., & Dolan, R. J. (2006). Cortical substrates for exploratory decisions in humans. Nature, 441(7095), 876-879.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_kalman_filter( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_kalman_filter( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_kalman_filter( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_kalman_filter( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task using 5 Parameter Model, without C (choice perseveration) but with xi (noise).
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), R
(reward sensitivity), P
(punishment sensitivity), xi
(noise).
Task: N-Armed Bandit Task
Model: 5 Parameter Model, without C (choice perseveration) but with xi (noise) (Seymour et al., 2012)
banditNarm_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_lapse").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Seymour, Daw, Roiser, Dayan, & Dolan (2012). Serotonin Selectively Modulates Reward Value in Human Decision-Making. J Neuro, 32(17), 5833-5842.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task using 5 Parameter Model, without C (choice perseveration) but with xi (noise). Added decay rate (Niv et al., 2015, J. Neuro)..
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), R
(reward sensitivity), P
(punishment sensitivity), xi
(noise), d
(decay rate).
Task: N-Armed Bandit Task
Model: 5 Parameter Model, without C (choice perseveration) but with xi (noise). Added decay rate (Niv et al., 2015, J. Neuro). (Aylward et al., 2018)
banditNarm_lapse_decay( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_lapse_decay( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_lapse_decay").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Aylward, Valton, Ahn, Bond, Dayan, Roiser, & Robinson (2018) Altered decision-making under uncertainty in unmedicated mood and anxiety disorders. PsyArxiv. 10.31234/osf.io/k5b8m
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_lapse_decay( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_lapse_decay( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_lapse_decay( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_lapse_decay( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the N-Armed Bandit Task using 4 Parameter Model, without C (choice perseveration) but with xi (noise). Single learning rate both for R and P..
It has the following parameters: A
(learning rate), R
(reward sensitivity), P
(punishment sensitivity), xi
(noise).
Task: N-Armed Bandit Task
Model: 4 Parameter Model, without C (choice perseveration) but with xi (noise). Single learning rate both for R and P. (Aylward et al., 2018)
banditNarm_singleA_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
banditNarm_singleA_lapse( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the N-Armed Bandit Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on the given trial: 1, 2, 3, ... N.
Floating point value representing the amount of currency won on the given trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on the given trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Cheol Jun Cho <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"banditNarm_singleA_lapse").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Aylward, Valton, Ahn, Bond, Dayan, Roiser, & Robinson (2018) Altered decision-making under uncertainty in unmedicated mood and anxiety disorders. PsyArxiv. 10.31234/osf.io/k5b8m
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- banditNarm_singleA_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_singleA_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- banditNarm_singleA_lapse( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- banditNarm_singleA_lapse( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Balloon Analogue Risk Task using Exponential-Weight Mean-Variance Model.
It has the following parameters: phi
(prior belief of burst), eta
(updating exponent), rho
(risk preference), tau
(inverse temperature), lambda
(loss aversion).
Task: Balloon Analogue Risk Task
Model: Exponential-Weight Mean-Variance Model (Park et al., 2020)
bart_ewmv( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bart_ewmv( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Balloon Analogue Risk Task, there should be 3 columns of data with the
labels "subjID", "pumps", "explosion". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
The number of pumps.
0: intact, 1: burst
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>, Jaeyeong Yang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bart_ewmv").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Park, H., Yang, J., Vassileva, J., & Ahn, W. (2020). The Exponential-Weight Mean-Variance Model: A novel computational model for the Balloon Analogue Risk Task. https://doi.org/10.31234/osf.io/sdzj4
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bart_ewmv( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bart_ewmv( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bart_ewmv( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bart_ewmv( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Balloon Analogue Risk Task using Re-parameterized version of BART model with 4 parameters.
It has the following parameters: phi
(prior belief of balloon not bursting), eta
(updating rate), gam
(risk-taking parameter), tau
(inverse temperature).
Task: Balloon Analogue Risk Task
Model: Re-parameterized version of BART model with 4 parameters (van Ravenzwaaij et al., 2011)
bart_par4( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
bart_par4( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Balloon Analogue Risk Task, there should be 3 columns of data with the
labels "subjID", "pumps", "explosion". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
The number of pumps.
0: intact, 1: burst
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>, Jaeyeong Yang <[email protected]>, Ayoung Lee <[email protected]>, Jeongbin Oh <[email protected]>, Jiyoon Lee <[email protected]>, Junha Jang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"bart_par4").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
van Ravenzwaaij, D., Dutilh, G., & Wagenmakers, E. J. (2011). Cognitive model decomposition of the BART: Assessment and application. Journal of Mathematical Psychology, 55(1), 94-105.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- bart_par4( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bart_par4( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- bart_par4( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- bart_par4( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Cambridge Gambling Task using Cumulative Model.
It has the following parameters: alpha
(probability distortion), c
(color bias), rho
(relative loss sensitivity), beta
(discounting rate), gamma
(choice sensitivity).
Task: Cambridge Gambling Task (Rogers et al., 1999)
Model: Cumulative Model
cgt_cm( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
cgt_cm( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Cambridge Gambling Task, there should be 7 columns of data with the
labels "subjID", "gamble_type", "percentage_staked", "trial_initial_points", "assessment_stage", "red_chosen", "n_red_boxes". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representng whether the bets on the current trial were presented in descending (0) or ascending (1) order.
Integer value representing the bet percentage (not proportion) selected on the current trial: 5, 25, 50, 75, or 95.
Floating point value representing the number of points that the subject has at the start of the current trial (e.g., 100, 150, etc.).
Integer value representing whether the current trial is a practice trial (0) or a test trial (1). Only test trials are used for model fitting.
Integer value representing whether the red color was chosen (1) versus the blue color (0).
Integer value representing the number of red boxes shown on the current trial: 1, 2, 3,..., or 9.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Nathaniel Haines <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"cgt_cm").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Rogers, R. D., Everitt, B. J., Baldacchino, A., Blackshaw, A. J., Swainson, R., Wynne, K., Baker, N. B., Hunter, J., Carthy, T., London, M., Deakin, J. F. W., Sahakian, B. J., Robbins, T. W. (1999). Dissociable deficits in the decision-making cognition of chronic amphetamine abusers, opiate abusers, patients with focal damage to prefrontal cortex, and tryptophan-depleted normal volunteers: evidence for monoaminergic mechanisms. Neuropsychopharmacology, 20, 322–339.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- cgt_cm( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- cgt_cm( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- cgt_cm( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- cgt_cm( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Choice Reaction Time Task using Drift Diffusion Model.
It has the following parameters: alpha
(boundary separation), beta
(bias), delta
(drift rate), tau
(non-decision time).
Task: Choice Reaction Time Task
Model: Drift Diffusion Model (Ratcliff, 1978)
choiceRT_ddm( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
choiceRT_ddm( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Choice Reaction Time Task, there should be 3 columns of data with the
labels "subjID", "choice", "RT". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Choice made for the current trial, coded as 1/2 to indicate lower/upper boundary or left/right choices (e.g., 1 1 1 2 1 2).
Choice reaction time for the current trial, in **seconds** (e.g., 0.435 0.383 0.314 0.309, etc.).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"choiceRT_ddm").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ratcliff, R. (1978). A theory of memory retrieval. Psychological Review, 85(2), 59-108. https://doi.org/10.1037/0033-295X.85.2.59
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- choiceRT_ddm( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- choiceRT_ddm( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- choiceRT_ddm( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- choiceRT_ddm( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Individual Bayesian Modeling of the Choice Reaction Time Task using Drift Diffusion Model.
It has the following parameters: alpha
(boundary separation), beta
(bias), delta
(drift rate), tau
(non-decision time).
Task: Choice Reaction Time Task
Model: Drift Diffusion Model (Ratcliff, 1978)
choiceRT_ddm_single( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
choiceRT_ddm_single( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Choice Reaction Time Task, there should be 3 columns of data with the
labels "subjID", "choice", "RT". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Choice made for the current trial, coded as 1/2 to indicate lower/upper boundary or left/right choices (e.g., 1 1 1 2 1 2).
Choice reaction time for the current trial, in **seconds** (e.g., 0.435 0.383 0.314 0.309, etc.).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"choiceRT_ddm_single").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ratcliff, R. (1978). A theory of memory retrieval. Psychological Review, 85(2), 59-108. https://doi.org/10.1037/0033-295X.85.2.59
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- choiceRT_ddm_single( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- choiceRT_ddm_single( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- choiceRT_ddm_single( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- choiceRT_ddm_single( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Choice Under Risk and Ambiguity Task using Exponential Subjective Value Model.
It has the following parameters: alpha
(risk attitude), beta
(ambiguity attitude), gamma
(inverse temperature).
Task: Choice Under Risk and Ambiguity Task
Model: Exponential Subjective Value Model (Hsu et al., 2005)
cra_exp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
cra_exp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Choice Under Risk and Ambiguity Task, there should be 6 columns of data with the
labels "subjID", "prob", "ambig", "reward_var", "reward_fix", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Objective probability of the variable lottery.
Ambiguity level of the variable lottery (0 for risky lottery; greater than 0 for ambiguous lottery).
Amount of reward in variable lottery. Assumed to be greater than zero.
Amount of reward in fixed lottery. Assumed to be greater than zero.
If the variable lottery was selected, choice == 1; otherwise choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"cra_exp").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Hsu, M., Bhatt, M., Adolphs, R., Tranel, D., & Camerer, C. F. (2005). Neural systems responding to degrees of uncertainty in human decision-making. Science, 310(5754), 1680-1683. https://doi.org/10.1126/science.1115327
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- cra_exp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- cra_exp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- cra_exp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- cra_exp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Choice Under Risk and Ambiguity Task using Linear Subjective Value Model.
It has the following parameters: alpha
(risk attitude), beta
(ambiguity attitude), gamma
(inverse temperature).
Task: Choice Under Risk and Ambiguity Task
Model: Linear Subjective Value Model (Levy et al., 2010)
cra_linear( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
cra_linear( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Choice Under Risk and Ambiguity Task, there should be 6 columns of data with the
labels "subjID", "prob", "ambig", "reward_var", "reward_fix", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Objective probability of the variable lottery.
Ambiguity level of the variable lottery (0 for risky lottery; greater than 0 for ambiguous lottery).
Amount of reward in variable lottery. Assumed to be greater than zero.
Amount of reward in fixed lottery. Assumed to be greater than zero.
If the variable lottery was selected, choice == 1; otherwise choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"cra_linear").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Levy, I., Snell, J., Nelson, A. J., Rustichini, A., & Glimcher, P. W. (2010). Neural representation of subjective value under risk and ambiguity. Journal of Neurophysiology, 103(2), 1036-1047.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- cra_linear( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- cra_linear( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- cra_linear( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- cra_linear( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Description Based Decison Making Task using Probability Weight Function.
It has the following parameters: tau
(probability weight function), rho
(subject utility function), lambda
(loss aversion parameter), beta
(inverse softmax temperature).
Task: Description Based Decison Making Task
Model: Probability Weight Function (Erev et al., 2010; Hertwig et al., 2004; Jessup et al., 2008)
dbdm_prob_weight( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
dbdm_prob_weight( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Description Based Decison Making Task, there should be 8 columns of data with the
labels "subjID", "opt1hprob", "opt2hprob", "opt1hval", "opt1lval", "opt2hval", "opt2lval", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Possiblity of getting higher value of outcome(opt1hval) when choosing option 1.
Possiblity of getting higher value of outcome(opt2hval) when choosing option 2.
Possible (with opt1hprob probability) outcome of option 1.
Possible (with (1 - opt1hprob) probability) outcome of option 1.
Possible (with opt2hprob probability) outcome of option 2.
Possible (with (1 - opt2hprob) probability) outcome of option 2.
If option 1 was selected, choice == 1; else if option 2 was selected, choice == 2.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Yoonseo Zoh <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"dbdm_prob_weight").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Erev, I., Ert, E., Roth, A. E., Haruvy, E., Herzog, S. M., Hau, R., ... & Lebiere, C. (2010). A choice prediction competition: Choices from experience and from description. Journal of Behavioral Decision Making, 23(1), 15-47.
Hertwig, R., Barron, G., Weber, E. U., & Erev, I. (2004). Decisions from experience and the effect of rare events in risky choice. Psychological science, 15(8), 534-539.
Jessup, R. K., Bishara, A. J., & Busemeyer, J. R. (2008). Feedback produces divergence from prospect theory in descriptive choice. Psychological Science, 19(10), 1015-1022.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- dbdm_prob_weight( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dbdm_prob_weight( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- dbdm_prob_weight( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dbdm_prob_weight( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Delay Discounting Task using Constant-Sensitivity (CS) Model.
It has the following parameters: r
(exponential discounting rate), s
(impatience), beta
(inverse temperature).
Task: Delay Discounting Task
Model: Constant-Sensitivity (CS) Model (Ebert et al., 2007)
dd_cs( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
dd_cs( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Delay Discounting Task, there should be 6 columns of data with the
labels "subjID", "delay_later", "amount_later", "delay_sooner", "amount_sooner", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
An integer representing the delayed days for the later option (e.g. 1, 6, 28).
A floating point number representing the amount for the later option (e.g. 10.5, 13.4, 30.9).
An integer representing the delayed days for the sooner option (e.g. 0).
A floating point number representing the amount for the sooner option (e.g. 10).
If amount_later was selected, choice == 1; else if amount_sooner was selected, choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"dd_cs").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ebert, J. E. J., & Prelec, D. (2007). The Fragility of Time: Time-Insensitivity and Valuation of the Near and Far Future. Management Science. https://doi.org/10.1287/mnsc.1060.0671
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- dd_cs( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_cs( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- dd_cs( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_cs( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Individual Bayesian Modeling of the Delay Discounting Task using Constant-Sensitivity (CS) Model.
It has the following parameters: r
(exponential discounting rate), s
(impatience), beta
(inverse temperature).
Task: Delay Discounting Task
Model: Constant-Sensitivity (CS) Model (Ebert et al., 2007)
dd_cs_single( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
dd_cs_single( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Delay Discounting Task, there should be 6 columns of data with the
labels "subjID", "delay_later", "amount_later", "delay_sooner", "amount_sooner", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
An integer representing the delayed days for the later option (e.g. 1, 6, 28).
A floating point number representing the amount for the later option (e.g. 10.5, 13.4, 30.9).
An integer representing the delayed days for the sooner option (e.g. 0).
A floating point number representing the amount for the sooner option (e.g. 10).
If amount_later was selected, choice == 1; else if amount_sooner was selected, choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"dd_cs_single").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ebert, J. E. J., & Prelec, D. (2007). The Fragility of Time: Time-Insensitivity and Valuation of the Near and Far Future. Management Science. https://doi.org/10.1287/mnsc.1060.0671
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- dd_cs_single( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_cs_single( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- dd_cs_single( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_cs_single( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Delay Discounting Task using Exponential Model.
It has the following parameters: r
(exponential discounting rate), beta
(inverse temperature).
Task: Delay Discounting Task
Model: Exponential Model (Samuelson, 1937)
dd_exp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
dd_exp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Delay Discounting Task, there should be 6 columns of data with the
labels "subjID", "delay_later", "amount_later", "delay_sooner", "amount_sooner", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
An integer representing the delayed days for the later option (e.g. 1, 6, 28).
A floating point number representing the amount for the later option (e.g. 10.5, 13.4, 30.9).
An integer representing the delayed days for the sooner option (e.g. 0).
A floating point number representing the amount for the sooner option (e.g. 10).
If amount_later was selected, choice == 1; else if amount_sooner was selected, choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"dd_exp").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Samuelson, P. A. (1937). A Note on Measurement of Utility. The Review of Economic Studies, 4(2), 155. https://doi.org/10.2307/2967612
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- dd_exp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_exp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- dd_exp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_exp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Delay Discounting Task using Hyperbolic Model.
It has the following parameters: k
(discounting rate), beta
(inverse temperature).
Task: Delay Discounting Task
Model: Hyperbolic Model (Mazur, 1987)
dd_hyperbolic( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
dd_hyperbolic( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Delay Discounting Task, there should be 6 columns of data with the
labels "subjID", "delay_later", "amount_later", "delay_sooner", "amount_sooner", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
An integer representing the delayed days for the later option (e.g. 1, 6, 28).
A floating point number representing the amount for the later option (e.g. 10.5, 13.4, 30.9).
An integer representing the delayed days for the sooner option (e.g. 0).
A floating point number representing the amount for the sooner option (e.g. 10).
If amount_later was selected, choice == 1; else if amount_sooner was selected, choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"dd_hyperbolic").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Mazur, J. E. (1987). An adjustment procedure for studying delayed reinforcement.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- dd_hyperbolic( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_hyperbolic( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- dd_hyperbolic( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_hyperbolic( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Individual Bayesian Modeling of the Delay Discounting Task using Hyperbolic Model.
It has the following parameters: k
(discounting rate), beta
(inverse temperature).
Task: Delay Discounting Task
Model: Hyperbolic Model (Mazur, 1987)
dd_hyperbolic_single( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
dd_hyperbolic_single( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Delay Discounting Task, there should be 6 columns of data with the
labels "subjID", "delay_later", "amount_later", "delay_sooner", "amount_sooner", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
An integer representing the delayed days for the later option (e.g. 1, 6, 28).
A floating point number representing the amount for the later option (e.g. 10.5, 13.4, 30.9).
An integer representing the delayed days for the sooner option (e.g. 0).
A floating point number representing the amount for the sooner option (e.g. 10).
If amount_later was selected, choice == 1; else if amount_sooner was selected, choice == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"dd_hyperbolic_single").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Mazur, J. E. (1987). An adjustment procedure for studying delayed reinforcement.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- dd_hyperbolic_single( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_hyperbolic_single( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- dd_hyperbolic_single( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- dd_hyperbolic_single( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Based on codes from 'http://stackoverflow.com/questions/2547402/is-there-a-built-in-function-for-finding-the-mode' see the comment by Rasmus Baath
estimate_mode(x)
estimate_mode(x)
x |
MCMC samples or some numeric or array values. |
Extract Model Comparison Estimates
extract_ic(model_data = NULL, ic = "looic", ncore = 2)
extract_ic(model_data = NULL, ic = "looic", ncore = 2)
model_data |
Object returned by |
ic |
Information Criterion. 'looic', 'waic', or 'both' |
ncore |
Number of cores to use when computing LOOIC |
IC Leave-One-Out and/or Watanabe-Akaike information criterion estimates.
## Not run: library(hBayesDM) output = bandit2arm_delta("example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 1) # To show the LOOIC model fit estimates (a detailed report; c) extract_ic(output) # To show the WAIC model fit estimates extract_ic(output, ic = "waic") ## End(Not run)
## Not run: library(hBayesDM) output = bandit2arm_delta("example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 1) # To show the LOOIC model fit estimates (a detailed report; c) extract_ic(output) # To show the WAIC model fit estimates extract_ic(output, ic = "waic") ## End(Not run)
Hierarchical Bayesian Modeling of the Orthogonalized Go/Nogo Task using RW + noise.
It has the following parameters: xi
(noise), ep
(learning rate), rho
(effective size).
Task: Orthogonalized Go/Nogo Task
Model: RW + noise (Guitart-Masip et al., 2012)
gng_m1( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
gng_m1( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Orthogonalized Go/Nogo Task, there should be 4 columns of data with the
labels "subjID", "cue", "keyPressed", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Nominal integer representing the cue shown for that trial: 1, 2, 3, or 4.
Binary value representing the subject's response for that trial (where Press == 1; No press == 0).
Ternary value representing the outcome of that trial (where Positive feedback == 1; Neutral feedback == 0; Negative feedback == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"gng_m1").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Guitart-Masip, M., Huys, Q. J. M., Fuentemilla, L., Dayan, P., Duzel, E., & Dolan, R. J. (2012). Go and no-go learning in reward and punishment: Interactions between affect and effect. Neuroimage, 62(1), 154-166. https://doi.org/10.1016/j.neuroimage.2012.04.024
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- gng_m1( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m1( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- gng_m1( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m1( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Orthogonalized Go/Nogo Task using RW + noise + bias.
It has the following parameters: xi
(noise), ep
(learning rate), b
(action bias), rho
(effective size).
Task: Orthogonalized Go/Nogo Task
Model: RW + noise + bias (Guitart-Masip et al., 2012)
gng_m2( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
gng_m2( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Orthogonalized Go/Nogo Task, there should be 4 columns of data with the
labels "subjID", "cue", "keyPressed", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Nominal integer representing the cue shown for that trial: 1, 2, 3, or 4.
Binary value representing the subject's response for that trial (where Press == 1; No press == 0).
Ternary value representing the outcome of that trial (where Positive feedback == 1; Neutral feedback == 0; Negative feedback == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"gng_m2").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Guitart-Masip, M., Huys, Q. J. M., Fuentemilla, L., Dayan, P., Duzel, E., & Dolan, R. J. (2012). Go and no-go learning in reward and punishment: Interactions between affect and effect. Neuroimage, 62(1), 154-166. https://doi.org/10.1016/j.neuroimage.2012.04.024
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- gng_m2( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m2( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- gng_m2( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m2( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Orthogonalized Go/Nogo Task using RW + noise + bias + pi.
It has the following parameters: xi
(noise), ep
(learning rate), b
(action bias), pi
(Pavlovian bias), rho
(effective size).
Task: Orthogonalized Go/Nogo Task
Model: RW + noise + bias + pi (Guitart-Masip et al., 2012)
gng_m3( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
gng_m3( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Orthogonalized Go/Nogo Task, there should be 4 columns of data with the
labels "subjID", "cue", "keyPressed", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Nominal integer representing the cue shown for that trial: 1, 2, 3, or 4.
Binary value representing the subject's response for that trial (where Press == 1; No press == 0).
Ternary value representing the outcome of that trial (where Positive feedback == 1; Neutral feedback == 0; Negative feedback == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"gng_m3").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Guitart-Masip, M., Huys, Q. J. M., Fuentemilla, L., Dayan, P., Duzel, E., & Dolan, R. J. (2012). Go and no-go learning in reward and punishment: Interactions between affect and effect. Neuroimage, 62(1), 154-166. https://doi.org/10.1016/j.neuroimage.2012.04.024
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- gng_m3( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m3( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- gng_m3( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m3( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Orthogonalized Go/Nogo Task using RW (rew/pun) + noise + bias + pi.
It has the following parameters: xi
(noise), ep
(learning rate), b
(action bias), pi
(Pavlovian bias), rhoRew
(reward sensitivity), rhoPun
(punishment sensitivity).
Task: Orthogonalized Go/Nogo Task
Model: RW (rew/pun) + noise + bias + pi (Cavanagh et al., 2013)
gng_m4( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
gng_m4( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Orthogonalized Go/Nogo Task, there should be 4 columns of data with the
labels "subjID", "cue", "keyPressed", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Nominal integer representing the cue shown for that trial: 1, 2, 3, or 4.
Binary value representing the subject's response for that trial (where Press == 1; No press == 0).
Ternary value representing the outcome of that trial (where Positive feedback == 1; Neutral feedback == 0; Negative feedback == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"gng_m4").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Cavanagh, J. F., Eisenberg, I., Guitart-Masip, M., Huys, Q., & Frank, M. J. (2013). Frontal Theta Overrides Pavlovian Learning Biases. Journal of Neuroscience, 33(19), 8541-8548. https://doi.org/10.1523/JNEUROSCI.5754-12.2013
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- gng_m4( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m4( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- gng_m4( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- gng_m4( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Computes the highest density interval from a sample of representative values, estimated as shortest credible interval. Based on John Kruschke's codes.
HDIofMCMC(sampleVec, credMass = 0.95)
HDIofMCMC(sampleVec, credMass = 0.95)
sampleVec |
A vector of representative values from a probability distribution (e.g., MCMC samples). |
credMass |
A scalar between 0 and 1, indicating the mass within the credible interval that is to be estimated. |
A vector containing the limits of the HDI
Hierarchical Bayesian Modeling of the Iowa Gambling Task using Outcome-Representation Learning Model.
It has the following parameters: Arew
(reward learning rate), Apun
(punishment learning rate), K
(perseverance decay), betaF
(outcome frequency weight), betaP
(perseverance weight).
Task: Iowa Gambling Task (Ahn et al., 2008)
Model: Outcome-Representation Learning Model (Haines et al., 2018)
igt_orl( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
igt_orl( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Iowa Gambling Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer indicating which deck was chosen on that trial (where A==1, B==2, C==3, and D==4).
Floating point value representing the amount of currency won on that trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on that trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Nate Haines <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"igt_orl").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ahn, W. Y., Busemeyer, J. R., & Wagenmakers, E. J. (2008). Comparison of decision learning models using the generalization criterion method. Cognitive Science, 32(8), 1376-1402. https://doi.org/10.1080/03640210802352992
Haines, N., Vassileva, J., & Ahn, W.-Y. (2018). The Outcome-Representation Learning Model: A Novel Reinforcement Learning Model of the Iowa Gambling Task. Cognitive Science. https://doi.org/10.1111/cogs.12688
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- igt_orl( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_orl( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- igt_orl( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_orl( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Iowa Gambling Task using Prospect Valence Learning (PVL) Decay-RI.
It has the following parameters: A
(decay rate), alpha
(outcome sensitivity), cons
(response consistency), lambda
(loss aversion).
Task: Iowa Gambling Task (Ahn et al., 2008)
Model: Prospect Valence Learning (PVL) Decay-RI (Ahn et al., 2014)
igt_pvl_decay( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
igt_pvl_decay( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Iowa Gambling Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer indicating which deck was chosen on that trial (where A==1, B==2, C==3, and D==4).
Floating point value representing the amount of currency won on that trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on that trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"igt_pvl_decay").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ahn, W. Y., Busemeyer, J. R., & Wagenmakers, E. J. (2008). Comparison of decision learning models using the generalization criterion method. Cognitive Science, 32(8), 1376-1402. https://doi.org/10.1080/03640210802352992
Ahn, W.-Y., Vasilev, G., Lee, S.-H., Busemeyer, J. R., Kruschke, J. K., Bechara, A., & Vassileva, J. (2014). Decision-making in stimulant and opiate addicts in protracted abstinence: evidence from computational modeling with pure users. Frontiers in Psychology, 5, 1376. https://doi.org/10.3389/fpsyg.2014.00849
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- igt_pvl_decay( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_pvl_decay( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- igt_pvl_decay( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_pvl_decay( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Iowa Gambling Task using Prospect Valence Learning (PVL) Delta.
It has the following parameters: A
(learning rate), alpha
(outcome sensitivity), cons
(response consistency), lambda
(loss aversion).
Task: Iowa Gambling Task (Ahn et al., 2008)
Model: Prospect Valence Learning (PVL) Delta (Ahn et al., 2008)
igt_pvl_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
igt_pvl_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Iowa Gambling Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer indicating which deck was chosen on that trial (where A==1, B==2, C==3, and D==4).
Floating point value representing the amount of currency won on that trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on that trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"igt_pvl_delta").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ahn, W. Y., Busemeyer, J. R., & Wagenmakers, E. J. (2008). Comparison of decision learning models using the generalization criterion method. Cognitive Science, 32(8), 1376-1402. https://doi.org/10.1080/03640210802352992
Ahn, W. Y., Busemeyer, J. R., & Wagenmakers, E. J. (2008). Comparison of decision learning models using the generalization criterion method. Cognitive Science, 32(8), 1376-1402. https://doi.org/10.1080/03640210802352992
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- igt_pvl_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_pvl_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- igt_pvl_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_pvl_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Iowa Gambling Task using Value-Plus-Perseverance.
It has the following parameters: A
(learning rate), alpha
(outcome sensitivity), cons
(response consistency), lambda
(loss aversion), epP
(gain impact), epN
(loss impact), K
(decay rate), w
(RL weight).
Task: Iowa Gambling Task (Ahn et al., 2008)
Model: Value-Plus-Perseverance (Worthy et al., 2013)
igt_vpp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
igt_vpp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Iowa Gambling Task, there should be 4 columns of data with the
labels "subjID", "choice", "gain", "loss". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer indicating which deck was chosen on that trial (where A==1, B==2, C==3, and D==4).
Floating point value representing the amount of currency won on that trial (e.g. 50, 100).
Floating point value representing the amount of currency lost on that trial (e.g. 0, -50).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"igt_vpp").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ahn, W. Y., Busemeyer, J. R., & Wagenmakers, E. J. (2008). Comparison of decision learning models using the generalization criterion method. Cognitive Science, 32(8), 1376-1402. https://doi.org/10.1080/03640210802352992
Worthy, D. A., & Todd Maddox, W. (2013). A comparison model of reinforcement-learning and win-stay-lose-shift decision-making processes: A tribute to W.K. Estes. Journal of Mathematical Psychology, 59, 41-49. https://doi.org/10.1016/j.jmp.2013.10.001
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- igt_vpp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_vpp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- igt_vpp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- igt_vpp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Plots multiple figures Based on codes from 'http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/'
multiplot(..., plots = NULL, cols = NULL)
multiplot(..., plots = NULL, cols = NULL)
... |
Plot objects |
plots |
List containing plot objects |
cols |
Number of columns within the multi-figure plot |
Hierarchical Bayesian Modeling of the Peer Influence Task using Other-Conferred Utility (OCU) Model.
It has the following parameters: rho
(risk preference), tau
(inverse temperature), ocu
(other-conferred utility).
Task: Peer Influence Task (Chung et al., 2015)
Model: Other-Conferred Utility (OCU) Model
peer_ocu( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
peer_ocu( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Peer Influence Task, there should be 8 columns of data with the
labels "subjID", "condition", "p_gamble", "safe_Hpayoff", "safe_Lpayoff", "risky_Hpayoff", "risky_Lpayoff", "choice". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
0: solo, 1: info (safe/safe), 2: info (mix), 3: info (risky/risky).
Probability of receiving a high payoff (same for both options).
High payoff of the safe option.
Low payoff of the safe option.
High payoff of the risky option.
Low payoff of the risky option.
Which option was chosen? 0: safe, 1: risky.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"peer_ocu").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Chung, D., Christopoulos, G. I., King-Casas, B., Ball, S. B., & Chiu, P. H. (2015). Social signals of safety and risk confer utility and have asymmetric effects on observers' choices. Nature Neuroscience, 18(6), 912-916.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- peer_ocu( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- peer_ocu( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- peer_ocu( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- peer_ocu( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Plots the histogram of MCMC samples.
plotDist( sample = NULL, Title = NULL, xLab = "Value", yLab = "Density", xLim = NULL, fontSize = NULL, binSize = NULL, ... )
plotDist( sample = NULL, Title = NULL, xLab = "Value", yLab = "Density", xLim = NULL, fontSize = NULL, binSize = NULL, ... )
sample |
MCMC samples |
Title |
Character value containing the main title for the plot |
xLab |
Character value containing the x label |
yLab |
Character value containing the y label |
xLim |
Vector containing the lower and upper x-bounds of the plot |
fontSize |
Size of the font to use for plotting. Defaults to 10 |
binSize |
Size of the bins for creating the histogram. Defaults to 30 |
... |
Arguments that can be additionally supplied to geom_histogram |
h1 Plot object
Plots highest density interval (HDI) from (MCMC) samples and prints HDI in the R console. HDI is indicated by a red line. Based on John Kruschke's codes.
plotHDI( sample = NULL, credMass = 0.95, Title = NULL, xLab = "Value", yLab = "Density", fontSize = NULL, binSize = 30, ... )
plotHDI( sample = NULL, credMass = 0.95, Title = NULL, xLab = "Value", yLab = "Density", fontSize = NULL, binSize = 30, ... )
sample |
MCMC samples |
credMass |
A scalar between 0 and 1, indicating the mass within the credible interval that is to be estimated. |
Title |
Character value containing the main title for the plot |
xLab |
Character value containing the x label |
yLab |
Character value containing the y label |
fontSize |
Integer value specifying the font size to be used for the plot labels |
binSize |
Integer value specifyin ghow wide the bars on the histogram should be. Defaults to 30. |
... |
Arguments that can be additionally supplied to geom_histogram |
A vector containing the limits of the HDI
Plots individual posterior distributions, using the stan_plot function of the rstan package
plotInd(obj = NULL, pars, show_density = T, ...)
plotInd(obj = NULL, pars, show_density = T, ...)
obj |
An output of the hBayesDM. Its class should be 'hBayesDM'. |
pars |
(from stan_plot's help file) Character vector of parameter names. If unspecified, show all user-defined parameters or the first 10 (if there are more than 10) |
show_density |
T(rue) or F(alse). Show the density (T) or not (F)? |
... |
(from stan_plot's help file) Optional additional named arguments passed to stan_plot, which will be passed to geoms. See stan_plot's help file. |
## Not run: # Run a model output <- dd_hyperbolic("example", 2000, 1000, 3, 3) # Plot the hyper parameters ('k' and 'beta') plot(output) # Plot individual 'k' (discounting rate) parameters plotInd(output, "k") # Plot individual 'beta' (inverse temperature) parameters plotInd(output, "beta") # Plot individual 'beta' parameters but don't show density plotInd(output, "beta", show_density = F) ## End(Not run)
## Not run: # Run a model output <- dd_hyperbolic("example", 2000, 1000, 3, 3) # Plot the hyper parameters ('k' and 'beta') plot(output) # Plot individual 'k' (discounting rate) parameters plotInd(output, "k") # Plot individual 'beta' (inverse temperature) parameters plotInd(output, "beta") # Plot individual 'beta' parameters but don't show density plotInd(output, "beta", show_density = F) ## End(Not run)
Print model-fits (mean LOOIC or WAIC values in addition to Akaike weights) of hBayesDM Models
printFit(..., ic = "looic", ncore = 2, roundTo = 3)
printFit(..., ic = "looic", ncore = 2, roundTo = 3)
... |
Model objects output by hBayesDM functions (e.g. output1, output2, etc.) |
ic |
Which model comparison information criterion to use? 'looic', 'waic', or 'both |
ncore |
Number of corse to use when computing LOOIC |
roundTo |
Number of digits to the right of the decimal point in the output |
modelTable A table with relevant model comparison data. LOOIC and WAIC weights are computed as Akaike weights.
## Not run: # Run two models and store results in "output1" and "output2" output1 <- dd_hyperbolic("example", 2000, 1000, 3, 3) output2 <- dd_exp("example", 2000, 1000, 3, 3) # Show the LOOIC model fit estimates printFit(output1, output2) # To show the WAIC model fit estimates printFit(output1, output2, ic = "waic") # To show both LOOIC and WAIC printFit(output1, output2, ic = "both") ## End(Not run)
## Not run: # Run two models and store results in "output1" and "output2" output1 <- dd_hyperbolic("example", 2000, 1000, 3, 3) output2 <- dd_exp("example", 2000, 1000, 3, 3) # Show the LOOIC model fit estimates printFit(output1, output2) # To show the WAIC model fit estimates printFit(output1, output2, ic = "waic") # To show both LOOIC and WAIC printFit(output1, output2, ic = "both") ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Experience-Weighted Attraction Model.
It has the following parameters: phi
(1 - learning rate), rho
(experience decay factor), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Experience-Weighted Attraction Model (Ouden et al., 2013)
prl_ewa( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_ewa( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_ewa").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ouden, den, H. E. M., Daw, N. D., Fernandez, G., Elshout, J. A., Rijpkema, M., Hoogman, M., et al. (2013). Dissociable Effects of Dopamine and Serotonin on Reversal Learning. Neuron, 80(4), 1090-1100. https://doi.org/10.1016/j.neuron.2013.08.030
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_ewa( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_ewa( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_ewa( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_ewa( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Fictitious Update Model.
It has the following parameters: eta
(learning rate), alpha
(indecision point), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Fictitious Update Model (Glascher et al., 2009)
prl_fictitious( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_fictitious( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_fictitious").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Glascher, J., Hampton, A. N., & O'Doherty, J. P. (2009). Determining a Role for Ventromedial Prefrontal Cortex in Encoding Action-Based Value Signals During Reward-Related Decision Making. Cerebral Cortex, 19(2), 483-495. https://doi.org/10.1093/cercor/bhn098
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Multiple-Block Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Fictitious Update Model.
It has the following parameters: eta
(learning rate), alpha
(indecision point), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Fictitious Update Model (Glascher et al., 2009)
prl_fictitious_multipleB( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_fictitious_multipleB( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 4 columns of data with the
labels "subjID", "block", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
A unique identifier for each of the multiple blocks within each subject.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_fictitious_multipleB").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Glascher, J., Hampton, A. N., & O'Doherty, J. P. (2009). Determining a Role for Ventromedial Prefrontal Cortex in Encoding Action-Based Value Signals During Reward-Related Decision Making. Cerebral Cortex, 19(2), 483-495. https://doi.org/10.1093/cercor/bhn098
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_multipleB( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_multipleB( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_multipleB( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_multipleB( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Fictitious Update Model, with separate learning rates for positive and negative prediction error (PE).
It has the following parameters: eta_pos
(learning rate, +PE), eta_neg
(learning rate, -PE), alpha
(indecision point), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Fictitious Update Model, with separate learning rates for positive and negative prediction error (PE) (Glascher et al., 2009; Ouden et al., 2013)
prl_fictitious_rp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_fictitious_rp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_fictitious_rp").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Glascher, J., Hampton, A. N., & O'Doherty, J. P. (2009). Determining a Role for Ventromedial Prefrontal Cortex in Encoding Action-Based Value Signals During Reward-Related Decision Making. Cerebral Cortex, 19(2), 483-495. https://doi.org/10.1093/cercor/bhn098
Ouden, den, H. E. M., Daw, N. D., Fernandez, G., Elshout, J. A., Rijpkema, M., Hoogman, M., et al. (2013). Dissociable Effects of Dopamine and Serotonin on Reversal Learning. Neuron, 80(4), 1090-1100. https://doi.org/10.1016/j.neuron.2013.08.030
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_rp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_rp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_rp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_rp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Fictitious Update Model, with separate learning rates for positive and negative prediction error (PE), without alpha (indecision point).
It has the following parameters: eta_pos
(learning rate, +PE), eta_neg
(learning rate, -PE), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Fictitious Update Model, with separate learning rates for positive and negative prediction error (PE), without alpha (indecision point) (Glascher et al., 2009; Ouden et al., 2013)
prl_fictitious_rp_woa( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_fictitious_rp_woa( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_fictitious_rp_woa").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Glascher, J., Hampton, A. N., & O'Doherty, J. P. (2009). Determining a Role for Ventromedial Prefrontal Cortex in Encoding Action-Based Value Signals During Reward-Related Decision Making. Cerebral Cortex, 19(2), 483-495. https://doi.org/10.1093/cercor/bhn098
Ouden, den, H. E. M., Daw, N. D., Fernandez, G., Elshout, J. A., Rijpkema, M., Hoogman, M., et al. (2013). Dissociable Effects of Dopamine and Serotonin on Reversal Learning. Neuron, 80(4), 1090-1100. https://doi.org/10.1016/j.neuron.2013.08.030
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_rp_woa( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_rp_woa( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_rp_woa( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_rp_woa( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Fictitious Update Model, without alpha (indecision point).
It has the following parameters: eta
(learning rate), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Fictitious Update Model, without alpha (indecision point) (Glascher et al., 2009)
prl_fictitious_woa( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_fictitious_woa( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_fictitious_woa").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Glascher, J., Hampton, A. N., & O'Doherty, J. P. (2009). Determining a Role for Ventromedial Prefrontal Cortex in Encoding Action-Based Value Signals During Reward-Related Decision Making. Cerebral Cortex, 19(2), 483-495. https://doi.org/10.1093/cercor/bhn098
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_woa( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_woa( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_fictitious_woa( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_fictitious_woa( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Reward-Punishment Model.
It has the following parameters: Apun
(punishment learning rate), Arew
(reward learning rate), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Reward-Punishment Model (Ouden et al., 2013)
prl_rp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_rp( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_rp").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ouden, den, H. E. M., Daw, N. D., Fernandez, G., Elshout, J. A., Rijpkema, M., Hoogman, M., et al. (2013). Dissociable Effects of Dopamine and Serotonin on Reversal Learning. Neuron, 80(4), 1090-1100. https://doi.org/10.1016/j.neuron.2013.08.030
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_rp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_rp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_rp( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_rp( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Multiple-Block Hierarchical Bayesian Modeling of the Probabilistic Reversal Learning Task using Reward-Punishment Model.
It has the following parameters: Apun
(punishment learning rate), Arew
(reward learning rate), beta
(inverse temperature).
Task: Probabilistic Reversal Learning Task
Model: Reward-Punishment Model (Ouden et al., 2013)
prl_rp_multipleB( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
prl_rp_multipleB( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Reversal Learning Task, there should be 4 columns of data with the
labels "subjID", "block", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
A unique identifier for each of the multiple blocks within each subject.
Integer value representing the option chosen on that trial: 1 or 2.
Integer value representing the outcome of that trial (where reward == 1, and loss == -1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang (for model-based regressors) <[email protected]>, Harhim Park (for model-based regressors) <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"prl_rp_multipleB").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Ouden, den, H. E. M., Daw, N. D., Fernandez, G., Elshout, J. A., Rijpkema, M., Hoogman, M., et al. (2013). Dissociable Effects of Dopamine and Serotonin on Reversal Learning. Neuron, 80(4), 1090-1100. https://doi.org/10.1016/j.neuron.2013.08.030
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- prl_rp_multipleB( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_rp_multipleB( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- prl_rp_multipleB( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- prl_rp_multipleB( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Selection Task using Gain-Loss Q Learning Model.
It has the following parameters: alpha_pos
(learning rate for positive feedbacks), alpha_neg
(learning rate for negative feedbacks), beta
(inverse temperature).
Task: Probabilistic Selection Task
Model: Gain-Loss Q Learning Model (Frank et al., 2007)
pst_gainloss_Q( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
pst_gainloss_Q( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Selection Task, there should be 4 columns of data with the
labels "subjID", "type", "choice", "reward". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Two-digit number indicating which pair of stimuli were presented for that trial, e.g. 12, 34, or 56. The digit on the left (tens-digit) indicates the presented stimulus for option1, while the digit on the right (ones-digit) indicates that for option2. Code for each stimulus type (1~6) is defined as for 80% (type 1), 20% (type 2), 70% (type 3), 30% (type 4), 60% (type 5), 40% (type 6). The modeling will still work even if different probabilities are used for the stimuli; however, the total number of stimuli should be less than or equal to 6.
Whether the subject chose the left option (option1) out of the given two options (i.e. if option1 was chosen, 1; if option2 was chosen, 0).
Amount of reward earned as a result of the trial.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Jaeyeong Yang <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"pst_gainloss_Q").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Frank, M. J., Moustafa, A. A., Haughey, H. M., Curran, T., & Hutchison, K. E. (2007). Genetic triple dissociation reveals multiple roles for dopamine in reinforcement learning. Proceedings of the National Academy of Sciences, 104(41), 16311-16316.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- pst_gainloss_Q( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pst_gainloss_Q( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- pst_gainloss_Q( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pst_gainloss_Q( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Selection Task using Q Learning Model.
It has the following parameters: alpha
(learning rate), beta
(inverse temperature).
Task: Probabilistic Selection Task
Model: Q Learning Model (Frank et al., 2007)
pst_Q( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
pst_Q( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Selection Task, there should be 4 columns of data with the
labels "subjID", "type", "choice", "reward". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Two-digit number indicating which pair of stimuli were presented for that trial, e.g. 12, 34, or 56. The digit on the left (tens-digit) indicates the presented stimulus for option1, while the digit on the right (ones-digit) indicates that for option2. Code for each stimulus type (1~6) is defined as for 80% (type 1), 20% (type 2), 70% (type 3), 30% (type 4), 60% (type 5), 40% (type 6). The modeling will still work even if different probabilities are used for the stimuli; however, the total number of stimuli should be less than or equal to 6.
Whether the subject chose the left option (option1) out of the given two options (i.e. if option1 was chosen, 1; if option2 was chosen, 0).
Amount of reward earned as a result of the trial.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
David Munoz Tord <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"pst_Q").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Frank, M. J., Moustafa, A. A., Haughey, H. M., Curran, T., & Hutchison, K. E. (2007). Genetic triple dissociation reveals multiple roles for dopamine in reinforcement learning. Proceedings of the National Academy of Sciences, 104(41), 16311-16316.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- pst_Q( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pst_Q( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- pst_Q( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pst_Q( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Selection Task (with RT data) using Drift Diffusion Model.
It has the following parameters: a
(boundary separation), tau
(non-decision time), d1
(drift rate scaling), d2
(drift rate scaling), d3
(drift rate scaling).
Task: Probabilistic Selection Task (with RT data) (Frank et al., 2007; Frank et al., 2004)
Model: Drift Diffusion Model (Pedersen et al., 2017)
pstRT_ddm( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
pstRT_ddm( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Selection Task (with RT data), there should be 4 columns of data with the
labels "subjID", "cond", "choice", "RT". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the task condition of the given trial (AB == 1, CD == 2, EF == 3).
Integer value representing the option chosen on the given trial (1 or 2).
Float value representing the time taken for the response on the given trial.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Hoyoung Doh <[email protected]>, Sanghoon Kang <[email protected]>, Jihyun K. Hur <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"pstRT_ddm").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Frank, M. J., Santamaria, A., O'Reilly, R. C., & Willcutt, E. (2007). Testing computational models of dopamine and noradrenaline dysfunction in attention deficit/hyperactivity disorder. Neuropsychopharmacology, 32(7), 1583-1599.
Frank, M. J., Seeberger, L. C., & O'reilly, R. C. (2004). By carrot or by stick: cognitive reinforcement learning in parkinsonism. Science, 306(5703), 1940-1943.
Pedersen, M. L., Frank, M. J., & Biele, G. (2017). The drift diffusion model as the choice rule in reinforcement learning. Psychonomic bulletin & review, 24(4), 1234-1251.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- pstRT_ddm( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pstRT_ddm( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- pstRT_ddm( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pstRT_ddm( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Selection Task (with RT data) using Reinforcement Learning Drift Diffusion Model 1.
It has the following parameters: a
(boundary separation), tau
(non-decision time), v
(drift rate scaling), alpha
(learning rate).
Task: Probabilistic Selection Task (with RT data) (Frank et al., 2007; Frank et al., 2004)
Model: Reinforcement Learning Drift Diffusion Model 1 (Pedersen et al., 2017)
pstRT_rlddm1( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
pstRT_rlddm1( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Selection Task (with RT data), there should be 6 columns of data with the
labels "subjID", "cond", "prob", "choice", "RT", "feedback". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the task condition of the given trial (AB == 1, CD == 2, EF == 3).
Float value representing the probability that a correct response (1) is rewarded in the current task condition.
Integer value representing the option chosen on the given trial (1 or 2).
Float value representing the time taken for the response on the given trial.
Integer value representing the outcome of the given trial (where 'correct' == 1, and 'incorrect' == 0).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Hoyoung Doh <[email protected]>, Sanghoon Kang <[email protected]>, Jihyun K. Hur <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"pstRT_rlddm1").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Frank, M. J., Santamaria, A., O'Reilly, R. C., & Willcutt, E. (2007). Testing computational models of dopamine and noradrenaline dysfunction in attention deficit/hyperactivity disorder. Neuropsychopharmacology, 32(7), 1583-1599.
Frank, M. J., Seeberger, L. C., & O'reilly, R. C. (2004). By carrot or by stick: cognitive reinforcement learning in parkinsonism. Science, 306(5703), 1940-1943.
Pedersen, M. L., Frank, M. J., & Biele, G. (2017). The drift diffusion model as the choice rule in reinforcement learning. Psychonomic bulletin & review, 24(4), 1234-1251.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- pstRT_rlddm1( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pstRT_rlddm1( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- pstRT_rlddm1( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pstRT_rlddm1( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Probabilistic Selection Task (with RT data) using Reinforcement Learning Drift Diffusion Model 6.
It has the following parameters: a
(boundary separation), bp
(boundary separation power), tau
(non-decision time), v
(drift rate scaling), alpha_pos
(learning rate for positive prediction error), alpha_neg
(learning rate for negative prediction error).
Task: Probabilistic Selection Task (with RT data) (Frank et al., 2007; Frank et al., 2004)
Model: Reinforcement Learning Drift Diffusion Model 6 (Pedersen et al., 2017)
pstRT_rlddm6( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
pstRT_rlddm6( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Probabilistic Selection Task (with RT data), there should be 7 columns of data with the
labels "subjID", "iter", "cond", "prob", "choice", "RT", "feedback". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value representing the trial number for each task condition.
Integer value representing the task condition of the given trial (AB == 1, CD == 2, EF == 3).
Float value representing the probability that a correct response (1) is rewarded in the current task condition.
Integer value representing the option chosen on the given trial (1 or 2).
Float value representing the time taken for the response on the given trial.
Integer value representing the outcome of the given trial (where 'correct' == 1, and 'incorrect' == 0).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Hoyoung Doh <[email protected]>, Sanghoon Kang <[email protected]>, Jihyun K. Hur <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"pstRT_rlddm6").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Frank, M. J., Santamaria, A., O'Reilly, R. C., & Willcutt, E. (2007). Testing computational models of dopamine and noradrenaline dysfunction in attention deficit/hyperactivity disorder. Neuropsychopharmacology, 32(7), 1583-1599.
Frank, M. J., Seeberger, L. C., & O'reilly, R. C. (2004). By carrot or by stick: cognitive reinforcement learning in parkinsonism. Science, 306(5703), 1940-1943.
Pedersen, M. L., Frank, M. J., & Biele, G. (2017). The drift diffusion model as the choice rule in reinforcement learning. Psychonomic bulletin & review, 24(4), 1234-1251.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- pstRT_rlddm6( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pstRT_rlddm6( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- pstRT_rlddm6( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- pstRT_rlddm6( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Risk Aversion Task using Prospect Theory, without loss aversion (LA) parameter.
It has the following parameters: rho
(risk aversion), tau
(inverse temperature).
Task: Risk Aversion Task
Model: Prospect Theory, without loss aversion (LA) parameter (Sokol-Hessner et al., 2009)
ra_noLA( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ra_noLA( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Risk Aversion Task, there should be 5 columns of data with the
labels "subjID", "gain", "loss", "cert", "gamble". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Possible (50%) gain outcome of a risky option (e.g. 9).
Possible (50%) loss outcome of a risky option (e.g. 5, or -5).
Guaranteed amount of a safe option. "cert" is assumed to be zero or greater than zero.
If gamble was taken, gamble == 1; else gamble == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ra_noLA").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Sokol-Hessner, P., Hsu, M., Curley, N. G., Delgado, M. R., Camerer, C. F., Phelps, E. A., & Smith, E. E. (2009). Thinking like a Trader Selectively Reduces Individuals' Loss Aversion. Proceedings of the National Academy of Sciences of the United States of America, 106(13), 5035-5040. https://www.pnas.org/content/106/13/5035
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ra_noLA( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ra_noLA( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ra_noLA( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ra_noLA( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Risk Aversion Task using Prospect Theory, without risk aversion (RA) parameter.
It has the following parameters: lambda
(loss aversion), tau
(inverse temperature).
Task: Risk Aversion Task
Model: Prospect Theory, without risk aversion (RA) parameter (Sokol-Hessner et al., 2009)
ra_noRA( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ra_noRA( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Risk Aversion Task, there should be 5 columns of data with the
labels "subjID", "gain", "loss", "cert", "gamble". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Possible (50%) gain outcome of a risky option (e.g. 9).
Possible (50%) loss outcome of a risky option (e.g. 5, or -5).
Guaranteed amount of a safe option. "cert" is assumed to be zero or greater than zero.
If gamble was taken, gamble == 1; else gamble == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ra_noRA").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Sokol-Hessner, P., Hsu, M., Curley, N. G., Delgado, M. R., Camerer, C. F., Phelps, E. A., & Smith, E. E. (2009). Thinking like a Trader Selectively Reduces Individuals' Loss Aversion. Proceedings of the National Academy of Sciences of the United States of America, 106(13), 5035-5040. https://www.pnas.org/content/106/13/5035
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ra_noRA( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ra_noRA( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ra_noRA( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ra_noRA( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Risk Aversion Task using Prospect Theory.
It has the following parameters: rho
(risk aversion), lambda
(loss aversion), tau
(inverse temperature).
Task: Risk Aversion Task
Model: Prospect Theory (Sokol-Hessner et al., 2009)
ra_prospect( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ra_prospect( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Risk Aversion Task, there should be 5 columns of data with the
labels "subjID", "gain", "loss", "cert", "gamble". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Possible (50%) gain outcome of a risky option (e.g. 9).
Possible (50%) loss outcome of a risky option (e.g. 5, or -5).
Guaranteed amount of a safe option. "cert" is assumed to be zero or greater than zero.
If gamble was taken, gamble == 1; else gamble == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ra_prospect").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Sokol-Hessner, P., Hsu, M., Curley, N. G., Delgado, M. R., Camerer, C. F., Phelps, E. A., & Smith, E. E. (2009). Thinking like a Trader Selectively Reduces Individuals' Loss Aversion. Proceedings of the National Academy of Sciences of the United States of America, 106(13), 5035-5040. https://www.pnas.org/content/106/13/5035
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ra_prospect( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ra_prospect( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ra_prospect( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ra_prospect( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Risky Decision Task using Happiness Computational Model.
It has the following parameters: w0
(baseline), w1
(weight of certain rewards), w2
(weight of expected values), w3
(weight of reward prediction errors), gam
(forgetting factor), sig
(standard deviation of error).
Task: Risky Decision Task
Model: Happiness Computational Model (Rutledge et al., 2014)
rdt_happiness( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
rdt_happiness( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Risky Decision Task, there should be 9 columns of data with the
labels "subjID", "gain", "loss", "cert", "type", "gamble", "outcome", "happy", "RT_happy". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Possible (50%) gain outcome of a risky option (e.g. 9).
Possible (50%) loss outcome of a risky option (e.g. 5, or -5).
Guaranteed amount of a safe option.
loss == -1, mixed == 0, gain == 1
If gamble was taken, gamble == 1; else gamble == 0.
Result of the trial.
Happiness score.
Reaction time for answering the happiness score.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"rdt_happiness").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Rutledge, R. B., Skandali, N., Dayan, P., & Dolan, R. J. (2014). A computational and neural model of momentary subjective well-being. Proceedings of the National Academy of Sciences, 111(33), 12252-12257.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- rdt_happiness( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- rdt_happiness( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- rdt_happiness( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- rdt_happiness( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
A convenience function for extracting Rhat values from an hBayesDM object. Can also check if all Rhat values are less than or equal to a specified value. If variational inference was used, an error message will be displayed.
rhat(fit = NULL, less = NULL)
rhat(fit = NULL, less = NULL)
fit |
Model output of class |
less |
A numeric value specifying how to check Rhat values. Defaults to FALSE. |
If 'less'
is specified, then rhat(fit, less)
will return TRUE
if all Rhat values are
less than or equal to 'less'
. If any values are greater than 'less'
, rhat(fit, less)
will
return FALSE
. If 'less'
is left unspecified (NULL), rhat(fit)
will return a data.frame
object
containing all Rhat values.
Hierarchical Bayesian Modeling of the 2-alternative forced choice task using Signal detection theory model.
It has the following parameters: d
(discriminability), c
(decision bias (criteria)).
Task: 2-alternative forced choice task
Model: Signal detection theory model
task2AFC_sdt( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
task2AFC_sdt( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the 2-alternative forced choice task, there should be 3 columns of data with the
labels "subjID", "stimulus", "response". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Types of Stimuli (Should be 1 or 0. 1 for Signal and 0 for Noise)
Types of Responses (It should be same format as the stimulus field. Should be 1 or 0)
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Heesun Park <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"task2AFC_sdt").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- task2AFC_sdt( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- task2AFC_sdt( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- task2AFC_sdt( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- task2AFC_sdt( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Two-Step Task using Hybrid Model, with 4 parameters.
It has the following parameters: a
(learning rate for both stages 1 & 2), beta
(inverse temperature for both stages 1 & 2), pi
(perseverance), w
(model-based weight).
Task: Two-Step Task (Daw et al., 2011)
Model: Hybrid Model, with 4 parameters (Daw et al., 2011; Wunderlich et al., 2012)
ts_par4( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ts_par4( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Two-Step Task, there should be 4 columns of data with the
labels "subjID", "level1_choice", "level2_choice", "reward". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Choice made for Level (Stage) 1 (1: stimulus 1, 2: stimulus 2).
Choice made for Level (Stage) 2 (1: stimulus 3, 2: stimulus 4, 3: stimulus 5, 4: stimulus 6).
Note that, in our notation, choosing stimulus 1 in Level 1 leads to stimulus 3 & 4 in Level 2 with a common (0.7 by default) transition. Similarly, choosing stimulus 2 in Level 1 leads to stimulus 5 & 6 in Level 2 with a common (0.7 by default) transition. To change this default transition probability, set the function argument 'trans_prob' to your preferred value.
Reward after Level 2 (0 or 1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ts_par4").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Daw, N. D., Gershman, S. J., Seymour, B., Ben Seymour, Dayan, P., & Dolan, R. J. (2011). Model-Based Influences on Humans' Choices and Striatal Prediction Errors. Neuron, 69(6), 1204-1215. https://doi.org/10.1016/j.neuron.2011.02.027
Daw, N. D., Gershman, S. J., Seymour, B., Ben Seymour, Dayan, P., & Dolan, R. J. (2011). Model-Based Influences on Humans' Choices and Striatal Prediction Errors. Neuron, 69(6), 1204-1215. https://doi.org/10.1016/j.neuron.2011.02.027
Wunderlich, K., Smittenaar, P., & Dolan, R. J. (2012). Dopamine enhances model-based over model-free choice behavior. Neuron, 75(3), 418-424.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ts_par4( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ts_par4( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ts_par4( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ts_par4( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Two-Step Task using Hybrid Model, with 6 parameters.
It has the following parameters: a1
(learning rate in stage 1), beta1
(inverse temperature in stage 1), a2
(learning rate in stage 2), beta2
(inverse temperature in stage 2), pi
(perseverance), w
(model-based weight).
Task: Two-Step Task (Daw et al., 2011)
Model: Hybrid Model, with 6 parameters (Daw et al., 2011)
ts_par6( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ts_par6( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Two-Step Task, there should be 4 columns of data with the
labels "subjID", "level1_choice", "level2_choice", "reward". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Choice made for Level (Stage) 1 (1: stimulus 1, 2: stimulus 2).
Choice made for Level (Stage) 2 (1: stimulus 3, 2: stimulus 4, 3: stimulus 5, 4: stimulus 6).
Note that, in our notation, choosing stimulus 1 in Level 1 leads to stimulus 3 & 4 in Level 2 with a common (0.7 by default) transition. Similarly, choosing stimulus 2 in Level 1 leads to stimulus 5 & 6 in Level 2 with a common (0.7 by default) transition. To change this default transition probability, set the function argument 'trans_prob' to your preferred value.
Reward after Level 2 (0 or 1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ts_par6").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Daw, N. D., Gershman, S. J., Seymour, B., Ben Seymour, Dayan, P., & Dolan, R. J. (2011). Model-Based Influences on Humans' Choices and Striatal Prediction Errors. Neuron, 69(6), 1204-1215. https://doi.org/10.1016/j.neuron.2011.02.027
Daw, N. D., Gershman, S. J., Seymour, B., Ben Seymour, Dayan, P., & Dolan, R. J. (2011). Model-Based Influences on Humans' Choices and Striatal Prediction Errors. Neuron, 69(6), 1204-1215. https://doi.org/10.1016/j.neuron.2011.02.027
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ts_par6( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ts_par6( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ts_par6( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ts_par6( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Two-Step Task using Hybrid Model, with 7 parameters (original model).
It has the following parameters: a1
(learning rate in stage 1), beta1
(inverse temperature in stage 1), a2
(learning rate in stage 2), beta2
(inverse temperature in stage 2), pi
(perseverance), w
(model-based weight), lambda
(eligibility trace).
Task: Two-Step Task (Daw et al., 2011)
Model: Hybrid Model, with 7 parameters (original model) (Daw et al., 2011)
ts_par7( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ts_par7( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, it's possible to set model-specific argument(s) as follows:
|
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Two-Step Task, there should be 4 columns of data with the
labels "subjID", "level1_choice", "level2_choice", "reward". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Choice made for Level (Stage) 1 (1: stimulus 1, 2: stimulus 2).
Choice made for Level (Stage) 2 (1: stimulus 3, 2: stimulus 4, 3: stimulus 5, 4: stimulus 6).
Note that, in our notation, choosing stimulus 1 in Level 1 leads to stimulus 3 & 4 in Level 2 with a common (0.7 by default) transition. Similarly, choosing stimulus 2 in Level 1 leads to stimulus 5 & 6 in Level 2 with a common (0.7 by default) transition. To change this default transition probability, set the function argument 'trans_prob' to your preferred value.
Reward after Level 2 (0 or 1).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Harhim Park <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ts_par7").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Daw, N. D., Gershman, S. J., Seymour, B., Ben Seymour, Dayan, P., & Dolan, R. J. (2011). Model-Based Influences on Humans' Choices and Striatal Prediction Errors. Neuron, 69(6), 1204-1215. https://doi.org/10.1016/j.neuron.2011.02.027
Daw, N. D., Gershman, S. J., Seymour, B., Ben Seymour, Dayan, P., & Dolan, R. J. (2011). Model-Based Influences on Humans' Choices and Striatal Prediction Errors. Neuron, 69(6), 1204-1215. https://doi.org/10.1016/j.neuron.2011.02.027
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ts_par7( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ts_par7( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ts_par7( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ts_par7( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Norm-Training Ultimatum Game using Ideal Observer Model.
It has the following parameters: alpha
(envy), beta
(guilt), tau
(inverse temperature).
Task: Norm-Training Ultimatum Game
Model: Ideal Observer Model (Xiang et al., 2013)
ug_bayes( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ug_bayes( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Norm-Training Ultimatum Game, there should be 3 columns of data with the
labels "subjID", "offer", "accept". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Floating point value representing the offer made in that trial (e.g. 4, 10, 11).
1 or 0, indicating whether the offer was accepted in that trial (where accepted == 1, rejected == 0).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ug_bayes").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Xiang, T., Lohrenz, T., & Montague, P. R. (2013). Computational Substrates of Norms and Their Violations during Social Exchange. Journal of Neuroscience, 33(3), 1099-1108. https://doi.org/10.1523/JNEUROSCI.1642-12.2013
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ug_bayes( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ug_bayes( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ug_bayes( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ug_bayes( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Norm-Training Ultimatum Game using Rescorla-Wagner (Delta) Model.
It has the following parameters: alpha
(envy), tau
(inverse temperature), ep
(norm adaptation rate).
Task: Norm-Training Ultimatum Game
Model: Rescorla-Wagner (Delta) Model (Gu et al., 2015)
ug_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
ug_delta( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Norm-Training Ultimatum Game, there should be 3 columns of data with the
labels "subjID", "offer", "accept". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Floating point value representing the offer made in that trial (e.g. 4, 10, 11).
1 or 0, indicating whether the offer was accepted in that trial (where accepted == 1, rejected == 0).
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"ug_delta").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Gu, X., Wang, X., Hula, A., Wang, S., Xu, S., Lohrenz, T. M., et al. (2015). Necessary, Yet Dissociable Contributions of the Insular and Ventromedial Prefrontal Cortices to Norm Adaptation: Computational and Lesion Evidence in Humans. Journal of Neuroscience, 35(2), 467-473. https://doi.org/10.1523/JNEUROSCI.2906-14.2015
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- ug_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ug_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- ug_delta( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- ug_delta( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
Hierarchical Bayesian Modeling of the Wisconsin Card Sorting Task using Sequential Learning Model.
It has the following parameters: r
(reward sensitivity), p
(punishment sensitivity), d
(decision consistency or inverse temperature).
Task: Wisconsin Card Sorting Task
Model: Sequential Learning Model (Bishara et al., 2010)
wcs_sql( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
wcs_sql( data = NULL, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 1, nthin = 1, inits = "vb", indPars = "mean", modelRegressor = FALSE, vb = FALSE, inc_postpred = FALSE, adapt_delta = 0.95, stepsize = 1, max_treedepth = 10, ... )
data |
Data to be modeled. It should be given as a data.frame object,
a filepath for a tab-seperated txt file, |
niter |
Number of iterations, including warm-up. Defaults to 4000. |
nwarmup |
Number of iterations used for warm-up only. Defaults to 1000. |
nchain |
Number of Markov chains to run. Defaults to 4. |
ncore |
Number of CPUs to be used for running. Defaults to 1. |
nthin |
Every |
inits |
Character value specifying how the initial values should be generated. Possible options are "vb" (default), "fixed", "random", or your own initial values. |
indPars |
Character value specifying how to summarize individual parameters. Current options are: "mean", "median", or "mode". |
modelRegressor |
Whether to export model-based regressors ( |
vb |
Use variational inference to approximately draw from a posterior distribution. Defaults
to |
inc_postpred |
Include trial-level posterior predictive simulations in model output (may greatly increase file
size). Defaults to |
adapt_delta |
Floating point value representing the target acceptance probability of a new sample in the MCMC chain. Must be between 0 and 1. See Details below. |
stepsize |
Integer value specifying the size of each leapfrog step that the MCMC sampler can take on each new iteration. See Details below. |
max_treedepth |
Integer value specifying how many leapfrog steps the MCMC sampler can take on each new iteration. See Details below. |
... |
For this model, there is no model-specific argument. |
This section describes some of the function arguments in greater detail.
data should be assigned a character value specifying the full path and name (including
extension information, e.g. ".txt") of the file that contains the behavioral data-set of all
subjects of interest for the current analysis. The file should be a tab-delimited text
file, whose rows represent trial-by-trial observations and columns represent variables.
For the Wisconsin Card Sorting Task, there should be 3 columns of data with the
labels "subjID", "choice", "outcome". It is not necessary for the columns to be in this particular order,
however it is necessary that they be labeled correctly and contain the information below:
A unique identifier for each subject in the data-set.
Integer value indicating which deck was chosen on that trial: 1, 2, 3, or 4.
1 or 0, indicating the outcome of that trial: correct == 1, wrong == 0.
*Note: The file may contain other columns of data (e.g. "ReactionTime", "trial_number", etc.), but only the data within the column names listed above will be used during the modeling. As long as the necessary columns mentioned above are present and labeled correctly, there is no need to remove other miscellaneous data columns.
nwarmup is a numerical value that specifies how many MCMC samples should not be stored
upon the beginning of each chain. For those familiar with Bayesian methods, this is equivalent
to burn-in samples. Due to the nature of the MCMC algorithm, initial values (i.e. where the
sampling chains begin) can have a heavy influence on the generated posterior distributions. The
nwarmup
argument can be set to a high number in order to curb the effects that initial
values have on the resulting posteriors.
nchain is a numerical value that specifies how many chains (i.e. independent sampling
sequences) should be used to draw samples from the posterior distribution. Since the posteriors
are generated from a sampling process, it is good practice to run multiple chains to ensure
that a reasonably representative posterior is attained. When the sampling is complete, it is
possible to check the multiple chains for convergence by running the following line of code:
plot(output, type = "trace")
. The trace-plot should resemble a "furry caterpillar".
nthin is a numerical value that specifies the "skipping" behavior of the MCMC sampler,
using only every i == nthin
samples to generate posterior distributions. By default,
nthin
is equal to 1, meaning that every sample is used to generate the posterior.
Control Parameters: adapt_delta
, stepsize
, and max_treedepth
are
advanced options that give the user more control over Stan's MCMC sampler. It is recommended
that only advanced users change the default values, as alterations can profoundly change the
sampler's behavior. Refer to 'The No-U-Turn Sampler: Adaptively Setting Path Lengths in
Hamiltonian Monte Carlo (Hoffman & Gelman, 2014, Journal of Machine Learning Research)' for
more information on the sampler control parameters. One can also refer to 'Section 34.2. HMC
Algorithm Parameters' of the Stan User's Guide
and Reference Manual, or to the help page for stan
for a less technical
description of these arguments.
Dayeong Min <[email protected]>
A class "hBayesDM" object modelData
with the following components:
Character value that is the name of the model (\code"wcs_sql").
Data.frame containing the summarized parameter values (as specified by
indPars
) for each subject.
List object containing the posterior samples over different parameters.
A class stanfit
object that contains the fitted Stan
model.
Data.frame containing the raw data used to fit the model, as specified by the user.
List object containing the extracted model-based regressors.
Bishara, A. J., Kruschke, J. K., Stout, J. C., Bechara, A., McCabe, D. P., & Busemeyer, J. R. (2010). Sequential learning models for the Wisconsin card sort task: Assessing processes in substance dependent individuals. Journal of Mathematical Psychology, 54(1), 5-13.
We refer users to our in-depth tutorial for an example of using hBayesDM: https://rpubs.com/CCSL/hBayesDM
## Not run: # Run the model with a given data.frame as df output <- wcs_sql( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- wcs_sql( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)
## Not run: # Run the model with a given data.frame as df output <- wcs_sql( data = df, niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Run the model with example data output <- wcs_sql( data = "example", niter = 2000, nwarmup = 1000, nchain = 4, ncore = 4) # Visually check convergence of the sampling chains (should look like 'hairy caterpillars') plot(output, type = "trace") # Check Rhat values (all Rhat values should be less than or equal to 1.1) rhat(output) # Plot the posterior distributions of the hyper-parameters (distributions should be unimodal) plot(output) # Show the WAIC and LOOIC model fit estimates printFit(output) ## End(Not run)