psychopy.org | Reference | Downloads | Github

Self Paced Reading Task with questions

@dvbridges thanks a lot, I don’t know why I couldn’t insert the code but this helped a lot thank you very much… :slight_smile:

Hi again @dvbridges one more question, again thx for the setup, but esc button doesn’t work to quit the experiment during the process. I ticked the button but nothing changed? Any idea?

Thx again… :slight_smile:

Hi @dilsah_kalay, I set the letter ‘q’ to quit the experiment, e.g.,

if 'q' in kb:
    core.quit()

however you can change this to whatever you want in the code component.

@dvbridges thx it works perfectly… another and I promise the last question, when the words pass one by one it doesn’t calculate the respose times of each word. I need those times. How can I change it?

thx again… :slight_smile:

Great @dilsah_kalay. This should solve your problem. In the code component, you create an empty list for storing your code in the Start Routine tab called rtList:

word_list = Sentence.split() 
word_list.reverse() # switch the order 
event.clearEvents()
rtList = []

Then, you need to amend the code in the Each Frame tab so that the keyboard events are timestamped, that key events are indexed correctly on every frame, and stored at the appropriate time in the rtList:

while continueRoutine:
    kb = event.getKeys(timeStamped=True)
    if len(kb) > 0:
        if 'space' in kb[0]:
            try:
                nextWord = word_list.pop()
                text.setText(nextWord)
            except IndexError:
                continueRoutine = False
                rtList.append(kb[0][1])
                break
        rtList.append(kb[0][1])
        if 'q' in kb[0]:
            core.quit()
    win.flip()

Finally, in the End Routine tab. you need to run a numpy (np) function that finds the difference between the RTs in the list, because all of the RTs in the keyboard component are stored relative to the onset of the very first presentation of a text stimuli in each trial - where a trial is a presentation of a sentence + question. Note, in this version I have inserted a fixation point at the beginning of every trial to mark the trial onset, and also a time from when to collect RTs i.e., after the first button press to remove the fixation. If this is not required, the code will need to be changed a bit. Finally, run a loop that writes the RTs to a data file, in separate columns for every word:

rtList = np.ediff1d(rtList)
for rts in range(len(rtList)):
    thisExp.addData('word_{}'.format(rts), rtList[rts])

@dvbridges Is this the same code component that we created for separating each word in text stumulus (routine), in the example you have created or another code component that we need to add into the routine???

@dilsah_kalay, its the same code component. The only other change that you may want to add is a very small addition to the text component - instead of leaving it blank you may want to add a ‘+’ to mark the trial onset. Everything else is the same, so you could just insert this code into your existing code component and it will (should) work - see attached sprt_example.psyexp (9.2 KB).

@dvbridges hey again, yeah I tried it, the experiment works but the response times for each word doesn’t come up in the excell sheet. what is the problem do you think? I attached the files…_sprt_2018_Mar_24_1658.xlsx (5.8 KB)
practice.xlsx (9.9 KB)
study.xlsx (13.4 KB)
sprt.psyexp (30.8 KB)

Hi @dilsah_kalay, I see two problems. The data is not being written to the file because the trial handler is not called thisExp as it is in my example. The trial handler takes the name of the loop. In your case the loop you are interested in for test phase is called trials. However, if you simply change the name of the trial handler in the code component, there will be an error thrown because you are using the code component in another loop - the practice phase - which takes a different name trials_2. To fix this, we can catch the error and fix the problem. So, if you add the following to the End Routine tab in the code component, the error should be fixed:

rtList = np.ediff1d(rtList)
try: 
    # practice phase
    trials_2.addData('senLen', len(rtList))
    for rts in range(len(rtList)):
        trials_2.addData('word_{}'.format(rts), rtList[rts])
except NameError:
    # study phase
    trials.addData('senLen', len(rtList))
    for rts in range(len(rtList)):
        trials.addData('word_{}'.format(rts), rtList[rts])

Just to clarify, in Builder scripts, thisExp is the name of the ExperimentHandler object for the overall script. The various loops get added as TrialHandler objects to thisExp, which kind of acts like a mother ship to the individual TrialHandlers.

