# JavaScript custom variables

Aim

To expand EthoVision XT’s analysis capabilities by introducing calculations, custom expression, and search functions in JavaScript code embedded in EthoVision XT.

There is a wide range of questions that can be answered with custom JavaScript variables. Here we list a few examples:

▪Calculate the average of coordinates x and y of a number of subjects.

▪Calculate the number of subjects present in a zone.

▪Find the body length of an animal by taking the distance between the nose-point and the tail-base point.

▪Calculate the nearest neighbor distance in a school of fish.

▪Recalculate the coordinates of a subject based on a reference point.

▪Calculate the running average of a variable.

▪Find the time when the animal reaches 80% of correct choices in a learning test.

▪Create bins of velocity and assign each sample to one of them depending on the speed of the subject.

You can find JavaScript variables ready to use on the EthoVision XT 19 Installation package, under Drivers and tools\JavaScript custom variables. You can also find the variables on GitHub:

https://github.com/noldus/EthoVision-JavaScriptCustomAnalysis

Simply copy the code to the JavaScript window in an Analysis profile of EthoVision XT (see below). You can often customize the code by adjusting specific parameters.

Calculation

When you define JavaScript code in EthoVision XT, the software considers the data available at sample Sk and produces a value JSk (numeric, or boolean) based on the JavaScript code specified.

In the figure above, Sk represents a generic sample, which contains not only the x,y coordinates of the subjects but also their body area, elongation and mobility at the current time. You can extract a lot of information and process it in the code.

The output values can be in one of three formats:

▪A rational number, like the average of speed of three subjects. This is an example of JavaScript continuous variable.

▪A point event, like the event that occurs when a certain variable reaches the threshold of 80%. This is an example of a JavaScript event variable.

▪A state event, like the time that a variable stays above a certain threshold. This is an example of a JavaScript state variable.

Remember that the JavaScript code outputs one or more values (depending on the code) per sample. Those values are used to calculate Trial statistics and Group statistics just like any other dependent variable; for example, the average and the standard deviation.

Procedure

1.Open your Analysis profile.

2.Choose of the three options: JavaScript continuous, JavaScript event, JavaScript state.

3.Insert the code in the window that appears.

4.Run analysis as usual.