Title: | Choice Item Response Theory |
---|---|
Description: | Jointly model the accuracy of cognitive responses and item choices within a Bayesian hierarchical framework as described by Culpepper and Balamuta (2015) <doi:10.1007/s11336-015-9484-7>. In addition, the package contains the datasets used within the analysis of the paper. |
Authors: | Steven Andrew Culpepper [aut, cph] , James Joseph Balamuta [aut, cph, cre] |
Maintainer: | James Joseph Balamuta <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.3.2 |
Built: | 2024-11-19 04:14:26 UTC |
Source: | https://github.com/tmsalab/cirt |
Jointly model the accuracy of cognitive responses and item choices within a Bayesian hierarchical framework as described by Culpepper and Balamuta (2015) <doi:10.1007/s11336-015-9484-7>. In addition, the package contains the datasets used within the analysis of the paper.
Maintainer: James Joseph Balamuta [email protected] (ORCID) [copyright holder]
Authors:
Steven Andrew Culpepper [email protected] (ORCID) [copyright holder]
Useful links:
Report bugs at https://github.com/tmsalab/cIRT/issues
Obtains the mean of each column of the matrix and subtracts it from the given matrix in a centering operation.
center_matrix(x)
center_matrix(x)
x |
A |
The application of this function to a matrix mimics the use of a centering matrix given by:
A matrix
with the same dimensions of X that has been centered.
James Joseph Balamuta
nobs = 500 nvars = 20 x = matrix(rnorm(nobs * nvars), nrow = nobs, ncol = nvars) r_centered = scale(x) arma_centered1 = center_matrix(x)
nobs = 500 nvars = 20 x = matrix(rnorm(nobs * nvars), nrow = nobs, ncol = nvars) r_centered = scale(x) arma_centered1 = center_matrix(x)
This data set contains the subject's choices and point values for the difficult questions.
choice_matrix
choice_matrix
A data frame with 3780 observations on the following 5 variables.
subject_id
Research Participant Subject ID. There are 102 IDs and each ID has 15 observations.
hard_q_id
The item ID of the hard question assigned to the student (16-30)
easy_q_id
The item ID of the easy question assigned to the student (1-15)
choose_hard_q
Selected either: Difficult Question (1) or Easy Question (0)
high_value
Range of values associated with Difficult Question that span from 12 to 16, repeated three times per subject
low_value
Range of values associated with Easy Question that span from 4 to 6, repeated five times per subject
is_correct_choice
Did the user select an item that was answered correctly?
Steven Andrew Culpepper and James Joseph Balamuta
Choice38 Experiment at UIUC during Spring 2014 - Fall 2014
Builds a model using MCMC
cIRT( subject_ids, fixed_effects, B_elem_plus1, rv_effects, trial_matrix, choices_nk, burnit, chain_length = 10000L )
cIRT( subject_ids, fixed_effects, B_elem_plus1, rv_effects, trial_matrix, choices_nk, burnit, chain_length = 10000L )
subject_ids |
A |
fixed_effects |
A |
B_elem_plus1 |
A |
rv_effects |
A |
trial_matrix |
A |
choices_nk |
A |
burnit |
An |
chain_length |
An |
A list
that contains:
as
A matrix
of dimension chain_length x J
bs
A matrix
of dimension chain_length x J
gs
A matrix
of dimension chain_length x P_1
Sigma_zeta_inv
An array
of dimension V x V x chain_length
betas
A matrix
of dimension chain_length x P_2
Steven Andrew Culpepper and James Joseph Balamuta
TwoPLChoicemcmc()
, probitHLM()
, center_matrix()
,
rmvnorm()
, rwishart()
, and riwishart()
## Not run: # Variables # Y = trial matix # C = KN vector of binary choices # N = #of subjects # J = # of items # K= # of choices # atrue = true item discriminations # btrue = true item locations # thetatrue = true thetas/latent performance # gamma = fixed effects coefficients # Sig = random-effects variance-covariance # subid = id variable for subjects # Load the Package library(cIRT) # Load the Data data(trial_matrix) data(choice_matrix) # Thurstone design matrices all_nopractice = subset(all_data_trials, experiment_loop.thisN > -1) 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)] # 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) # 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 ) }) 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) )))) inv_sd %*% S_thurstone %*% inv_sd apply(out_model_thurstone$as, 2, FUN = mean) apply(out_model_thurstone$bs, 2, FUN = mean) ## End(Not run)
## Not run: # Variables # Y = trial matix # C = KN vector of binary choices # N = #of subjects # J = # of items # K= # of choices # atrue = true item discriminations # btrue = true item locations # thetatrue = true thetas/latent performance # gamma = fixed effects coefficients # Sig = random-effects variance-covariance # subid = id variable for subjects # Load the Package library(cIRT) # Load the Data data(trial_matrix) data(choice_matrix) # Thurstone design matrices all_nopractice = subset(all_data_trials, experiment_loop.thisN > -1) 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)] # 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) # 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 ) }) 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) )))) inv_sd %*% S_thurstone %*% inv_sd apply(out_model_thurstone$as, 2, FUN = mean) apply(out_model_thurstone$bs, 2, FUN = mean) ## End(Not run)
Computes the direct sum of all matrices passed in via the list.
direct_sum(x)
direct_sum(x)
x |
A |
Consider matrix (
) and
(
). A direct sum is a diagonal matrix
with dimensions
.
Matrix containing the direct sum of all matrices in the list.
James Joseph Balamuta
x = list(matrix(0, nrow = 5, ncol = 3), matrix(1, nrow = 5, ncol = 3)) direct_sum(x) x = list(matrix(rnorm(15), nrow = 5, ncol = 3), matrix(rnorm(30), nrow = 5, ncol = 6), matrix(rnorm(18), nrow = 2, ncol = 9)) direct_sum(x)
x = list(matrix(0, nrow = 5, ncol = 3), matrix(1, nrow = 5, ncol = 3)) direct_sum(x) x = list(matrix(rnorm(15), nrow = 5, ncol = 3), matrix(rnorm(30), nrow = 5, ncol = 6), matrix(rnorm(18), nrow = 2, ncol = 9)) direct_sum(x)
Generates observed cognitive and choice data from the IRT-Thurstone model.
Generate_Choice( N, J, K, theta, as, bs, zeta, gamma, X, W, subject_ids, unique_subject_ids )
Generate_Choice( N, J, K, theta, as, bs, zeta, gamma, X, W, subject_ids, unique_subject_ids )
N |
An |
J |
An |
K |
An |
theta |
A |
as |
A |
bs |
A |
zeta |
A |
gamma |
A |
X |
A |
W |
A |
subject_ids |
A |
unique_subject_ids |
A |
A list
that contains:
Y
A matrix
of dimension N by J
C
A vector
of length NK
Steven Andrew Culpepper and James Joseph Balamuta
This data set contains the payout information for each subject.
payout_matrix
payout_matrix
A data frame with 252 observations on the following 4 variables.
Participant
Subject ID
cum_sum
Sum of all payouts
num_correct_choices
Total number of correct choices (out of 15)
num_correct_trials
Total number of correct trials (out of 30)
Steven Andrew Culpepper and James Joseph Balamuta
Choice38 Experiment at UIUC during Spring 2014 - Fall 2014
Performs modeling procedure for a Probit Hierarchical Level Model.
probitHLM( unique_subject_ids, subject_ids, choices_nk, fixed_effects_design, rv_effects_design, B_elem_plus1, gamma, beta, theta, zeta_rv, WtW, Z_c, Wzeta_0, inv_Sigma_gamma, mu_gamma, Sigma_zeta_inv, S0, mu_beta, sigma_beta_inv )
probitHLM( unique_subject_ids, subject_ids, choices_nk, fixed_effects_design, rv_effects_design, B_elem_plus1, gamma, beta, theta, zeta_rv, WtW, Z_c, Wzeta_0, inv_Sigma_gamma, mu_gamma, Sigma_zeta_inv, S0, mu_beta, sigma_beta_inv )
unique_subject_ids |
A |
subject_ids |
A |
choices_nk |
A |
fixed_effects_design |
A |
rv_effects_design |
A |
B_elem_plus1 |
A |
gamma |
A |
beta |
A |
theta |
A |
zeta_rv |
A |
WtW |
A |
Z_c |
A |
Wzeta_0 |
A |
inv_Sigma_gamma |
A |
mu_gamma |
A |
Sigma_zeta_inv |
A |
S0 |
A |
mu_beta |
A |
sigma_beta_inv |
A |
The function is implemented to decrease the amount of vectorizations necessary.
A list
that contains:
zeta_1
A vector
of length N
sigma_zeta_inv_1
A matrix
of dimensions V x V
gamma_1
A vector
of length P
beta_1
A vector
of length V
B
A matrix
of length V
Steven Andrew Culpepper and James Joseph Balamuta
rwishart()
and TwoPLChoicemcmc()
Creates a random inverse wishart distribution when given degrees of freedom and a sigma matrix.
riwishart(df, S)
riwishart(df, S)
df |
An |
S |
A |
A matrix
that is an inverse wishart distribution.
James Joseph Balamuta
rwishart()
and TwoPLChoicemcmc()
#Call with the following data: riwishart(3, diag(2))
#Call with the following data: riwishart(3, diag(2))
Creates a random Multivariate Normal when given number of obs, mean, and sigma.
rmvnorm(n, mu, S)
rmvnorm(n, mu, S)
n |
An |
mu |
A |
S |
A |
A matrix
that is a Multivariate Normal distribution.
James Joseph Balamuta
TwoPLChoicemcmc()
and probitHLM()
# Call with the following data: rmvnorm(2, c(0,0), diag(2))
# Call with the following data: rmvnorm(2, c(0,0), diag(2))
Creates a random wishart distribution when given degrees of freedom and a sigma matrix.
rwishart(df, S)
rwishart(df, S)
df |
An |
S |
A |
A matrix
that is a Wishart distribution, aka the sample covariance
matrix of a Multivariate Normal Distribution
James Joseph Balamuta
# Call with the following data: rwishart(3, diag(2)) # Validation set.seed(1337) S = toeplitz((10:1)/10) n = 10000 o = array(dim = c(10,10,n)) for(i in 1:n){ o[,,i] = rwishart(20, S) } mR = apply(o, 1:2, mean) Va = 20*(S^2 + tcrossprod(diag(S))) vR = apply(o, 1:2, var) stopifnot(all.equal(vR, Va, tolerance = 1/16))
# Call with the following data: rwishart(3, diag(2)) # Validation set.seed(1337) S = toeplitz((10:1)/10) n = 10000 o = array(dim = c(10,10,n)) for(i in 1:n){ o[,,i] = rwishart(20, S) } mR = apply(o, 1:2, mean) Va = 20*(S^2 + tcrossprod(diag(S))) vR = apply(o, 1:2, var) stopifnot(all.equal(vR, Va, tolerance = 1/16))
This data set contains the subject's responses survey questions administered using Choice38.
survey_data
survey_data
A data frame with 102 observations on the following 2 variables.
id
Subject's Assigned Research ID
sex
Subject's sex:
Male
Female
Steven Andrew Culpepper and James Joseph Balamuta
Choice38 Experiment at UIUC during Spring 2014 - Fall 2014
Internal function to -2LL
Total_Tabulate(N, J, Y)
Total_Tabulate(N, J, Y)
N |
An |
J |
An |
Y |
A N by J |
A vector of tabulated total scores.
Steven Andrew Culpepper
This data set contains the subject's responses to items. Correct answers are denoted by 1 and incorrect answers are denoted by 0.
trial_matrix
trial_matrix
A data frame with 252 observations on the following 30 variables.
t1
Subject's Response to Item 1.
t2
Subject's Response to Item 2.
t3
Subject's Response to Item 3.
t4
Subject's Response to Item 4.
t5
Subject's Response to Item 5.
t6
Subject's Response to Item 6.
t7
Subject's Response to Item 7.
t8
Subject's Response to Item 8.
t9
Subject's Response to Item 9.
t10
Subject's Response to Item 10.
t11
Subject's Response to Item 11.
t12
Subject's Response to Item 12.
t13
Subject's Response to Item 13.
t14
Subject's Response to Item 14.
t15
Subject's Response to Item 15.
t16
Subject's Response to Item 16.
t17
Subject's Response to Item 17.
t18
Subject's Response to Item 18.
t19
Subject's Response to Item 19.
t20
Subject's Response to Item 20.
t21
Subject's Response to Item 21.
t22
Subject's Response to Item 22.
t23
Subject's Response to Item 23.
t24
Subject's Response to Item 24.
t25
Subject's Response to Item 25.
t26
Subject's Response to Item 26.
t27
Subject's Response to Item 27.
t28
Subject's Response to Item 28.
t29
Subject's Response to Item 29.
t30
Subject's Response to Item 30.
Steven Andrew Culpepper and James Joseph Balamuta
Choice38 Experiment at UIUC during Spring 2014 - Fall 2014
Performs an MCMC routine for a two parameter IRT Model using Choice Data
TwoPLChoicemcmc( unique_subject_ids, subject_ids, choices_nk, fixed_effects, B, rv_effects_design, gamma, beta, zeta_rv, Sigma_zeta_inv, Y, theta0, a0, b0, mu_xi0, Sig_xi0 )
TwoPLChoicemcmc( unique_subject_ids, subject_ids, choices_nk, fixed_effects, B, rv_effects_design, gamma, beta, zeta_rv, Sigma_zeta_inv, Y, theta0, a0, b0, mu_xi0, Sig_xi0 )
unique_subject_ids |
A |
subject_ids |
A |
choices_nk |
A |
fixed_effects |
A |
B |
A |
rv_effects_design |
A |
gamma |
A |
beta |
A |
zeta_rv |
A |
Sigma_zeta_inv |
A |
Y |
A |
theta0 |
A |
a0 |
A |
b0 |
A |
mu_xi0 |
A |
Sig_xi0 |
A |
A list
that contains:
ai1
A vector
of length J
bi1
A vector
of length J
theta1
A vector
of length N
Z_c
A matrix
of length NK
Wzeta_0
A matrix
of length NK
Steven Andrew Culpepper and James Joseph Balamuta
cIRT()
, rmvnorm()
, and riwishart()
## Not run: # Call with the following data: TwoPLChoicemcmc(cogDAT, theta0, a0, b0, mu_xi0, Sig_xi0) ## End(Not run)
## Not run: # Call with the following data: TwoPLChoicemcmc(cogDAT, theta0, a0, b0, mu_xi0, Sig_xi0) ## End(Not run)