Individual Grouping

Certain requirements in terms of the grouping for behavioral research experiments are not covered by the grouping mechanisms mentioned here. For some experiments it might be necessary to have a real random grouping, where participants are guaranteed to compete with a different participant every round and not play with the same partner twice. Another situation might be a different, pregenerated grouping for individual stepgroups.

You can create your own grouping mechanisms by using the grouping API functionalities. Below you can see an example on how to use these. Assuming that a pregenerated grouping with two participants each was used for the first part of the experiment, we would like to have ten participants per group for the rest of the experiment. Participants from the same group stay together in the same group.

$groups = $groupApi->getGroupLabels();

$participantArray = array();
foreach ($groups as $group)
{
    $groupMembers = $groupApi->getGroupMemberLabels($group);

    foreach($groupMembers as $groupMember)
    {
        if (count($participantArray) < 10)
        {
            $participantArray[] = $groupMember;
        }
        else
        {
            $emptyGroups = $groupApi->getEmptyGroupLabels();
            $groupApi->addGroupMembers($participantArray, $emptyGroups[0]);
            $participantArray = array();
        }
    }

    $groupApi->removeGroupMembers($groupMembers, $group);
}

Random Re-Grouping

If you are looking to randomly regroup participants after a certain stage you can take a look at the following example. Please note that this example is used under the assumption that you created an experiment without pregenerated grouping. Also, this should only be used in a lab experiment inside of a Sync Everyone step at the beginning of the new stepgroup. MTurk experiments require more flexibility in terms of the grouping.

$emptyGroups = $groupApi->getEmptyGroupLabels();
$participants = $participantApi->getParticipantLabels();

// randomize the grouping by shuffling participants

shuffle($participants);

// define the group size that you want to have
$groupSize = 2;

foreach ($emptyGroups as $group)
{
    $newGroupMembers = array();
    for ($i = 1; $i <= $groupSize; $i++)
    {
        if (count($participants) > 0)
        {
            $newGroupMembers[] = array_pop($participants);
        }
    }

    $groupApi->addGroupMembers($newGroupMembers, $group, 'stepGroupLabel', 'stepGroupLoop');
}