-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdev.R
79 lines (67 loc) · 1.59 KB
/
dev.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
library(mirt)
set.seed(1)
d_sim = simdata(
N = 1000,
itemtype = '2PL',
a = runif(50, .5, 2),
d = runif(50, -2, 2)
)
irt_fit = mirt(d_sim, 1)
get_reliability_at(irt_fit, 'total')
get_reliability_at(irt_fit, c(0))
get_reliability_at(irt_fit, c(-2, -1, 0, 1, 2))
abbrev_at_1 = abbreviate_scale(
d_sim,
item_target = 20,
selection_method = "r",
reliability_at = 1
)
abbrev_at_0 = abbreviate_scale(
d_sim,
item_target = 20,
selection_method = "r",
reliability_at = 0
)
abbrev_at_m1 = abbreviate_scale(
d_sim,
item_target = 20,
selection_method = "r",
reliability_at = -1
)
abbrev_at_extremes = abbreviate_scale(
d_sim,
item_target = 20,
selection_method = "r",
reliability_at = c(-2, 2)
)
abbrev_at_total = abbreviate_scale(
d_sim,
item_target = 20,
selection_method = "r",
reliability_at = "total"
)
#extract reliability data
abbrev_reliabilities = map2_dfr(list(abbrev_at_m1, abbrev_at_0, abbrev_at_1, abbrev_at_extremes, abbrev_at_total), c(-1, 0, 1, "-2, 2", "total"), function(abbrev_obj, target) {
abbrev_obj$best_sets %>%
tail(1) %>%
pull(fit) %>%
extract2(1) %>%
extract2("fit") %>%
get_reliabilities() %>%
mutate(target = as.character(target))
}) %>%
bind_rows(
get_reliabilities(irt_fit) %>%
mutate(target = "full")
)
#plot reliability data
abbrev_reliabilities %>%
filter(is_between(z,-3, 3)) %>%
mutate(
target = factor(target)
) %>%
ggplot(aes(z, y = rel, color = target)) +
geom_line() +
theme_bw() +
#add target values at vertical lines
geom_vline(xintercept = c(-1, 0, 1), linetype = "dashed")