javascript - 如何更改 JSPsych 中刺激呈现的权重?

标签 javascript image for-loop shuffle jspsych

我正在 JSPsych 中编写一个实验,其中有十个条件。我需要根据条件呈现不同频率的五个图像的数组。

我已经设法使用 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. 

关于javascript - 如何更改 JSPsych 中刺激呈现的权重?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59154173/

相关文章:

php - 在新标签页中打开随机图片 PHP

css - Base64编码缓存

c++ - Qt foreach 循环排序与 QList 的 for 循环

javascript - 为什么已检查的 radio 输入的值可以正确访问,但在 "for"循环内访问时默认为组中的第一个值?

javascript - Rails data-remote 属性并不总是请求 JS 响应

javascript - 如何查看/抓取隐藏在页面源代码中的真实文本值?

javascript - 如何在 Image() 构造函数中发送 cookie

C++11 基于范围的按值、引用和指针的自动 for 循环

javascript - 在javascript中实现扩展方法

javascript - 在触发 onChange 时 react 仅更新列表的第一个元素