Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Pre-fill answer to list question based on sequence of answers options in array

More
21 hours 12 minutes ago #272488 by vzyldd
Please help us help you and fill where relevant:
LimeSurvey version: LimeSurvey Community Edition   Version 6.15.11+250909 
Own server or LimeSurvey Cloud: Own
Survey theme/template: Inherit (fruity)
==================
I need urgent guidance please.

I have a standard array with 6 sub-questions and 2 answer options (yes/no). Depending on the sequence of yes/no answers (there are 64), the sequence is placed in 3 categories.   For this I created an equation type question (hidden) followed by a list question with the categories in a separate section.
My struggle is with the equation I am using. Just not working doesn’t matter how I try to adapt it.

I checked a previous post ( forums.limesurvey.org/forum/can-i-do-thi...d-on-previous-answer ) and the manual ( www.limesurvey.org/manual/Expression_Man...code_Variable_Naming ) that gave me some guidance. 

I need a nudge in the right direction please. 

Attached is the lss file with the first sequence option. I’ll add the rest as soon as I have the correct format of the equation.

As always, a big thank you.

Please Log in to join the conversation.

More
7 hours 54 minutes ago #272494 by vzyldd
So I got the equation format to work when defining a single sequence. I can't get it to work when adding a second sequence.

The equation I used for a specific answer sequence in my array: {LC=(if(LSM_A1==2 and LSM_A2==2 and LSM_A3==2 and LSM_A4==2 and LSM_A5==2 and LSM_A6==2,"3",""))}

This will prefill the next list question (question code -
LC in separate group) with option 3.

I need to combine 64 different sequences in a single equation e.g.
{LC=(if(LSM_A1==2 and LSM_A2==2 and LSM_A3==2 and LSM_A4==2 and LSM_A5==2 and LSM_A6==2,"3",""))} or {LC=(if(LSM_A1==2 and LSM_A2==2 and LSM_A3==2 and LSM_A4==2 and LSM_A5==2 and LSM_A6==1,"2",""))} or ......etc.

I have no idea how to combine these .

Please Log in to join the conversation.

More
5 hours 20 minutes ago - 5 hours 19 minutes ago #272501 by Joffm
Hi,
first you should explain better the algorithm.
I only see in the classification 
A: 8-10
B: 5-7
C: 1-4
Which Yes/No combinaions  lead to which result?
Do you only sum up certain values? Or what do you do to reach a "10"?

Well, some ideas:
Use functions like countif, countifop, sumif.
Use an appropriate coding, e.g. if you sum something it's better to use "0" and "1" instead of "1" and "2"
Using "0" and "1" you could join the six values to a string that you see as a binary number from "000000" = 0 to "111111" = 63

Anyway, as long as I do not understand the logic "When is the outcome A? When is it C?"
I can't say more.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 hours 19 minutes ago by Joffm.

Please Log in to join the conversation.

More
2 hours 41 minutes ago #272507 by vzyldd
Thank you Joffm for making me realise I’m running around in circles and breaking my head by not logically looking at the issue properly. Like they say, you need to understand the problem yourself before you can find a solution. Old age does that.

The survey has 3 questions. First question is an array type, 6 sub-questions (A1...A6), 2 answer options (Yes/No); second question is the equation type question; third (in a separate group) is the list question with the 3 categories.

The array can have different Yes/No answer sequences and these sequences were provided by the client. I have a predefined list with 64 sequences thus do not have insight into how they classify each sequence. All that I have is the sequence and the list question code it represents. 


I use the equation type question to prefill the list question with the category the sequence represents. The equation I use is {LC=(if(LSM_A1==2 and LSM_A2==2 and LSM_A3==2 and LSM_A4==2 and LSM_A5==2 and LSM_A6==2,"3",""))}. LC represents the list question code, LSM the array question code and A1 to A6 the sub-question options in the array (I changed it to alpha-numerical from the original to avoid uncertainty with the answer codes)

