forked from gkrajewski/CDI-IRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_usage.Rmd
174 lines (148 loc) · 5.38 KB
/
item_usage.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
---
title: "Item usage in CAT"
author: "Piotr Król"
date: "01 09 2021"
output: html_document
---
```{r setup, include=F}
knitr::opts_chunk$set(echo = TRUE, fig.align = "center")
```
Content:
* Items parameters and category belonging
* Frequency of items and categories in CAT simulation
```{r libraries, warning=F, message=F}
library(mirtCAT)
library(parallel)
library(ggpubr)
library(plyr)
```
```{r data preparation}
responses_demo <- read.csv("Data/responses_demo.csv", encoding = "UTF-8")
responses <- as.matrix(responses_demo[,5:ncol(responses_demo)])
cdi <- read.csv("Data/cdi.csv", encoding = "UTF-8")
load("Data/items_to_remove")
load("Data/params")
load("Data/fscores")
load("Data/mod_r")
load("Data/start_thetas")
responses <- responses[, -items_to_remove]
cdi <- cdi[!cdi$number.ws %in% items_to_remove, ]
source(paste0(getwd(),"/get_sim_results.R"))
```
```{r ready report data, include=F}
load("Data/items_usage.RData")
```
```{r }
mod_r
```
# Items parameters and category belonging
```{r eval=F}
params_IRT <- as.data.frame(coef(mod_r, simplify = T, IRTpars = T)$items)[1:2]
```
```{r fig.width=12, fig.height=8}
params_cdi <- cbind(params_IRT, cdi)
ggplot(params_cdi, aes(b, a, colour=category, label=position)) +
geom_text(check_overlap = T) +
geom_point(alpha = 0.3) +
xlab("Difficulty") +
ylab("Discrimination") +
labs(colour = "Category") +
theme(
panel.background = element_rect(fill = NA),
panel.grid.major = element_line(colour = "grey"),
legend.position = "top"
)
```
# Frequency of items and categories in CAT simulation
Make simulation with recommended settings and starting thetas decreased by 2:
```{r eval=F}
sim_results <- mirtCAT(
mo = generate.mirt_object(params, '2PL'),
method = "MAP",
criteria = "MI",
start_item = "MI",
local_pattern = responses,
cl = makeCluster(detectCores()),
design = list(min_items = 10, min_SEM = 0.1, max_items = 50, thetas.start = start_thetas - 2)
)
```
Check frequency of occurence of particular items:
```{r fig.width=12, fig.height=8}
#Prepare cuts
raw_responses <- laply(sim_results, function(x) x$raw_responses)
freq <- apply(raw_responses, 2, function(x) length(which(!is.na(x))))/nrow(responses)*100
cuts <- cut(freq, breaks = c(0, 0.001, 10, 20, 30, 51, 100), labels = c("0 (unused)", "0 - 10", "10 - 20", "20 - 30", "30 - 51", "93.3"), include.lowest = TRUE)
#Plot
ggplot(data.frame(table(cuts)), aes(x = cuts, y = Freq)) +
xlab("Frequency of use (%)") +
ylab("Number of items") +
geom_bar(stat = "identity") +
geom_text(aes(label = Freq), vjust = -0.3, size=6) +
theme_pubclean() +
theme(text = element_text(size=16))
```
```{r}
params_cdi$freq <- freq
params_cdi[order(params_cdi$freq, decreasing = T), ][1:10, ]
```
```{r eval=F, include=F}
#Table for thesis
table <- params_cdi[order(params_cdi$freq, decreasing = T), ][1:10, ]
row.names(table) <- NULL
table$freq <- round(table$freq, 1)
table$dscrmn <- round(table$a, 2)
table$dffclt <- round(table$b, 2)
table$a <- NULL
table$b <- NULL
table$number.wg <- NULL
table$number.ws <- NULL
write.table(table, file="table.txt", quote = F, row.names = F)
```
Items colored by frequency:
```{r fig.width=12, fig.height=8}
ggplot(params_cdi[!params_cdi$position %in% c('szukać'), ], aes(b, a, label=position, colour=freq)) + #Remove 'szukać' since it has 93.3% frequency
geom_text(aes(label=ifelse(freq > 0, as.character(position), " ")), check_overlap = T) +
geom_text(aes(label=ifelse(freq > 30, as.character(position), " ")), check_overlap = F) +
geom_point(alpha = 0.3) +
annotate("text", x = params_cdi[params_cdi$number.ws == 508, "b"] - 0.05, y = params_cdi[params_cdi$number.ws == 508, "a"], colour = "black", label = "szukać") +
annotate("text", x = params_cdi[params_cdi$number.ws == 508, "b"] - 0.05, y = params_cdi[params_cdi$number.ws == 508, "a"] + 0.15, colour = "black", label = "(93.3%)") +
xlab("Difficulty") +
ylab("Discrimination") +
labs(colour = "Frequency (%)") +
scale_color_gradient(low="green", high="red") +
theme(
panel.background = element_rect(fill = NA),
panel.grid.major = element_line(colour = "grey"),
legend.position = "top"
)
```
Most popular categories:
```{r}
cat_categories <- data.frame(matrix(NA, nrow = length(sim_results), ncol = length(unique(cdi$category))))
colnames(cat_categories) <- unique(cdi$category)
n <- 1
for (sim in sim_results){
person_items <- sim$items_answered
person_cats <- table(cdi[person_items, "category"]) / length(person_items)
for (col in colnames(cat_categories)){
if (col %in% names(person_cats)){
cat_categories[[col]][n] <- person_cats[[col]]
} else {
cat_categories[[col]][n] <- 0
}
}
n <- n + 1
}
cat_categories <- data.frame(category = unique(cdi$category), freq = round( apply(cat_categories, 2, function(x) mean(x)), 3) * 100)
cdi_categories <- as.data.frame(round(table(cdi$category) / nrow(cdi), 3) * 100)
colnames(cdi_categories) <- c("category", "freq")
categories_used <- merge(cat_categories, cdi_categories, by="category", suffixes = c("_CAT", "_full"))
#categories_used$diff <- categories_used$freq_CAT - categories_used$freq_full
categories_used$mean_dscr <- round(aggregate(a ~ category, data = params_cdi, mean)$a, 2)
categories_used$mean_dfclt <- round(aggregate(b ~ category, data = params_cdi, mean)$b, 2)
categories_used
```
```{r eval=F, include=F}
#for thesis
write.table(categories_used, file="categories.txt", quote = F, row.names = F)
```