Skip to content

Commit

Permalink
3.7-13
Browse files Browse the repository at this point in the history
  • Loading branch information
Robitzsch committed Jun 23, 2021
1 parent dd5d8bd commit f6b720c
Show file tree
Hide file tree
Showing 27 changed files with 235 additions and 75 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: TAM
Type: Package
Title: Test Analysis Modules
Version: 3.7-5
Date: 2021-05-16 13:48:06
Version: 3.7-13
Date: 2021-06-23 14:35:26
Author:
Alexander Robitzsch [aut,cre] (<https://orcid.org/0000-0002-8226-3132>),
Thomas Kiefer [aut],
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export(plotDevianceTAM)
export(require_namespace_msg)
export(Scale)
export(tam)
export(tam.cb)
export(tam.ctt)
export(tam.ctt2)
export(tam.ctt3)
Expand Down
2 changes: 1 addition & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## File Name: RcppExports.R
## File Version: 3.007005
## File Version: 3.007013
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

Expand Down
21 changes: 17 additions & 4 deletions R/designMatrices.mfr2.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## File Name: designMatrices.mfr2.R
## File Version: 9.448
## File Version: 9.480


##*** create design matrices
Expand Down Expand Up @@ -69,9 +69,12 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,

# A Matrix
if( is.null(A) ){
AX <- tam_A_matrix2( resp=resp, formulaA=formulaA, facets=facets,
#AX <- tam_A_matrix2( resp=resp, formulaA=formulaA, facets=facets,
# constraint=constraint, progress=progress, Q=Q)
AX <- .A.matrix2( resp=resp, formulaA=formulaA, facets=facets,
constraint=constraint, progress=progress, Q=Q)
A <- AX$A

X <- AX$X
otherFacets <- AX$otherFacets
xsi.elim <- AX$xsi.elim
Expand Down Expand Up @@ -176,7 +179,6 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,
colnames(gresp) <- rownames(X)
# X$empty <- 1* (colSums( gresp, na.rm=TRUE )==0)
X$empty <- tam_rcpp_mml_mfr_colsums_gresp( gresp )

colnames(gresp.noStep) <- rownames(X.noStep)
# X.noStep$empty <- 1* (colSums( gresp.noStep, na.rm=TRUE )==0)
X.noStep$empty <- tam_rcpp_mml_mfr_colsums_gresp( gresp.noStep)
Expand Down Expand Up @@ -213,6 +215,11 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,
str.ss2 <- gsub( paste0("(^|-)+",str.ss), "", rownames(x)[iss] )
ind_str_ss2 <- intersect( str.ss2, dimnames(x2)[[2]] )
x2[ss+1,ind_str_ss2,] <- x[ iss, ]

# version 3.4
# iss <- grep( paste0(str.ss,"+(-|$)"), rownames(x) )#, fixed=TRUE )
# str.ss2 <- gsub( paste0("(^|-)+",str.ss), "", rownames(x)[iss] )
# x2[ss+1,str.ss2,] <- x[ iss, ]
}
x2 <- aperm( x2, c(2,1,3) )

Expand Down Expand Up @@ -275,18 +282,21 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,
}
# cat(".....\nbefore rename A" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
# print("g100")
A <- .rename.items( matr=A, itemren )

A <- .rename.items( matr=A, itemren )
dimnames(A)[[1]] <- .rename.items2aa( vec=dimnames(A)[[1]],
facet.list=facet.list, I=I )

# cat(".rename.items (A)" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
xsi.table <- xsi.constr$xsi.table
# A <- .rename.items3( matr=A, facet.list, I )
#cat(".rename.items3 (A)" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1

A <- .rename.items3a( matr=A, facet.list, I, cols=TRUE, xsi.table )

#cat(".rename.items3a (A)" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
B <- .rename.items( matr=B, itemren )

# cat(".rename.items (B)" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
dimnames(B)[[1]] <- dimnames(A)[[1]]
# B <- .rename.items3( matr=B, facet.list )
Expand All @@ -307,6 +317,7 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,
# Q <- .rename.items3( matr=Q, facet.list, cols=FALSE)
X <- .rename.items( matr=X, itemren, cols=FALSE)
dimnames(X)[[1]] <- dimnames(A)[[1]]

# X <- .rename.items3( matr=X, facet.list, cols=FALSE)
# cat(".rename.items (Q,X)" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
X.noStep <- .rename.items( matr=X.noStep, itemren, cols=FALSE)
Expand All @@ -319,6 +330,7 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,
#cat(".rename.items2a (G1$parameter) " ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
G1$parameter <- .rename.items2b( paste( G1$parameter), facet.list, I, xsi.table )
xsi.constr$xsi.table <- G1

# cat(".rename.items2b (G1$parameter) " ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
#***
G1 <- xsi.constr$xsi.constraints
Expand Down Expand Up @@ -347,6 +359,7 @@ designMatrices.mfr2 <- function( resp, formulaA=~ item + item:step, facets=NULL,
# B
B.flat.0 <- B.flat <- B; B.flat.0[ind,] <- 0
B.3d <- .generateB.3d( B.flat )

B.flat <- B.flat[!ind,]
B.3d.0 <- .generateB.3d( B.flat.0 )
if(!is.null(B.store.in)) B.3d.0[] <- B.store.in
Expand Down
64 changes: 33 additions & 31 deletions R/designMatrices_aux2.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## File Name: designMatrices_aux2.R
## File Version: 9.167
## File Version: 9.201


## function tam_A_matrix2
###########################################################
## function .A.matrix
.A.matrix2 <- function( resp, formulaA=~ item + item*step, facets=NULL,
constraint=c("cases", "items"), progress=FALSE,
maxKi=NULL, Q=Q )
Expand All @@ -25,7 +26,6 @@
}
}
#cat(" +++ v62" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1

