Have an idea?

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

Identifying segments for screening purposes

I need to identify segments in the screening section of a survey that will qualify for it. We have a 5-segment algorithm based on 5 questions + a constant. The segment is identified by multiplying the questions value ( 1 to 5) by its coefficient for each segment, adding them and selecting the segment with the largest sum. Of the 5 segments we need only those who fall in segment 1 or 2, so I need a way to:
- Calculate the multiplication between the questions' value and its correspondent coefficient by segment and store it
- Calculate each segment total sum of coefficients + constant and store it
- Select the segment with the largest sum and store its value (1 to 5)

Is there a way of doing this using SSI script functions or Perl in SSIweb?
asked Jan 26, 2014 by anonymous

2 Answers

0 votes
You are talking about pulling the Fischer's discriminant function calculations into SSI Web.  You can do this by creating hidden variables in a Free Format question:  write your equations in unverfied perl inside the HTML definition for each variable.  Be sure to test your equations very carefully to make sure they function as you want them to by using the generate data feature of the software.
answered Jan 28, 2014 by Keith Chrzan Platinum Sawtooth Software, Inc. (60,325 points)
0 votes
Here's a free format hidden variable example  where a variable called "HdSegment1_CODE" is created and takes the Q1 response and adds 3 to it. You can perform all mathematical functions. Pop this in the HTML box ...

<input name="HdSegment1_CODE" type="hidden" value="
[%
Begin Unverified Perl

 my $segment1_code=0;
 
  $segment1_code=VALUE("Q1")+3;

 return $segment1_code;
 
End Unverified
%]
">


Create a number of segment variables in free format hidden variables as Keith mentioned. Once you have all variables calculating correctly, you can pop them into another free format hidden question and use conditional script to determine the highest segment value or sort them in an array using Perl.
answered Jan 28, 2014 by Paul Moon Platinum (62,580 points)
Thank you! What would be the code to to determine the highest segment by their estimated value using Perl?
Let's assume you have earlier calculated 5 segment variables called QS1 / QS2 / QS3 / QS4 / QS5 (as indicated in my earlier post).

In a new free format hidden question, you can sort the 5 segment values from highest to lowest by storing them in an array, sorting them in descending order and selecting the first item (that being the highest value) from the array. See code below ...

<input name="HdHighestSegment_CALC" type="hidden" value="
[%
Begin Unverified Perl

 my @segments=(VALUE("QS1"),VALUE("QS2"),VALUE("QS3"),VALUE("QS4"),VALUE("QS5"));
 my @sortedsegments=0;
 my $highestsegment=0;
 
 @sortedsegments=sort{$b<=>$a}@segments;
 
 $highestsegment=$sortedsegments[0];

 return $highestsegment;
 
End Unverified
%]
">


So the HdHighestSegment_CALC variable has the highest segment value stored.

Create the following parent list ...

1 Segment 1
2 Segment 2
3 Segment 3
4 Segment 4
5 Segment 5

And now create the following constructed list ...

Begin Unverified Perl

if (VALUE("QS1")==VALUE("HdHighestSegment_CALC")) 
 {
  ADD("SegmentList",1);
 }

if (VALUE("QS2")==VALUE("HdHighestSegment_CALC")) 
 {
  ADD("SegmentList",2);
 }

if (VALUE("QS3")==VALUE("HdHighestSegment_CALC")) 
 {
  ADD("SegmentList",3);
 }

if (VALUE("QS4")==VALUE("HdHighestSegment_CALC")) 
 {
  ADD("SegmentList",4);
 }

if (VALUE("QS5")==VALUE("HdHighestSegment_CALC")) 
 {
  ADD("SegmentList",5);
 }

RANDOMIZE();
LISTMAX(1);
 
End Unverified


This constructed list selects the segment(s) that match the highest segment value. If there are multiple highest valued segments, one segment will be randomly selected. You can modify the constructed list accordingly if you do not like this behaviour.

Hope that gets you sorted out.
...