Random assignment to treatments

1,036 views
Skip to first unread message

Melissa Brooks

unread,
Oct 7, 2021, 2:24:49 AM10/7/21
to oTree help & discussion
Hi Chris and others,

I've spent some time on reading up on how to assign subjects to a random treatment. I realize that different treatments could be assigned in the same app sequence (using only one session config) or via different session configurations (different sequence of apps). 

This is the page that has largely guided me: https://otree.readthedocs.io/en/latest/treatments.html 

On this page, I'm confused on the example given where the app sequence is the same (I have a different app sequence) but subjects could be randomly assigned to different time pressures (please see attached). 

In my set-up, the first app in the sequence for the different session configs (I'm referring to treatments, in the attached example it's 'my_game_prime' and 'my_game_noprime') is the same so I thought I could randomly assign individual subjects to different treatments using the function creating_session(subsession) in the models.py of the first app. 

But when I start a room using the default 'Econ 101 class' room, I can only use one of two different session configurations which assigns subjects to that particular treatment I select. How can I randomly assign subjects to a session config? 

Thank you for your time, any help would mean a lot!

ExampleT.png

Chris @ oTree

unread,
Oct 7, 2021, 4:33:06 AM10/7/21
to oTree help & discussion
That technique of using the session config does not apply to you. Just make 1 session config (with no time_pressure entry). And randomize players in creating_session, as described at the top of the page here: https://otree.readthedocs.io/en/latest/treatments.html

Melissa Brooks

unread,
Oct 7, 2021, 5:05:03 AM10/7/21
to oTree help & discussion
Thank you for the prompt response Chris. If there's only 1 session config in the 'settings.py' file, that would mean I only have one sequence of apps. How could I assign subjects to different app sequences? Where should I include the binary variable 'time_pressure' which is set to either true or false -- in the first app of the sequence in 'models.py' where the creating_session function is defined? Where else should I include it so only those with 'time_pressure' set to true can undergo a set of apps (while those whose value is set to false undergo a different set of apps)? Thank you again and I'm sorry about my confusion,

Chris @ oTree

unread,
Oct 7, 2021, 5:17:30 AM10/7/21
to oTree help & discussion
Can you describe the difference between the apps that the 2 treatment groups go through?

Melissa Brooks

unread,
Oct 7, 2021, 5:24:54 AM10/7/21
to oTree help & discussion
The differences are in presentation formats. I am aware there I could randomly assign to treatments using one sequence of apps but this is very burdensome for my experiment. I could do it by displaying pages to those assigned to specific treatments -- for example in my two treatments, I could use the 'def is_displayed(player): return treatment == 1' but I have about 50 pages for each treatment. If instead I could have them undergo different apps, that would be a lot easier,

Melissa Brooks

unread,
Oct 7, 2021, 5:26:54 AM10/7/21
to oTree help & discussion
Is there an app-level variable like a page-level variable for displaying to subjects that meet a certain condition like in the 'def is_displayed(player):.' This could allow me to have one sequence of apps and each app in the sequence of a session config being displayed depending on treatment variable of a subject. 

Chris @ oTree

unread,
Oct 7, 2021, 5:42:20 AM10/7/21
to oTree help & discussion
Could you use an if-statement inside the templates for the 2 formats? For example:

{{ if player.time_pressure }} only time pressure people see this {{ endif }}

If it's the same thing on every page, you could make an includable template that just contains that if-statement:

{{ if player.time_pressure }} only time pressure people see this {{ endif }}

Then in each template, you include that 1 line:

{{ include 'my_app/time_pressure_stuff.html' }}

Chris @ oTree

unread,
Oct 7, 2021, 5:43:50 AM10/7/21
to oTree help & discussion
You can use app_after_this_page to skip entire apps.

Melissa Brooks

unread,
Oct 7, 2021, 5:53:52 AM10/7/21
to oTree help & discussion
Thank you Chris! After the treatment app, all subjects would go to a payment app so I could use:
@staticmethod 
def app_after_this_page(player, upcoming_apps): 
  if player.whatever: return upcoming_apps[-1]

There is one caveat -- order of pages is randomized for each subject in the app before the last app. Would I have to include the above code after every page in the 'pages.py' file? 

Melissa Brooks

unread,
Oct 7, 2021, 7:26:56 AM10/7/21
to oTree help & discussion
I figured a simple solution would be to add an app after corresponding treatments with a single page and use the app_after_this_page then. Thank you again!
Reply all
Reply to author
Forward
0 new messages