Welcome to the LimeSurvey Community Forum

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

Storing assessment results in a variable inside "equation" question type

  • Bharadwaj_Srikumar
  • Bharadwaj_Srikumar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 2 months ago - 2 years 2 months ago #234211 by Bharadwaj_Srikumar
Hello Users, 
I am developing an assessment in Limesurvey with 20 questions. I want to display the result of the assessment inside the "equation question type" based on an assessment logic (if..else if..).

But while writing the loop with 4 conditions I always need to write the assessment logic again in every argument. Is there a way to store the assessment logic in a a variable say
Total_Score  =  Q1.value + Q2.value + ....+ Q20.value;
If(Total_Score<25, "Beginner", if(Total_Score >=25 && Total_Score<75, "Intermediate", if(Total_Score>=75, "Expert", "Error")),

Instead of writing the expression for Total_Score 3 time in the above statement?

Thank you for your response in advance.
Last edit: 2 years 2 months ago by Bharadwaj_Srikumar.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234213 by holch
Afaik you can't have variables in expressions.

Just use two equation type questions. In one you calculate and store the Total_score, and in the other one you display the statements.

Or better: Calculate the score in the equation and display the message in a text display question. That would be the correct way to do so.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234217 by Joffm
Hi, why don't you show exactly what you did?
Are there really missing curly brackets in your equation?
And is the code of this question really "Total_Score"? You see, underscores are forbidden as question code.

You see, I have no issue with this equation 




Anyway, it is better to use twi equations, as @holch.
As you see the score itself is displayed and the text - obvious, you have two equations
And have a look at the answer table to see what is stored.

Joffm

 

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

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234221 by holch
Oh, so it IS possible to use variables in equations. Didn't know that!

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

  • Bharadwaj_Srikumar
  • Bharadwaj_Srikumar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 2 months ago - 2 years 2 months ago #234222 by Bharadwaj_Srikumar
Hello @Joffm and @holsch.Thank you for your reply. 
My assessment logic is a bit complicated. I will attach my equation below.
So in the image that I have attached below, I have written the logic to calculate the total score. Currently I just display the score using the TextDisplay question. But instead of that, I would like to build an if..else logic that gives the level of the assessment (basic, intermediate, advanced, Expert) based on the score. Could you explain how you would store this in a variable which I can use in the same question to build the logic @Joffm?  If like @holsch said, we can't use variables in a question then I guess I must use 2 questions. 
Last edit: 2 years 2 months ago by Bharadwaj_Srikumar.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234223 by holch
In any way it is best to separate the calculation form the display.

Where is the problem in using two different questions?

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

  • Bharadwaj_Srikumar
  • Bharadwaj_Srikumar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 2 months ago #234224 by Bharadwaj_Srikumar
@holsch, As they say, when you can do in in one place, why do it in 2. But your suggestion makes a lot more sense, which I also currently use. Just wanted to know out of curiosity if I can do it in one :)

Please Log in to join the conversation.

  • Bharadwaj_Srikumar
  • Bharadwaj_Srikumar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 2 months ago #234226 by Bharadwaj_Srikumar
Hello @Joffm, I wanted to ask you a question regarding the assessment logic that you shared. When I try to assign the equation to the total score variable , i get an error. I attach pictures of the error as attachments.
I would appreciate it if you can help me fix this error. 

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234227 by holch

As they say, when you can do in in one place, why do it in 2.


Never heard that one before. As long as you are not running into any database limits in terms of number of questions you can store, I think it makes a whole lot sense to separate the score from the display of the Text.

Because you can't calculate with the score if there is loads of other stuff in the same question (e.g. your text).

But if you just have the score, you can use it for further calculations, relevance equations, etc.

So in this case the saying in my opinion should be: "If you can separate the two, why do it in one." It is a lot cleaner if separated in my opinion. Also, you have a lot more control over how you can display the output like "Beginner", "intermediate", etc. separate in a text display question.

If you have more complicated out put I probably would actually would even use 3 questions:

1. Equation question with the calculation of the score (hidden)
2. Equation question with the output like Beginner/Intermediate/Expert/Error (hidden)
3. Text display question that will display the result to the respondent, with something like that:
Code:
You scored {eq1} points. This means you are an {eq2}

It gives you a lot more freedom. Might be overkill for what you are doing, but as you seem to show only a simplyfied version of your actual issue, this might help.
3.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234228 by holch
This shows that the variable TotalScore does not exist and would support my theory that variables within an equation do not exist on its own.

You probably need to have a question with the name TotalScore to do what you are trying to do.

If you look at Joffm's example, he called the question TotalScore, which means the variable TotalScore exists for Limesurvey. But your question is called QTS and if there is no other question that is called TotalScore, Limesurvey will complain that the variable you use does not exist.

So it seems like in order to use a variable in equations, you will need to have a question with that variable name. At least this is how I am reading this.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago - 2 years 2 months ago #234229 by Joffm
Of course,
if the question code is QTS you can't assign something to TotalScore (except TotalScore is the code of another question.

​​​​​​Joffm 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 2 months ago by Joffm.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #234411 by Joffm
Well, one last word.

Split the question (well, you already know it)
1. an equation called "TotalScore" with only {sum(Q1.NAOK,Q2.NAOK,...)}
without this assigment "TotalScore="
Now you create a column in the database called "TotalScore" where the result of the equation is stored and can be accessed later.

You assign values to a different (existing) question to preset it or use it as a (hidden) container

2. Show the result in a "text display"
Always use to appropriate question type.
"Your level is {If(TotalScore<25, "Beginner", if(TotalScore<75, "Intermediate", "Expert"))}"

And try to understand the IF function "IF(condition,true,false)"

{If(TotalScore<25, "Beginner", if(TotalScore >=25 && TotalScore<75, "Intermediate", if(TotalScore>=75, "Expert", "Error"))}
a.
"TotalScore >=25 " is not necessary,because it is the "false" part of the first condition (<25) -> this part is only reached by scores >=25
"TotalScore >=75 " is not necessary,because it is the "false" part of the second condition (<75) -> this part is only reached by scores >=75

What you do, is not really a nested if. You show three independent IFs like
{If(TotalScore<25, "Beginner","")}
{if(TotalScore >=25 && Total_Score<75, "Intermediate", "")}
{if(TotalScore>=75, "Expert", "")}
The result will be the same

b.
How do you imagine to reach the "Error"?
All numbers (from -infinite to +infinite) are covered by your three levels

As they say, when you can do in in one place, why do it in 2

Becase the way you do it
a. displays both values - the sum and the text.
b. stores both into your answer table in one column (like "12 Beginner", "78 Expert")
I assume you want to calculate some statistical values of this score later (mean, std.deviation) or run some statistical tests.
Then you have to split these entries in your analysis tool.

3. You use assessment values to calculate the score.
Of course this is possible, but sometimes not necessary.
Only, if there are negative assessment values or two or more answer options have the same assessment value you must use them.
Usually you use the numerical code of the answer options.
Advantage: These are stored in the database, while the assessment vaules are not.

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