-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExample_1stim_1psy_2resp_Watson(2017).html
73 lines (61 loc) · 3.21 KB
/
Example_1stim_1psy_2resp_Watson(2017).html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<script src="../dist/jsQuestPlus.js"></script>
</head>
<body>
<p>This program simulates <a href="https://doi.org/10.1167/17.3.10">Watson (2017)'s</a> first example: "Estimation of contrast threshold {1, 1, 2}".</p>
<p>Watson wrote that:</p>
<blockquote>
<p>The first is a very simple case in which there is a single stimulus dimension (contrast), and only a single psychometric parameter (threshold). This is the case for which the original QUEST was designed.</p>
</blockquote>
<p>Please open the JavaScript console window in your browser. If you are using Chrome on Windows, press Ctrl + Shift + I to open the console.</p>
</body>
<script>
// Example: 1 stimulus parameter x 1 PF parameter x 2 responses
// Psychometric function corresponding to the first response (response = 0)
// You can specify the function or use the weibull/normcdf function jsQuest provides.
function func_resp0(stim, threshold, slope, guess, lapse) {
// const tmp = slope * (stim - threshold)/20
// return lapse - (guess + lapse -1)*Math.exp(-Math.pow(10, tmp))
return jsQuestPlus.weibull(stim, threshold, slope, guess, lapse)
}
// Psychometric function corresponding to the second response (response = 1).
function func_resp1(stim, threshold, slope, guess, lapse) {
return 1 - func_resp0(stim, threshold, slope, guess, lapse)
}
const contrast_samples = jsQuestPlus.linspace(-40, 0) // [-40, -39, -38, ..., -1, 0]
const threshold_samples = jsQuestPlus.linspace(-40,0) // [-40, -39, -38, ..., -1, 0]
const slope = [3.5] // Don't forget to add brackets, i.e., specify as an array.
const guess = [0.5]
const lapse = [0.02]
// These values are written in Watson (2017)
// Note that, in Watson (2017), the first answer corresponds to 1 and the second answer to 2.
const simulated_answers = [1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
const simulated_stim = [-18, -22, -25, -28, -30, -22, -13, -15, -16, -18, -19, -20, -21, -22, -23, -19, -20, -20, -18, -18, -19, -17, -17, -18, -18, -18, -19, -19, -19, -19, -19, -19]
// jsqp means jsQuestPlus. You can use any variable name you like.
const jsqp = new jsQuestPlus({
psych_func: [func_resp0, func_resp1],
stim_samples: [contrast_samples],
psych_samples: [threshold_samples, slope, guess, lapse]
})
console.log(jsqp)
for (let i = 0; i < simulated_answers.length; i++){
const contrast = jsqp.getStimParams()
const resp = simulated_answers[i]
if (contrast !== simulated_stim[i]) alert(`Check trial ${i+1}`)
console.log(`Trial ${i+1}: Contrast = ${contrast}; Response = ${resp}`)
jsqp.update(contrast, resp)
}
const estimates = jsqp.getEstimates()
console.log(estimates)
console.log(`Watson (2017) wrote the estimated threshold as -20.`)
console.log(`jsQuestPlus estimates as ${estimates[0]}.`)
//////////////////////////////
// This is optional
// const estimates_mean = jsqp.getEstimates('mean')
// console.log(estimates_mean)
// const sd = jsqp.getSDs()
// console.log(sd)
</script>
</html>