Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Question Randomization on One Page Using Forms

edited February 2013 in OpenSesame

I would like to present multiple questions in randomized order on one page using Forms. I was able to use the open sesame code to create a page with multiple question, but I have not been successful in getting it to randomize the order of question presentation. If I create multiple variables with a list of all the questions, then that creates the problem of having some questions asked more than once and others skipped. Is there a way to sample randomly from a variable with the specification that previously called up levels of that variable should not be sampled? Could you point me in the right direction for a solution to my problem.

Thanks and thank you for Open Sesame.

Jason

Comments

  • edited February 2013

    Hi Jason,

    Is there a way to sample randomly from a variable with the specification that previously called up levels of that variable should not be sampled?

    Generally speaking, yes. In Python you would use the pop() function to take the last item out of list. If you shuffle the list first, this will give you random sampling without replacement:

    from random import shuffle
    l = [1,2,3,4] # Create a list
    shuffle(l) # Shuffle the list order
    while len(l) > 0: # While the list is not empty
        val = l.pop() # 'Pop' the first item
        print val # And print it
    

    However, I suspect that this might not be what you have in mind. If not, could you perhaps describe in more detail what you are trying to do and how you have currently set up your experiment?

    Cheers,
    Sebastiaan

  • edited February 2013

    I'm running an experiment with some self-report measures at the end. I would like to randomize the order of presentation of the self-report questions so that each participant will get the same questions presented in a randomized order, on the same page. For instance the order of question 1, 2, and 3 below would be determined randomly, but each participant would get every question on one screen.


    from libopensesame import widgets form = widgets.form(self.experiment, cols=[1,2,1], rows=[1,1,1,1,1]) title = widgets.label(form, text='Indicate how much you agree with the following statement') question1 = widgets.label(form, text='', center=False) question2 = widgets.label(form, text='', center=False) question3 = widgets.label(form, text='', center=False) ratingScale1 = widgets.rating_scale(form, var='question1', nodes=['Agree', "Don't know", 'Disagree']) ratingScale2 = widgets.rating_scale(form, var='question3', nodes=['Agree', "Don't know", 'Disagree']) ratingScale3 = widgets.rating_scale(form, var='question3', nodes=['Agree', "Don't know", 'Disagree']) image_button = widgets.image_button(form, path=self.experiment.get_file('nextbutton.png'), var='response') form.set_widget(title, (0,0), colspan=2) form.set_widget(question1, (0,1)) form.set_widget(question2, (0,2)) form.set_widget(question3, (0,3)) form.set_widget(ratingScale1, (1,1)) form.set_widget(ratingScale2, (1,2)) form.set_widget(ratingScale3, (1,3)) form.set_widget(image_button, (1,4)) form._exec()
  • edited 6:19AM

    Ah, I see. So you want to present the same three questions on a single form, but randomize the order of the questions. This is quite easy to accomplish, especially since you are using Python code already. First you create a list of row indices ([1,2,3]). You shuffle this list, to get a random order of row indices (e.g. [3,1,2], and then use this list to specify the actual row indices of the question and ratingScale widgets (i.e., rows[0], etc.).

    Hope this helps!

    from libopensesame import widgets
    from random import shuffle
    
    # Create a list of row indices for the questions (1, 2, and 3)
    # and shuffle the list. When specifying the rows for the
    # questions, you can then use rows[0], rows[1], and rows[2], to
    # get a randomized order.
    rows = [1,2,3]
    shuffle(rows)
    
    form = widgets.form(self.experiment, cols=[1,2,1], rows=[1,1,1,1,1])
    title = widgets.label(form, text='Indicate how much you agree with the following statement')
    question1 = widgets.label(form, text='q1', center=False)
    question2 = widgets.label(form, text='q2', center=False)
    question3 = widgets.label(form, text='q3', center=False)
    ratingScale1 = widgets.rating_scale(form, var='question1', nodes=['Agree', "Don't know", 'Disagree'])
    ratingScale2 = widgets.rating_scale(form, var='question3', nodes=['Agree', "Don't know", 'Disagree'])
    ratingScale3 = widgets.rating_scale(form, var='question3', nodes=['Agree', "Don't know", 'Disagree'])
    image_button = widgets.image_button(form, path=self.experiment.get_file('nextbutton.png'), var='response')
    form.set_widget(title, (0,0), colspan=2)
    form.set_widget(question1, (0,rows[0]))
    form.set_widget(question2, (0,rows[1]))
    form.set_widget(question3, (0,rows[2]))
    form.set_widget(ratingScale1, (1,rows[0]))
    form.set_widget(ratingScale2, (1,rows[1]))
    form.set_widget(ratingScale3, (1,rows[2]))
    form.set_widget(image_button, (1,4))
    form._exec()
    

    PS. I removed your last post, as it seemed to only contain the code that you already posted.

  • edited 6:19AM

    Thank you! That does exactly what I need it to do! It randomizes the order of question presentation while also keeping the rating scales attached to their respective questions. I was somewhat concerned that the latter part wasn't going to happen, but it did.

  • edited 6:19AM

    This is a quite common task and should somehow be implemented within the gui items / questionnaire possibilites.

  • edited 6:19AM

    HI @refuzee,

    if you believe this is something that should be built-in OpenSesame by default, you can request it in the wishlist. There, suggestions for future improvements of OpenSesame are very welcome and collected centralized.

    Thanks,

    Eduard

Sign In or Register to comment.