Welcome, Guest
Username: Password: Remember me

TOPIC: Using a series of Equation type questions in another calculation

Using a series of Equation type questions in another calculation 1 year 7 months ago #84743

  • tfj
  • tfj's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 6
  • Karma: 5
I have been struggling for the past couple of days on the syntax required for using a series of equation type questions for another calculation. I'm sure it is something simple and I am somewhat embarrassed to ask . . .

I have attached a sample survey to calculate the Addiction Severity Index for a series of questions related to Alcohol usage. On the second page of the survey, you will see some of the checks and various calculations I have tried. The first of the calculations works perfectly. (This is the one that says "The ASI for Alcohol Use = XXXX."

When I attempt an alternative calculation, however, in order to account for questions that may not have been answered, I get a concatenation, rather than an addition. I even ran checks on the equation questions to make sure they were numeric. This alternative calculation is based upon a series of previous equation questions.

I am using version 1.92+ build 120808.

Thanks!

tfj
Attachments:
The administrator has disabled public write access.

Re: Using a series of Equation type questions in another calculation 1 year 7 months ago #84745

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
That might be a bug. The JavaScript portion of EM is supposed to concatenate strings, but add numbers when it sees the "+" sign.

I never ran into that myself because I always use the sum() function which will solve your immediate problem:

ASIAlcohol =
sum(alc30_1_1 / 180, Intox30_1_1 / 180, alcprob30_1_1 / 180, alctroub30 - 1 / 24, (alctximp - 1) / 24, LogAlcExp / 44)

ASIAlc2 =
sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, LogAlcExp / 44)
The administrator has disabled public write access.

Re: Using a series of Equation type questions in another calculation 1 year 7 months ago #84746

  • tfj
  • tfj's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 6
  • Karma: 5
Thank you for your help!

When I put the following for the question for ASIAlc2:

{sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, (LogAlcExp/44)}

I get the attached. I tried other combinations, but had no luck.

tfj
Attachments:
The administrator has disabled public write access.

Re: Using a series of Equation type questions in another calculation 1 year 7 months ago #84748

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
If you hover your mouse over the word sum (which is surrounded by a red box), it will tell you that you are missing a closing parenthesis.

You need either:
sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, LogAlcExp / 44)

or
sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, (LogAlcExp / 44))
Last Edit: 1 year 7 months ago by TMSWhite.
The administrator has disabled public write access.

Re: Using a series of Equation type questions in another calculation 1 year 7 months ago #84749

  • tfj
  • tfj's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 6
  • Karma: 5
Oops. Many thanks. It is interesting, though, how my two calculations, the original ASIAlc and the new ASIAlc2 don't quite match, but they are very close -- I'll do some more digging.

Thank you for your help . . . I totally forgot that hover part.

tfj
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.321 seconds
Donation Image