From 3c50fb7c3e5d1a810459e7f0fb8d2736b978f2d7 Mon Sep 17 00:00:00 2001 From: Kjell S Slupphaug Date: Mon, 11 Nov 2024 22:30:12 +0100 Subject: [PATCH] Add workflows for tests and `R CMD check` (#262) * inital-attempt for running workflows * add Encoding: UTF-8 in DESCRIPTION * replace expect_is() since it is deprecated * dont run tests in check * fix partial matches * vuongtest -> nonnest2::vuongtest * expect_equal(tol=...) -> expect_equal(tolerance=...) * fix groupName partial match * unamed arg -> tolerance=... * tol -> tolerance in test-10-extras.R * dont trigger tests automatically on push to main --- .github/workflows/checks.yml | 23 +++++++ .github/workflows/tests.yml | 23 +++++++ DESCRIPTION | 5 +- R/03-estimation.R | 8 +-- R/05-model.elements.R | 2 +- R/EMstep.group.R | 2 +- R/M2.R | 2 +- R/MultipleGroup-methods.R | 2 +- R/fscores.internal.R | 4 +- R/utils.R | 4 +- tests/{tests => testthat}/test-00-basics.R | 4 +- tests/{tests => testthat}/test-01-mirtOne.R | 60 +++++++++--------- tests/{tests => testthat}/test-02-mirtTwo.R | 58 ++++++++--------- tests/{tests => testthat}/test-03-bfactor.R | 26 ++++---- .../test-04-multipleGroup.R | 38 +++++------ .../{tests => testthat}/test-05-confmirtOne.R | 18 +++--- .../{tests => testthat}/test-06-confmirtTwo.R | 30 ++++----- tests/{tests => testthat}/test-07-mixedmirt.R | 24 +++---- .../{tests => testthat}/test-08-createItem.R | 16 ++--- .../{tests => testthat}/test-09-mirt.model.R | 2 +- tests/{tests => testthat}/test-10-extras.R | 12 ++-- tests/{tests => testthat}/test-11-discrete.R | 2 +- tests/{tests => testthat}/test-12-gpcm_mats.R | 2 +- tests/{tests => testthat}/test-13-grsmIRT.R | 2 +- tests/{tests => testthat}/test-14-GGUM.R | 2 +- tests/{tests => testthat}/test-15-IRTpars.R | 2 +- tests/{tests => testthat}/test-16-DCIRT.R | 14 ++-- tests/{tests => testthat}/test-17-DIF_DRF.R | 14 ++-- tests/{tests => testthat}/test-18-LLTM.R | 34 +++++----- tests/{tests => testthat}/testdata/MG1.rds | Bin tests/{tests => testthat}/testdata/MG2.rds | Bin tests/{tests => testthat}/testdata/MG3.rds | Bin .../{tests => testthat}/testdata/bfactor1.rds | Bin .../{tests => testthat}/testdata/bfactor2.rds | Bin .../{tests => testthat}/testdata/conftwo1.rds | Bin tests/{tests => testthat}/testdata/dcirt1.rds | Bin tests/{tests => testthat}/testdata/dcirt2.rds | Bin tests/{tests => testthat}/testdata/dcirt3.rds | Bin tests/{tests => testthat}/testdata/dif1.rds | Bin .../testdata/discrete1.rds | Bin .../{tests => testthat}/testdata/extras1.rds | Bin tests/{tests => testthat}/testdata/mixed1.rds | Bin tests/{tests => testthat}/testdata/mixed2.rds | Bin tests/{tests => testthat}/testdata/rst.rds | Bin 44 files changed, 242 insertions(+), 193 deletions(-) create mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/tests.yml rename tests/{tests => testthat}/test-00-basics.R (95%) rename tests/{tests => testthat}/test-01-mirtOne.R (90%) rename tests/{tests => testthat}/test-02-mirtTwo.R (91%) rename tests/{tests => testthat}/test-03-bfactor.R (94%) rename tests/{tests => testthat}/test-04-multipleGroup.R (94%) rename tests/{tests => testthat}/test-05-confmirtOne.R (88%) rename tests/{tests => testthat}/test-06-confmirtTwo.R (88%) rename tests/{tests => testthat}/test-07-mixedmirt.R (96%) rename tests/{tests => testthat}/test-08-createItem.R (82%) rename tests/{tests => testthat}/test-09-mirt.model.R (99%) rename tests/{tests => testthat}/test-10-extras.R (96%) rename tests/{tests => testthat}/test-11-discrete.R (99%) rename tests/{tests => testthat}/test-12-gpcm_mats.R (94%) rename tests/{tests => testthat}/test-13-grsmIRT.R (98%) rename tests/{tests => testthat}/test-14-GGUM.R (97%) rename tests/{tests => testthat}/test-15-IRTpars.R (97%) rename tests/{tests => testthat}/test-16-DCIRT.R (97%) rename tests/{tests => testthat}/test-17-DIF_DRF.R (94%) rename tests/{tests => testthat}/test-18-LLTM.R (78%) rename tests/{tests => testthat}/testdata/MG1.rds (100%) rename tests/{tests => testthat}/testdata/MG2.rds (100%) rename tests/{tests => testthat}/testdata/MG3.rds (100%) rename tests/{tests => testthat}/testdata/bfactor1.rds (100%) rename tests/{tests => testthat}/testdata/bfactor2.rds (100%) rename tests/{tests => testthat}/testdata/conftwo1.rds (100%) rename tests/{tests => testthat}/testdata/dcirt1.rds (100%) rename tests/{tests => testthat}/testdata/dcirt2.rds (100%) rename tests/{tests => testthat}/testdata/dcirt3.rds (100%) rename tests/{tests => testthat}/testdata/dif1.rds (100%) rename tests/{tests => testthat}/testdata/discrete1.rds (100%) rename tests/{tests => testthat}/testdata/extras1.rds (100%) rename tests/{tests => testthat}/testdata/mixed1.rds (100%) rename tests/{tests => testthat}/testdata/mixed2.rds (100%) rename tests/{tests => testthat}/testdata/rst.rds (100%) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 000000000..e7f7ebb05 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,23 @@ +name: R-CMD-CHECK + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + workflow_dispatch: + +jobs: + R-CMD-CHECK: + runs-on: ubuntu-latest + + container: + image: ghcr.io/kss2k/container-mirt:latest + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: R CMD CHECK + run: | + Rscript -e 'devtools::check(error_on = "warning")' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..bb97394cf --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,23 @@ +name: Tests (Ubuntu-latest) + +on: + # push: + # branches: [main, master] + pull_request: + branches: [main, master] + workflow_dispatch: + +jobs: + Run-Tests: + runs-on: ubuntu-latest + + container: + image: ghcr.io/kss2k/container-mirt:latest + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Run tests + run: | + Rscript -e 'options(warnPartialMatchDollar = TRUE); Sys.setenv("_R_CHECK_LENGTH_1_CONDITION_" = "TRUE", "_R_CHECK_LENGTH_1_LOGIC2_" = "TRUE"); devtools::test(stop_on_failure = TRUE)' diff --git a/DESCRIPTION b/DESCRIPTION index 9c81394e8..56b1143a6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -56,14 +56,17 @@ Suggests: nloptr, sirt, plink, - mirtCAT + mirtCAT, + testthat (>= 3.0.0) ByteCompile: yes LazyLoad: yes LazyData: yes LinkingTo: Rcpp, RcppArmadillo License: GPL (>= 3) +Encoding: UTF-8 Repository: CRAN Maintainer: Phil Chalmers URL: https://philchalmers.github.io/mirt/, https://github.com/philchalmers/mirt/wiki, https://groups.google.com/forum/#!forum/mirt-package BugReports: https://github.com/philchalmers/mirt/issues?state=open RoxygenNote: 7.3.2 +Config/testthat/edition: 3 diff --git a/R/03-estimation.R b/R/03-estimation.R index 903211935..820ed7f80 100644 --- a/R/03-estimation.R +++ b/R/03-estimation.R @@ -867,8 +867,8 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1 Consider changing the starting values', call.=FALSE) dontrun <- TRUE } - lengthsplit <- do.call(c, lapply(strsplit(names(ESTIMATE$correct), 'COV_'), length)) - lengthsplit <- lengthsplit + do.call(c, lapply(strsplit(names(ESTIMATE$correct), 'MEAN_'), length)) + lengthsplit <- do.call(c, lapply(strsplit(names(ESTIMATE$correction), 'COV_'), length)) + lengthsplit <- lengthsplit + do.call(c, lapply(strsplit(names(ESTIMATE$correction), 'MEAN_'), length)) is.latent <- lengthsplit > 2L if(!dontrun){ if(ESTIMATE$cycles <= 10L) @@ -1016,7 +1016,7 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1 .mirtClusterEnv$ncores <- 1L } for(g in seq_len(Data$ngroups)){ - cmods[[g]]@Data <- list(data=Data$data[Data$group == Data$groupName[g], ], + cmods[[g]]@Data <- list(data=Data$data[Data$group == Data$groupNames[g], ], fulldata=Data$fulldata[[g]], tabdata=Data$tabdata, Freq=list(Data$Freq[[g]]), K=Data$K) cmods[[g]] <- calcLogLik(cmods[[g]], opts$draws, G2 = 'return', @@ -1166,7 +1166,7 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1 } else { if(Options$exploratory){ FF <- F %*% t(F) - V <- eigen(FF)$vector[ ,1L:nfact] + V <- eigen(FF)$vectors[ ,1L:nfact] L <- eigen(FF)$values[1L:nfact] if (nfact == 1L) F <- as.matrix(V * sqrt(L)) else F <- V %*% sqrt(diag(L)) diff --git a/R/05-model.elements.R b/R/05-model.elements.R index 3ae8d725e..9a04cb26d 100644 --- a/R/05-model.elements.R +++ b/R/05-model.elements.R @@ -98,7 +98,7 @@ model.elements <- function(model, factorNames, itemtype, nfactNames, nfact, J, K if(exploratory){ Rpoly <- cormod(data, K, guess) - loads <- eigen(Rpoly)$vector[,seq_len(nfact), drop = FALSE] + loads <- eigen(Rpoly)$vectors[,seq_len(nfact), drop = FALSE] u <- 1 - rowSums(loads^2) u[u < .001 ] <- .2 cs <- sqrt(u) diff --git a/R/EMstep.group.R b/R/EMstep.group.R index 31661c34f..0777fe98b 100644 --- a/R/EMstep.group.R +++ b/R/EMstep.group.R @@ -150,7 +150,7 @@ EM.group <- function(pars, constrain, Ls, Data, PrepList, list, Theta, DERIV, so tmp <- tmp[lower.tri(tmp, TRUE)] tmpmat <- matrix(0, ns, 2L) for(i in seq_len(ns)) - tmpmat[i, ] <- c(gp$gmean[np + i], gp$gcov[np+i, np+i]) + tmpmat[i, ] <- c(gp$gmeans[np + i], gp$gcov[np+i, np+i]) for(g in seq_len(ngroups)){ pars[[g]][[J+1L]]@bindex <- as.integer(c(gp$gmeans[seq_len(np)], tmp)) pars[[g]][[J+1L]]@sindex = tmpmat diff --git a/R/M2.R b/R/M2.R index b82e42005..ff79516d9 100644 --- a/R/M2.R +++ b/R/M2.R @@ -381,7 +381,7 @@ M2 <- function(obj, type="M2*", calcNull = TRUE, quadpts = NULL, theta_lim = c(- pars[[g]]@Internals$Prior <- list(obj@Internals$Prior[[g]]) pars[[g]]@Model$Theta <- obj@Model$Theta } - pars[[g]]@Data <- list(data=obj@Data$data[obj@Data$group == obj@Data$groupName[g], ], + pars[[g]]@Data <- list(data=obj@Data$data[obj@Data$group == obj@Data$groupNames[g], ], mins=obj@Data$mins, K=obj@Data$K, fulldata=list(obj@Data$fulldata[[g]])) if(is(obj, 'MixtureClass')) pars[[g]]@Data$data <- extract.mirt(obj, 'data') diff --git a/R/MultipleGroup-methods.R b/R/MultipleGroup-methods.R index 8acbb8cae..f0c77f6f2 100644 --- a/R/MultipleGroup-methods.R +++ b/R/MultipleGroup-methods.R @@ -341,7 +341,7 @@ setMethod( for(g in 1L:length(ret)){ cmod <- object@ParObjects$pars[[g]] cmod@Data <- object@Data - cmod@Data$data <- object@Data$data[object@Data$group == object@Data$groupName[g], ] + cmod@Data$data <- object@Data$data[object@Data$group == object@Data$groupNames[g], ] cmod@Data$Freq[[1L]] <- cmod@Data$Freq[[g]] cmod@Options$quadpts <- object@Options$quadpts cmod@Internals$bfactor <- object@Internals$bfactor diff --git a/R/fscores.internal.R b/R/fscores.internal.R index 1491165a4..fb12ea3df 100644 --- a/R/fscores.internal.R +++ b/R/fscores.internal.R @@ -864,7 +864,7 @@ EAPsum <- function(x, full.scores = FALSE, full.scores.SE = FALSE, factorNames <- extract.mirt(x, 'factorNames') colnames(thetas) <- factorNames[!grepl('\\(',factorNames)] colnames(SEthetas) <- paste0('SE_', colnames(thetas)) - ret <- data.frame(Sum.Scores=Sum.Scores + sum(x@Data$min), thetas, SEthetas) + ret <- data.frame(Sum.Scores=Sum.Scores + sum(x@Data$mins), thetas, SEthetas) rownames(ret) <- ret$Sum.Scores if(full.scores){ dat <- x@Data$data @@ -1082,4 +1082,4 @@ EAP_classify <- function(ID, log_itemtrace, tabdata, W, nclass){ } probs <- matrix(expLW / nc, ncol=nclass) colSums(probs) -} \ No newline at end of file +} diff --git a/R/utils.R b/R/utils.R index 1416b6af5..33f15658e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -95,7 +95,7 @@ thetaStack <- function(theta, nclass){ #' } secondOrderTest <- function(mat, ..., method = 'eigen'){ if(method == 'eigen'){ - evs <- eigen(mat, ...)$value + evs <- eigen(mat, ...)$values ret <- all(!sapply(evs, function(x) isTRUE(all.equal(x, 0))) & evs > 0) } else if(method == 'chol'){ chl <- try(chol(mat, ...), silent = TRUE) @@ -2428,7 +2428,7 @@ MGC2SC <- function(x, which){ } tmp@Data <- x@Data tmp@Data$completely_missing <- integer(0L) - tmp@Data$data <- tmp@Data$data[tmp@Data$group == tmp@Data$groupName[which], , drop=FALSE] + tmp@Data$data <- tmp@Data$data[tmp@Data$group == tmp@Data$groupNames[which], , drop=FALSE] tmp@Data$rowID <- 1L:nrow(tmp@Data$data) tmp@Data$Freq[[1L]] <- tmp@Data$Freq[[which]] tmp@Data$fulldata[[1L]] <- x@Data$fulldata[[which]] diff --git a/tests/tests/test-00-basics.R b/tests/testthat/test-00-basics.R similarity index 95% rename from tests/tests/test-00-basics.R rename to tests/testthat/test-00-basics.R index a006ebc07..4a124bb40 100644 --- a/tests/tests/test-00-basics.R +++ b/tests/testthat/test-00-basics.R @@ -1,4 +1,4 @@ -context('basics') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('basics', { group <- rep(c('G1', 'G2'), each=nrow(Science)/2) @@ -19,7 +19,7 @@ test_that('basics', { tscore <- expected.test(mod, Theta) expect_equal(tscore, c(7.935196,9.270222,10.53705,11.69166,12.7803,13.83405,14.73532), tolerance=1e-6) IG <- itemGAM(Science[group == 'G1',1], theta_se[,1, drop=FALSE]) - expect_is(IG, 'itemGAM') + expect_class(IG, 'itemGAM') info <- iteminfo(item1, Theta) expect_equal(as.vector(info), c(0.2031261,0.2118485,0.2069816,0.187747,0.1793368,0.1902587,0.1761818), diff --git a/tests/tests/test-01-mirtOne.R b/tests/testthat/test-01-mirtOne.R similarity index 90% rename from tests/tests/test-01-mirtOne.R rename to tests/testthat/test-01-mirtOne.R index c59403e24..429268b5f 100644 --- a/tests/tests/test-01-mirtOne.R +++ b/tests/testthat/test-01-mirtOne.R @@ -1,9 +1,9 @@ -context('mirtOne') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('dich', { data <- expand.table(LSAT7) mod1 <- mirt(data, 1, verbose=FALSE) - expect_is(mod1, 'SingleGroupClass') + expect_class(mod1, 'SingleGroupClass') expect_equal(extract.mirt(mod1, 'df'), 21) cfs <- as.numeric(do.call(c, coef(mod1))) expect_equal(cfs, c(0.988, 1.8561, 0, 1, 1.081, 0.808, 0, 1, 1.706, 1.8043, 0, 1, 0.7651, 0.486, 0, 1, 0.7358, 1.8545, 0, 1, 0, 1), @@ -11,7 +11,7 @@ test_that('dich', { sv <- mod2values(mod1) sv$est <- FALSE moddummy <- mirt(data, 1, pars= sv, verbose=FALSE) - expect_is(moddummy, 'SingleGroupClass') + expect_class(moddummy, 'SingleGroupClass') sv2 <- mod2values(moddummy) expect_equal(sv$value, sv2$value) modm1 <- mirt(data, 1, SE = TRUE, SE.type = 'SEM', verbose=FALSE) @@ -20,17 +20,17 @@ test_that('dich', { expect_equal(extract.mirt(modm1, 'condnum'), 30.12751, tolerance = 1e-4) expect_equal(cfs, c(0.9876, 0.6367, 1.3384, 1.8559, 1.5978, 2.1139, 0, NA, NA, 1, NA, NA, 1.0808, 0.7604, 1.4013, 0.808, 0.6335, 0.9825, 0, NA, NA, 1, NA, NA, 1.7075, 1.0868, 2.3281, 1.8052, 1.4028, 2.2076, 0, NA, NA, 1, NA, NA, 0.765, 0.5065, 1.0235, 0.486, 0.3114, 0.6606, 0, NA, NA, 1, NA, NA, 0.7357, 0.4246, 1.0467, 1.8545, 1.6332, 2.0757, 0, NA, NA, 1, NA, NA, 0, NA, NA, 1, NA, NA), tolerance = 1e-2) - expect_is(modm1, 'SingleGroupClass') + expect_class(modm1, 'SingleGroupClass') modm2 <- mirt(data, 1, SE = TRUE, SE.type = 'Richardson', verbose=FALSE) cfs <- as.numeric(do.call(c, coef(modm2))) expect_equal(extract.mirt(modm2, 'condnum'), 30.24068, tolerance = 1e-3) expect_equal(cfs, c(0.988, 0.6406, 1.3354, 1.8561, 1.5984, 2.1138, 0, NA, NA, 1, NA, NA, 1.081, 0.7501, 1.4119, 0.808, 0.6291, 0.9869, 0, NA, NA, 1, NA, NA, 1.706, 1.0779, 2.334, 1.8043, 1.4036, 2.205, 0, NA, NA, 1, NA, NA, 0.7651, 0.5022, 1.028, 0.486, 0.3392, 0.6328, 0, NA, NA, 1, NA, NA, 0.7358, 0.4395, 1.032, 1.8545, 1.6302, 2.0787, 0, NA, NA, 1, NA, NA, 0, NA, NA, 1, NA, NA), tolerance = 1e-2) - expect_is(modm2, 'SingleGroupClass') + expect_class(modm2, 'SingleGroupClass') modm2b <- mirt(data, 1, SE = TRUE, SE.type = 'Fisher', verbose=FALSE) expect_equal(extract.mirt(modm2b, 'condnum'), 29.0323, tolerance = 1e-3) modm3 <- mirt(data, 1, itemtype = 'Rasch', verbose=FALSE, SE=TRUE) - expect_is(modm3, 'SingleGroupClass') + expect_class(modm3, 'SingleGroupClass') expect_equal(extract.mirt(modm3, 'df'), 25) expect_equal(extract.mirt(modm3, 'condnum'), 4.488772, tolerance = 1e-4) LG <- lagrange(modm3, parnum = list(1, 5)) @@ -39,7 +39,7 @@ test_that('dich', { expect_equal(LG2$X2, 0.4816444, tolerance = 1e-4) dat <- expand.table(LSAT6) modm3 <- mirt(dat, 1, itemtype = 'Rasch', SE = TRUE, SE.type = 'SEM', verbose=FALSE) - expect_is(modm3, 'SingleGroupClass') + expect_class(modm3, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modm3))) expect_equal(cfs, c(1,NA,NA,2.73,2.478,2.983,0,NA,NA,1,NA,NA,1,NA,NA,0.999,0.845,1.152,0,NA,NA,1,NA,NA,1,NA,NA,0.24,0.1,0.38,0,NA,NA,1,NA,NA,1,NA,NA,1.306,1.143,1.47,0,NA,NA,1,NA,NA,1,NA,NA,2.099,1.896,2.303,0,NA,NA,1,NA,NA,0,NA,NA,0.57,0.371,0.77), tolerance = 1e-2) @@ -58,18 +58,18 @@ test_that('dich', { svalues <- mirt(data, 1, pars = 'values', verbose=FALSE) svalues[22, 'value'] <- 2 modm5 <- mirt(data, 1, pars = svalues, verbose=FALSE) - expect_is(modm5, 'SingleGroupClass') + expect_class(modm5, 'SingleGroupClass') expect_warning(modm7 <- mirt(data, 1, '4PL', verbose=FALSE, parprior = list(c(3,7,11,15,19,'norm', -1.7, .1), c(4,8,12,16,20,'norm', 1.7, .1))), "EM cycles terminated after 500 iterations.") expect_equal(extract.mirt(modm7, 'df'), 11) - expect_is(modm7, 'SingleGroupClass') + expect_class(modm7, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modm7))) expect_equal(cfs, c(5.12,8.557,0.154,0.859,5.741,3.595,0.16,0.843,10.215,10.937,0.155,0.861,1.284,0.854,0.153,0.845,4.629,8.905,0.154,0.859,0,1), tolerance = 1e-2) data[1,1] <- data[2,2] <- NA modm6 <- mirt(data, 1, verbose=FALSE) expect_equal(modm6@Fit$df, 21) - expect_is(modm6, 'SingleGroupClass') + expect_class(modm6, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modm6))) expect_equal(cfs, c(0.969, 1.851, 0, 1, 1.074, 0.808, 0, 1, 1.717, 1.811, 0, 1, 0.763, 0.486, 0, 1, 0.731, 1.852, 0, 1, 0, 1), tolerance = 1e-2) modideal <- mirt(data, 1, verbose=FALSE, itemtype='ideal') @@ -93,26 +93,26 @@ test_that('dich', { expect_equal(as.numeric(rfit[,1]), c(NA, 0.0468866, 0.3906001, 0.2476980, 0.5195561), tolerance = 1e-2) fm1 <- fscores(modm1, verbose = FALSE, full.scores=FALSE) - expect_is(fm1, 'matrix') + expect_class(fm1, 'matrix') expect_true(mirt:::closeEnough(fm1[1:6,'F1'] - c(-1.8665957, -1.5266920, -1.5134024, -1.1852276, -1.0946830, -0.7666992), -1e-2, 1e-2)) fm2 <- fscores(modm2, method = 'MAP', verbose = FALSE, full.scores=FALSE) - expect_is(fm2, 'matrix') + expect_class(fm2, 'matrix') expect_true(mirt:::closeEnough(fm2[1:6,'F1'] - c(-1.8165552, -1.4946906, -1.4822982, -1.1789899, -1.0958928, -0.7951026), -1e-2, 1e-2)) fm3 <- fscores(modm4, method = 'ML', full.scores = TRUE, verbose = FALSE) - expect_is(fm3, 'matrix') + expect_class(fm3, 'matrix') expect_true(fm3[1, 'F'] == -Inf && fm3[1000, 'F'] == Inf) expect_true(mirt:::closeEnough(as.numeric(fm3[c(13,34,40),'F']) - c(-2.783489, -1.750890, -2.783489), -1e-2, 1e-2)) fm3 <- fscores(modm3, method = 'ML', full.scores = TRUE, verbose = FALSE, scores.only=TRUE) - expect_is(fm3, 'matrix') + expect_class(fm3, 'matrix') fm4 <- fscores(modm6, method = 'ML', full.scores = TRUE, verbose = FALSE) - expect_is(fm4, 'matrix') + expect_class(fm4, 'matrix') fm5 <- fscores(modm6, method = 'ML', full.scores = FALSE, verbose = FALSE) - expect_is(fm5, 'matrix') + expect_class(fm5, 'matrix') fm6 <- fscores(modm1, method = 'EAPsum', full.scores = FALSE, verbose = FALSE) - expect_is(fm6, 'data.frame') + expect_class(fm6, 'data.frame') expect_true(mirt:::closeEnough(as.numeric(as.matrix(fm6)) - c(0,1,2,3,4,5,-1.86979,-1.431861,-0.9488463,-0.4131963,0.1517289,0.7271877,0.6927032,0.6838697,0.6942298,0.7210951,0.758772,0.8009335,12,40,114,205,321,308,10.08994,44.65882,109.773,207.7391,319.1854,308.5536,0.6013157,0.6971433,0.4034422,0.1900446,0.101567,0.0315184), -1e-2, 1e-2)) expect_equal(as.numeric(attr(fm6, 'fit')['rxx_F1']), 0.4319948, tolerance = 1e-4) @@ -120,18 +120,18 @@ test_that('dich', { expect_equal(as.numeric(res1), c(NA,0.451213,0.8562096,2.577395,2.392183,-0.02124177,NA,1.053826,0.2662122,1.383089,-0.02926106,0.03246269,NA,0.1542321,0.002940504,0.05076805,-0.01631601,-0.01241902,NA,9.962506e-06,0.04890994,-0.0371899,-0.00171479,9.981236e-05,NA), tolerance = 1e-2) res2 <- residuals(modm2, verbose = FALSE) - expect_is(res1, 'matrix') - expect_is(res2, 'matrix') + expect_class(res1, 'matrix') + expect_class(res2, 'matrix') IP1 <- itemplot(modm1, 1) IP2 <- itemplot(modm2, 1) - expect_is(IP1, 'trellis') - expect_is(IP2, 'trellis') + expect_class(IP1, 'trellis') + expect_class(IP2, 'trellis') TP1 <- plot(modm1) TP2 <- plot(modm2) - expect_is(TP1, 'trellis') - expect_is(TP2, 'trellis') + expect_class(TP1, 'trellis') + expect_class(TP2, 'trellis') ifit <- itemfit(modm1, c('S_X2', 'X2', 'Zh')) - expect_is(ifit, 'data.frame') + expect_class(ifit, 'data.frame') expect_true(mirt:::closeEnough(as.numeric(ifit$Zh) - c(1.431838, 6.354917, 5.310844, 5.804449, 0.696139), -1e-2, 1e-2)) expect_true(mirt:::closeEnough(as.numeric(ifit$X2) - c(91.71819, 390.07985, 145.39978, 329.48529, 129.49679), -1e-2, 1e-2)) @@ -141,11 +141,11 @@ test_that('dich', { expect_true(mirt:::closeEnough(as.numeric(ifit$df.S_X2) - c(2,2,2,2,2), -1e-4, 1e-4)) fitm1 <- M2(modm1) - expect_is(fitm1, 'data.frame') + expect_class(fitm1, 'data.frame') expect_true(mirt:::closeEnough(fitm1$M2 - 11.93841, -1e-2, 1e-2)) expect_true(mirt:::closeEnough(fitm1$df.M2 - 5, -1e-4, 1e-4)) fitm2 <- M2(modm3) - expect_is(fitm2, 'data.frame') + expect_class(fitm2, 'data.frame') expect_true(mirt:::closeEnough(fitm2$M2 - 5.291576, -1e-2, 1e-2)) expect_true(mirt:::closeEnough(fitm2$df.M2 - 9, -1e-4, 1e-4)) @@ -160,12 +160,12 @@ test_that('dich', { tolerance = 1e-2) expect_equal(extract.mirt(modm2, 'df'), 19) modm3 <- mirt(data, model, SE = TRUE, verbose=FALSE) - expect_is(modm3, 'SingleGroupClass') + expect_class(modm3, 'SingleGroupClass') fm1 <- fscores(modm1, verbose = FALSE, full.scores=FALSE) - expect_is(fm1, 'matrix') + expect_class(fm1, 'matrix') fm2 <- fscores(modm3, method = 'MAP', verbose = FALSE) - expect_is(fm2, 'matrix') + expect_class(fm2, 'matrix') data[1,1] <- NA modm1 <- mirt(data, 1, verbose=FALSE) @@ -192,6 +192,6 @@ test_that('dich', { CONSTRAIN = (1-5, a1)' mod3 <- mirt(dat, syntax, verbose=FALSE) expect_equal(2*logLik(mod) - logLik(mod2) - logLik(mod3), - 0, 1e-2) + 0, tolerance=1e-2) }) diff --git a/tests/tests/test-02-mirtTwo.R b/tests/testthat/test-02-mirtTwo.R similarity index 91% rename from tests/tests/test-02-mirtTwo.R rename to tests/testthat/test-02-mirtTwo.R index 8e74f4579..281bca60b 100644 --- a/tests/tests/test-02-mirtTwo.R +++ b/tests/testthat/test-02-mirtTwo.R @@ -1,8 +1,8 @@ -context('mirtTwo') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('poly', { modp1 <- mirt(Science, 1, verbose=FALSE) - expect_is(modp1, 'SingleGroupClass') + expect_class(modp1, 'SingleGroupClass') expect_equal(extract.mirt(modp1, 'df'), 239) cfs <- as.numeric(do.call(c, coef(modp1))) expect_equal(cfs, c(1.041, 4.864, 2.64, -1.466, 1.226, 2.924, 0.901, -2.266, 2.296, 5.238, 2.216, -1.965, 1.095, 3.348, 0.992, -1.688, 0, 1), @@ -11,7 +11,7 @@ test_that('poly', { expect_equal(C2$M2, 19.17929, tolerance=1e-4) expect_equal(C2$p, 6.84337e-05, tolerance=1e-4) modp2 <- mirt(Science, 1, 'sequential', verbose=FALSE) - expect_is(modp2, 'SingleGroupClass') + expect_class(modp2, 'SingleGroupClass') expect_equal(extract.mirt(modp2, 'df'), 239) cfs <- as.numeric(do.call(c, coef(modp2))) expect_equal(cfs, c(0.997414,4.831609,2.750703,-1.365844,1.067633,2.815793,1.104466,-1.87485,2.132679,5.021663,2.223683,-1.784284,0.9942698,3.287169,1.12849,-1.308458,0,1), @@ -19,19 +19,19 @@ test_that('poly', { expect_equal(logLik(modp2), -1609.768, tolerance = 1e-4) modLouis <- mirt(Science, 1, SE=T, SE.type='Louis', verbose=FALSE) - expect_is(modp1, 'SingleGroupClass') + expect_class(modp1, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modLouis, printSE=TRUE))) expect_equal(cfs, c(1.04236, 0.18838, 4.86544, 0.49088, 2.64044, 0.22267, -1.46621, 0.15868, 1.22569, 0.18189, 2.924, 0.23928, 0.90115, 0.14289, -2.26661, 0.20308, 2.29058, 0.48269, 5.22988, 0.72817, 2.21201, 0.3564, -1.96222, 0.32209, 1.09557, 0.18336, 3.34845, 0.27659, 0.9919, 0.14053, -1.68846, 0.16864, 0, NA, 1, NA), tolerance = 1e-3) expect_equal(modLouis@OptimInfo$condnum, 98.26492, tolerance = 1e-2) modsandwich <- mirt(Science, 1, SE=T, SE.type='sandwich.Louis', verbose=FALSE) - expect_is(modsandwich, 'SingleGroupClass') + expect_class(modsandwich, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modsandwich, printSE=TRUE))) expect_equal(cfs, c(1.04236, 0.23843, 4.86544, 0.46794, 2.64044, 0.24659, -1.46621, 0.17162, 1.22569, 0.1922, 2.924, 0.24655, 0.90115, 0.14592, -2.26661, 0.19899, 2.29058, 0.52026, 5.22988, 0.80736, 2.21201, 0.373, -1.96222, 0.33683, 1.09557, 0.22701, 3.34845, 0.29203, 0.9919, 0.14491, -1.68846, 0.18015, 0, NA, 1, NA), tolerance = 1e-3) expect_equal(extract.mirt(modsandwich, 'condnum'), 141.5391, tolerance = 1e-2) modsandwich <- mirt(Science, 1, SE=T, SE.type='sandwich', verbose=FALSE) - expect_is(modsandwich, 'SingleGroupClass') + expect_class(modsandwich, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modsandwich, printSE=TRUE))) expect_equal(cfs, c(1.04236, 0.23843, 4.86544, 0.46794, 2.64044, 0.24659, -1.46621, 0.17162, 1.22569, 0.1922, 2.924, 0.24655, 0.90115, 0.14592, -2.26661, 0.19899, 2.29058, 0.52026, 5.22988, 0.80736, 2.21201, 0.373, -1.96222, 0.33683, 1.09557, 0.22701, 3.34845, 0.29203, 0.9919, 0.14491, -1.68846, 0.18015, 0, NA, 1, NA), tolerance = 1e-3) @@ -39,31 +39,31 @@ test_that('poly', { modOakes <- mirt(Science, 1, SE=T, SE.type='Oakes', verbose=FALSE) expect_equal(modOakes@OptimInfo$condnum, 97.8644, tolerance = 1e-4) modp1 <- mirt(Science, 1, verbose=FALSE) - expect_is(modp1, 'SingleGroupClass') + expect_class(modp1, 'SingleGroupClass') expect_equal(extract.mirt(modp1, 'df'), 239) cfs <- as.numeric(do.call(c, coef(modp1))) expect_equal(cfs, c(1.041, 4.864, 2.64, -1.466, 1.226, 2.924, 0.901, -2.266, 2.296, 5.238, 2.216, -1.965, 1.095, 3.348, 0.992, -1.688, 0, 1), tolerance = 1e-2) vals <- mirt(Science, 1, large = 'return', verbose=FALSE) modp1 <- mirt(Science, 1, large = vals, verbose=FALSE) - expect_is(modp1, 'SingleGroupClass') + expect_class(modp1, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modp1))) expect_equal(cfs, c(1.041, 4.864, 2.64, -1.466, 1.226, 2.924, 0.901, -2.266, 2.296, 5.238, 2.216, -1.965, 1.095, 3.348, 0.992, -1.688, 0, 1), tolerance = 1e-2) modp1 <- mirt(Science, 1, SE=TRUE, SE.type = 'SEM', verbose=FALSE) - expect_is(modp1, 'SingleGroupClass') + expect_class(modp1, 'SingleGroupClass') expect_equal(extract.mirt(modp1, 'condnum'), 108.8042, tolerance = 1e-2) cfs <- as.numeric(do.call(c, coef(modp1))) expect_equal(cfs, c(1.041, 0.656, 1.425, 4.863, 3.849, 5.876, 2.639, 2.196, 3.083, -1.466, -1.782, -1.149, 1.226, 0.887, 1.565, 2.924, 2.45, 3.398, 0.901, 0.614, 1.188, -2.266, -2.639, -1.894, 2.3, 1.325, 3.275, 5.244, 3.804, 6.685, 2.218, 1.488, 2.949, -1.967, -2.605, -1.329, 1.094, 0.727, 1.461, 3.347, 2.801, 3.893, 0.991, 0.717, 1.266, -1.688, -2.018, -1.357, 0, NA, NA, 1, NA, NA), tolerance = 1e-2) modp2 <- mirt(Science, 2, verbose=FALSE) - expect_is(modp2, 'SingleGroupClass') + expect_class(modp2, 'SingleGroupClass') expect_equal(modp2@Fit$df, 236) cfs <- as.numeric(do.call(c, coef(modp2, verbose=FALSE))) expect_equal(abs(cfs), abs(c(-1.3278,0.1081,5.1934,2.8583,-1.5996,-0.8762,1.8783,3.7248,1.1598,-2.9225,-1.4614,1.1639,4.6495,1.951,-1.7322,-1.7397,0,4.0053,1.2008,-2.0548,0,0,1,0,1)), tolerance = 1e-2) modp3 <- mirt(Science, 1, constrain = list(c(1,5)), parprior = list(c(4,'norm',0,1)), verbose=FALSE) - expect_is(modp3, 'SingleGroupClass') + expect_class(modp3, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modp3, verbose = FALSE))) expect_true(mirt:::closeEnough(cfs - c(1.134,4.964,2.711,-1.473,1.134,2.865,0.882,-2.205,2.211,5.136,2.171,-1.91,1.129,3.383,1.006,-1.7,0,1), -1e-2, 1e-2)) @@ -71,7 +71,7 @@ test_that('poly', { CONSTRAIN = (1-2,a1) PRIOR = (1, d1, norm, 4, 1)') modp3 <- mirt(Science, newmodel, verbose=FALSE) - expect_is(modp3, 'SingleGroupClass') + expect_class(modp3, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modp3, verbose = FALSE))) expect_true(mirt:::closeEnough(cfs - c(1.132,4.795,2.677,-1.507,1.132,2.856,0.874,-2.211,2.216,5.127,2.16,-1.927,1.128,3.374,0.999,-1.707,0,1), -1e-2, 1e-2)) @@ -79,17 +79,17 @@ test_that('poly', { expect_equal(modOakes@OptimInfo$condnum, 106.0775, tolerance = 1e-4) modp4 <- mirt(Science, 1, itemtype = c(rep('graded',3), 'nominal'), verbose=FALSE) - expect_is(modp4, 'SingleGroupClass') + expect_class(modp4, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modp4, verbose = FALSE))) expect_equal(cfs, c(1.0408, 4.862, 2.6387, -1.4664, 1.2063, 2.9083, 0.8958, -2.254, 2.3376, 5.2972, 2.2404, -1.9886, 0.7986, 0, 1.0782, 1.7756, 3, 0, 2.1964, 2.9637, 1.6742, 0, 1), tolerance = 1e-2) modp5 <- mirt(Science, 1, itemtype = c(rep('graded',3), 'gpcm'), SE = TRUE, SE.type = 'SEM', verbose=FALSE) - expect_is(modp5, 'SingleGroupClass') + expect_class(modp5, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modp5, verbose = FALSE))) expect_equal(cfs, c(1.057,0.659,1.454,4.876,3.908,5.844,2.65,2.206,3.093,-1.472,-1.799,-1.146,1.219,0.865,1.573,2.918,2.444,3.391,0.9,0.615,1.185,-2.263,-2.662,-1.864,2.254,1.244,3.265,5.177,3.606,6.747,2.19,1.395,2.985,-1.942,-2.587,-1.298,0.771,0.441,1.1,0,NA,NA,1,NA,NA,2,NA,NA,3,NA,NA,0,NA,NA,2.16,1.537,2.782,2.973,2.276,3.671,1.767,1.128,2.407,0,NA,NA,1,NA,NA), tolerance = 1e-2) modp6 <- mirt(Science, 1, dentype="empiricalhist", verbose = FALSE, TOL=1e-3) - expect_is(modp6, 'SingleGroupClass') + expect_class(modp6, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modp6, verbose = FALSE))) expect_equal(cfs, c(0.856,5.072,2.639,-1.35,1.095,2.951,0.968,-2.181,2.601,5.541,2.634,-1.752,0.988,3.443,1.058,-1.595,0,1), tolerance = 1e-2) @@ -97,22 +97,22 @@ test_that('poly', { fm0 <- fscores(modp1, method='EAP', response.pattern = c(1,2,3,4), full.scores=FALSE) expect_equal(as.numeric(fm0[,c('F1','SE_F1')]), c(-0.3494903, 0.6004922), tolerance=1e-4) fm1 <- fscores(modp1, verbose = FALSE, full.scores=FALSE) - expect_is(fm1, 'matrix') + expect_class(fm1, 'matrix') expect_true(mirt:::closeEnough(fm1[1:6,'F1'] - c(-2.7488324, -1.4190140, -0.7154329, -0.4453752, -2.5438490, -1.2481072), -1e-2, 1e-2)) fm1b <- fscores(modp1, verbose = FALSE, full.scores=TRUE) expect_equal(cor(fm1b, rowSums(Science))[1], .969, tolerance = .02) fm2 <- fscores(modp2, rotate = 'oblimin', verbose = FALSE, full.scores=FALSE) - expect_is(fm2, 'matrix') + expect_class(fm2, 'matrix') expect_true(mirt:::closeEnough(abs(as.numeric(fm2[1:6,c('F1','F2')])) - c(2.5966,1.8668,0.6578,1.1597,2.4204,0.7001,2.412,0.8689,0.0258,0.2609,2.3376,1.4844), -1e-2, 1e-2)) fm3 <- fscores(modp3, rotate = 'oblimin', full.scores = TRUE, verbose = FALSE) - expect_is(fm3, 'matrix') + expect_class(fm3, 'matrix') fm4 <- fscores(modp4, verbose = FALSE, full.scores=FALSE) - expect_is(fm4, 'matrix') + expect_class(fm4, 'matrix') expect_true(mirt:::closeEnough(fm4[1:6,'F1'] - c(-2.7320802, -1.4459303, -0.7910009, -0.5438761, -2.5310045, -1.1434060), -1e-2, 1e-2)) fm5 <- fscores(modp5, verbose = FALSE, full.scores=FALSE) - expect_is(fm5, 'matrix') + expect_class(fm5, 'matrix') expect_true(mirt:::closeEnough(fm5[1:6,'F1'] - c(-2.7249561, -1.4446593, -0.7364399, -0.5627047, -2.5174376, -1.1732461), -1e-2, 1e-2)) resmat <- residuals(modp3, type = 'Q3', Theta = fm3[,'F'], verbose = FALSE) @@ -122,13 +122,13 @@ test_that('poly', { resmatG2 <- residuals(modp3, type = 'LDG2', verbose = FALSE) expect_equal(as.numeric(resmatG2), c(NA,21.11214,10.52294,19.91545,-0.1339869,NA,10.25686,17.55354,-0.09459427,0.0933907,NA,18.39732,0.1301342,-0.122174,-0.1250759,NA), tolerance=1e-2) cof1 <- coef(modp1) - expect_is(cof1, 'list') + expect_class(cof1, 'list') cof2 <- coef(modp2, verbose = FALSE) - expect_is(cof2, 'list') + expect_class(cof2, 'list') IP1 <- itemplot(modp1, 1) IP2 <- itemplot(modp2, 1) - expect_is(IP1, 'trellis') - expect_is(IP2, 'trellis') + expect_class(IP1, 'trellis') + expect_class(IP2, 'trellis') fit <- suppressMessages(itemfit(modp2, c('S_X2', 'Zh'))) expect_equal(fit$Zh, c(1.287093, 4.581860, 3.934030, 3.989205), tolerance=1e-4) expect_equal(fit$S_X2, c(3.941804,10.58528,6.913239,10.11068), tolerance=1e-4) @@ -151,8 +151,8 @@ test_that('poly', { load('testdata/rst.rds') grsm <- mirt(data, 1, itemtype = 'grsm', pars = sv, calcNull= FALSE, verbose=FALSE, TOL=1e-5) rsm <- mirt(data, 1, itemtype = 'rsm', calcNull= FALSE, verbose=FALSE, TOL = 1e-3) - expect_is(grsm, 'SingleGroupClass') - expect_is(rsm, 'SingleGroupClass') + expect_class(grsm, 'SingleGroupClass') + expect_class(rsm, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(grsm, verbose = FALSE))) expect_equal(cfs, c(0.958,1,0.491,-0.543,-1.034,-1,0.986,1,0.491,-0.543,-1.034,-0.765,0.993,1,0.491,-0.543,-1.034,-0.543,1.026,1,0.491,-0.543,-1.034,-0.272,0.994,1,0.491,-0.543,-1.034,-0.104,0.986,1,0.491,-0.543,-1.034,0.18,0.956,1,0.491,-0.543,-1.034,0.405,1.039,1,0.491,-0.543,-1.034,0.579,0.963,1,0.491,-0.543,-1.034,0.879,0.946,1,0.491,-0.543,-1.034,1.137,0,1), tolerance = 1e-2) @@ -172,11 +172,11 @@ test_that('poly', { Theta <- matrix(seq(-4,4,.01)) x <- extract.item(modp1, 1) iinfo <- iteminfo(x, Theta) - expect_is(iinfo, 'numeric') + expect_class(iinfo, 'numeric') iinfo <- iteminfo(x, Theta, total.info=FALSE) - expect_is(iinfo, 'matrix') + expect_class(iinfo, 'matrix') tinfo <- testinfo(modp1, Theta) - expect_is(tinfo, 'numeric') + expect_class(tinfo, 'numeric') ER <- fscores(modp2, returnER = TRUE) expect_equal(as.numeric(ER), c(0.4882546, 0.5099054), tolerance=1e-4) diff --git a/tests/tests/test-03-bfactor.R b/tests/testthat/test-03-bfactor.R similarity index 94% rename from tests/tests/test-03-bfactor.R rename to tests/testthat/test-03-bfactor.R index a39d00667..685c83fa1 100644 --- a/tests/tests/test-03-bfactor.R +++ b/tests/testthat/test-03-bfactor.R @@ -1,23 +1,23 @@ -context('bfactor') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('dich data', { key <- c(1,4,5,2,3,1,2,1,3,1,2,4,2,1,5,3,4,4,1,4,3,3,4,1,3,5,1,3,1,5,4,5) data <- key2binary(SAT12, key) specific <- c(2,3,2,3,3,2,1,2,1,1,1,3,1,3,1,2,1,1,3,3,1,1,3,1,3,3,1,3,2,3,1,2) mod1 <- bfactor(data, specific, verbose=FALSE, SE = TRUE, SE.type = 'crossprod') - expect_is(mod1, 'SingleGroupClass') + expect_class(mod1, 'SingleGroupClass') expect_equal(extract.mirt(mod1, 'df'), 4294967199) cfs <- do.call(c, coef(mod1)) cfs <- as.numeric(na.omit(cfs[cfs != 0 & cfs != 1])) expect_equal(cfs, c(0.7861, 0.5159, 1.0563, 0.4426, 0.0102, 0.875, -1.0729, -1.3116, -0.8343, 1.4909, 1.066, 1.9157, 0.8135, 0.3039, 1.3231, 0.471, 0.1911, 0.7509, 1.1476, 0.8265, 1.4687, -0.1526, -0.5584, 0.2532, -1.1727, -1.4361, -0.9093, 0.5277, 0.296, 0.7595, 0.5813, 0.1573, 1.0053, -0.5576, -0.7686, -0.3465, 0.968, 0.6684, 1.2677, 0.5136, 0.0972, 0.9299, 0.6283, 0.3893, 0.8672, 1.1389, 0.8043, 1.4734, 0.5835, 0.0236, 1.1435, -2.1287, -2.5185, -1.7389, 1.0383, 0.6538, 1.4228, 0.9505, 0.3252, 1.5758, 1.5624, 1.1836, 1.9412, 0.6731, 0.3993, 0.9468, 0.524, 0.0133, 1.0347, -1.57, -1.8547, -1.2853, 0.4473, 0.051, 0.8437, 1.0716, 0.2209, 1.9223, 2.4985, 1.8584, 3.1386, 1.0389, 0.7071, 1.3706, 0.8009, 0.2857, 1.316, -0.4025, -0.6423, -0.1626, 1.5827, 0.1568, 3.0087, 0.8549, -0.9418, 2.6517, 5.4019, 3.4336, 7.3702, 0.1221, -0.0922, 0.3364, 0.2729, -0.0654, 0.6113, -0.3504, -0.532, -0.1689, 1.0958, 0.7507, 1.4409, 0.5884, 0.1265, 1.0502, 0.8847, 0.629, 1.1404, 1.0908, 0.6922, 1.4894, 1.034, 0.4259, 1.642, 1.3605, 1.0081, 1.713, 1.3277, 0.9036, 1.7518, 0.5674, 0.0418, 1.0931, 2.0162, 1.6303, 2.4022, 0.7375, 0.4793, 0.9957, 0.3912, 0.0054, 0.777, -0.3909, -0.5967, -0.185, 1.5223, 0.7735, 2.271, 0.3034, -0.545, 1.1518, 4.1836, 3.3304, 5.0369, 1.7575, 1.3192, 2.1959, 0.1929, -0.3447, 0.7304, -0.8748, -1.1651, -0.5845, 0.8645, 0.5785, 1.1506, 0.0331, -0.3091, 0.3754, 0.2388, 0.0304, 0.4472, 1.5332, 0.9808, 2.0856, 0.4104, -0.1434, 0.9642, 2.6505, 2.1186, 3.1823, 0.5263, 0.0806, 0.9721, 0.6773, -0.1142, 1.4687, 2.6609, 2.1603, 3.1615, 1.6737, 0.8655, 2.4818, -0.0344, -0.7411, 0.6722, 3.6147, 2.7752, 4.4542, 0.6087, 0.3653, 0.8522, 0.4945, 0.0858, 0.9031, -0.8815, -1.1074, -0.6556, 1.2319, 0.8525, 1.6114, 0.2423, -0.1535, 0.6382, 1.2882, 1.0023, 1.5741, 0.7354, 0.476, 0.9947, 0.6426, 0.2139, 1.0712, -0.5995, -0.8249, -0.3742, 1.4898, 1.0991, 1.8806, 0.4859, 0.0468, 0.9251, -0.1725, -0.4279, 0.0828, 1.9058, 1.3075, 2.504, 0.415, -0.169, 0.9991, 2.8064, 2.2378, 3.375, 1.0572, 0.761, 1.3534, 0.149, -0.2358, 0.5338, 0.1725, -0.0414, 0.3863, 1.2276, 0.0476, 2.4075, 2.0402, -1.1072, 5.1875, -1.1821, -2.307, -0.0571, 0.4342, 0.1946, 0.6738, -0.1733, -0.5266, 0.1801, -0.2521, -0.4383, -0.0658, 2.5816, 1.5551, 3.6081, -0.235, -0.9097, 0.4398, 2.9944, 2.0731, 3.9156, 0.1326, -0.1185, 0.3838, 0.0294, -0.3714, 0.4302, -1.6521, -1.8929, -1.4113), tolerance = 1e-2) fs <- suppressWarnings(fscores(mod1, verbose = FALSE, full.scores=FALSE, method='MAP')) - expect_is(fs, 'matrix') + expect_class(fs, 'matrix') expect_equal(fs[1:6,'G'], c(-1.0103793, -0.7807428, -1.2088350, -1.4099888, -2.0074429, -1.2226505), tolerance = 1e-2) cof <- coef(mod1, verbose = FALSE) - expect_is(cof, 'list') + expect_class(cof, 'list') sum <- summary(mod1, verbose = FALSE) - expect_is(sum, 'list') + expect_class(sum, 'list') fs <- suppressWarnings(fscores(mod1, method = 'EAPsum', verbose = FALSE, full.scores=FALSE)) expect_equal(fs[1:3,'G'], c(-3.153030, -2.973976, -2.786622), tolerance = 1e-4) expect_equal(fs[1:3,'S1'], c(-1.319310, -1.097647, -0.893891), tolerance = 1e-4) @@ -25,9 +25,9 @@ test_that('dich data', { expect_equal(fit$M2, 553.6781, tolerance = 1e-2) expect_equal(fit$df, 432, tolerance = 1e-2) pfit1 <- suppressWarnings(personfit(mod1)) - expect_is(pfit1, 'data.frame') + expect_class(pfit1, 'data.frame') ifit <- suppressWarnings(itemfit(mod1)) - expect_is(ifit, 'data.frame') + expect_class(ifit, 'data.frame') mod2 <- bfactor(data, specific, pars=mod2values(mod1), TOL=NaN, verbose=FALSE, SE = TRUE, SE.type = 'Oakes') expect_equal(extract.mirt(mod2, 'condnum'), 619.3619, tolerance = 1e-4) @@ -93,7 +93,7 @@ test_that('dich data', { specific <- c(rep(1,7),rep(2,7)) items[items == 'dich'] <- '2PL' simmod <- bfactor(dataset, specific, itemtype = items, verbose=FALSE, TOL=3e-3) - expect_is(simmod, 'SingleGroupClass') + expect_class(simmod, 'SingleGroupClass') expect_equal(extract.mirt(simmod, 'df'), 442315) cfs <- as.numeric(do.call(c, coef(simmod))) cfs <- cfs[cfs != 0 & cfs != 1] @@ -101,7 +101,7 @@ test_that('dich data', { tolerance = 1e-2) specific[1] <- NA simmod2 <- bfactor(dataset, specific, itemtype = items, verbose=FALSE, TOL=3e-3) - expect_is(simmod2, 'SingleGroupClass') + expect_class(simmod2, 'SingleGroupClass') expect_equal(extract.mirt(simmod2, 'df'), 442316) cfs <- as.numeric(do.call(c, coef(simmod2))) cfs <- cfs[cfs != 0 & cfs != 1] @@ -109,13 +109,13 @@ test_that('dich data', { tolerance = 1e-2) fs <- fscores(simmod, verbose = FALSE, full.scores=FALSE) expect_true(mirt:::closeEnough(fs[1:6,'G'] - c(-2.6461, -2.0541, -2.3838, -2.4061, -1.7492, -1.8682), -1e-2, 1e-2)) - expect_is(fs, 'matrix') + expect_class(fs, 'matrix') res <- residuals(simmod, verbose = FALSE, QMC=TRUE) - expect_is(res, 'matrix') + expect_class(res, 'matrix') expect_equal(res[2,1], 0.08305725, tolerance = 1e-2) sum <- summary(simmod, verbose = FALSE) - expect_is(sum, 'list') + expect_class(sum, 'list') #two-tier if(FALSE){ @@ -156,7 +156,7 @@ test_that('dich data', { COV = G1*G2') simmod <- bfactor(dataset, specific, model, quadpts = 11, TOL = 1e-2, verbose=FALSE) - expect_is(simmod, 'SingleGroupClass') + expect_class(simmod, 'SingleGroupClass') expect_equal(extract.mirt(simmod, 'df'), 65486) cfs <- as.numeric(do.call(c, coef(simmod))) cfs <- cfs[cfs != 0 & cfs != 1] diff --git a/tests/tests/test-04-multipleGroup.R b/tests/testthat/test-04-multipleGroup.R similarity index 94% rename from tests/tests/test-04-multipleGroup.R rename to tests/testthat/test-04-multipleGroup.R index 8627485d9..84f71b190 100644 --- a/tests/tests/test-04-multipleGroup.R +++ b/tests/testthat/test-04-multipleGroup.R @@ -1,4 +1,4 @@ -context('multipleGroup') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('one factor', { if(FALSE){ @@ -36,7 +36,7 @@ test_that('one factor', { # expect_equal(extract.mirt(mod_QMCEM, 'logLik'), -17849.64, tolerance=1e-2) mod_configural <- multipleGroup(dat, models, SE=TRUE, SE.type = 'crossprod', optimizer='NR', group = group, verbose = FALSE, method = 'EM') - expect_is(mod_configural, 'MultipleGroupClass') + expect_class(mod_configural, 'MultipleGroupClass') expect_equal(logLik(mod_configural), -17903.76, tolerance = 1e-4) cfs <- as.numeric(do.call(c, coef(mod_configural)[[1L]])) cfs <- as.numeric(na.omit(cfs[cfs != 0 & cfs != 1])) @@ -45,7 +45,7 @@ test_that('one factor', { expect_equal(extract.mirt(mod_configural, 'df'), 65474) mod_metric <- multipleGroup(dat, models, group = group, invariance=c('slopes'), verbose = FALSE, method = 'EM', optimizer = 'NR') - expect_is(mod_metric, 'MultipleGroupClass') + expect_class(mod_metric, 'MultipleGroupClass') expect_equal(extract.mirt(mod_metric, 'df'), 65489) mod_scalar2 <- multipleGroup(dat, models, group = group, verbose = FALSE, method = 'EM', invariance=c('slopes', 'intercepts', 'free_var','free_means')) @@ -54,15 +54,15 @@ test_that('one factor', { cfs <- cfs[cfs != 0 & cfs != 1] expect_equal(cfs, c(1.104323,0.5385656,1.20104,-0.6295554,1.061246,-0.2649867,0.8824239,0.9004537,1.081875,0.1640334,0.4445889,0.636301,1.180488,0.9758879,0.977318,-0.3768236,0.8786338,-1.034887,0.6847666,-1.117687,0.948221,1.213217,1.389262,-0.2233858,1.261964,0.4288545,1.153485,0.4531765,0.7745967,-0.06987377), tolerance = 1e-2) - expect_is(mod_scalar2, 'MultipleGroupClass') + expect_class(mod_scalar2, 'MultipleGroupClass') expect_equal(extract.mirt(mod_scalar2, 'df'), 65502) newmodel <- mirt.model('F = 1-15 CONSTRAINB = (1-15, a1), (1,2,3-15,d)') mod_scalar1 <- multipleGroup(dat, newmodel, group = group, verbose = FALSE, invariance='free_var') - expect_is(mod_scalar1, 'MultipleGroupClass') + expect_class(mod_scalar1, 'MultipleGroupClass') mod_EH <- multipleGroup(dat, models, group = group, verbose = FALSE, method = 'EM', dentype="empiricalhist", optimizer = 'NR') - expect_is(mod_EH, 'MultipleGroupClass') + expect_class(mod_EH, 'MultipleGroupClass') cfs <- as.numeric(do.call(c, coef(mod_EH)[[1L]])) expect_equal(cfs, c(0.9915433,0.5344622,0,1,1.163903,-0.6905668,0,1,0.8828766,-0.1765539,0,1,0.8374425,0.8539179,0,1,1.031439,0.1393504,0,1,0.5279401,0.689807,0,1,1.179048,1.011893,0,1,0.8773885,-0.3201687,0,1,0.8273324,-1.047761,0,1,0.6713642,-1.076773,0,1,0.7647824,1.196511,0,1,1.385943,-0.2402286,0,1,1.196881,0.4558509,0,1,0.963759,0.4638302,0,1,0.8105823,-0.05165506,0,1,0,1), tolerance = 1e-2) @@ -78,7 +78,7 @@ test_that('one factor', { dat[1,1] <- dat[2,2] <- NA mod_missing <- multipleGroup(dat, models, group = group, verbose = FALSE, method = 'EM', invariance=c('slopes', 'intercepts', 'free_var')) - expect_is(mod_missing, 'MultipleGroupClass') + expect_class(mod_missing, 'MultipleGroupClass') expect_equal(extract.mirt(mod_missing, 'df'), 65503) out1 <- M2(mod_missing, na.rm=TRUE) out2 <- itemfit(mod_missing, na.rm=TRUE) @@ -95,19 +95,19 @@ test_that('one factor', { fs3 <- fscores(mod_missing, verbose = FALSE, full.scores=FALSE) fs4 <- fscores(mod_missing, full.scores = TRUE) fs5 <- fscores(mod_metric, full.scores = TRUE, scores.only=TRUE) - expect_is(fs1, 'list') - expect_is(fs2, 'matrix') - expect_is(fs3, 'list') - expect_is(fs4, 'matrix') + expect_class(fs1, 'list') + expect_class(fs2, 'matrix') + expect_class(fs3, 'list') + expect_class(fs4, 'matrix') fit1 <- M2(mod_metric) - expect_is(fit1, 'data.frame') + expect_class(fit1, 'data.frame') expect_true(mirt:::closeEnough(fit1$M2 - 184.5311, -1e-2, 1e-2)) expect_equal(fit1$SRMSR.D1, 0.04055562, tolerance = 1e-4) expect_equal(fit1$TLI, 1.001405, tolerance = 1e-4) expect_true(mirt:::closeEnough(fit1$df - 195, -1e-4, 1e-4)) fit2 <- itemfit(mod_metric, c('S_X2', 'Zh')) - expect_is(fit2, 'list') + expect_class(fit2, 'list') expect_equal(as.numeric(fit2[[1]][1L,-1L]), c(2.733099, 7.851266, 11.000000, 0, 0.726562), tolerance = 1e-4) fit3 <- M2(mod_scalar2) @@ -126,7 +126,7 @@ test_that('one factor', { ), tolerance=1e-4) expect_equal(as.vector(fscores(mod)[1:3,]), c(0.7325525, 0.9279133, 0.5071795), tolerance=1e-4) - expect_is(plot(mod, type = 'trace'), 'trellis') + expect_class(plot(mod, type = 'trace'), 'trellis') ifit <- itemfit(mod, 'X2') expect_equal(as.vector(ifit$D1$p.X2[1:4]), c(NaN,NaN,0.0002541653, 0.0009022802), tolerance=1e-4) @@ -146,7 +146,7 @@ test_that('one factor', { load('testdata/MG2.rds') group <- factor(c(rep('g1',1000), rep('g2',1000))) x <- multipleGroup(dat, 1, group=group, method='EM', verbose = FALSE) - expect_is(x, 'MultipleGroupClass') + expect_class(x, 'MultipleGroupClass') out <- empirical_ES(x) expect_equal(as.numeric(out[1,]), c(-0.01984901,0.1397911,-0.02010119,0.1390092,-0.03393749,-2.687888,-0.4657692,3.53414,3.553989), tolerance=1e-4) out2 <- empirical_ES(x, DIF = FALSE) @@ -154,7 +154,7 @@ test_that('one factor', { dat[1,1] <- dat[2,2] <- NA x2 <- multipleGroup(dat, 1, group=group, method='EM', verbose = FALSE) - expect_is(x2, 'MultipleGroupClass') + expect_class(x2, 'MultipleGroupClass') cfs <- as.numeric(do.call(c, coef(x2)[[1L]])) cfs <- cfs[cfs != 0 & cfs != 1] expect_true(mirt:::closeEnough(cfs - c(0.54559,2.87963,2.09834,1.04898,0.08764,-1.01597,-1.88808,-2.80774,0.5721,3.66458,2.86098,2.07309,0.97108,-0.04591,-1.13943,-2.04077,2.19508,3.985,2.93076,1.92402,0.93888,-3e-04,-0.92533,-2.15966,2.75051,5.52755,4.54548,3.22867,2.2928,1.26823,0.37394,-0.49598,0.40521,2.24053,1.23686,0.3006,-0.65966,-1.68032,-2.71625,-3.65993,5.18399,3.21456,2.30067,1.19408,0.1821,-0.8039,-1.83942,-2.96744,2.50677,2.45572,1.40808,0.48888,-0.67763,-1.67403,-2.61442,-3.75363,1.90942,4.6516,3.56213,2.57738,1.45019,0.65221,-0.43677,-1.41043,2.0672,3.3566,2.50567,1.64636,0.6884,-0.28202,-1.35771,-2.31969,2.54578,2.31928,1.26861,0.29768,-0.87537,-1.86427,-2.76917,-3.71823), -1e-2, 1e-2)) @@ -191,20 +191,20 @@ test_that('one factor', { mod_metric <- multipleGroup(dat, MGmodelg2, group = group, invariance=c('slopes'), method = 'MHRM', verbose = FALSE, draws = 10) - expect_is(mod_metric, 'MultipleGroupClass') + expect_class(mod_metric, 'MultipleGroupClass') cfs <- as.numeric(do.call(c, coef(mod_metric)[[1]]))[1:20] expect_equal(cfs, c(1.223844,0,0,0.5986703,0,1,1.478027,0,0,-0.542961,0,1,1.090491,0,0,-0.2585476,0,1,0.8359449,0), tolerance = 1e-2) mod_configural <- multipleGroup(dat, MGmodelg1, group = group, verbose = FALSE, method = 'EM', SE=TRUE, optimizer = 'NR') - expect_is(mod_configural, 'MultipleGroupClass') + expect_class(mod_configural, 'MultipleGroupClass') cfs <- as.numeric(do.call(c, coef(mod_configural)[[1]])) cfs <- cfs[cfs != 0 & cfs != 1] expect_equal(as.numeric(na.exclude(cfs)), c(1.175122,0.8723134,1.47793,0.5905031,0.4203281,0.7606781,1.432219,1.051584,1.812853,-0.5385373,-0.7236171,-0.3534576,1.054938,0.7785073,1.331368,-0.2574002,-0.4120382,-0.1027621,0.9510795,0.6902863,1.211873,0.8776461,0.7088456,1.046447,1.147247,0.8538526,1.440642,0.2582053,0.09907628,0.4173343,0.6090205,0.3766148,0.8414262,0.5171881,0.3763434,0.6580327,1.590855,0.9590698,2.22264,1.129202,0.8384696,1.419934,1.058027,0.7076615,1.408393,-0.5338947,-0.6989874,-0.368802,0.8613521,0.5565073,1.166197,-1.216261,-1.405812,-1.026709,0.5272607,0.2895619,0.7649595,-1.023556,-1.178142,-0.8689692,1.00044,0.707042,1.293839,1.302659,1.102789,1.502529,1.459818,1.046385,1.873251,-0.5183716,-0.7054787,-0.3312645,1.027813,0.7488713,1.306755,0.4739741,0.3155796,0.6323687,1.425603,1.026227,1.824979,0.4233488,0.2429515,0.6037461,0.6053667,0.397785,0.8129484,-0.1520328,-0.2869917,-0.01707401), tolerance = 1e-2) fs1 <- fscores(mod_metric, verbose = FALSE, full.scores=FALSE) - expect_is(fs1, 'list') + expect_class(fs1, 'list') expect_equal(fs1[[1L]][1:6, 'F3'], c(-0.36817499, -0.45410998, -0.19616041, 0.07609491, 0.33779790, -0.44366024), tolerance = 1e-2) diff --git a/tests/tests/test-05-confmirtOne.R b/tests/testthat/test-05-confmirtOne.R similarity index 88% rename from tests/tests/test-05-confmirtOne.R rename to tests/testthat/test-05-confmirtOne.R index e87dfb0e3..06ee60c6a 100644 --- a/tests/tests/test-05-confmirtOne.R +++ b/tests/testthat/test-05-confmirtOne.R @@ -1,10 +1,10 @@ -context('confmirtOne') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('exploratory mods', { data(LSAT7) fulldata <- expand.table(LSAT7) onefact <- mirt(fulldata, 1, verbose = FALSE, SE.type='MHRM', SE=TRUE) - expect_is(onefact, 'SingleGroupClass') + expect_class(onefact, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(onefact))) expect_equal(cfs, c(0.9879254,0.5978895,1.377961,1.85606,1.580046,2.132075,0,NA,NA,1,NA,NA,1.080885,0.772476,1.389293,0.8079786,0.6345122,0.981445,0,NA,NA,1,NA,NA,1.705801,0.8574762,2.554125,1.804219,1.308859,2.299578,0,NA,NA,1,NA,NA,0.7651853,0.4655423,1.064828,0.4859966,0.3374257,0.6345675,0,NA,NA,1,NA,NA,0.735798,0.4468093,1.024787,1.854513,1.62773,2.081295,0,NA,NA,1,NA,NA,0,NA,NA,1,NA,NA), tolerance = 1e-2) @@ -25,32 +25,32 @@ test_that('exploratory mods', { fitonefact <- M2(onefact) - expect_is(fitonefact, 'data.frame') + expect_class(fitonefact, 'data.frame') expect_equal(fitonefact$M2, 11.93769, tolerance = 1e-2) twofact <- mirt(fulldata, 2, verbose = FALSE, draws = 10, method = 'MHRM') cfs <- as.numeric(do.call(c, coef(twofact, verbose = FALSE))) expect_equal(cfs, c(-1.389256,0.3038708,2.108244,0,1,-1.055821,-1.13757,0.9310239,0,1,-1.376235,-0.6974982,1.71311,0,1,-0.8597142,0.05825403,0.499093,0,1,-0.8210638,0,1.893461,0,1,0,0,1,0,1), tolerance = 1e-2) - expect_is(twofact, 'SingleGroupClass') + expect_class(twofact, 'SingleGroupClass') modm7 <- mirt(fulldata, 1, '4PL', verbose=FALSE, parprior = list(c(3,7,11,15,19,'norm', -1.7, .25), c(4,8,12,16,20,'norm', 1.7, .25)), method = 'MHRM', draws = 10) expect_equal(extract.mirt(modm7, 'df'), 11) - expect_is(modm7, 'SingleGroupClass') + expect_class(modm7, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(modm7))) expect_equal(cfs, c(2.503,4.279,0.153,0.883,3.114,1.908,0.183,0.852,8.703,8.461,0.157,0.89,1.331,0.874,0.15,0.843,2.568,5.007,0.154,0.878,0,1), tolerance = 1e-2) fulldata[1,1] <- fulldata[2,2] <- NA onefactmissing <- mirt(fulldata, 1, verbose = FALSE, draws = 10, method = 'MHRM') - expect_is(onefactmissing, 'SingleGroupClass') + expect_class(onefactmissing, 'SingleGroupClass') cfs <- as.numeric(do.call(c, coef(onefactmissing, verbose = FALSE))) expect_equal(cfs, c(0.9366883,1.832658,0,1,1.070041,0.804908,0,1,1.770225,1.837219,0,1,0.7649542,0.4847653,0,1,0.7494625,1.859265,0,1,0,1), tolerance = 1e-2) fs1 <- fscores(onefact, verbose = FALSE, mean=c(1), cov=matrix(2), full.scores=FALSE) - expect_is(fs1, 'matrix') + expect_class(fs1, 'matrix') expect_true(mirt:::closeEnough(fs1[1:3,'F1'] - c(-2.1821, -1.6989, -1.6807), -1e-2, 1e-2)) fs2 <- fscores(twofact, verbose = FALSE, full.scores=FALSE) - expect_is(fs2, 'matrix') + expect_class(fs2, 'matrix') fs3 <- fscores(onefactmissing, verbose = FALSE, full.scores=FALSE) - expect_is(fs3, 'matrix') + expect_class(fs3, 'matrix') }) diff --git a/tests/tests/test-06-confmirtTwo.R b/tests/testthat/test-06-confmirtTwo.R similarity index 88% rename from tests/tests/test-06-confmirtTwo.R rename to tests/testthat/test-06-confmirtTwo.R index 99379da00..7f553f6d1 100644 --- a/tests/tests/test-06-confmirtTwo.R +++ b/tests/testthat/test-06-confmirtTwo.R @@ -1,4 +1,4 @@ -context('confmirtTwo') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('confirmatory mods', { if(FALSE){ @@ -55,7 +55,7 @@ test_that('confirmatory mods', { model.combo <- mirt.model(modelcombo, quiet = TRUE) mod1 <- mirt(dataset,model.1, verbose = FALSE, draws = 10, method = 'MHRM') - expect_is(mod1, 'SingleGroupClass') + expect_class(mod1, 'SingleGroupClass') expect_equal(extract.mirt(mod1, 'df'), 1512) cfs <- as.numeric(do.call(c, coef(mod1))) expect_equal(cfs, c(1.725311,0,-1.003746,0,1,0.4296214,0,-1.418875,0,1,0.8736704,0,1.451735,0,1,0.8736917,0.4298316,0.05164668,0,1,0,1.380402,2.886302,1.919996,-0.3822423,0,0.6367169,2.507395,1.030947,-1.026989,0,0.8973311,2.019848,0.09872695,0,0.923406,1.123934,0,1,0,0,1,0.4793236,1), @@ -65,56 +65,56 @@ test_that('confirmatory mods', { expect_equal(info[1:4], c(0.3079868,0.3687883,0.4502187,0.593109), tolerance = 1e-4) mod1b <- mirt(dataset,model.1, verbose = FALSE) - expect_is(mod1b, 'SingleGroupClass') + expect_class(mod1b, 'SingleGroupClass') expect_equal(extract.mirt(mod1b, 'df'), 1512) cfs <- as.numeric(do.call(c, coef(mod1b))) expect_equal(cfs, c(1.6146,0,-0.9786,0,1,0.455,0,-1.4272,0,1,0.9052,0,1.46,0,1,0.8899,0.4345,0.0463,0,1,0,1.3875,2.8938,1.9211,-0.3892,0,0.6358,2.5058,1.0294,-1.028,0,0.8851,2.0124,0.0958,0,0.9291,1.1242,0,1,0,0,1,0.4679,1), tolerance = 1e-2) mod.quad <- mirt(dataset, model.quad, verbose = FALSE, draws = 10, method = 'MHRM') - expect_is(mod.quad, 'SingleGroupClass') + expect_class(mod.quad, 'SingleGroupClass') expect_equal(extract.mirt(mod.quad, 'df'), 1510) cfs <- as.numeric(do.call(c, coef(mod.quad))) expect_equal(cfs, c(0.9008854,0.4617326,-1.174335,0,1,0.3751464,0.07415233,-1.487041,0,1,0.7719363,0.255426,1.169278,0,1,1.037831,0.1488222,-0.06758965,0,1,1.136647,0,2.685626,1.767618,-0.3708233,0.5774083,0,2.475542,1.012218,-1.018043,0.7840536,0,1.954257,0.0851495,0.9447677,0,1.122107,0,1,0,1), tolerance = 1e-2) mod.combo <- mirt(dataset, model.combo, verbose = FALSE, draws = 10, method = 'MHRM') - expect_is(mod.combo, 'SingleGroupClass') + expect_class(mod.combo, 'SingleGroupClass') expect_equal(extract.mirt(mod.combo, 'df'), 1512) cfs <- as.numeric(do.call(c, coef(mod.combo))) expect_equal(cfs, c(2.175565,0,1.124398,-1.196377,0,1,0.3772646,0,0,-1.411797,0,1,0.8485753,0,0,1.431696,0,1,0.9730396,0,0,0.03585494,0,1,0,1.414372,-0.2296381,2.96445,1.970084,-0.3634654,0,0.6340928,0,2.509455,1.035055,-1.022543,0,0.9094451,0,2.034747,0.1080139,0,0.877999,0,1.115907,0,1,0,0,1,0,1), tolerance = 1e-2) mod.combob <- mirt(dataset, model.combo, verbose = FALSE) - expect_is(mod.combob, 'SingleGroupClass') + expect_class(mod.combob, 'SingleGroupClass') expect_equal(extract.mirt(mod.combob, 'df'), 1512) cfs <- as.numeric(do.call(c, coef(mod.combob))) expect_equal(cfs, c(2.0294,0,0.9383,-1.1511,0,1,0.4035,0,0,-1.418,0,1,0.8781,0,0,1.4422,0,1,0.9923,0,0,0.0352,0,1,0,1.3989,-0.2031,2.9465,1.9576,-0.3648,0,0.6501,0,2.5172,1.0377,-1.0276,0,0.9077,0,2.0328,0.1067,0,0.8806,0,1.1162,0,1,0,0,1,0,1), tolerance = 1e-2) fs1 <- fscores(mod1, verbose = FALSE, full.scores=FALSE) - expect_is(fs1, 'matrix') + expect_class(fs1, 'matrix') fs2 <- fscores(mod1, method = 'WLE', response.pattern = dataset[1:2,]) expect_equal(as.vector(fs2[,c('F1', 'F2')]), c(-0.3647738,-0.8722322,-2.168684,0.7796325), tolerance=1e-4) fs3 <- fscores(mod.quad, full.scores=TRUE, verbose = FALSE) - expect_is(fs3, 'matrix') + expect_class(fs3, 'matrix') fs4 <- fscores(mod.combo, verbose = FALSE, full.scores=FALSE) - expect_is(fs4, 'matrix') + expect_class(fs4, 'matrix') TI <- plot(mod1) - expect_is(TI, 'trellis') + expect_class(TI, 'trellis') res <- residuals(mod1, verbose = FALSE) - expect_is(res, 'matrix') + expect_class(res, 'matrix') IP <- itemplot(mod1, 1) - expect_is(IP, 'trellis') + expect_class(IP, 'trellis') TI <- plot(mod.quad) - expect_is(TI, 'trellis') + expect_class(TI, 'trellis') TI <- plot(mod.combo) - expect_is(TI, 'trellis') + expect_class(TI, 'trellis') IP <- itemplot(mod.combo, 1) - expect_is(IP, 'trellis') + expect_class(IP, 'trellis') }) diff --git a/tests/tests/test-07-mixedmirt.R b/tests/testthat/test-07-mixedmirt.R similarity index 96% rename from tests/tests/test-07-mixedmirt.R rename to tests/testthat/test-07-mixedmirt.R index 5aab77470..7febd7f56 100644 --- a/tests/tests/test-07-mixedmirt.R +++ b/tests/testthat/test-07-mixedmirt.R @@ -1,4 +1,4 @@ -context('mixedmirt') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('mixed dich', { if(FALSE){ @@ -31,7 +31,7 @@ test_that('mixed dich', { require(boot, quietly=TRUE, warn.conflicts=FALSE) set.seed(1) bs <- boot.mirt(mod0, R = 3) - expect_is(bs, 'boot') + expect_class(bs, 'boot') fs <- fscores(mod0, full.scores.SE=TRUE, full.scores=FALSE) expect_equal(as.numeric(head(fs)), c(-0.3326607,-0.6466616,-0.4794936,-0.3070341,-0.4769525,-0.5488866,0.2940349,0.2963674,0.2951423,0.2938395,0.2951234,0.2956562), tolerance=1e-3) @@ -39,7 +39,7 @@ test_that('mixed dich', { #group as a fixed effect predictor (aka, uniform dif) mod1 <- mixedmirt(data, covdata, model, fixed = ~ 0 + items + group, verbose = FALSE, draws = 1) - expect_is(mod1, 'MixedClass') + expect_class(mod1, 'MixedClass') cfs <- as.numeric(do.call(c, coef(mod1))) expect_equal(cfs, c(1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-1.747882,-1.944582,-1.551183,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-2.066577,-2.270076,-1.863078,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-1.705846,-1.901775,-1.509917,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-1.043203,-1.230739,-0.8556669,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-0.2660702,-0.4541086,-0.07803179,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-1.377461,-1.568343,-1.186579,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-1.684929,-1.880486,-1.489373,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-2.127009,-2.331998,-1.922021,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,-2.007019,-2.209114,-1.804923,0,NA,NA,1,NA,NA,1.066421,0.9144826,1.218359,2.336545,2.178417,2.494673,1,NA,NA,1.546882,1.281149,1.812614,0,NA,NA,1,NA,NA,0,NA,NA,0.1554333,0.1170689,0.1937978), tolerance = 1e-2) @@ -49,7 +49,7 @@ test_that('mixed dich', { expect_equal(wld$W[1], .7341243, tolerance = 1e-4) set.seed(1) bs <- boot.mirt(mod1, R=2) - expect_is(bs, 'boot') + expect_class(bs, 'boot') mod1a <- mixedmirt(data, covdata, model, fixed = ~ 0 + items + group, SE=FALSE, verbose = FALSE, draws = 1, internal_constraints = FALSE) @@ -72,7 +72,7 @@ test_that('mixed dich', { data[1,1] <- covdata[1,2] <- NA expect_warning(mod1b <- mixedmirt(data, covdata, model, fixed = ~ 0 + items + group, itemtype = '2PL', verbose = FALSE, draws = 1)) - expect_is(mod1b, 'MixedClass') + expect_class(mod1b, 'MixedClass') expect_equal(extract.mirt(mod1b, 'df'), 1001) cfs <- as.numeric(do.call(c, coef(mod1b))) expect_equal(cfs, c(1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.6801064,0.2472736,1.112939,-1.764637,-1.981088,-1.548186,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.3225088,-0.01222681,0.6572444,-2.04966,-2.252809,-1.846511,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.1730519,-0.08809251,0.4341962,-1.68213,-1.873847,-1.490413,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,-0.6751006,NaN,NaN,-1.027004,-1.217833,-0.8361756,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.442664,-0.003793412,0.8891215,-0.2375153,-0.4341578,-0.04087278,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.1315495,-0.1747718,0.4378707,-1.357544,-1.544107,-1.170982,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.2533267,-0.1310559,0.6377093,-1.664991,-1.856788,-1.473194,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.3229516,-0.1145078,0.760411,-2.110101,-2.317428,-1.902774,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.7662229,0.01146026,1.520985,-2.051964,-2.303527,-1.800401,0,NA,NA,1,NA,NA,1.055344,0.910874,1.199815,2.313518,2.1583,2.468737,0.4567099,-0.08615558,0.9995754,1.610767,1.276957,1.944577,0,NA,NA,1,NA,NA,0,NA,NA,1,NA,NA), @@ -81,7 +81,7 @@ test_that('mixed dich', { covdataold$group <- factor(rep(paste0('G',1:50), each = nrow(data)/50)) rmod1 <- try(mixedmirt(data, covdataold, 1, fixed = ~ 0 + items, random = ~ 1|group, draws = 1, verbose = FALSE), TRUE) - expect_is(rmod1, 'MixedClass') + expect_class(rmod1, 'MixedClass') expect_equal(extract.mirt(rmod1, 'df'), 1011) cfs <- as.numeric(do.call(c, coef(rmod1))) @@ -90,14 +90,14 @@ test_that('mixed dich', { model <- mirt.model('F1 = 1-4', quiet = TRUE) mod <- mixedmirt(Science, covdat, model=model, SE=FALSE, fixed = ~ 0 + group, verbose = FALSE, draws = 1) - expect_is(mod, 'MixedClass') + expect_class(mod, 'MixedClass') cfs <- as.numeric(na.omit(do.call(c, coef(mod)))) expect_equal(cfs, c(-0.08424103,1,0,1,2,3,0,3.097676,5.718138,4.364193,-0.08424103,1,0,1,2,3,0,1.918539,2.858765,1.037761,-0.08424103,1,0,1,2,3,0,2.664839,4.113727,3.013447,-0.08424103,1,0,1,2,3,0,2.469392,3.397754,2.075902,0,0.9854896), tolerance = 1e-2) mod2 <- mixedmirt(Science, covdat, model=model, draws = 1, fixed = ~ 0 + group, itemtype = 'gpcm', verbose = FALSE) - expect_is(mod2, 'MixedClass') + expect_class(mod2, 'MixedClass') expect_equal(extract.mirt(mod, 'df') - extract.mirt(mod2, 'df'), 3) cfs <- as.numeric(na.omit(do.call(c, coef(mod2)))) expect_equal(cfs, c(-0.1764055,-0.4078213,0.05501025,0.8245979,0.5139055,1.13529,0,1,2,3,0,2.838464,1.720788,3.95614,5.387634,4.161899,6.613368,4.164414,2.956008,5.37282,-0.1764055,-0.4078213,0.05501025,0.844655,0.5531942,1.136116,0,1,2,3,0,1.800049,1.265608,2.33449,2.753831,2.133251,3.37441,1.105474,0.4461877,1.764761,-0.1764055,-0.4078213,0.05501025,2.48884,1.112024,3.865655,0,1,2,3,0,5.154023,2.685469,7.622577,7.582648,4.134116,11.03118,5.645098,2.915675,8.374521,-0.1764055,-0.4078213,0.05501025,0.7096472,0.447945,0.9713493,0,1,2,3,0,2.167818,1.586001,2.749634,3.048915,2.382779,3.715051,1.96501,1.268023,2.661996,0,1), @@ -105,7 +105,7 @@ test_that('mixed dich', { mod3 <- mixedmirt(Science, covdat, model=model, draws = 1, fixed = ~ 0 + group, itemtype = 'graded', verbose = FALSE) - expect_is(mod3, 'MixedClass') + expect_class(mod3, 'MixedClass') expect_equal(extract.mirt(mod3, 'df'), 238) cfs <- as.numeric(na.omit(do.call(c, coef(mod3)))) expect_equal(cfs, c(-0.2481932,-0.5779923,0.08160588,0.9996557,0.63628,1.363031,4.951115,3.989263,5.912968,2.735017,2.288555,3.18148,-1.326709,-1.681992,-0.971426,-0.2481932,-0.5779923,0.08160588,1.21205,0.8732852,1.550815,3.033993,2.545489,3.522498,1.019672,0.6971102,1.342234,-2.132917,-2.553508,-1.712325,-0.2481932,-0.5779923,0.08160588,2.580794,1.250539,3.91105,5.76086,3.732607,7.789113,2.523845,1.49681,3.55088,-1.994636,-2.807197,-1.182076,-0.2481932,-0.5779923,0.08160588,1.075305,0.7278781,1.422733,3.456143,2.90494,4.007346,1.10973,0.7960739,1.423387,-1.553964,-1.924532,-1.183396,0,1), @@ -114,13 +114,13 @@ test_that('mixed dich', { covdat$group <- factor(rep(paste0('G',1:20), length.out = nrow(Science))) rmod1 <- try(mixedmirt(Science, covdat, model=model, draws=10, random = ~ 1|group, itemtype = 'graded', verbose = FALSE, SE=FALSE), TRUE) - expect_is(rmod1, 'MixedClass') + expect_class(rmod1, 'MixedClass') expect_equal(extract.mirt(rmod1, 'df'), 238) cfs <- as.numeric(na.omit(do.call(c, coef(rmod1)))) expect_equal(cfs, c(1.032039,4.865985,2.63557,-1.47773,1.231335,2.936047,0.8979343,-2.2878,2.234105,5.191735,2.178876,-1.943804,1.059907,3.328831,0.9763014,-1.689545,0,1,0.01040838), tolerance = 1e-4) re <- randef(rmod1, ndraws=100) - expect_is(re, 'list') + expect_class(re, 'list') expect_equal(length(re), 2) @@ -154,7 +154,7 @@ test_that('mixed dich', { expect_equal(extract.mirt(mod2, 'logLik'), -4647.105, tolerance = 1e-4) # set.seed(1) # bs <- boot.mirt(mod2, R = 3) - # expect_is(bs, 'boot') + # expect_class(bs, 'boot') #uncorrelated random slope covdata$theta <- Theta diff --git a/tests/tests/test-08-createItem.R b/tests/testthat/test-08-createItem.R similarity index 82% rename from tests/tests/test-08-createItem.R rename to tests/testthat/test-08-createItem.R index bbd2266d5..0c936092a 100644 --- a/tests/tests/test-08-createItem.R +++ b/tests/testthat/test-08-createItem.R @@ -1,4 +1,4 @@ -context('createItem') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('old2PL', { name <- 'old2PL' @@ -17,14 +17,14 @@ test_that('old2PL', { dat <- expand.table(LSAT7) sv <- mirt(dat, 1, c(rep('2PL',4), 'old2PL'), customItems=list(old2PL=x), pars = 'values', verbose=FALSE) - expect_is(sv, 'data.frame') + expect_class(sv, 'data.frame') mod <- mirt(dat, 1, c(rep('2PL',4), 'old2PL'), customItems=list(old2PL=x), verbose=FALSE) - expect_is(mod, 'SingleGroupClass') - expect_is(coef(mod), 'list') + expect_class(mod, 'SingleGroupClass') + expect_class(coef(mod), 'list') expect_equal(logLik(mod), -2658.805, tolerance = 1e-4) mod2 <- mirt(dat, 1, c(rep('2PL',4), 'old2PL'), customItems=list(old2PL=x), verbose = FALSE, draws = 10, method = 'MHRM') - expect_is(mod2, 'SingleGroupClass') - expect_is(coef(mod2), 'list') + expect_class(mod2, 'SingleGroupClass') + expect_class(coef(mod2), 'list') mod3 <- mirt(dat, 'F = 1-5 PRIOR = (5, b, norm, 0, 1)', c(rep('2PL',4), 'old2PL'), customItems=list(old2PL=x), verbose=FALSE) expect_equal(logLik(mod3), -2659.1, tolerance = 1e-4) @@ -44,8 +44,8 @@ test_that('old2PL', { x2 <- createItem(name, par=par, est=est, P=P.nonlin) mod <- mirt(dat, 1, c(rep('2PL',4), 'nonlin'), customItems=list(nonlin=x2), verbose=FALSE) - expect_is(mod, 'SingleGroupClass') - expect_is(coef(mod), 'list') + expect_class(mod, 'SingleGroupClass') + expect_class(coef(mod), 'list') fs <- fscores(mod) expect_equal(unname(fs[1,]), c(-1.828444), tolerance = 1e-4) diff --git a/tests/tests/test-09-mirt.model.R b/tests/testthat/test-09-mirt.model.R similarity index 99% rename from tests/tests/test-09-mirt.model.R rename to tests/testthat/test-09-mirt.model.R index 37d28f202..84b829bae 100644 --- a/tests/tests/test-09-mirt.model.R +++ b/tests/testthat/test-09-mirt.model.R @@ -1,4 +1,4 @@ -context('mirt.model') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('syntax', { data <- expand.table(LSAT7) diff --git a/tests/tests/test-10-extras.R b/tests/testthat/test-10-extras.R similarity index 96% rename from tests/tests/test-10-extras.R rename to tests/testthat/test-10-extras.R index fc0823b3a..33c37d482 100644 --- a/tests/tests/test-10-extras.R +++ b/tests/testthat/test-10-extras.R @@ -1,4 +1,4 @@ -context('extras') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('extras', { suppressMessages(require(nonnest2, quietly=TRUE, warn.conflicts=FALSE)) @@ -6,9 +6,9 @@ test_that('extras', { itemtype <- c('2PL', '2PL', '2PL', '2PL', 'ggum') mod_2PL_ggum <- mirt(expand.table(LSAT7), model=1, itemtype=itemtype, SE=TRUE, verbose=FALSE) - out <- vuongtest(mod_2PL, mod_2PL_ggum) - expect_equal(out$p_omega, 0.000246, tol=.01) - expect_equal(as.numeric(out$p_LRT), c(0.6205581, 0.3794419), tol=.01) + out <- nonnest2::vuongtest(mod_2PL, mod_2PL_ggum) + expect_equal(out$p_omega, 0.000246, tolerance=.01) + expect_equal(as.numeric(out$p_LRT), c(0.6205581, 0.3794419), tolerance=.01) require(boot, quietly=TRUE, warn.conflicts=FALSE) data <- expand.table(LSAT7) @@ -75,7 +75,7 @@ test_that('extras', { expect_equal(expected[1:3], c(0.1083150, 0.1133415, 0.1185956), tolerance=1e-4) data[1,1] <- NA data <- imputeMissing(mod1, Theta=fscores(mod1, full.scores=TRUE), warn=FALSE) - expect_is(data, 'matrix') + expect_class(data, 'matrix') expect_true(!all(is.na(data))) pb <- probtrace(extr.2, Theta) expect_equal(pb[1:3, 1], c(0.9965890, 0.9963601, 0.9961159), tolerance = 1e-5) @@ -83,7 +83,7 @@ test_that('extras', { expect_equal(ti[1:3], c(0.06607895, 0.06918330, 0.07242870), tolerance = 1e-5) set.seed(1234) fs <- fscores(mod1, MI=20, verbose=FALSE, full.scores=FALSE) - expect_is(fs, 'matrix') + expect_class(fs, 'matrix') expect_equal(fs[1:3,'F1'], c(-1.853914, -1.509722, -1.514913), tolerance=1e-3) set.seed(1) diff --git a/tests/tests/test-11-discrete.R b/tests/testthat/test-11-discrete.R similarity index 99% rename from tests/tests/test-11-discrete.R rename to tests/testthat/test-11-discrete.R index 507b8afca..bd3aa62fb 100644 --- a/tests/tests/test-11-discrete.R +++ b/tests/testthat/test-11-discrete.R @@ -1,4 +1,4 @@ -context('discrete') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('discrete', { diff --git a/tests/tests/test-12-gpcm_mats.R b/tests/testthat/test-12-gpcm_mats.R similarity index 94% rename from tests/tests/test-12-gpcm_mats.R rename to tests/testthat/test-12-gpcm_mats.R index 55bc177bc..61c2f69d2 100644 --- a/tests/tests/test-12-gpcm_mats.R +++ b/tests/testthat/test-12-gpcm_mats.R @@ -1,4 +1,4 @@ -context('gpcm_mats') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('gpcm_mats', { diff --git a/tests/tests/test-13-grsmIRT.R b/tests/testthat/test-13-grsmIRT.R similarity index 98% rename from tests/tests/test-13-grsmIRT.R rename to tests/testthat/test-13-grsmIRT.R index 7c4720d92..8145b1140 100644 --- a/tests/tests/test-13-grsmIRT.R +++ b/tests/testthat/test-13-grsmIRT.R @@ -1,4 +1,4 @@ -context('grsmIRT') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('grsmIRT', { # Response data : num of response categories = 5 diff --git a/tests/tests/test-14-GGUM.R b/tests/testthat/test-14-GGUM.R similarity index 97% rename from tests/tests/test-14-GGUM.R rename to tests/testthat/test-14-GGUM.R index 2440f4416..8bd1b442e 100644 --- a/tests/tests/test-14-GGUM.R +++ b/tests/testthat/test-14-GGUM.R @@ -1,4 +1,4 @@ -context('GGUM') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('GGUM', { diff --git a/tests/tests/test-15-IRTpars.R b/tests/testthat/test-15-IRTpars.R similarity index 97% rename from tests/tests/test-15-IRTpars.R rename to tests/testthat/test-15-IRTpars.R index ee0b33969..c7b02fd44 100644 --- a/tests/tests/test-15-IRTpars.R +++ b/tests/testthat/test-15-IRTpars.R @@ -1,4 +1,4 @@ -context('IRTpars') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('IRTpars', { diff --git a/tests/tests/test-16-DCIRT.R b/tests/testthat/test-16-DCIRT.R similarity index 97% rename from tests/tests/test-16-DCIRT.R rename to tests/testthat/test-16-DCIRT.R index 37c32fbe0..7d55c32f0 100644 --- a/tests/tests/test-16-DCIRT.R +++ b/tests/testthat/test-16-DCIRT.R @@ -1,4 +1,4 @@ -context('DCIRT') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('DCIRT', { @@ -37,7 +37,7 @@ test_that('DCIRT', { expect_equal(unname(resid2[2:4,1]), c(2.145994,1.908699,0.1207362), tolerance=1e-4) pp <- plot(mod, type = 'empiricalhist') - expect_is(pp, 'trellis') + expect_class(pp, 'trellis') mod2 <- mirt(dat_bm, 1, dentype = 'EHW', verbose=FALSE) expect_equal(extract.mirt(mod2, 'logLik'), -12758.689, tolerance=1e-4) @@ -66,7 +66,7 @@ test_that('DCIRT', { expect_equal(out2$S_X2[1:3], c(25.44766, 14.06284, 13.88462), tolerance=1e-2) pp <- plot(res_bm, type = 'Davidian') - expect_is(pp, 'trellis') + expect_class(pp, 'trellis') }) test_that('DCIRT Option Errors and Warnings', { @@ -173,7 +173,7 @@ test_that('DCIRT-MG', { expect_equal(out2$G2$S_X2[1:3], c(10.2253,15.41447,9.010604), tolerance=1e-1) pp <- plot(mod_configural, type = 'Davidian') - expect_is(pp, 'trellis') + expect_class(pp, 'trellis') # not equated mod_scalar0 <- multipleGroup(dat, 1, group = group, verbose=FALSE, dentype='Davidian-6', @@ -183,7 +183,7 @@ test_that('DCIRT-MG', { expect_equal(extract.mirt(mod_scalar0, 'df'), 67108760) # plot(mod_scalar0) pp <- plot(mod_scalar0, type = 'Davidian') - expect_is(pp, 'trellis') + expect_class(pp, 'trellis') # equated expect_error(multipleGroup(dat, 1, group = group, verbose=FALSE, dentype='Davidian-6', @@ -196,7 +196,7 @@ test_that('DCIRT-MG', { # expect_equal(cfs, c(0.4745419,0.6083134,1.200818,2.058516,2.109649,3.667984,-0.6940906,0.7198784), tolerance=1e-4) # # pp <- plot(mod_scalar, type = 'Davidian') - # expect_is(pp, 'trellis') + # expect_class(pp, 'trellis') # equated EHW mod_scalarEHW <- multipleGroup(dat, 1, group = group, verbose=FALSE, dentype='EHW', @@ -208,7 +208,7 @@ test_that('DCIRT-MG', { expect_equal(cfs, c(0.5085824, 0.5889403), tolerance=1e-4) pp <- plot(mod_scalarEHW, type = 'empiricalhist') - expect_is(pp, 'trellis') + expect_class(pp, 'trellis') }) diff --git a/tests/tests/test-17-DIF_DRF.R b/tests/testthat/test-17-DIF_DRF.R similarity index 94% rename from tests/tests/test-17-DIF_DRF.R rename to tests/testthat/test-17-DIF_DRF.R index 6a1b6151c..1aa84d429 100644 --- a/tests/tests/test-17-DIF_DRF.R +++ b/tests/testthat/test-17-DIF_DRF.R @@ -1,4 +1,4 @@ -context('DIF') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('DIF', { @@ -23,14 +23,14 @@ test_that('DIF', { invariance = c('slopes', 'intercepts', 'free_means', 'free_var')) DIFF <- suppressMessages(DIF(model1a, which.par='d', items2test = c(1,3))) - expect_is(DIFF, 'data.frame') + expect_class(DIFF, 'data.frame') expect_equal(DIFF[2,'AIC'], -3.414, tolerance = 1e-3) DIFF2 <- suppressMessages(DIF(model2, which.par=c('a1', 'd'), items2test = c(1,3), scheme='drop')) - expect_is(DIFF2, 'data.frame') + expect_class(DIFF2, 'data.frame') expect_equal(DIFF2[1L, 'X2'], 18.88, tolerance = 1e-3) WALD <- suppressMessages(DIF(model1a, which.par='d', items2test = 1:3, Wald=TRUE)) - expect_is(WALD, 'data.frame') + expect_class(WALD, 'data.frame') expect_equal(WALD$W[1], 1.532718, tolerance = 1e-3) expect_equal(WALD$p[1], 0.2157049, tolerance = 1e-3) WALD2 <- suppressMessages(DIF(model1a, which.par=c('a1', 'd'), Wald=TRUE, p.adjust = 'fdr')) @@ -41,11 +41,11 @@ test_that('DIF', { 'free_means', 'free_var')) out <- DIF(model1b, which.par = c('a1', 'd'), items2test = 6:10, Wald = TRUE) - expect_is(out, 'data.frame') + expect_class(out, 'data.frame') expect_equal(out$p, c(0.1090403,0.07219868,0.175297,0.1354964,0.6970995), tolerance = 1e-4) out <- DIF(model1b, which.par = c('a1', 'd'), items2test = 6:10) - expect_is(out, 'data.frame') + expect_class(out, 'data.frame') expect_equal(out$p, c(0.103812,0.04867894,0.1565903,0.1118176,0.6921238), tolerance = 1e-4) model <- "F = 1-10 @@ -53,7 +53,7 @@ test_that('DIF', { model2 <- multipleGroup(dat, model, group, SE = TRUE, verbose=FALSE, invariance = c(colnames(dat)[1:5], 'free_means', 'free_var')) out <- DIF(model2, which.par = c('a1', 'd'), items2test = 6:10, seq_stat = 'BIC') - expect_is(out, 'data.frame') + expect_class(out, 'data.frame') expect_equal(out$BIC, c(11.449,9.038,11.424,10.739,14.448), tolerance = 1e-3) drf <- DRF(model2) diff --git a/tests/tests/test-18-LLTM.R b/tests/testthat/test-18-LLTM.R similarity index 78% rename from tests/tests/test-18-LLTM.R rename to tests/testthat/test-18-LLTM.R index 708c14fb8..d911a6db6 100644 --- a/tests/tests/test-18-LLTM.R +++ b/tests/testthat/test-18-LLTM.R @@ -1,4 +1,4 @@ -context('LLTM') +expect_class <- function(x, class) expect_true(inherits(x, class)) test_that('LLTM', { set.seed(42) @@ -11,27 +11,27 @@ test_that('LLTM', { lltm <- mirt(dat, itemtype = 'Rasch', SE=TRUE, verbose=FALSE, item.formula = ~ 0 + difficulty, itemdesign=itemdesign) - expect_equal(as.numeric(coef(lltm, simplify=TRUE)$items[1:2,1]), c(0.9587247, 0.9587247), tol=1e-2) - expect_equal(as.numeric(coef(lltm, printSE=TRUE)[[1]][2, 1:3]), c(0.03886556, 0.03898911, 0.03769205), tol=1e-2) - expect_equal(extract.mirt(lltm, 'condnum'), 6.633144, tol=1e-2) + expect_equal(as.numeric(coef(lltm, simplify=TRUE)$items[1:2,1]), c(0.9587247, 0.9587247), tolerance=1e-2) + expect_equal(as.numeric(coef(lltm, printSE=TRUE)[[1]][2, 1:3]), c(0.03886556, 0.03898911, 0.03769205), tolerance=1e-2) + expect_equal(extract.mirt(lltm, 'condnum'), 6.633144, tolerance=1e-2) # additional information for LLTM oo <- plot(lltm) - expect_is(oo, 'trellis') + expect_class(oo, 'trellis') ifit <- itemfit(lltm) - expect_equal(ifit$S_X2[1:3], c(20.06072, 20.90161, 23.48163), tol=1e-2) + expect_equal(ifit$S_X2[1:3], c(20.06072, 20.90161, 23.48163), tolerance=1e-2) eap <- fscores(lltm) - expect_equal(eap[1:3], c(1.0141828, -0.2427042, -0.2427042), tol=1e-2) + expect_equal(eap[1:3], c(1.0141828, -0.2427042, -0.2427042), tolerance=1e-2) # using unconditional modeling for first four items itemdesign.sub <- itemdesign[5:nrow(itemdesign), , drop=FALSE] lltm.4 <- mirt(dat, itemtype = 'Rasch', SE=TRUE, verbose=FALSE, item.formula = ~ 0 + difficulty, itemdesign=itemdesign.sub) cfs <- coef(lltm.4, simplify=TRUE)$items - expect_equal(as.vector(cfs[c(1,5), 1:3]), c(0, .9063842, numeric(4)), tol=1e-2) - expect_equal(anova(lltm, lltm.4)$p[2], 0.04288353, tol=1e-2) + expect_equal(as.vector(cfs[c(1,5), 1:3]), c(0, .9063842, numeric(4)), tolerance=1e-2) + expect_equal(anova(lltm, lltm.4)$p[2], 0.04288353, tolerance=1e-2) m2 <- M2(lltm.4) - expect_equal(m2$TLI, 1.001862, tol=1e-2) + expect_equal(m2$TLI, 1.001862, tolerance=1e-2) }) @@ -54,8 +54,8 @@ test_that('MLTM', { itemtype <- c(rep('Rasch', 18), rep('PC1PL', 12)) mod <- mirt(dat, syntax, itemtype=itemtype, verbose=FALSE) expect_equal(as.numeric(coef(mod, simplify=TRUE)$items[19:21, c('d1', 'd2')]), - c(2.86919500, 3.71533102, 3.23797689, 0.01323629, 0.83160425, 1.90030392), tol=1e-2) - expect_equal(logLik(mod), -43860.17, tol=1e-2) + c(2.86919500, 3.71533102, 3.23797689, 0.01323629, 0.83160425, 1.90030392), tolerance=1e-2) + expect_equal(logLik(mod), -43860.17, tolerance=1e-2) # MLTM design only for PC1PL items itemdesign <- data.frame(t1_difficulty= factor(d1, labels=c('medium', 'easy')), @@ -67,16 +67,16 @@ test_that('MLTM', { mltm <- mirt(dat, syntax, itemtype=itemtype, itemdesign=itemdesign, item.formula = list(theta1 ~ 0 + t1_difficulty, theta2 ~ 0 + t2_difficulty), SE=TRUE, verbose=FALSE) - expect_equal(extract.mirt(mltm, 'condnum'), 36.33511, tol=1e-2) - expect_equal(anova(mltm, mod)$p[2], 0.592, tol=1e-2) + expect_equal(extract.mirt(mltm, 'condnum'), 36.33511, tolerance=1e-2) + expect_equal(anova(mltm, mod)$p[2], 0.592, tolerance=1e-2) cfs <- coef(mltm, simplify=TRUE)$items expect_equal(sort(unique(as.vector(cfs[,1:5]))), - c(-0.07838095, 0.00000000, 0.92424686, 1.03069049, 1.85666146, 3.18998660), tol=1e-2) + c(-0.07838095, 0.00000000, 0.92424686, 1.03069049, 1.85666146, 3.18998660), tolerance=1e-2) fs <- fscores(mltm) expect_equal(as.vector(fs[1:3,]), c(-2.0019607,1.138449,0.149316, - -0.4814751,0.3697978,1.7928627), tol=1e-2) + -0.4814751,0.3697978,1.7928627), tolerance=1e-2) m2 <- M2(mltm) - expect_equal(m2$CFI, 0.9758302, tol=1e-2) + expect_equal(m2$CFI, 0.9758302, tolerance=1e-2) }) diff --git a/tests/tests/testdata/MG1.rds b/tests/testthat/testdata/MG1.rds similarity index 100% rename from tests/tests/testdata/MG1.rds rename to tests/testthat/testdata/MG1.rds diff --git a/tests/tests/testdata/MG2.rds b/tests/testthat/testdata/MG2.rds similarity index 100% rename from tests/tests/testdata/MG2.rds rename to tests/testthat/testdata/MG2.rds diff --git a/tests/tests/testdata/MG3.rds b/tests/testthat/testdata/MG3.rds similarity index 100% rename from tests/tests/testdata/MG3.rds rename to tests/testthat/testdata/MG3.rds diff --git a/tests/tests/testdata/bfactor1.rds b/tests/testthat/testdata/bfactor1.rds similarity index 100% rename from tests/tests/testdata/bfactor1.rds rename to tests/testthat/testdata/bfactor1.rds diff --git a/tests/tests/testdata/bfactor2.rds b/tests/testthat/testdata/bfactor2.rds similarity index 100% rename from tests/tests/testdata/bfactor2.rds rename to tests/testthat/testdata/bfactor2.rds diff --git a/tests/tests/testdata/conftwo1.rds b/tests/testthat/testdata/conftwo1.rds similarity index 100% rename from tests/tests/testdata/conftwo1.rds rename to tests/testthat/testdata/conftwo1.rds diff --git a/tests/tests/testdata/dcirt1.rds b/tests/testthat/testdata/dcirt1.rds similarity index 100% rename from tests/tests/testdata/dcirt1.rds rename to tests/testthat/testdata/dcirt1.rds diff --git a/tests/tests/testdata/dcirt2.rds b/tests/testthat/testdata/dcirt2.rds similarity index 100% rename from tests/tests/testdata/dcirt2.rds rename to tests/testthat/testdata/dcirt2.rds diff --git a/tests/tests/testdata/dcirt3.rds b/tests/testthat/testdata/dcirt3.rds similarity index 100% rename from tests/tests/testdata/dcirt3.rds rename to tests/testthat/testdata/dcirt3.rds diff --git a/tests/tests/testdata/dif1.rds b/tests/testthat/testdata/dif1.rds similarity index 100% rename from tests/tests/testdata/dif1.rds rename to tests/testthat/testdata/dif1.rds diff --git a/tests/tests/testdata/discrete1.rds b/tests/testthat/testdata/discrete1.rds similarity index 100% rename from tests/tests/testdata/discrete1.rds rename to tests/testthat/testdata/discrete1.rds diff --git a/tests/tests/testdata/extras1.rds b/tests/testthat/testdata/extras1.rds similarity index 100% rename from tests/tests/testdata/extras1.rds rename to tests/testthat/testdata/extras1.rds diff --git a/tests/tests/testdata/mixed1.rds b/tests/testthat/testdata/mixed1.rds similarity index 100% rename from tests/tests/testdata/mixed1.rds rename to tests/testthat/testdata/mixed1.rds diff --git a/tests/tests/testdata/mixed2.rds b/tests/testthat/testdata/mixed2.rds similarity index 100% rename from tests/tests/testdata/mixed2.rds rename to tests/testthat/testdata/mixed2.rds diff --git a/tests/tests/testdata/rst.rds b/tests/testthat/testdata/rst.rds similarity index 100% rename from tests/tests/testdata/rst.rds rename to tests/testthat/testdata/rst.rds