-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSimulation_1stim_1psy_2resp_Watson(2017).html
74 lines (63 loc) · 2.95 KB
/
Simulation_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
74
<!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 true_slope = 3.5
const true_guess = 0.5
const true_lapse = 0.02
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 = [true_slope] // Don't forget to add brackets, i.e., specify as an array.
const guess = [true_guess]
const lapse = [true_lapse]
// 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)
// Note that the response is binominal.
function simulate_observer(contrast){
const true_threshold = -20
if (Math.random() > func_resp0(contrast, true_threshold, true_slope, true_guess, true_lapse)){
return 1 // yes
} else {
return 0 // no
}
}
const nTrials = 32 // This is identical to that of Watson (2017)
for (let i = 0; i < nTrials; i++){
const contrast = jsqp.getStimParams()
const resp = simulate_observer(contrast)
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 true threshold as -20.`)
console.log(`jsQuestPlus estimates as ${estimates[0]}.`)
</script>
</html>