Exclude specific answer from randomization

More
5 years 5 months ago - 5 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: 5 years 5 months ago by Thomas.

Please Log in to join the conversation.

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


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
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 to join the conversation.

More
5 years 5 months ago - 5 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: 5 years 5 months ago by Thomas.

Please Log in to join the conversation.

More
5 years 5 months ago - 5 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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
Last Edit: 5 years 5 months ago by Mazi.

Please Log in to join the conversation.

More
5 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 to join the conversation.

More
5 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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 6 days ago - 5 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: 5 years 6 days ago by paulalford.

Please Log in to join the conversation.

More
5 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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 days ago - 5 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: 5 years 4 days ago by paulalford.

Please Log in to join the conversation.

More
5 years 4 days ago - 5 years 4 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: 5 years 4 days ago by paulalford.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now