You can download and run the notebook locally:

Download jupyter notebook


Table S3-4#

[1]:
import scipy.stats
import numpy as np
from statsmodels.stats.multicomp import pairwise_tukeyhsd
from statsmodels.sandbox.stats.multicomp import get_tukey_pvalue
import joblib
import pandas as pd
[2]:
decoding_results = pd.read_hdf("../data/Figure5Revision.h5", data="key")
[3]:
def get_data2(decoding_results, task, decoders, methods, window, modality, num_neurons):
    if modality == "ca":
        index = 0
    elif modality == "np":
        index = 1
    accs = []
    keys = []
    for decoder, method in zip(decoders, methods):
        key = f"{modality}_{method}_{window}"
        if "joint" in method:
            acc = np.array(decoding_results[task][decoder][key][num_neurons])[:, index]
        else:
            acc = np.array(decoding_results[task][decoder][key][num_neurons])
        accs.append(acc)
        keys.append([f"{key}_{decoder}"] * len(acc))
    return np.concatenate(accs), np.concatenate(keys)


def concat_neurons(decoding_results, task, decoder, method, window, modality):
    if modality == "ca":
        index = 0
    elif modality == "np":
        index = 1
    key = f"{modality}_{method}_{window}"
    accs = []
    for n in decoding_results[task][decoder][key].keys():
        if "joint" in method:
            accs.append(np.array(decoding_results[task][decoder][key][n])[:, index])
        else:
            accs.append(np.array(decoding_results[task][decoder][key][n]))
    return np.concatenate(accs)

ANOVA for CEBRA, CEBRA-joint, baseline 330 ms (10 frame window):#

[4]:
np_total_stats = scipy.stats.f_oneway(
    concat_neurons(decoding_results, "frame_id", "knn", "cebra", "330", "np"),
    concat_neurons(decoding_results, "frame_id", "knn", "cebra_joint", "330", "np"),
    concat_neurons(decoding_results, "frame_id", "knn", "baseline", "330", "np"),
    concat_neurons(decoding_results, "frame_id", "bayes", "baseline", "330", "np"),
)


print(f"NP total stats \n {np_total_stats}")
NP total stats
 F_onewayResult(statistic=1.2871516854445968, pvalue=0.27999880116247905)

ANOVA for CEBRA, CEBRA-joint, baseline 33 ms (1 frame window):#

[5]:
np_total_stats = scipy.stats.f_oneway(
    concat_neurons(decoding_results, "frame_id", "knn", "cebra", "33", "np"),
    concat_neurons(decoding_results, "frame_id", "knn", "cebra_joint", "33", "np"),
    concat_neurons(decoding_results, "frame_id", "knn", "baseline", "33", "np"),
    concat_neurons(decoding_results, "frame_id", "bayes", "baseline", "33", "np"),
)


print(f"NP total stats \n {np_total_stats}")
NP total stats
 F_onewayResult(statistic=5.881619459851054, pvalue=0.0007278034882167102)

ANOVA for CEBRA, CEBRA-joint, baseline for each neuron numbers#

[6]:
num_neurons = [10, 30, 50, 100, 200, 400, 600, 800, 900, 1000]
for i in num_neurons:
    print(f"For {i} neurons from np recording (330ms):")

    np_data, np_keys = get_data2(
        decoding_results,
        "frame_id",
        ["knn", "knn", "knn", "bayes"],
        ["cebra", "cebra_joint", "baseline", "baseline"],
        "330",
        "np",
        i,
    )

    stats = pairwise_tukeyhsd(
        np_data.flatten(),
        np_keys,
    )
    print(stats)
For 10 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn     -5.7 0.5269 -17.4894  6.0894  False
np_baseline_330_bayes       np_cebra_330_knn  -4.1111 0.7529 -15.9005  7.6782  False
np_baseline_330_bayes np_cebra_joint_330_knn  -8.0833 0.2429 -19.8727   3.706  False
  np_baseline_330_knn       np_cebra_330_knn   1.5889 0.9798 -10.2005 13.3782  False
  np_baseline_330_knn np_cebra_joint_330_knn  -2.3833 0.9371 -14.1727   9.406  False
     np_cebra_330_knn np_cebra_joint_330_knn  -3.9722 0.7713 -15.7616  7.8171  False
------------------------------------------------------------------------------------
For 30 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn -14.0167  0.016 -25.6823  -2.351   True
np_baseline_330_bayes       np_cebra_330_knn  -9.6278 0.1255 -21.2935  2.0379  False
np_baseline_330_bayes np_cebra_joint_330_knn -15.6278 0.0072 -27.2935 -3.9621   True
  np_baseline_330_knn       np_cebra_330_knn   4.3889 0.7083  -7.2768 16.0546  False
  np_baseline_330_knn np_cebra_joint_330_knn  -1.6111 0.9784 -13.2768 10.0546  False
     np_cebra_330_knn np_cebra_joint_330_knn     -6.0 0.4762 -17.6657  5.6657  False
