Generate random number as condition

More
1 week 5 days ago - 1 week 5 days ago #173812 by Pernelle
Pernelle created the topic: Generate random number as condition
In my survey, I have 12 hidden questions that generate a random number between 1 and 4 which determine which of the four subquestions in the 12 following questions will be displayed to the participant.
To do this, I use a hidden question of the type:
if(DispRec1 >= 1, DispRec1, floor(rand(1, 4.9999)))

and then in the following question, each subquestion has a condition of the type:
((( ! is_empty(321522X4X36.NAOK) && (321522X4X36.NAOK == 2))))


I have collected data from more than 1000 participants so far, and I realise that the 4th condition is largely underrepresented (so the number 4 is not generated as often as the 1, 2, and 3).
Do you know why and how to solve this?

Note that I now use Version 3.7.3+180516, but I developed it in a previous version, where I was advised to use " 4.9999" for the last randomly generated number. Maybe that is the problem, in version 3?

Thank you.
Last Edit: 1 week 5 days ago by Pernelle.

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #173814 by jelo
jelo replied the topic: Generate random number as condition
Without having the complete survey (LSS export) it looks impossible to me to check for issues.
Perhaps someone will invest the time to ask questions without looking at the actual survey, but the chances will be narrow.

You generate random numbers with hidden equation question
E.g. DispRec1 is:
if(DispRec1 >= 1, DispRec1, floor(rand(1, 4.9999)))

And if you look at the saved values, you see 1-3 way more often than 4?

Which PHP version and OS is used? You can >>>click<<< on the LimeSurvey version number at the bottom to get a window with more infos about your installation.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #173819 by tpartner
tpartner replied the topic: Generate random number as condition
Why are you using floor()? Why not simply rand(1, 4)?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #173820 by jelo
jelo replied the topic: Generate random number as condition

tpartner wrote: Why are you using floor()? Why not simply rand(1, 4)?

You're right for PHP, but I still find the common floor approach (used for non integer rand functions) in the manual. E.g. manual.limesurvey.org/Expression_Manager...e_Question_Per_Group

At the outset, in Group 0, five hidden Equation questions, called ask1-ask5, are populated. Each one has the value of {floor(rand(1,6.9999))} in the question text field


BTW: Starting with PHP 7.1 rand() should be delivering a good quality of random numbers.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #173821 by Pernelle
Pernelle replied the topic: Generate random number as condition
Thank you both for your quick reactions.

Here is the LSS survey structure.

I used floor because I found this in the manual, indeed.

Regarding my system configuration:


LimeSurvey version
3.7.3
LimeSurvey build
180516
Operating system
Linux ks01.sl-services.be 4.9.58-xxxx-std-ipv6-64 #1 SMP Mon Oct 23 11:35:59 CEST 2017 x86_64
PHP version
7.0.22-0ubuntu0.16.04.1
Web server name
survey2.sl-services.be
Web server software
Apache
Web server info
Database driver
mysql
Database driver version
mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
Database server info
Uptime: 9958600 Threads: 1 Questions: 9808849 Slow queries: 0 Opens: 167322 Flush tables: 1 Open tables: 416 Queries per second avg: 0.984
Database server version
Uptime: 9958600 Threads: 1 Questions: 9808849 Slow queries: 0 Opens: 167322 Flush tables: 1 Open tables: 416 Queries per second avg: 0.984
Attachments:

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #173822 by Pernelle
Pernelle replied the topic: Generate random number as condition
"And if you look at the saved values, you see 1-3 way more often than 4?"

--> that's right

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #173824 by jelo
jelo replied the topic: Generate random number as condition

Pernelle wrote: "And if you look at the saved values, you see 1-3 way more often than 4?"
--> that's right

Without seeing the complete survey, I would say "It's the way it is".

In percentage, what distribution is on the 12 random generator questions?

1 more than 2 more than 3 more than 4.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago - 1 week 5 days ago #173825 by Pernelle
Pernelle replied the topic: Generate random number as condition
Overall, the distribution of the four numbers generated over the 12 stimuli for all the participants are:

1: 413 (30%)
2: 389 (29%)
3: 373 (27%)
4: 188 (14%)

--> You can see that 1, 2, and 3 have similar frequencies, but 4 is much lower
Last Edit: 1 week 5 days ago by Pernelle.

Please Log in or Create an account to join the conversation.

More
1 week 1 day ago #173950 by Pernelle
Pernelle replied the topic: Generate random number as condition
I realised that the frequencies I reported above were for only a subset of the sample. But the actual frequencies are very similar (and as unbalanced, hence as problematic):

1: 3781 (28%)
2: 3775 (28%)
3: 3710 (28%)
4: 8388 (16%)

Please Log in or Create an account to join the conversation.

More
1 week 1 day ago - 1 week 1 day ago #173955 by jelo
jelo replied the topic: Generate random number as condition
Why is 8338 16% and 3710 28%? How do you get these numbers?

Without seeing the complete survey to investigate I have nothing to add.
If it's not an issue in the survey structure (still can trigger a bug in LimeSurvey), it's an issue around PHP.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey
Last Edit: 1 week 1 day ago by jelo.

Please Log in or Create an account to join the conversation.

More
1 week 1 day ago - 1 week 1 day ago #173972 by Joffm
Joffm replied the topic: Generate random number as condition
Hi,

First I tried to check if there is an issue with your formula.
In a small test survey I entered 100 answers.
With your formula: floor(rand(1,4.999)) I got

and with simple:rand(1,4) I got


So, it is not the worst distribution and there is no difference between the formulas.

But then looking into the programming: I found this:
In both Chinese languages there is:

{if(DispRec1>=1,DispRec1,floor(rand(1,3.9999)))}





So it's just a typo on your side.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last Edit: 1 week 1 day ago by Joffm.
The following user(s) said Thank You: f_funke

Please Log in or Create an account to join the conversation.

More
1 week 1 day ago #173976 by jelo
jelo replied the topic: Generate random number as condition
Upps. Sorry, just overlooked that the LSS export was attached. Nice catch, Joffm.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 week 1 day ago #173977 by Pernelle
Pernelle replied the topic: Generate random number as condition
Many thanks for this, Joffm! I don't know how I could overlook this! Thanks a lot!

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!