R Under development (unstable) (2025-10-22 r88967 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # ---------------------------------------------------------------------------------------- > # Compare test results for not imputed data > # ---------------------------------------------------------------------------------------- > library(micd) Loading required package: pcalg Loading required package: mice Attaching package: 'mice' The following object is masked from 'package:stats': filter The following objects are masked from 'package:base': cbind, rbind > > dat <- data.frame(x = rnorm(200), + A = factor(rbinom(200, 1, 0.4)), + y = rnorm(200), + B = factor(rbinom(200, 2, c(0.1,0.4))), + z = rnorm(200), + C = factor(rbinom(200, 2, c(0.2,0.3))), + Z = rnorm(200), + D = factor(rbinom(200, 1, 0.5))) > > # 2 variables ---------------------------------------------------------------------------- > # 2 continuous ---------------- > x <- 3 > y <- 5 > S <- NULL > > res1 <- flexCItest(x, y, S, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, S, suffStat = dat) > res3 <- pcalg::gaussCItest(1, 2, NULL, suffStat = getSuff(dat[,c(x, y, S)], test = "gaussCItest")) > > (eq1 <- all.equal(res1, res2, res3, tol = 1e-5)) [1] TRUE > test1 <- isTRUE(eq1) > rm(res1, res2, res3, x, y, S) > > > # 2 discrete ------------------ > x <- 2; nlev_x <- nlevels(dat[,x]) > y <- 4; nlev_y <- nlevels(dat[,y]) > S <- NULL > > res1 <- flexCItest(x, y, S, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, S, suffStat = dat) > res3 <- pcalg::disCItest(1,2,NULL, + suffStat = getSuff(dat[,c(x,y,S)], test = "disCItest", + adaptDF = TRUE, nlev = c(nlev_x, nlev_y))) > > (eq2 <- all.equal(res1, res2, res3, tol = 1e-5)) [1] TRUE > test2 <- isTRUE(eq2) > rm(res1, res2, res3, x, y, S, nlev_x, nlev_y) > > > # 1 discrete, 1 continuous ---- > x <- 3; > y <- 6; nlev_y <- nlevels(dat[,y]) > S <- NULL > > res1 <- flexCItest(x, y, NULL, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, NULL, suffStat = dat) > > (eq3 <- all.equal(res1, res2, tol = 1e-5)) [1] TRUE > test3 <- isTRUE(eq3) > rm(res1, res2, x, y, S, nlev_y) > > > > > # 3 variables ---------------------------------------------------------------------------- > # 3 continuous ---------------- > x <- 3 > y <- 5 > S <- 1 > > res1 <- flexCItest(x, y, S, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, S, suffStat = dat) > res3 <- pcalg::gaussCItest(1, 2, NULL, suffStat = getSuff(dat[,c(x, y, S)], test = "gaussCItest")) > > (eq4 <- all.equal(res1, res2, res3, tol = 1e-5)) [1] TRUE > test4 <- isTRUE(eq4) > rm(res1, res2, res3, x, y, S) > > > # 3 discrete ------------------ > x <- 2; nlev_x <- nlevels(dat[,x]) > y <- 4; nlev_y <- nlevels(dat[,y]) > S <- 6; nlev_S <- nlevels(dat[,S]) > > res1 <- flexCItest(x, y, S, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, S, suffStat = dat) > res3 <- pcalg::disCItest(1,2,3, + suffStat = getSuff(dat[,c(x,y,S)], test = "disCItest", + adaptDF = TRUE, nlev = c(nlev_x, nlev_y, nlev_S))) > > (eq5 <- all.equal(res1, res2, res3, tol = 1e-5)) [1] TRUE > test5 <- isTRUE(eq5) > rm(res1, res2, res3, x, y, S, nlev_x, nlev_y, nlev_S) > > > # 1 discrete, 2 continuous ---- > x <- 1 > y <- 3 > S <- 2; nlev_S <- nlevels(dat[,S]) > > res1 <- flexCItest(x, y, NULL, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, NULL, suffStat = dat) > > (eq6 <- all.equal(res1, res2, tol = 1e-5)) [1] TRUE > test6 <- isTRUE(eq6) > rm(res1, res2, x, y, S, nlev_S) > > > > > > > # more variables ------------------------------------------------------------------------- > # 4 continuous ---------------- > x <- 3 > y <- 5 > S <- c(1,7) > > res1 <- flexCItest(x, y, S, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, S, suffStat = dat) > res3 <- pcalg::gaussCItest(1, 2, NULL, suffStat = getSuff(dat[,c(x, y, S)], test = "gaussCItest")) > > (eq7 <- all.equal(res1, res2, res3, tol = 1e-5)) [1] TRUE > test7 <- isTRUE(eq7) > rm(res1, res2, res3, x, y, S) > > > # 4 discrete ------------------ > x <- 2; nlev_x <- nlevels(dat[,x]) > y <- 4; nlev_y <- nlevels(dat[,y]) > S <- c(6,8); nlev_S <- c(nlevels(dat[,S[1]]), nlevels(dat[,S[2]])) > > res1 <- flexCItest(x, y, S, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, S, suffStat = dat) > res3 <- pcalg::disCItest(1, 2, c(3,4), + suffStat = getSuff(dat[,c(x,y,S)], test = "disCItest", + adaptDF = TRUE, nlev = c(nlev_x, nlev_y, nlev_S))) > > (eq8 <- all.equal(res1, res2, res3, tol = 1e-5)) [1] TRUE > test8 <- isTRUE(eq8) > rm(res1, res2, res3, x, y, S, nlev_x, nlev_y, nlev_S) > > > # 2 discrete, 2 continuous ---- > x <- 1 > y <- 3 > S <- c(7,8); nlev_S <- nlevels(dat[,8]) > > res1 <- flexCItest(x, y, NULL, suffStat = getSuff(dat, test="flexCItest")) > res2 <- mixCItest(x, y, NULL, suffStat = dat) > > (eq9 <- all.equal(res1, res2, tol = 1e-5)) [1] TRUE > test9 <- isTRUE(eq9) > rm(res1, res2, x, y, S, nlev_S) > > > > > # Result -------------------------------------------------------------------------------- > if (!all(test1,test2,test3,test4,test5,test6,test7,test8,test9)) + stop("CI tests wrong!") > > proc.time() user system elapsed 2.71 0.46 3.12