<jupyter_start><jupyter_text>Fit the LBA on individual data<jupyter_code>import rlssm
import pandas as pd
import os<jupyter_output><empty_output><jupyter_text>Import individual data<jupyter_code># import some example data:
data = rlssm.load_example_dataset(hierarchical_levels = 1)

data.head()<jupyter_output><empty_output><jupyter_text>Initialize the model<jupyter_code>model = rlssm.LBAModel_2A(hierarchical_levels = 1)<jupyter_output>Using cached StanModel<jupyter_text>Fit<jupyter_code># sampling parameters
n_iter = 1000
n_chains = 2
n_thin = 5
model_fit = model.fit(
    data,
    thin = n_thin,
    iter = n_iter,
    chains = n_chains)<jupyter_output>Fitting the model using the priors:
drift_priors {'mu': 1, 'sd': 5}
k_priors {'mu': 1, 'sd': 1}
A_priors {'mu': 0.3, 'sd': 1}
tau_priors {'mu': 0, 'sd': 1}<jupyter_text>Get rhat<jupyter_code>model_fit.rhat<jupyter_output><empty_output><jupyter_text>Get WAIC<jupyter_code>model_fit.waic<jupyter_output><empty_output><jupyter_text>Save results<jupyter_code>model_fit.to_pickle()<jupyter_output>Saving file as: /Users/laurafontanesi/git/rlssm/docs/notebooks/LBA_2A.pkl<jupyter_text>Posteriors<jupyter_code>model_fit.samples.describe()
import seaborn as sns
sns.set(context = "talk", 
        style = "white", 
        palette = "husl",
        rc={'figure.figsize':(15, 8)})
model_fit.plot_posteriors(height=5, show_intervals='HDI');<jupyter_output><empty_output><jupyter_text>Posterior predictives  Ungrouped<jupyter_code>pp = model_fit.get_posterior_predictives_df(n_posterior_predictives=100)
pp
pp_summary = model_fit.get_posterior_predictives_summary(n_posterior_predictives=100)
pp_summary
model_fit.plot_mean_posterior_predictives(n_posterior_predictives=100, figsize=(20,8), show_intervals='HDI');
model_fit.plot_quantiles_posterior_predictives(n_posterior_predictives=100, kind='shades');<jupyter_output><empty_output><jupyter_text>Grouped<jupyter_code>import numpy as np
# Define new grouping variables, in this case, for the different choice pairs, but any grouping var can do
data['choice_pair'] = 'AB'
data.loc[(data.cor_option == 3) & (data.inc_option == 1), 'choice_pair'] = 'AC'
data.loc[(data.cor_option == 4) & (data.inc_option == 2), 'choice_pair'] = 'BD'
data.loc[(data.cor_option == 4) & (data.inc_option == 3), 'choice_pair'] = 'CD'

data['block_bins'] = pd.cut(data.trial_block, 8, labels=np.arange(1, 9))
model_fit.get_grouped_posterior_predictives_summary(
                grouping_vars=['block_label', 'choice_pair'],
                quantiles=[.3, .5, .7],
                n_posterior_predictives=100)
model_fit.get_grouped_posterior_predictives_summary(
                grouping_vars=['block_bins'],
                quantiles=[.3, .5, .7],
                n_posterior_predictives=100)
model_fit.plot_mean_grouped_posterior_predictives(grouping_vars=['block_bins'], 
                                                  n_posterior_predictives=100, 
                                                  figsize=(20,8));
model_fit.plot_quantiles_grouped_posterior_predictives(
    n_posterior_predictives=100,
    grouping_var='choice_pair',
    kind='shades',
    quantiles=[.1, .3, .5, .7, .9]);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12421972534332085, 'fraction_numerical': 0.02278401997503121, 'mean_word_length': 5.211240310077519, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '455931', 'license': 'MIT', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1176, 'n_words': 174, 'path': 'docs/notebooks/LBA_2A_fitting.ipynb', 'repo_name': 'birgovanandrei/rlssm', 'size': '3204'}