@decidables/detectable-elements 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE.md +1112 -0
  3. package/README.md +1218 -0
  4. package/lib/detectableElements.esm.js +18385 -0
  5. package/lib/detectableElements.esm.js.map +1 -0
  6. package/lib/detectableElements.esm.min.js +13 -0
  7. package/lib/detectableElements.esm.min.js.map +1 -0
  8. package/lib/detectableElements.umd.js +18413 -0
  9. package/lib/detectableElements.umd.js.map +1 -0
  10. package/lib/detectableElements.umd.min.js +13 -0
  11. package/lib/detectableElements.umd.min.js.map +1 -0
  12. package/package.json +58 -0
  13. package/src/components/detectable-control.js +272 -0
  14. package/src/components/detectable-response.js +414 -0
  15. package/src/components/detectable-table.js +602 -0
  16. package/src/components/index.js +7 -0
  17. package/src/components/rdk-task.js +586 -0
  18. package/src/components/roc-space.js +1220 -0
  19. package/src/components/sdt-model.js +1835 -0
  20. package/src/detectable-element.js +121 -0
  21. package/src/equations/dc2far.js +182 -0
  22. package/src/equations/dc2hr.js +191 -0
  23. package/src/equations/facr2far.js +120 -0
  24. package/src/equations/hm2hr.js +121 -0
  25. package/src/equations/hmfacr2acc.js +161 -0
  26. package/src/equations/hrfar2c.js +179 -0
  27. package/src/equations/hrfar2d.js +162 -0
  28. package/src/equations/index.js +8 -0
  29. package/src/equations/sdt-equation.js +141 -0
  30. package/src/examples/double-interactive.js +171 -0
  31. package/src/examples/human.js +184 -0
  32. package/src/examples/index.js +6 -0
  33. package/src/examples/interactive.js +131 -0
  34. package/src/examples/model.js +203 -0
  35. package/src/examples/sdt-example.js +76 -0
  36. package/src/examples/unequal.js +43 -0
  37. package/src/index.js +6 -0
