Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence drm output #7

Open
nlubock opened this issue Feb 20, 2019 · 4 comments
Open

Silence drm output #7

nlubock opened this issue Feb 20, 2019 · 4 comments

Comments

@nlubock
Copy link

nlubock commented Feb 20, 2019

I'm trying to silence all drm output, but it appears to be ignoring the options set in drmc. For example:

dose <- c(
  1.69e-10,1.69e-10,1.69e-10,1.69e-10,
  5.08e-10,5.08e-10,5.08e-10,5.08e-10,
  1.52e-09,1.52e-09,1.52e-09,1.52e-09,
  4.57e-09,4.57e-09,4.57e-09,4.57e-09,
  1.37e-08,1.37e-08,1.37e-08,1.37e-08,
  4.12e-08,4.12e-08,4.12e-08,4.12e-08,
  1.23e-07,1.23e-07,1.23e-07,1.23e-07,
  3.7e-07,3.7e-07,3.7e-07,3.7e-07,
  1.11e-06,1.11e-06,1.11e-06,1.11e-06,
  3.33e-06,3.33e-06,3.33e-06,3.33e-06,
  1e-05,1e-05,1e-05,1e-05
)

response <- c(
  0.286,0.302,0.235,0.362,
  -0.08,-0.479,0.508,0.435,
  0.004,0.676,0.04,-0.751,
  -0.789,-1.053,0.389,-0.095,
  0.326,-0.226,0.038,0.137,
  0.406,-0.223,0.066,0.743,
  -0.113,0.061,-0.244,-0.237,
  0.658,0.146,-0.191,-0.106,
  -0.636,0.145,0.043,0.58,
  0.119,-0.219,0.262,-0.226,
  0.101,0.004,0.163,0.269
)

set.seed(42)
control <- drmc(errorm = FALSE, noMessage = TRUE, warnVal = -1)
foo <- drm(response ~ dose, fct=LL.4(), control = control)

results in the output:

Error in optim(startVec, opfct, hessian = TRUE, method = optMethod, control = list(maxit = maxIt,  : 
  non-finite finite-difference value [4]
In addition: Warning message:
In log(dose/parmMat[, 4]) : NaNs produced
Warning message:
Convergence failed. The model was not fitted! 

Session Info

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS: /usr/lib/libblas.so.3.8.0
LAPACK: /usr/lib/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2.2  forcats_0.4.0   stringr_1.3.1   dplyr_0.7.8    
 [5] purrr_0.2.5     readr_1.3.1     tidyr_0.8.2     tibble_2.0.1   
 [9] ggplot2_3.1.0   tidyverse_1.2.1 magrittr_1.5    furrr_0.1.0    
[13] future_1.11.1.1 broom_0.5.1     drc_3.0-6       drcData_1.0-0  
[17] sandwich_2.5-0  glmnet_2.0-16   foreach_1.4.4   Matrix_1.2-15  
[21] MASS_7.3-51.1   edgeR_3.24.3    limma_3.38.3   

loaded via a namespace (and not attached):
 [1] httr_1.4.0        jsonlite_1.6      splines_3.5.2     carData_3.0-2    
 [5] modelr_0.1.2      gtools_3.8.1      assertthat_0.2.0  cellranger_1.1.0 
 [9] yaml_2.2.0        globals_0.12.4    pillar_1.3.1      backports_1.1.3  
[13] lattice_0.20-38   glue_1.3.0        digest_0.6.18     rvest_0.3.2      
[17] colorspace_1.4-0  plyr_1.8.4        pkgconfig_2.0.2   listenv_0.7.0    
[21] haven_2.1.0       mvtnorm_1.0-8     scales_1.0.0      openxlsx_4.1.0   
[25] rio_0.5.16        generics_0.0.2    car_3.0-2         withr_2.1.2      
[29] TH.data_1.0-10    lazyeval_0.2.1    cli_1.0.1         survival_2.43-3  
[33] crayon_1.3.4      readxl_1.3.0      fansi_0.4.0       nlme_3.1-137     
[37] xml2_1.2.0        foreign_0.8-71    tools_3.5.2       data.table_1.12.0
[41] hms_0.4.2         multcomp_1.4-8    munsell_0.5.0     locfit_1.5-9.1   
[45] plotrix_3.7-4     zip_1.0.0         compiler_3.5.2    rlang_0.3.1      
[49] grid_3.5.2        iterators_1.0.10  rstudioapi_0.8    gtable_0.2.0     
[53] codetools_0.2-15  abind_1.4-5       curl_3.3          R6_2.4.0         
[57] zoo_1.8-4         lubridate_1.7.4   utf8_1.1.4        bindr_0.1.1      
[61] stringi_1.2.4     parallel_3.5.2    Rcpp_1.0.0        tidyselect_0.2.5 
@nlubock nlubock changed the title drm ignoring noMessage Silence drm output Feb 21, 2019
@jpquast
Copy link

jpquast commented Jul 8, 2020

I have the same problem. Is there any update on this? I iterate over drm with purrr::map and use tryCatch to continue after an error occurs. This works. However, the error message is still printed, which messes up my progress bar.

@OnofriAndreaPG
Copy link
Contributor

Hello, the error message comes from ‘optim()’ that is wrapped inside drc. I do not think it can be silenced from drc.

@jpquast
Copy link

jpquast commented Jul 9, 2020

Thank you for your answer. I already noticed that the problem is optim(). As far as I could see, it is called at least in drmOpt() which is called in drm(). However, it looks like the error of optim() is intended to be silenced since it is wrapped in try() with the option silent = TRUE. So this seems to be a bug. The only intended error message here seems to be "Convergence failed" which is part of drmOpt().

drmOpt <- function (opfct, opdfct1, startVec, optMethod, constrained, warnVal, 
    upperLimits, lowerLimits, errorMessage, maxIt, relTol, opdfct2 = NULL, 
    parmVec, traceVal, silentVal = TRUE, matchCall) 
{
    options(warn = warnVal)
    if (is.null(opdfct2)) {
        hes <- TRUE
    }
    else {
        hes <- FALSE
    }
    psVec <- abs(startVec)
    psVec[psVec < 1e-04] <- 1
    {
        if (!is.null(opdfct1)) {
            if (constrained) {
                nlsObj <- try(optim(startVec, opfct, opdfct1, 
                  hessian = hes, method = "L-BFGS-B", lower = lowerLimits, 
                  upper = upperLimits, control = list(maxit = maxIt, 
                    reltol = relTol, parscale = psVec)), silent = silentVal)
            }
            else {
                nlsObj <- try(optim(startVec, opfct, opdfct1, 
                  hessian = hes, method = optMethod, control = list(maxit = maxIt, 
                    reltol = relTol, parscale = psVec)), silent = silentVal)
            }

.....

@OnofriAndreaPG
Copy link
Contributor

OnofriAndreaPG commented Jul 9, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants