Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Randomize CBC attributes with rules

I need to randomize attributes 2-10 in a CBC (out of 15). However, I have a few pairs that must travel together (2&3, 5&6, 7&9).

The off-the-shelf randomization will only allow me to randomize the entire block. Is there another way around this that will not mess up my analysis?
asked Sep 6, 2017 by userlc (195 points)
retagged Sep 6, 2017 by userlc
What version of SSI Web / Lighthouse Studio are you running?  Are you using any conditional attribute displaying, or are all fifteen attributes shown every time?
I'm running 9.3.1. I'm not using any conditional attribute displaying; everything is shown every time.
Sorry, one more follow-up: should the same randomized order apply for the whole CBC for a single respondent, or should the attributes be re-randomized for each CBC task?
The same randomization should apply for the whole CBC for a single respondent so that attributes aren't jumping around. Thanks!

1 Answer

0 votes
Create a predefined list with 15 items.  Then create a constructed list with this code:

Begin Unverified Perl
my $list = 'list1';
my @arr = (1, 2, 4, 5, 7, 8, 10, 11, 12, 13, 14, 15); # 2&3, 5&6, 7&9
for (my $i = 11; $i >= 1; $i--) {
    my $j = int(rand($i + 1));
    my $temp = $arr[$i];
    $arr[$i] = $arr[$j];
    $arr[$j] = $temp;
}
foreach my $val (@arr) {
    if ($val == 2) {
        if (rand() > 0.5) {
            ADD($list, 2);
            ADD($list, 3);
        }
        else {
            ADD($list, 3);
            ADD($list, 2);
        }
    }
    elsif ($val == 5) {
        if (rand() > 0.5) {
            ADD($list, 5);
            ADD($list, 6);
        }
        else {
            ADD($list, 6);
            ADD($list, 5);
        }
    }
    elsif ($val == 7) {
        if (rand() > 0.5) {
            ADD($list, 7);
            ADD($list, 9);
        }
        else {
            ADD($list, 9);
            ADD($list, 7);
        }
    }
    else {
        ADD($list, $val);
    }
}
End Unverified


"list1" must be replaced with the name of your predefined list.

Now add these codes to your CBC:

<style>
.cbc_top_row > td {
    border-top-width: 0px !important;
}

.cbc .inner_table > tbody > tr:first-child > td {
    border-top: 1px solid #6A6A6A;
}
</style>


<script>
$(document).ready(function(){
    var rand = [% ListValuesArray(list2) %];
    for (var i = 14; i >= 0; i--) {
        var row = rand[i];
        $('.cbc .inner_table > tbody').prepend($('.cbc_row_' + row));
    }
})
</script>


"list2" must be replaced with the name of your constructed list.
answered Sep 6, 2017 by Zachary Platinum Sawtooth Software, Inc. (81,800 points)
...