AllenInstitute / visual_behavior_analysis

Python package for analyzing behavioral data for Brain Observatory: Visual Behavior
Other
21 stars 6 forks source link

computation of fano factor is incorrect #806

Closed alexpiet closed 2 years ago

alexpiet commented 2 years ago

In visual_behavior.ophys.response_analysis.cell_metrics one metric that is computed is the fano factor. I believe this metric is being incorrectly computed.

The code is defined here: https://github.com/AllenInstitute/visual_behavior_analysis/blob/master/visual_behavior/ophys/response_analysis/cell_metrics.py#L211

mean_responses = group.mean_response.values
sd = np.nanstd(mean_responses)
mean_response = np.nanmean(mean_responses)
fano_factor = np.abs((sd * 2) / mean_response)

However the fano factor is defined as the ratio of the variance to the mean (https://en.wikipedia.org/wiki/Fano_factor), so this code should be:

mean_responses = group.mean_response.values
var = np.nanvar(mean_responses)
mean_response = np.nanmean(mean_responses)
fano_factor = np.abs(nanvar / mean_response)

Technically, fano factor is used for positive valued responses, so the fact that the mean response is sometimes negative is a bit hard to deal with, but I think the use of np.abs() is probably ok.