------------------------------------------------------------------------------------
For 50 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn -15.7778 0.0358 -30.6554 -0.9002   True
np_baseline_330_bayes       np_cebra_330_knn  -9.1889  0.324 -24.0665  5.6887  False
np_baseline_330_bayes np_cebra_joint_330_knn -12.1833 0.1296 -27.0609  2.6943  False
  np_baseline_330_knn       np_cebra_330_knn   6.5889 0.5956  -8.2887 21.4665  False
  np_baseline_330_knn np_cebra_joint_330_knn   3.5944 0.8989 -11.2832 18.4721  False
     np_cebra_330_knn np_cebra_joint_330_knn  -2.9944 0.9379 -17.8721 11.8832  False
------------------------------------------------------------------------------------
For 100 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn    -17.5    0.0  -24.032 -10.968   True
np_baseline_330_bayes       np_cebra_330_knn  -4.3833 0.2589 -10.9153  2.1486  False
np_baseline_330_bayes np_cebra_joint_330_knn  -3.8056  0.372 -10.3375  2.7264  False
  np_baseline_330_knn       np_cebra_330_knn  13.1167 0.0002   6.5847 19.6486   True
  np_baseline_330_knn np_cebra_joint_330_knn  13.6944 0.0001   7.1625 20.2264   True
     np_cebra_330_knn np_cebra_joint_330_knn   0.5778 0.9941  -5.9542  7.1098  False
------------------------------------------------------------------------------------
For 200 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn -11.7278    0.0 -16.0601 -7.3954   True
np_baseline_330_bayes       np_cebra_330_knn   0.2833 0.9976   -4.049  4.6157  False
np_baseline_330_bayes np_cebra_joint_330_knn  -1.3778 0.7999  -5.7101  2.9546  False
  np_baseline_330_knn       np_cebra_330_knn  12.0111    0.0   7.6788 16.3435   True
  np_baseline_330_knn np_cebra_joint_330_knn    10.35    0.0   6.0177 14.6823   True
     np_cebra_330_knn np_cebra_joint_330_knn  -1.6611 0.6964  -5.9935  2.6712  False
------------------------------------------------------------------------------------
For 400 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn  -6.7389 0.0004 -10.3943 -3.0835   True
np_baseline_330_bayes       np_cebra_330_knn   2.4722 0.2531  -1.1832  6.1277  False
np_baseline_330_bayes np_cebra_joint_330_knn      2.6 0.2166  -1.0554  6.2554  False
  np_baseline_330_knn       np_cebra_330_knn   9.2111    0.0   5.5557 12.8665   True
  np_baseline_330_knn np_cebra_joint_330_knn   9.3389    0.0   5.6835 12.9943   True
     np_cebra_330_knn np_cebra_joint_330_knn   0.1278 0.9996  -3.5277  3.7832  False
------------------------------------------------------------------------------------
For 600 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
====================================================================================
        group1                group2         meandiff p-adj   lower    upper  reject
------------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn  -6.6944 0.0002 -10.1351 -3.2538   True
np_baseline_330_bayes       np_cebra_330_knn   2.4722 0.2095  -0.9685  5.9129  False
np_baseline_330_bayes np_cebra_joint_330_knn   2.2222 0.2884  -1.2185  5.6629  False
  np_baseline_330_knn       np_cebra_330_knn   9.1667    0.0    5.726 12.6073   True
  np_baseline_330_knn np_cebra_joint_330_knn   8.9167    0.0    5.476 12.3573   True
     np_cebra_330_knn np_cebra_joint_330_knn    -0.25 0.9967  -3.6907  3.1907  False
------------------------------------------------------------------------------------
For 800 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
===================================================================================
        group1                group2         meandiff p-adj   lower   upper  reject
-----------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn  -6.4944 0.0001 -9.6586 -3.3302   True
np_baseline_330_bayes       np_cebra_330_knn     1.85 0.3691 -1.3142  5.0142  False
np_baseline_330_bayes np_cebra_joint_330_knn   2.4278 0.1668 -0.7364   5.592  False
  np_baseline_330_knn       np_cebra_330_knn   8.3444    0.0  5.1802 11.5086   True
  np_baseline_330_knn np_cebra_joint_330_knn   8.9222    0.0   5.758 12.0864   True
     np_cebra_330_knn np_cebra_joint_330_knn   0.5778 0.9524 -2.5864   3.742  False
-----------------------------------------------------------------------------------
For 900 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
===================================================================================
        group1                group2         meandiff p-adj   lower   upper  reject
