Welcome to the LimeSurvey Community Forum

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

set conditions doesn't work for control group and experiment group example

  • nannancy
  • nannancy's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 11 months ago #183733 by nannancy
Hello, we are using Limesurvey Version 2.72.6+171207. In our survey design, there are one experiment group and one control group. The implementation is as following:
question 1 [Q00] is a masked question with an equation {rand(1,2)}.
question 2 [Q01] should be shown to the respondents who has Q00==1.
question 3 [Q02] should be shown to the respondents who has Q00==2.
But it goes wrong sometimes (not always...) in the way that question 2 [Q01] is shown to me when I have Q00==2
or question 3 [Q02] is shown to me when I have Q00==1.

File Attachment:

File Name: limesurvey...5712.lss
File Size:15 KB
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 11 months ago #183736 by DenisChenu

nannancy wrote: …
question 1 [Q00] is a masked question with an equation {rand(1,2)}.

Didn't check but with such system result can be different when loading and after load.

Equation must be
{if(is_empty(self.NAOK,rand(1,2),self.NAOK)}

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: cdorin, nannancy
The topic has been locked.
More
4 years 11 months ago #183745 by cdorin
Hmm, I can use rand(1,2) in LS3 without any issues. However, I can reproduce the above error in 2.73.

But, the solution provided by @DenisChenu works in LS 2.73 (as always :) ). I think an extra bracket is needed:

{if(is_empty(self.NAOK),rand(1,2),self.NAOK)}

Manual: manual.limesurvey.org/LimeSurvey_Manual
Bugs tracker: bugs.limesurvey.org/my_view_page.php
If you self-host and need help, contact one of our partners: limesurvey.com
Please do not contact me via PM - thank you.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • nannancy
  • nannancy's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 11 months ago #183750 by nannancy
Thank you so much! You save my day!
The topic has been locked.
  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 11 months ago - 4 years 11 months ago #183754 by holch
[strike]really? The extra bracket makes no sense to me... will test this.[/strike]

OK, thought about it a little more. Makes sense now.

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

Last edit: 4 years 11 months ago by holch.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 11 months ago - 4 years 11 months ago #183769 by DenisChenu

cdorin wrote: Hmm, I can use rand(1,2) in LS3 without any issues. …

Strange ?

Maybe it's happen because you have «chance» than rand(1,2) give the same value when page loading 1st time and page loading 2nd time ?

PS : thanks for bracket …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 4 years 11 months ago by DenisChenu. Reason: thanks for bracket …
The following user(s) said Thank You: cdorin
The topic has been locked.
  • nannancy
  • nannancy's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 11 months ago #183801 by nannancy
Hey! Since you said that rand(1,2) give the same value when page loading 1st time and page loading 2nd time, I have one question: the wrong survey was sent out and 100 respondents have accessed it. For every respondent, does the rand(1,2) work correctly if we assume all of them access the page 1st time? Thank you very much in advance!
The topic has been locked.
  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 11 months ago #183806 by holch
The "rand(1,2)" is triggered EVERY time any one accesses the page where this is hidden. It doesn't matter if it is 100 different people or one person 100 times.

So this is not the problem. The problem with using only "rand(1,2)" is that if the same person accesses the page again (for whatever reason, maybe because they went back in the survey, the closed the survey and opened it again, etc.), the randomization will be triggered again for them. So it could happen that they received "1" as their random number, continued, saw the questions that will be shown with "1" and then they went back. Then the randomization process would be triggered again and there is a 50% chance that they now will receive "2" as their random number and when they continue they suddenly see the other questions...

To avoid this, you should use the code given by Denis, as it checks if the random number has already been set for this session (this does not impact other people on different sessions - other devices/browsers, only this current session). If the random number has already been set, then it would just take this number and not create a new one, if the number has not been set, then there will be created a random number.

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: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 11 months ago - 4 years 11 months ago #183807 by DenisChenu
Even if user don't use back:

By program
1. We call _validateQuestion when page load : rand is done #1
2. Unsure : page is shown, and the rand JS is done (unusure on this point)
3. We call _validateQuestion before calling next page (move next) : rand is done #2

The 2 solutions i know :
1. Use rand Equation in a group without any question, and disallow move previous.
2. Use the is_empty system

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 4 years 11 months ago by DenisChenu.
The following user(s) said Thank You: cdorin
The topic has been locked.
  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 11 months ago #183810 by holch
I would always prefer the "is_empty" system. It is quite simple and it effective. Why complicate things. ;-)

Thanks for the additional occasions where the simple rand() approach could cause trouble.

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

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose