# Experiment design question

**URL:** <https://mworks.discourse.group/t/experiment-design-question/303>\
**Category:** Support\
**Created:** [September 5, 2018, 1:51pm UTC](https://mworks.discourse.group/t/experiment-design-question/303 "2018-09-05T13:51:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 5, 2018, 1:51pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/1 "2018-09-05T13:51:49Z")

</div>

I have another question, this one a question of strategy and  
how to program something “right” with mwel. So in the current experiment  
I’m coding there are four possible conditions: stimulate/do not stimulate  
and left hemisphere LED array/right hemisphere LED array. There are also 22  
possible images that could be shown to the monkey during any one of those  
conditions.

The monkeys task, like the other experiments we’ve been coding, is to  
detect the stimulus. Gaze up for yes, down for no. The problem is, we don’t  
want to give the monkey the ability to “skip” a trial he doesn’t like by  
breaking fixation. Our first thought was to make the trial repeat  
immediately through its state system, any trials that end with a broken  
fixation get taken back to the top.

However, since the output of our task is the detection, this would give the  
monkey more information about some trials than others, possibly muddying  
our results. So Arash’s idea was to use blocks and a  
random-without-replacement selection criteria. I can think of how to make  
this with range replicators without too much trouble but there is one more  
complication: We would like there to be more trials in the left hemisphere  
than the right hemisphere. I am having trouble thinking of a good way to do  
this. Is there a way that you would recommend?

Thanks,

Simon

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 5, 2018, 2:00pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/2 "2018-09-05T14:00:47Z")

</div>

Hi Simon,

> We would like there to be more trials in the left hemisphere than the right hemisphere.

Can you be more specific about the set of parameters you want to exercise? E.g.

- Is each image presented exactly once, more than once, or potentially not presented at all?
- How is the choice whether to stimulate made? Do you want to present each image under both conditions?
- How do you determine the ratio of left hemisphere to right hemisphere stimulation?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 5, 2018, 5:34pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/3 "2018-09-05T17:34:01Z")

</div>

Hi Chris,

In answer to your questions:

- Each image should be presented more than once
- The choice of stimulation should be random, it would be good to  
present each image under both conditions but not necessary due to law of  
large numbers I think
- The ratio of left-to-right hemisphere stimulation should be  
pre-determined

Since yesterday, with some consultation with Arash I’ve made some progress  
on a design that I think will work, so this question is less urgent. My  
solution is not very elegant, however, but that may be the price of doing  
this. Let me sketch it out for you and please let me know if you can see  
any glaring problems.

List, sequential repeating 10000 times  
Block, with random without replacement selection  
Range Replicator (1-22 image index variable)  
Range Replicator (0 - 9 conditions variable)  
Trial  
If statement within trial:  
if condition = 0, 1, 2, 3 → trial is a stimulate left  
trial  
if condition = 4, 5, 6, 7 → trial is a no  
stimulate/left trial  
if condition = 8 → trial is a stimulate right trial  
if trial = 9 → trial is a no stimulate right trial  
Reject the selection variable in cases where fixation  
is broken, accept it in cases where the end of trial is reached

Let me know if you see any reason this wouldn’t work, though I implementing  
it right now and might know sooner than you can get back to me 🙂

Simon

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 6, 2018, 3:16pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/4 "2018-09-06T15:16:48Z")

</div>

Hi Simon,

I think that will work, but I’m not 100% sure it fits the requirements you described. Execution of the block won’t complete until every combination of image and condition has been accepted. If the monkey breaks fixation during the final (i.e. 220th) trial, then that trial will repeat until it succeeds, which is what you want to avoid.

> The choice of stimulation should be random, it would be good to present each image under both conditions but not necessary due to law of large numbers I think

If you’re willing to rely on random selection plus a large number of trials to ensure that all potential image/condition combinations are exercised, then you could structure the experiment like this:

```
// No enclosing list, block, or range replicators
trial (nsamples = 10000) {
    image_index = disc_rand(1, 22)
    condition = disc_rand(0, 9)
    // Same "if" statements as above. Don't bother with accept/reject, because all
    // conditions will be repeated eventually.
}

```

This would result in a more random order for the different image/condition combinations, with a constant, low likelihood of following a failed trial with the exact same image/condition. However, you would be relying on chance to ensure that all scenarios get exercised. Just another approach to consider.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 6, 2018, 6:31pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/5 "2018-09-06T18:31:36Z")

</div>

Thanks Chris, I thought of that way as well but I think the other is the  
lesser of two evils. Although there might be some information the monkey  
can glean by repeating late trials, at least he can’t just skip trials he  
doesn’t like their prevalence being increased in future trials and  
eventually repeated to him.

Another question: I am writing a small python bridge script to log  
per-trial relevant variables to a csv so we don’t have to parse through the  
mwk file. One thing I would like to keep track of is the image being  
displayed. I generate the stimulus group of all the images in a folder. Are  
they parsed alphabetically? Is this predictable and repeatable between days  
and reloads? It seems to be in my limited tests but I just want to make  
sure image 0, for example, is the first image in the folder if I sort by  
alphabet descending, and will always be so I can just record that number  
and have it mean the same thing every time as long as I don’t modify the  
contents of the folder.

Simon

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 6, 2018, 7:52pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/6 "2018-09-06T19:52:09Z")

</div>

Oh, Chris, one other question. Is there any way to access as a variable the  
time between one part of an experiment and another? e.g. starting a timer  
and stopping the timer and having the current time on it assigned to a  
variable. I just want a sanity check to make sure all the other timers and  
states are working together right.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 7, 2018, 5:46pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/7 "2018-09-07T17:46:32Z")

</div>

Hi Simon,

> I generate the stimulus group of all the images in a folder. Are they parsed alphabetically? Is this predictable and repeatable between days and reloads?

Are you using a [list replicator](https://mworks.github.io/documentation/latest/components/list_replicator.html) with a “filenames” directive? If yes, then the matching file names are sorted in “ascending collation order” (according to the man page for `glob`, the system function MWorks uses to find the matches), which should basically be alphanumeric with additional handling of symbols, and the ordering should always be the same for the same set of file names.

> Is there any way to access as a variable the time between one part of an experiment and another? e.g. starting a timer and stopping the timer and having the current time on it assigned to a variable.

Timers can’t be used for this. You need to store the value of [now()](https://mworks.github.io/documentation/latest/expressions/index.html#time-related) at each point of interest, in separate variables, and subtract them to get the elapsed time.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 9:40pm UTC](https://mworks.discourse.group/t/experiment-design-question/303/8 "2022-07-19T21:40:20Z")

</div>


