-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal_fit.qmd
74 lines (55 loc) · 1.6 KB
/
global_fit.qmd
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
---
format: html
---
# Study 6: Tests of global fit
Tests of global fit are often used in published psychometric research...
```{r}
pcasim <- function(dat, iterations, samplesize, cpu = 9) {
require(doParallel)
registerDoParallel(cores = cpu)
fit <- data.frame()
fit <- foreach(i = 1:iterations, .combine = rbind) %dopar% {
data <- dat[sample(1:nrow(dat), samplesize), ]
erm_out <- RM(data)
ple <- eRm::person.parameter(erm_out)
item.fit <- eRm::itemfit(ple)
std.resids <- item.fit$st.res
pca <- pca(std.resids, nfactors = ncol(data), rotate = "oblimin")
pca$values[1]
}
return(fit)
}
test <- pcasim(simdata3, 100, 500, cpu = 1)
# expected values when the data fits, no misfitting items
baseline_pca <- pcasim(simdata[[1]][,-9], 100, 500, cpu = 1)
```
```{r}
hist(test)
hist(baseline_pca)
```
```{r}
lrtsim <- function(dat, iterations, samplesize, cpu = 9) {
require(doParallel)
registerDoParallel(cores = cpu)
fit <- data.frame()
fit <- foreach(i = 1:iterations, .combine = rbind) %dopar% {
data <- dat[sample(1:nrow(dat), samplesize), ]
erm_out <- RM(data)
lrt <- LRtest(erm_out)
lrt[["pvalue"]]
# same p-values with clr_tests()
#clr <- clr_tests(dat.items = data, model = "RM")
#clr[,3]
}
return(fit)
}
test_lrt <- lrtsim(simdata3, 100, 500, cpu = 1)
test_lrt2 <- lrtsim(simdata3, 100, 500, cpu = 1)
# expected values when the data fits, no misfitting items
baseline_lrt <- lrtsim(simdata[[1]][,-9], 100, 500, cpu = 1)
```
```{r}
hist(as.numeric(test_lrt))
hist(test_lrt2)
hist(as.numeric(baseline_lrt))
```