def get_cond_diff(cond_1, cond_2, voi): """ This function computes the differences in perseveration and estimation errors between two task conditions in the follow-up experiment :param cond_1: First condition of interest :param cond_2: Second condition of interest :param voi: Variable of interes :return: desc, stat, zero_stat: descriptive, inferential statistics and inferential statistics against zero """ # Identify variable of interest if voi == 1: voi_name = 'e_t' print_name = 'Estimation error' elif voi == 2: voi_name = 'pers' print_name = 'Perseveration' else: voi_name = 'motor_pers' print_name = 'Motor perseveration' # Compute mean of variable of interest voi_cond_1 = get_mean_voi(cond_1, voi) voi_cond_2 = get_mean_voi(cond_2, voi) # Compute difference between conditions cond_diff = voi_cond_2.copy() cond_diff[voi_name] = cond_diff[voi_name] - voi_cond_1[voi_name] print('\n\n' + print_name + ' difference\n') median_diff, q1_diff, q3_diff, p_values_diff, stat_diff = get_stats(cond_diff, 2, voi_name) stat = pd.DataFrame() stat['p'] = p_values_diff stat['stat'] = stat_diff stat.index.name = 'test' stat = stat.rename({0: 'kw', 1: 'ch_ad', 2: 'ch_ya', 3: 'ch_oa', 4: 'ad_ya', 5: 'ad_oa', 6: 'ya_oa'}, axis='index') desc = pd.DataFrame() desc['median'] = round(median_diff, 3) desc['q1'] = round(q1_diff, 3) desc['q3'] = round(q3_diff, 3) desc.index.name = 'age_group' desc = desc.rename({1: 'ch', 2: 'ad', 3: 'ya', 4: 'oa'}, axis='index') print('\n\n' + print_name + ' difference test against zero\n') _, _, _, p_values_diff, stat_diff = get_stats(cond_diff, 2, voi_name, test=2) zero_stat = pd.DataFrame() zero_stat['p'] = p_values_diff zero_stat['stat'] = stat_diff zero_stat.index.name = 'age_group' zero_stat = zero_stat.rename({0: 'ch', 1: 'ya', 2: 'oa'}, axis='index') return cond_diff, desc, stat, zero_stat
# Save statistics for Latex manuscript fig_5_ef_desc.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_ef_desc.csv') fig_5_ef_stat.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_ef_stat.csv') # --------------------------------------------------------------------------------------- # 3. Differences of perseveration frequency between shifting- and stable bucket condition # --------------------------------------------------------------------------------------- # Read out push and noPush trials df_noPush = df_exp2[df_exp2['cond'] == 'main_noPush'] df_push = df_exp2[df_exp2['cond'] == 'main_push'] # Perseveration in stable-bucket condition voi = 2 pers_noPush = get_mean_voi(df_noPush, voi) # Compute differences fig_5_c_cond_diff, fig_5_c_desc, fig_5_c_stat, fig_5_c_zero_stat = get_cond_diff(df_noPush, df_push, voi) fig_5_c_desc.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_c_desc.csv') fig_5_c_stat.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_c_stat.csv') fig_5_c_zero_stat.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_c_zero_stat.csv') # ---------------------------------------------------------------------------------- # 4. Differences of estimation errors between shifting- and stable bucket condition # ---------------------------------------------------------------------------------- voi = 1 fig_5_d_cond_diff, fig_5_d_desc, fig_5_d_stat, fig_5_d_zero_stat = get_cond_diff(df_noPush, df_push, voi) fig_5_d_desc.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_d_desc.csv') fig_5_d_stat.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_5_d_stat.csv')
# Perseveration-frequency differences between high- and low-reward condition voi = 2 _, fig_SM_1_a_desc, _, fig_SM_1_a_zero_stat = get_cond_diff(low, high, voi) fig_SM_1_a_zero_stat.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_SM_1_a_zero_stat.csv') fig_SM_1_a_desc.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_SM_1_a_desc.csv') # Estimation-error differences between high- and low-reward condition voi = 1 _, fig_SM_1_b_desc, _, fig_SM_1_b_zero_stat = get_cond_diff(low, high, voi) fig_SM_1_b_zero_stat.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_SM_1_b_zero_stat.csv') fig_SM_1_b_desc.to_csv('~/Dropbox/Apps/Overleaf/al_manuscript/al_dataframes/fig_SM_1_b_desc.csv') # Perseveration in high- and low reward condition voi = 2 pers_high = get_mean_voi(high, voi) pers_low = get_mean_voi(low, voi) pers_high['Condition'] = 1 pers_low['Condition'] = 2 # Perseveration in stable- and shifting-bucket condition voi = 2 pers_noPush = get_mean_voi(df_noPush, voi) pers_push = get_mean_voi(df_push, voi) pers_noPush['Condition'] = 1 pers_push['Condition'] = 2 # Estimation errors in high- and low-reward condition voi = 1 est_err_high = get_mean_voi(high, voi) est_err_low = get_mean_voi(low, voi)
path = paths.split(os.path.sep) home_dir = path[1] # ------------ # 1. Load data # ------------ # Load data from first experiment df_exp1 = pd.read_pickle('al_data/data_prepr_1.pkl') # Parameter estimates model_results = pd.read_pickle('al_data/estimates_first_exp_25_sp.pkl') # Compute perseveration frequency voi = 2 pers = get_mean_voi(df_exp1, voi) # Print out perseveration statistics for paper print('\n\nPerseveration\n') median_pers, q1_pers, q3_pers, p_pers, stat_pers = get_stats(pers, 1, 'pers') # Create data frame for descriptive results fig_3_a_desc = pd.DataFrame() # Median perseveration fig_3_a_desc['median'] = round(median_pers, 3) # First quartile fig_3_a_desc['q1'] = round(q1_pers, 3) # Third quartile
# Get home directory paths = os.getcwd() path = paths.split(os.path.sep) home_dir = path[1] # ------------------------------------ # 1. Load data and compute performance # ------------------------------------ # Load data df_exp1 = pd.read_pickle('al_data/data_prepr_1.pkl') n_subj = len(np.unique(df_exp1['subj_num'])) # Compute estimation errors voi = 1 e_t = get_mean_voi(df_exp1, voi) # --------------------------------- # 2. Compute average learning rates # --------------------------------- # Initialize learning rate and age_group variables alpha = np.full(n_subj, np.nan) age_group = np.full(n_subj, np.nan) # Cycle over participants for i in range(0, n_subj): # Extract data of current participant df_subj = df_exp1[(df_exp1['subj_num'] == i + 1)].copy() x = np.linspace(0, len(df_subj) - 1, len(df_subj))