psychopy.org | Reference | Downloads | Github

Saving responses of two routines from distinct loops into the same/corresponding row(s) in the csv file

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win7):
PsychoPy version (e.g. 3.2.4):
Standard Standalone? Y

What are you trying to achieve?:

My experiment has two simple routines, each one has it’s own loop:
(1) “Trial”, where a subject sees a stimulus word and has to respond with a word (types it in). This is looped N times (a loop named “testing”).
(2) “Check”, here the subject sees the words he/she delivered in the Trial(s) in the same order and has to provide an additional rating for each using a rating scale (rating element), which is also looped N times (a loop named “checking”).

Problem and question

Problem: this stores the data from Trial(s) (word responses typed in by subject, RTs, etc) in separate line (first N lines) and ratings in subsequent N lines, as they are in different loops.

Question: is there a way how to make psychopy to store all the data from “Trial” and “Check” routine in the same line of the data.csv file? However, I would like to have the subjects do word responding part as the first “block” in the experiment and the “rating” part as the second, separately.

Figure: How to put the data from looped-routine “Check” (marked in blue) into the rows that has been stored from routine “Trial”?

@Martin, try unchecking the is trials option in your loops. See

https://www.psychopy.org/builder/flow.html#loops

Thank you for the reply! Unfortunately, this does not solve the problem since both loops nest trials that are not saved if I uncheck “is trials”. (I have tried to uncheck both loops, at once as well as one at a time, but then Psychopy did not store the responses of the unchecked loop(s)).

I guess I can create a two-dimensional array to store the responses from the first routine and then fill in the responses from the second routine (in the corresponding “lines”) so to “recreate” and export my own output, but I was hoping there is a simpler way around.

Do you have your two loops nested in an outer loop? This should save a new row after every iteration of the two inner loops, so long as the outer loop has is trials checked.

Again, thank you for helping me with this issue!

Nope, there is no outer loop. Just to clarify, let’s say there are 5 trials in an excel file. In the first routine (“trials”), participants respond using words - 5x, one after the another (trials are repeated via a loop named “testing”). After the first loop finishes (after 5 trials), there is another routine (“Check”). Here I would like to have the participants to see the same 5 trials again (from excel) and respond using rating scale (again looped 5x), i.e., to get additional information. Thus, the second routine should not create additional/separate data rows but extend the already created rows with additional columns and fill them (ratings). As an example, one row of the datafile would follow this structure (coma separated):

Stimulus , Word(from routine “Trial”) , RT(from “Trial”) , Rating(from “Check”) , date , time , etc…

After adding an “outer loop”, while unchecking the “is trial” from the inner loops, psychopy saves only one line (since the outer loop repetitions = 1, I don’t want to repeat the set again).

Best,
M.

As you note, you could manually manage a data structure that could be exported to give what you want. But PsychoPy can’t do this automatically for you. It might seem like an obvious feature given your particular situation, but we have to design for the general use case. e.g. what if the first loop had 20 reps and the second loop had 8 repetitions. How could PsychoPy know how to match up rows across loops? The default unfortunately has to be that each iteration of a loop gets its own line in the data file.

So if you aren’t manually crafting your own data export format, the alternative is to process PsychoPy’s exported file to get it into the shape that you need. R’s tidyverse packages, in particular tidyr, are particularly suited to this sort of task.

1 Like

Thank you Michael, I absolutely understand your point and I know that such a post-hoc “data validation” (or “re-loop”) is not a common feature in psychological experiments (but perhaps interesting). Its a good idea to use a simple syntax in R to resolve this issue, rather efficiently. Thank you four your quick and effective support!