Exclude specific answer from randomization

More
6 years 5 months ago - 6 years 5 months ago #79243 by Thomas
Thomas created the topic: Exclude specific answer from randomization
Dear all,

I am currently working on a questionnaire including a constant sum scale. That is, I have included a question of the type multiple numerical input. To reduce biases, I have activated random order.

However I also need to include an answer option "Others:". As multiple numerical input does not feature "other" functionality I have simply included one answer option "Others:". Unfortunately this gets included in the randomization.

So what I currently might get is:

Answer C: _____
Others: _____
Answer A: _____
Answer D: _____
Answer B: _____

What I would like to achieve is:

Answer C: _____
Answer A: _____
Answer D: _____
Answer B: _____
Others: _____

In brief: I would need to exclude one specific answer from randomization and statically set it as the final answer.

Is there any know way to achieve this?

Thanks for your help!

Thomas
Last Edit: 6 years 5 months ago by Thomas.

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

More
6 years 5 months ago #79272 by Mazi
Mazi replied the topic: Exclude specific answer from randomization


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
The following user(s) said Thank You: Thomas

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

More
6 years 5 months ago - 6 years 5 months ago #79283 by Thomas
Thomas replied the topic: Exclude specific answer from randomization
Mazi,

Thank you very much for pointing me in the right direction.

Even though my jQuery and JavaScript capabilities are really limited I have managed to modify the workarounds to achieve what I have been looking for.

For future reference I would integrate my solution into the wiki. However I believe the jQuery insertion I have chosen is rather specific and would not work if the advanced settings of the question would not contain an "equal_sum", as I had to insert the answer right before the "li.multiplenumerichelp" (see below) which I believe only appears in this specific case.

Does any of you with more jQuery/DOM experience have an idea how to generalize?

Anyway, thank you very much for the help - my current problem has been solved!
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Function to allow randomization of all answers except the last one in multiple numeric input questions
		function partRand(sID, gID, qID) { 
 
			// Find the number of answers
			var ansCount = ''
			$( 'div#question' + qID + ' div.answers li' ).each(function(i) {
				ansCount = (i - 1);
			});
 
			// Place the last answer created at the end of the list - but before the first helping sum
			$( 'li#javatbd' + sID + 'X' + gID + 'X' + qID + ansCount + '' ).insertBefore($( 'div#question' + qID + ' div.answers li.multiplenumerichelp' ).first());
			}
 
		// Call the function with the SID, GID and QID
		partRand(SID, GID, QID);
 
	});
Last Edit: 6 years 5 months ago by Thomas.

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

More
6 years 5 months ago - 6 years 5 months ago #79411 by Mazi
Mazi replied the topic: Exclude specific answer from randomization

Thomas wrote: For future reference I would integrate my solution into the wiki.

Please add your solution!


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
Last Edit: 6 years 5 months ago by Mazi.

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

More
6 years 5 months ago #79441 by Thomas
Thomas replied the topic: Exclude specific answer from randomization
Ok, I have tried my very best and added a note regarding the specific requirements:
docs.limesurvey.org/Workarounds%3A+Manip...iple_numerical_input

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

More
6 years 5 months ago #79450 by Mazi
Mazi replied the topic: Exclude specific answer from randomization
Great, thanks!


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

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

More
6 years 6 days ago - 6 years 6 days ago #86814 by paulalford
paulalford replied the topic: Exclude specific answer from randomization

Mazi wrote: Have a look at these workarounds:
docs.limesurvey.org/Workarounds%3A+Manip...List_radio_questions

docs.limesurvey.org/Workarounds%3A+Manip...t_dropdown_questions


That works OK for one answer in a list, but can it be done for more than one. I have a list:

Photovoltaic (PV) Array to generate electricity
Wind Farm to generate electricity
Energy efficient lighting
Combined heat and power
Electric Vehicles
Energy efficient IT
Solar water heating
Improved insulation
Other
None
Don’t know

And these need to be randomized, except the last three in the list. Is that possible?
Last Edit: 6 years 6 days ago by paulalford.

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

More
6 years 5 days ago #86819 by Mazi
Mazi replied the topic: Exclude specific answer from randomization
When using your own, custom code, this is possible as well, you just need to adjust the code accordingly.

To have multiple exclude other options, simply separate them with a ";" when entering the answer codes at the advanced question settings.


Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

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

More
6 years 4 days ago - 6 years 4 days ago #86885 by paulalford
paulalford replied the topic: Exclude specific answer from randomization
Hi Mazi,

Often in market research studies we want to random order and have three options that shouldn't be randomized, for example, Other, None and Don't Know. This is the problem I encountered.

Below is the JavaScript that lets me randomize the list but forces the last three list options to be placed at the end. I will modify this script so we can specify how many list options we force to be un-randomized.

Randomize answer options needs to be turned off in Advanced Options.

Cheers
Paul
<script type="text/javascript">
 
