Randomly select control items from list


Author
Message
Ine Van der Cruyssen
Ine Van der Cruyssen
Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)
Group: Forum Members
Posts: 9, Visits: 75
Hi everyone,

I'm running into some problems when programming my experiment.
What I want to do is that participants see a checklist with 16 items and have to check the ones that are significant to them. The ones that are checked are removed from the list and from the items that remain, we want to randomly select 4 items that will serve as control items in the experiment.
However, I have no idea how to do the last step. I don't seem to manage to randomly select 4 items (no repeat) and make them work as control items.
I would be very happy if someone could help me out. 

I attached my script. The part where I'm stuck is line 376.

Thank you in advance!
All the best,
Ine


Attachments
ExpNathalie.iqx (107 views, 63.00 KB)
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K
Ine Van der Cruyssen - 3/7/2022
Hi everyone,

I'm running into some problems when programming my experiment.
What I want to do is that participants see a checklist with 16 items and have to check the ones that are significant to them. The ones that are checked are removed from the list and from the items that remain, we want to randomly select 4 items that will serve as control items in the experiment.
However, I have no idea how to do the last step. I don't seem to manage to randomly select 4 items (no repeat) and make them work as control items.
I would be very happy if someone could help me out. 

I attached my script. The part where I'm stuck is line 376.

Thank you in advance!
All the best,
Ine


First you need to figure out how many items are left in the item element. Use the itemcount property.
Then you need to set up a list with that many item numbers.
Then you need to sample four random item numbers from that list.

<checkboxes significantLastname>
/ caption="שם פרטי:"
/ required = false
/ range = (0,12)
/ options=(    "Lastname1", "Lastname2", "Lastname3", "Lastname4", "Lastname5", "Lastname6", "Lastname7", "Lastname8",
            "Lastname9", "Lastname10", "Lastname11", "Lastname12", "Lastname13", "Lastname14", "Lastname15", "Lastname16")
</checkboxes>

<surveypage significantLastname>
/ caption = "Please check the names that are significant to you or similar to a name that is significant to you. You can pick max. 12 names."
/ questions = [1 = significantLastname]
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
/ itemfontstyle = ("Arial", 3%, true, false, false, false, 5, 1)
/ responsefontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txcolor = (0, 0, 0)
/ showpagenumbers = false
/ showquestionnumbers = false
/ ontrialend = [
        if(checkboxes.significantLastname.checked.1) {
item.Lastnames.removeitem(1);
};
if(checkboxes.significantLastname.checked.2) {
item.Lastnames.removeitem(2);
};
if(checkboxes.significantLastname.checked.3) {
item.Lastnames.removeitem(3);
};
if(checkboxes.significantLastname.checked.4) {
item.Lastnames.removeitem(4);
};
     if(checkboxes.significantLastname.checked.5) {
item.Lastnames.removeitem(5);
};
     if(checkboxes.significantLastname.checked.6) {
item.Lastnames.removeitem(6);
};
     if(checkboxes.significantLastname.checked.7) {
item.Lastnames.removeitem(7);
};
     if(checkboxes.significantLastname.checked.8) {
item.Lastnames.removeitem(8);
};
     if(checkboxes.significantLastname.checked.9) {
item.Lastnames.removeitem(9);
};
     if(checkboxes.significantLastname.checked.10) {
item.Lastnames.removeitem(10);
};
     if(checkboxes.significantLastname.checked.11) {
item.Lastnames.removeitem(11);
};
     if(checkboxes.significantLastname.checked.12) {
item.Lastnames.removeitem(12);
};
     if(checkboxes.significantLastname.checked.13) {
item.Lastnames.removeitem(13);
};
     if(checkboxes.significantLastname.checked.14) {
item.Lastnames.removeitem(14);
};
     if(checkboxes.significantLastname.checked.15) {
item.Lastnames.removeitem(15);
};
     if(checkboxes.significantLastname.checked.16) {
item.Lastnames.removeitem(16);
};
]
/ ontrialend = [
    var i = 0;
    while (i < item.Lastnames.itemcount){
        i += 1;
        list.control.appenditem(i);
    };
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    ]
</surveypage>

