-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhy_BTM.html
910 lines (873 loc) · 56.4 KB
/
why_BTM.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.4.553">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Johannes Keil">
<title>Why should we use the BTM in psychology?</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="why_BTM_files/libs/clipboard/clipboard.min.js"></script>
<script src="why_BTM_files/libs/quarto-html/quarto.js"></script>
<script src="why_BTM_files/libs/quarto-html/popper.min.js"></script>
<script src="why_BTM_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="why_BTM_files/libs/quarto-html/anchor.min.js"></script>
<link href="why_BTM_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="why_BTM_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="why_BTM_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="why_BTM_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="why_BTM_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
<script type="text/javascript">
const typesetMath = (el) => {
if (window.MathJax) {
// MathJax Typeset
window.MathJax.typeset([el]);
} else if (window.katex) {
// KaTeX Render
var mathElements = el.getElementsByClassName("math");
var macros = [];
for (var i = 0; i < mathElements.length; i++) {
var texText = mathElements[i].firstChild;
if (mathElements[i].tagName == "SPAN") {
window.katex.render(texText.data, mathElements[i], {
displayMode: mathElements[i].classList.contains('display'),
throwOnError: false,
macros: macros,
fleqn: false
});
}
}
}
}
window.Quarto = {
typesetMath
};
</script>
</head>
<body>
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#the-btm-has-comparable-test-retest-reliability-to-likert-scale-items" id="toc-the-btm-has-comparable-test-retest-reliability-to-likert-scale-items" class="nav-link active" data-scroll-target="#the-btm-has-comparable-test-retest-reliability-to-likert-scale-items">The BTM has comparable test-retest reliability to Likert scale items</a>
<ul>
<li><a href="#reliability" id="toc-reliability" class="nav-link" data-scroll-target="#reliability">Reliability</a>
<ul>
<li><a href="#internal-consistency-rankings" id="toc-internal-consistency-rankings" class="nav-link" data-scroll-target="#internal-consistency-rankings">Internal consistency: rankings</a></li>
<li><a href="#internal-consistency-abilities" id="toc-internal-consistency-abilities" class="nav-link" data-scroll-target="#internal-consistency-abilities">Internal consistency: Abilities</a></li>
<li><a href="#test-retest-rankings" id="toc-test-retest-rankings" class="nav-link" data-scroll-target="#test-retest-rankings">Test-retest: Rankings</a></li>
<li><a href="#test-retest-abilities" id="toc-test-retest-abilities" class="nav-link" data-scroll-target="#test-retest-abilities">Test-retest: Abilities</a></li>
</ul></li>
</ul></li>
<li><a href="#validity" id="toc-validity" class="nav-link" data-scroll-target="#validity">Validity</a></li>
</ul>
</nav>
</div>
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Why should we use the BTM in psychology?</h1>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Johannes Keil </p>
</div>
</div>
</div>
</header>
<p>This is a collection of ideas for why we would want to use BTMs to assess preferences in a clinical (research) context, rather than Likert scales. For each ‘argument’, I introduce the reasoning, as well as the method one could use to test it (also, whether it can be done with existing data, or requires re-collection).</p>
<section id="the-btm-has-comparable-test-retest-reliability-to-likert-scale-items" class="level2">
<h2 class="anchored" data-anchor-id="the-btm-has-comparable-test-retest-reliability-to-likert-scale-items">The BTM has comparable test-retest reliability to Likert scale items</h2>
<p>The reasoning is that, if the BTM is not reliable there’s no real point using it. The problem is that there may be different ways of estimating this.</p>
<section id="reliability" class="level3">
<h3 class="anchored" data-anchor-id="reliability">Reliability</h3>
<p>We may want to consider two kinds of reliability - internal consistency and test-retest reliability. The problem is that we can’t use methods common for Likert scales: Rankings are ipsative data (i.e., the satisfy the constraint that the sum of all items == the overall mean) is already known.</p>
<section id="internal-consistency-rankings" class="level4">
<h4 class="anchored" data-anchor-id="internal-consistency-rankings">Internal consistency: rankings</h4>
<p>For rankings, we can’t just use Cronbach’s alpha for two reasons (Van Leeuwen & Mandabach, 2002):</p>
<p>First, rankings are constrained to sum to a specific number (the sum of all ranks). As a result, there are no ‘between-subject’ effects. All subjects will have the same mean score. So, we are concerned with a very different question compared to ‘regular’ Cronbach alpha. Recall that this is asking to which extent variation in the items is due to variation in participants’ responses (sigma_o) versus total variation.</p>
<p><span class="math display">\[
\alpha = \dfrac{\sigma_o} {\sigma_o + \sigma_e}
\]</span></p>
<p>Second, with rankings, error terms are bound to be negatively correlated - If I’ve assigned rank 1, no other item can have rank 1, so if item i has rank 1, this rank will be negatively correlated with the rank of any other candidates for rank 1 and so on (Rice, 1988). This leads to an under-estimation of standard errors for the comparison of any two items.</p>
<p>Van Leeuwen & Mandabach (2002) offer a way to get a ‘number’-estimate for internal consistency, but caution against its use due to additional assumptions (that I admittedly don’t quite grasp). They recommend showing that, across participants there are significant item effects, i.e., that across participants the rank of item i tends to be different from the average rank obtained if rankings were made at random.</p>
</section>
<section id="internal-consistency-abilities" class="level4">
<h4 class="anchored" data-anchor-id="internal-consistency-abilities">Internal consistency: Abilities</h4>
<p>Abilities are ipsative in the same way that ranks are. We may make the same argument, but showing that BTM abilities are significantly different from their (pre-determined) mean. To do this, we need to run a BTM which constrains the item mean to 0, rather than having a specific reference category.</p>
<p>To ‘put a number’ to it, we can exploit that we are using a Bayesian BTM, with credible intervals for all abilities. Credible intervals have a 95% percent chance of containing the (actually unkown) true mean for that ability. Assume that, in fact, the respondent responds at random (i.e., all abilities are truly 0). Thus, all credible interval should have a 95% chance of containing 0. We can construct a hypothesis test out of this (the irony of using a Bayesian BTM just to do a frequentist significance test is not lost on me):</p>
<ul>
<li><p><em>H0</em>: The number of credible intervals not containing 0 is not larger than would be expected given random responding</p></li>
<li><p><em>H1</em>: The number of credible intervals not containing 0 is larger than would be expected given random responding.</p></li>
</ul>
<p>We can test this with a simple binomial distribution, which we could then check against a pre-determined significance threshold:</p>
<p><span class="math display">\[
P(X = k) = \binom{n}{k} * 0.05^k * 0.95^{n-k}
\]</span></p>
<p>E.g., among 20 items, the probability of obtaining at least 3 credible intervals that don’t contain 0 would be:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">choose</span>(<span class="dv">20</span>, <span class="dv">3</span>) <span class="sc">*</span> <span class="fl">0.05</span><span class="sc">^</span><span class="dv">3</span> <span class="sc">*</span> <span class="fl">0.95</span><span class="sc">^</span><span class="dv">17</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.06</code></pre>
</div>
</div>
<p><strong>Note a problem with this!</strong> The binomial distribution assumes that individual events are independent. However, if we assume that credible intervals are comparable for different abilities (they should be) and abilities are ipsative, there will necessarily be some items that perform close to average. In our case, this means that this measure should be conservative (true non-random responding should generate MORE credible intervals containing 0 than if data were independent, so larger p-values than if data were independent).</p>
<p>To illustrate this idea, simulate some data where a respondent is choosing truly at random:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># try out a simple BT model</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>k <span class="ot">=</span> <span class="dv">20</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>dat <span class="ot"><-</span> <span class="fu">list</span>(</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="at">K =</span> k, <span class="co"># number of items</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="at">N =</span> <span class="dv">0</span>, <span class="co"># number of contests</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> <span class="at">player0 =</span> <span class="fu">c</span>(), <span class="co"># vector containing player0 for each game</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="at">player1 =</span> <span class="fu">c</span>(), <span class="co"># vector containing player1 for each game</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="fu">c</span>(), <span class="co"># who won?</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a> <span class="at">true_ability =</span> <span class="fu">rep</span>(<span class="dv">0</span>, k), <span class="co"># all abilities are equally 0</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a> <span class="at">true_probability =</span> <span class="fu">c</span>() <span class="co"># true probability of winning on this trial</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="co"># run the contests</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a>remaining_players <span class="ot"><-</span> <span class="dv">2</span><span class="sc">:</span>dat<span class="sc">$</span>K</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>dat<span class="sc">$</span>K) {</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (j <span class="cf">in</span> remaining_players) {</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span>(i <span class="sc">!=</span> j) {</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>player0 <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>player0, i)</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>player1 <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>player1, j)</span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>N <span class="ot">=</span> dat<span class="sc">$</span>N <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a> <span class="co">#probability that item 1 wins the contest</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a> p <span class="ot"><-</span> <span class="fu">inv_logit</span>(dat<span class="sc">$</span>true_ability[i] <span class="sc">-</span> dat<span class="sc">$</span>true_ability[j])</span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>true_probability <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>true_probability, p)</span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>y <span class="ot">=</span> <span class="fu">append</span>(dat<span class="sc">$</span>y,</span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a> <span class="fu">ifelse</span>(<span class="fu">runif</span>(<span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">1</span>) <span class="sc"><</span> p, <span class="dv">0</span>, <span class="dv">1</span>)) <span class="co"># if p < than threshold player 0 wins (0) otherwise player 1 (1)</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true" tabindex="-1"></a> <span class="co"># don't repeat items that already fought every other item.</span></span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true" tabindex="-1"></a> remaining_players <span class="ot">=</span> remaining_players[remaining_players <span class="sc">!=</span> i]</span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Now, analyse with a Bayesian BTM:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>fit <span class="ot"><-</span> <span class="fu">stan</span>(<span class="at">file =</span> <span class="fu">paste</span>(<span class="fu">getwd</span>(), <span class="st">"/Course_BTM/individual.stan"</span>, <span class="at">sep =</span> <span class="st">""</span>), <span class="at">data =</span> dat)</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co"># get the alpha values fitted with RSTAN</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>alpha <span class="ot"><-</span> rstan<span class="sc">::</span><span class="fu">extract</span>(fit, <span class="at">pars =</span> <span class="fu">c</span>(<span class="st">"alpha"</span>)) <span class="sc">%>%</span> <span class="fu">as.data.frame</span>()</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>point_estimate <span class="ot"><-</span> alpha <span class="sc">%>%</span> <span class="fu">colMeans</span>()</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>credible_ints <span class="ot"><-</span> <span class="fu">apply</span>(alpha, <span class="dv">2</span>, <span class="cf">function</span>(x) <span class="fu">quantile</span>(x, <span class="at">probs =</span> <span class="fu">c</span>(<span class="fl">0.025</span>, <span class="fl">0.975</span>), <span class="at">na.rm =</span> <span class="cn">TRUE</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Plot results. Most of the error bars should include 0.</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="why_BTM_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Now, compute the probability of observing this result if the responded acted at random:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># how many credible intervals do not contain 0</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>a <span class="ot"><-</span> credible_ints <span class="sc">%>%</span> <span class="fu">t</span>() <span class="sc">%>%</span> as.data.frame <span class="sc">%>%</span> </span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="at">no_zero =</span> <span class="fu">ifelse</span>(</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">2.5%</span><span class="st">`</span> <span class="sc"><</span> <span class="dv">0</span> <span class="sc">&</span> <span class="st">`</span><span class="at">97.5%</span><span class="st">`</span> <span class="sc">></span> <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">1</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>q <span class="ot">=</span> <span class="fu">sum</span>(a<span class="sc">$</span>no_zero)</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="co"># recall we had k items</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a>p <span class="ot"><-</span> <span class="fu">choose</span>(k, q) <span class="sc">*</span> <span class="fl">0.05</span><span class="sc">^</span>q <span class="sc">*</span> <span class="fl">0.95</span><span class="sc">^</span>(k<span class="sc">-</span>q)</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a><span class="co">#what's our probability?</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.36</code></pre>
</div>
</div>
<p>We would expect to get a p-value above our significance threshold (e.g., 0.05).</p>
<p>Now, repeat the same experiment, but with non-random responding:</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="why_BTM_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 1.9e-07</code></pre>
</div>
</div>
<p>Here, our p-value should be below our significance threshold. For this simulation, this is likely the case.</p>
</section>
<section id="test-retest-rankings" class="level4">
<h4 class="anchored" data-anchor-id="test-retest-rankings">Test-retest: Rankings</h4>
<p>Test-retest reliabilities are typically estimated as the correlation between subject-level scores from timepoint 1 to timepoint 2. In principle, we could simply use a non-parametric correlation for this purpose. The situation is a bit more difficult since we’re not ranking individuals (what spearman’s rank coefficient is meant for)</p>
<p>Normally, we expect to have data with three columns for this subject-time1-time2. This is not the case for our data. We have a rank for every item i, meaning there are i correlations to be computed. We could compute one reliability per participant all independently. A plot of this would likely tell us a lot about individual differences in change preference stability (do some participants have stable preferences whereas others do not?), but it doesn’t answer the main question (how much variance in preference scores is true versus error?).</p>
<p>Alternatively, we could aggregate over participants, and compute a test-retest reliability using Spearman’s rho. This would disregard a lot of the data that we have available.</p>
<p>Finally, we could fit a two-level model:</p>
<p><span class="math display">\[
rank_2 = \beta_1 * rank_1
\]</span></p>
<p>where:</p>
<p><span class="math display">\[
\beta_1 = \alpha_1 + u_i
\]</span></p>
<p>In this model, beta_1 represents reliability, as the correlation between ranks at time_1 and time_2. However, to incorporate the idea that some items may be more stable than others, we include a random slope u_i for each item in the data-set. Since it is not meaningful in this context, drop the intercept. Set the mean of all ranks to zero by subtracting (i + 2) / 2 from the ranks. Remove fixed and random intercept from the model accordingly.</p>
<p>One may debate whether we should include the item-level effect as random effect or fixed effect, but the problem with a fixed effect is that, for high levels of item-variability, the model may start predicting rank more from the identity of the item than its actual rank (which is not quite what we want it to do).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>n_subj <span class="ot">=</span> <span class="dv">1000</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>n_item <span class="ot">=</span> <span class="dv">5</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>true_var <span class="ot">=</span> <span class="dv">10</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>noise_var <span class="ot">=</span> <span class="fl">0.05</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>item_noise_var <span class="ot">=</span> <span class="dv">5</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Here the true correlation between time 1 and time 2 (= true reliability) should be:</p>
<p><span class="math display">\[
\rho = \dfrac{cov(t_1, t_2)} {\sqrt{(var(t_1) * var(t_2)}}
\]</span> where:</p>
<p><span class="math display">\[
var(t_2) = var(t_1 + item + noise)
\]</span></p>
<p><span class="math display">\[
var(t_2) = var(t_1) + var(item) + var(noise) + cov(t_1, item) + cov(t_1, noise) + cov(noise, item)
\]</span></p>
<p>Since we assume that random effects and error are uncorrelated with true score and each other:</p>
<p><span class="math display">\[
var(t_2) = var(t_1) + var(item) + var(noise)
\]</span></p>
<p>And:</p>
<p><span class="math display">\[
cov(t_1, t_2) = cov(t_1, t_1 + item + noise) = var(t_1) + cov(t_1, item) + cov(t_1, noise)
\]</span></p>
<p>Which again simplifies, since true scores and random effects/errors are uncorrelated:</p>
<p><span class="math display">\[
cov(t_1, t_2) = var(t_1)
\]</span></p>
<p>In total, this yields:</p>
<p><span class="math display">\[
\rho = \dfrac{var(t_1)} {\sqrt{var(t_1) * (var(t_1) + var(item) + var(noise))}}
\]</span></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>true_cor <span class="ot">=</span> true_var <span class="sc">/</span> <span class="fu">sqrt</span>(true_var <span class="sc">*</span> (true_var <span class="sc">+</span> noise_var <span class="sc">+</span> item_noise_var))</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>true_cor</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.82</code></pre>
</div>
</div>
<p>Now set up the simulation:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co"># create a few random rankings:</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>dat <span class="ot"><-</span> <span class="fu">list</span>(</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="at">item =</span> <span class="fu">c</span>(),</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="at">subj =</span> <span class="fu">c</span>(),</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="at">true =</span> <span class="fu">c</span>(),</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> <span class="at">noise =</span> <span class="fu">c</span>(),</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a> <span class="at">rank1 =</span> <span class="fu">c</span>(),</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a> <span class="at">rank2 =</span> <span class="fu">c</span>()</span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a>item_noise <span class="ot"><-</span> <span class="fu">rnorm</span>(<span class="at">n =</span> n_item, <span class="at">mean =</span> <span class="dv">0</span>, <span class="at">sd =</span> item_noise_var) <span class="co"># item-level random effect</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>n_subj) {</span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a> true <span class="ot"><-</span> <span class="fu">rnorm</span>(<span class="at">n =</span> n_item, <span class="at">mean =</span> <span class="dv">0</span>, <span class="at">sd =</span> true_var) <span class="co"># true score at both timepoints</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a> noise <span class="ot"><-</span> <span class="fu">rnorm</span>(<span class="at">n =</span> n_item, <span class="at">mean =</span> <span class="dv">0</span>, <span class="at">sd =</span> noise_var) <span class="co"># random noise</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a> rank1 <span class="ot"><-</span> <span class="fu">rank</span>(true) <span class="sc">-</span> (n_item <span class="sc">+</span> <span class="dv">1</span>) <span class="sc">/</span> <span class="dv">2</span> <span class="co"># corresponding rank</span></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a> rank2 <span class="ot"><-</span> <span class="fu">rank</span>(true <span class="sc">+</span> item_noise <span class="sc">+</span> noise) <span class="sc">-</span> (n_item <span class="sc">+</span> <span class="dv">1</span>) <span class="sc">/</span> <span class="dv">2</span> <span class="co"># rank at time 2</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>item <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>item, <span class="fu">as.factor</span>(<span class="dv">1</span><span class="sc">:</span>n_item))</span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>subj <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>subj, <span class="fu">rep</span>(i, n_item))</span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>true <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>true, true)</span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>noise <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>noise, noise)</span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>rank1 <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>rank1, rank1)</span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a> dat<span class="sc">$</span>rank2 <span class="ot"><-</span> <span class="fu">append</span>(dat<span class="sc">$</span>rank2, rank2)</span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a>model <span class="ot"><-</span> <span class="fu">lmer</span>(rank2 <span class="sc">~</span> <span class="dv">0</span> <span class="sc">+</span> rank1 <span class="sc">+</span> (<span class="dv">0</span> <span class="sc">+</span> rank1 <span class="sc">|</span>item), <span class="at">data =</span> dat)</span>
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a>res <span class="ot"><-</span> <span class="fu">summary</span>(model)</span>
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(res)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Linear mixed model fit by REML ['lmerMod']
Formula: rank2 ~ 0 + rank1 + (0 + rank1 | item)
Data: dat
REML criterion at convergence: 14038
Scaled residuals:
Min 1Q Median 3Q Max
-3.117 -0.629 0.000 0.745 3.324
Random effects:
Groups Name Variance Std.Dev.
item rank1 0.0156 0.125
Residual 0.9662 0.983
Number of obs: 5000, groups: item, 5
Fixed effects:
Estimate Std. Error t value
rank1 0.7115 0.0567 12.5</code></pre>
</div>
</div>
<p>Now, compare with model without random effects:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># compare with model without random effects</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>model2 <span class="ot"><-</span> <span class="fu">lm</span>(rank2 <span class="sc">~</span> <span class="dv">0</span> <span class="sc">+</span> rank1, <span class="at">data =</span> dat)</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>model2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = rank2 ~ 0 + rank1, data = dat)
Coefficients:
rank1
0.71 </code></pre>
</div>
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">anova</span>(model, model2)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Data: dat
Models:
model2: rank2 ~ 0 + rank1
model: rank2 ~ 0 + rank1 + (0 + rank1 | item)
npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
model2 2 14149 14162 -7073 14145
model 3 14040 14059 -7017 14034 112 1 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
</div>
</div>
<p>If significant, this will tell us if there is true variation in reliability between the items.</p>
<p>To see whether our model is making reasonable predictions, also get the individual item-level reliabilities:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>item_cors <span class="ot"><-</span> <span class="fu">list</span>(</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="at">item =</span> <span class="dv">1</span><span class="sc">:</span>n_item,</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> <span class="at">cor =</span> <span class="fu">c</span>()</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>n_item){</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a> temp <span class="ot"><-</span> dat <span class="sc">%>%</span> <span class="fu">as.data.frame</span>() <span class="sc">%>%</span> </span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(item <span class="sc">==</span> i)</span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a> c <span class="ot"><-</span> <span class="fu">cor.test</span>(temp<span class="sc">$</span>rank1, temp<span class="sc">$</span>rank2, <span class="at">method =</span> <span class="st">"spearman"</span>)<span class="sc">$</span>estimate[<span class="dv">1</span>]</span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a> item_cors<span class="sc">$</span>cor <span class="ot"><-</span> <span class="fu">append</span>(item_cors<span class="sc">$</span>cor, c)</span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(item_cors)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>$item
[1] 1 2 3 4 5
$cor
rho rho rho rho rho
0.88 0.75 0.86 0.81 0.88 </code></pre>
</div>
</div>
<p>Our lme model estimates that the variance in the 2-level data is very, very small - sometimes we run into singularities (i.e., variance in reliability at item level is predicted to be exactly 0). So, it’s important to double check with our ‘raw’ computed values: Their variance is:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>item_cors<span class="sc">$</span>cor <span class="sc">%>%</span> <span class="fu">var</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.0031</code></pre>
</div>
</div>
<p>Now, compare with a standard spearman rho, computed ignoring the hierarchical structure of the data.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>c <span class="ot"><-</span> <span class="fu">cor.test</span>(dat<span class="sc">$</span>rank1, dat<span class="sc">$</span>rank2, <span class="at">method =</span> <span class="st">"spearman"</span>)</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>c</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Spearman's rank correlation rho
data: dat$rank1 and dat$rank2
S = 6e+09, p-value <2e-16
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.71 </code></pre>
</div>
</div>
<p>To summarise:</p>
<ul>
<li><p>We can estimate overall (raw) test-retest reliability, ignoring item-structure with spearman’s rho</p></li>
<li><p>We can supplement this by calculating separate reliabilities for each item.</p></li>
<li><p>We can supplement this by computing a 2-level lme including random slopes for items. However, this seems to run into singularities a lot and may not be trustworthy.</p></li>
</ul>
</section>
<section id="test-retest-abilities" class="level4">
<h4 class="anchored" data-anchor-id="test-retest-abilities">Test-retest: Abilities</h4>
<p>The same problems should arise for abilities computed at the subject level, so they can be solved in the same way (using a total reliability and individual item reliabilities). Unlike ranks, abilities are a continuous measure, and our BTM can be set to compute abilities under the assumption of normally distributed errors - so we could try a parametric analysis instead of spearman’s rho?</p>
</section>
</section>
</section>
<section id="validity" class="level2">
<h2 class="anchored" data-anchor-id="validity">Validity</h2>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var mailtoRegex = new RegExp(/^mailto:/);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// undo the damage that might have been done by quarto-nav.js in the case of
// links that we want to consider external
if (link.dataset.originalHref !== undefined) {
link.href = link.dataset.originalHref;
}
}
}
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
const config = {
allowHTML: true,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start',
};
if (contentFn) {
config.content = contentFn;
}
if (onTriggerFn) {
config.onTrigger = onTriggerFn;
}
if (onUntriggerFn) {
config.onUntrigger = onUntriggerFn;
}
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note) {
return note.innerHTML;
} else {
return "";
}
});
}
const xrefs = window.document.querySelectorAll('a.quarto-xref');
const processXRef = (id, note) => {
// Strip column container classes
const stripColumnClz = (el) => {
el.classList.remove("page-full", "page-columns");
if (el.children) {
for (const child of el.children) {
stripColumnClz(child);
}
}
}
stripColumnClz(note)
if (id === null || id.startsWith('sec-')) {
// Special case sections, only their first couple elements
const container = document.createElement("div");
if (note.children && note.children.length > 2) {
container.appendChild(note.children[0].cloneNode(true));
for (let i = 1; i < note.children.length; i++) {
const child = note.children[i];
if (child.tagName === "P" && child.innerText === "") {
continue;
} else {
container.appendChild(child.cloneNode(true));
break;
}
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(container);
}
return container.innerHTML
} else {
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
return note.innerHTML;
}
} else {
// Remove any anchor links if they are present
const anchorLink = note.querySelector('a.anchorjs-link');
if (anchorLink) {
anchorLink.remove();
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
// TODO in 1.5, we should make sure this works without a callout special case
if (note.classList.contains("callout")) {
return note.outerHTML;
} else {
return note.innerHTML;
}
}
}
for (var i=0; i<xrefs.length; i++) {
const xref = xrefs[i];
tippyHover(xref, undefined, function(instance) {
instance.disable();
let url = xref.getAttribute('href');
let hash = undefined;
if (url.startsWith('#')) {
hash = url;
} else {
try { hash = new URL(url).hash; } catch {}
}
if (hash) {
const id = hash.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note !== null) {
try {
const html = processXRef(id, note.cloneNode(true));
instance.setContent(html);
} finally {
instance.enable();
instance.show();
}
} else {
// See if we can fetch this
fetch(url.split('#')[0])
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.getElementById(id);
if (note !== null) {
const html = processXRef(id, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
} else {
// See if we can fetch a full url (with no hash to target)
// This is a special case and we should probably do some content thinning / targeting
fetch(url)
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.querySelector('main.content');
if (note !== null) {
// This should only happen for chapter cross references
// (since there is no id in the URL)
// remove the first header
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
note.children[0].remove();
}
const html = processXRef(null, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
}, function(instance) {
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
div.style.left = 0;
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
elRect = undefined;
if (selectedAnnoteEl) {
selectCodeLines(selectedAnnoteEl);
}
}, 10)
);
function throttle(fn, ms) {
let throttle = false;
let timer;
return (...args) => {
if(!throttle) { // first call gets through
fn.apply(this, args);
throttle = true;
} else { // all the others get throttled
if(timer) clearTimeout(timer); // cancel #2
timer = setTimeout(() => {
fn.apply(this, args);
timer = throttle = false;
}, ms);
}
};
}
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>