-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetprob_gpirt.R
More file actions
51 lines (49 loc) · 1.22 KB
/
getprob_gpirt.R
File metadata and controls
51 lines (49 loc) · 1.22 KB
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
getprobs_gpirt = function(xs, irfs, thresholds){
C = ncol(thresholds) - 1
probs = data.frame(matrix(ncol = 3, nrow = 0))
colnames(probs) = c("order", "xs","p")
for (i in 1:length(xs)) {
ps = matrix(0, nrow=ncol(irfs), ncol=C)
for (c in 1:C){
for (iter in 1:ncol(irfs)){
z1 = thresholds[iter, c] - irfs[i,iter]
z2 = thresholds[iter, c+1] - irfs[i,iter]
ps[iter, c] = pnorm(z2)-pnorm(z1)
}
}
ps = colMeans(ps)
for (c in 1:C){
probs[nrow(probs) + 1,] = c(c, xs[i], ps[c])
}
}
return(probs)
}
getprobs_2PL = function(xs, betas){
C = length(betas)
probs = data.frame(matrix(ncol = 3, nrow = 0))
slope = betas[[C]]
colnames(probs) = c("order", "xs","p")
for (i in 1:length(xs)) {
ps = rep(0, C+1)
ps[C+1] = 1
for (c in 1:(C-1)){
lp = betas[[c]] - xs[i]*slope
ps[c+1] = 1 / (1+ exp(-lp))
}
for (c in 1:C) {
probs[nrow(probs) + 1,] = c(c, xs[i], ps[c+1]-ps[c])
}
}
return(probs)
}
SEKernel = function(xs, sigma=1){
n = length(xs)
result = matrix(0, nrow=n, ncol=n)
for (i in 1:n) {
for (j in 1:n) {
diff = xs[i] - xs[j]
result[i,j] = exp(-0.5*diff*diff/sigma/sigma)
}
}
return(result)
}