So thisExp.addData() should always work, and avoids having to keep track of what particular loop you are in (and I’m not sure, but might also have the advantage that all values for that variable get added to the same column in the data file, rather than a column specific to a given loop?) So maybe there is some other issue here?

2 Likes

Thanks for the clarification @Michael. It turns out the data is actually written using the experiment handler. @dilsah_kalay, when I run your experiment there are two spreadsheet files written with this experiment, one is the practice file with no RT data (this is a csv file) the other is the practice and test data (with RT data) - they have the same name but are different file types. Could you check your data outputs? If you have the excel data, then you can ignore the amendments to the code in my previous comment.

@dvbridges thnks a lot, yeah as you said all the RTs are stored in the other file but when I made a change as you said before on the End Routine tab, it worked perfectly, as well. I think both solutions are useful for me.

Thanks you very very much for your endless help. Thanks a lot… :slight_smile:

1 Like

@dvbridges hey again sorry to bother you but in the attached file for some of the sentences no RTs are calculated. When I made the last changes in End Routine, as you told, it works for the practice trail perfectly but not for the actual study. No response times are calculated there again in the excel file. Which one is more reliable do you think?NO CHANGE IN END ROUTINE.csv (18.7 KB)
sprt.psyexp (30.7 KB)

This is the file with change as you said…
_sprt_2018_Mar_26_2145.xlsx (12.8 KB)
_sprt_2018_Mar_26_2145.csv (22.1 KB)
sprt.psyexp (31.0 KB)

The second one is much easier for me but it doesn’t calculate RTs for the actual study. Why not?

thx again…

@dvbridges actually in csv files there is always a missing data because of the sentences, so I need RTs to be written in an excel file but it doesn’t work for the study trail although it works for the practice… How can I fix it?

Hi @dilsah_kalay, sorry I am not sure if there is a problem. Attached is a csv output from the experiment you posted, without the changes that catch error because it is not actually needed. There are rows for the practice sentence, and two rows for the test sentences (because I deleted all other rows to speed it up). The columns will need to be re-organised because other response data is inserted between word RT columns, but that is ok because the data is not affected. The test sentences in my attached example are 11 and 12 words long. The first test sentence is 11 words long, so we see RTs for words 0 to 10 (making 11 RTs). The second test sentence is 12 words long, so we see RTs for words 0 to 11 (making 12 RTs). However, the first test sentence will have missing data for “word_11” (which is actually word 12 as the first word starts at zero), because the sentence is only 11 words long.

I would ignore the excel workbook, and use the RTs in the csv file (which already holds the data from the Excel workbook).

_sprt_2018_Mar_26_2118.csv (3.3 KB)

@dvbridges yeah I see what you mean but in some of the other test sentences with 18-19 word length, some problems occur in csv output. No information is written if you see the csv output data that i sent, so i think i should use excel output format not to skip any data…

@dvbridges I mean the problem is in csv file some of the infirmation is missing, especially the ones for longer sentences - I have 10 sentence information missing in the NO CHANGE file I sent -, all those rows are seen empty, isn’t it? I tried the experiment many times and same problem occurs for the same sentences.

Ah yes I see. The NO CHANGE spreadsheet is missing trials that have a semi-colon in the text. Semi-colon in Python would be used to separate statements, so this could be causing problems in how the information is being used in the trials. It may be better to remove the semi-colons from your statements.

However, I think everything is fine in the second csv output that you have posted called “_sprt_2018_Mar_26_2145.csv” as I do not see any missing data for any of the study trials, other than that which should be missing - e.g., sentences with only 8 words will not have RTs for words > “word_7”. The csv file may not have overall response times per sentence, but you can always calculate this with the AVERAGE function in Excel. Just save the csv as an excel workbook, move some columns around and use the AVERAGE function to calculate average RTs, as in the attached.

_sprt_2018_Mar_26_2145.xlsx (26.2 KB)

1 Like

@dvbridges yeah i got your point when i deleted the semi-colons everything went perfectly. Thanks a lot again, for all the help you provided, i deeply appreciate your help. thx :slight_smile:

1 Like

Thank you. I’m also trying to create a SPR experiment just like this and your solutions helped me a lot.

However, I need my sentences to appear phrase by phrase, not word by word. would you be able to help please?