How to assign participants to two sessions

PennController for IBEX Forums Support How to assign participants to two sessions

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6640
    zawazn
    Participant

    Hi Jeremy,

    My experiment is conducted on two separate days, with counterbalanced lists. So half of the participants need to finish list A on the first day and list B on the second day. The other half of the participants need to finish list B on the first day and list A on the second day. The participants are assigned to two groups based on the ID. I will ask them to type in both their ID and session (day1 or day2) in the beginning of the experiment. I was wondering if there is a way to use the input text(ID & session) to assign them to different experimental items?

    I tried to combine if-else command in js with Sequence command in Penn.Comptroller. But it didn’t work in these ways:
    1. the value of input text cannot be stored in the variable “day”
    2. the sequence “Session” cannot be conducted.
    3. the value of constant “s” cannot be set as the value of variable “day”.

    I have pasted my codes below. I was wondering if you have some suggestions on my code? Or, is there a better way to solve this?
    I would really appreciate your help!

    Best,
    Nan

    Sequence("Session");
            const s = getVar("day");
            switch (s) {
                case 1:
                Sequence( "test",  randomize("experiment") , SendResults() , "bye" );    
                    // code
                    break;
                case 2:
                Sequence( "test2", randomize("experiment") , SendResults() , "bye" );    
                    // code
                    break;
                default:
                Sequence( randomize("experiment") , SendResults() , "bye" );
    
    Header(
        newVar("day")
        .global()
        ).log("session",getVar("day"));
        
    
    newTrial("Session",
        newText("sessionlabel")
            .text("Session:")
        ,
        newTextInput("inputsession")
            .before(getText("sessionlabel"))
            .print()
            .wait()
            .setVar("day")
        );
    • This topic was modified 3 years, 1 month ago by zawazn.
    #6642
    zawazn
    Participant

    I am using the withsquare+ID in the URL to group participants but this can only assign them to different groups. I was wondering if there is a way to insert the session number in the URL as well?

    #6643
    Jeremy
    Keymaster

    Hi Nan,

    The whole const/switch part of your code is executed at the very beginning of your experiment, at which point your Var element named day has not been set to the participant’s input yet. What’s tricky is that you do need to run Sequence at the very beginning of your experiment, because the engine won’t accept modifications to the sequence after it has started running the first trial.

    You can pass the session number in the URL, and then retrieve it from your script using GetURLParameter. If you’re already using the URL to control which group your participants are assigned, you could have your links end with server.py?withsquare=1&day=1 and do something like this:

    const group = Number(GetURLParameter("withsquare"));
    const day = Number(GetURLParameter("day"));
    
    switch (day){
      case 1:
        switch(group){
          case 1:
            Sequence( "test",  randomize("experiment") , SendResults() , "bye" );    
            break;
          case 2:
          default:
            Sequence( "test2",  randomize("experiment") , SendResults() , "bye" );    
            break;
        }
        break;
      case 2:
      default:
        switch (group) {
          case 1:
            Sequence( "test2",  randomize("experiment") , SendResults() , "bye" );    
            break;
          case 2:
          default:
            Sequence( "test",  randomize("experiment") , SendResults() , "bye" );    
            break;
        }
        break;
    }

    If you need to ask your participant to type an ID and/or a day number, I would actually add a statement to the switch checking that day is not set, and in that case execute Sequence("form")—with a trial labeled "form" which should generate a link with the appropriate parameters in the URL. Here’s an example (assuming participant IDs end with a digit and you assign group based on it being odd vs even):

    newTrial( "form" ,
      newText("Is this your first or your second session?").print()
      ,
      newScale("day", "1st", "2nd")
        .default("1st")
        .labelsPosition("right")
        .print()
      ,
      newText("Please type in your ID below").print()
      ,
      newTextInput("ID").print()
      ,
      newButton("Submit")
        .print()
        .wait( 
            getTextInput("ID").test.text(/\d/).failure( newText("Please type your ID").print() ) 
        )
      ,
      clear()
      ,
      getTextInput("ID").test.text(/[02468]$/)
        .success(
            getScale("day").test.selected("1st")
              .success( newText("<a href='server.py?withsquare=1&day=1'>Start the experiment</a>").print() )
              .failure( newText("<a href='server.py?withsquare=1&day=2'>Start the experiment</a>").print() )
        )
        .failure(
            getScale("day").test.selected("1st")
              .success( newText("<a href='server.py?withsquare=2&day=1'>Start the experiment</a>").print() )
              .failure( newText("<a href='server.py?withsquare=2&day=2'>Start the experiment</a>").print() )
        )
      ,
      newButton().wait() // Wait until a click on the link refreshes the page
    )

    Let me know if you have questions

    Jeremy

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.