Can I select a random answer from a multiple choice question

More
1 year 11 months ago #161791 by davebostockgmail
I have a survey that has the following requirements

1) Survey is displayed question by question
2) I have a list of 20 brands with an other specify at the end in a multiple choice question
3) I need to ask a respondent about a randomly answered brand for a series of subsequent questions

So for example
B5a Which of the following have you heard of
apples
banana
pears

E1 What do you like about [Random from B5a]

I have looked through the solutions that have been provided in the past but these all include group by group with a hidden text question ... this will not work for me as we have over 100 questions so each would have to be moved into its own group.

Is this even possible?

Thanks in advance

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

LimeSurvey Partners
More
1 year 11 months ago #161799 by holch
First of all: I assume that the random brand should be chosen from the ones answered, right? So only from the ones they have heard of?

Problem with question by question is where to "hide" the question that creates the randomness.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 year 11 months ago #161804 by davebostockgmail
That's correct Holch ... I have thought the best way to do this would be to create an array in JQuery using the answers given then create a random number from the number of answers given and then use that to select from the array and push that into a single choice question.
Unfortunately my Jquery skills are not that advanced.

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

More
1 year 11 months ago - 1 year 11 months ago #161810 by Joffm
Hi,
you can do this with some equations.
I did this some time ago. Maybe not the best, but working.

1. Equation "eqmyString"
I create a string with the "join"-function.
{join(if(Q01_SQ001=="Y","01",""),if(Q01_SQ002=="Y","02",""),if(Q01_SQ003=="Y","03",""),if(Q01_SQ004=="Y","04",""),...)}
You see if the brand was selected the code is added to the string.
You will get something like "0306111417"

2. Equation "eqnBrands"
{count(that.Q01)}

I count the number of entered brands and get "eqnBrands". In this case 5.

3. Equation "eqRandom"
I create a random number (1-numberBrands)
{rand(1,eqnBrands)}
Let's say: 4

4. Equation "eqmyBrand"
I get the substring of my string depending on the random number (eqRandom)
{substr(eqmyString,2*(eqRandom-1),2)}.
In this case substr(eqmyString,6,2) and you get "14".

You have to set (eqRandom-1) because substr starts at position 0.

And in your next question you pipe in the name.?
What do you like about {if(eqmyBrand=="01","Apples",if(eqmyBrand=="02","Bananas",if(eqmyBrand=="03","Pears","")))}?


Best regards
Joffmn


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 11 months ago by Joffm.

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

More
1 year 11 months ago #161811 by davebostockgmail
Amazing ... thank you so much ...

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

More
1 year 11 months ago #161816 by holch
Joffm, looks good. But where do you hide those equation type questions in a question by question environment?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

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

More
1 year 11 months ago - 1 year 11 months ago #161821 by Joffm
Have a look at the sample.

Here it is question by question , and I did it group by group as well.

File Attachment:

File Name: limesurvey...2-18.lss
File Size:22 KB


Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 1 year 11 months ago by Joffm.

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

More
5 months 5 days ago #186363 by Nighthawlk
Hi there,
I tried to addapt Joffms solution for a question including text as answers
Everything is working for me, exept step one:
"1. Equation "eqmyString"
I create a string with the "join"-function.
{join(if(Q01_SQ001=="Y","01",""),if(Q01_SQ002=="Y","02",""),if(Q01_SQ003=="Y","03",""))}
"

My first addaption is looking like this:
{join(if(!is_empty(NW1_SQ001),
if(!is_empty(NW1_SQ002),
if(!is_empty(NW1_SQ003))))}

Here, limesurvey doesn't accept the commas

Afterwards, I tried out an other addaption like this:
{ ... if(!is_empty(NW1_SQ003),3,
if(!is_empty(NW1_SQ002),2,
if(!is_empty(NW1_SQ001),1))))}

This was working yesterday. Today it is only working when I have NW1_SQ018 answered.

Can you help me finding the mistakes?

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

More
5 months 4 days ago #186391 by Joffm

{join(if(!is_empty(NW1_SQ001),
if(!is_empty(NW1_SQ002),
if(!is_empty(NW1_SQ003))))}
Here, limesurvey doesn't accept the commas


LimeSurvey does accept comma, but your usage of the if-statements seems to be wrong.
We don't see your sample.

Remember:
if(condition,what if true,what if false)

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

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

More
5 months 3 days ago #186397 by DenisChenu

Joffm wrote: Remember:
if(condition,what if true,what if false)

Just a correction :
if(condition,what if true)
OR
if(condition,what if true,what if false)
Since 3.0.2 LimeSurvey version :)

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 .
An error happen ? Before make a new topic : remind the Debug mode .

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

More
5 months 2 days ago #186439 by Nighthawlk
Thank you very much for your answers.

Remember:
if(condition,what if true,what if false)

that would mean, my example 2 should work properly although it doesn't, right?

We don't see your sample

I also attached my sample for a better comprehensibility of the appearing errors

It would be very nice, if you could find the time for a deeper look inside the code

File Attachment:

File Name: limesurvey...5926.lsg
File Size:19 KB
Attachments:

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

More
5 months 2 days ago #186443 by Nighthawlk
PS: see question COUNT1

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

More
5 months 2 days ago - 5 months 2 days ago #186456 by Joffm

that would mean, my example 2 should work properly although it doesn't, right?


No, because there are only if-statements but nothing what you want to join.

And, please, send a whole survey (*.lss) with only the relevant questions.

lsq and lsg are language dependent.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 months 2 days ago by Joffm.

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

More
5 months 2 days ago - 5 months 2 days ago #186461 by Joffm
Hi, here your survey back.

There was an error in the join-statement. (no brackets in front of the "if")
join(if( ! is_empty(NW1_SQ001), "01", ""),(if( ! is_empty(NW1_SQ002), "02", ""),(if( ! is_empty(NW1_SQ003), "03", ""),...
The bracket in front of the first "if" is the bracket of the join function.

And I set subquestion relevance to zhe first question so that one row after the other is displayed.
And the equations have to be on a different page.
I explained it already in a different post with the same approach.
https://www.limesurvey.org/forum/can-i-do-this-with-limesurvey/118275-children-randomization
If the random-function is on the same page it will be fired each time and each time you will get a new value.
To avoid this we use "if(is_empty(random),rand(1,5),random).
But in this case the random function will fire after your first entry, selects "1" as random value, which never is changed.





Best regards
Joffm

File Attachment:

File Name: limesurvey...3929.lss
File Size:33 KB


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 5 months 2 days ago by Joffm.
The following user(s) said Thank You: Nighthawlk

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

More
5 months 2 days ago #186475 by Joffm
Furthermore: remove the equation "JOIN".
It is not used ib your survey.
You see, you use all filled fields of your first question.
The "trick" to create a string by joining characters was used if you'd only consider entries that have to fulfill a condition.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Nighthawlk

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!