How to Compute Columns in JASP

One of our latest releases, JASP 0.9.1, came with an exciting new feature: the ability to compute new variables. This post demonstrates how to use this new functionality by going over a few examples.

When analyzing data, it can come in handy to create an extra column that contains a new variable, obtained from one or several of the existing variables by means of some transformation. For instance, when you have a repeated measures design you may want to compute a difference score, when your variables are not normally distributed you may want to apply a log transformation, etc.

Setting Up the Computed Column

When a data set is opened in JASP 0.9.1 (or higher), there will be a plus sign (“+”) at the far right of the data set, next to the rightmost column.

Clicking on the “+” sign opens up a small dialog window where you can

  • enter the name of the new column,
  • select whether you would like to enter the R code directly or use the drag and drop interface, and
  • select what data type is required.

Next you can click create to start computing your new variable. The compute-columns functionality in JASP has two interfaces: the Drag and Drop Column Creator and the R Column Creator. To illustrate their use, we will take a couple of data sets from the JASP Data Library.

The Drag and Drop Column Creator

To create a column with the drag and drop interface, select the hand icon when setting up the new variable as shown above. After clicking create, the drag and drop interface appears.

If you have used JASP’s filtering functionality before, this probably looks familiar to you. On the left hand side, you can see all variables in your data set, including the column you have just added. Above the box, there is a selection of various mathematical operators, and on the right hand side, a selection of transformations. You can scroll the left and right hand options to see more variables or more functions, respectively. The box in the middle is where new columns can be computed.

For our first example, we are going to use the Moon and Aggression data set (Data Library -> T-Tests). The two variables show the average number of disruptive behaviors of dementia patients during full moon days (‘Moon’) and other days (‘Other’). We want to create a column of data showing the difference between those two variables. Once you have entered the Drag and Drop Column Creator, the name of your new variable will appear in the spreadsheet window. Now, the mathematical operation needs to be defined. We drag ‘Moon’ into the equation box, drag the ‘minus’ sign down and then drag in ‘Other’. As can be seen in the GIF below, this can also be done by clicking instead of dragging. Finally, click on Compute column to apply your formula.

A nice feature of the drag and drop interface in JASP — accessible when computing columns as well as creating filters — is that if you made a mistake while assembling your formula (i.e., using the wrong variable or operator), you can remove the item by dragging it into the bin in the bottom right corner. To remove everything inside the box at once, simply double-click the bin. Similarly, you can delete the computed column by clicking the bin icon in the bottom left corner next to the R icon.

In our next example, we will look at some simulated data that have a skewed distribution. To normalise the data, we can apply a log transformation by creating a new column. We drag the function log(y) into the dialog box, and then drag ‘responseTime’ between the brackets. Again, we click Compute column to apply the formula. The log-transformed data now show a much more normal distribution.

In the same way, all kinds of columns can be added. Next to the options that you may already be familiar with from the filtering functionality, you can create columns that mimic other columns but replace missing values (replaceNA(y)), columns in which random samples are drawn from a normal distribution (normalDist(mean, sd)), and much more. Furthermore, you can obtain the R code of any computed column by clicking the R symbol next to the bin in the bottom left corner.

However, if the options in the Drag and Drop Column Creator do not suffice for your purposes, or if you simply prefer R to the drag and drop interface, you can turn to the R Column Creator.

The R Column Creator

To access the R Column Creator, create a column as described above, but click the R icon instead of the hand icon. Using R code, you can now enter a formula for your computed column. Below you can see an example where we perform the same action as in the first example, this time in R. For more inspiration, see our blog post on filtering.

Editing your Computed Column and Exporting the Data

In case you need to change the formula of a previously computed column, click on the “fx” symbol to re-enter the column creator. You can edit the variable type of your computed column by clicking the variable type icon next to the “fx” symbol. When all is set, you can export your data to a .csv file by going to File -> Export Data. Then, just choose a directory and click Save.

About the authors

Mark Goss-Sampson

Mark is Associate Professor at the Department of Life and Sports Sciences at the University of Greenwich. He is also the author of "Statistical Analysis in JASP: A Guide for Students".

Tim Draws

Tim Draws is a graduate student at the Department of Psychological Methods at the University of Amsterdam. At JASP, he is responsible for marketing and communication.