Welcome to the LimeSurvey Community Forum

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

Calculations on personality test with random questions

  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #209350 by ernahaka
Hello everyone,

i am making a personality test, a bit similar to the one in this thread forums.limesurvey.org/forum/can-i-do-thi...03-personality-tests

But in my case, I want to have random questions (20 questions chosen in a bank of 60). So I cannot use questions names (Q1, Q2, etc.) in the calculation {sum(if(Q1=="a",1,0),if(Q2=="c",1,0),...} , because i dont know which question will be selected. Maybe the questions will be Q2, Q8, ...

Thanks in advance if you can help!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209352 by Joffm
Of course you can.
It doesn't matter that you only have a subset.
The question code are as you defined them.

{sum(if(Q1=="a",1,0),if(Q2=="c",1,0),...} , because i dont know which question will be selected.

Maybe the questions will be Q2, Q8, ...


And, what is the problem? In this case Q1 is NOT equal "a" because it isn't there at all and therefore will be added "0".
But you have to use ".NAOK", because the missing questions have undefined values.
{sum(if(Q1.NAOK=="a",1,0),if(Q2.NAOK=="c",1,0),...}

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #209354 by ernahaka
thanks Joffm,
do you mean that the calculation has to include all the 60 questions, like that : sum(if(Q1.NAOK=="a",1,0),if(Q2.NAOK=="c",1,0),...,if(Q60.NAOK=="c",1,0)} ?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209359 by Joffm
If your test has really the same scenario as the one you linked to

The key to test is
1 a Choleric
1 b Sanguine
1 c Phlegmatic
1 d Melancholic

2 a Sanguine
2 b Phlegmatic
2 c Choleric
2 d Melancholic

yes, of course, you have to do it for all 60.
And you have to create four times this equation - one for each of the four to calculate the sums of Sanguine, Phlegmatic, Choleric and Melancholic.

But if your survey is only

a bit similar to the one in this thread

you should show us exactly what and how you want to calculate.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #209365 by ernahaka
thanks for spending your Sunday helping lost souls!

actually i have the algorithm but i dont know how to make it happen in ExpressionScript. Sorry for my clumsy coding vocabulary.
LS version is 4.3.15+200907

All 60 questions are Multiple choice and named Q01, Q02, ... Q60
Only 20 questions will be displayed, chosen randomly.
Each question has 5 subquestions, Y scale (lines)
Each subquestion has title A, B, C, D or E and sentences
Subquestions are displayed in random order.
The user can select 1 to 5 answers.

so the answers will be something like that:
Q01: A, D
Q02: B, C, E
Q03: A, C, D, E
...

>> How do I calculate the total number of occurences of each title A B C D E ?

i think the calculation is:
totalA = sum ( for every question Q01 to Q60, if ("number of answers>0" and "A is answered") then "1" else "0") )
etc.

I was looking for a shortcut by not having to write 60 times the same formula, something like: "for Q01 to Q60, ..."


bonus question: instead of having the result 1 at the if function, i want to return the result of a calculation "100/nb of answers"
i could already get the "nb of answers"for every question, by the count function. They are stored in questions NbAnswersQ01, ... - but i dont know the syntax for "100/nb of answers".


thanks in advance if you can help!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209375 by Joffm
Hi,
this is something different

All 60 questions are Multiple choice and named Q01, Q02, ... Q60
Each question has 5 subquestions, Y scale (lines)

Means: You have 300 questions to calculate.

Each subquestion has title A, B, C, D or E and sentences
The user can select 1 to 5 answers.

Seems to be a matrix(numbers). Or?

Without seeing your approach (better you send a lss export) I should say.
code the y-axis "Y001", "Y002",... and the x-axis "A", "B", "C", ...

You already know "count". But only "count" is not sufficient. You have to restrict the counting to the columns.
To calculate how many "A" you had, it is something like
{count(that.Q01.sq_A.NAOK,that.Q02.sq_A.NAOK,that.Q03.sq_A.NAOK,...,that.Q60.sq_A.NAOK)}
To calculate how many "B" you had, it is something like
{count(that.Q01.sq_B.NAOK,that.Q02.sq_B.NAOK,that.Q03.sq_B.NAOK,...,that.Q60.sq_B.NAOK)}
It is important that you have unique identifiers for the columns.

Read about "this", "that", "self" in the manual
manual.limesurvey.org/ExpressionScript_-....22that.22_variables

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #209496 by ernahaka
hello Joffm,


the formula works fine, thank you:

{count(that.Q01.sq_A.NAOK,that.Q02.sq_A.NAOK,that.Q03.sq_A.NAOK,...,that.Q60.sq_A.NAOK)}


unfortunately i can't share the lss, my client doesn't allow.

Seems to be a matrix(numbers). Or?

I am not sure if it is a matrix, maybe i filled it wrong: when i added a new question type M, i put the 5 possible answers in "Subquestions"
In LS4, every line to add a subquestion has the fields Title, Subquestion, Condition.
In "Title" I put the code (A, B, ...or E), in "Subquestion"I put a sentence (it's one of the 5 possible answers).
So I mentioned "Y scale (lines)" just because I see it written in the Question editor - i didnt use the Y scale on purpose.


I want to calculate the "total score" for each answer A, B..., E:
total_scoreA = (scoreA in Q01)+(scoreA in Q02)+...(scoreA in Q60)
scoreA in Q01 = if (Q01 has been answered) and (one of the answer is A), then scoreA = 100/(nb of answers in Q01), else 0

Example:
-- at Q01, user answered A, E and B
=> total answers 3
=> scoreA = 33, scoreE=33, scoreB=33 (scoreC=0 and scoreD=0)
-- at Q02, user answers A and D
=> total answers: 2
=> scoreA = 50, scoreD=50 (and scoreB and scoreC and scoreE=0)

in the end:
total_scoreA = 33+50
total_scoreB = 33 + 0
total_scoreC = 0 + 0
total_scoreD = 0 + 0
total_scoreE= 33 + 0

to calculate the nb of answers, i used this function, the result is correct.
for Q01: count(Q01_A.NAOK, Q01_B.NAOK, Q01_C.NAOK, Q01_D.NAOK, Q01_E.NAOK)

thanks again!

ps: i just discovered manual.limesurvey.org/ExpressionScript_examples , very useful! I dive into it now, see if i can find the answer
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209498 by Joffm
Then create a sample survey with dummy text.

At least show a screenshot (you may gray the text, or change it)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209499 by holch

unfortunately i can't share the lss, my client doesn't allow.

No one here wants or needs to see your original survey, but a LSS file helps to better understand what you are doing or where you are doing something wrong.

So, either create a copy of your survey, delete everything that is not necessary for the problem, change the question texts to make it not recognizable, and post it.

Or create a new little survey to demonstrate the issue.

We do not need your whole survey, but a LSS file often helps to understand the problem better. You can use a dummy to show us what you are doing.

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

The following user(s) said Thank You: ernahaka
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #209501 by Joffm
But you wanted to tell us, that you were successful, didn't you?

Yes, you have 5 equations
scoreA:
{count(that.Q01.sq_A.NAOK,that.Q02.sq_A.NAOK,that.Q03.sq_A.NAOK,...,that.Q60.sq_A.NAOK)}

scoreb:
{count(that.Q01.sq_B.NAOK,that.Q02.sq_B.NAOK,that.Q03.sq_B.NAOK,...,that.Q60.sq_B.NAOK)}

scoreC:
{count(that.Q01.sq_C.NAOK,that.Q02.sq_C.NAOK,that.Q03.sq_C.NAOK,...,that.Q60.sq_C.NAOK)}

scoreD:
{count(that.Q01.sq_D.NAOK,that.Q02.sq_D.NAOK,that.Q03.sq_D.NAOK,...,that.Q60.sq_D.NAOK)}

scoreE:
{count(that.Q01.sq_E.NAOK,that.Q02.sq_E.NAOK,that.Q03.sq_E.NAOK,...,that.Q60.sq_E.NAOK)}

According to your last explanation (question type M) I think you only use multiple questions.
You should have said that before, because an array(numbers) with checkboxes and a multiple question store the data differently.

Instead of
for Q01: count(Q01_A.NAOK, Q01_B.NAOK, Q01_C.NAOK, Q01_D.NAOK, Q01_E.NAOK)
only count(Q01.NAOK)

and the total number of answers is
sum(scoreA,scoreB,scoreC.scoreD,scoreE)

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: ernahaka
The topic has been locked.
  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #209505 by ernahaka

But you wanted to tell us, that you were successful, didn't you?

I am trying really hard but not there yet!

I sent you the lss in a private message.

You will see that I didnt use A B C D E but other letters - and there are 6 instead of 5.

Sorry I repeat the calculation I need to make:

I want to calculate the "total_score" for each answer A, B..., E:
total_scoreA = (scoreA in Q01)+(scoreA in Q02)+...(scoreA in Q60)
scoreA in Q01 = if (Q01 has been answered) and (one of the answer is A), then scoreAQ01 = [100/(nb of answers in Q01)], else 0

Example:
-- at Q01, user answered A, E and B
=> total answers 3
=> scoreA = 33, scoreE=33, scoreB=33 (scoreC=0 and scoreD=0)
-- at Q02, user answers A and D
=> total answers: 2
=> scoreA = 50, scoreD=50 (and scoreB and scoreC and scoreE=0)

in the end:
total_scoreA = 33+50
total_scoreB = 33 + 0
total_scoreC = 0 + 0
total_scoreD = 0 + 0
total_scoreE= 33 + 0

The topic has been locked.
  • ernahaka
  • ernahaka's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 4 months ago #209515 by ernahaka
I did this code and it worked!

totalscoreA = {sum(
if(Q01NbRep>0 and Q01_A=="Y",100/Q01NbRep,0),
if(Q02NbRep>0 and Q02_A=="Y",100/Q02NbRep,0),
if(Q03NbRep>0 and Q03_A=="Y",100/Q03NbRep,0),
if(Q21NbRep>0 and Q21_A=="Y",100/Q21NbRep,0),
if(Q22NbRep>0 and Q22_A=="Y",100/Q22NbRep,0),
if(Q23NbRep>0 and Q23_A=="Y",100/Q23NbRep,0)
)}

If you've seen my lss, Q01NbRep is the number of answers selected in Q01.

but as you mentioned

Instead of
for Q01: count(Q01_A.NAOK, Q01_B.NAOK, Q01_C.NAOK, Q01_D.NAOK, Q01_E.NAOK)
only count(Q01.NAOK)

I tried to replace Q01NbRep by count(Q01.NAOK), but it says "undefined value".

It's not really important as my code above works! :woohoo:

But that means I will need:
1. to create Q01NbRep, Q02NbRep, ..., Q60NbRep
2. then totalscoreA mentioned above will have 60 times if(Q01NbRep>0 and Q01_A=="Y",100/Q01NbRep,0), until Q60.
3. then i need to create totalscoreB, totalscoreC, totalscoreD, totalscoreE

That's a lot of repetitive commands, so i guess (and hope) it's possible to write a shorter code?
For task 1:
So far i created one question (type Equation) for each value: Question Q01NbRep, Question Q02NbRep, ... until Q60NbRep
How to calculate these 60 values in 1 question?

For task 2:
Is there a command using the questions ID or other variable, that could be:
for QID=Q01 to Q60,
totalscoreA = if(QIDNbRep>0 and QID_A=="Y",100/QIDNbRep,0) + totalscore A


Thank you so much for your help and patience.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose