我正在用Qualtrics和JavaScript建立一个关于投票 Select 和违反民主规范的联合实验.在典型的联合操作中,您让所有属性级别都是随机的.然而,这在选举中是不现实的,因 for each 政党只有一名候选人.
以下是我现在使用的代码:
// Set number of choices (number of elections);
var CJ_numChoice = 3;
// Vectors containing all attribute levels:
var CJ_eth = ["White", "South Asian", "East Asian", "Indigenous"];
var CJ_gender = ["Man", "Woman"];
var CJ_age = ["35", "65"];
var CJ_pid = ["Liberal", "Conservative", "NDP"];
var CJ_occup = ["Lawyer", "Political Staffer", "Construction worker", "Business person"];
var CJ_exp = ["No experience", "Mayor", "Member of provincial legislature", "Member of Parliament"];
var CJ_wel = ["Spending on welfare should be kept the same", "Spending on welfare should be increased", "Spending on welfare should be reduced"];
var CJ_enviro = ["Must find a balance between reducing greenhouse gas emissions and maintaining jobs in the oil and gas sector", "Must prioritize reducing greenhouse gas emissions over the jobs in the oil and gas sector", "Must prioritize jobs in the oil and gas sector over reducing greenhouse gas emissions"];
var CJ_court = ["A prime minister should always adhere to court decisions even though they might seem politicized", "A prime minister should not be bound by court decisions he or she regards as politicized"];
var CJ_prot = ["The prime minister should not be allowed to ban non-violent opposition protests under any circumstances", "The prime minister should be free to ban non-violent opposition protests if they are disruptive to society"];
// Fisher - Yates shuffle:
function shuffle(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
// Shuffle a vector, choose the first entry:
function shuffle_one(theArray) {
var out = shuffle(theArray);
return out[0];
}
var CJ_attribnames = ["Ethnicity", "Gender", "Age", "Party", "Previous occupation", "Prior political experience", "Position on welfare spending", "Position on environmental issues", "Position on courts", "Position on press freedom", "Position on protests rights"];
function randomize(i) {
// Randomly draw the attributes for each candidate
var c1 = [shuffle_one(CJ_eth), shuffle_one(CJ_gender), shuffle_one(CJ_age), shuffle_one(CJ_pid), shuffle_one(CJ_occup), shuffle_one(CJ_exp), shuffle_one(CJ_wel), shuffle_one(CJ_enviro), shuffle_one(CJ_court), shuffle_one(CJ_prot)];
var c2 = [shuffle_one(CJ_eth), shuffle_one(CJ_gender), shuffle_one(CJ_age), shuffle_one(CJ_pid), shuffle_one(CJ_occup), shuffle_one(CJ_exp), shuffle_one(CJ_wel), shuffle_one(CJ_enviro), shuffle_one(CJ_court), shuffle_one(CJ_prot)];
// Save the results
for (var k = 1; k <= CJ_attribnames.length; k++) {
var CJ_index = k - 1;
Qualtrics.SurveyEngine.setEmbeddedData('c' + i + '_attrib' + k + '_name', CJ_attribnames[CJ_index]);
Qualtrics.SurveyEngine.setEmbeddedData('c' + i + '_attrib' + k + '_c1', c1[CJ_index]);
Qualtrics.SurveyEngine.setEmbeddedData('c' + i + '_attrib' + k + '_c2', c2[CJ_index]);
}
}
for (var i = 1; i <= CJ_numChoice; i++) {
randomize(i);
}
});
你能帮我弄清楚如何确保两个候选人的政党在以下方面总是不同的风格:让候选人S的政党是随机的.如果候选人1是自由党或新民主党候选人2只能是保守党.如果候选人1是保守党,候选人2可以随机成为自由党或新民主党.