The objective of this vignette is to provide clarity as to the
estimation procedure used to obtain the results in the paper. This
vignette breaks down each section in the example displayed in
cIRT()
function.
Within this vignette, we used two different data sets to generate a
Choice Item Response Theory Model with the routine located in
cIRT
.
The first data set, trial_matrix
, contains whether or
not the subject correctly identified the spatial rotation. The second
dataset, choice_matrix
, provides information regarding the
choice decision subjects were asked to make.
Here we construct a thurstone design matrix by obtaining the IDs of hard and easy questions presented for the subject to make a decision upon.
# Create the Thurstone Design Matrices
hard_items = choice_matrix$hard_q_id
easy_items = choice_matrix$easy_q_id
D_easy = model.matrix( ~ -1 + factor(easy_items))
D_hard = -1 * model.matrix( ~ -1 + factor(hard_items))[, -c(5, 10, 15)]
Within this setting, we setup the effect-codes for different constraints.
# Defining effect-coded contrasts
high_contrasts = rbind(-1, diag(4))
rownames(high_contrasts) = 12:16
low_contrasts = rbind(-1, diag(2))
rownames(low_contrasts) = 4:6
# Creating high & low factors
high = factor(choice_matrix[, 'high_value'])
low = factor(choice_matrix[, 'low_value'])
contrasts(high) = high_contrasts
contrasts(low) = low_contrasts
fixed_effects = model.matrix( ~ high + low)
fixed_effects_base = fixed_effects[, 1]
fixed_effects_int = model.matrix( ~ high * low)
Generate the cIRT model using a Thurstone Design Matrix generated above.
# Model with Thurstone D matrix
system.time({
out_model_thurstone = cIRT(
choice_matrix[, 'subject_id'],
cbind(fixed_effects[, -1], D_easy, D_hard),
c(1:ncol(fixed_effects)),
as.matrix(fixed_effects),
as.matrix(trial_matrix),
choice_matrix[, 'choose_hard_q'],
20000,
25000
)
})
## user system elapsed
## 272.140 456.491 183.345
We recommend saving the model object as a .rda
file even
though the total computational time is less than 2.5 minutes.
## Save model output to an rda file.
# save(out_model_thurstone, file='choiceMCMCoutput.rda')
## Load model output back into R.
# load(file='choiceMCMCoutput.rda')
Next up, we obtain the parameter estimates of the model by averaging over the different estimates obtained via the Gibbs sampling technique employed.
vlabels_thurstone = colnames(cbind(fixed_effects[, -1], D_easy, D_hard))
G_thurstone = t(apply(
out_model_thurstone$gs0,
2,
FUN = quantile,
probs = c(.5, .025, .975)
))
rownames(G_thurstone) = vlabels_thurstone
B_thurstone = t(apply(
out_model_thurstone$beta,
2,
FUN = quantile,
probs = c(.5, 0.025, .975)
))
rownames(B_thurstone) = colnames(fixed_effects)
S_thurstone = solve(
apply(out_model_thurstone$Sigma_zeta_inv, c(1, 2), FUN = mean)
)
inv_sd = diag(1 / sqrt(diag(solve(
apply(out_model_thurstone$Sigma_zeta_inv, c(1, 2), FUN = mean)
))))
corrmat = inv_sd %*% S_thurstone %*% inv_sd
as = apply(out_model_thurstone$as, 2, FUN = mean)
bs = apply(out_model_thurstone$bs, 2, FUN = mean)
Thus, we have the following results:
## 50% 2.5% 97.5%
## high1 -0.011616159 -0.119965568 0.09525692
## high2 -0.078753961 -0.181768006 0.02540104
## high3 0.128374836 0.023820711 0.23563779
## high4 0.155769224 0.044055962 0.26711524
## low1 0.003514825 -0.075756411 0.08091877
## low2 0.087039152 0.008389939 0.16683674
## factor(easy_items)1 -0.256304184 -0.540916533 0.02521818
## factor(easy_items)2 -0.358790117 -0.644347522 -0.07313970
## factor(easy_items)3 -0.241421049 -0.530290291 0.04510703
## factor(easy_items)4 -0.398389480 -0.682557636 -0.12282396
## factor(easy_items)5 -0.194632970 -0.485907217 0.09488271
## factor(easy_items)6 -0.447236499 -0.734726563 -0.16547427
## factor(easy_items)7 -0.294459372 -0.577861814 -0.01513976
## factor(easy_items)8 0.057547081 -0.220418506 0.33205796
## factor(easy_items)9 -0.369293092 -0.650853923 -0.09091956
## factor(easy_items)10 -0.035437058 -0.317581311 0.24715730
## factor(easy_items)11 -0.294142058 -0.578195956 -0.01568502
## factor(easy_items)12 0.037300609 -0.239872689 0.30994310
## factor(easy_items)13 -0.260231583 -0.547034165 0.02448258
## factor(easy_items)14 -0.507778813 -0.787026036 -0.22686563
## factor(easy_items)15 -0.093025821 -0.374495609 0.18621908
## factor(hard_items)16 -0.518529819 -0.793535372 -0.24886888
## factor(hard_items)17 -0.567507911 -0.836181669 -0.29525533
## factor(hard_items)18 -1.388112117 -1.675335951 -1.10130330
## factor(hard_items)19 -0.205495438 -0.473942745 0.06449499
## factor(hard_items)21 -0.717461976 -0.986818028 -0.44857475
## factor(hard_items)22 -0.250435710 -0.514367783 0.01052499
## factor(hard_items)23 -0.218579909 -0.483180613 0.04114413
## factor(hard_items)24 -1.209257089 -1.492537135 -0.92595024
## factor(hard_items)26 -0.151686347 -0.410548024 0.10944208
## factor(hard_items)27 -0.252280243 -0.512886996 0.01275203
## factor(hard_items)28 0.371161283 0.108326438 0.64064080
## factor(hard_items)29 0.754717068 0.480710271 1.03766963
## 50% 2.5% 97.5%
## (Intercept) 0.691375660 0.56188153 0.83084450
## high1 -0.114557584 -0.24573364 0.01818109
## high2 -0.000541141 -0.12854530 0.12990424
## high3 0.036251599 -0.09128242 0.17931154
## high4 0.106165182 -0.02803444 0.24384073
## low1 0.022670742 -0.07646204 0.11910493
## low2 -0.115641502 -0.21122941 -0.02010128
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.3848096769 -0.007162762 0.011875661 -0.0003695273 -0.013962691
## [2,] -0.0071627623 0.079687193 -0.011960511 -0.0037037327 -0.026514601
## [3,] 0.0118756607 -0.011960511 0.064571488 -0.0081523925 -0.005709389
## [4,] -0.0003695273 -0.003703733 -0.008152393 0.0636713163 -0.008438216
## [5,] -0.0139626907 -0.026514601 -0.005709389 -0.0084382165 0.085817669
## [6,] -0.0147320422 0.007001498 -0.003104423 -0.0057958258 0.001315661
## [7,] -0.0140548489 -0.008166296 0.002518279 0.0047216279 0.005928743
## [,6] [,7]
## [1,] -0.014732042 -0.014054849
## [2,] 0.007001498 -0.008166296
## [3,] -0.003104423 0.002518279
## [4,] -0.005795826 0.004721628
## [5,] 0.001315661 0.005928743
## [6,] 0.064481083 -0.014276634
## [7,] -0.014276634 0.062686737
## [1] 0.6280684 0.4994993 1.1407664 0.3179958 1.0060373 1.0701466 0.8186902
## [8] 0.3727781 0.8189779 0.7415893 0.6117843 1.2014612 0.8364509 0.9698820
## [15] 0.7941717 1.0133794 0.7120329 0.5840037 0.9426831 1.0752962 1.0107506
## [22] 0.6583718 0.6359003 0.5809416 0.6167177 0.6176203 0.6684032 0.7925571
## [29] 0.5025188 0.6428482
## [1] -1.13956037 -1.15805079 -1.54095155 -0.88412134 -1.01188650 -0.93468308
## [7] -0.84195685 -0.43490909 -0.47418879 -0.74840991 -0.68957966 -0.59685995
## [13] -0.66711005 -0.48628509 -0.30420064 -0.58968438 -0.49941204 -0.26746078
## [19] -0.43083252 -0.52657433 -0.32212831 -0.30623207 -0.40475776 -0.22668400
## [25] -0.06349239 0.06536198 -0.31941846 0.12981124 0.48821035 0.93079132