Welcome, Guest
Username: Password: Remember me

TOPIC: Exclude specific answer from randomization

Exclude specific answer from randomization 2 years 6 months ago #79243

  • Thomas
  • Thomas's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 23
  • Thank you received: 4
  • Karma: 5
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: 2 years 6 months ago by Thomas.
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 6 months ago #79272

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
The following user(s) said Thank You: Thomas

Re: Exclude specific answer from randomization 2 years 6 months ago #79283

  • Thomas
  • Thomas's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 23
  • Thank you received: 4
  • Karma: 5
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: 2 years 6 months ago by Thomas.
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 6 months ago #79411

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252
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)limesurvey.org'"
Last Edit: 2 years 6 months ago by Mazi.
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 6 months ago #79441

  • Thomas
  • Thomas's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 23
  • Thank you received: 4
  • Karma: 5
Ok, I have tried my very best and added a note regarding the specific requirements:
docs.limesurvey.org/Workarounds%3A+Manip...iple_numerical_input
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 6 months ago #79450

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 1 month ago #86814

  • paulalford
  • paulalford's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 1
Mazi wrote:
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: 2 years 1 month ago by paulalford.
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 1 month ago #86819

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 1 month ago #86885

  • paulalford
  • paulalford's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 1
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: 2 years 1 month ago by paulalford.
The administrator has disabled public write access.

Re: Exclude specific answer from randomization 2 years 1 month ago #86914

  • paulalford
  • paulalford's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 1
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: 2 years 1 month ago by paulalford.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.298 seconds
Donation Image