Javascript for input based formula calculation in matrix cells

Plus d'informations
il y a 1 mois 1 semaine #185674 par DPetrik
Dear community,

i am currently trying to implement a calculation logic for the array (number) matrix question type, where the values for some cells (which are disabled for editing) are calculated automatically, based on the user input of other cells.

Here is a concrete example: If a user in a 2x2 matrix (AA, AB, BA, BB) enters "5" as a value in AB, the disabled counter cell BA should calculate a formula based on this input, such as "=1/5".

Does anyone have experience with this logic implementation in LimeSurvey? I would be very thankful for any suggestion or JS code snippet for further testing.

Thanks a lot in advance.

Kind Regards

DPetrik

Connexion ou Créer un compte pour participer à la conversation.

LimeSurvey Partners
Plus d'informations
il y a 1 mois 6 jours - il y a 1 mois 6 jours #185695 par Joffm
Hi,
I do not think that you really need javascript. You can achieve this with built-in features (Expression Manager)
It is related to your other question, isn't it?

Well, you can disable the lower left triangle by just removing all "<options>" from the "select" of these cells.

A following hidden question of type equation fills an array with the calculated values (also hidden).


equation like:
{Result_Y001_X001=1}

{Result_Y002_X001=if(Q1f_Y001_X002=="0.1111",9,if(Q1f_Y001_X002=="0.1414",7,if(Q1f_Y001_X002=="0.2000",5,if(Q1f_Y001_X002=="0.3333",3,if(Q1f_Y001_X002=="1",1,if(Q1f_Y001_X002=="3",0.3333,if(Q1f_Y001_X002=="5",0.2000,if(Q1f_Y001_X002=="7",0.1414,0.1111))))))))}

{Result_Y001_X002=Q1f_Y001_X002}

{Result_Y002_X002=1}

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Pièces jointes :
Dernière édition: il y a 1 mois 6 jours par Joffm.
Les utilisateur(s) suivant ont remercié: DenisChenu

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 5 jours #185705 par DPetrik
Hi Joffm,

thank you very much for your reply. I am struggling with the Expression Manager and getting undefined variables. Could you kindly provide an export of an examplary lss file, which contains the implemented equation?

Thank you a lot in advance.

Kind Regards

Dimitri

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 5 jours #185706 par Joffm
Hi,
here an example.
1. I used the array(numbers) with text input.
2. I changed all "select" to "input" in the first part of the javascript.
3. It is not mandatory to fill all cells. If you want to change it to mandatory, you have to validate the question.

Original question with some empty fields


Result (which should be hidden in your real survey)


Here the survey.
Remember: Check the hardcoded SGQ ([SurveyID]X[GroupID]X[QuestionID]) in the javascript. It should be adapted but who knows...

Fichier attaché :

Nom du fichier : limesurvey...2286.lss
Taille du ficher :41 ko


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Pièces jointes :
Les utilisateur(s) suivant ont remercié: DPetrik

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 5 jours #185719 par DPetrik
Dear Jeffm,

thank you for your great help! I am so excited to see the working results, which would never be possible without your support!

Now i am even not sure, whether the second (calculated) matrix should be hidden or either enable a consistency self-check for the survey participants :-)

Anyway great thanks for your help. I am really appreciating it. I am planing to conduct a survey for my dissertation and this technical puncture was a great milestone, to replace prototypical excel sheets :-)

I still have one more short question. As the survey is not live, i was not able to check what is practically stored in the database - the results from both matrices (questions 1+3)?

Kind Regards

Dimitri

P. S. Your signature is a program :-)

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 4 jours #185722 par Joffm

As the survey is not live, i was not able to check what is practically stored in the database - the results from both matrices (questions 1+3)?

Why not activate your small example as open survey, enter data, and have a look at the answer table? Then deactivate again.
Everything is stored, even the results of the equation.

enable a consistency self-check for the survey participants

Remember, if you show, participant may enter new data, or you have to disable all cells of this question, too.
Or, if you want to show, use a question of type "textdisplay" and display the values in a grid there.

Now there is one question that came to my mind.
Do you use the calculated values later in your survey?
Like in a later question
"You entered a value of {Frage1R_SQ005_SQ001} for 'DevOps Metrics -> APIs'.
Please, explain in a few words, why."

If not, everything here was "l'art pour l'art" and you could have calculated these values in your statistic tool.
Nevertheless, it's a process of learning.

Best regards
Joffm


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

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 8 heures #185900 par Joffm


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

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 semaines 4 jours #186044 par DPetrik
Dear Jeffm,

thank you very much for this suggestion. I will definitely test it out. I have to dig deeper into the practiced ways of how to conduct a survey for AHP. Maybe a read-only check up is a really good improvement.

However, AHP also requires a consistency check, which is based on several formulas in the background. I would like to talk with my collegueas first, who are experts into this method, whether the consistency check should also be implemented in the survey.

If it should, the consistency check could use the calculated values to calculate:
1. Normalized values of the whole matrix
2. Sum of each row of the normalized matrix
3. Average by dividing the sum (2) by the Average of each Row
4. Average of all the average values (3)
5. Consistency Index = ( Result from step 4 - Number of Criteria)/(Number of Criteria - 1)
6. Divide the consistency index through the random index (random index = number of items compared in the matrix)
7. Compare whether the consistency index is < 0,1. If it is it should warn the user to check his input one more time.

That will be a whole lotta' fun :-)


Kind Regards

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 semaines 4 jours #186050 par Joffm
Oh, interesting.

LimeSurvey doesn't know skips, neither forward nor backward.
If there were skips you could calculate the few values which is easy (only a bit summing, counting and dividing) and skip back to the question of the condition is not fulfilled.

If, yes, if.
The only way IMO is to show an incremental index and ask the respondent to go back to the question.
Disadvantage: The old values are not saved. The respondent has to enter everything again.

Or you throw away everything and try to do it with javascript within the question.

Best regards
Joffm

P.S.
Are you sure?

Average by dividing the sum (2) by the Average of each Row

This is sum/(sum/count) = count


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

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 semaines 4 jours #186055 par jelo

Joffm écrit: LimeSurvey doesn't know skips, neither forward nor backward.

Perhaps the whole thing can be done inside one questiongroup. Depends a bit on ExpressionScript (ExpressionManager) and that some things need a page change to be calculated.

For some AHP inspiration, I recommend
bpmsg.com/new-ahp-excel-template-with-multiple-inputs/

There are some PHP onlinetools as well.
bpmsg.com/academic/ahp.php

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Connexion ou Créer un compte pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!