%% plot correlation score of subj-ERS t-stat and param value (e.g. age / performance)

function posthoc_ers_param(roi_tag,rsa_tag,stats_tag,param_name,corrType,direction)

    load(['..\STATS\ERS\' rsa_tag '\' stats_tag '\memory\' roi_tag '_stats.mat']);
    load('..\subject_list.mat'); %subNames for easier folder accessing

    %get clustertimes
    if strcmp(direction,'pos')
        clustidx = find(groupstats.emp_cluster.pos.map == groupstats.emp_cluster.pos.idx);
    else
        clustidx = find(groupstats.emp_cluster.neg.map == groupstats.emp_cluster.neg.idx);
    end
    
    %fetch subjects
    subs = groupstats.subnum;
    sub_age = age(subs);
    sub_perf = recognition(subs);
    old_ix = find(sub_age>=median(sub_age));
    yung_ix = find(sub_age<median(sub_age));
    gd_ix = find(sub_perf>=median(sub_perf));
    bd_ix = find(sub_perf<median(sub_perf));
    
    %
    subavg = squeeze(nanmean(groupstats.sub.emp(:,clustidx),2));
    subage = age(groupstats.subnum);
    subperf = recognition(groupstats.subnum);
    
    if strcmp(param_name,'age')
        val = subage';
    elseif strcmp(param_name,'performance')
        val = subperf;
    end
    plot_correlation_raw(val,subavg,param_name,[replace(roi_tag,'_',' ') ' ERS t-stat'],corrType)

end
    