Welcome to the LimeSurvey Community Forum

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

A complex relevance equation for tracking study

  • maxersloan
  • maxersloan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 5 months ago #207405 by maxersloan
Hello,

I have a brand tracking study that requires a complex relevance equation and I'm not sure how to piece it all together. Say I have 10 brands as subquestions of a multiple choice question ("select all that apply"). In order to show the brand, the respondent must have selected the brand in a previous question.

Now for the tricky part: I want to show a maximum of 3 brands and I want to prioritize as follows:

1 - My brand
2 - Two other top competitor brands
3 - All others

Anyone have a good idea for this?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207412 by Joffm
Hi,

I have a solution.
1st question M1 - only to select some brands - your "previous" question.

Then:
eqM1 (hidden question of type equation): build a list of characters, if the main brands were selected
{join(if(M1_SQ001=="Y","A",""),if(M1_SQ002=="Y","B",""),if(M1_SQ003=="Y","C",""))}

eqM2 (hidden question of type equation): build a list of characters if the other brands were selected
{list(if(M1_SQ004=="Y","D",""),if(M1_SQ005=="Y","E",""),if(M1_SQ006=="Y","F",""),if(M1_SQ007=="Y","G",""),if(M1_SQ008=="Y","H",""),if(M1_SQ009=="Y","I",""),if(M1_SQ010=="Y","J",""))}

eqM3 (hidden question of type "short text" with default value "eqM2"):
Included this javascript to select three brands randomly selected out of eqM2
Code:
<script type="text/javascript" charset="utf-8">
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
 
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
 
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
 
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
 
  return array;
}
 
 
  $(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
      var arr =  $('#question{QID} input[type="text"]').val();
      var nArr = arr.split(', ');
      arr = shuffle(nArr);
      anumbers = arr.slice(0,3);
      $('#question{QID} input[type="text"]').val(anumbers);
      $('#question{QID}').hide();
   });
</script>

QInfo (question of type "text display")
Because we hide eqM3 by javascript we need some visible question in this group.
Use it to explain to the respondent what happens next

eqM4 (hidden question of type equation): build a three letter string with leading eqM1 and trailing eqM3
{substr(join('#',eqM1,str_replace(',','',eqM3)),0,4)}
The first "#" is to avoid an idex of "0". the function "strpos" uses "0" as "not found".
And the function "str_replace", removes the comma.

M2: The resulting multiple question.
With subquestion relevance
My Brand: strpos(eqM4,"A")>0
Comp 1: strpos(eqM4,"B")>0
...





File Attachment:

File Name: limesurvey...5525.lss
File Size:32 KB


If I misunderstood your requirements, use it as an example.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: maxersloan
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207414 by Joffm
Here a slightly better solution without the "text display".

File Attachment:

File Name: limesurvey...5525.lss
File Size:32 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: maxersloan
The topic has been locked.
  • maxersloan
  • maxersloan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 5 months ago #207451 by maxersloan
Replied by maxersloan on topic A complex relevance equation for tracking study
Hi Joffm,

Thank you!!! This is very close to working for me. The only part that does not work yet is the question eqM3. I don't know anything about javascript, so I'm sorry for my ignorance...

I imported and tested your survey. When I viewed the results in excel, I see that eqM3 randomizes the list from eqM2. But when I tested my survey, eqM3 didn't populate. See attached for a comparison (your survey on the left and mine on the right).

Do I have to change anything in the javascript code for eqM3 for it to work properly? In your survey, I don't see any question codes/IDs anywhere within eqM3, so I thought I could copy and paste without needing to change anything. Everything is the same as your survey (same question codes, advanced settings, etc.).
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago - 3 years 5 months ago #207453 by Joffm

I don't see any question codes/IDs anywhere within eqM3

Of course you see, it is the placeholder {QID}

and second: without YOUR survey (lss export) nobody can see your mistake.

Joffm

Did you set the default value of eqM3 to {eqM2}?

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 5 months ago by Joffm.
The following user(s) said Thank You: maxersloan
The topic has been locked.
  • maxersloan
  • maxersloan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 5 months ago - 3 years 5 months ago #207466 by maxersloan
Replied by maxersloan on topic A complex relevance equation for tracking study
Hi Joffm,