<list control>
/ selectionrate = always
</list>



Ine Van der Cruyssen
Ine Van der Cruyssen
Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)Associate Member (85 reputation)
Group: Forum Members
Posts: 9, Visits: 75
Dave - 3/7/2022
Ine Van der Cruyssen - 3/7/2022
Hi everyone,

I'm running into some problems when programming my experiment.
What I want to do is that participants see a checklist with 16 items and have to check the ones that are significant to them. The ones that are checked are removed from the list and from the items that remain, we want to randomly select 4 items that will serve as control items in the experiment.
However, I have no idea how to do the last step. I don't seem to manage to randomly select 4 items (no repeat) and make them work as control items.
I would be very happy if someone could help me out. 

I attached my script. The part where I'm stuck is line 376.

Thank you in advance!
All the best,
Ine


First you need to figure out how many items are left in the item element. Use the itemcount property.
Then you need to set up a list with that many item numbers.
Then you need to sample four random item numbers from that list.

<checkboxes significantLastname>
/ caption="שם פרטי:"
/ required = false
/ range = (0,12)
/ options=(    "Lastname1", "Lastname2", "Lastname3", "Lastname4", "Lastname5", "Lastname6", "Lastname7", "Lastname8",
            "Lastname9", "Lastname10", "Lastname11", "Lastname12", "Lastname13", "Lastname14", "Lastname15", "Lastname16")
</checkboxes>

<surveypage significantLastname>
/ caption = "Please check the names that are significant to you or similar to a name that is significant to you. You can pick max. 12 names."
/ questions = [1 = significantLastname]
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
/ itemfontstyle = ("Arial", 3%, true, false, false, false, 5, 1)
/ responsefontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txcolor = (0, 0, 0)
/ showpagenumbers = false
/ showquestionnumbers = false
/ ontrialend = [
        if(checkboxes.significantLastname.checked.1) {
item.Lastnames.removeitem(1);
};
if(checkboxes.significantLastname.checked.2) {
item.Lastnames.removeitem(2);
};
if(checkboxes.significantLastname.checked.3) {
item.Lastnames.removeitem(3);
};
if(checkboxes.significantLastname.checked.4) {
item.Lastnames.removeitem(4);
};
     if(checkboxes.significantLastname.checked.5) {
item.Lastnames.removeitem(5);
};
     if(checkboxes.significantLastname.checked.6) {
item.Lastnames.removeitem(6);
};
     if(checkboxes.significantLastname.checked.7) {
item.Lastnames.removeitem(7);
};
     if(checkboxes.significantLastname.checked.8) {
item.Lastnames.removeitem(8);
};
     if(checkboxes.significantLastname.checked.9) {
item.Lastnames.removeitem(9);
};
     if(checkboxes.significantLastname.checked.10) {
item.Lastnames.removeitem(10);
};
     if(checkboxes.significantLastname.checked.11) {
item.Lastnames.removeitem(11);
};
     if(checkboxes.significantLastname.checked.12) {
item.Lastnames.removeitem(12);
};
     if(checkboxes.significantLastname.checked.13) {
item.Lastnames.removeitem(13);
};
     if(checkboxes.significantLastname.checked.14) {
item.Lastnames.removeitem(14);
};
     if(checkboxes.significantLastname.checked.15) {
item.Lastnames.removeitem(15);
};
     if(checkboxes.significantLastname.checked.16) {
item.Lastnames.removeitem(16);
};
]
/ ontrialend = [
    var i = 0;
    while (i < item.Lastnames.itemcount){
        i += 1;
        list.control.appenditem(i);
    };
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    item.controlItems.appenditem(item.Lastnames.item(list.control.nextvalue));
    ]
</surveypage>

<list control>
/ selectionrate = always
</list>



Great!

Thank you so much!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search