philips-software / latrend

An R package for clustering longitudinal datasets in a standardized way, providing interfaces to various R packages for longitudinal clustering, and facilitating the rapid implementation and evaluation of new methods
https://philips-software.github.io/latrend/
GNU General Public License v2.0
28 stars 5 forks source link

funFEM tests can fail at random #112

Closed niekdt closed 2 years ago

niekdt commented 2 years ago

CRAN checks failed on a rare case where funFEM fails to fit, triggering an error. It seems that funFEM is using its own RNG.

Version: 1.3.0
Check: tests
Result: ERROR
     Running ‘testthat.R’ [158s/422s]
    Running the tests in ‘tests/testthat.R’ failed.
    Complete output:
     > library(testthat)
     > library(latrend)
     >
     > test_check('latrend')
     Error in .fstep(fd, T, lambda) : One cluster is almost empty!
     [ FAIL 1 | WARN 1 | SKIP 9 | PASS 2176 ]

     ══ Skipped tests ═══════════════════════════════════════════════════════════════
     • On CRAN (7)
     • empty test (1)
     • skipping MixTVEM tests because the TVEMMixNormal() function is not loaded (1)

     ══ Failed tests ════════════════════════════════════════════════════════════════
     ── Error (test-funfem.R:12:3): default ─────────────────────────────────────────
     Error in `test.latrend("lcMethodFunFEM", tests = tests, clusterRecovery = "skip",
     args = list(basis = function(time) fda::create.bspline.basis(time,
     nbasis = 4L, norder = 2L)))`: Unexpected error occurred while evaluating test context: "cluster-three"
     Error message:
     "No reliable results to return (empty clusters in all partitions)!"
     Stack trace:
     15: sys.source(file, envir = env)
     14: eval(exprs[i], envir)
     13: eval(exprs[i], envir)
     12: latrend(m, data = testData)
     11: .fitLatrendMethod(cmethod, modelData, envir = modelEnv, mc = mc,
     verbose = verbose)
     10: suppressFun({
     modelEnv = preFit(method = method, data = data, envir = envir,
     verbose = verbose)
     model = fit(method = method, data = data, envir = modelEnv,
     verbose = verbose)
     ...
     9: capture.output(suppressMessages(...))
     8: withVisible(...elt(i))
     7: suppressMessages(...)
     6: withCallingHandlers(expr, message = function(c) if (inherits(c,
     classes)) tryInvokeRestart("muffleMessage"))
     5: fit(method = method, data = data, envir = modelEnv, verbose = verbose)
     4: fit(method = method, data = data, envir = modelEnv, verbose = verbose)
     3: do.call(funFEM::funFEM, args)
     2: (function (fd, K = 2:6, model = "AkjBk", crit = "bic", init = "kmeans",
     Tinit = c(), maxit = 50, eps = 1e-06, disp = FALSE, lambda = 0,
     graph = FALSE)
     {
     call = match.call()
     ...
     1: stop("No reliable results to return (empty clusters in all partitions)!")
     Backtrace:
     ▆
     1. ├─testthat::expect_true(...) at test-funfem.R:12:2
     2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
     3. │ └─rlang::eval_bare(expr, quo_get_env(quo))
     4. └─latrend::test.latrend(...) at test-funfem.R:13:4

     [ FAIL 1 | WARN 1 | SKIP 9 | PASS 2176 ]
     Error: Test failures
     Execution halted
Flavor: [r-devel-linux-x86_64-fedora-clang](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/latrend-00check.html)

Solution: look into how to make funFEM fitting reproducible.