| Reference | Downloads | Github

Cooporation with R


Hi, everyone.

I am trying to get a reaction time data and make a plot of reaction time at the same time.
I think there are three points to do that.

  • Is it possible to send a reaction time data from Psychopy to R?
  • Is it possible to make a plot of reaction time distribution along with the data from Psychopy.
  • Is it possible to finish the experiment according to the parameter of the reaction time distribution made by R.

I understand it is hard to answer without an example,
but I would like to know what we can do with the combination of R and Psychopy.

Thank you for your attention.


I guess you could, but it would be significantly more complicated than doing it entirely within Python from within your PsychoPy script.

If you maintain a list of reaction times, you can calculate the mean simply with:

mean_rt = sum(your_rt_list)/len(your_rt_list)

The numpy library (distributed with PsychoPy) contains functions like std() to calculate standard deviations and so on.

The matplotlib library is also distributed with PsychoPy and allows you to plot graphs as required.

There are many alternative plotting packages in Python, including seaboard which gives results that look a bit like R’s ggplot2:
but these would probably need to be installed additionally.

I’m a great fan of using R for analysis and visualisation, but for this real-time case, keeping within Python would be much easier to do than trying to interact with R in real time. PsychoPy can draw to a second window on another monitor, so the participant doesn’t need to see what you are graphing. But it would be good to only update the graph once per trial or so rather than update it continually on every screen refresh, as that would likely impair the stimulus drawing performance.