【问题标题】:How to randomly assign to treatment groups for online web study?如何随机分配到治疗组进行在线网络学习?
【发布时间】:2020-06-01 16:44:36
【问题描述】:

我正在进行一项网络研究,参与者将以不同网页的形式按比例随机分配到治疗组。我有一个研究登录页面,我计划在其中根据样本量范围内的随机整数将参与者引导到不同的页面,从而将参与者分配到不同的治疗组。例如,对于 n=100 的研究,此代码可能如下所示:

/// Function for randomly shuffling array
function shuffle(array) {
  array.sort(() => Math.random() - 0.5);
}

const STUDY_LEN = 100;  /// Study n
const arr_0 = new Array(STUDY_LEN/2).fill(0);  /// Create array for treatment 1
const arr_1 = new Array(STUDY_LEN/2).fill(1);  /// Create array for treatment 2

const arr_assign = arr_0.concat(arr_1);  /// Concatenate treatment arrays for entire study assignment
arr_shuffle = shuffle(arr_assign);  /// Randomize order of array

for (i = 0; i < STUDY_LEN-1; i++){
  if (arr_shuffle[i] == 0){
    //// Change hyperlink to web page for treatment 1
}
  else{
    //// Change hyperlink to web page for treatment 2
  }
}

如何在对网页的多次访问中存储这些变量(主要是打乱的分配数组),以便我将参与者平等地分配给每个治疗(治疗 1 中的 50 名参与者,治疗 2 中的 50 名参与者)?我的解决方案似乎不是一种非常可靠的随机分配用户不同治疗方法的方法,因此我愿意接受任何/所有建议。

【问题讨论】:

  • 您可以多次尝试shuffle()ing 以获得更好的随机分布。因为您总是有 50 (0)-50 (1),所以没有机会发生组倾斜,即。 arr_assign.reduce((t,n)=&gt; t+n) 永远是 50

标签: javascript random variable-assignment


【解决方案1】:

如果您想随机但均等地分发测试,则必须从服务器获取测试类型

function getTestType () {
  if (Math.random() < 0.5) {
    // This will ensure that the maximum number of occurences for the test A will be 50.
    if (getNumberOfOccurencesOfTestA() < 50) {
      return true; // Test A
    }
  }

  // This will ensure that the maximum number of occurences for the test B will be 50.
  if (getNumberOfOccurencesOfTestB() < 50) {
    return false; // Test B
  }

  // Just return 'undefined' if both of the test already have 50 occurences each.
  return;
}

“getNumberOfOccurencesOfTestA”和“getNumberOfOccurencesOfTestB”是查看变量的函数,该变量保持测试A和测试B分别发生的次数状态,它可以是全局变量、数据库、文件等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-19
    • 2022-05-06
    • 2020-09-18
    • 2013-04-24
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 2018-03-15
    相关资源
    最近更新 更多