#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# Creating 3 (or more) conditions - Between subject design

Hi all,

I want to create multiple conditions to implement a between-subjects design with 3 conditions.
I've succesfully implemented this with 2 conditions before. Here it was quite easy because I programmed it to set even numbers to condition 1 and uneven numbers to condition 2. Of course, this doesn't work with 3 condtions. Hence, I'm looking for an easy way to implement this.

An obvious solution would be to randomly assign people to condition 1,2, or 3 but I want to have balanced groups which is of course not garanteed when using a fully random design.

Thanks!

Eva

• Hi Eva,

The easiest way to do this is with the module (`%`) operator, which gives you the remainder of an integer division. That sounds abstract, but it goes like this:

``````0 % 3 == 0
1 % 3 == 1
2 % 3 == 2
3 % 3 == 0
4 % 3 == 1
etc.
``````

Does that make sense?

So you can create a variable `subject_group` that rotates from 0 through 2 like so:

``````var.subject_group = var.subject_nr % 3
``````

And then you use that variable in much the same way as you used `subject_parity` before.

Cheers!
Sebastiaan

• Hi, Thanks! Yes ! Will try and implement it but should be straight forward

• Quick question, I added "var.subject_group = var.subject_nr % 3" to the general script but this seems to cause problems. When I run it I get the following error: "' "subject"_"group" == 1' is not a valid conditional statement"

• Hi Eva,

This is Python code, which you need to add to an `inline_script` item. The general script contains OpenSesame script, which is a simple language that defines the experiment. But it's different from Python, which is a full programming language. See also:

Does that clear things up?

Cheers,
Sebastiaan

• Ahhh ok, no i know what python is, but didn't realise i should use the inline_script item to implement it. Thanks! Eva

• Hi all,

I study cognitive science in France and I actually learn how to work with Open Sesame
thanks to the tutorials of Sebastiaan.

I have to do exactly the same thing and I have the same problem than Eva at the last step.
I tried few things with the inline_script and the general script but nothing works correctly.

Can someone help me a little please?

Thanks!

Hugo

• Hi all, I didn't have time to look at it again until now but I also get similar issues as Hugo has I think.
If I run it as above it seems to not see subject_group as one thing but rather as "subject"_"group" which it then doesn't count as a valid conditional stateent when I later use it the way I originally used subject_parity. This could be solved by using camelCase so calling the variable subjectGroup. Then Opensesame doesnt return errors and runs, however it skips my condition sequence. Apperently now it thinks that the conditional statement "run if "subjectGroup = 1" is a valid statement but it's not met (neither are subjectGroup=2 or 3) so it just skips the experiment block and goes to the end of the experiment..

any idea on what may be going wrong?
Eva

• Hi Eva,

In run-if statements, you need to indicate that `subject_group` is the name of a variable by putting it between square brackets: `[subject_group] = 1`

Does that clear things up?

Cheers,
Sebastiaan

• Hi,

I finally found the way to make it work. Courage Eva, the solution is really not so far.

Sebastiaan thank you for all your investment for the community !!

Bye

• Hi Sebastian,

Oh god.. how dumb .. -.-" always the stupidest stuff when programming isn't it...

that basically solved the whole thing, thanks!

Eva

p.s. Hugo, nice to hear it solved your problem too

• Hi everyone,

In my previous study I only had 2 conditions and it was easy: even and odd. But this time I am trying to implement 4 conditions. As it was discussed above I added an inline script item and copied and pasted "var.subject_group = var.subject_nr % 4". Plus I created 4 runifs such as loop_1 [subject_group] = 1, loop_2 [subject_group] = 2, etc. It is perfectly working for 1 and 2 but not 3 and 4. What might be the possible reason?

Thanks,

Esra.

• Hi Esra,

this commend ``var.subject_group = var.subject_nr % 4`` will give (depending on the subject nr) the output `0,1,2,3`

Are you sure that the problem is not simply that?

At least it works for me (see attached example)

Eduard