-----------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn  -6.4389 0.0003  -9.865 -3.0128   True
np_baseline_330_bayes       np_cebra_330_knn   1.9611 0.3867  -1.465  5.3872  False
np_baseline_330_bayes np_cebra_joint_330_knn   2.0444 0.3522 -1.3816  5.4705  False
  np_baseline_330_knn       np_cebra_330_knn      8.4    0.0  4.9739 11.8261   True
  np_baseline_330_knn np_cebra_joint_330_knn   8.4833    0.0  5.0572 11.9094   True
     np_cebra_330_knn np_cebra_joint_330_knn   0.0833 0.9999 -3.3428  3.5094  False
-----------------------------------------------------------------------------------
For 1000 neurons from np recording (330ms):
                Multiple Comparison of Means - Tukey HSD, FWER=0.05
===================================================================================
        group1                group2         meandiff p-adj   lower   upper  reject
-----------------------------------------------------------------------------------
np_baseline_330_bayes    np_baseline_330_knn  -5.2222 0.0018 -8.5376 -1.9068   True
np_baseline_330_bayes       np_cebra_330_knn   1.7167 0.4707 -1.5987   5.032  False
np_baseline_330_bayes np_cebra_joint_330_knn   1.9167 0.3785 -1.3987   5.232  False
  np_baseline_330_knn       np_cebra_330_knn   6.9389 0.0001  3.6235 10.2543   True
  np_baseline_330_knn np_cebra_joint_330_knn   7.1389 0.0001  3.8235 10.4543   True
     np_cebra_330_knn np_cebra_joint_330_knn      0.2 0.9981 -3.1154  3.5154  False
-----------------------------------------------------------------------------------
[7]:
num_neurons = [10, 30, 50, 100, 200, 400, 600, 800, 900, 1000]
for i in num_neurons:
    print(f"For {i} neurons from np recording (33ms):")

    np_data, np_keys = get_data2(
        decoding_results,
        "frame_id",
        ["knn", "knn", "knn", "bayes"],
        ["cebra", "cebra_joint", "baseline", "baseline"],
        "33",
        "np",
        i,
    )

    stats = pairwise_tukeyhsd(np_data.flatten(), np_keys)
    print(stats)
For 10 neurons from np recording (33ms):
              Multiple Comparison of Means - Tukey HSD, FWER=0.05
================================================================================
       group1                group2        meandiff p-adj   lower  upper  reject
--------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn  -1.7333 0.6751 -6.1089 2.6423  False
np_baseline_33_bayes       np_cebra_33_knn   0.3556 0.9954   -4.02 4.7312  False
np_baseline_33_bayes np_cebra_joint_33_knn   0.6667 0.9714 -3.7089 5.0423  False
  np_baseline_33_knn       np_cebra_33_knn   2.0889 0.5371 -2.2867 6.4645  False
  np_baseline_33_knn np_cebra_joint_33_knn      2.4 0.4225 -1.9756 6.7756  False
     np_cebra_33_knn np_cebra_joint_33_knn   0.3111 0.9969 -4.0645 4.6867  False
--------------------------------------------------------------------------------
For 30 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn  -3.2222 0.6128 -10.6673  4.2229  False
np_baseline_33_bayes       np_cebra_33_knn   1.3111  0.957   -6.134  8.7562  False
np_baseline_33_bayes np_cebra_joint_33_knn   1.8444 0.8921  -5.6007  9.2895  False
  np_baseline_33_knn       np_cebra_33_knn   4.5333 0.3356  -2.9118 11.9784  False
  np_baseline_33_knn np_cebra_joint_33_knn   5.0667 0.2484  -2.3784 12.5118  False
     np_cebra_33_knn np_cebra_joint_33_knn   0.5333 0.9968  -6.9118  7.9784  False
----------------------------------------------------------------------------------
For 50 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
=================================================================================
       group1                group2        meandiff p-adj   lower   upper  reject
---------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn  -6.6222 0.0232 -12.446 -0.7985   True
np_baseline_33_bayes       np_cebra_33_knn   1.4444 0.8918 -4.3793  7.2682  False
np_baseline_33_bayes np_cebra_joint_33_knn   1.7556 0.8238 -4.0682  7.5793  False
  np_baseline_33_knn       np_cebra_33_knn   8.0667 0.0055  2.2429 13.8904   True
  np_baseline_33_knn np_cebra_joint_33_knn   8.3778  0.004   2.554 14.2015   True
     np_cebra_33_knn np_cebra_joint_33_knn   0.3111 0.9987 -5.5126  6.1349  False
