Re: [R] CEoptim problems
Thanks for the suggestion, Ivan. The issue has been overcome with a simple change of the code to the form (is.null(A) || any(is.na(A)) following advice from Peter Dalgard. However, I have kept a note of the R Inferno reference, for future problems. Best wishes, Adelchi > On 9 Apr 2024, at 12:22, Ivan Krylov wrote: > > В Tue, 9 Apr 2024 12:04:26 +0200 > Adelchi Azzalini пишет: > >> res <- CEoptim(sumsqrs, f.arg = list(xt), continuous = list(mean = >> c(0, 0, 0), sd = rep(1,3), conMat = A, conVec = b), discrete = >> list(categories = c(298L, 298L), smoothProb = 0.5),N = 1, rho >> = 0.001) >> >> Error in is.null(A) || is.na(A) : >> 'length = 18' in coercion to 'logical(1)' > > There is a book titled "The R Inferno" with lots of debugging tips for > R: https://www.burns-stat.com/documents/books/the-r-inferno/ > > Start with a traceback(). Which function gave a matrix to the || > operator (which accepts only logical scalars)? > > If traceback is not enough, use options(error = recover). Once the > error happens, you will be able to inspect local variables inside any > of the active call frames, which may help understand where did A come > from and why it was given to the || operator. > > Good luck! > > -- > Best regards, > Ivan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] CEoptim problems
> On 9 Apr 2024, at 14:54, peter dalgaard wrote: > > Hi, Adelchi, > > Depends on what you want help with... > > The proximate cause would seem to be that the code ought to have "is.null(A) > || any(is.NA(A))", which I presume you could fairly easily fix for yourself > in the package sources or even locally in an R session. Vector-valued > logicals in flow control constructions have gone through an elborate > deprecation process before getting turned into errors. Thanks, Peter. This has actually solved the problem. I should have thought about this fix. It surprises me that problems of this sort are not caught by the extensive automatic checks which a package goes through when is submitted to CRAN. Probably it happens because the only example within the CEoptim documentation is quite basic, while the more substantial examples are in the accompanying paper, but these are not checked by CRAN. Best regards, Adelchi > > If the problem is how to activate a dormant maintainer and fix the issue for > everyone, I don't really have a clue, but you might consider cantacting the > CRAN team. > > Best, > Peter D. > >> On 9 Apr 2024, at 12:04 , Adelchi Azzalini wrote: >> >> In the attempt to explore the usage of package CEoptim, I have run the code >> listed at the end of this message. This code is nothing but the one >> associated to example 5.7 in the main reference of the package, available at >> https://www.jstatsoft.org/article/view/v076i08 >> and is included in the associated file v76i08.R >> >> Unfortunately, the call to CEoptim stops with error message >> >> Error in is.null(A) || is.na(A) : >> 'length = 18' in coercion to 'logical(1)’ >> >> On 2024–04-03, I have written about this problem to >> Maintainer: Benoit Liquet >> but so far no reply has reached me. >> >> Could anyone help? >> >> Best regards, >> >> Adelchi Azzalini >> http://azzalini.stat.unipd.it >> >> >> >> library(CEoptim) >> ## 5.7 AR(1) Model with Regime Switching >> set.seed(123) >> >> sumsqrs <- function(theta, rm1, x) { >> N <- length(x) #without x[0] >> r <- 1 + sort(rm1) # internal end points of regimes >> if (r[1] == r[2]) { >> # test for dupes -> invalid regime >> return(Inf) >> } >>thetas <- rep(theta, times = c(r, N) - c(1, r + 1) + 1) >> xhat <- c(0, head(x, -1)) * thetas >> ## Compute sum of squared errors >> sum((x - xhat)^2) >> } >> >> ## Read the data from CEoptim package >> data("yt", package = "CEoptim") >> xt <- yt - c(0, yt[-300]) >> A <- rbind(diag(3), -diag(3)) >> b <- rep(1, 6) >> >> res <- CEoptim(sumsqrs, f.arg = list(xt), continuous = list(mean = c(0, 0, >> 0), sd = rep(1,3), conMat = A, conVec = b), discrete = list(categories = >> c(298L, 298L), smoothProb = 0.5),N = 1, rho = 0.001) >> >> Error in is.null(A) || is.na(A) : >> 'length = 18' in coercion to 'logical(1)' >> >> R> sessionInfo() >> R version 4.3.3 (2024-02-29) >> Platform: aarch64-apple-darwin20 (64-bit) >> Running under: macOS Ventura 13.0 >> >> Matrix products: default >> BLAS: >> /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib >> >> LAPACK: >> /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; >> LAPACK version 3.11.0 >> >> locale: >> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 >> >> time zone: Europe/Rome >> tzcode source: internal >> >> attached base packages: >> [1] stats utils datasets grDevices graphics methods base >> >> other attached packages: >> [1] CEoptim_1.3 sna_2.7-2network_1.18.2 >> statnet.common_4.9.0 >> [5] msm_1.7.1MASS_7.3-60.0.1 >> >> loaded via a namespace (and not attached): >> [1] vctrs_0.6.2cli_3.6.1 rlang_1.1.1generics_0.1.3 >> >> [5] jsonlite_1.8.4 glue_1.6.2 colorspace_2.1-0 scales_1.2.1 >> >> [9] fansi_1.0.4dlstats_0.1.7 grid_4.3.3 expm_0.999-9 >> >> [13] munsell_0.5.0 tibble_3.2.1 mvtnorm_1.1-3 >> lifecycle_1.0.3 >> [17] compiler_4.3.3 dplyr_1.1.2coda_0.19-4.1 >> RColorBrewer_1.1-3 >> [21] pkgconfig_2.0.3lattice_0.22-5 R6_2.5.1 >> tidyselect_1.2.0 >> [25] utf8_1.2.3 splines_4.3.3 pillar_1.9.0 magrittr_2.0.3 >> >> [29] Matrix_1.6-5 tools_4.3.3gtable_0.3.3 survival_3.5-8 >> >> [33] ggplot2_3.4.2 >> R> >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000
Re: [R] CEoptim problems
Hi, Adelchi, Depends on what you want help with... The proximate cause would seem to be that the code ought to have "is.null(A) || any(is.NA(A))", which I presume you could fairly easily fix for yourself in the package sources or even locally in an R session. Vector-valued logicals in flow control constructions have gone through an elborate deprecation process before getting turned into errors. If the problem is how to activate a dormant maintainer and fix the issue for everyone, I don't really have a clue, but you might consider cantacting the CRAN team. Best, Peter D. > On 9 Apr 2024, at 12:04 , Adelchi Azzalini wrote: > > In the attempt to explore the usage of package CEoptim, I have run the code > listed at the end of this message. This code is nothing but the one > associated to example 5.7 in the main reference of the package, available at > https://www.jstatsoft.org/article/view/v076i08 > and is included in the associated file v76i08.R > > Unfortunately, the call to CEoptim stops with error message > > Error in is.null(A) || is.na(A) : > 'length = 18' in coercion to 'logical(1)’ > > On 2024–04-03, I have written about this problem to > Maintainer: Benoit Liquet > but so far no reply has reached me. > > Could anyone help? > > Best regards, > > Adelchi Azzalini > http://azzalini.stat.unipd.it > > > > library(CEoptim) > ## 5.7 AR(1) Model with Regime Switching > set.seed(123) > > sumsqrs <- function(theta, rm1, x) { > N <- length(x) #without x[0] > r <- 1 + sort(rm1) # internal end points of regimes > if (r[1] == r[2]) { ># test for dupes -> invalid regime >return(Inf) > } > thetas <- rep(theta, times = c(r, N) - c(1, r + 1) + 1) > xhat <- c(0, head(x, -1)) * thetas > ## Compute sum of squared errors > sum((x - xhat)^2) > } > > ## Read the data from CEoptim package > data("yt", package = "CEoptim") > xt <- yt - c(0, yt[-300]) > A <- rbind(diag(3), -diag(3)) > b <- rep(1, 6) > > res <- CEoptim(sumsqrs, f.arg = list(xt), continuous = list(mean = c(0, 0, > 0), sd = rep(1,3), conMat = A, conVec = b), discrete = list(categories = > c(298L, 298L), smoothProb = 0.5),N = 1, rho = 0.001) > > Error in is.null(A) || is.na(A) : > 'length = 18' in coercion to 'logical(1)' > > R> sessionInfo() > R version 4.3.3 (2024-02-29) > Platform: aarch64-apple-darwin20 (64-bit) > Running under: macOS Ventura 13.0 > > Matrix products: default > BLAS: > /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib > > LAPACK: > /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; > LAPACK version 3.11.0 > > locale: > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > > time zone: Europe/Rome > tzcode source: internal > > attached base packages: > [1] stats utils datasets grDevices graphics methods base > > other attached packages: > [1] CEoptim_1.3 sna_2.7-2network_1.18.2 > statnet.common_4.9.0 > [5] msm_1.7.1MASS_7.3-60.0.1 > > loaded via a namespace (and not attached): > [1] vctrs_0.6.2cli_3.6.1 rlang_1.1.1generics_0.1.3 > > [5] jsonlite_1.8.4 glue_1.6.2 colorspace_2.1-0 scales_1.2.1 > > [9] fansi_1.0.4dlstats_0.1.7 grid_4.3.3 expm_0.999-9 > > [13] munsell_0.5.0 tibble_3.2.1 mvtnorm_1.1-3 lifecycle_1.0.3 > > [17] compiler_4.3.3 dplyr_1.1.2coda_0.19-4.1 > RColorBrewer_1.1-3 > [21] pkgconfig_2.0.3lattice_0.22-5 R6_2.5.1 > tidyselect_1.2.0 > [25] utf8_1.2.3 splines_4.3.3 pillar_1.9.0 magrittr_2.0.3 > > [29] Matrix_1.6-5 tools_4.3.3gtable_0.3.3 survival_3.5-8 > > [33] ggplot2_3.4.2 > R> > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] CEoptim problems
В Tue, 9 Apr 2024 12:04:26 +0200 Adelchi Azzalini пишет: > res <- CEoptim(sumsqrs, f.arg = list(xt), continuous = list(mean = > c(0, 0, 0), sd = rep(1,3), conMat = A, conVec = b), discrete = > list(categories = c(298L, 298L), smoothProb = 0.5),N = 1, rho > = 0.001) > > Error in is.null(A) || is.na(A) : > 'length = 18' in coercion to 'logical(1)' There is a book titled "The R Inferno" with lots of debugging tips for R: https://www.burns-stat.com/documents/books/the-r-inferno/ Start with a traceback(). Which function gave a matrix to the || operator (which accepts only logical scalars)? If traceback is not enough, use options(error = recover). Once the error happens, you will be able to inspect local variables inside any of the active call frames, which may help understand where did A come from and why it was given to the || operator. Good luck! -- Best regards, Ivan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] CEoptim problems
In the attempt to explore the usage of package CEoptim, I have run the code listed at the end of this message. This code is nothing but the one associated to example 5.7 in the main reference of the package, available at https://www.jstatsoft.org/article/view/v076i08 and is included in the associated file v76i08.R Unfortunately, the call to CEoptim stops with error message Error in is.null(A) || is.na(A) : 'length = 18' in coercion to 'logical(1)’ On 2024–04-03, I have written about this problem to Maintainer: Benoit Liquet but so far no reply has reached me. Could anyone help? Best regards, Adelchi Azzalini http://azzalini.stat.unipd.it library(CEoptim) ## 5.7 AR(1) Model with Regime Switching set.seed(123) sumsqrs <- function(theta, rm1, x) { N <- length(x) #without x[0] r <- 1 + sort(rm1) # internal end points of regimes if (r[1] == r[2]) { # test for dupes -> invalid regime return(Inf) } thetas <- rep(theta, times = c(r, N) - c(1, r + 1) + 1) xhat <- c(0, head(x, -1)) * thetas ## Compute sum of squared errors sum((x - xhat)^2) } ## Read the data from CEoptim package data("yt", package = "CEoptim") xt <- yt - c(0, yt[-300]) A <- rbind(diag(3), -diag(3)) b <- rep(1, 6) res <- CEoptim(sumsqrs, f.arg = list(xt), continuous = list(mean = c(0, 0, 0), sd = rep(1,3), conMat = A, conVec = b), discrete = list(categories = c(298L, 298L), smoothProb = 0.5),N = 1, rho = 0.001) Error in is.null(A) || is.na(A) : 'length = 18' in coercion to 'logical(1)' R> sessionInfo() R version 4.3.3 (2024-02-29) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Ventura 13.0 Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0 locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 time zone: Europe/Rome tzcode source: internal attached base packages: [1] stats utils datasets grDevices graphics methods base other attached packages: [1] CEoptim_1.3 sna_2.7-2network_1.18.2 statnet.common_4.9.0 [5] msm_1.7.1MASS_7.3-60.0.1 loaded via a namespace (and not attached): [1] vctrs_0.6.2cli_3.6.1 rlang_1.1.1generics_0.1.3 [5] jsonlite_1.8.4 glue_1.6.2 colorspace_2.1-0 scales_1.2.1 [9] fansi_1.0.4dlstats_0.1.7 grid_4.3.3 expm_0.999-9 [13] munsell_0.5.0 tibble_3.2.1 mvtnorm_1.1-3 lifecycle_1.0.3 [17] compiler_4.3.3 dplyr_1.1.2coda_0.19-4.1 RColorBrewer_1.1-3 [21] pkgconfig_2.0.3lattice_0.22-5 R6_2.5.1 tidyselect_1.2.0 [25] utf8_1.2.3 splines_4.3.3 pillar_1.9.0 magrittr_2.0.3 [29] Matrix_1.6-5 tools_4.3.3gtable_0.3.3 survival_3.5-8 [33] ggplot2_3.4.2 R> __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.