-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconvergence_behavior.R
58 lines (39 loc) · 1.81 KB
/
convergence_behavior.R
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
# study of number of pathfinder paths & convergence behavior
library(idealstan)
library(tidyverse)
set.seed(20241020)
# number of paths
paths <- 1:100
# number of sims
sims <- 1:10
results <- lapply(paths, function(p) {
lapply(sims, function(s) {
bin_irt_2pl_sim <- id_sim_gen(num_person=100,num_bills=5,ordinal=F,inflate=F,
diff_sd=1,
reg_discrim_sd = 1,
absence_discrim_sd = 1)
bin_irt_2pl_est <- id_estimate(idealdata=bin_irt_2pl_sim,
model_type=1,init_pathfinder = TRUE,
restrict_ind_high = as.character(sort(bin_irt_2pl_sim@simul_data$true_person,
decreasing=T,
index=T)$ix[1]),
restrict_ind_low = as.character(sort(bin_irt_2pl_sim@simul_data$true_person,
decreasing=F,
index=T)$ix[1]),
fixtype='prefix',
person_sd = 3,
nchains=4,ncores=4,compile_optim = F,num_pathfinder_paths = p)
# get summaries
summaries <- bin_irt_2pl_est@summary
# return max rhat
tibble(draw=s,
path_num=p,
max_rhat=max(summaries$rhat,na.rm=T),
ll_rhat=summaries$rhat[summaries$variable=="lp__"])
}) %>% bind_rows
}) %>% bind_rows
results %>%
ggplot(aes(y=ll_rhat,x=path_num)) +
geom_point() +
stat_smooth(method="lm") +
ggthemes::theme_clean()