mpascariu / ungroup

Estimating Smooth Distributions from Coarsely Binned Data - R Package
Other
13 stars 9 forks source link

switch MortalitySmooth to remote ref #11

Closed timriffe closed 3 years ago

timriffe commented 3 years ago

See emails on svcm and MortalitySmooth for more context: This just switches the MortalitySmooth reference to my github fork. The MortalitySmooth version differs only in that its svcm dependency is removed: the function has been copied into the package, as GC intended to do. I did not run checks(), because many other files are modified and I don't want to commit unrelated changes at this time. This minimal change should make ungroup viable again I think.

mpascariu commented 3 years ago

thanks @timriffe !

timriffe commented 3 years ago

regarding the new error message:

Error: processing vignette 'Intro.Rmd' failed with diagnostics: 6956"dgCMatrix" is not a defined class 6957--- failed re-building ‘Intro.Rmd’

When I step through the vignette, I can provoke the same error in the first use of pclm(). Here's traceback():

19: stop(gettextf("%s is not a defined class", dQuote(Class)), domain = NA)

18: getClass("dgCMatrix")

17: .Call("_ungroup_asSparseMat", PACKAGE = "ungroup", X) at RcppExports.R#5

16: asSparseMat(C) at RcppExports.R#9

15: pclmloop(asSparseMat(C), P, B, y, max.iter, tol) at pclm_fit.R#45

14: pclm.fit(x = I$x, y = I$y, nlast = I$nlast, offset = I$offset,

    out.step = I$out.step, verbose = FALSE, lambda = L, kr = kr,

    deg = deg, diff = diff, max.iter = max.iter, tol = tol, type =

type) at pclm_optim.R#15

13: eval(substitute(expr), data, enclos = parent.frame())

12: eval(substitute(expr), data, enclos = parent.frame())

11: with.default(I$control, {

    M <- pclm.fit(x = I$x, y = I$y, nlast = I$nlast, offset = I$offset,

        out.step = I$out.step, verbose = FALSE, lambda = L, kr = kr,

        deg = deg, diff = diff, max.iter = max.iter, tol = tol,

        type = type)

    fn <- paste0(opt.method, ".pclm")

    aic_bic <- get(fn)

    out <- aic_bic(M)

    return(out)

})

10: with(I$control, {

    M <- pclm.fit(x = I$x, y = I$y, nlast = I$nlast, offset = I$offset,

        out.step = I$out.step, verbose = FALSE, lambda = L, kr = kr,

        deg = deg, diff = diff, max.iter = max.iter, tol = tol,

        type = type)

    fn <- paste0(opt.method, ".pclm")

    aic_bic <- get(fn)

    out <- aic_bic(M)

    return(out)

}) at pclm_optim.R#14

9: f(arg, ...)

8: (function (arg)

f(arg, ...))(2.97447036821528)

7: optimise(f = ofun, interval = log(int.lambda), I = I, type = type,

   tol = 1e-05) at pclm_optim.R#56

6: eval(substitute(expr), data, enclos = parent.frame())

5: eval(substitute(expr), data, enclos = parent.frame())

4: with.default(I$control, {

   if (I$verbose)

       pb <- startpb(0, 100)

   if (any(is.na(lambda))) {

       if (I$verbose) {

           setpb(pb, 40)

           cat("   Optimizing lambda  ")

       }

       if (type == "1D") {

           opt <- optimise(f = ofun, interval = log(int.lambda),

               I = I, type = type, tol = 1e-05)

           lambda.hat <- round(exp(opt$minimum), 6)

       }

       else {

           L1_lw = L1_up = L1 <- log(lambda[1])

           L2_lw = L2_up = L2 <- log(lambda[2])

           if (is.na(lambda[1])) {

               L1_lw <- log(int.lambda)[1]

               L1_up <- log(int.lambda)[2]

               L1 <- log(mean(int.lambda))

           }

           if (is.na(lambda[2])) {

               L2_lw <- log(int.lambda)[1]

               L2_up <- log(int.lambda)[2]

               L2 <- log(mean(int.lambda))

           }

           opt <- nlminb(start = c(L1, L2), objective = ofun,

               I = I, type = type, lower = c(L1_lw, L2_lw),

               upper = c(L1_up, L2_up))

           lambda.hat <- round(exp(opt$par), 6)

       }

   }

   if (lambda.hat[1] == int.lambda[2]) {

       warning(paste0("'lambda' has reached the upper limit of ",

           int.lambda[2], ". Maybe it is a good idea to extend interval. ",

           "See 'int.lambda' argument in 'pclm2D.control'."),

           call. = FALSE)

   }

   return(lambda.hat)

})

3: with(I$control, {

   if (I$verbose)

       pb <- startpb(0, 100)

   if (any(is.na(lambda))) {

       if (I$verbose) {

           setpb(pb, 40)

           cat("   Optimizing lambda  ")

       }

       if (type == "1D") {

           opt <- optimise(f = ofun, interval = log(int.lambda),

               I = I, type = type, tol = 1e-05)

           lambda.hat <- round(exp(opt$minimum), 6)

       }

       else {

           L1_lw = L1_up = L1 <- log(lambda[1])

           L2_lw = L2_up = L2 <- log(lambda[2])

           if (is.na(lambda[1])) {

               L1_lw <- log(int.lambda)[1]

               L1_up <- log(int.lambda)[2]

               L1 <- log(mean(int.lambda))

           }

           if (is.na(lambda[2])) {

               L2_lw <- log(int.lambda)[1]

               L2_up <- log(int.lambda)[2]

               L2 <- log(mean(int.lambda))

           }

           opt <- nlminb(start = c(L1, L2), objective = ofun,

               I = I, type = type, lower = c(L1_lw, L2_lw),

               upper = c(L1_up, L2_up))

           lambda.hat <- round(exp(opt$par), 6)

       }

   }

   if (lambda.hat[1] == int.lambda[2]) {

       warning(paste0("'lambda' has reached the upper limit of ",

           int.lambda[2], ". Maybe it is a good idea to extend interval. ",

           "See 'int.lambda' argument in 'pclm2D.control'."),

           call. = FALSE)

   }

   return(lambda.hat)

}) at pclm_optim.R#48

2: optimize_par(I, type) at pclm_1D.R#156

1: pclm(x, y, nlast)

So, something may have changed with the Rcpp sparse matrix deps, not sure, this one's over my head, but it gives a good hint.

Best wishes,

Tim

On Mon, Dec 28, 2020 at 5:50 PM Marius D. Pascariu notifications@github.com wrote:

thanks @timriffe https://github.com/timriffe !

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mpascariu/ungroup/pull/11#issuecomment-751783534, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG43G7BAS3NFKKONZIEELLSXCZMZANCNFSM4VMDBABA .

mpascariu commented 3 years ago

i am investigating this now

mpascariu commented 3 years ago

The source of the Error in getClass("dgCMatrix") : “dgCMatrix” is not a defined class issue is the Matrix package, which is a base package. Basically, the dgCMatrix class is required by the Rcpp.

If we load the Matrix package before ungroup the code will run.

So I understand, that we need to import the dgCMatrix class in the NAMESPACE to avoid calling library(Matrix) every time we load ungroup. This is be done by roxygen2 if we add the following somewhere in our script:

#' @importClassesFrom Matrix dgCMatrix

Problem solved! But... now we do not pass the R CMD check and get the following:

E  checking package dependencies (5s)
   Namespace dependency not required: 'Matrix'

   See section 'The DESCRIPTION file' in the 'Writing R Extensions'
   manual.

Matrix as a base package should not be in the NAMESPACE.

Any ideas how to go around this?

mpascariu commented 3 years ago

The Matrix has to be specified in Description as well and we should be fine. Rookie omission.

I will prepare tomorrow the CRAN package and it should be up again before the end of the year... if the CRAN people are not on holiday.

timriffe commented 3 years ago

Great to hear!

On Mon, Dec 28, 2020 at 9:44 PM Marius D. Pascariu notifications@github.com wrote:

The Matrix has to be specified in Description as well and we should be fine. Rookie omission.

I will prepare tomorrow the CRAN package and it should be up again before the end of the year... if the CRAN people are not on holiday.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mpascariu/ungroup/pull/11#issuecomment-751858437, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG43GYP3BZCCIQZEZGXGV3SXDUZLANCNFSM4VMDBABA .

mpascariu commented 3 years ago

v1.2.0 available on GitHub is now ready for CRAN. It will be submitted on Jan 4 after CRAN team resumes activity.

mpascariu commented 3 years ago

v1.3.0 can be installed from CRAN now.