<jupyter_start><jupyter_text>count number of cells or sites with significant contextual effects<jupyter_code># analyses = ['single cell', 'population', 'probewise pop', 'pop ceiling'] # 4 sounds
analyses = ['single cell', 'population']
nsounds = [4, 10]# 10 sounds

for analysis, ns in itt.product(analyses, nsounds):
    print(f'\n{analysis} {ns} sounds')
    all_id_df= pivoted.loc[(pivoted.nsounds == ns) & (pivoted.analysis == analysis), ['id', "integral (d'*ms)"]]

    # count of cells or sites with significant instances
    all_id_count = len(all_id_df.id.unique())
    good_id_df= all_id_df.loc[(all_id_df["integral (d'*ms)"] > 0), ['id']]
    good_id_count = len(good_id_df.id.unique())
    print(f'{good_id_count} of {all_id_count} total modulated neurons/PCs. {good_id_count/all_id_count*100:.2f}%')

    # total count of significant instances
    total_instances = all_id_df["integral (d'*ms)"].shape[0]
    significant_instances = np.sum(all_id_df["integral (d'*ms)"] > 0)
    print(f"{significant_instances} of {total_instances} total significant instances, {significant_instances/total_instances*100:.2f}%")

    # count of significant instances per neuron or PC, corrected for multiple comparisons
    signif_prop_per_neuron = all_id_df.groupby('id').agg(corr_signif_prop=("integral (d'*ms)",corrected_proportion))
    modulated_neurons =  signif_prop_per_neuron.loc[signif_prop_per_neuron.corr_signif_prop > 0]
    print(f"modulated neurons/PCs have {np.mean(modulated_neurons.values)*100 :.2f}% significant instances on average")

    # count of significant neurons per site
    if analysis == 'single cell':
        signif_prop_per_neuron = signif_prop_per_neuron.reset_index()
        signif_prop_per_neuron['site'] = signif_prop_per_neuron['id'].apply(lambda x: x[:7])
        gp = signif_prop_per_neuron.groupby('site').agg(
            signif_neu_prop=('corr_signif_prop', lambda x: np.sum(x>0)/np.size(x)))
        print(f"sites have {np.mean(gp.values)*100 :.2f}% of modulated neurons on average")<jupyter_output>single cell 4 sounds
375 of 862 total modulated neurons/PCs. 43.50%
1463 of 34480 total significant instances, 4.24%
modulated neurons/PCs have 9.75% significant instances on average
sites have 42.27% of modulated neurons on average

single cell 10 sounds
199 of 247 total modulated neurons/PCs. 80.57%
6676 of 135850 total significant instances, 4.91%
modulated neurons/PCs have 6.10% significant instances on average
sites have 78.95% of modulated neurons on average

population 4 sounds
35 of 35 total modulated neurons/PCs. 100.00%
428 of 1400 total significant instances, 30.57%
modulated neurons/PCs have 30.57% significant instances on average

population 10 sounds
6 of 6 total modulated neurons/PCs. 100.00%
1002 of 3300 total significant instances, 30.36%
modulated neurons/PCs have 30.36% significant instances on average