guide for using NEMOS for fitting a GLM to firing rate during different behaviors #358
Replies: 2 comments
-
Hello and thanks for your message! I may need a bit more context to understand what type of model you would want to setup, but I can try to guess. We have ways to model responses to individual events. Modeling a temporal predictor that model a response to the event "start epoch" and "end epoch" can be done by creating a one-hot vector that is 1 when the event happens and 0 otherwise. Then, this vector should be convolved with a basis to create the model design matrix. This would be equivalent of using the spike times as predictors, as you first count the spikes, and then convolve the counts, see this tutorial for example). One can also create the boolean predictor that you are describing and convolve that instead. Unfortunately we don't have a tutorial showing how to do that, but it is fairly simple to do with import numpy as np
import pynapple as nap
import nemos as nmo
import matplotlib.pyplot as plt
# some start/end of stimuli
stimulus_a = nap.IntervalSet([0, 5, 10], [3, 8, 13])
stimulus_b = nap.IntervalSet([1, 7, 11], [2, 8, 12])
# simulate some spike times for a neuron
spk = nap.TsGroup({1: nap.Ts(np.sort(np.random.uniform(0, 15, 20)))})
# count spikes
counts = spk.count(0.01)
n_samples, n_neurons = counts.shape
# initialize predictors
predictors = nap.TsdFrame(t=counts.t, d=np.zeros((n_samples, 2)), columns = ['stimulus A', 'stimulus B'])
# Check whether there is a flash within a given bin of spikes
idx_a = stimulus_a.in_interval(counts)
idx_b = stimulus_b.in_interval(counts)
# Replace everything that is not nan with 1 in the corresponding column
predictors.d[~np.isnan(idx_a), 0] = 1
predictors.d[~np.isnan(idx_b), 1] = 1
plt.subplot(211)
plt.title("stimulus")
plt.plot(predictors)
plt.subplot(212)
plt.title("counts")
plt.plot(counts)
plt.tight_layout()
plt.show()
# define a basis and convolve
basis = nmo.basis.RaisedCosineLogConv(4, window_size=80)
# design
X = basis.compute_features(predictors) Let me know if I interpreted correctly, otherwise could you provide an synthetic data example of a stimulus and explain a bit more on how you would go about constructing the glm design? Thanks again, |
Beta Was this translation helpful? Give feedback.
-
thanks for the reply. let's say i only take two: escape and pursuit. import numpy as np
if name == 'main':
in the tutorial the basis and model are refereing to the firing. and here the basis is refereing to the behavior |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
behavior responsive cells pose an interesting challange. a normal GLM cannot handle this, maybe if we turn the behavior epochs to binomial continuous variables (on /off for every FR bin).
can you publish a guide on how to use NEMOS in this case?
Beta Was this translation helpful? Give feedback.
All reactions