Skip to content

Commit 8fb1529

Browse files
author
Wenchao-Ma
committed
Bug fixed - v.1.0.0
1 parent 7deffec commit 8fb1529

File tree

5 files changed

+125
-27
lines changed

5 files changed

+125
-27
lines changed

DESCRIPTION

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
Package: GDINA
22
Type: Package
33
Title: The Generalized DINA Model Framework
4-
Version: 1.0.0
5-
Date: 2016-12-12
4+
Version: 1.1.0
5+
Date: 2017-1-2
66
Authors@R: c(person(given = "Wenchao",family = "Ma", role = c("aut", "cre"),email = "wenchao.ma@rutgers.edu"),person(given = "Jimmy", family = "de la Torre", role = "aut"))
7-
Description: A set of psychometric tools for cognitive diagnostic analyses for both dichotomous and polytomous responses. Various cognitive diagnosis models (CDMs) can be estimated, include the generalized deterministic inputs, noisy and gate (G-DINA) model by de la Torre (2011) <DOI:10.1007/s11336-011-9207-7>, the sequential G-DINA model by Ma and de la Torre (2016)<DOI:10.1111/bmsp.12070>, and many other models they subsume. Joint attribute distribution can be saturated, higher-order or structured. Q-matrix validation, item and model fit statistics, model comparison at test and item level and differential item functioning can also be conducted. A graphical user interface is also provided.
7+
Description: A set of psychometric tools for cognitive diagnostic analyses for
8+
both dichotomous and polytomous responses. Various cognitive diagnosis models
9+
(CDMs) can be estimated, include the generalized deterministic inputs, noisy
10+
and gate (G-DINA) model by de la Torre (2011) <DOI:10.1007/s11336-011-9207-7>,
11+
the sequential G-DINA model by Ma and de la Torre (2016)<DOI:10.1111/bmsp.
12+
12070>, and many other models they subsume. Joint attribute distribution can
13+
be saturated, higher-order or structured. Q-matrix validation, item and model
14+
fit statistics, model comparison at test and item level and differential item
15+
functioning can also be conducted. A graphical user interface is also provided.
816
License: GPL-3
917
LazyData: TRUE
1018
Depends:
1119
R (>= 3.1.0)
1220
Imports:
13-
stats, graphics, utils, Rcpp (>= 0.12.1), nloptr, MASS, numDeriv, alabama, Rsolnp, ggplot2, shiny, shinydashboard
21+
stats,
22+
graphics,
23+
utils,
24+
Rcpp (>= 0.12.1),
25+
nloptr,
26+
MASS,
27+
numDeriv,
28+
alabama,
29+
Rsolnp,
30+
ggplot2,
31+
shiny,
32+
shinydashboard,
33+
data.table
1434
Suggests:
1535
testthat
1636
LinkingTo: Rcpp, RcppArmadillo
@@ -57,6 +77,7 @@ Collate:
5777
'plotIRF.GDINA.R'
5878
'plotPVAF.Qval.R'
5979
'print.GDINA.R'
80+
'rowCount.R'
6081
's3GDINA.R'
6182
'sim10GDINA.R'
6283
'sim20seqGDINA.R'

