Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/R/hBayesDM_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ hBayesDM_model <- function(task_name = "",
if ((model_name == "hgf_ibrb") && (model_type == "single")) {
pars <- c(pars, paste0("logit_", names(parameters)))
}
if ((task_name == "pst") && (model_name == "Q")) {
pars <- c(pars, "pe")
}
pars <- c(pars, "log_lik")
if (modelRegressor) {
pars <- c(pars, names(regressors))
Expand Down
8 changes: 8 additions & 0 deletions R/inst/plotting/plot_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ plot_cra_exp <- function(obj, fontSize = 10, ncols = 3, binSize = 30) {
return(h_all)
}

plot_pst_Q <- function(obj, fontSize = 10, ncols = 2, binSize = 30) {
pars = obj$parVals
h1 = plotDist(sample = pars$mu_alpha, fontSize = fontSize, binSize = binSize, xLim = c(0,1), xLab = expression(paste(alpha, " (Learning Rate)")))
h2 = plotDist(sample = pars$mu_beta, fontSize = fontSize, binSize = binSize, xLim = c(0,10), xLab = expression(paste(beta, " (Inverse Temp.)")))
h_all = multiplot(h1, h2, cols = ncols)
return(h_all)
}

plot_pst_gainloss_Q <- function(obj, fontSize = 10, ncols = 3, binSize = 30) {
pars = obj$parVals
h1 = plotDist(sample = pars$mu_alpha_pos, fontSize = fontSize, binSize = binSize, xLim = c(0,2), xLab = expression(paste(alpha[pos], " (+Learning Rate)")))
Expand Down
20 changes: 9 additions & 11 deletions commons/stan_files/pst_Q.stan
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@ transformed parameters {
vector<lower=0,upper=1>[N] alpha;
vector<lower=0,upper=10>[N] beta;

alpha = Phi_approx(mu_pr[1] + sigma[1] * alpha_pr);
beta = Phi_approx(mu_pr[2] + sigma[2] * beta_pr) * 10;
alpha = Phi_approx(mu_pr[1] + sigma[1] * alpha_pr);
beta = Phi_approx(mu_pr[2] + sigma[2] * beta_pr) * 10;
}

model {
// Priors for group-level parameters
mu_pr ~ normal(0, 1);
mu_pr ~ normal(0, 1);
sigma ~ normal(0, 0.2);

// Priors for subject-level parameters
alpha_pr ~ normal(0, 1);
beta_pr ~ normal(0, 1);
beta_pr ~ normal(0, 1);

for (i in 1:N) {
int co; // Chosen option
real delta; // Difference between two options
real pe; // Prediction error
//real alpha;
vector[6] ev; // Expected values

ev = initial_values;
Expand All @@ -71,19 +70,18 @@ generated quantities {
// For group-level parameters
real<lower=0,upper=1> mu_alpha;
real<lower=0,upper=10> mu_beta;
real pe[N, T]; // Prediction error

// For log-likelihood calculation
real log_lik[N];

mu_alpha = Phi_approx(mu_pr[1]);
mu_beta = Phi_approx(mu_pr[2]) * 10;
mu_alpha = Phi_approx(mu_pr[1]);
mu_beta = Phi_approx(mu_pr[2]) * 10;

{
for (i in 1:N) {
int co; // Chosen option
real delta; // Difference between two options
real pe; // Prediction error
//real alpha;
vector[6] ev; // Expected values

ev = initial_values;
Expand All @@ -97,8 +95,8 @@ generated quantities {
delta = ev[option1[i, t]] - ev[option2[i, t]];
log_lik[i] += bernoulli_logit_lpmf(choice[i, t] | beta[i] * delta);

pe = reward[i, t] - ev[co];
ev[co] += alpha[i] * pe;
pe[i, t] = reward[i, t] - ev[co];
ev[co] += alpha[i] * pe[i, t];
}
}
}
Expand Down