Welcome, Guest
Username: Password: Remember me

TOPIC: What are the most complex Conditions anyone has implemented in LimeSurvey ...

What are the most complex Conditions anyone has implemented in LimeSurvey ... 3 years 2 months ago #63270

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
... using conditions,JavaScript, or both? And what are examples of conditional branching, validation, or tailoring that users have wanted to implement but couldn't?

ExpressionManager can support very complex equations for tailoring. I'm now working on having it be backwards-compatible to conditions, but also support more complex branching logic and assessments.

I'm hoping we can use this emerging strategy to replace the need for 80% or more of the custom JavaScript. So, I'm trying to get a sense of what users have needed JavaScript to do, such as:
(1) control visibility of questions or answer options
(2) tailor text of questions or answer options
(3) conditional validation of questions based upon prior responses
(4) create complex assessments
(5) control branching or tailoring based upon assessment results
(6) access question/answer metadata (like the text of the question or answer options; or the textual answer selected rather than the code value)
(7) conditional branching based upon regular-expression analysis of a response
(8) conditional branching based upon response latency (e.g. time taken to answer a question)
(9) conditional branching based upon path analysis or changed answers (e.g. tracking whether a respondent backtracks to change an answer and go down a different path within the survey)
(10) generation of tailored recommendations, printable reports, and/or emails based upon responses.
(11) other?

Answers to this thread will help me understand the types of question/answer attributes and functions which should be considered for ExpressionManager.

/Tom
The administrator has disabled public write access.

Re: What are the most complex Conditions anyone has implemented in LimeSurvey ... 3 years 2 months ago #63276

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1098
  • Thank you received: 247
  • Karma: 78
3JavaScript 100%-dependant cases

1) Positive and negative depression scales scoring - and + values for questions placed into differents groups, for example:
g1q3, g2q7, g3q9 = positive scale
g1q2, g2q6, g3q8 = negative positive

2) Positive and negative depression scales like the PANNS with final composite assessment scored by subtracting the negative score from the positive score.

3) Scales assessed by range of points ( 0-2 unlikely | 2-5 likely ) where 'unlikely' or 'likely' have to be stored into the db as more relevant than the score itself.
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 3 years 2 months ago by Ben_V.
The administrator has disabled public write access.

Re: What are the most complex Conditions anyone has implemented in LimeSurvey ... 3 years 2 months ago #63277

  • claudio123
  • claudio123's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Tom,

thanks for your efforts in making limesurvey even better and helping to make it easier to define conditions.

1) I'd REALLY like to be able to define forward jumps, but this might ask for a completely different concept.

2) I'd also like to be able to make conditions like this:
qu1, qu2, qu3, qu4 and qu5 are arrays, where qu1 has only one, qu2 and qu3 have 4 and qu4 and qu5 have 7 subquestions with 4 different answers (1,2,3,4) each.
I'd like to be able to define a condition that is something like:
Display qu6
- if at least 5 subquestions are answered 3, where two have to be answers to subquestions of qu5
and if at least 3 subquestions are answered "4", where one of them is an answer to qu1.

3) It would be great if this worked no matter if qu6 is on the same or on the next page (=in the same group).

You already mentioned lots of other very interesting scenarii in your post.

Thanks and
best regards
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.

Re: What are the most complex Conditions anyone has implemented in LimeSurvey ... 3 years 2 months ago #63290

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
benitov wrote:
1) Positive and negative depression scales scoring - and + values for questions placed into differents groups, for example:
g1q3, g2q7, g3q9 = positive scale
g1q2, g2q6, g3q8 = negative positive

Yes, that is easy.
benitov wrote:
2) Positive and negative depression scales like the PANNS with final composite assessment scored by subtracting the negative score from the positive score.

Also easy. I'm a colleague and friend of one of the PANNS co-authors (Lew Opler), and implemented the PANSS using another version of ExpressionManager about 5 years ago.
benitov wrote:
3) Scales assessed by range of points ( 0-2 unlikely | 2-5 likely ) where 'unlikely' or 'likely' have to be stored into the db as more relevant than the score itself.

I do this using the Equation question type as an intermediate step. First get the score from the assessment (like the Hamilton, Beck, or Zung depression inventories), then use nested if(condition,true,false) function to create the unlikely, likely, etc. categories. Since that result is a valid question type, those unlikely/likely values will be stored in the database.
The administrator has disabled public write access.
The following user(s) said Thank You: Ben_V

