[R-SIG-Finance] seeking assistance in library(mbsts)
Joshua Ulrich
jo@h@m@u|r|ch @end|ng |rom gm@||@com
Tue Apr 15 20:42:20 CEST 2025
Hi Weihan,
Please keep your replies on-list so everyone has all the same information.
I cannot replicate the error using the code in your most recent email
using the latest version of R (4.5.0) and the latest packages from
CRAN. Here's my sessionInfo():
R$ sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.2 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
LAPACK version 3.12.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
time zone: America/Chicago
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices datasets utils methods
[7] base
other attached packages:
[1] mbsts_3.0
loaded via a namespace (and not attached):
[1] Matrix_1.7-3 gtable_0.3.6 dplyr_1.1.4
[4] compiler_4.5.0 Rcpp_1.0.14 tidyselect_1.2.1
[7] colorout_1.3-0.1 bspm_0.5.7 stringr_1.5.1
[10] MatrixModels_0.5-4 splines_4.5.0 scales_1.3.0
[13] lattice_0.22-7 coda_0.19-4.1 plyr_1.8.9
[16] ggplot2_3.5.2 R6_2.6.1 MCMCpack_1.7-1
[19] BBmisc_1.13 generics_0.1.3 MASS_7.3-65
[22] backports_1.5.0 checkmate_2.3.2 tibble_3.2.1
[25] munsell_0.5.1 pillar_1.10.2 rlang_1.1.6
[28] stringi_1.8.7 cli_3.6.4 magrittr_2.0.3
[31] mcmc_0.9-8 grid_4.5.0 quantreg_6.1
[34] lifecycle_1.0.4 vctrs_0.6.5 pscl_1.5.9
[37] SparseM_1.84-2 glue_1.8.0 data.table_1.14.99
[40] KFAS_1.5.1 survival_3.8-3 colorspace_2.1-1
[43] reshape2_1.4.4 tools_4.5.0 matrixStats_1.5.0
[46] pkgconfig_2.0.3
> On Apr 14, 2025 at 8:20 PM Wei-han Liu wrote:
>
> Thanks, Josh.
>
> The error message is "
> as.vector(x, mode):
> > cannot coerce type 'closure' to vector of type 'any'"
>
> The data is attached.
>
> Much appreciated for your assistance.
>
> CHEERS!
>
> Weihan
>
>
> library(mbsts)
>
> n<-1800 #n: sample size
> set.seed(1)
>
> #Regression component
> #coefficients for predictors
> beta<-t(matrix(c(2,-1.5,0,4,2.5,0,0,2.5,1.5,-1,-2,0,0,-3,3.5,0.5),nrow=2,ncol=8))
> #predictors
> X1<-rnorm(n,5,5^2)
> X4<-rnorm(n,-2,5)
> X5<-rnorm(n,-5,5^2)
> X8<-rnorm(n,0,100)
> X2<-rpois(n, 10)
> X6<-rpois(n, 15)
> X7<-rpois(n, 20)
> X3<-rpois(n, 5)
> X<-cbind(X1,X2,X3,X4,X5,X6,X7,X8)
>
> #covariance matrix of target series
> cov<-matrix(c(1.1,0.7,0.7,0.9), nrow=2, ncol=2)
>
> #Simulated data
> data=sim_data(X=X, beta=beta, cov, k=c(8,8), mu=c(1,1), rho=c(0.06,0.08),
> Dtilde=c(-0.1,0.3), Season=c(100,0), vrho=c(0,0.99), lambda=c(0,pi/100))
>
>
> On Mon, Apr 14, 2025 at 9:47 AM Joshua Ulrich <josh.m.ulrich using gmail.com> wrote:
> >
> > Hi,
> >
> > It's hard to help you without a reproducible example. We can't run
> > your code because we don't have the crypto-all.csv file.
> >
> > Also, please only send plain text to the list. Your html email was
> > converted to text by the list-server and is hard to interpret (see
> > your message below).
> >
> > Best,
> > Josh
> >
> >
> > On Sun, Apr 13, 2025 at 9:16 PM Wei-han Liu via R-SIG-Finance
> > <r-sig-finance using r-project.org> wrote:
> > >
> > > Hi there:
> > > I tried the following R lines and encountered the error message in the end:as.vector(x, mode):
> > > cannot coerce type 'closure' to vector of type 'any'
> > > Could any person share me some advice to solve this problem?
> > > Thannks in advance.
> > > Weihan
> > > library(mbsts)
> > > all_data <- read.csv("crypto-all.csv")all_data <- na.omit(all_data)
> > > m<-5 #m: dimension of target seriesn<-nrow(all_data) #n: sample size
> > > #covariance matrix of target seriescov_all<-matrix(cov(all_data[,-1]), nrow=5, ncol=5)
> > > #Regression component#coefficients for predictorsbeta<-t(matrix(c(2,-1.5,0,4,2.5,0,0,2.5,1.5,-1,-2,0,0,-3,3.5,0.5,0.5,0.5,0.5,0.5),nrow=5,ncol=8))#predictorsX1<-rnorm(n,5,5^2)X4<-rnorm(n,-2,5)X5<-rnorm(n,-5,5^2)X8<-rnorm(n,0,100)X2<-rpois(n, 10)X6<-rpois(n, 15)X7<-rpois(n, 20)X3<-rpois(n, 5)X<-cbind(X1,X2,X3,X4,X5,X6,X7,X8)
> > > #Simulated datadata=sim_data(X=X, beta=beta, cov, k=c(8,8,8,8,8), mu=c(1,1,1,1,1), rho=c(0.06,0.08,0.07,0.06,0.08), Dtilde=c(-0.1,0.3,0.1,0.2,0.3), Season=c(100,0,100,0,100,0), vrho=c(0,0.99,0,0.99,0), lambda=c(0,pi/100,0,pi/100,0))
> > >
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > _______________________________________________
> > > R-SIG-Finance using r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > > -- Subscriber-posting only. If you want to post, subscribe first.
> > > -- Also note that this is not the r-help list where general R questions should go.
> >
> >
> >
> > --
> > Joshua Ulrich | about.me/joshuaulrich
> > FOSS Trading | www.fosstrading.com
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
More information about the R-SIG-Finance
mailing list