Welcome to the LimeSurvey Community Forum

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

computing two rows of data for same questions to extract a score

  • Emma_F
  • Emma_F's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago #183525 by Emma_F
Hello there!

I've been trying to program a table with two questions (practice is used/ practice doesn't apply). I want to make a sum of the practices used and of those not applying to create the following equation:

sum(used practices)/ 20 - (sum(practice not applying))

It's to display a diagnosis regarding the security practices based on whether the result of this question is higher or lower to certain bounds. The twenty is the total number of questions.

I use the "questionnumber_value.NAOK" model to identify my variables, but when I work with tables, Limesurvey can't recognize them and I can't seem to find a way around it this time.

I've tried making a table, but I can't identify each separate row and I can't have them summed together. I've tried separating each question from the table in a single question and using the listed buttons as an option, but my variables are still not recognized. I made sure they all have a different codename so that no variable could be mixed together. I'm not sure which angle to take and I'd really prefer to be able to use a table instead of 20 separate questions.

Thank you in advance for your suggestions,

Best regards,

Emma F.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #183526 by holch
To be able to help you, you will need to give a little bit more of information. What type of question are you using?

Ideally you upload a LSS file with ONLY the relevant questions and what you have done so far.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Emma_F
  • Emma_F's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago #183530 by Emma_F
I'm currently using listed questions (reduced the number of questions for the sake of getting an explanation). I want to display text if a certain score is calculated by the following expression:

sum(q1.naok, q2.naok, q3.naok, q3.naok)/(4- sum(q1b.naok,q2b.naok,q3b.naok,q4b.naok))

File Attachment:

File Name: limesurvey...8415.lss
File Size:18 KB


Thank you for your help!
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago - 4 years 10 months ago #183535 by holch
Had a look at your survey. I am confused. What are you trying to add?? This makes no sense what so ever.

You are trying to add up the answer codes. OK, so far so good. Just your answer codes are strings. How do you want to add up strings? What should be the outcome?

You also have assessment mode active. Are you trying to add the assessment values? But this would also make no sense, because all answers of all questions have an assessment value of 1. So whatever you would count, it would always end up with the same sum.

So I think we really need to clarify the basics: What are you trying to do?






Seems like you are trying to add up the "used" and the "not used" answers. This won't work like this. You see the things mark in red? They indicate that your code does not exist. Because List type questions don't have subquestions, but answer options. So you can't use QUESTIONCODE_SUBQUESTIONCODE, because there are no subquestions.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 4 years 10 months ago by holch.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago - 4 years 10 months ago #183540 by Joffm
Hi, Emma,
some additions to holch:

1. holch already said: You cannot add strings.
sum("SSR12A","SSR12B","SSR12C","SSR12D") is the same as "eggs"+"fish"+"ABC"+"laughing"

To use your codes, you have to say:
{sum(if(SSR12A=="SSR12A",1,0),if(SSR12B=="SSR12B",1,0),if(SSR12C=="SSR12C",1,0),if(SSR12D=="SSR12D",1,0))}
Meaning: If the answer of question SSR12A is code "SSR12A" there is added "1", else "0".

Obviously this is not the best way.
If you want to do some arithmetical calculations you should use numerical codes.
Using 1= Utilisée, 0 = Ne s'applique pas
the equation {sum(SSR12A.NAOK,SSR12B.NAOK,SSR12C.NAOK,SSR12D.NAOK)} will work, where "SSR12A",... are the question codes.

2. What exactly do you want to calculate? Your formula is
x/(4-y), with y=4-x
x/(4-(4-x))
x/x
So your result always will be "1", except if somebody doesn't use anything; then your formula will fail "0/0".


3. You entered your formula into the relevance equation of the question.
Into the relevance equation is entered a boolean value to decide whether a question is displayed or not.
In my opinion you are going to calculate something. So you have to create a question of type equation.

4. and last: There is a surplus comma.

So, I'd recommend:
Study the demo surveys in the demo installation

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 10 months ago by Joffm.
The topic has been locked.
  • Emma_F
  • Emma_F's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago #183550 by Emma_F
Thank you both for your time! I'll try to explain this better. I made a copy of my original survey, so the value added to the questions was not included, that's my mistake. I gave a value of 1 to both type of answers.

The logic here is that we want to display a diagnosis after people answer this question based on the result of a question. The score would normally be computed as this:

n practice / n questions

but we want to take into account that if the practice aren't used or doesn't apply, than the "n questions" shouldn't be as high.


So the equation should be as you surmised

sum(q1,q2,q3,q4)/(nquestion - sum(q1b,q2b,...)) < or > scorex


We're perfectly aware that some answers might turn the score to a 0 if too many practices doesn't apply or aren't used. I may be facing a conceptual problem from the start with this, the people I work for weren't exactly sure of how to angle this, but I'm trying to understand where I identify the variables wrong. As you can tell, english isn't my first language, but I knew I had more chances to get an answer.

I'll try refering myself to the demo.

Thanks again for your time!

Best regards,

Emma
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #183554 by holch
Well, the way you try to do it won't work.

Let's assume you give the assessment value of "1" to both answers, LS sees always 1, no matter what answer was given. Because for the question type you are using, only one value is written to the database.

At the moment in the question with the screenshot above, if the respondent ticks "Utilisée", SR12A is written into the database, if "Ne s'applique pas" is ticked SR13A is written into the database. You can't sum this up.

Actually you don't want a sum, but you want to count how often people marked "utilisée" and how often they marked "Ne s'applique pas". But this won't work like this.

I am currently thinking about how this could be done without going the route Joffm described, because you would need to check 2x 20 questions. If you wouldn't devide before you subtract, you could give the assessment values of 1 and -1 to do the subtraction automatically, but the way your formula is, this won't work.

I would probably go with 3 equation questions. One that checks with for each question if "used" was marked and sum them up and one that checks if the second question option (not used) was marked and sum it. Then in the second equation question you create your formula based on the values in the first two. Still, you need to check for every question which answer option was marked. But for now, I don't think there is any other way to do this.

Maybe Tpartner or Denis come up with some Expression Manager magic.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #183560 by Joffm
Hi, Emma,
I read your first post again.
There you talk about tables.

In my opinion a question of type array is the best to achieve this.

And just to calculate your percentage is easy.

sum(used practices)/ 20 - (sum(practice not applying))

Use the function "countif"

{countif("A1",Q1)/ (20-countif("A2",Q1))}

See example.

File Attachment:

File Name: limesurvey...9484.lss
File Size:25 KB


BTW: Is this question mandatory?
If yes, your formula will not work, as I explained before.
Then the count of "used" is always the same as "number of questions"- count of "not applicable".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago - 4 years 10 months ago #183571 by Joffm
Thinking again about your design:
With the two answer options "used" - "not applicable" you only get a usable result if the respondent doesn't answer the questions where the answer is "applicable, but not used"
So the question must not be mandatory.

IMHO better to use the three answer options "(A1) applicable and used" - "(A2) applicable and not used" - "(A3) not applicable"
Now the question can be mandatory.
Using an array you can use the formula:
{countif("A1",Q1)/(20-countif("A3",Q1))}


A different approach is:
Just use two multiple questions:
1. question (Q1): Please select all practices that are applicable?
2. question (Q2): Which are used? (with array filter (Q1))
Now you can calculate: {count(Q2)/count(Q1)}

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 10 months ago by Joffm.
The topic has been locked.
  • Emma_F
  • Emma_F's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 10 months ago #183876 by Emma_F
I want to thank you both for your help. I was able to get the equation working with the countif function. This will be quite useful for me in the future.

Thank you for your time!

Best regards,

Emma
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose