[R] Replacing elements of list
Dear all, I have following two list object, both are basically collection of matrices : dat1 <- matrix(rnorm(25*6), ncol=6) dat1 <- split(dat1, seq(5,25,by=5)) dat1 <- lapply(dat1, matrix, ncol=6) dat2 <- matrix(rnorm(25*4), ncol=4) dat2 <- split(dat2, seq(5,25,by=5)) dat2 <- lapply(dat2, matrix, ncol=4) Now I want to replace last 4 columns of each matrix at "dat1" with the corresponding matrix in "dat2". However I want to avoid the time consuming loop to do that. Is there any way to do that without using loop? Thanks -- View this message in context: http://n4.nabble.com/Replacing-elements-of-list-tp1677293p1677293.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Simulation of VAR
Dear all, is there any package/function available which simulates a co-integrating VAR model once the model parameters are input over some arbitrary horizon? Please let me know anyone aware of that. Thanks -- View this message in context: http://n4.nabble.com/Simulation-of-VAR-tp1693295p1693295.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Need help on matrix manipulation
Dear all, Ket say I have 3 matrices : mat1 <- matrix(rnorm(16), 4) mat2 <- matrix(rnorm(16), 4) mat3 <- matrix(rnorm(16), 4) Now I want to merge those three matrices to a single one with dimension 4*3=12 and 4 wherein on resulting matrix, row 1,4,7,10 will be row-1,2,3,4 of "mat1", row 2,5,8,11 will be row-1,2,3,4 of "mat2" and row 3,6,8,12 will be row-1,2,3,4 of "mat3". For example suppose the matrices are : > mat1 [,1] [,2][,3][,4] [1,] -0.3597661 -0.8725675 0.92033577 0.42461934 [2,] -1.0431990 -0.5221843 0.31821494 -0.01963307 [3,] 0.4736285 -1.3917844 0.03776291 0.52503899 [4,] 0.2341584 0.2959110 -0.33166146 1.22208331 > mat2 [,1] [,2] [,3] [,4] [1,] 1.0666719 -1.0310117 -1.4418511 -0.2461388 [2,] 2.0099067 -0.3866974 -0.2978510 0.9377186 [3,] -1.5532591 -0.1341572 -1.0745971 0.1120120 [4,] 0.4318782 0.1166596 -0.6320177 -0.4709091 > mat3 [,1][,2] [,3] [,4] [1,] -0.15092091 1.11900300 0.7173543 0.3631286 [2,] -1.09844902 1.55239518 -0.5049884 0.8974597 [3,] -1.60176717 -0.03991147 -1.2475162 1.4643000 [4,] -0.06721017 -0.88329791 -1.9875210 -0.7989177 then the resulting matrix will be : -0.3597661 -0.8725675 0.92033577 0.42461934 1.0666719 -1.0310117 -1.4418511 -0.2461388 -0.15092091 1.1190030.7173543 0.3631286 -1.043199 -0.5221843 0.31821494 -0.01963307 2.0099067 -0.3866974 -0.297851 0.9377186 -1.09844902 1.55239518 -0.5049884 0.8974597 0.4736285 -1.3917844 0.03776291 0.52503899 -1.5532591 -0.1341572 -1.0745971 0.112012 -1.60176717 -0.03991147 -1.2475162 1.4643 0.2341584 0.295911-0.33166146 1.22208331 0.4318782 0.1166596 -0.6320177 -0.4709091 -0.06721017 -0.88329791 -1.987521 -0.7989177 -- View this message in context: http://n4.nabble.com/Need-help-on-matrix-manipulation-tp1694804p1694804.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Simulation of VAR
Yes I looked into "dse" package. Here I have implemented two approach for simulation like following : library(dse) A1 <- matrix(rnorm(16),4) A2 <- matrix(rnorm(16),4) mu <- rnorm(4) sigma <- matrix(c(0.006594712, 0.006467731, -0.000254914, 0.005939934, 0.006467731, 0.006654184, -0.000384097, 0.005658247, -0.000254914, -0.000384097, 0.000310294, 4.34141E-05, 0.005939934, 0.005658247, 4.34141E-05, 0.00574024), 4) initial.val <- matrix(c(-0.2347096, -0.1803612, -0.2780356, -0.2154427 , 3.740364, 3.757908, 3.50216 , 3.57783), 2) # My approach res <- matrix(NA, 4,4); res[c(1,2),] <- initial.val library(mnormt); shocks <- rmnorm(2, rep(0,4), sigma) for (i in 1:2) { res[i+2,] <- mu + A1%*%res[i+2-1,] + A2%*%res[i+2-2,] + shocks[i,] } res # dse approach temp1 <- matrix(t(cbind(diag(4), A1, A2)), ncol = 4, byrow = TRUE) model <- ARMA(A=array(temp1, c(3,4,4)), B=diag(4), TREND=mu) simulate(model, y0=initial.val, sampleT=2, noise=shocks) Ideally last two rows of "res" and simulate() should be exactly same. However that is not what I am getting. Can anyone please tell me whether there is any mistale in any of those approaches? Am I missing somthing? Thanks -- View this message in context: http://n4.nabble.com/Simulation-of-VAR-tp1693295p1694899.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Merging "list" object
Hi, I have created following "list" object : > library(zoo) > dat <- vector("list") > for (i in 1:4) dat[[i]] <- zooreg(rnorm(i*10), > start=as.Date("2000-01-01"), frequency=1) > dat[[1]] 2000-01-01 2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-08 2000-01-09 2000-01-10 -0.7023352 -0.2063284 -1.0684688 -0.5345360 1.0045435 -0.6528107 1.0922850 0.6592155 0.1889817 -0.5154872 > dat[[2]] 2000-01-01 2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-08 2000-01-09 2000-01-10 -1.33096001 -0.41484364 0.03850233 -0.78752649 1.50566685 -1.05094523 0.58845956 0.28183515 0.90528437 -0.61535069 2000-01-11 2000-01-12 2000-01-13 2000-01-14 2000-01-15 2000-01-16 2000-01-17 2000-01-18 2000-01-19 2000-01-20 -0.76326498 -0.38750503 0.59519399 -0.39464736 0.80053668 0.56286659 0.03991622 1.20224474 -0.11436020 0.79030262 > dat[[3]] 2000-01-01 2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-08 2000-01-09 -0.939523920 0.679475552 -0.248264399 0.658726986 -0.154457503 -0.327342956 1.358551653 -0.051436045 0.455469878 2000-01-10 2000-01-11 2000-01-12 2000-01-13 2000-01-14 2000-01-15 2000-01-16 2000-01-17 2000-01-18 2.982439031 0.499840045 0.009528193 0.372458627 -0.762186202 -0.988996299 -0.673831659 -0.443536816 0.413445687 2000-01-19 2000-01-20 2000-01-21 2000-01-22 2000-01-23 2000-01-24 2000-01-25 2000-01-26 2000-01-27 -0.069849302 0.520691745 -0.296890679 2.093093754 0.696635791 -0.286680977 -0.354431757 -0.157794595 -2.247776154 2000-01-28 2000-01-29 2000-01-30 -1.429291735 -0.302251311 0.071380311 > dat[[4]] 2000-01-01 2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-08 2000-01-09 1.229357467 -1.231028063 -0.384540478 1.058490237 -0.275243948 0.097183122 -1.768885144 -0.611407839 -3.441311777 2000-01-10 2000-01-11 2000-01-12 2000-01-13 2000-01-14 2000-01-15 2000-01-16 2000-01-17 2000-01-18 -0.312644935 0.380036670 0.025232772 -0.090080369 -1.157750720 0.859936199 0.590191927 -0.824260485 -1.570709392 2000-01-19 2000-01-20 2000-01-21 2000-01-22 2000-01-23 2000-01-24 2000-01-25 2000-01-26 2000-01-27 -1.356200595 -0.163619627 1.680948233 2.045026560 1.756296234 -1.422084889 -0.075294543 1.986966298 0.171919466 2000-01-28 2000-01-29 2000-01-30 2000-01-31 2000-02-01 2000-02-02 2000-02-03 2000-02-04 2000-02-05 0.474975000 -1.226787467 0.508195208 -1.237140935 0.361799136 0.497959878 -0.857453525 2.833531013 0.396793937 2000-02-06 2000-02-07 2000-02-08 2000-02-09 -0.966378375 0.556724596 0.170147308 -0.005016784 Now I want to merge all these 4 time series with "all=FALSE". I have tried with Reduce() function, However could not get desired result : > tail(Reduce("merge", dat)) init x[[i]] x[[i]].1 x[[i]].2 2000-02-04 NA NA NA 2.833531013 2000-02-05 NA NA NA 0.396793937 2000-02-06 NA NA NA -0.966378375 2000-02-07 NA NA NA 0.556724596 2000-02-08 NA NA NA 0.170147308 2000-02-09 NA NA NA -0.005016784 If I all additinal argument for merge() function I get error : > tail(Reduce("merge", all=F, dat)) Error in Reduce("merge", all = F, dat) : unused argument(s) (all = F) How to force R to report the data available only for all days? Thanks, -- View this message in context: http://n4.nabble.com/Merging-list-object-tp1838111p1838111.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Matrix to list object
let consider following matrix : mat <- matrix(rnorm(45), 15) Now I want to convert it to a list object "mat_list", which will have 15 elements and each element will again be a matrix with 3 rows and 3 columns. How can I do that? Thanks, -- View this message in context: http://n4.nabble.com/Matrix-to-list-object-tp989738p989738.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] RHTMLForms Package
Can anyone tell me from where to download the package "RHTMLForms" ? CRAN seems not holding this anymore. I am using Windows Vista OS. Thanks -- View this message in context: http://n4.nabble.com/RHTMLForms-Package-tp997672p997672.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] A question
Hi all, I have a expression like that : > rep(2,4) [1] 2 2 2 2 Now I want to write it as "" through some automated way. Is there is function for doing that? I have tested with paste(), but count not get any desired result. Thanks, -- View this message in context: http://n4.nabble.com/A-question-tp1018144p1018144.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Problem to create a matrix polynomial
Dear all R users, I was trying to create a polymonial using the polynom() of "PolynomF" package. My problem is, if I pass coefficients as simple numerical values, it is working, but for matrix coefficient it is not. Here is my try: library(PolynomF) z <- polynom() ## following is working p1 <- 1- 4.5*z ## However following is not giving results as intended p1 <- diag(3)- matrix(1:9, 3,3)*z In the 2nd example, I was expecting a matrix polynomial in "z" upto degree 1, which I did not get. Can anyone please correct me how to address this problem? Thanks, -- View this message in context: http://r.789695.n4.nabble.com/Problem-to-create-a-matrix-polynomial-tp2993411p2993411.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.