import numpy as np
import scipy.io
import sklearn.linear_model
import cmdstanpy
import arviz as az
import bebi103
import bokeh.io
import bokeh.plotting
bokeh.io.output_notebook()54 GLMs applied to neurons and aggression
In this lesson, I will demonstrate the use of a GLM in practice. Specifically, we will perform a logistic regression using the data from Remedios, et al. that we have already encountered in ?sec-matlab-files.
Now that we are modeling these data in earnest, it is important to note some facts from the paper about the data set.
- Sampling rate of 30 Hz.
- The fluorescence reported for each neuron is the relative fluorescent change, \((F(t) - F_0)/F_0\), were \(F_0\) is the average fluorescent intensity over all frames.
- Scoring of attack behavior done by human.
We have already loaded and visualized the data set in ?sec-matlab-files. I will expose the code to load in the data set, but hide the visualization code.
data = scipy.io.loadmat('../data/hypothalamus_calcium_imaging_remedios_et_al.mat')
neural_data = data['neural_data'].transpose() # Row is time index, column is neuron
attack_vector = data['attack_vector'].flatten()
sex_vector = data['sex_vector'].flatten()
# Time points at 30 Hz sampling
t = np.arange(len(attack_vector)) / 30Code
p_attack = bokeh.plotting.figure(
frame_height=50,
frame_width=600,
x_axis_label=None,
y_axis_label='attack',
y_range=['no', 'yes'],
toolbar_location=None,
)
attack_color = ['tomato' if a else 'gray' for a in attack_vector]
p_attack.scatter(t, ['yes' if a else 'no' for a in attack_vector], size=2, color=attack_color)
p_attack.xaxis.major_label_text_font_size = '0pt'
p_sex = bokeh.plotting.figure(
frame_height=50,
frame_width=600,
x_axis_label=None,
y_axis_label='sex',
y_range=['m', 'f'],
toolbar_location=None,
)
sex_color = ['orchid' if s else 'dodgerblue' for s in sex_vector]
p_sex.scatter(t, ['f' if s else 'm' for s in sex_vector], size=2, color=sex_color)
p_sex.xaxis.major_label_text_font_size = '0pt'
p_neuron = bebi103.image.imshow(
neural_data.transpose(),
frame_height=150,
frame_width=600,
x_axis_label="time (s)",
y_axis_label="neuron",
interpixel_distance=1/30,
)
p_neuron.yaxis.major_label_text_font_size = '0pt'
p_attack.x_range = p_neuron.x_range
p_sex.x_range = p_neuron.x_range
bokeh.io.show(bokeh.layouts.column(p_sex, p_attack, p_neuron))