package/README.md ADDED
@@ -0,0 +1,1218 @@
1
+ <!--lint ignore first-heading-level-->
2
+
3
+ # detectable-elements: Web Components for Visualizing Signal Detection Theory
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@decidables/detectable-elements?logo=npm)](https://www.npmjs.com/package/@decidables/detectable-elements)
6
+ [![license](https://img.shields.io/npm/l/@decidables/detectable-elements)](https://github.com/decidables/decidables/blob/main/LICENSE.md)
7
+
8
+ ## Usage
9
+
10
+ ### Install
11
+
12
+ ```shell
13
+ yarn add @decidables/detectable-elements
14
+ ```
15
+
16
+ ### Use
17
+
18
+ ```javascript
19
+ import '@decidables/detectable-elements';
20
+ ```
21
+
22
+ A bare import is used to register the elements in the custom registry, so they are then available
23
+ for use in HTML.
24
+
25
+ ## Contents
26
+
27
+ ### Components
28
+
29
+ Building blocks for interactive visualizations of SDT
30
+
31
+ #### `RDKTask` / `<rdt-task>`
32
+
33
+ Displays stimuli for random dot kinematogram signal detection task
34
+
35
+ When run, a block of trials is presented. Before each trial is an inter-trial interval (ITI). Each
36
+ trial then consists of a stimulus followed by a period of waiting for a response. The stimulus
37
+ consists of a circle with a collection of small dots moving about. Some trials are *signal* trials
38
+ and others are *noise* trials. On *noise* trials, the directions of the dots is independent and
39
+ random. On *signal* trials, a subset of the dots move coherently in the same direction. The task can
40
+ be paused and then resumed, and it can also be reset and run again.
41
+
42
+ ##### Attributes
43
+
44
+ - `coherence: number = 0.5`
45
+ - Proportion of dots moving coherently
46
+ - `count: number = 100`
47
+ - Number of dots
48
+ - `probability: number = 0.5`
49
+ - Probability of signal (as opposed to noise)
50
+ - `duration: number = 2000`
51
+ - Duration of stimulus in milliseconds
52
+ - `wait: number = 2000`
53
+ - Duration of wait period for response in milliseconds
54
+ - `iti: number = 2000`
55
+ - Duration of inter-trial interval in milliseconds
56
+ - `trials: number = 5`
57
+ - Number of trials per block
58
+ - `running: boolean = false`
59
+ - Currently executing block of trials
60
+
61
+ ##### Methods
62
+
63
+ - `reset()`
64
+ - Stops a currently running or ended block of trials and resets everything to be ready to run
65
+ again
66
+
67
+ ##### Custom Events
68
+
69
+ - `rdk-block-start`
70
+ - Indicates the beginning of a block of trials
71
+ - `rdk-block-end`
72
+ - Indicates the completion of a block of trials
73
+ - `detail` for `rdk-block-start` and `rdk-block-end`
74
+ - `trials: number`
75
+ - Number of trials in the block
76
+ - `rdk-trial-start`
77
+ - Indicates the beginning of a trial (iti is over and stimulus is about to start)
78
+ - `rdk-trial-middle`
79
+ - Indicates the middle of a trial (stimulus is over and the wait is about to start)
80
+ - `rdk-trial-end`
81
+ - Indicates the end of a trial (wait is over and iti is about to start)
82
+ - `detail` for `rdk-trial-start`, `rdk-trial-middle`, and `rdk-trial-end`
83
+ - `trials: number`
84
+ - Number of trials in the block
85
+ - `duration: number`
86
+ - Duration of stimulus in milliseconds
87
+ - `wait: number`
88
+ - Duration of wait period in milliseconds
89
+ - `iti: number`
90
+ - Duration of inter-trial interval in milliseconds
91
+ - `trial: number`
92
+ - Count of trial in block (one-based)
93
+ - `signal: string`
94
+ - Whether the signal is `present` or `absent` in this trial
95
+
96
+ ##### Example
97
+
98
+ ```html
99
+ <rdt-task coherence="0.1" count="50" probability="0.5" duration="1000" wait="1000" iti="500" trials="10" running></rdt-task>
100
+ ```
101
+
102
+ #### `ROCSpace` / `<roc-space>`
103
+
104
+ Interactive receiver operating characteristic (ROC) plot
105
+
106
+ An ROC plot that can show one or more locations in ROC space or zROC space. Each location can be
107
+ shown with a point, and/or with intersecting iso-sensitivity and iso-bias curves. In interactive
108
+ mode, the points can be moved via direct manipulation with the mouse, touch, or keyboard arrows. The
109
+ plot can also display the topography of the space with contour lines indicating iso-sensitivity,
110
+ iso-bias, or iso-accuracy.
111
+
112
+ ##### Attributes
113
+
114
+ - `interactive: boolean = false`
115
+ - Allow direct manipulation of points in the plot
116
+ - `contour: string = undefined`
117
+ - Show contour lines on plot
118
+ - Options
119
+ - `undefined`
120
+ - Show no contours
121
+ - `'sensitivity'`
122
+ - Show iso-sensitivity contours
123
+ - `'bias'`
124
+ - Show iso-bias contours
125
+ - `'accuracy'`
126
+ - Show iso-accuracy contours
127
+ - `point: string = 'all'`
128
+ - Show a point on the plot for each *location*
129
+ - Options:
130
+ - `'all'`
131
+ - Show points for all *locations*
132
+ - `'first'`
133
+ - Only show a point for the first (`'default'`) *location*
134
+ - `'rest'`
135
+ - Show points for all except the first (`'default'`) *location*
136
+ - `'none'`
137
+ - Show no points
138
+ - `iso-d: string = 'first'`
139
+ - Show an iso-sensitivity line for each *location*
140
+ - Options:
141
+ - `'all'`
142
+ - Show contours for all *locations*
143
+ - `'first'`
144
+ - Only show a contour for the first (`'default'`) *location*
145
+ - `'rest'`
146
+ - Show contours for all except the first (`'default'`) *location*
147
+ - `'none'`
148
+ - Show no contours
149
+ - `iso-c: string = 'first'`
150
+ - Show an iso-bias line for each *location*
151
+ - Options:
152
+ - `'all'`
153
+ - Show contours for all *locations*
154
+ - `'first'`
155
+ - Only show a contour for the first (`'default'`) *location*
156
+ - `'rest'`
157
+ - Show contours for all except the first (`'default'`) *location*
158
+ - `'none'`
159
+ - Show no contours
160
+ - `z-roc: boolean = false`
161
+ - Plot in zROC space instead of ROC space
162
+ - `far: number = 0.25`
163
+ - False alarm rate for the first (`'default'`) *location*
164
+ - `hr: number = 0.75`
165
+ - Hit rate for the first (`'default'`) *location*
166
+
167
+ ##### Methods
168
+
169
+ - `set(hr, far, name = 'default', label = '', s = 1)`
170
+ - Create or update the *location* identified by `name`
171
+ - The `name` `'default'` is reserved for the first location
172
+ - Parameters
173
+ - `hr: number`
174
+ - Hit rate
175
+ - `far: number`
176
+ - False alarm rate
177
+ - `name: string = 'default'`
178
+ - A unique name to identify the *location* being set
179
+ - `label: string = ''`
180
+ - A visual label to use in the plot for this location
181
+ - `s: number = 1`
182
+ - Unequal variance parameter (default of `1` is equal variance)
183
+ - `setWidthSDT(d, c, name = 'default', label = '', s = 1)`
184
+ - Create or update the *location* identified by `name`
185
+ - The `name` `'default'` is reserved for the first location
186
+ - Parameters
187
+ - `d: number`
188
+ - Sensitivity
189
+ - `c: number`
190
+ - Bias
191
+ - `name: string = 'default'`
192
+ - A unique name to identify the *location* being set
193
+ - `label: string = ''`
194
+ - A visual label to use in the plot for this location
195
+ - `s: number = 1`
196
+ - Unequal variance parameter (default of `1` is equal variance)
197
+
198
+ ##### Custom Events
199
+
200
+ - `roc-point-change`
201
+ - Indicates a location on the plot has been moved
202
+ - `detail`
203
+ - `name: string`
204
+ - A unique name to identify the *location*
205
+ - `far: number`
206
+ - False alarm rate
207
+ - `hr: number`
208
+ - Hit rate
209
+ - `d: number`
210
+ - Sensitivity
211
+ - `c: number`
212
+ - Bias
213
+ - `s: number`
214
+ - Variance
215
+ - `label: string`
216
+ - Display label
217
+
218
+ ##### Example
219
+
220
+ ```html
221
+ <roc-space interactive contour="bias" point="all" isoD="first" isoC="first" z-roc far="0.2" hr="0.9"></roc-space>
222
+ ```
223
+
224
+ #### `DetectableControl` / `<detectable-control>`
225
+
226
+ Control panel for SDT demos
227
+
228
+ A configurable set of controls for user manipulation of examples of signal detection theory.
229
+ Controls can be provided for the number of trials, the timing of trials, the coherence of the dots
230
+ on *signal* trials, the balance of payoff on incentivized trials, the coloring used in the results
231
+ table, the use of ROC or zROC coordinates in ROC space, and for running, pausing, or resetting a
232
+ block of trials.
233
+
234
+ ##### Attributes
235
+
236
+ - `trials: number = undefined`
237
+ - Show a slider for setting the number of trials, initialized to the value provided
238
+ - Options
239
+ - `1` to `100` in steps of `1`
240
+ - `duration: number = undefined`
241
+ - Show a slider for setting the duration of the stimulus, wait, and inter-trial interval on each
242
+ trial, initialized to the value provided in milliseconds
243
+ - Options
244
+ - `10` to `2000` in steps of `10`
245
+ - `coherence: number = undefined`
246
+ - Show a slider for setting the proportion of coherent dots on *signal* trials
247
+ - Options
248
+ - `0` to `1` in steps of `0.01`
249
+ - `payoff: number = undefined`
250
+ - Show a slider for setting the relative dollar payoff for hits and misses compared to false
251
+ alarms and correct rejections
252
+ - Options
253
+ - `0` to `100` in steps of `1`
254
+ - `color: string = undefined`
255
+ - Show a set of options to select how to color the cells in the results table
256
+ - Options
257
+ - `'none'`
258
+ - No use of color
259
+ - `'accuracy'`
260
+ - Color based on accuracy of responses
261
+ - `'stimulus'`
262
+ - Color based on *signal* or *noise* stimulus
263
+ - `'response'`
264
+ - Color based on *'signal'* or *'noise'* response
265
+ - `'outcome'`
266
+ - Color based on outcome of hit, miss, false alarm or correct rejection
267
+ - `zRoc: boolean = undefined`
268
+ - Show a switch to set whether to use z-transformed ROC coordinates (`true`) or ROC coordinates
269
+ (`false`)
270
+ - `run: boolean = false`
271
+ - Show a button to run the task
272
+ - `pause: boolean = false`
273
+ - Show a button to pause the task
274
+ - `reset: boolean = false`
275
+ - Show a button to reset the task
276
+
277
+ ##### Methods
278
+
279
+ - `complete()`
280
+ - Indicates that a trial block is done, so it can no longer be paused
281
+
282
+ ##### Custom Events
283
+
284
+ - `detectable-control-trials`
285
+ - Indicates the number of trials slider has been adjusted
286
+ - `detail`
287
+ - `trials: number`
288
+ - The new number of trials
289
+ - `detectable-control-duration`
290
+ - Indicates the duration of trials slider has been adjusted
291
+ - `detail`
292
+ - `duration: number`
293
+ - The new duration
294
+ - `detectable-control-coherence`
295
+ - Indicates the coherence of stimulus dots slider has been adjusted
296
+ - `detail`
297
+ - `coherence: number`
298
+ - The new coherence
299
+ - `detectable-control-payoff`
300
+ - Indicates the payoff slider has been adjusted
301
+ - `detail`
302
+ - `payoff: number`
303
+ - The new payoff
304
+ - `detectable-control-color`
305
+ - Indicates the color selection for the results table has been toggled
306
+ - `detail`
307
+ - `color: string`
308
+ - The new color scheme
309
+ - `detectable-control-z-roc`
310
+ - Indicates the plot coordinates switch have been changed
311
+ - `detail`
312
+ - `zRoc: boolean`
313
+ - Whether or not to use z-transformed coordinates now
314
+ - `detectable-control-run`
315
+ - Indicates the run button has been pushed
316
+ - `detectable-control-pause`
317
+ - Indicates the pause button has been pushed
318
+ - `detectable-control-reset`
319
+ - Indicates the reset button has been pushed
320
+
321
+ ##### Example
322
+
323
+ ```html
324
+ <detectable-control trials="15" duration="1500" coherence="0.2" payoff="75" color="outcome" z-roc run pause reset></detectable-control>
325
+ ```
326
+
327
+ #### `SDTModel` / `<sdt-model>`
328
+
329
+ Interactive visualization of SDT in terms of signal and noise distributions
330
+
331
+ This widget provides a visualization of signal detection theory. It can show *signal* and *noise*
332
+ distributions and a threshold. The distributions can have unequal variance. The sensitivity, bias,
333
+ and *signal* variance can be set and optionally displayed. In interactive mode, the bias can be
334
+ adjusted by directly moving the threshold horizontally with mouse, touch, or keyboard, the
335
+ sensitivity can be adjusted by directly moving a distribution horizontally with mouse, touch, or
336
+ keyboard, and the variance can be adjusted by directly moving the *signal* distribution vertically
337
+ with mouse, touch, or keyboard.
338
+
339
+ In addition, the observation of stimuli can be visualized as blocks arriving at particular evidence
340
+ levels, and stacking with previous stimuli to form a histogram. In interactive mode, when the model
341
+ is adjusted, the blocks in the histogram will rearrange accordingly.
342
+
343
+ The thresholded distributions and the histogram blocks can be colored based on the stimuli, the
344
+ responses, or the outcomes.
345
+
346
+ ##### Attributes
347
+
348
+ - `interactive: boolean = false`
349
+ - Allow direct manipulation of threshold and distributions
350
+ - `color: string = 'outcome'`
351
+ - Set how to color distributions and trials
352
+ - Options
353
+ - `'outcome'`
354
+ - Color based on outcome of the hit, miss, false alarm, or correct rejection
355
+ - `'response'`
356
+ - Color based on the `'present'` or `'absent'` response provided
357
+ - `'stimulus'`
358
+ - Color based on the `present` or `absent` stimulus displayed
359
+ - `'none'`
360
+ - No coloring
361
+ - `distributions: boolean = false`
362
+ - Show distributions
363
+ - `threshold: boolean = false`
364
+ - Show threshold
365
+ - `unequal: boolean = false`
366
+ - Allow unequal variance
367
+ - `sensitivity: boolean = false`
368
+ - Show the sensitivity as *d'* with a measurement bar
369
+ - `bias: boolean = false`
370
+ - Show the bias as *c* with a measurement bar
371
+ - `variance: boolean = false`
372
+ - Show the variance as *s* with a measurement bar
373
+ - `histogram: boolean = false`
374
+ - Show a histogram with a block for each trial/stimulus
375
+ - `d: number = 1`
376
+ - Set the sensitivity, *d`*
377
+ - `c: number = 0`
378
+ - Set the bias, *c*
379
+ - `s: number = 1`
380
+ - Set the variance of the *signal* distribution, *s*
381
+
382
+ ##### Methods
383
+
384
+ - `reset()`
385
+ - Reset the histogram to have no trials
386
+ - `trial(trialNumber, signal, duration, wait, iti)`
387
+ - Add a trial to the histogram
388
+ - Parameters
389
+ - `trialNumber: number`
390
+ - Numerical count of the trial in the block
391
+ - `signal: string`
392
+ - Whether this is a signal `'present'` or `'absent'` trial
393
+ - `duration: number`
394
+ - The stimulus duration on this trial in milliseconds
395
+ - `wait: number`
396
+ - The wait duration on this trial in milliseconds
397
+ - `iti: number`
398
+ - The inter-trial interval duration after this trial in milliseconds
399
+ - `pauseTrial()`
400
+ - Pause the animation of trials in the histogram
401
+ - `resumeTrial()`
402
+ - Resume the animation of trials in the histogram
403
+
404
+ ##### Custom Events
405
+
406
+ - `sdt-model-change`
407
+ - Indicates that one or more model parameters have been changed
408
+ - `detail`
409
+ - `d: number`
410
+ - Sensitivity
411
+ - `c: number`
412
+ - Bias
413
+ - `s: number`
414
+ - Variance
415
+ - `far: number`
416
+ - False alarm rate
417
+ - `hr: number`
418
+ - Hit rate
419
+ - `h: number`
420
+ - Hits
421
+ - `m: number`
422
+ - Misses
423
+ - `fa: number`
424
+ - False alarms
425
+ - `cr: number`
426
+ - Correct rejections
427
+ - `detectable-response`
428
+ - Indicates that an animated histogram trial has generated a response
429
+ - `detail`
430
+ - `stimulus: string`
431
+ - Whether the signal was actually `'present'` or `'absent'`
432
+ - `response: string`
433
+ - Whether the response was `'present'` or `'absent'`
434
+ - `outcome: string`
435
+ - The outcome of the trial as a hit (`'h'`), miss (`'m'`), correct rejection (`'cr'`), or
436
+ false alarm (`'fa'`)
437
+ - `h: number`
438
+ - Total hits in this block
439
+ - `m: number`
440
+ - Total misses in this block
441
+ - `fa: number`
442
+ - Total false alarms in this block
443
+ - `cr: number`
444
+ - Total correct rejections in this block
445
+ - `nr: number`
446
+ - Total no responses in this block
447
+
448
+ ##### Example
449
+
450
+ ```html
451
+ <sdt-model interactive color="outcome" distributions threshold unequal sensitivity bias variance histogram d="2" c="1" s="1.5"></sdt-model>
452
+ ```
453
+
454
+ #### `DetectableResponse` / `<detectable-response>`
455
+
456
+ Response buttons, feedback, and payoffs for signal detection tasks
457
+
458
+ This element provides 'present' and 'absent' response buttons. It can also display a running count
459
+ of the trials, display feedback in terms of accuracy or SDT outcome, and display the current trial
460
+ and total payoff.
461
+
462
+ ##### Attributes
463
+
464
+ - `interactive: boolean = false`
465
+ - Allow user to respond, instead of just displaying simulated model responses
466
+ - `feedback: string = 'outcome'`
467
+ - What type of feedback to display
468
+ - Options
469
+ - `'none'`
470
+ - No feedback
471
+ - `'accuracy'`
472
+ - Feedback in terms of accuracy, i.e. 'correct' or 'error'
473
+ - `'outcome'`
474
+ - Feedback in terms of outcome, i.e. 'hit, 'miss', 'false alarm', or 'correct rejection'
475
+ - `trial: boolean = false`
476
+ - Display the running count of trials, i.e. 'Trial: 2 of 10'
477
+ - `payoff: string = 'none'`
478
+ - What payoff information to display
479
+ - Options
480
+ - `'none'`
481
+ - No payoff information displayed
482
+ - `'trial'`
483
+ - Only display payoff for the current trial
484
+ - `'total'`
485
+ - Display payoff for the current trial and display the total payoff for the block
486
+ - `hit-payoff: number = 0`
487
+ - Value of payoff for a hit
488
+ - `miss-payoff: number = 0`
489
+ - Value of payoff for a miss
490
+ - `correct-rejection-payoff: number = 0`
491
+ - Value of payoff for a correct rejection
492
+ - `false-alarm-payoff: number = 0`
493
+ - Value of payoff for a false alarm
494
+ - `no-response-payoff: number = 0`
495
+ - Value of payoff for no response
496
+
497
+ ##### Methods
498
+
499
+ - `start(signal, trial)`
500
+ - Indicates that a trial has started, and its time to wait for a response
501
+ - Parameters
502
+ - `signal: string`
503
+ - Whether this is a signal `'present'` or `'absent'` trial
504
+ - `trial: number`
505
+ - The count of the trial within the block
506
+ - `stop()`
507
+ - Indicates that the trial is over and it is time to display any requested feedback
508
+ - **Note:** If no response has been made yet, the trial is recorded as having no response
509
+ - `present()`
510
+ - Emulate a 'present' response
511
+ - `absent()`
512
+ - Emulate an 'absent' response
513
+ - `responded(response)`
514
+ - Emulate a response
515
+ - Parameters
516
+ - `response: string`
517
+ - Whether to emulate a `'present'` or `'absent'` response
518
+ - `reset()`
519
+ - Reset to the state at the start of a block of trials
520
+
521
+ ##### Custom Events
522
+
523
+ - `detectable-response`
524
+ - Indicates that a response has been made on this trial
525
+ - `detail`
526
+ - `trial: number`
527
+ - The count of this trial in the block
528
+ - `signal: string`
529
+ - Whether the signal was actually `'present'` or `'absent'`
530
+ - `response: string`
531
+ - Whether the response was `'present'` or `'absent'`
532
+ - `outcome: string`
533
+ - The outcome of the trial as a hit (`'h'`), miss (`'m'`), correct rejection (`'cr'`), or
534
+ false alarm (`'fa'`)
535
+ - `payoff: number`
536
+ - The payoff for this trial
537
+ - `h: number`
538
+ - Total hits in this block
539
+ - `m: number`
540
+ - Total misses in this block
541
+ - `fa: number`
542
+ - Total false alarms in this block
543
+ - `cr: number`
544
+ - Total correct rejections in this block
545
+ - `nr: number`
546
+ - Total no responses in this block
547
+ - `totalPayoff: number`
548
+ - Total payoff for the block
549
+
550
+ ##### Example
551
+
552
+ ```html
553
+ <detectable-response interactive feedback="outcome" trial payoff="total" hit-payoff="60" miss-payoff="-60" false-alarm-payoff="-40" correct-rejection-payoff="40" no-response-payoff="-100"></detectable-response>
554
+ ```
555
+
556
+ #### `DetectableTable` / `<detectable-table>`
557
+
558
+ Interactive table of SDT outcomes
559
+
560
+ A results table for signal detection tasks. The results are presented in a two by two table
561
+ organized by stimuli (signal present or absent) and responses ('present' or 'absent') leading to
562
+ four possible outcomes: hits, misses, false alarms, and correct rejections. Results on signal
563
+ present trials are optionally marginalized with the hit rate and those on signal absent trials with
564
+ the false alarm rate. Results on response 'present' trials are optionally marginalized with the
565
+ positive predictive value and those on response 'absent' trials with the false omission rate. And
566
+ overall results are optionally marginalized with accuracy.
567
+
568
+ ##### Attributes
569
+
570
+ - `interactive: boolean = false`
571
+ - Allow user to change values in the table
572
+ - `numeric: boolean = false`
573
+ - Show numeric values instead of just labelling the cells
574
+ - `summary: Set = <empty>`
575
+ - Which marginals to display
576
+ - Expressed in HTML as a space-separated list
577
+ - Options
578
+ - `'stimulusRates'`
579
+ - Display hit rate and false alarm rate
580
+ - `'responseRates'`
581
+ - Display positive predictive value and false omission rate
582
+ - `'accuracy'`
583
+ - Display overall accuracy
584
+ - `color: string = 'outcome'`
585
+ - How to color the cells
586
+ - Options
587
+ - `'none'`
588
+ - No colors
589
+ - `'accuracy'`
590
+ - Color based on accuracy, i.e. correct or error
591
+ - `'stimulus'`
592
+ - Color based on stimulus present or absent
593
+ - `'response'`
594
+ - Color based on response 'present' or 'absent'
595
+ - `'outcome'`
596
+ - Full coloration based on hits, misses, false alarms and correct rejections
597
+ - `hits: number = 40`
598
+ - Number of hits
599
+ - `misses: number = 60`
600
+ - Number of misses
601
+ - `false-alarms: number = 75`
602
+ - Number of false alarms
603
+ - `correct-rejections: number = 25`
604
+ - Number of correct rejections
605
+ - `payoff: boolean = false`
606
+ - Whether to display payoffs
607
+ - `hit-payoff: number = undefined`
608
+ - Payoff for hits
609
+ - `miss-payoff: number = undefined`
610
+ - Payoff for misses
611
+ - `correct-rejection-payoff: number = undefined`
612
+ - Payoff for correct rejections
613
+ - `false-alarm-payoff: number = undefined`
614
+ - Payoff for false alarms
615
+
616
+ ##### Custom Events
617
+
618
+ - `detectable-table-change`
619
+ - One or more values in the table have changed
620
+ - `detail`
621
+ - `h: number`
622
+ - Hits
623
+ - `m: number`
624
+ - Misses
625
+ - `fa: number`
626
+ - False alarms
627
+ - `cr: number`
628
+ - Correct rejections
629
+ - `hr: number`
630
+ - Hit rate
631
+ - `far: number`
632
+ - False alarm rate
633
+ - `ppv: number`
634
+ - Positive predictive value
635
+ - `fomr: number`
636
+ - False omission rate
637
+ - `acc: number`
638
+ - Accuracy
639
+
640
+ ##### Example
641
+
642
+ ```html
643
+ <detectable-table interactive numeric summary="stimulusRates responseRates accuracy" = color="outcome" hits="80" misses="20" false-alarms="35" correct-rejections="65" payoff hit-payoff="60" miss-payoff="-60" false-alarm-payoff="-40" correct-rejection-payoff="40"></detectable-table>
644
+ ```
645
+
646
+ ### Equations
647
+
648
+ Interactive equations for SDT
649
+
650
+ The equations can either be static and display the variable names, be static and display names and
651
+ values or be interactive with names and editable values, in which case only the values on the right
652
+ side of the equals sign are editable.
653
+
654
+ **Note:** The layout for these equations leaves something to be desired, especially on smaller
655
+ screens. Ideally a proper math renderer would be used, but I haven't found one that takes kindly to
656
+ insertion of the custom elements needed for live editing.
657
+
658
+ #### `SDTEquationDC2Far` / `<sdt-equation-dc2far>`
659
+
660
+ False alarm rate from sensitivity and bias
661
+
662
+ ##### Attributes
663
+
664
+ - `numeric: boolean = false`
665
+ - Show values instead of just the names of variables
666
+ - `interactive: boolean = false`
667
+ - Allow editing of numeric values in the equation
668
+ - `unequal: boolean = false`
669
+ - Show the unequal variance version of the equation, including a variance parameter
670
+ - `d: number = 0`
671
+ - Sensitivity, *d`*
672
+ - `c: number = 0`
673
+ - Bias, *c*
674
+ - `s: number = 1`
675
+ - Variance, *s*
676
+
677
+ ##### Properties
678
+
679
+ - `far: number`
680
+ - False alarm rate
681
+
682
+ ##### Custom Events
683
+
684
+ - `sdt-equation-dc2far-change`
685
+ - Indicates that the values in the equation have changed
686
+ - `detail`
687
+ - `d: number`
688
+ - New value of sensitivity
689
+ - `c: number`
690
+ - New value of bias
691
+ - `s: number`
692
+ - New value of variance
693
+ - `far: number`
694
+ - New value of false alarm rate
695
+
696
+ ##### Example
697
+
698
+ ```html
699
+ <sdt-equation-dc2far numeric interactive unequal d="2" c="-1" s="1.5"></sdt-equation-dc2far>
700
+ ```
701
+
702
+ #### `SDTEquationDC2Hr` / `<sdt-equation-dc2hr>`
703
+
704
+ Hit rate from sensitivity and bias
705
+
706
+ ##### Attributes
707
+
708
+ - `numeric: boolean = false`
709
+ - Show values instead of just the names of variables
710
+ - `interactive: boolean = false`
711
+ - Allow editing of numeric values in the equation
712
+ - `unequal: boolean = false`
713
+ - Show the unequal variance version of the equation, including a variance parameter
714
+ - `d: number = 0`
715
+ - Sensitivity, *d`*
716
+ - `c: number = 0`
717
+ - Bias, *c*
718
+ - `s: number = 1`
719
+ - Variance, *s*
720
+
721
+ ##### Properties
722
+
723
+ - `hr: number`
724
+ - Hit rate
725
+
726
+ ##### Custom Events
727
+
728
+ - `sdt-equation-dc2hr-change`
729
+ - Indicates that the values in the equation have changed
730
+ - `detail`
731
+ - `d: number`
732
+ - New value of sensitivity
733
+ - `c: number`
734
+ - New value of bias
735
+ - `s: number`
736
+ - New value of variance
737
+ - `hr: number`
738
+ - New value of hit rate
739
+
740
+ ##### Example
741
+
742
+ ```html
743
+ <sdt-equation-dc2hr numeric interactive unequal d="2" c="-1" s="1.5"></sdt-equation-dc2hr>
744
+ ```
745
+
746
+ #### `SDTEquationFaCr2Far` / `<sdt-equation-facr2far>'
747
+
748
+ False alarm rate from false alarms and correct rejections
749
+
750
+ ##### Attributes
751
+
752
+ - `numeric: boolean = false`
753
+ - Show values instead of just the names of variables
754
+ - `interactive: boolean = false`
755
+ - Allow editing of numeric values in the equation
756
+ - `false-alarms: number = 0`
757
+ - False alarms
758
+ - `correct-rejections: number = 0`
759
+ - Correct rejections
760
+
761
+ ##### Properties
762
+
763
+ - `far: number`
764
+ - False alarm rate
765
+
766
+ ##### Custom Events
767
+
768
+ - `sdt-equation-facr2far-change`
769
+ - Indicates that the values in the equation have changed
770
+ - `detail`
771
+ - `fa: number`
772
+ - New value of false alarms
773
+ - `cr: number`
774
+ - New value of correct rejections
775
+ - `far: number`
776
+ - New value of false alarm rate
777
+
778
+ ##### Example
779
+
780
+ ```html
781
+ <sdt-equation-facr2far numeric interactive false-alarms="25" correct-rejections="75"></sdt-equation-facr2far>
782
+ ```
783
+
784
+ #### `SDTEquationHM2Hr` / `<sdt-equation-hm2hr>`
785
+
786
+ Hit rate from hits and misses
787
+
788
+ ##### Attributes
789
+
790
+ - `numeric: boolean = false`
791
+ - Show values instead of just the names of variables
792
+ - `interactive: boolean = false`
793
+ - Allow editing of numeric values in the equation
794
+ - `hits: number = 0`
795
+ - Hits
796
+ - `misses: number = 0`
797
+ - Misses
798
+
799
+ ##### Properties
800
+
801
+ - `far: number`
802
+ - Hit rate
803
+
804
+ ##### Custom Events
805
+
806
+ - `sdt-equation-hm2hr-change`
807
+ - Indicates that the values in the equation have changed
808
+ - `detail`
809
+ - `h: number`
810
+ - New value of hits
811
+ - `m: number`
812
+ - New value of misses
813
+ - `hr: number`
814
+ - New value of hit rate
815
+
816
+ ##### Example
817
+
818
+ ```html
819
+ <sdt-equation-hm2hr numeric interactive hits="75" misses="25"></sdt-equation-hm2hr>
820
+ ```
821
+
822
+ #### `SDTEquationHMFaCr2Acc` / `<sdt-equation-hmfacr2c>`
823
+
824
+ Accuracy from hits, misses, false alarms, and correct rejections
825
+
826
+ ##### Attributes
827
+
828
+ - `numeric: boolean = false`
829
+ - Show values instead of just the names of variables
830
+ - `interactive: boolean = false`
831
+ - Allow editing of numeric values in the equation
832
+ - `hits: number = 0`
833
+ - Hits
834
+ - `misses: number = 0`
835
+ - Misses
836
+ - `false-alarms: number = 0`
837
+ - False alarms
838
+ - `correct-rejections: number = 0`
839
+ - Correct rejections
840
+
841
+ ##### Properties
842
+
843
+ - `acc: number`
844
+ - Accuracy
845
+
846
+ ##### Custom Events
847
+
848
+ - `sdt-equation-hmfacr2c-change`
849
+ - Indicates that the values in the equation have changed
850
+ - `detail`
851
+ - `h: number`
852
+ - New value of hits
853
+ - `m: number`
854
+ - New value of misses
855
+ - `fa: number`
856
+ - New value of false alarms
857
+ - `cr: number`
858
+ - New value of correct rejections
859
+ - `acc: number`
860
+ - New value of accuracy
861
+
862
+ ##### Example
863
+
864
+ ```html
865
+ <sdt-equation-hmfacr2c numeric interactive hits="75" misses="25" false-alarms="25" correct-rejections="75"></sdt-equation-hmfacr2c>
866
+ ```
867
+
868
+ #### `SDTEquationHrFar2C` / `<sdt-equation-hrfar2c>`
869
+
870
+ Bias from hit rate and false alarm rate
871
+
872
+ ##### Attributes
873
+
874
+ - `numeric: boolean = false`
875
+ - Show values instead of just the names of variables
876
+ - `interactive: boolean = false`
877
+ - Allow editing of numeric values in the equation
878
+ - `hit-rate: number = 0`
879
+ - Hits
880
+ - `false-alarm-rate: number = 0`
881
+ - Misses
882
+ - `s: number = 1`
883
+ - Variance, *s*
884
+
885
+ ##### Properties
886
+
887
+ - `c: number`
888
+ - Bias, *c*
889
+
890
+ ##### Custom Events
891
+
892
+ - `sdt-equation-hrfar2c-change`
893
+ - Indicates that the values in the equation have changed
894
+ - `detail`
895
+ - `hr: number`
896
+ - New value of hits
897
+ - `far: number`
898
+ - New value of misses
899
+ - `s: number`
900
+ - New value of variance
901
+ - `c: number`
902
+ - New value of bias
903
+
904
+ ##### Example
905
+
906
+ ```html
907
+ <sdt-equation-hrfar2c numeric interactive unequal hit-rate="0.75" false-alarm-rate="0.25" s="1.5"></sdt-equation-hrfar2c>
908
+ ```
909
+
910
+ #### `SDTEquationHrFar2D` / `<sdt-equation-hrfar2d>`
911
+
912
+ Sensitivity from hit rate and false alarm rate
913
+
914
+ ##### Attributes
915
+
916
+ - `numeric: boolean = false`
917
+ - Show values instead of just the names of variables
918
+ - `interactive: boolean = false`
919
+ - Allow editing of numeric values in the equation
920
+ - `hit-rate: number = 0`
921
+ - Hits
922
+ - `false-alarm-rate: number = 0`
923
+ - Misses
924
+ - `s: number = 1`
925
+ - Variance, *s*
926
+
927
+ ##### Properties
928
+
929
+ - `d: number`
930
+ - Sensitivity, *d`*
931
+
932
+ ##### Custom Events
933
+
934
+ - `sdt-equation-hrfar2c-change`
935
+ - Indicates that the values in the equation have changed
936
+ - `detail`
937
+ - `hr: number`
938
+ - New value of hits
939
+ - `far: number`
940
+ - New value of misses
941
+ - `s: number`
942
+ - New value of variance
943
+ - `d: number`
944
+ - New value of sensitivity
945
+
946
+ ##### Example
947
+
948
+ ```html
949
+ <sdt-equation-hrfar2d numeric interactive unequal hit-rate="0.75" false-alarm-rate="0.25" s="1.5"></sdt-equation-hrfar2d>
950
+ ```
951
+
952
+ #### `SDTEquation`
953
+
954
+ Base class for all interactive SDT equations
955
+
956
+ To define a new equation:
957
+
958
+ ```javascript
959
+ export default class SDTEquationSomething extends SDTEquation {
960
+ ...
961
+ }
962
+ ```
963
+
964
+ `SDTEquation` extends `DetectableElement` extends `DecidableElement` extends `LitElement`
965
+
966
+ ### Examples
967
+
968
+ Full examples built from multiple components
969
+
970
+ #### `DetectableExampleHuman` / `<detectable-example-human>`
971
+
972
+ User runs task, and results are fit and displayed in real-time using SDT
973
+
974
+ Used to build examples where the user is performing the random-dot kinematogram task. Can include
975
+ controls, the task itself, response buttons with feedback and payoffs, a table of results, ROC
976
+ space, and a visual rendering of signal detection theory. The table of results, ROC space, and the
977
+ SDT model should not be interactive, because their values are received from the user's task
978
+ performance.
979
+
980
+ ##### Slots
981
+
982
+ - *unnamed*
983
+ - Place relevant `detectable-elements` components here
984
+ - Wired elements
985
+ - `<detectable-control>`
986
+ - Allows user to adjust parameters and control the task
987
+ - `<rdk-task>`
988
+ - Displays the task
989
+ - `<detectable-response>`
990
+ - Allows user to make responses and see feedback and payoffs
991
+ - `<detectable-table>`
992
+ - Displays numerical results for the current block of trials
993
+ - `<roc-space>`
994
+ - Displays the hit rate and false alarm rate in ROC space based on current results
995
+ - `<sdt-model>`
996
+ - Displays a visual rendering of sensitivity and bias based on current results
997
+
998
+ ##### Example
999
+
1000
+ ```html
1001
+ <detectable-example-human>
1002
+ <detectable-control coherence=".5" trials="10" duration="1000" run pause reset></detectable-control>
1003
+ <rdk-task coherence=".5" trials="10" duration="1000" wait="1000" iti="1000"></rdk-task>
1004
+ <detectable-response interactive trial feedback="outcome"></detectable-response>
1005
+ <detectable-table numeric summary="stimulusRates accuracy" hits="0" misses="0" false-alarms="0" correct-rejections="0"></detectable-table>
1006
+ <roc-space point="all" iso-d="all" iso-c="all" far=".5" hr=".5"></roc-space>
1007
+ <sdt-model threshold bias distributions sensitivity histogram color="outcome" d="0" c="0"></sdt-model>
1008
+ </detectable-example-human>
1009
+ ```
1010
+
1011
+ #### `DetectableExampleInteractive` / `<detectable-example-interactive>`
1012
+
1013
+ Exploration of relationship between SDT visualizations
1014
+
1015
+ Used to build examples where the user can explore the relationship between results and
1016
+ model parameters. Can include controls, a table of results, ROC space, and a visual rendering of
1017
+ signal detection theory. The table of results, ROC space, and the SDT model should be interactive,
1018
+ to allow the user to modify values and see the implications for the other components.
1019
+
1020
+ ##### Slots
1021
+
1022
+ - *unnamed*
1023
+ - Place relevant `detectable-elements` components here
1024
+ - Wired elements
1025
+ - `<detectable-control>`
1026
+ - Allows user to adjust parameters
1027
+ - `<detectable-table>`
1028
+ - Display and change numerical results
1029
+ - `<roc-space>`
1030
+ - Display and change the hit rate and false alarm rate in ROC space
1031
+ - `<sdt-model>`
1032
+ - Display and change sensitivity and bias in a visualization
1033
+
1034
+ ##### Example
1035
+
1036
+ ```html
1037
+ <detectable-example-interactive>
1038
+ <detectable-table numeric interactive summary="stimulusRates accuracy" hits="80" misses="20" false-alarms="10" correct-rejections="90"></detectable-table>
1039
+ <roc-space interactive point="all" iso-d="all" iso-c="all"></roc-space>
1040
+ <sdt-model interactive threshold bias distributions sensitivity color="outcome"></sdt-model>
1041
+ </detectable-example-interactive>
1042
+ ```
1043
+
1044
+ #### `DetectableExampleDoubleInteractive` / `<detectable-example-double-interactive>`
1045
+
1046
+ Compare two sets of results using signal detection theory
1047
+
1048
+ Used to build examples where the user can explore the relationship between two sets of results and
1049
+ model parameters. Can include two tables of results, a single ROC space, and two visual renderings
1050
+ of signal detection theory. The tables of results, ROC space, and models can all be interactive, to
1051
+ allow the user to modify values and see the implications for the other components.
1052
+
1053
+ ##### Slots
1054
+
1055
+ - *unnamed*
1056
+ - Place relevant `detectable-elements` components here
1057
+ - Wired elements
1058
+ - **2×** `<detectable-table>`
1059
+ - Display and change values for two sets of results
1060
+ - `<roc-space>`
1061
+ - Display and change the hit rate and false alarm rate in ROC space for each of two results
1062
+ - **2×** `<sdt-model>`
1063
+ - Display and change sensitivity and bias in a visualization for two sets of results
1064
+
1065
+ ##### Example
1066
+
1067
+ ```html
1068
+ <detectable-example-double-interactive>
1069
+ <detectable-table numeric interactive summary="stimulusRates accuracy" hits="0" misses="0" false-alarms="0" correct-rejections="0"></detectable-table>
1070
+ <roc-space interactive contour="accuracy" point="all" iso-d="none" iso-c="none"></roc-space>
1071
+ <detectable-table numeric interactive summary="stimulusRates accuracy" hits="0" misses="0" false-alarms="0" correct-rejections="0"></detectable-table>
1072
+ </detectable-example-double-interactive>
1073
+ ```
1074
+
1075
+ #### `DetectableExampleModel` / `<detectable-example-model>`
1076
+
1077
+ Model simulates task based on SDT parameter values
1078
+
1079
+ Used to build examples where the model is simulated to perform the random-dot kinematogram task. Can
1080
+ include controls, the task itself, response buttons with feedback and payoffs, a table of results,
1081
+ ROC space, and a visual rendering of signal detection theory. The SDT model should be interactive,
1082
+ so the user can modify the model. The table of results and ROC space should not be interactive,
1083
+ because their values are received from the model's task performance.
1084
+
1085
+ ##### Slots
1086
+
1087
+ - *unnamed*
1088
+ - Place relevant `detectable-elements` components here
1089
+ - Wired elements
1090
+ - `<detectable-control>`
1091
+ - Allows user to adjust parameters and control the task
1092
+ - `<rdk-task>`
1093
+ - Displays the task
1094
+ - `<sdt-model>`
1095
+ - Display and change a visual rendering of the sensitivity and bias of the model
1096
+ - `<detectable-response>`
1097
+ - Displays model's responses and the resulting feedback and payoffs
1098
+ - `<detectable-table>`
1099
+ - Displays model's numerical results for the current block of trials
1100
+ - `<roc-space>`
1101
+ - Displays the model's hit rate and false alarm rate in ROC space based on current results
1102
+
1103
+ ##### Example
1104
+
1105
+ ```html
1106
+ <detectable-example-model>
1107
+ <detectable-control run pause reset coherence=".5" trials="10" duration="500"></detectable-control>
1108
+ <rdk-task count="100" coherence=".5" trials="10" duration="500" wait="500" iti="500"></rdk-task>
1109
+ <sdt-model interactive threshold bias distributions sensitivity histogram color="outcome" d="1" c=".5"></sdt-model>
1110
+ <detectable-response trial feedback="outcome"></detectable-response>
1111
+ <detectable-table numeric summary="stimulusRates accuracy" hits="0" misses="0" false-alarms="0" correct-rejections="0"></detectable-table>
1112
+ <roc-space hr=".5" far=".5" point="all" iso-d="all" iso-c="all"></roc-space>
1113
+ </detectable-example-model>
1114
+ ```
1115
+
1116
+ #### `DetectableExampleUnequal` / `<detectable-example-unequal>`
1117
+
1118
+ Unequal variance example
1119
+
1120
+ Used to build specialized examples illustrating the implications of unequal variance. Can
1121
+ include controls, ROC space, and a visual rendering of signal detection theory. The SDT model and
1122
+ ROC space can be interactive.
1123
+
1124
+ **Note:** Unequal variance can be included in other examples, such as `<detectable-example-interactive>` as
1125
+ well. This example is for a particular bespoke illustration, and illustrates the highly specialized
1126
+ demonstrations that are possible by composing the various elements.
1127
+
1128
+ ##### Slots
1129
+
1130
+ - *unnamed*
1131
+ - Place relevant `detectable-elements` components here
1132
+ - Wired elements
1133
+ - `<detectable-control>`
1134
+ - Allows user to adjust parameters
1135
+ - `<sdt-model>`
1136
+ - Display and change a visual rendering of sensitivity and bias
1137
+ - `<roc-space>`
1138
+ - Displays the hit rate and false alarm rate in ROC space
1139
+
1140
+ ##### Example
1141
+
1142
+ ```html
1143
+ <detectable-example-unequal>
1144
+ <detectable-control z-roc></detectable-control>
1145
+ <sdt-model interactive unequal distributions sensitivity variance color="stimulus"></sdt-model>
1146
+ <roc-space z-roc contour="sensitivity" point="rest" iso-d="rest" iso-c="rest"></roc-space>
1147
+ </detectable-example-unequal>
1148
+ ```
1149
+
1150
+ #### `DetectableExample`
1151
+
1152
+ Base class for all SDT examples
1153
+
1154
+ To define a new example:
1155
+
1156
+ ```javascript
1157
+ export default class DetectableExampleSomething extends DetectableExample {
1158
+ ...
1159
+ }
1160
+ ```
1161
+
1162
+ `DetectableExample` extends `DetectableElement` extends `DecidableElement` extends `LitElement`
1163
+
1164
+ ### Base class
1165
+
1166
+ #### `DetectableElement`
1167
+
1168
+ Base class for all *detectable* web components
1169
+
1170
+ To define a new element:
1171
+
1172
+ ```javascript
1173
+ export default class DetectableElementSomething extends DetectableElement {
1174
+ ...
1175
+ }
1176
+ ```
1177
+
1178
+ `DetectableElement` extends `DecidableElement` extends `LitElement`
1179
+
1180
+ ## Features/Bugs/Notes
1181
+
1182
+ - Remove extraneous spaces from equation tagged template literals!
1183
+ - Label values IN iso-plots? or allow hover or click querying of iso-plots?
1184
+ - Hover/click could be extended ROC generally and to Model plot as well?
1185
+ - Use localStorage to maintain state?
1186
+ - Optimize update() based on changedProperties?
1187
+ - Edge/IE11 - minor edge defects between SVG element and shadow
1188
+ - Firefox - No CSS SVG Geometry Properties
1189
+
1190
+ ## Development Tooling
1191
+
1192
+ ### Local Scripts
1193
+
1194
+ - `yarn lint`
1195
+ - Lints scripts in `src/`
1196
+ - `yarn test`
1197
+ - Runs all tests and reports coverage in `test/coverage/`
1198
+ - `yarn test:watch`
1199
+ - Runs all tests in watch mode and reports coverage in `test/coverage/`
1200
+ - `yarn test:file <filename>`
1201
+ - Runs tests for a single file and reports coverage in `test/coverage/`
1202
+ - `yarn build`
1203
+ - Builds browser-compatible optimized bundle from `src/` to `lib/`
1204
+
1205
+ ## File Organization
1206
+
1207
+ - `detectable-elements/`
1208
+ - `lib/` (Bundles created from `src/` by `build`) **\[autogenerated\]**
1209
+ - `src/` (Source files)
1210
+ - `components/` (Source for visualizations)
1211
+ - `equations/` (Source for equations)
1212
+ - `examples/` (Source for examples combining visualizations)
1213
+ - `test/` (Testing files)
1214
+ - `coverage/` (Code coverage results) **\[autogenerated\]**
1215
+ - `CHANGELOG.md` (Based on conventional commits) **\[autogenerated\]**
1216
+ - `gulpfile.js` (Config for *gulp*)
1217
+ - `package.json` (Config for *yarn* and *npm*)
1218
+ - `README.md` (This file)