I’m trying to put together an experiment where two squares are presented on the screen, one on the right side and one on the left side. Within their respective sides of the screen, the squares’ locations will be randomized and the whole square will be on the screen for each trial.

Furthermore, in each trial one of the squares will be 10 cm, and the other one will range from 9.5 to 9.9 cm. It should be randomly determined which side of the screen the 10 cm square is on. Participants should click on the smaller square, so each trial will end with a valid click on a square. There will be 50 trials total.

Anyone know how to accomplish this? So far I’ve got an excel file that has the length and width for each pair of squares (eg, 10x10 vs 9.9x9.9; 10x10 vs 9.8x9.8; 9.9x9.9 vs 10x10; etc.). Those pairings would be randomized. That bit is working for me, but I can’t figure out how to add the random locations within one side of the screen.

You need to specify the problem fully. ie what are “random locations” (explaining both words)?

eg are the locations sampled continuously between a range of values, or is there a fixed set of discrete possible locations? Do they vary both horizontally and vertically, or in just one dimension?

Is “random” an independent sampling process, or effectively a shuffled ordering of a balanced set of options? Is it a fixed pseudo-random order, or is it regenerated afresh for each subject? Are there balancing requirements or will random sampling be assumed to give sufficient control? Or…

Think the level of detail that would be required to explain your design in a paper. We can’t suggest how to implement your design without knowing what the design is.

Great response, thanks Michael! I’m trying to model this experiment based off of a previous paper and I realize I need to figure out exactly what I’m trying to accomplish before I can really get started.

I would like the locations to be random as in: both coordinates vary and are sampled from a continuous range of values. Values are selected in an independent sampling process. The x-coordinate for the right square should be greater than or equal to zero and the x-coordinate for the left square should be less than or equal to 0. The y-value for both squares can vary from the bottom to the top of the screen.

The sizes of the squares are chosen from a given set. There is always one square that is 10 cm length, and there is another square randomly selected (random selection with replacement) from the set (9.9 cm, 9.8 cm, 9.7 cm, 9.6 cm, 9.5 cm).

Both squares should be clickable and each trial ends when one of the squares is clicked on. There will be 50 trials.

Re the stimulus sizes, that could be handled via your Excel conditions file as you describe, but note that conditions files necessarily entail selection without replacement (as each row is presented the same number of times). If you want sampling with replacement, that would probably need to be handled in code.

Code for generating locations to follow:

Insert a code component (from the “custom” component panel). In its “begin routine” tab, put something like this:

# set boundaries for the stimuli, so their edges don't cross the midline or
# the edge of the screen. Tweak as needed:
min_x = 5 # assuming cm as units
max_x = 15
min_y = -10
max_y = 10
right_x = min_x + np.random.random() * (max_x - min_x)
left_x = -1 * min_x - np.random.random() * (max_x - min_x)
right_y = np.random.random() * (max_y - min_y)
left_y = np.random.random() * (max_y - min_y)
# manually save these in the data file:
thisExp.addData('left_x', left_x)
thisExp.addData('right_x', right_x)
thisExp.addData('left_y', left_y)
thisExp.addData('right_y', right_y)

Make sure the code component is above your stimulus components, so that these calculated variables are available to them before they attempt to refer to them. In their location fields, put things like this:

(left_x, left_y)

and

(right_x, right_y)

as appropriate. Set those fields to update on every repeat.

If you need to do election of stimulus sizes with replacement (as we are effectively doing here for the location attributes), then you could do exactly the same thing with the size variables instead of controlling them via the conditions file. NB though (as shown above) for all manually calculated variables, you also need to manually store them in the datafile for use during the analysis stage.