### Basic Information and Initializations
constraint <- match.arg(constraint)
if ( is.null(maxKi) ){
Expand Down Expand Up @@ -70,9 +70,10 @@
expand.list[[vv]] <- paste( expand.list[[vv]] )
}


# cat(" +++ v110" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
g2 <- g1 <- expand.grid(expand.list)
diffK <- ( stats::sd( maxKi) > 1e-10 )
diffK <- ( stats::sd( maxKi) > 0 )
# diffK <- FALSE
diffK <- TRUE
# reduced combinations of items
Expand Down Expand Up @@ -137,8 +138,8 @@
}

A <- NULL
stepgroups <- unique( gsub( "(^|-)+step([[:digit:]])*", "\\1step([[:digit:]])*",
x=rownames(X), perl=TRUE ) )

stepgroups <- unique( gsub( "(^|-)+step([[:digit:]])*", "\\1step([[:digit:]])*", rownames(X) ) )
X.out <- data.frame(as.matrix(X), stringsAsFactors=FALSE)
#cat(" +++ v150" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
if (progress){
Expand All @@ -155,21 +156,23 @@
}
}
#******


# collect xsi parameters to be excluded
xsi.elim.index <- xsi.elim <- NULL
ii <- 0 ; vv <- 1
for( sg in stepgroups ){
mm1 <- grep(paste0("(", sg, ")+$"), rownames(mm))
ind2 <- grep( paste0("(", sg, ")+$"), rownames(mm))
mm.sg.temp <- rbind( 0, apply( mm[ ind2,,drop=FALSE], 2, cumsum ) )
if ( is.null(rownames(mm.sg.temp)) ){
rownames(mm.sg.temp) <- paste0("rn", seq(0,nrow(mm.sg.temp)-1) )
}
for( sg in stepgroups ){
# sg <- stepgroups[2]
# mm1 <- mm[ grep(sg, rownames(mm)),]
mm1 <- grep(paste0("(", sg, ")+$"), rownames(mm))
# ind2 <- grep(sg, rownames(mm))
ind2 <- grep( paste0("(", sg, ")+$"), rownames(mm))
# if (length(ind2)>0){
mm.sg.temp <- rbind( 0, apply( mm[ ind2,,drop=FALSE], 2, cumsum ) )
# }
if ( is.null(rownames(mm.sg.temp)) ){
rownames(mm.sg.temp) <- paste0("rn", seq(0,nrow(mm.sg.temp)-1) )
}
# substitute the following line later if ...
rownames(mm.sg.temp)[1] <- gsub("step([[:digit:]])*", "step0", sg, fixed=TRUE)
# rownames(mm.sg.temp)[1] <- gsub("step([[:digit:]])*", "step0", sg, fixed=FALSE, perl=TRUE)
rownames(mm.sg.temp)[1] <- gsub("step([[:digit:]])*", "step0", sg, fixed=T)
rownames(mm.sg.temp)[-1] <- rownames(mm[ind2,,drop=FALSE])
#****
# set entries to zero if there are no categories in data
Expand Down Expand Up @@ -255,10 +258,7 @@
facet.design <- list( "facets"=facets, "facets.orig"=facets0,
"facet.list"=facet.list[otherFacets])
A <- A[ ! duplicated( rownames(A) ), ]

if ( max(apply(resp,2,max,na.rm=TRUE)) > 9 ){
A <- A[order(rownames(A)),,drop=FALSE]
}
A <- A[order(rownames(A)),,drop=FALSE]
X.out <- X.out[order(rownames(X.out)),,drop=FALSE]


Expand All @@ -269,30 +269,32 @@
xsi.elim <- data.frame( xsi.elim, xsi.elim.index )
xsi.elim <- xsi.elim[ ! duplicated( xsi.elim[,2] ), ]
xsi.elim <- xsi.elim[ order( xsi.elim[,2] ), ]
}
# A <- A[,-xsi.elim[,2] ]
}


