Analyzing behavioral data

Analyzing behavioral data of fish responding to stimuli

In the context of analyzing sleep and wake behavior in larval zebrafish, I am regularly confronted with the question of how to define a response to a stimulus. Larvae initiate a movement on average once a second, so disambiguating spontaneous and stimulus evoked movements is not an easy task. Also, we need to be able to disambiguate noise from actual movements.

Before I describe one way to think about this problem, let me first introduce the experiment. We monitor the behavior of larval zebrafish (the orange worm-like shapes in the sketch below) in small individual wells with a camera. Every 30 seconds, the computer sends a signal to two solenoids to deliver a mechanical “tap” to the dish, which is felt by the fish via water vibration. We record behavior for several hours. In the simplest form of the software, the computer measures the change in intensity at each pixel. Later versions of the software track the body of the fish and calculate movement statistics such as heading, displacement, and velocity. However, the basic question remains the same: how can we tell whether the fish moves in response to the stimulus, or whether it is moving spontaneously?

Behavior rig

Dealing with instances when the fish was already moving at the time of the stimulus

A basic concept is that a fish in motion has a tendency to stay in motion. So that if the fish is moving at the time of the stimulus, the probability that it will continue to move after the stimulus is large. A simple way to deal with these instances is just to throw them out and only look at instances when the fish was not moving at the time of the stimulus. Depending on the time window over which we look for a response and the average length of a movement, we have to ignore 10-30 % of the data. There isn’t really a better way to deal with this data because a fish at rest and a fish in motion are in fundamentally two different categories, and they can’t be treated the same way.


Distinguishing real responses from noise when the fish is at rest

To distinguish real responses from small spontaneous movements and noise, we need to set appropriate thresholds. Visually, we can plot the number of detected responses as a function of two factors: 1) the number of pixels in each well that changes above baseline 2) the window, in number of frames acquired by the camera, over which to evaluate the pixel change. Below, I varied only the first factor on the x-axis, and kept the second factor constant at a window length of 7 frames. You can see that for very low thresholds, all 950 stimuli elicit a “response”. But as the threshold increases, the number of detected responses falls dramatically. At a threshold of 27, the curve presents an inflexion point. This change in the shape of the curve suggests that a different phenomenon is at play, namely that above 27 pixel change at a window length of 7 frames, on the whole we capture real responses and no longer only noise.

Noise threshold

If the threshold and window length are well chosen, then the number of detected responses should not change significantly when the chosen parameters are varied over a small range. We also expect that if the chosen parameters are good, then they are applicable to a variety of experimental conditions and type of fish.


Accounting for differences in spontaneous movement rates

Different fish have widely different movement rates. This needs to be taken into account in the measurement of response rate.

To do this, in addition to calculating the response probability after each stimulus, we also compute the response probability at time points in between stimuli, using the same criteria. This gives a measure of the probability of making a movement spontaneously, whether the stimulus occurred or not. It enables to correct for the fact that some fish are much more active than others. The assumption here is that spontaneous movements and responses to stimuli can be uncorrelated. There is a danger that this method overcorrects real responses. But it is the most conservative way of to disambiguate between true responses to stimuli and spontaneous activity.

Correct responses