Trying to locate the error in my formula | XM Community
Skip to main content

I'm trying to use the Wilks coefficient formula (https://en.wikipedia.org/wiki/Wilks_coefficient) in my survey using the math operations function.
The formula is:
image.pngx is the body weight of the lifter in kilograms.
Values for men are:

  • a = −216.0475144

  • b = 16.2606339

  • c = −0.002388645

  • d = −0.00113732

  • e = 7.01863× 10 ^ −6

  • f = −1.291 × 10 ^ −8

tempsnip.jpgThe green part is working correctly (it's calculating the total lifted weight, which has to be multiplied by the Wilks coefficient) The red part, which is the Wilks coefficient formula gives "{invalid espression}" as result.

The code in text form:
$e{ ( q://QID7/ChoiceTextEntryValue/1 * 100 / q://QID7/ChoiceTextEntryValue/2 + q://QID7/ChoiceTextEntryValue/3 * 100 / q://QID7/ChoiceTextEntryValue/4 + q://QID7/ChoiceTextEntryValue/5 * 100 / q://QID7/ChoiceTextEntryValue/6 ) * 500 / ( ( −216.0475144 ) + 16.2606339 * q://QID6/ChoiceTextEntryValue + ( −0.002388645 ) * q://QID6/ChoiceTextEntryValue ^ 2 + ( −0.00113732 ) * q://QID6/ChoiceTextEntryValue ^ 3 + 7.01863 * 0.000001 * q://QID6/ChoiceTextEntryValue ^ 4 + ( −1.291 ) * 0.00000001 * q://QID6/ChoiceTextEntryValue ^ 5 ) }
q://QID6/ChoiceTextEntryValue is x

I've failed to locate the source of the issue, any ideas?

Math operations are quite finicky, read the support pages to see some possible issues.
You can add the following JS to any question after QID6 to store the value into an embedded data called "wilks"
Qualtrics.SurveyEngine.addOnReady(function () {
    let x = Number("q://QID6/ChoiceTextEntryValue"),
        x2 = Math.pow(x, 2),
        x3 = Math.pow(x, 3),
        x4 = Math.pow(x, 4),
        x5 = Math.pow(x, 5),
        a = -216.0475144,
        b = 16.2606339,
        c = -0.002388645,
        d = -0.00113732,
        e = 7.01863 * Math.pow(10, -6),
        f = -1.291 * Math.pow(10, -8);


    let coeff = a + b * x + c * x2 + d * x3 + e * x4 + f * x5;
    coeff = 500 / coeff;
    Qualtrics.SurveyEngine.setEmbeddedData("wilks", coeff);
});


https://community.qualtrics.com/XMcommunity/discussion/comment/39558#Comment_39558Thank you. I need to display the wilks score (the marked green part * wilks) in the next question. Can I somehow use the embedded value in math operations?


Yes. Please read the support pages on math operations on how to do that.


I tried to use the following JS in the survey, and it works when I set the embedded data (wilks) value to a number instead of "coeff", but when the JS is supposed to set the value to wilks, in math operations I just get the same number (-2.314305727555271) as the result of the equation no matter what value is given in the previous question.
Qualtrics.SurveyEngine.addOnReady(function() 
{
    let x = Number("${q://QID6/ChoiceTextEntryValue}"),
        x2 = Math.pow(x, 2),
        x3 = Math.pow(x, 3),
        x4 = Math.pow(x, 4),
        x5 = Math.pow(x, 5),
        a = -216.0475144,
        b = 16.2606339,
        c = -0.002388645,
        d = -0.00113732,
        e = 7.01863 * Math.pow(10, -6),
        f = -1.291 * Math.pow(10, -8);




    let coeff = a + b * x + c * x2 + d * x3 + e * x4 + f * x5;
coeff = 500 / coeff;
Qualtrics.SurveyEngine.setEmbeddedData('wilks', coeff);
});
Any ideas on what could be causing the problem?


I've figured out what was causing the problem: the JS can't be on the same page as the question, which is the source of "x" in the script


Leave a Reply