The equation works perfect for a single sequence and the list question is prefilled. My problem is when defining all the sequence options and placing it in the same equation question, nothing is prefilled in the list question. I tried it all-in-one, different equation questions each with a single equation but no luck.  

The equations I use for the sequences are as follows etc:
{LC=(if(LSM_1==2 and LSM_2==2 and LSM_3==2 and LSM_4==2 and LSM_5==2 and LSM_6==2,"3",""))}
{LC=(if(LSM_1==2 and LSM_2==2 and LSM_3==2 and LSM_4==2 and LSM_5==2 and LSM_6==1,"2",""))}

Somehow, I need to combine all the different sequence equations into one. This is where I am stuck. I don’t know if it is even possible using the equation type at all. Attached the latest lss export.

Any guidance will be highly appreciated. 

 

Please Log in to join the conversation.

More
2 hours 12 minutes ago - 2 hours 9 minutes ago #272512 by vzyldd
Joffm,

here is the routing diagram the client used to determine the categories. Not sure if this is of any help.

Last edit: 2 hours 9 minutes ago by vzyldd.

Please Log in to join the conversation.

More
2 hours 10 minutes ago #272513 by vzyldd

Please Log in to join the conversation.

More
24 minutes ago #272516 by Joffm
Hi, 
you have to use a nested IF

A. The first solution - what I already mentioned could be to join the six values in a first equation
eqJoin: {join(that.LSM.NAOK)}
Then - in a second equation you preset. Now you only use the several strings, like
{LC=if(eqJoin=="222222",3,if(eqJoin=="222221",2,if(eqJoin=="222212",3,,if(eqJoin=="222211",2,...,if(eqJoin=="111111",1,0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))})))))))}


The next solutions are based on my understanding of the routing scheme, better you'd provided the whole table with all 64 values)

B. The second solution
Now if you investigate the routing a bit, you will see that there are only 10 relevant routes.
I changed the codes from 1/2 to 0/1
X = value irrelevant
Now I see these strings as binary numbers (X->0) and get
000XXX = 0 -> 1
001XXX = 8 -> 2

1XX00X = 32 -> 1
1XX01X = 34 -> 2
1XX1X0 = 36 -> 2
1XX1X1 = 37 -> 3

01X00X = 16 -> 1
01X01X = 18 -> 2
01X1X0 = 20 -> 2
01X1X1 = 21 -> 3

This willl be a bit more work at the beginning to calculate the decimal numbers out of the binary numbers, but you only have 10 nested IFs instead of 64,
{LC=if(newValue==0,1,if(newValue==8,2,if(newValue==32,1,if(newValue==34,2,if(newValue==36,2,if(newValue==37,3,if(newValue==16,1,if(newValue==18,2,if(newValue==20,2,if(newValue==21,3,0))))))))))}

C. And the third:
You see the structure of the numbers above
If it starts with 
00: the third character defines the group (value + 1)
1:   if the fourth character is 0, the fifth defines the group (value + 1)
      if the fourth character is 1, the sixth defines the group (value + 2)
01: if the fourth character is 0, the fifth defines the group (value + 1)
      if the fourth character is 1, the sixth defines the group (value + 2)

This could lead to an equation like
{LC=if(substr(eqJoin,0,2)=="00",  sum(substr(eqJoin,2,1),1),if(substr(eqJoin,0,1)=="1",  if(substr(eqJoin,3,1)=="0",    sum(substr(eqJoin,4,1),1),    sum(substr(eqJoin,5,1),2)  ),if(substr(eqJoin,0,2)=="01",  if(substr(eqJoin,3,1)=="0",    sum(substr(eqJoin,4,1),1),    sum(substr(eqJoin,5,1),2)  ),0)))}

Well, the first is straightforward, though a bit lengthy, the second is elegant, but requires some additional calculations, the third is in my opinion the best (though to be checked)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose