Estimate parameters with MCMC
a data.frame of length [n_person x n_block]
with at least three first variables:
variable person
of the format p
for person number p
,
variable block
of the format b
for block number b
,
variable resp
of the format r
for response number r
which corresponds to mupp::find_permutation_index().
a data.frame of length [total items]
with five variables:
variable item
of the format i
for item number i
,
variable block
of the format b
for block number b
,
variable dim
of the format d
for dimension number d
,
variable key
with -1 for negatively- and 1 for positively-keyed items.
a list of three parameters to control the MCMC algorithm:
n_iter
for the number of iterations,
n_burnin
for the number of burn-ins,
step_size_sd
for the step size of new parameter generation,
either one value for all 4 parameters,
or a vector of 4 values in the following order:
theta, gamma, lambda, psisq
a list of initial parameters to start the algorithm, each parameter needs to be a matrix named theta, gamma, lambda, or psisq.
a list of fixed parameters to be excluded from estimation, each parameter needs to be a matrix named theta, gamma, lambda, or psisq.
a list of fixed parameters for operational items, each parameter needs to be a matrix named gamma, lambda, or psisq.
a list of three objects if no operational items are provided:
all_iters
is a list of length [n_iter]
for parameter estimates for all iterations,
mean_mcmc
is a list of length 4 for mean of four parameters after burn-ins,
sd_mcmc
is a list of length 4 for SD of four parameters after burn-ins.
three additional objects are included if operational items are provided:
all_iters_test
includes all iterations for test items calibration,
mean_mcmc_test
includes parameter estimates for test items calibration,
sd_mcmc_test
includes parameter SD across iterations for test items calibration.
if (FALSE) {
set.seed(202108)
# designs
n_person <- 100
n_item <- 3
n_neg <- 1
n_block <- 2
n_dim <- 4
n_iter <- 1000
n_burnin <- 20
step_size_sd <- 0.1
# simulate parameters
params <- simulate_thirt_params(n_person = n_person,
n_item = n_item,
n_neg = n_neg,
n_block = n_block,
n_dim = n_dim)
resp <- do.call(simulate_thirt_resp, params)
gamma <- params$gamma$gamma
lambda <- params$items$lambda
psisq <- params$items$psisq
theta <- params$persons[, -1]
# operational parameters
op_gamma <- matrix(
# first pair 1-2 is fixed for each of 2 blocks
c(0.4, NA, NA,
-0.9, NA, NA)
)
op_lambda <- matrix(
# first 2 items are fixed for each of 2 blocks
c(-0.65, 0.55, NA,
0.57, -0.40, NA)
)
op_psisq <- matrix(
# first 2 items are fixed for each of 2 blocks
c(0.89, 0.72, NA,
0.02, 0.41, NA)
)
# estimation output
start_mcmc <- Sys.time()
output <- estimate_thirt_params_mcmc(resp = resp$resp,
items = resp$items,
control = list(n_iter = n_iter,
n_burnin = n_burnin,
step_size_sd = step_size_sd),
op_params = list(gamma = op_gamma,
lambda = op_lambda,
psisq = op_psisq)
)
end_mcmc <- Sys.time()
# correlate estimated and true parameters
diag(cor(theta, output$mean_mcmc$theta))
cor(gamma, output$mean_mcmc_test$gamma)
cor(lambda, output$mean_mcmc_test$lambda)
cor(psisq, output$mean_mcmc_test$psisq)
(time_mcmc <- end_mcmc - start_mcmc)
}