我正在JSPsych中编写一个实验,其中有10个条件。我需要根据情况呈现由五个具有不同频率的图像组成的阵列。

我已经设法使用for循环和randomize.sampleWithReplacement进行某种工作,但是它没有以我需要的频率显示图像。

例如,在一种情况下,我希望图像5被呈现8次,图像4被呈现6次,依此类推。

有谁知道我如何使用插件和JSPsych函数实现这一目标?

到目前为止,这是我的代码:

if (cond2 == 'uniform') {
  var ratings_r = jsPsych.randomization.repeat(ratings, 4);
  for (var i = 0; i < ratings_r.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=" + ratings_r[i] + "><br><br><br>"
      }
    ]
  });
}
} if (cond2 == 'left-skew') {
  var ratings_ls = jsPsych.randomization.sampleWithReplacement(ratings, 20, [2, 1, 1, 1, 1]);
  console.log(ratings_ls)
  for (var i = 0; i < ratings_ls.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=" + ratings_ls[i] + "><br><br><br>"
    }
    ]
    });
  }
  } else {
  var ratings_rs = jsPsych.randomization.sampleWithReplacement(ratings, 20, [1, 1, 1, 1, 4]);
  console.log(ratings_rs)
  for (var i = 0; i < ratings_rs.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=" + ratings_rs[i] + "><br><br><br>"
    }
    ]
    });
  }

  };


它适用于第一个条件(因为这很简单)。

这只是我用JSPsych编写的第二个实验,因此我是一个新手,将不胜感激!

------------------更新--------------

我现在有这个:

if (cond2 == 'uniform') {
  var uni = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1]);
  console.log(uni);
  for (var i = 0; i < uni.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=" + ratings[i] + "><br><br><br>"
      }
    ]
  });
}
} else if (cond2 == 'left-skew') {
  var lesk = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]);
  console.log(lesk);
  for (var i = 0; i < lesk.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=" + ratings[i] + "><br><br><br>"
    }
    ]
    });
  }
  } else {
  var risk = jsPsych.randomization.sampleWithoutReplacement([1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5]);
  console.log(risk);
  for (var i = 0; i < risk.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=" + ratings[i] + "><br><br><br>"
    }
    ]
    });
  }

  };


我创建了一个随机排列的数组,该数组规定了演示频率,但是我不确定如何将其合并到循环中,以使图像呈现该次数。图像分别标记为1,2,3,4,5。

最佳答案

终于找到了可行的方法。

if (cond2 == 'uniform') {
  var uni = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1], 20);
  console.log(uni);
  for (var i = 0; i < uni.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=./img/" + uni[i] + ".png><br><br><br>"
      }
    ]
  });
}
} else if (cond2 == 'left_skew') {
  var lesk = jsPsych.randomization.sampleWithoutReplacement([5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1], 20);
  console.log(lesk);
  for (var i = 0; i < lesk.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=./img/" + lesk[i] + ".png><br><br><br>"
    }
    ]
    });
  }
  } else {
  var risk = jsPsych.randomization.sampleWithoutReplacement([1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5], 20);
  console.log(risk);
  for (var i = 0; i < risk.length; i++) {
  timeline.push({
    type: "html-button-response",
    choices: ['Click here to continue'],
    button_html: '<button class="jspsych-btn" style="display:none">%choice%</button>',
    on_start: function() { setTimeout(function(){setDisplay("jspsych-btn","")}, 3000)},
    is_html: true,
    timeline: [{
      stimulus: "<img src=./img/" + risk[i] + ".png><br><br><br>"
    }
    ]
    });
  }

  };

So I basically created an array specifying the frequency for each condition and called that in the for loop.

10-07 22:04