$(document).ready(function() {
 
		// Function to allow randomization of all answers except the last three in Multiple options and List/radio questions
		function partRand(sID, gID, qID) { 
 
			// Find the number of answers
			var ansCount = ''
			lastthreeitems=new Array();
		    var liid=new Array();
		    var $ul;
		    var j=0;
			$( '#question' + qID + ' td.answer li' ).each(function(i) {
							ansCount = (i + 1);							
 
});
 
$( '#question' + qID + ' td.answer li' ).each(function(i) {
							if(i>ansCount-4){							
							  lastthreeitems[j]=$(this).html();	
							  liid[j]=$(this).attr("id");
 
 
							  j++;						  
							  $(this).remove();
							 }												
 
});
$( '#question' + qID + ' td.answer li' ).each(function(i) {		
// get current ul
 
 
 
 
$ul = $(this).parent();
// get array of list items in current ul
var $liArr = $ul.children('li');
// sort array of list items in current ul randomly
$liArr.sort(function(a,b){
// Get a random number between 0 and 100
var temp = parseInt( Math.random()*100 );
// Get 1 or 0, whether temp is odd or even
var isOddOrEven = temp%2;
// Get +1 or -1, whether temp greater or smaller than 5
var isPosOrNeg = temp>5 ? 1 : -1;
// Return -1, 0, or +1
return( isOddOrEven*isPosOrNeg );
})
// append list items to ul
.appendTo($ul);
 
});	
 
$.each(lastthreeitems,function(i){
 
$( '#question' + qID + ' td.answer ul' ).append("<li id="+liid[i]+">"+this+"</li>");
});
 
	}
 
		// Call the function with the SID, GID and QID
		partRand(SSSSS, GG, QQ);
 
	});
 
</script>
Last Edit: 6 years 4 days ago by paulalford.

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

More
6 years 3 days ago - 6 years 3 days ago #86914 by paulalford
paulalford replied the topic: Exclude specific answer from randomization
Here is the updated Javascript to determine how many codes you exclude from the randomization. In the code example it is set to three. Just change the number of the var insertitems. I'll add this to the Wiki later too.
<script type="text/javascript">
 
$(document).ready(function() {
 
		// Function to allow randomization of all answers except the last one in Multiple options and List/radio questions
		function partRand(sID, gID, qID) { 
			//var to define how many lists to be added at the end
			var insertitems=3;
			// Find the number of answers
			var ansCount = ''
			lastitems=new Array();
		    var liid=new Array();
		    var $ul;
		    var j=0;
			$( '#question' + qID + ' td.answer li' ).each(function(i) {
							ansCount = (i + 1);							
 
});
 
$( '#question' + qID + ' td.answer li' ).each(function(i) {
							if(i>ansCount-(insertitems+1)){							
							  lastitems[j]=$(this).html();	
							  liid[j]=$(this).attr("id");
 
 
							  j++;						  
							  $(this).remove();
							 }												
 
});
$( '#question' + qID + ' td.answer li' ).each(function(i) {		
// get current ul
 
 
 
 
$ul = $(this).parent();
// get array of list items in current ul
var $liArr = $ul.children('li');
// sort array of list items in current ul randomly
$liArr.sort(function(a,b){
// Get a random number between 0 and 100
var temp = parseInt( Math.random()*100 );
// Get 1 or 0, whether temp is odd or even
var isOddOrEven = temp%2;
// Get +1 or -1, whether temp greater or smaller than 5
var isPosOrNeg = temp>5 ? 1 : -1;
// Return -1, 0, or +1
return( isOddOrEven*isPosOrNeg );
})
// append list items to ul
.appendTo($ul);
 
});	
 
$.each(lastitems,function(i){
 
$( $ul ).append("<li id="+liid[i]+">"+this+"</li>");
});
 
	}
 
		// Call the function with the SID, GID and QID
		partRand(SSSSS, GG, QQ);
 
	});
 
</script>
 
Last Edit: 6 years 3 days ago by paulalford.

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

More
6 months 3 weeks ago #166447 by stephanied
stephanied replied the topic: Exclude specific answer from randomization
In version 2.73.1 I am trying to partially randomize a multiple numeric input question that has an equal sum value setting applied. I've attempted to manipulate the above code to work on this version, but my coding skills are subpar. Can anyone help me with editing this code? The question I am working on only has one fixed answer, but I would also like to be able to fix multiple answers in the future.

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

More
6 months 3 weeks ago #166451 by tpartner
tpartner replied the topic: Exclude specific answer from randomization
That code is too bloated for your requirements.

Try this, modifying the "lastItems" values as required.

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question ID
		var qID = '{QID}';
 
		// List the sub-question codes to be placed at the end of the list
		// (comma-separated)
		var lastItems = ['SQ007','SQ008'];
 
		// Insert the last items
		$.each(lastItems, function(i, val) {
			$('#question{QID} tr[id^="javatbd"]:last').after($('#question{QID} tr[id^="javatbd"][id$="X'+qID+val+'"]'));
		});
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3514.lss
File Size:18 KB

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

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

More
6 months 3 weeks ago #166452 by stephanied
stephanied replied the topic: Exclude specific answer from randomization
Thank you!!!!!!

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

More
3 weeks 3 days ago #174534 by stephanied
stephanied replied the topic: Exclude specific answer from randomization
I'm looking for an updated code for version 3.14
Multiple numeric input with two answers fixed to the bottom.

I've tried to alter the code but cannot get it to work..

Thanks in advance!

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

More
3 weeks 2 days ago #174556 by tpartner
tpartner replied the topic: Exclude specific answer from randomization
This will work in 3.x:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question ID
		var qID = '{QID}';
 
		// List the sub-question codes to be placed at the end of the list
		// (comma-separated)
		var lastItems = ['SQ007','SQ008'];
 
		// Insert the last items
		$.each(lastItems, function(i, val) {
			$('#question{QID} li[id^="javatbd"]:last').after($('#question{QID} li[id^="javatbd"][id$="X'+qID+val+'"]'));
		});
	});
</script>

Sample survey attached:

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

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!