R/personparm.GDINA.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ personparm.GDINA <- function(object,
6464
}
6565
colnames(out)[1:K] <- paste("A",1:K,sep = "")
6666
}else if(what=="MLE"){
67-
if(max(Q) > 1) stop("Please use EAP.att for polytomous attributes.", call. = FALSE)
68-
out <- data.frame(MLE=pattern[max.col(extract.GDINA(object,what = "logposterior.i")),],
69-
multimodes=as.logical(rowSums(extract.GDINA(object,what = "logposterior.i")==apply(extract.GDINA(object,what = "logposterior.i"),1,max))-1))
67+
if(max(Q) > 1) stop("Please use EAP for polytomous attributes.", call. = FALSE)
68+
out <- data.frame(MLE=pattern[max.col(extract.GDINA(object,what = "loglikelihood.i")),],
69+
multimodes=as.logical(rowSums(extract.GDINA(object,what = "loglikelihood.i")==apply(extract.GDINA(object,what = "loglikelihood.i"),1,max))-1))
7070
colnames(out)[1:K] <- paste("A",1:K,sep = "")
7171
}else if(what=="MAP"){
72-
if(max(Q) > 1) stop("Please use EAP.att for polytomous attributes.", call. = FALSE)
72+
if(max(Q) > 1) stop("Please use EAP for polytomous attributes.", call. = FALSE)
7373
out <- data.frame(MAP=pattern[max.col(extract.GDINA(object,what = "logposterior.i")),],
7474
multimodes=as.logical(rowSums(extract.GDINA(object,what = "logposterior.i")==apply(extract.GDINA(object,what = "logposterior.i"),1,max))-1))
7575
colnames(out)[1:K] <- paste("A",1:K,sep = "")

R/print.GDINA.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ print.GDINA <-
55
{
66
cat("\nThe Generalized DINA Model Framework \n")
77
packageinfo <- utils::packageDescription("GDINA")
8-
cat( paste( " Beta Version " , packageinfo$Version , " (" , packageinfo$Date , ")" , sep="") , "\n" )
8+
cat( paste( " Version " , packageinfo$Version , " (" , packageinfo$Date , ")" , sep="") , "\n" )
99
cat("\nCall:\n", paste(deparse(extract.GDINA(x,"call")), sep = "\n", collapse = "\n"),
1010
"\n", sep = "")
1111
cat("\nNumber of items =", extract.GDINA(x,"nitem"), "\n")

R/rowCount.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#' Count and label unique rows in data frame
2+
#'
3+
#' @param df a data frame or matrix
4+
#'
5+
#' @return freq the number of rows
6+
#' @return group the data frame with a column named row.no giving unique labels for all unique rows
7+
#' @export
8+
#' @import data.table
9+
#' @examples
10+
#'
11+
#' df <- data.frame(V1=c(1L,2L),V2=LETTERS[1:3],V3=rep(1,12))
12+
#' rowCount(df)
13+
#'
14+
#'
15+
#'
16+
rowCount <- function(df){
17+
DT <- data.table(df)
18+
varb <- colnames(DT)
19+
freq <- DT[,.N,by=c(varb)]
20+
DT$gr <- as.numeric(factor(apply(DT,1,paste0,collapse="")))
21+
return(list(freq=data.frame(freq),group=data.frame(DT)))
22+
}
23+
24+
#' Count the frequency of a row vector in a data frame
25+
#'
26+
#' @param df a data frame or matrix
27+
#'
28+
#' @return count the number of vector vec in the data frame
29+
#' @return row.no row numbers of the vector vec in the data frame
30+
#' @export
31+
#'
32+
#' @examples
33+
#'
34+
#' df <- data.frame(V1=c(1L,2L),V2=LETTERS[1:3],V3=rep(1,12))
35+
#' rowMatch(df,c(2,"B",1))
36+
#'
37+
#'
38+
#'
39+
rowMatch <- function(df,vec=NULL){
40+
logicalvec <- apply(df,1,paste0,collapse="")==paste0(vec,collapse = "")
41+
return(list(count=sum(logicalvec),row.no=which(logicalvec)))
42+
}

R/utils.R

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -495,24 +495,6 @@ seq_coding <- function(dat,Q){
495495
return(out)
496496
}
497497

498-
Rmatrix.att <- function(K){
499-
R <- vector("list",K)
500-
Lk <- 2^K
501-
if (K<=1) return(warning("K must be 2 or more!"))
502-
# gives which groups should be set to equal
503-
pattK <- alpha(K)
504-
pattK_1 <- alpha(K-1)
505-
for(a in 1:K){
506-
Rk <- matrix(0,Lk/2,Lk)
507-
for (l in 1:nrow(pattK_1)){
508-
loc <- which(apply(pattK[,-a,drop=FALSE],1,function(x){all(x==pattK_1[l,])}))
509-
Rk[l,loc[1]] <- 1
510-
Rk[l,loc[2]] <- -1
511-
}
512-
R[[a]] <- Rk
513-
}
514-
return(R)
515-
}
516498

517499

518500
bdiag <- function(mlist,fill=0){
@@ -634,3 +616,56 @@ scorefunc <- function(object,...){
634616
list(score = scof$score, index = index)
635617
}
636618

619+
Rmatrix.vec <- function(K){
620+
patt <- alpha(K)
621+
eta <- eta.loc(patt[-c(1,nrow(patt)),])
622+
Rv <- vector("list",nrow(eta))
623+
for (r in 1:nrow(eta)){
624+
for(lc in seq_len(max(eta[r,]))){
625+
loc <- which(eta[r,]==lc)
626+
tmp <- matrix(0,length(loc)-1,2^K)
627+
tmp[,loc[1]] <- 1
628+
tmp[cbind(seq_len(length(loc)-1),loc[-1])] <- -1
629+
Rv[[r]] <- rbind(Rv[[r]],tmp)
630+
}
631+
}
632+
return(Rv)
633+
}
634+
635+
636+
Rmatrix.att <- function(K){
637+
R <- vector("list",K)
638+
Lk <- 2^K
639+
if (K<=1) return(warning("K must be 2 or more!"))
640+
# gives which groups should be set to equal
641+
pattK <- alpha(K)
642+
pattK_1 <- alpha(K-1)
643+
for(a in 1:K){
644+
Rk <- matrix(0,Lk/2,Lk)
645+
for (l in 1:nrow(pattK_1)){
646+
loc <- which(apply(pattK[,-a,drop=FALSE],1,function(x){all(x==pattK_1[l,])}))
647+
Rk[l,loc[1]] <- 1
648+
Rk[l,loc[2]] <- -1
649+
}
650+
R[[a]] <- Rk
651+
}
652+
return(R)
653+
654+
655+
}
656+
657+
658+
valQrate <- function(trueQ,misQ,valQ){
659+
Qs <- data.frame(trueQ=c(as.matrix(trueQ)),misQ=c(as.matrix(misQ)),valQ=c(as.matrix(valQ)))
660+
CR <- data.frame(true2mis=
661+
apply(matrix(c(0,0,
662+
1,1,
663+
0,1,
664+
1,0),ncol = 2,byrow = TRUE),1,function(x)rowMatch(Qs[,-3],x)$count),
665+
mis2val=apply(matrix(c(0,0,0,
666+
1,1,1,
667+
0,1,0,
668+
1,0,1),ncol = 3,byrow = TRUE),1,function(x)rowMatch(Qs,x)$count),
669+
row.names = c("000/00","111/11","010/01","101/10"))
670+
return(CR)
671+
}

0 commit comments

Comments
 (0)