#--- clean xsi.constr
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ARb 2015-10-16
#@@@@ clean xsi.constr
xsi1 <- xsi.constr$xsi.constraints
xsi.constr$intercept_included <- FALSE
ind <- grep("(Intercept", rownames(xsi1), fixed=TRUE)
if ( length(ind) > 0 ){
xsi1 <- xsi1[ - ind, ]
xsi.constr$xsi.constraints <- xsi1
xsi.constr$intercept_included <- TRUE
}
}
xsi1 <- xsi.constr$xsi.table
ind <- grep("(Intercept", paste(xsi1$parameter), fixed=TRUE)
if ( length(ind) > 0 ){
xsi1 <- xsi1[ - ind, ]
xsi.constr$xsi.table <- xsi1
}
}
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#cat(" +++ out .A.matrix" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1
res <- list( "A"=A, "X"=X.out, "otherFacets"=otherFacets, "xsi.constr"=xsi.constr,
"facet.design"=facet.design, "xsi.elim"=xsi.elim )
return(res)
return(list( "A"=A, "X"=X.out, "otherFacets"=otherFacets, "xsi.constr"=xsi.constr,
"facet.design"=facet.design, "xsi.elim"=xsi.elim ) )
}
## end .A.matrix
#####################################################



.A.matrix2 -> tam_A_matrix2
119 changes: 119 additions & 0 deletions R/tam.cb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
## File Name: tam.cb.R
## File Version: 0.16



tam.cb <- function( dat, wlescore=NULL, group=NULL, max_ncat=30, progress=TRUE,
pweights=NULL, digits_freq=5)
{
resp <- dat
wgt <- pweights
if (is.null(wgt)){
wgt <- rep(1,nrow(resp))
}
I <- ncol(resp)
if ( is.null(wlescore) ){
est_wle <- 0
wlescore <- rep(1, nrow(resp) )
} else {
est_wle <- 1
}

resp0 <- resp
wlescore0 <- wlescore

# define progress bar
if ( is.null(group) ){
group <- rep(1, nrow(resp) )
}
groups <- sort( unique( group ) )
G <- length(groups)
I <- ncol(resp)
dfr <- NULL
for (gg in 1:G){
ind.gg <- which( group==groups[gg] )
resp <- resp0[ ind.gg, ]
wlescore <- wlescore0[ ind.gg ]
wgt1 <- wgt[ind.gg]
prg <- round( seq( 1, I, len=10 ) )
prg[ prg==I ] <- I-1
if (progress){
cat("|")
cat( paste( rep("*", 10 ), collapse="") )
cat("| Group", groups[gg], "\n|")
prg <- round( seq( 1, I, len=10 ) )
prg[ prg==I ] <- I-1
}

if ( ! progress ){
prg <- 1
}

dfr.gg <- data.frame( "group"=groups[gg], "groupindex"=gg,
"itemno"=1:I, "item"=colnames(resp0))
nar <- is.na(resp)
dfr.gg$N <- colSums(1-nar)
dfr.gg$W <- colSums(wgt1*(1-nar))
dfr.gg$miss_prop <- colSums(wgt1*nar)/sum(wgt1)
dfr.gg$is_numeric <- 0
dfr.gg$M <- NA
dfr.gg$kurtosis <- dfr.gg$skewness <- dfr.gg$SD <- NA
dfr.gg$Min <- NA
dfr.gg$Max <- NA
dfr.gg$N_unique_val <- NA
dfr.gg$freq <- ""
if (est_wle){
dfr.gg$r.WLE <- NA
}

resp1 <- data.matrix(frame=resp)
for (ii in 1:I){
v1 <- resp[,ii]
v2 <- paste(v1)
v3 <- suppressWarnings(as.numeric(v2))
is_num <- FALSE
if ( mean(is.na(v3))<1 ){
v2 <- v3
is_num <- TRUE
dfr.gg$is_numeric[ii] <- 1
}
if ( is_num ){
dfr.gg$M[ii] <- weighted_mean(x=v3, w=wgt1)
dfr.gg$SD[ii] <- weighted_sd(x=v3, w=wgt1)
dfr.gg$skewness[ii] <- weighted_skewness(x=v3, w=wgt1)
dfr.gg$kurtosis[ii] <- weighted_kurtosis(x=v3, w=wgt1)
dfr.gg$Min[ii] <- min(v2, na.rm=TRUE)
dfr.gg$Max[ii] <- max(v2, na.rm=TRUE)
if (est_wle){
x2 <- data.frame( v3, wlescore )
ind <- which(rowSums(is.na(x2))==0)
c1 <- stats::cov.wt(x2[ind,], wt=wgt1[ind], method="ML")$cov
eps <- 1e-15
diag(c1) <- diag(c1) + eps
dfr.gg$r.WLE[ii] <- stats::cov2cor(c1)[1,2]
}
}
l1 <- length(setdiff(unique(v1),NA))
dfr.gg$N_unique_val[ii] <- l1
if (l1 < max_ncat){
wt <- weighted_table(v2, w=wgt1)
wt <- wt / sum(wt)
dfr.gg$freq[ii] <- paste0( " ", paste0( paste0( names(wt), " : ", round(wt,digits_freq)),
collapse=" # " ) )
}
if ( ii %in% prg){
cat("-")
utils::flush.console()
}

}
dfr <- rbind( dfr, dfr.gg )
if (progress){
cat("|\n")
}
} # end group
dfr <- dfr[ order( paste0( 10000+ dfr$itemno, dfr$group ) ), ]
dfr <- data.frame( "index"=seq(1,nrow(dfr) ), dfr )
return(dfr)
}

4 changes: 2 additions & 2 deletions R/tam.mml.2pl.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## File Name: tam.mml.2pl.R
## File Version: 9.588
## File Version: 9.589

tam.mml.2pl <- function( resp, Y=NULL, group=NULL, irtmodel="2PL",
formulaY=NULL, dataY=NULL,
Expand Down Expand Up @@ -338,7 +338,7 @@ tam.mml.2pl <- function( resp, Y=NULL, group=NULL, irtmodel="2PL",
# cat("m step regression") ; a1 <- Sys.time(); print(a1-a0) ; a0 <- a1

beta <- resr$beta
variance <- resr$variance
variance <- resr$variance
itemwt <- resr$itemwt
variance_acceleration <- resr$variance_acceleration
variance_change <- resr$variance_change
Expand Down
4 changes: 2 additions & 2 deletions R/tam.mml.3pl.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## File Name: tam.mml.3pl.R
## File Version: 9.878
## File Version: 9.879

tam.mml.3pl <- function( resp, Y=NULL, group=NULL,
formulaY=NULL, dataY=NULL,
Expand Down Expand Up @@ -720,7 +720,7 @@ tam.mml.3pl <- function( resp, Y=NULL, group=NULL,

#*** include NAs in AXsi
AXsi <- tam_mml_include_NA_AXsi(AXsi=AXsi, maxcat=maxcat, A=A, xsi=xsi)

#**** standard errors AXsi
se.AXsi <- tam_mml_se_AXsi( AXsi=AXsi, A=A, se.xsi=se.xsi, maxK=maxK )

Expand Down
Loading

0 comments on commit f6b720c

Please sign in to comment.