Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

selecting randomization lists in Latin Squared designs

Hi there!

most experiments are Latin Squared. Suppose you have a 2x2 within subject design, you will have a total of 4 lists that you wish to rotate between subjects (and therefore obtain that each item was seen in all conditions across 4 subjects).

Therefore, I was wondering is there an easy way to select such list directly from the start of the experiment? So, you input the name of the subject AND select the randomization lists? I guess it might be possible to do so by specifying a variable in the dataframe for the trial sequence that you could call and subset the part of the dataframe needed, but I am not quite sure how to do that. Otherwise, for a 2x2 design, I would end up with four different versions of the experiment, which does not sound right.

I am using OpenSesame 3.0.7 because I need to record speech.

thanks a lot for your kind help!

Moreno

Comments

  • morenomoreno Posts: 21
    edited October 2016

    mmm ... as it seems I was unsuccessful, let me try again, perhaps, I will be clearer this time.
    So, suppose you have 24 items in a 2x2 (within subject) Latin Squared design.

    The only way you have to present 24 items (without repetition) in all four conditions, is to divide them into 4 lists (a, b, c, d), and then have 4 subjects each seeing only 1 list. It is quite a classic problem I believe.

    I am using OpenSesame 3.0.7, and I have found a workaround solution to select such lists (without having to duplicate the experiment 4 times).
    (http://www.chrislongmore.co.uk/screencasts/html/counterbalance-opensesame.html)

    What I do thought (as explained in the tutorial linked above), it is literally to copy the block sequence 4 times (one for each list) and then have a variable (e.g., called rblock), which I input at the beginning of the experiment using a text form, that I use to select the block to run in the experiment sequence. I mean, this solution works, but if you have 12 different conditions (because of counterbalancing other co-variates) plus a division into blocks (e.g., easy and hard), you end up with 24 copies of the block sequences, which makes a ridiculously redundant experiment.

    This solution is admittedly quite ugly, so I hope someone could suggest me something better and more elegant by using in line scripts.

    I believe, but I might be wrong, that I should be able to have just a single block sequence (or perhaps two at the most -- if the experiment is divided into an easy and a hard block) with all trials for all the lists in it (or to be read from a .csv file), and then use the variable (rblock) that I input at the beginning of the exp., to select only the relevant part of the dataframe (i.e., the randomization list) to display my stimuli.

    I have been looking around the internet and in the forum, and although, there are some solutions, I am not quite sure I have really fully understood them. So, I truly appreciate a very concrete, simple (working) example, something like this that I found for psychopy (https://groups.google.com/forum/#!topic/psychopy-users/3tbsPRvb9WY) but applied to opensesame.

    If that's not possible, no problem. I will live with my ugly solution for now ...

    thanks a lot for any time you would ever spend thinking about this!

  • eduardeduard Posts: 977

    Hi Moreno,

    Depending on the details of your experiment, it could work for you if you had only one generic loop, in which you present condition 1 through 4. In the beginning of your experiment you could have your lists hard coded and use the subject number (var.subject_nr) as identifier as for which element of a list you want to use for this particular subject. Once selected, you could proceed to your trial sequence and present the stimuli that fit the first chosen condition (not necessarily the first condition in your terminology), so for example, if you have four conditions A, B, C and D, you set the order of them in the beginning of the script and assign the respective identifier (A,B,C or D) to variables you will use in the experiment (cond1, cond2,cond3, cond4) . Importantly, in your main trial/block loop, you use latter variable. So that regardless of the order of conditions (a,b,c,d) you can code the blocks generically. Of course this requires that the conditions are comparable to some extent. Presenting words in own condition and pictures in another, might be a little tricky (though far from impossible).

    Hope this helped.

    Eduard

    Thanked by 1moreno
  • morenomoreno Posts: 21

    Hi Eduard,

    thanks for your response. I am not completely sure I really understood what you are suggesting.

    Let's do this... let's work on a very simple example together, if you | anyone else would be so kind to help out.

    I have attached a very simple 'experiment' called latin square, which simply present words selected from two lists (1,2). I modeled it on the basis of what I understood from your response, as well as, following this other post.

    http://forum.cogsci.nl/index.php?p=/discussion/814/open-nested-lists-functionality

    It does not do really what I want, and also again, I do not think this is an elegant solution. It still implies repeating the same block of code for every randomization list we might have, so a 2x2 Latin Square Design will have 4 blocks of identical code, a 2x2x2 would have 12, and so on. This is in essence, identical to the solution posted above.

    I am trying instead to imagine a solution where you really have only one structure of your experiment, and then you feed only the list of items you want a subject to see. It would be great to have a mock up experiment that does this, as latin squaring, it is really a very common thing to do.

    thanks a lot!!

  • eduardeduard Posts: 977

    Hi Moreno,

    I hope I haven't misunderstood you.
    Attached you can find an example of the structure that I had in mind.

    Let me know whether you like it or not (and sorry for the late response).

    Eduard

    Thanked by 1moreno
  • morenomoreno Posts: 21

    Hi Eduard,

    Thanks and sorry for the late response. I have been working on it, and now I have a final solution.
    I wanted a solution that was somewhat more general than what you have proposed.

    I simply wanted to choose a subset e/o block of stimuli from a .csv dataset.
    Such dataset should already be organized by the researcher outside of OpenSesame, with whichever randomization Latin Squaring etc. he/she wants, and he/she accesses the randomization list wished to be presented, at the start of the experiment.

    I have attached the final product, which does what I want. You can choose between two lists (1,2).

    A couple of caveats for whoever may end up using this code:

    a) I have used pandas and numpy to extract and process the .csv.
    However, very often the versions available are in conflict (at least that's what happened to me). So make sure they are compatible.

    b) You need to change the file path to load your .csv data from the inline called (define_list_practice, line 16)

    I hope somebody else would benefit by this ...

    Moreno

  • morenomoreno Posts: 21

    Dear developers,

    I have used this solution with OpenSesame 3.0.7. I knew that it was a hack, but it worked. I have another experiment running fine on it.

    Now, I am designing another experiment, and I would like to move to the latest versions of OpenSesame, and I have tried it with the last one 3.1.6.

    This solution does not work any longer. The problem is that OpenSesame does not accept the way I input and subset the dataset, which is by loading and subsetting it through an in_line script. It always default back to the one specified in the block loop. No matter what I do, it would always consider that dataframe.

    Guys, seriously, I believe this is a straightforward not so strange thing to do (read above), but to reiterate, I want to input the dataset only once, then have a variable in it, where I specify the randomization list I am interested. I want to use such variable to subset the dataset ONLY to the list I want to run.
    Why it looks so difficult? What am I doing wrong?

    NB, now also the bulky solution (http://www.chrislongmore.co.uk/screencasts/html/counterbalance-opensesame.html) that seemed to work, it is not working any longer either.

    I have honestly spent two solid days reading all around, but: (a) I do not understand how I can use datamatrix (or pandas) within in_line script to do this, (b) I am not sure I understand the difference between dm and live.dm, and how can I manipulate either of the two (perhaps i do not understand where is the dataframe stored ... but especially how can I access it), but I could not find documentation that guides a user to get from a dataset containing all possible randomized lists of material, just a subset (i.e., the list I want to present to a specific subject), and run the experiment fine.

    I believe that if this problem is clearly solved once, it would be very beneficial to many users, and not just me. I cannot believe I am the only one creating his randomization lists outside of opensesame, and simply wanting to subset the one to run without having to duplicate the experiment code.

    Forgive me if the solution is somewhat trivial, but I am completely lost now.

    Thanks for your time and kind help,

    Moreno

    PS @sebastiaan (please help me :-))

  • sebastiaansebastiaan Posts: 2,813

    Hi Moreno,

    It's a long discussion (which I haven't read entirely), but there are few fairly straightforward ways to implement counterbalancing. Both options below require OpenSesame ≥ 3.1.

    Selecting a source file based on subject number

    In the loop you can select a source file. Say that you have created three stimulus lists for counterbalancing (list0.csv, list1.csv, and list2.csv), then you could rotate these lists across participants by entering the following in the File input:

    list[=var.subject_nr % 3].csv
    

    So you're embedding a short Python statement that takes the modulo 3 of the subject number. See also:

    Selecting rows from the loop table based on subject_nr

    Alternatively, you could create a loop table that has the information in it for all participants, and then select a subset of rows from this table. Say that you have a column called counterbalancing that again goes from 0 to 2, then you could select the relevant rows like so:

    items['block_loop'].dm = items['block_loop'].dm.counterbalancing == var.subject % 3
    

    This would go into the Prepare phase of an inline_script that preceded block_loop. This changes the original DataMatrix (before randomization, repeating, etc) so that it contains only those rows where the counterbalancing column matches subject_nr modulo 3. (To clarify: the live_dm is the DataMatrix after randomization, repeating, and other loop operations.)

    In most cases, Option 1 seems easier to me.

    Cheers!
    Sebastiaan

    Thanked by 1moreno

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • morenomoreno Posts: 21

    yes! indeed. exactly, a simple solution for a simple problem! it worked like charm. thank you so much!
    p.s. I prefer to use an external variable list rather than subject nr.

    Moreno

Sign In or Register to comment.