Hi Ni,
Apologies for the long delay—for the IGT, I tend to prefer plotting the empirical versus posterior predicted probability of selecting each deck separately over trials. For example, you can access the posterior predictions through the hBayesDM object like so:
fit$parVals$y_pred
This should be an array of dimension N_samples x N_subjects x N_trials, where each sample will be a value of 1, 2, 3, or 4, indicating a selection of that deck on the given trial for the given participant.
You can use the R package bayesplot to nicely plot out the probability of selecting each deck across trials. For example, something like:
library(dplyr)
y_pp <- fit$parVals$y_pred
y_true <- fit$raw_data %>%
group_by(Trial) %>%
summarize(prA = mean(choice==1, na.rm=T),
prB = mean(choice==2, na.rm=T),
prC = mean(choice==3, na.rm=T),
prD = mean(choice==4, na.rm=T))
should give you the posterior predictions and the proportion of subjects who selected each deck on a given trial. Note that you should make sure that the y_true$Trial value is actually ordered in the data.frame y_true by Trial
number. I find sometimes that dplyr will set the order to something like 1, 10, etc., so just check that before proceeding with the next step.
Then, you can do:
library(bayesplot)
plot_deckA <- ppc_intervals(
y = y_true$prA,
yrep = apply(y_pp, c(1,3), function(x) mean(x==1, na.rm=T)),
x = y_true$Trial,
prob = 0.5,
prob_outer = .95
) +
labs(
x = "Trial",
y = "Pr(choose A)",
title = "Deck A"
)
You can do the same to make a plot for deck B, C, and D, and then combine them like so:
library(patchwork)
(plot_deckA | plot_deckB) /
(plot_deckC | plot_deckD)
This should give you a 2x2 grid, where the x-axis for each panel indicates the trial number, and y-axis the proportion of participants who selected the deck on each trial, along with the posterior predictions of the same values.
Sorry again for the delay, and let me know if this works out!
Best,
Nate