'How to plot a Sequential Bayes Factor as participants are added
I am currently analyzing eye-tracking data using the Sequential Bayes Factor method, and I would like to plot how the resulting Bayes Factor (BF; calculated from average looking times) changes as participants are added.
I would like the x-axis to represent the number of participants included in the calculation, and the y-axis to represent the resulting Bayes Factor.
For example, when participants 1-10 are included, BF = [y-value], and that is one plot point on the graph. When participants 1-11 are included, BF = [y-value], and that is the second plot point on the graph.
Is there a way to do this in R?
For example, I have this data set:
ID avg_PTL
<chr> <dbl>
1 D07 -0.0609
2 D08 0.0427
3 D12 0.112
4 D15 -0.106
5 D16 0.199
6 D19 0.0677
7 D20 0.0459
8 d21 -0.158
9 D23 0.0650
10 D25 0.0579
11 D27 0.0463
12 D29 0.00822
13 D30 0.00613
14 D36 -0.0484
15 D37 0.0312
16 D39 0.000547
17 D44 0.0336
18 D46 0.0514
19 D48 0.236
20 D51 -0.000487
21 D60 0.0410
22 D61 0.0622
23 D62 0.0337
24 D64 -0.125
25 D65 0.215
26 D66 0.200
And I calculate the BF with:
bf.mono.correct = ttestBF(x = avg_PTL_mono_correct$avg_PTL)
Any tips are much appreciated!
Solution 1:[1]
You can use sapply
to run the test multuiple times and just subset the vector of observations each time. For example
srange <- 10:nrow(avg_PTL_mono_correct)
BF <- sapply(srange, function(i) {
extractBF(ttestBF(x = avg_PTL_mono_correct$avg_PTL[1:i]), onlybf=TRUE)
})
plot(srange, BF)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MrFlick |