Thanks. I saw in your survey that you left the QID as "QID", so I did not change it. Should both QID's be replaced with the question code ("eqM2") or the full ID (surveyidXgroupidXquestionID) for eqM2? I tried both but neither worked.

I did not see the default value anywhere. Is this a new feature? I'm working with 2.6.7-lts.


EDIT: Nevermind! I found the "edit default answers" button. I had never used that before. Now it works perfectly. Thank you Joffm!! :)
Last edit: 3 years 5 months ago by maxersloan.
The topic has been locked.
  • maxersloan
  • maxersloan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 5 months ago #207942 by maxersloan
Replied by maxersloan on topic A complex relevance equation for tracking study
Hi Joffm,

If I wanted to change the number of brands it selects, what do I do?

Now I am trying to select a maximum of 4 brands. So I tried changing the argument in eqM3 to:
Code:
slice(0,4)

and the equation at eqM4 to:
Code:
{substr(join('#',eqM1,str_replace(',','',eqM3)),0,5)}

But no luck...
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207944 by Joffm
Please, always provide the lss export.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207957 by Joffm
So, what means 4 brands.

In your first requirements you had "YourBrand" and two "CompetitorBrands".
Now you would like to extend to four brands.
Is this a third "CompetitorBrand" or randomly one of the "OtherBrands"?

According to this you have to adapt "eqM1" resp. "eqM2".

Assuming you stay to "YourBrand" and two "CompetitorBrands" I do not see an issue just changing to
eqM3 to: anumbers = arr.slice(0,4);
eqM4 to: {substr(join('#',eqM1,str_replace(',','',eqM3)),0,5)}





Therefore again:
Send YOUR survey (lss export).

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • maxersloan
  • maxersloan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 5 months ago #207979 by maxersloan
Replied by maxersloan on topic A complex relevance equation for tracking study
Thanks Joffm. I found the mistake--I just had to update the QID in eqM3.

However, it seems that eqM3 is not shuffling the 'other' brands. Attached is the LSS. I took the survey 3 times, each time selecting the same brands: my brand (F), 2 primary competitor brands (P and S), and 3 'other' brands (A, B, and D). Attached are the results of the shuffling, which then results in brand A being selected as the 4th brand every time.

(In the attached LSS survey, you can find the equation questions in the groups with "(Q11a)" and "(Q12)" in the group titles. The ones being used are eqM1-eqM4. You can ignore eqA1-eqA4.)
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207981 by Joffm
This is GIGO (Garbage in, Garbage out).

Why did you change this
var arr = $('#question{QID} input[type="text"]').val();
to
var arr = $('#question{742698X1624X21381} input[type="text"]').val();

{QID} is a placeholder that contains the actual question ID
as {SID} the actual survey ID and {SAVEDID} the ID in the answer table.
Or {SGQA} (survey,group,question,answer) expands to your "742698X1624X21381".
There are many more.
Whereas {742698X1624X21381} is nothing, it is just a string.

So "question{QID}" is expanded to "question21381", and this is used in the javascript.
This is not to be changed.


And you should not hide eqM3 nor eqA3 by css. Then they are not existing in the DOM and do not work.
You see this questions are hidden by javascript, here $('#question{QID}').hide();

Joffm

By the way:
Not all of the brands are taken in account for the equations. Did you check what happens if none of the interesting brands are selected?
And some other issues with look and feel.
1. Shorten the input of numbers
2. Why is it mandatory to enter something in Q6? If I only know the brand of Q5.
3. Q7, mandatory. But I didn't see any ads. Have a look at the plugin "checkBoxForText"
4. Q8 -> Q9. If I saw an ad (Q9) I should know this brand (Q8). You may filter or recode afterwards.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207987 by holch

And you should not hide eqM3 nor eqA3 by css. Then they are not existing in the DOM and do not work.

Really? I always thought by hiding them with CSS they are still in the HTML code. Generally CSS shouldn't delete HTML code, just not showing it on the page, right? I might be wrong though, my CSS/HTML is a little rusty.

But in general you should be able to hide questions via CSS, just not via the Limesurvey GUI with "Always hide this question", then it won't appear in the html code, but when using the class .hidden they should still be in the source code, just not showing up for the user.

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