# NOT RUN {
#############################################################################
# EXAMPLE 1: Model fit for sim.dina
#############################################################################
data(sim.dina, package="CDM")
data(sim.qmatrix, package="CDM")
dat <- sim.dina
q.matrix <- sim.qmatrix
#*** Model 1: DINA model for DINA simulated data
mod1 <- CDM::din(dat, q.matrix=q.matrix, rule="DINA" )
fmod1 <- CDM::modelfit.cor.din(mod1, jkunits=10)
summary(fmod1)
## Test of Global Model Fit
## type value p
## 1 max(X2) 8.728 0.113
## 2 abs(fcor) 0.143 0.080
##
## Fit Statistics
## est jkunits jk_est jk_se est_low est_upp
## MADcor 0.030 10 0.020 0.005 0.010 0.030
## SRMSR 0.040 10 0.023 0.006 0.011 0.035
## 100*MADRESIDCOV 0.671 10 0.445 0.125 0.200 0.690
## MADQ3 0.062 10 0.037 0.008 0.021 0.052
## MADaQ3 0.059 10 0.034 0.008 0.019 0.050
# look at first five item pairs with highest degree of local dependence
itempairs <- fmod1$itempairs
itempairs <- itempairs[ order( itempairs$X2, decreasing=TRUE ), ]
itempairs[ 1:5, c("item1","item2", "X2", "X2_p", "X2_p.holm", "Q3") ]
## item1 item2 X2 X2_p X2_p.holm Q3
## 29 Item5 Item8 8.728248 0.003133174 0.1127943 -0.26616414
## 32 Item6 Item8 2.644912 0.103881881 1.0000000 0.04873154
## 21 Item3 Item9 2.195011 0.138458201 1.0000000 0.05948456
## 10 Item2 Item4 1.449106 0.228671389 1.0000000 -0.08036216
## 30 Item5 Item9 1.393583 0.237800911 1.0000000 -0.01934420
#*** Model 2: DINO model for DINA simulated data
mod2 <- CDM::din(dat, q.matrix=q.matrix, rule="DINO" )
fmod2 <- CDM::modelfit.cor.din(mod2, jkunits=10 ) # 10 jackknife units
summary(fmod2)
## Test of Global Model Fit
## type value p
## 1 max(X2) 13.139 0.010
## 2 abs(fcor) 0.199 0.001
##
## Fit Statistics
## est jkunits jk_est jk_se est_low est_upp
## MADcor 0.056 10 0.041 0.007 0.026 0.055
## SRMSR 0.072 10 0.045 0.019 0.007 0.083
## 100*MADRESIDCOV 1.225 10 0.878 0.183 0.519 1.236
## MADQ3 0.073 10 0.055 0.012 0.031 0.080
## MADaQ3 0.073 10 0.066 0.012 0.042 0.089
#*** Model 3: estimate DINA model with gdina function
mod3 <- CDM::gdina( dat, q.matrix=q.matrix, rule="DINA" )
fmod3 <- CDM::modelfit.cor.din( mod3, jkunits=0 ) # no Jackknife estimation
summary(fmod3)
## Test of Global Model Fit
## type value p
## 1 max(X2) 8.756 0.111
## 2 abs(fcor) 0.143 0.078
##
## Fit Statistics
## est
## MADcor 0.030
## SRMSR 0.040
## MX2 0.719
## 100*MADRESIDCOV 0.668
## MADQ3 0.062
## MADaQ3 0.059
#############################################################################
# EXAMPLE 2: Simulated Example DINA model
#############################################################################
set.seed(9765)
# specify Q-matrix
Q <- matrix( c(1,0, 0,1, 1,1 ), nrow=3, ncol=2, byrow=TRUE )
q.matrix <- Q[ rep(1:3,4), ]
I <- nrow(q.matrix)
# simulate data
guess <- stats::runif(I, 0, .3 )
slip <- stats::runif( I, 0, .4 )
N <- 150 # number of persons
dat <- CDM::sim.din( N=N, q.matrix=q.matrix, slip=slip, guess=guess )$dat
#*** estmate DINA model
mod1 <- CDM::din( dat, q.matrix=q.matrix, rule="DINA" )
fmod1 <- CDM::modelfit.cor.din(mod1, jkunits=10)
summary(fmod1)
## Test of Global Model Fit
## type value p
## 1 max(X2) 10.697 0.071
## 2 abs(fcor) 0.277 0.026
##
## Fit Statistics
## est jkunits jk_est jk_se est_low est_upp
## MADcor 0.052 10 0.026 0.010 0.006 0.045
## SRMSR 0.074 10 0.048 0.013 0.022 0.074
## 100*MADRESIDCOV 1.259 10 0.646 0.213 0.228 1.063
## MADQ3 0.080 10 0.047 0.010 0.027 0.068
## MADaQ3 0.079 10 0.046 0.010 0.027 0.065
# }
Run the code above in your browser using DataLab