---------------------------------------------------------------------------------
For 100 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn -11.3778    0.0 -16.2363 -6.5192   True
np_baseline_33_bayes       np_cebra_33_knn  -5.3778 0.0275 -10.2363 -0.5192   True
np_baseline_33_bayes np_cebra_joint_33_knn  -0.3111 0.9977  -5.1696  4.5474  False
  np_baseline_33_knn       np_cebra_33_knn      6.0 0.0132   1.1415 10.8585   True
  np_baseline_33_knn np_cebra_joint_33_knn  11.0667    0.0   6.2081 15.9252   True
     np_cebra_33_knn np_cebra_joint_33_knn   5.0667 0.0395   0.2081  9.9252   True
----------------------------------------------------------------------------------
For 200 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn -11.6444 0.0005 -18.0394 -5.2495   True
np_baseline_33_bayes       np_cebra_33_knn   3.7333 0.3703  -2.6617 10.1283  False
np_baseline_33_bayes np_cebra_joint_33_knn      8.8 0.0058    2.405  15.195   True
  np_baseline_33_knn       np_cebra_33_knn  15.3778    0.0   8.9828 21.7728   True
  np_baseline_33_knn np_cebra_joint_33_knn  20.4444    0.0  14.0495 26.8394   True
     np_cebra_33_knn np_cebra_joint_33_knn   5.0667 0.1478  -1.3283 11.4617  False
----------------------------------------------------------------------------------
For 400 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn     -6.0 0.0044 -10.2102 -1.7898   True
np_baseline_33_bayes       np_cebra_33_knn   4.5111 0.0336   0.3009  8.7213   True
np_baseline_33_bayes np_cebra_joint_33_knn  23.7333    0.0  19.5231 27.9436   True
  np_baseline_33_knn       np_cebra_33_knn  10.5111    0.0   6.3009 14.7213   True
  np_baseline_33_knn np_cebra_joint_33_knn  29.7333    0.0  25.5231 33.9436   True
     np_cebra_33_knn np_cebra_joint_33_knn  19.2222    0.0   15.012 23.4324   True
----------------------------------------------------------------------------------
For 600 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn  -6.8444 0.0125 -12.3415 -1.3474   True
np_baseline_33_bayes       np_cebra_33_knn      2.4 0.6063   -3.097   7.897  False
np_baseline_33_bayes np_cebra_joint_33_knn  26.5333    0.0  21.0363 32.0304   True
  np_baseline_33_knn       np_cebra_33_knn   9.2444  0.001   3.7474 14.7415   True
  np_baseline_33_knn np_cebra_joint_33_knn  33.3778    0.0  27.8807 38.8748   True
     np_cebra_33_knn np_cebra_joint_33_knn  24.1333    0.0  18.6363 29.6304   True
----------------------------------------------------------------------------------
For 800 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn  -9.3778 0.0006 -14.6758 -4.0798   True
np_baseline_33_bayes       np_cebra_33_knn   9.0667 0.0008   3.7687 14.3647   True
np_baseline_33_bayes np_cebra_joint_33_knn  22.9111    0.0  17.6131 28.2091   True
  np_baseline_33_knn       np_cebra_33_knn  18.4444    0.0  13.1464 23.7425   True
  np_baseline_33_knn np_cebra_joint_33_knn  32.2889    0.0  26.9909 37.5869   True
     np_cebra_33_knn np_cebra_joint_33_knn  13.8444    0.0   8.5464 19.1425   True
----------------------------------------------------------------------------------
For 900 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn    -11.0 0.0004 -16.9047 -5.0953   True
np_baseline_33_bayes       np_cebra_33_knn   8.3111 0.0048   2.4065 14.2158   True
np_baseline_33_bayes np_cebra_joint_33_knn  22.4667    0.0   16.562 28.3713   True
  np_baseline_33_knn       np_cebra_33_knn  19.3111    0.0  13.4065 25.2158   True
  np_baseline_33_knn np_cebra_joint_33_knn  33.4667    0.0   27.562 39.3713   True
     np_cebra_33_knn np_cebra_joint_33_knn  14.1556    0.0   8.2509 20.0602   True
----------------------------------------------------------------------------------
For 1000 neurons from np recording (33ms):
               Multiple Comparison of Means - Tukey HSD, FWER=0.05
==================================================================================
       group1                group2        meandiff p-adj   lower    upper  reject
----------------------------------------------------------------------------------
np_baseline_33_bayes    np_baseline_33_knn -10.0889    0.0 -14.5064 -5.6713   True
np_baseline_33_bayes       np_cebra_33_knn  15.4667    0.0  11.0491 19.8842   True
np_baseline_33_bayes np_cebra_joint_33_knn  22.3778    0.0  17.9602 26.7953   True
  np_baseline_33_knn       np_cebra_33_knn  25.5556    0.0   21.138 29.9731   True
  np_baseline_33_knn np_cebra_joint_33_knn  32.4667    0.0  28.0491 36.8842   True
     np_cebra_33_knn np_cebra_joint_33_knn   6.9111 0.0019   2.4936 11.3287   True
----------------------------------------------------------------------------------