Re: What are the most complex Conditions anyone has implemented in LimeSurvey ... 3 years 2 months ago #63292

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Claudio-
claudio123 wrote:
1) I'd REALLY like to be able to define forward jumps, but this might ask for a completely different concept.

What kind of forward jumps do you want?

What I call relevance, below, is effectively the same as what LimeSurvey does - in my case, I'd write Not Applicable to the database in addition to making the question invisible (although I didn't do it as gracefully as LimeSurvey does).

RelevanceOverview_2011-07-09.jpg


I've found is that "relevance" can replace any forward-jumping "goto" statement using the following equation.

ConvertGotoToRelevance_2011-07-09.jpg


If you are converting a survey that heavily uses such Gotos, it is preferable to automate that conversion function, otherwise it can get a little mind-numbing, but it definitely works and can support cascading.

More often, I find a need to jump over sections - say if Q1=Y I want to skip to Q5, I'd have a relevance of Q1!=Y for questions 2-4. You don't have to put complete relevance equations for every question. For example, say you have 10 questions, and you only want to show Q2 if Q1 is Y, and only show Q3 if Q2 is Y, etc. you'd have relevance of Q1==Y for Q2, and Q2==Y for Q3, ... and Q9==Y for Q10.
claudio123 wrote:
2) I'd also like to be able to make conditions like this:
qu1, qu2, qu3, qu4 and qu5 are arrays, where qu1 has only one, qu2 and qu3 have 4 and qu4 and qu5 have 7 subquestions with 4 different answers (1,2,3,4) each.
I'd like to be able to define a condition that is something like:
Display qu6
- if at least 5 subquestions are answered 3, where two have to be answers to subquestions of qu5
and if at least 3 subquestions are answered "4", where one of them is an answer to qu1.

Since there are database fields for each of those subquestions, that should also be do-able. Say your subquestions are names sq1-sq7 (depending upon the number of subquestions for each question), you could make one long relevance equation, but I'd create a couple of hidden Equations to make it easier to debug and validate.
numQeq3 = count(qu1.sq1==3, qu2.sq1==3, qu2.sq2==3, qu2.sq3==3, qu2.sq4==3, qu3.sq1==3, qu3.sq2==3, qu3.sq3==3, qu3.sq4==3, qu4.sq1==3, qu4.sq2==3, qu4.sq3==3, qu4.sq4==3, qu4.sq5==3, qu4.sq6==3, qu4.sq7==3, qu5.sq1==3, qu5.sq2==3, qu5.sq3==3, qu5.sq4==3, qu5.sq5==3, qu5.sq6==3, qu5.sq7==3)
 
numQeq3inQ5 = count(qu5.sq1==3, qu5.sq2==3, qu5.sq3==3, qu5.sq4==3, qu5.sq5==3, qu5.sq6==3, qu5.sq7==3) 
 
numQeq4 = count(qu1.sq1==4, qu2.sq1==4, qu2.sq2==4, qu2.sq3==4, qu2.sq4==4, qu3.sq1==4, qu3.sq2==4, qu3.sq3==4, qu3.sq4==4, qu4.sq1==4, qu4.sq2==4, qu4.sq3==4, qu4.sq4==4, qu4.sq5==4, qu4.sq6==4, qu4.sq7==4, qu5.sq1==4, qu5.sq2==4, qu5.sq3==4, qu5.sq4==4, qu5.sq5==4, qu5.sq6==4, qu5.sq7==4) 

I didn't understand the last condition. Do you mean that if qu1 was answered 1, that at least one of the remaining sub-questions was also answered 1? If so,
lastCondition = count(qu2.sq1==qu1.sq1, qu2.sq2==qu1.sq1, qu2.sq3==qu1.sq1, qu2.sq4==qu1.sq1, qu3.sq1==qu1.sq1, qu3.sq2==qu1.sq1, qu3.sq3==qu1.sq1, qu3.sq4==qu1.sq1, qu4.sq1==qu1.sq1, qu4.sq2==qu1.sq1, qu4.sq3==qu1.sq1, qu4.sq4==qu1.sq1, qu4.sq5==qu1.sq1, qu4.sq6==qu1.sq1, qu4.sq7==qu1.sq1, qu5.sq1==qu1.sq1, qu5.sq2==qu1.sq1, qu5.sq3==qu1.sq1, qu5.sq4==qu1.sq1, qu5.sq5==qu1.sq1, qu5.sq6==qu1.sq1, qu5.sq7) 

Then, the relevance equation for qu6 would be:
(numQeq3 >= 5) and (numQeq3inQ5 >= 2) and (numQeq4 >= 3) and (lastCondition >= 1)
claudio123 wrote:
3) It would be great if this worked no matter if qu6 is on the same or on the next page (=in the same group).

Yes, this approach would work even if qu6 was on the same page.
The administrator has disabled public write access.

Re: What are the most complex Conditions anyone has implemented in LimeSurvey ... 3 years 2 months ago #63360

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
vadindot-

Someone else will have to answer about whether/how this could be done using LimeSurvey 1.91+.

Below is how you would do it with the ExpressionManager extensions, which may be available as early as 1.92.
vadindot wrote:
Okay, this is possibly the most complicated thing I have asked of the Limesurvey community, I am not holding my breath that it can be done.

Here are 6 questions from a survey, they all have the same answers listed below
Q4 When you think of Stouts or Porters what brand comes to mind first? (List-Radio)
Q6 What others come to mind? (Multiple - checkbox)
Q7 Which have you drunk in the past 3 months? (Multiple - checkbox)
Q15 Which Stout or Porter have you seen advertisements for in the past 3 months? (Multiple - checkbox)
Q19 Which Stout or Porter have you seen in promoted in pubs/bars in the past 3 months? (Multiple - checkbox)
Q22 (only asked if Q21=2) What Stout or Porter is your favorite? (List-Radio)

Answer List:
1 Guiness Draught
2 Murphy's Stout
3 Samuel Adams Imperial Stout
4 Beamish Stout
5 Courage Imperial Russian Stout
6 Marston's Oyster Stout
7 Rouge Ale's Chocolate Stout
8 Porterhouse Brewing Company Plain Porter
9 Don't remember
10 Other (Specify)

Q28 and Q29 are 2 arrays which are going to be asked of two brands. Here is the logic as to how it gets decided, this is in order of how they are to be chosen:

Q28:
1. If Guiness (1) is mentioned in any question, this is the brand for 28, if not...
2. If Murphy's (2) Sam Adams (3) or Beamish (4) are mentioned in Q4 Q6 Q7 Q15 or Q19, randomly select one, if not...
3. Randomly select another brand mentioned in Q4 Q6 Q7 Q15 or Q19 (except for Don't know or Other)

It looks as though Q28 is always asked - you just need to tailor the text of the question. So, I'd create three hidden Equation questions to address the broad criteria #s 1-3.
GuinessMentioned = (count(Q4==1, Q6==1, Q7==1, Q15==1, Q19==1, Q22==1) >= 1)
SecondTierMentioned = (count((Q4>=2 and Q4<=4), (Q6>=2 and Q6<=4), (Q7>=2 and Q7<=4), (Q15>=2 and Q15<=4), (Q19>=2 and Q19<=4), (Q22>=2 and Q22<=4)) >= 1)
PickBrand = if(GuinessMentioned,1,if(SecondTierMentioned,(floor(rand() * 2.999)+ 2),(floor(rand() * 3.999) + 5)))

One of the functions I expect to add to ExpressionManager is this:
FunctionSyntaxDescription
getAnsOptiongetAnsOption(X)
getAnsOption(X,Y)
returns the text corresponding to the selected option for node X
returns the text corresponding to the option at index Y of node X

So, using that function, the text for Q28 might be (depending upon what you're really asking):
Here are some more questions about {getAnsOption(Q4,PickBrand)}.  
vadindot wrote:
Q29:
1. Response to Q22 if it is not Guiness or Don't Know, if not....
2. If Murphy's (2) Sam Adams (3) or Beamish (4) are mentioned in Q4 Q6 Q7 Q15 or Q19, randomly select one that hasn't already been picked for Q28, if not...
3. Randomly select another brand mentioned in Q4 Q6 Q7 Q15 or Q19 (except for Don't know or Other) that wasn't chosen for Q28

As I've seen too often in textbooks, "The solution to this problem is left as an excercise for the student".

Seriously however, this is no harder than the criteria for Q28.

/Tom
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.411 seconds
Donation Image