oTree Forum >

Randomize app sequence

#1 by emily255

Hi there,

I am a student and just started learning oTree. I want to design an experiment in which each player goes through all apps in the app sequence, but in a different and randomized order. Specifically:
        name='Treatment 1',
        display_name='Treatment 1',
        app_sequence=['A', 'B', 'C', 'D', 'E'],
I want to shuffle the order of apps 'C' and 'D' so that within the same session, some players would do 'C' first and then 'D', while others would do 'D' first and then 'C'.

Do you have any suggestions for me? Many thanks in advance!


#2 by Chris_oTree

This is not supported. I recommend to create 2 session configs and 2 sessions.

#3 by AndyFM

You can do it by duplicating app C and using the app_after_this_page function on the last page of app B conditional on a background variable X you set randomly to 0 or 1. 
On last page of B you put

 def app_after_this_page():
     if player.X == 0:
         return "C"
         return "D"

Your app sequence in the settings would be app_sequence=['A', 'B', 'C', 'D', 'C2', 'E']
Then respondents with X=0 will go from the last page of app B to C, while those with X=1 will be propelled to D.
Then you do the same thing on the last page of app D, sending those who already participated in C (X=0) directly to E.

It's a hassle but it's doable. I'm currently randomising the order of 4 apps..

#4 by emily255

Thanks for your reply. Is there any way I can randomize these two "sessions" to have both configs in one session?


#5 by Chris_oTree

If you need it to be 1 session, then the solution suggested by AndyFM works fine.

#6 by emily255

I see. Thank you both!

#7 by nicolas

Hello AndyFM, Did you manage to randomise the sequence of 4 apps? If so, how?

#8 by AndyFM

By doing exactly what I suggest above but expanded to four apps instead of two.
In synthesis:
- Compute the number of permutations of your apps
- Set a variable to a random number between 0 and than number -1
- Each app sequence corresponds to one of those numbers, so it's a matter of making sure that at the end of each app the right people are redirected towards the right app.

You will have to surely 1) duplicate some of those apps, 2) check whether you can reduce the number of branches by nesting some of those sequences into each other.

If someone can come up with something better than this, please share!

#9 by nicolas

Ok, thanks for the quick reply!
I have just created a new post to show my setup. 

If the configuration allows (e.g. number of questions or pages per application), a single application could be created. Python functions would then be used to control the questions displayed and the order in which they are displayed per participant, effectively packing all the applications into a single application.

Write a reply

Set forum username