Pavlovia Surveys - How can I limit the number of participants I want to join my experiment per condition group?

Hi all,

I’m currently designing an experiment that is going to begin with participants filling out a brief screening survey that will place them into one of three groups based on their answers. I want to ensure that my three groups are evenly distributed, with the same number of participants in each group. Is there a way that I can use Pavlovia surveys to counterbalance my groups based on their answers within the survey? Ideally, if the participant’s answers were allocated to a group that was already full, a message would come up saying thanks for their time, but they could not complete the rest of the experiment due to their answers.

Would really appreciate any advice that can be given on this. Thank you in advance!

Hello

you could use either @wakecarter’s VESPR Study Portal and other VESPR tools offline or the shelf-feature of Pavlovia Using the Shelf for Multi-session testing, Counterbalancing and more online — PsychoPy v2023.1.2.

Best wishes Jens

1 Like

In this case I think you need the shelf and embedded survey routines in a PsychoPy experiment. I am giving a talk on this topic at the ATSiP conference later this month.

Basically you need to retrieve the group allocation in PsychoPy, update the shelf, and then block progression if that group has reached the maximum number. Would it fit your use case if I created a simple survey (are you in group 1, 2 or 3?) and then showed how to block progression after 5 people have picked a given group number?

2 Likes

Hi, there! Thank you both so much for your help with this. Wakecarter that sounds pretty similar to what I’m aiming for, yes. Is it possible to do that after people have chosen multiple responses? For context, I’ll be using a standardised survey to group people based on the total score they achieve based on their answers. So I’ll want one group set to totals of 1-10, another set to 11-20, etc. Is that something that can be achieved with this method?

Thank you and JensBoelte again for your help!

Yes, that will work too – maybe I should include how to score in my demo since that’s likely to be the most common use case.

Here’s my demo

Participation Cap | code | try it

This demo is a PsychoPy experiment with two embedded surveys. The first is a consent form, and the second is the Alcohol Use Disorders Identification Test—Consumption (AUDIT-C) . The AUDIT-C is scored within the survey and then participants are allocated to low and high risk groups based on a cut-off. The number of participants in each group are tracked using the shelf. For demo purposes the participation cap itself can be selected in the expInfo dialogue box.

The shelf dictionary was created as {“low risk”: 0, “high risk”: 0}

1 Like

Hi Wakecarter!

Apologies for the very late reply, but thank you so much for this solution! I really appreciate all of your help!!

Hi

I’m currently trying to implement something very similar to the experiment mentioned above. I tried the demo proposed here but I receive the following error message at the very beginning of my experiment:

when updating the value of the DICTIONARY record associated with key: [“participation-cap”]
malformed request: missing fieldName in FIELD_SET update

The rest of the experiment runs smoothly. However, it seems like it is not connecting to the shelf at all.
Since I am an absolute PsychoPy/Python beginner, I am not sure if you need any further information on my experiment to give advice on this?

Thank you so much in advance!

You need to create a shelf entry. Did you do that?

Yes I did. It works now, I think it was just that PsychoPy generally did not connect with Pavlovia because it worked after I emptied the browser cache.

However, it still does not work fully… the participants all get assigned to the “low risk” group in the shelf as defined in the beginning of the experiment but this does not get updated after the score of the questionnaire was calculated. If I download the data, there is a variable “group” and there it is correct. Any idea what could be the problem here?

Thanks in advance!

Hello

You need to show us how you try to achieve the group assignment.

Best wishes Jens

Hi Jens
Thanks for your quick reply!
I think this is the only part that I changed from wakecarters demo from above (in Begin Routine):

washing_scale = int(survey_OCI12._overallSurveyResults['block_1/score_washing_scale'])

if washing_scale > 3:
    group = 'high risk'
else:
    group = 'low risk'

thisExp.addData('group',group)
print('group',group)

Are you using a survey component called survey_OCI12 ?

I don’t recognise ._overallSurveyResults. Where does that code come from?

I suspect all participants get low risk because washing_scale is never > 3.

Try

surveyResponse = survey_OCI12.getResponse()
washing_scale = int(surveyResponse['block_1/score_washing_scale'])

print('washing_scale',washing_scale)

if washing_scale > 3:
    group = 'high risk'
else:
    group = 'low risk'

thisExp.addData('group',group)
print('group',group)

Yes, the survey component is called survey_OCI12.

I changed the code according to your suggestion but this did not change anything.

The thing is, washing_scale apparently can be > 3 (or at least ‘block_1/score_washing_scale’ can be) because I can see it in the data files and also the group assignment is correct there.
So a participant with a score of 9 is assigned to high risk group in the data but to low risk group in the shelf.

Where did ._overallSurveyResults come from?

Is print(‘washing_scale’,washing_scale)

What does your shelf entry look like?

What does your shelf code look like?

What is supposed to happen?

I found ._overallSurveyResults in this tutorial from PsychoPy Using Pavlovia Survey Responses in Experiments.

If I print washing_scale it also shows the correct score which can be > 3.

My shelf entry looks like the one from your demo:

{
“low risk”: 0,
“high risk”: 0
}

And this is the code:

participationCount = await psychoJS.shelf.getDictionaryFieldNames({key: ["participation-cap"]});

//increase the number of sessions completed by this participant
count = await psychoJS.shelf.getDictionaryFieldValue({key: ["participation-cap"], fieldName:group, defaultValue:'no sessions detected'});
count = count + 1;
if ((count > Number.parseInt(expInfo["participation limit"]))) {
    capped = true;
    cappedText = (("Thank you for your interest in this study. Unfortunately the " + group) + " group is now full.");
    } 
else {
    psychoJS.shelf.setDictionaryFieldValue({key: ["participation-cap"], fieldName: group, fieldValue :count});
    cappedText = (((("Hi there, you are participant " + count) + " in the ") + group) + " group.");
    }

psychoJS.experiment.addData("Count", count);

Basically, I want to achieve the same as you did in the demo. I want to assign participants to groups according to their score on a subscale of my survey OCI12 (which is the score on the washing_scale). I only want a certain number of participants per group and once the group is full, the experiment should terminate for other participants with those scores.
In the end I plan to add more groups not just low risk and high risk, but I think this will be easier to achieve once I fully grasped the function of the shelf. The washing_scale can range from 0 to 12 and I want to have a group of 20 participants for each of the scores.

I hope this information helps let me know if you need more. Thank you for your efforts!

Thanks to for highlighting this. I discovered I was getting the same issue in my demo.

To fix it move the shelf code form Begin Experiment to Begin Routine.

The shelf was being checked based on the default group, not the assigned group.

Now it works perfectly, thanks for the help!