Subject session randomisation

79 views
Skip to first unread message

Spape, Michiel

unread,
Jun 25, 2020, 5:36:11 AM6/25/20
to e-p...@googlegroups.com

Hi E-Primers!

Does anyone know how you can easily randomly assign subject numbers and/or session numbers to experiments? The problem at the moment is that people doing e-prime go experiments online might give subject 1 session 1 upon request, causing potential for overwriting data files when we’re collecting data. There are somewhat labour intensive ways around this, of course, but ideally I’d just save data with a random key in there. Actually, this would be beneficial in general for anonymisation purposes.

 

Just changing subject/session in the inline doesn’t work anyway.

Any suggestions?

Best,

Michiel

David McFarlane

unread,
Jun 26, 2020, 3:11:33 PM6/26/20
to e-p...@googlegroups.com
Michiel,

I have puzzled over this too, and the possibilities seem slim. E-Prime
assigns the file name before running SessionProc, so we cannot do
anything with inline code to reassign the file names. Inline code does
work to change the Subject or Session that gets stored in the files
themselves (and might help with E-Merge), but this does not solve the
problem of overwriting files.

Best,
-- David McFarlane

Chris Broz

unread,
Jun 27, 2020, 10:15:04 AM6/27/20
to E-Prime
Is it possible to modify the startup sequence in your case to ask the user for date and time, and then include those in file names? Or even asking them to pull the number from a site before beginning (e.g., a timestamp). That might minimize overwriting. You could then treat that string as a unique subject number. It's still possible for users to submit the same values, but it seems less likely than folks accepting the default.

I just tried to insert a math function Random(Low, High) into a startup prompt as the default. It didn't work, which makes sense. Code injection into a file name seems risky. Here's an old forum post from 2010 about making custom file names in the session proc, but I'll assume it's outdated because David didn't mention it in response to your post.

Best of luck,
Chris

David McFarlane

unread,
Jul 2, 2020, 11:53:42 AM7/2/20
to e-p...@googlegroups.com
Wow, I had forgotten about that hack! Thanks for reminding me Chris. I
thought we had no more use for that hack once EP2.0.10 included its own
facility for custom data file names. But it becomes useful again for
the purpose here.

I tested the hack with EP3, running it as a InLine in SessionProc, and
it still works. I revised it a bit based on a reading of the Full
Script generated by EP3 (one can learn a lot from reading the code
generated by E-Studio!). Give this a try, and modify as desired:

Dim filenameBase As String
Dim filenameRecovery As String
Dim filenameEDAT As String
Dim fileNameExport As String
' Close data file already started in the Main() routine.
If (CLng(c.GetAttrib("Subject")) <> 0) Then c.DataFile.Close
' Construct new file or path name any way we like. May want to add code
to deal
' with potential problems such as existing (duplicate) or illegal file
names and
' non-existent directories.
' For this example, we add the date and a random number to the file name (I
' leave it as an exercise to add the time to the file name -- hint,
Windows does
' not allow colons in file names).
filenameBase = c.GetAttrib("Experiment") & "-" _
& c.GetAttrib("Subject") & "-" & c.GetAttrib("Session") _
& "-(" & c.GetAttrib("SessionDate") & "#" & PRNG.GetNext() & ")"
filenameRecovery = filenameBase & ".txt"
filenameEDAT = filenameBase & ".edat3"
fileNameExport = filenameBase & "-Export.txt"
c.DataFile.Filename = filenameRecovery
c.SetAttrib "DataFile.Basename", filenameBase
If CLng(c.GetAttrib("Subject")) <> 0 Then
' Remove any existing file; may want to add some overwrite
protection here.
If FileExists(filenameEDAT) Then Kill filenameEDAT
If FileExists(fileNameExport) Then Kill fileNameExport
If FileExists(c.DataFile.Filename) Then Kill c.DataFile.Filename
' Start new data file.
c.DataFile.Open
c.LogHeader
End If

-- David McFarlane


On 2020-06-27 Sat 10:15 AM, Chris Broz wrote:
> Is it possible to modify the startup sequence in your case to ask the user
> for date and time, and then include those in file names? Or even asking
> them to pull the number from a site before beginning (e.g., a timestamp
> <https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Fwww.unixtimestamp.com%2F__%3B!!HXCxUKc!jtE8ei6dTfjWIni-EKHAJlyrRUzwFOjDZ359UUr4Okzna9x_bJgkWxKcStg5qBOz%24&amp;data=01%7C01%7Cmcfarla9%40msu.edu%7Cd11cd7ead9664b82f03e08d81aa480eb%7C22177130642f41d9921174237ad5687d%7C0&amp;sdata=oZ9OW7xM7ppl%2FiXM7kOk1htpgwNPw0jcBqjPdMt8MxQ%3D&amp;reserved=0 >). That might minimize overwriting. You
> could then treat that string as a unique subject number. It's still
> possible for users to submit the same values, but it seems less likely than
> folks accepting the default.
>
> I just tried to insert a math function Random(Low, High) into a startup
> prompt as the default. It didn't work, which makes sense. Code injection
> into a file name seems risky. Here's
> <https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.com%2Fv3%2F__https%3A%2F%2Fgroups.google.com%2Fforum%2F*!topic%2Fe-prime%2FBWWATXRikOA__%3BIw!!HXCxUKc!jtE8ei6dTfjWIni-EKHAJlyrRUzwFOjDZ359UUr4Okzna9x_bJgkWxKcSuFI3Zec%24&amp;data=01%7C01%7Cmcfarla9%40msu.edu%7Cd11cd7ead9664b82f03e08d81aa480eb%7C22177130642f41d9921174237ad5687d%7C0&amp;sdata=Jm%2B0ILOGyISm8tNS5S9Lk5nIXgeThK75ko1hQODO02E%3D&amp;reserved=0 > an old forum
Reply all
Reply to author
Forward
0 new messages