Title: | Generalized Linear Regression with DDM |
---|---|
Description: | Drift-Diffusion Model (DDM) has been widely used to model binary decision-making tasks, and many research studies the relationship between DDM parameters and other characteristics of the subject. This package uses 'RStan' to perform generalized liner regression analysis over DDM parameters via a single Bayesian Hierarchical model. Compared to estimating DDM parameters followed by a separate regression model, 'RegDDM' reduces bias and improves statistical power. |
Authors: | Zekai Jin [aut, cre] |
Maintainer: | Zekai Jin <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1 |
Built: | 2024-12-10 15:32:06 UTC |
Source: | https://github.com/biorabbit/regddm |
This function generates a simulated dataset under different configurations
It can be used to test the performance and functionality of RegDDM.
The outcome variable is y
, which is influenced by different variables.
generate_sim_data( N = 30, n_each = 100, n_xvar = 2, beta_0 = 0, beta_c1 = 0, beta_c2 = 0, beta_v_0 = 0, beta_v_x1 = 0, beta_v_x2 = 0, sigma_y = 1, sigma_v = 0, y_family = "gaussian" )
generate_sim_data( N = 30, n_each = 100, n_xvar = 2, beta_0 = 0, beta_c1 = 0, beta_c2 = 0, beta_v_0 = 0, beta_v_x1 = 0, beta_v_x2 = 0, sigma_y = 1, sigma_v = 0, y_family = "gaussian" )
N |
Number of subjects. |
n_each |
Number of trials per subject |
n_xvar |
Number of trial-level variables influencing drift rate |
beta_0 |
Intercept |
beta_c1 |
Slope of c1 |
beta_c2 |
Slope of c2 |
beta_v_0 |
Slope of v_0 |
beta_v_x1 |
Slope of v_x1 |
beta_v_x2 |
Slope of v_x2 |
sigma_y |
Standard deviation of error term of y, Only used when
|
sigma_v |
Contaminant level for drift rate v. |
y_family |
Family of distribution of y. Can be either "gaussian", "bernoulli" or "poisson" |
A named list with four elements. data1_true
and
data2_true
are true values of DDM parameters of each subject and
trial. data1
and data2
removed those hidden variables.
sim_data = generate_sim_data() sim_data$data1 sim_data$data2
sim_data = generate_sim_data() sim_data$data1 sim_data$data2
Get the stanfit
object of the regddmfit
object to perform further analysis and diagnosis.
get_stan_fit(fit)
get_stan_fit(fit)
fit |
A |
A stanfit
object.
Summarize the posterior distributions of estimated regression coefficients and print necessary information.
## S3 method for class 'regddmfit' print(x, digits = 3, ...)
## S3 method for class 'regddmfit' print(x, digits = 3, ...)
x |
An |
digits |
digits of the output results. Default value is 3. |
... |
Unused... |
No values are returned.
summary.regddmfit
Table summaries of the regddmfit
object.
regddm
makes it easy to fit a single Bayesian hierarchical drift-diffusion
model (DDM) that estimates the DDM parameters of each subject and uses the
estimated parameters as variables in a generalized linear regression.
regddm( data1, data2, model = list(), family = "gaussian", init = "default", prior = TRUE, stan_filename = "", gen_model = TRUE, fit_model = TRUE, warmup = 500, iter = 1000, chains = 4, cores = 4, ... )
regddm( data1, data2, model = list(), family = "gaussian", init = "default", prior = TRUE, stan_filename = "", gen_model = TRUE, fit_model = TRUE, warmup = 500, iter = 1000, chains = 4, cores = 4, ... )
data1 |
Subject-level dataframe with column such as age and gender. It
must contain an |
data2 |
Trial-level dataframe. It must contain three columns: |
model |
A list containing 0-5 formulas, specifying the dependence structure between variables. |
family |
Family of distribution of |
init |
Either |
prior |
A losigtic value, specifying whether or not to use default prior
for DDM parameters. By default, |
stan_filename |
A string specifying the automatically generated |
gen_model |
A logistic value indicating weather or not to generate the
model. If not, RegDDM will not generate the code but use the existing |
fit_model |
A logistic value indicating weather or not to fit the model.
If not, RegDDM will only generate the code and return an unfitted
|
warmup |
Number of warm-up iterations. Default is 500. |
iter |
Number of iterations, which must be greater than |
chains |
Number of chains to run for diagnosis. Default value is 4. |
cores |
Number of cores to run the chains. It is best to make
|
... |
Other parameters sent to |
A regddmfit
object.
To be added
# Note: each example takes about 20 minutes to run. During this period, you # may not be able to open/save files or see the progress. To prevent this, # it is recommended to copy, paste and run the example code in the console. ## Not run: # Example analysis over the simulated tutorial dataset. data(regddm_tutorial) model = list(v ~ x1, y ~ v_0 + v_x1 + c1) fit1 = regddm( regddm_tutorial$data1, regddm_tutorial$data2, model, stan_filename = "" ) print(fit1) # Alternatively, subjects' DDM parameters can be used as the outcome. model = list(v ~ x1, v_x1 ~ y + c1) fit2 = regddm( regddm_tutorial$data1, regddm_tutorial$data2, model, stan_filename = "" ) print(fit2) ## End(Not run)
# Note: each example takes about 20 minutes to run. During this period, you # may not be able to open/save files or see the progress. To prevent this, # it is recommended to copy, paste and run the example code in the console. ## Not run: # Example analysis over the simulated tutorial dataset. data(regddm_tutorial) model = list(v ~ x1, y ~ v_0 + v_x1 + c1) fit1 = regddm( regddm_tutorial$data1, regddm_tutorial$data2, model, stan_filename = "" ) print(fit1) # Alternatively, subjects' DDM parameters can be used as the outcome. model = list(v ~ x1, v_x1 ~ y + c1) fit2 = regddm( regddm_tutorial$data1, regddm_tutorial$data2, model, stan_filename = "" ) print(fit2) ## End(Not run)
This is the same simulated dataset used in the tutorial part of the RegDDM paper.
regddm_tutorial
regddm_tutorial
An object of class list
of length 2.
regddmfit
is an S3 object sotring the fitted models of RegDDM.
It contains information used to fit the model and the resulting
stanfit
and can be summarized and printed using
summary
and print
.
regddmfit(data1, data2, model, family, stan_fit)
regddmfit(data1, data2, model, family, stan_fit)
data1 |
Subject-level data frame. |
data2 |
Trial-level data frame. |
model |
A list containing 0-5 formulas, specifying the dependence structure between variables. |
family |
Family of distribution of the outcome. |
stan_fit |
Fitted |
Use methods(class = "regddmfit")
for a list of available methods.
Summarize the posterior distributions of estimated parameters and group them into four categories.
## S3 method for class 'regddmfit' summary(object, ...)
## S3 method for class 'regddmfit' summary(object, ...)
object |
A |
... |
parameters passed to |
The summary method returns a named list of glm_coefficiets
,
subject_ddm_param
, group_param
, and missing_value
.
Each element is a tibble
data frame of posterior
summary statistics of the regression coefficient, DDM parameter of each
subject, group mean and standard deviation of DDM parameters and covariates,
plus the estimated missing values.
print.regddmfit
a printed summary of the regddmfit
object.