Skip to content

Commit b7b47c0

Browse files
4.2-121
1 parent a81fe32 commit b7b47c0

38 files changed

+725
-125
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: sirt
22
Type: Package
33
Title: Supplementary Item Response Theory Models
4-
Version: 4.2-114
5-
Date: 2025-04-07 15:44:35
4+
Version: 4.2-121
5+
Date: 2025-05-12 12:25:44
66
Author: Alexander Robitzsch [aut,cre] (<https://orcid.org/0000-0002-8226-3132>)
77
Maintainer: Alexander Robitzsch <robitzsch@ipn.uni-kiel.de>
88
Description:

R/RcppExports.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## File Name: RcppExports.R
2-
## File Version: 4.002114
2+
## File Version: 4.002121
33
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
44
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
55

@@ -399,12 +399,20 @@ sirt_rcpp_xxirt_compute_likelihood <- function(dat, dat_resp_bool, probs, TP, ma
399399
.Call('_sirt_sirt_rcpp_xxirt_compute_likelihood', PACKAGE='sirt', dat, dat_resp_bool, probs, TP, maxK)
400400
}
401401

402+
sirt_rcpp_xxirt_compute_likelihood_person_covariates <- function(dat, dat_resp_bool, probs, TP, maxK) {
403+
.Call('_sirt_sirt_rcpp_xxirt_compute_likelihood_person_covariates', PACKAGE='sirt', dat, dat_resp_bool, probs, TP, maxK)
404+
}
405+
406+
sirt_rcpp_xxirt_compute_loglike_case_theta_covariates <- function(dat, dat_resp_bool, logprobs, TP, maxK) {
407+
.Call('_sirt_sirt_rcpp_xxirt_compute_loglike_case_theta_covariates', PACKAGE='sirt', dat, dat_resp_bool, logprobs, TP, maxK)
408+
}
409+
402410
sirt_rcpp_xxirt_hessian_reduced_probs <- function(dat, dat_resp_bool, probs_ratio, TP, maxK, itemnr, itemnr2, use_itemnr2, p_xi_aj) {
403411
.Call('_sirt_sirt_rcpp_xxirt_hessian_reduced_probs', PACKAGE='sirt', dat, dat_resp_bool, probs_ratio, TP, maxK, itemnr, itemnr2, use_itemnr2, p_xi_aj)
404412
}
405413

406-
sirt_rcpp_xxirt_newton_raphson_derivative_par <- function(dat, dat_resp_bool, ratio, p_xi_aj, item, prior_Theta, group0, weights, ll_case0, eps) {
407-
.Call('_sirt_sirt_rcpp_xxirt_newton_raphson_derivative_par', PACKAGE='sirt', dat, dat_resp_bool, ratio, p_xi_aj, item, prior_Theta, group0, weights, ll_case0, eps)
414+
sirt_rcpp_xxirt_newton_raphson_derivative_par <- function(dat, dat_resp_bool, ratio, p_xi_aj, item, prior_Theta, group0, weights, ll_case0, eps, person_covariates, person_covariates_items) {
415+
.Call('_sirt_sirt_rcpp_xxirt_newton_raphson_derivative_par', PACKAGE='sirt', dat, dat_resp_bool, ratio, p_xi_aj, item, prior_Theta, group0, weights, ll_case0, eps, person_covariates, person_covariates_items)
408416
}
409417

410418
sirt_rcpp_xxirt_nr_pml_opt_fun <- function(prior_Theta, probs_items, freq1, freq2, W1, W2_long, G, K, I, TP, NI2, eps) {

R/mcmc_3pno_testlet_draw_itempars.R

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## File Name: mcmc_3pno_testlet_draw_itempars.R
2-
## File Version: 0.12
2+
## File Version: 0.137
33

44

55
#---- draw item parameters a and b
@@ -8,14 +8,18 @@ mcmc_3pno_testlet_draw_itempars <- function( theta, Z, I, N, weights,
88
{
99
# define adjusted Z values
1010
gamma.testletM <- gamma.testlet[, testletgroups ]
11-
if (param==1){ Z <- Z - gamma.testletM }
12-
if (param==3){ Z <- Z - a.testletM*gamma.testletM }
11+
if (param==1){
12+
Z <- Z - gamma.testletM
13+
}
14+
if (param==3){
15+
Z <- Z - a.testletM*gamma.testletM
16+
}
1317
if (param==2){ # Z <- Z
1418
theta0 <- theta
1519
Z0 <- Z
1620
}
1721
# for parametrization 2, this function must be rewritten
18-
# because "the theta" is now item specific
22+
# because 'the theta' is now item specific
1923
# loop over testlets tt=1,...,TT
2024
# maybe for TT+1 some adjustment has to be done
2125
#--- parametrization param=1
@@ -57,9 +61,10 @@ mcmc_3pno_testlet_draw_itempars <- function( theta, Z, I, N, weights,
5761
b <- rep(NA,I)
5862
TTT <- TT
5963
if ( sum( testletgroups==TT+1 ) > 0 ){
60-
TTT <- TT + 1 }
61-
for (tt in 1:TTT){
62-
#tt <- 1
64+
TTT <- TT + 1
65+
}
66+
for (tt in 1L:TTT){
67+
6368
theta <- theta0
6469
Z <- Z0
6570
ind.tt <- which( testletgroups==tt)
@@ -91,16 +96,16 @@ mcmc_3pno_testlet_draw_itempars <- function( theta, Z, I, N, weights,
9196
# compute t(Xast) %*% Z (weighted)
9297
mj <- Sigma %*% crossprod( Xast * weights, Z )
9398
mj <- as.matrix( t(mj))
94-
}
99+
}
95100
#--------------
96101
# draw item parameters
97102
ipars <- sirt_rmvnorm( Itt, sigma=Sigma ) + mj
98103
a[ind.tt] <- ipars[,1]
99104
b[ind.tt] <- ipars[,2]
100-
} # end testlet tt
101-
} # end param=2
105+
} # end testlet tt
106+
} # end param=2
102107
#-- output
103-
res <- list( "a"=a, "b"=b)
108+
res <- list( a=a, b=b)
104109
return(res)
105110
}
106111

R/mcmc_as_formula.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## File Name: mcmc_as_formula.R
2-
## File Version: 0.11
2+
## File Version: 0.121
33

44
mcmc_as_formula <- function( string )
55
{
6-
string <- paste0( string, collapse=" " )
7-
string <- gsub("___ ", "___", string, fixed=TRUE )
6+
string <- paste0( string, collapse=' ' )
7+
string <- gsub('___ ', '___', string, fixed=TRUE )
88
form <- stats::as.formula(string)
99
return(form)
1010
}

R/mcmc_confint.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## File Name: mcmc_confint.R
2-
## File Version: 0.11
2+
## File Version: 0.121
33

4-
###########################################
5-
# confidence interval
4+
5+
#*** confidence interval
66
mcmc_confint <- function( mcmcobj, parm, level=.95, exclude="deviance" )
77
{
88
mcmcobj <- mcmcobj[, ! ( colnames(mcmcobj) %in% exclude ) ]
@@ -14,9 +14,8 @@ mcmc_confint <- function( mcmcobj, parm, level=.95, exclude="deviance" )
1414
q2 <- 1 - ( 1 - level ) / 2
1515
h2 <- apply( mcmcobj, 2, stats::quantile, q2 )
1616
res <- data.frame( h1, h2)
17-
colnames(res)[1] <- paste0( round( 100*q1,1 ), " %")
18-
colnames(res)[2] <- paste0( round( 100*q2,1 ), " %")
17+
colnames(res)[1] <- paste0( round( 100*q1,1 ), ' %')
18+
colnames(res)[2] <- paste0( round( 100*q2,1 ), ' %')
1919
rownames(res) <- colnames(mcmcobj)
2020
return(res)
2121
}
22-
###############################################

R/mcmc_rename_define_symbols.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## File Name: mcmc_rename_define_symbols.R
2-
## File Version: 0.05
2+
## File Version: 0.061
33

44
mcmc_rename_define_symbols <- function()
55
{
6-
trans <- c("X", "Z", "M")
7-
orig <- c("[", "]", ",")
6+
trans <- c('X', 'Z', 'M')
7+
orig <- c('[', ']', ',')
88
res <- list(trans=trans, orig=orig)
99
return(res)
1010
}

R/xxirt.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## File Name: xxirt.R
2-
## File Version: 1.172
2+
## File Version: 1.188
33

44

55
#--- user specified item response model
@@ -62,7 +62,6 @@ xxirt <- function( dat, Theta=NULL, itemtype=NULL, customItems=NULL,
6262
item_index <- res$item_index
6363
dat <- as.matrix(dat)
6464

65-
6665
# create item list
6766
item_list <- xxirt_createItemList( customItems=customItems, itemtype=itemtype,
6867
items=items, partable=partable )
@@ -97,7 +96,6 @@ xxirt <- function( dat, Theta=NULL, itemtype=NULL, customItems=NULL,
9796
do_cv <- cv_kfold>0
9897
em_count <- 1
9998

100-
10199
while(em_iterate){
102100

103101
#--- create list with arguments for EM algorithm
@@ -250,6 +248,7 @@ xxirt <- function( dat, Theta=NULL, itemtype=NULL, customItems=NULL,
250248

251249
#--- output
252250
s2 <- Sys.time()
251+
time_diff <- s2-s1
253252
res <- list( partable=partable, par_items=par_items,
254253
par_items_summary=par_items_summary, par_items_bounds=par_items_bounds,
255254
par_Theta=par_Theta, Theta=Theta, probs_items=probs_items,
@@ -268,7 +267,7 @@ xxirt <- function( dat, Theta=NULL, itemtype=NULL, customItems=NULL,
268267
res_opt_nr=res_opt_nr, opt_values_nr=opt_values_nr, maxit_nr=maxit_nr,
269268
iter=iter-1, iter_em=iter_em-1, iter_nr=iter_nr,
270269
estimator=estimator, pml_args=pml_args, em_args=em_args,
271-
CALL=CALL, s1=s1, s2=s2 )
270+
CALL=CALL, s1=s1, s2=s2, time_diff=time_diff )
272271
class(res) <- 'xxirt'
273272
return(res)
274273
}

R/xxirt_compute_casewise_likelihood.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
## File Name: xxirt_compute_casewise_likelihood.R
2-
## File Version: 0.01
2+
## File Version: 0.085
33

4-
xxirt_compute_casewise_likelihood <- function(prior_Theta, group, p.xi.aj)
4+
xxirt_compute_casewise_likelihood <- function(prior_Theta, group, p.xi.aj,
5+
customTheta=NULL)
56
{
6-
prior1 <- t( prior_Theta[, group ] )
7+
if (is.null(customTheta)){
8+
customTheta <- list(person_covariates=FALSE)
9+
}
10+
if (customTheta$person_covariates){
11+
prior1 <- t( prior_Theta )
12+
} else {
13+
prior1 <- t( prior_Theta[, group ] )
14+
}
715
p.aj.xi <- prior1 * p.xi.aj
816
ll_case <- rowSums(p.aj.xi)
917
return(ll_case)

R/xxirt_compute_itemprobs.R

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
## File Name: xxirt_compute_itemprobs.R
2-
## File Version: 0.215
2+
## File Version: 0.226
33

44

55
# compute item probabilities
66
xxirt_compute_itemprobs <- function( item_list, items, Theta, ncat,
77
partable, partable_index, item_index=NULL )
88
{
9+
person_covariates <- attr(partable, 'person_covariates')
910
TP <- nrow(Theta)
1011
maxK <- max(ncat)
1112
if ( is.null(item_index) ){
@@ -14,16 +15,29 @@ xxirt_compute_itemprobs <- function( item_list, items, Theta, ncat,
1415
}
1516
I <- length(item_index)
1617
# compute item probabilities as a function of theta
17-
probs <- array( 0, dim=c(I,maxK,TP) )
18+
if (person_covariates){
19+
N <- nrow( (item_list[[1]])$X )
20+
dim_probs <- c(I,maxK,TP,N)
21+
} else {
22+
dim_probs <- c(I,maxK,TP)
23+
}
24+
probs <- array( 0, dim=dim_probs )
1825
for (jj in 1L:I){
1926
ii <- item_index[jj]
2027
item_ii <- item_list[[ii]]
2128
par_ii <- partable[ partable_index[[ii]], 'value' ]
2229
ncat_ii <- ncat[ii]
2330
arg_ii <- list( par=par_ii, Theta=Theta, ncat=ncat_ii )
24-
probs_ii <- do.call( item_ii$P, arg_ii )
25-
probs[ jj, 1L:ncat_ii,] <- t(probs_ii)
26-
}
31+
if (person_covariates){
32+
arg_ii$X <- item_ii$X
33+
}
34+
probs_ii <- do.call( what=item_ii$P, args=arg_ii )
35+
if (!person_covariates){
36+
probs[ jj, 1L:ncat_ii,] <- t(probs_ii)
37+
} else {
38+
probs[jj,,,] <- aperm(probs_ii, perm=c(2,1,3) )
39+
}
40+
} # end jj
2741
return(probs)
2842
}
2943

R/xxirt_compute_likelihood.R

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
## File Name: xxirt_compute_likelihood.R
2-
## File Version: 0.271
2+
## File Version: 0.290
33

44

55
##-- xxirt compute likelihood
66
xxirt_compute_likelihood <- function( probs_items, dat, resp_index=NULL,
7-
dat_resp_bool=NULL )
7+
dat_resp_bool=NULL, person_covariates_items=FALSE )
88
{
99
N <- nrow(dat)
1010
TP <- dim(probs_items)[3]
1111
I <- dim(probs_items)[1]
1212
maxK <- dim(probs_items)[2]
13-
p.xi.aj <- matrix( 1, nrow=N, ncol=TP )
14-
probs <- matrix( probs_items, nrow=I, ncol=maxK*TP )
15-
p.xi.aj <- sirt_rcpp_xxirt_compute_likelihood( dat=dat, dat_resp_bool=dat_resp_bool,
16-
probs=probs, TP=TP, maxK=maxK )
13+
# p.xi.aj <- matrix( 1, nrow=N, ncol=TP )
14+
if (!person_covariates_items){
15+
probs <- matrix( probs_items, nrow=I, ncol=maxK*TP )
16+
p.xi.aj <- sirt_rcpp_xxirt_compute_likelihood( dat=dat,
17+
dat_resp_bool=dat_resp_bool,
18+
probs=probs, TP=TP, maxK=maxK )
19+
} else {
20+
probs <- as.vector( probs_items )
21+
p.xi.aj <- sirt_rcpp_xxirt_compute_likelihood_person_covariates( dat=dat,
22+
dat_resp_bool=dat_resp_bool, probs=probs, TP=TP, maxK=maxK )
23+
}
24+
#-- output
1725
return(p.xi.aj)
1826
}
1927

0 commit comments

Comments
 (0)