-
Notifications
You must be signed in to change notification settings - Fork 0
/
BF_comparisons.Rmd
613 lines (458 loc) · 18 KB
/
BF_comparisons.Rmd
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
---
title: "BF_comparison"
author: "Ulrich Lösener"
date: "9-9-2024"
output: html_document
---
In this file, I compare the results of the function `BF` from the package BFpack (v. 1.2.3), the function `bain` from the bain package (v. 0.2.8), and my own function `bf_hand` to calculate the multivariate Bayes Factor for informative hypotheses.
First, I define a function to "translate" hypotheses into restriction matrices as in (Gu et al., 2018)
```{r hyp2mat}
hyp2mat <- function(hypothesis) {
# Split the hypothesis into parts
parts <- unlist(strsplit(hypothesis, "(?=[<>=])|(?<=[<>=])", perl = TRUE))
# Extract parameters
parameters <- unique(parts[!parts %in% c("<", ">", "=")])
num_params <- length(parameters)
# storage for restriction matrices
ineq_constraints <- list()
eq_constraints <- list()
# Parse the hypothesis
for (i in seq(1, length(parts) - 1, by = 2)) {
param1 <- parts[i]
operator <- parts[i + 1]
param2 <- parts[i + 2]
index1 <- match(param1, parameters)
index2 <- match(param2, parameters)
if (operator == "<" || operator == ">") {
constraint <- rep(0, num_params)
if (operator == "<") {
constraint[c(index1, index2)] <- c(-1, 1)
} else {
constraint[c(index1, index2)] <- c(1, -1)
}
ineq_constraints[[length(ineq_constraints) + 1]] <- constraint
} else if (operator == "=") {
constraint <- rep(0, num_params)
constraint[c(index1, index2)] <- c(1, -1)
eq_constraints[[length(eq_constraints) + 1]] <- constraint
}
}
# Convert lists to matrices
if (length(ineq_constraints) > 0) {
Ineq.mat <- do.call(rbind, ineq_constraints)
} else {
Ineq.mat <- matrix(0, 0, num_params)
}
if (length(eq_constraints) > 0) {
Eq.mat <- do.call(rbind, eq_constraints)
} else {
Eq.mat <- matrix(0, 0, num_params)
}
list(Ineq.mat = Ineq.mat, Eq.mat = Eq.mat)
}
```
Next, I define my own function to calculate BF_u for informative hypotheses.
```{r my own multivariate BF function}
bf_hand <- function(N, est, sigma, hypothesis, fraction = 1) {
hypothesis <- gsub("([>=<])", " \\1 ", hypothesis) # Add spaces
hypothesis <- gsub("\\s+", " ", hypothesis) # Remove any extra spaces
hypothesis <- trimws(hypothesis) # Trim leading and trailing spaces
b <- fraction/N
struc <- unlist(strsplit(hypothesis, " "))
params <- struc[seq(1, length(struc), 2)]
constr <- struc[seq(2, length(struc) - 1, 2)]
ineq.constr <- constr[constr == "<" | constr == ">"]
eq.constr <- constr[constr == "="]
# Contrast matrix
Rmat <- hyp2mat(hypothesis = hypothesis)
Rmat_ineq <- Rmat$Ineq.mat
Rmat_eq <- Rmat$Eq.mat
# Compute the complexity (c) and fit (f) for inequalities
if(!is.null(Rmat_ineq) && nrow(Rmat_ineq) > 0) {
# if there are < constraints, reverse sign of estimates
if(any(constr == "<")) {
est_adjusted <- -est
} else {
est_adjusted <- est
}
# Initialize bounds for inequalities
lower <- rep(-Inf, length(ineq.constr))
upper <- rep(Inf, length(ineq.constr))
# Assign bounds based on inequality constraints
lower[ineq.constr == ">"] <- 0
upper[ineq.constr == "<"] <- 0
c_ineq <- as.numeric(mvtnorm::pmvnorm(lower = lower, upper = upper,
mean = rep(0, length(ineq.constr)),
sigma = Rmat_ineq %*% sigma %*% t(Rmat_ineq)/b,
keepAttr = F))
f_ineq <- as.numeric(mvtnorm::pmvnorm(lower = lower, upper = upper,
mean = c(Rmat_ineq %*% est_adjusted),
sigma = Rmat_ineq %*% sigma %*% t(Rmat_ineq),
keepAttr = F))
BFu_ineq <- f_ineq / c_ineq
} else {
c_ineq <- 1
f_ineq <- 1
BFu_ineq <- 1
}
if (!is.null(Rmat_eq) && nrow(Rmat_eq) > 0) {
c_eq <- mvtnorm::dmvnorm(rep(0, nrow(Rmat_eq)),
sigma = Rmat_eq %*% sigma %*% t(Rmat_eq)/b)
f_eq <- mvtnorm::dmvnorm(x = rep(0, nrow(Rmat_eq)), mean = Rmat_eq %*% est,
sigma = Rmat_eq %*% sigma %*% t(Rmat_eq))
BFu_eq <- f_eq / c_eq
} else {
c_eq <- 1
f_eq <- 1
BFu_eq <- 1
}
BFu <- BFu_ineq * BFu_eq
return(list(complex_ineq = c_ineq,
complex_eq = c_eq,
fit_ineq = f_ineq,
fit_eq = f_eq,
BFu = BFu))
}
```
Now, we load the packages bain and BFpack.
```{r libraries, message=FALSE, warning=FALSE}
library(bain)
library(BFpack)
```
## Simulation 1: Fix N, vary effect size
#### $H_1: a<b<c$
The effect size in this case is the difference between the three parameters "a", "b", and "c". In this simulation, we evaluate 100 different effect sizes from very small (a=0, b=0.1, c=0.2) to very large (a=0, b=10, c=20), keeping N constant at N=100.
The first hypothesis under consideration is $H_1: a<b<c$. We expect the $BF_{1u}$ to increase with increasing effect size.
```{r simulation1}
hyp1 <- "a<b<c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
ests <- list() # space for estimates of a, b, and c
# create vectors of a, b, and c according to different effect sizes and store them in ests
for(i in 1:m){
a <- 0
b <- a+i/10
c <- b+i/10
ests[[i]] <- c(a, b, c)
names(ests[[i]]) <- c("a", "b", "c")
}
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = ests[[i]], N=100, sigma=sig, hypothesis=hyp1)
BFs_hand[i] <- r$BFu
r2 <- BF(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp1)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp1)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
Now, we plot the results.
```{r plots1.1, warning=FALSE}
library(ggplot2)
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes( x=iteration, y=bf, color=type)) +
geom_line() +
xlab("effect size") +
ggtitle("H1: a<b<c")
BFs_bfpack == BFs_hand # TRUE
```
My function `bf_hand` gives the exact same results as BFpack. The results from bain are a bit noisy but also in accordance with the other two functions.
#### $H_2:a<b=c$
Now, we do the same for a different hypothesis. $H_2:a<b=c$. Because we know that $b\neq c$, we expect the BF to decline at some point. For convenience, the code for the second simulation is hidden. It is very similar to the code for the first simulation with exception of the hypothesis.
```{r simulation1b, include=FALSE}
hyp2 <- "a<b=c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
ests <- list() # space for estimates of a, b, and c
# create vectors of a, b, and c according to different effect sizes and store them in ests
for(i in 1:m){
a <- 0
b <- a+i/10
c <- b+i/10
ests[[i]] <- c(a, b, c)
names(ests[[i]]) <- c("a", "b", "c")
}
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = ests[[i]], N=100, sigma=sig, hypothesis=hyp2)
BFs_hand[i] <- r$BFu
r2 <- BF(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp2)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp2)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
Now, we plot the results.
```{r plots1.2, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes( x=iteration, y=bf, color=type)) +
geom_line() +
xlab("effect size") +
ggtitle("H2: a<b=c")
```
This is interesting. All three functions give different results. My own function `bf_hand` seems to be in between the other two.
#### $H_3:a=b=c$
Let's see what happens when the hypothesis is $H_3:a=b=c$
```{r simulation1c, include=FALSE}
hyp3 <- "a=b=c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
ests <- list() # space for estimates of a, b, and c
# create vectors of a, b, and c according to different effect sizes and store them in ests
for(i in 1:m){
a <- 0
b <- a+i/10
c <- b+i/10
ests[[i]] <- c(a, b, c)
names(ests[[i]]) <- c("a", "b", "c")
}
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = ests[[i]], N=100, sigma=sig, hypothesis=hyp3)
BFs_hand[i] <- r$BFu
r2 <- BF(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp3)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp3)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
```{r plots1.3, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes(x=iteration, y=bf, color=type)) +
geom_line() +
xlab("effect size") +
ggtitle("H3: a=b=c")
```
```{r}
BFs_bfpack == BFs_hand # TRUE
```
As was the case in the first simulation, the function from BFpack and `bf_hand` give the exact same results. Interestingly, the BF from bain is exactly half of the other BFs.
```{r simulation1d, include=FALSE, cache=TRUE}
hyp4 <- "a>b>c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
ests <- list() # space for estimates of a, b, and c
# create vectors of a, b, and c according to different effect sizes and store them in ests
for(i in 1:m){
a <- 0
b <- a+i/10
c <- b+i/10
ests[[i]] <- c(a, b, c)
names(ests[[i]]) <- c("a", "b", "c")
}
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = ests[[i]], N=100, sigma=sig, hypothesis=hyp4)
BFs_hand[i] <- r$BFu
r2 <- BF(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp4)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=ests[[i]], n=100, Sigma=sig, hypothesis=hyp4)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
#### $H_4:a>b>c$
Lastly, we have a look at the hypothesis $H_4:a>b>c$.
```{r plots1.4, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes(x=iteration, y=bf, color=type)) +
geom_line() +
xlab("effect size") +
ggtitle("H4: a>b>c")
```
```{r}
BFs_bain - BFs_bfpack # non-zero difference
BFs_bfpack - BFs_hand # zero difference
```
Although this is a similar form to $H_1$ (inequality constraints only), this scenario is different in that all three functions give the same results. Note that only `bf_hand` and `BF` (from BFpack) are *exactly* equivalent while results from `bain` are (ever so) slightly different. This difference becomes even smaller for larger effect sizes. This is most likely due to the fact that `bain` relies on stochastic processes such as repeated sampling from the posterior.
## Simulation 2: Vary N, fix effect size
Now we fix the effect size to a medium effect, resulting in the following estimates: $a=0; b=1; c=2$.
For the first hypothesis $H_1:a<b<c$, we expect no effect of N as no (about) equality constraints are present.
```{r simulation2a, include=FALSE, cache=TRUE}
hyp1 <- "a<b<c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
est <- c(0,1,2) # space for estimates of a, b, and c
names(est) <- c("a", "b", "c")
Ns <- seq(10:110)
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = est, N=Ns[i], sigma=sig, hypothesis=hyp1)
BFs_hand[i] <- r$BFu
r2 <- BF(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp1)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp1)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
```{r plots2.1, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes(x=iteration, y=bf, color=type)) +
geom_line() +
xlab("N-10") +
ggtitle("H1: a<b<c")
```
```{r}
BFs_bfpack==BFs_hand
```
Unsurprisingly, N has no effect on the $BF_{1u}$. We can see that the result from `bain` oszillates around the results from `BF` and `bf_hand` which are identical to each other (except for some values which deviate slightly from each other).
#### $H_2:a<b=c$
```{r simulation2b, include=FALSE, cache=TRUE}
hyp2 <- "a<b=c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
est <- c(0,1,2) # space for estimates of a, b, and c
names(est) <- c("a", "b", "c")
Ns <- seq(10:110)
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = est, N=Ns[i], sigma=sig, hypothesis=hyp2)
BFs_hand[i] <- r$BFu
r2 <- BF(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp2)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp2)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
```{r plots2.2, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes(x=iteration, y=bf, color=type)) +
geom_line() +
xlab("N-10") +
ggtitle("H2: a<b=c")
```
Because there is an equality constraint, N has an effect on the $BF_{2u}$.
We see the same pattern as in simulation 1: `bf_hand` gives results which are in between `BF` and `bain`.
```{r simulation2c, include=FALSE, cache=TRUE}
hyp3 <- "a=b=c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
est <- c(0,1,2) # space for estimates of a, b, and c
names(est) <- c("a", "b", "c")
Ns <- seq(10:110)
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = est, N=Ns[i], sigma=sig, hypothesis=hyp3)
BFs_hand[i] <- r$BFu
r2 <- BF(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp3)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp3)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
```{r plots2.3, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes(x=iteration, y=bf, color=type)) +
geom_line() +
xlab("N-10") +
ggtitle("H3: a=b=c")
```
```{r}
BFs_hand==BFs_bfpack
```
Again, `bf_hand` and `BF` virtually give the same results while the result from `bain` is about half the value of the others (analogous to simulation 1).
#### $H_{4b}:a=b>$
```{r simulation2d, include=FALSE, cache=TRUE}
hyp4 <- "a=b>c" # define our hypothesis H1
sig <- matrix(c(1, 0.3, 0.3, # covariance matrix of parameters
0.3, 1, 0.3,
0.3, 0.3, 1), nrow = 3)
m <- 100 # number of iterations
est <- c(0,1,2) # space for estimates of a, b, and c
names(est) <- c("a", "b", "c")
Ns <- seq(10:110)
# storage
BFs_hand <- rep(NA, m)
BFs_bfpack <- rep(NA, m)
BFs_bain <- rep(NA, m)
# fix N, vary eff.size
set.seed(123)
for(i in 1:m){
r <- bf_hand(est = est, N=Ns[i], sigma=sig, hypothesis=hyp4)
BFs_hand[i] <- r$BFu
r2 <- BF(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp4)
BFs_bfpack[i] <- r2[["BFtable_confirmatory"]][1,7]
r3 <- bain(x=est, n=Ns[i], Sigma=sig, hypothesis=hyp4)
BFs_bain[i] <- r3[["fit"]][["BF.u"]][1]
}
```
```{r plots2.4, echo=FALSE}
sim_dat1 <- data.frame(cbind(c(BFs_hand, BFs_bfpack, BFs_bain), rep(c("hand", "bfpack", "bain"), each=100), as.numeric(rep(seq(1:100), 3))))
names(sim_dat1) <- c("bf", "type", "iteration")
sim_dat1$bf <- as.numeric(sim_dat1$bf)
sim_dat1$iteration <- as.numeric(sim_dat1$iteration)
ggplot(sim_dat1, aes(x=iteration, y=bf, color=type)) +
geom_line() +
xlab("N-10") +
ggtitle("H4: a=b>c")
```
This is the first time that the result from `bf_hand` is quite different from the results from the other functions. The $BF_{4bu}$ from my function is dramatically larger than the others.