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 Chapter 8.
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 Chapter 8. I will expose the code to load in the data set, but hide the visualization code.
= scipy.io.loadmat('../data/hypothalamus_calcium_imaging_remedios_et_al.mat')
data = data['neural_data'].transpose() # Row is time index, column is neuron
neural_data = data['attack_vector'].flatten()
attack_vector = data['sex_vector'].flatten()
sex_vector
# Time points at 30 Hz sampling
= np.arange(len(attack_vector)) / 30 t
Code
= bokeh.plotting.figure(
p_attack =50,
frame_height=600,
frame_width=None,
x_axis_label='attack',
y_axis_label=['no', 'yes'],
y_range=None,
toolbar_location
)= ['tomato' if a else 'gray' for a in attack_vector]
attack_color 'yes' if a else 'no' for a in attack_vector], size=2, color=attack_color)
p_attack.scatter(t, [= '0pt'
p_attack.xaxis.major_label_text_font_size
= bokeh.plotting.figure(
p_sex =50,
frame_height=600,
frame_width=None,
x_axis_label='sex',
y_axis_label=['m', 'f'],
y_range=None,
toolbar_location
)= ['orchid' if s else 'dodgerblue' for s in sex_vector]
sex_color 'f' if s else 'm' for s in sex_vector], size=2, color=sex_color)
p_sex.scatter(t, [= '0pt'
p_sex.xaxis.major_label_text_font_size
= bebi103.image.imshow(
p_neuron
neural_data.transpose(),=150,
frame_height=600,
frame_width="time (s)",
x_axis_label="neuron",
y_axis_label=1/30,
interpixel_distance
)
= '0pt'
p_neuron.yaxis.major_label_text_font_size
= p_neuron.x_range
p_attack.x_range = p_neuron.x_range
p_sex.x_range
bokeh.io.show(bokeh.layouts.column(p_sex, p_attack, p_neuron))