Generate random number as condition

Mehr
2 Monate 1 Tag her - 2 Monate 1 Tag her #173812 von Pernelle
Pernelle erstellte das Thema 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.
Letzte Änderung: 2 Monate 1 Tag her von Pernelle.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her #173814 von jelo
jelo antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her #173819 von tpartner
tpartner antwortete auf das Thema: 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.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her #173820 von jelo
jelo antwortete auf das Thema: Generate random number as condition

tpartner schrieb: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her #173821 von Pernelle
Pernelle antwortete auf das Thema: 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
Anhang:

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her #173822 von Pernelle
Pernelle antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her #173824 von jelo
jelo antwortete auf das Thema: Generate random number as condition

Pernelle schrieb: "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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
2 Monate 1 Tag her - 2 Monate 1 Tag her #173825 von Pernelle
Pernelle antwortete auf das Thema: 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
Letzte Änderung: 2 Monate 1 Tag her von Pernelle.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Monat 4 Wochen her #173950 von Pernelle
Pernelle antwortete auf das Thema: 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%)

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Monat 4 Wochen her - 1 Monat 4 Wochen her #173955 von jelo
jelo antwortete auf das Thema: 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
Letzte Änderung: 1 Monat 4 Wochen her von jelo.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Monat 4 Wochen her - 1 Monat 4 Wochen her #173972 von Joffm
Joffm antwortete auf das Thema: 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
Letzte Änderung: 1 Monat 4 Wochen her von Joffm.
Folgende Benutzer bedankten sich: f_funke

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Monat 4 Wochen her #173976 von jelo
jelo antwortete auf das Thema: 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

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Monat 4 Wochen her #173977 von Pernelle
Pernelle antwortete auf das Thema: Generate random number as condition
Many thanks for this, Joffm! I don't know how I could overlook this! Thanks a lot!

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha