[R] CEoptim problems

Adelchi Azzalini @zz@||n| @end|ng |rom @t@t@un|pd@|t
Tue Apr 9 12:04:26 CEST 2024


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 <b.liquet using uq.edu.au>
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 = 10000, 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-2            network_1.18.2       statnet.common_4.9.0
[5] msm_1.7.1            MASS_7.3-60.0.1     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.2        cli_3.6.1          rlang_1.1.1        generics_0.1.3    
 [5] jsonlite_1.8.4     glue_1.6.2         colorspace_2.1-0   scales_1.2.1      
 [9] fansi_1.0.4        dlstats_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.2        coda_0.19-4.1      RColorBrewer_1.1-3
[21] pkgconfig_2.0.3    lattice_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.3        gtable_0.3.3       survival_3.5-8    
[33] ggplot2_3.4.2     
R> 



More information about the R-help mailing list