Welcome to the LimeSurvey Community Forum

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

Scoring Array responses with different weight

  • captainwalker
  • captainwalker's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 4 days ago #258941 by captainwalker
Scoring Array responses with different weight was created by captainwalker
I have an array with 4 sub-questions. I want to create an assessment based on scores from the array sub-questions. My attached screenshot shows what I'm trying to do

I have 'Assessments' enabled but can't figure out how to pull the scores from the array sub-questions to show a rating of mild, moderate or severe.

I'm pretty new to Limesurvey. I am grateful for any ideas or suggestions. 

=================
LimeSurvey version: Community Edition Version 6.5.1+240320 
Own server on XAMPP
Survey theme/template: Fruity twenty-three
==================

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 4 days ago - 1 month 4 days ago #258942 by Joffm
Hi,
the first thing you do: Forget "assessment rules".
Since there is ExpressionScript (since version 2.0) it is outdated.
While assessment values may still be important; in case you have negative weights or several answer options have the same weight.

Well, in your case the answer options have different weights among the subquestions.
Here you have to sum each outcome. 
I'd advise to calculate the score separately and than display the result.
Reason: To display the result you need a nested if. And the separated calculation avoids that the same is calculated several times.

So.
Create a (hidden) question of type equation (call it as you like; here I used "numScore")
and enter this
{sum(countif("2",Q1_Y004.NAOK), countif("3",Q1_Y002.NAOK,Q1_Y003.NAOK), countif("4",Q1_Y001.NAOK,Q1_Y002.NAOK), 2*countif("3",Q1_Y004.NAOK), 2*countif("4",Q1_Y003.NAOK,Q1_Y004.NAOK), 2*countif("5",that.Q1.NAOK))}

You see we sum the number of answer options that are weighted 1 and twice the answer options that are weighted 2.

And in a question of type "text display" or wherever you want - even in the question itself, you show the result with this nested IF
{if(numScore<4,'mild',if(numScore<8,'moderate','severe'))}

Here I assume that there were some typos in your requirement
a. you didn't define a result for "4"
b. you didn't define a result for "8"
c. a score >8 is impossible

 

 

File Attachment:

File Name: limesurvey...7351.lss
File Size:35 KB


Joffm

Edit:
{sum(if(Q1_Y001.NAOK>4,2,if(Q1_Y001.NAOK>3,1,0)), if(Q1_Y002.NAOK>4,2,if(Q1_Y002.NAOK>2,1,0)), if(Q1_Y003.NAOK>3,2,if(Q1_Y003.NAOK>2,1,0)), if(Q1_Y004.NAOK>2,2,if(Q1_Y004.NAOK>1,1,0)))}
Maybe this is easier 
The values are summed up row by row (with nested IFs).

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 4 days ago by Joffm.
The following user(s) said Thank You: tpartner, captainwalker

Please Log in to join the conversation.

  • captainwalker
  • captainwalker's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 3 days ago - 1 month 3 days ago #258954 by captainwalker
Replied by captainwalker on topic Scoring Array responses with different weight
Wow!! That's put me lime-years ahead in survey development. You are priceless - and thanks for including the .lss file. 
Claude.ai did an analysis to explain more. Do add to the following if it would benefit others. 
Code:
{sum(   countif("2",Q1_Y004.NAOK),   countif("3",Q1_Y002.NAOK,Q1_Y003.NAOK),   countif("4",Q1_Y001.NAOK,Q1_Y002.NAOK),   2*countif("3",Q1_Y004.NAOK),   2*countif("4",Q1_Y003.NAOK,Q1_Y004.NAOK),   2*countif("5",that.Q1.NAOK) )}
The code uses the
Code:
sum()
function to add up the results of several
Code:
countif()
functions. Each
Code:
countif()
function counts the number of occurrences of a specific answer code in the specified subquestions. 
  1. Code:
    countif("2",Q1_Y004.NAOK)
    : This counts the number of times the answer code "2" appears in the subquestion "Q1_Y004". The ".NAOK" suffix ensures that the count is performed even if the subquestion is not answered (i.e., treated as "Not Applicable" or missing).
  2. Code:
    countif("3",Q1_Y002.NAOK,Q1_Y003.NAOK)
    : This counts the number of times the answer code "3" appears in either subquestion "Q1_Y002" or "Q1_Y003".
  3. Code:
    countif("4",Q1_Y001.NAOK,Q1_Y002.NAOK)
    : This counts the number of times the answer code "4" appears in either subquestion "Q1_Y001" or "Q1_Y002".
  4. Code:
    2*countif("3",Q1_Y004.NAOK)
    : This counts the number of times the answer code "3" appears in subquestion "Q1_Y004" and multiplies the count by 2. This is done to assign a weight of 2 to this specific answer code in this subquestion.
  5. Code:
    2*countif("4",Q1_Y003.NAOK,Q1_Y004.NAOK)
    : This counts the number of times the answer code "4" appears in either subquestion "Q1_Y003" or "Q1_Y004" and multiplies the count by 2. This assigns a weight of 2 to this answer code in these subquestions.
  6. Code:
    2*countif("5",that.Q1.NAOK)
    : This counts the number of times the answer code "5" appears in any subquestion of the main question "Q1" and multiplies the count by 2. The "that." prefix is used to refer to the main question.
Regarding the subquestion codes like "Q1_Y002.NAOK", the "Y002" part represents the specific subquestion code. In your screenshot, the subquestions are labeled as "Sub-question 1", "Sub-question 2", etc. The actual subquestion codes in your survey might be different (e.g., "SQ001", "SQ002", etc.). You need to replace "Y001", "Y002", etc., with the corresponding subquestion codes used in your survey.The ".NAOK" suffix is used to ensure that the count is performed even if the subquestion is not answered. It stands for "Not Applicable OK" and treats unanswered subquestions as missing values rather than causing an error in the calculation.Finally, the
Code:
sum()
function adds up all the counts and weighted counts to calculate the total score.
Last edit: 1 month 3 days ago by captainwalker.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose