On Fri, Nov 27, 2009 at 2:22 PM, David Winsemius <dwinsem...@comcast.net> wrote: > > On Nov 26, 2009, at 9:45 PM, Gad Abraham wrote: > >> Hi, >> >> I'd like to store large covariance matrices using Matrix classes. >> >> dsyMatrix seems like the right one, but I want to specify just the >> upper/lower triangle and diagonal and not have to instantiate a huge >> n^2 vector just for the sake of having half of it ignored: >> >> Dumb example: >> M <- new("dsyMatrix", uplo="U", x=rnorm(1e4), Dim=as.integer(c(100, 100))) >> diag(M) <- 1 >> >> This doesn't work: >> M <- new("dsyMatrix", uplo="U", x=0, Dim=as.integer(c(100, 100))) > > Per help > Slots > > uplo:A character object indicating if the upper triangle ("U") or the lower > triangle ("L") is stored. At present only the lower triangle form is > allowed. > > This "works" ( at least to the extent of not producing an error message) > after addressing a couple of other error messages that were helpful. > > M <- new("dsyMatrix", uplo="L", x=as.double(1:(100*100)), > Dim=as.integer(c(100, 100))) > > I'm not sure that I would have expected the result, though it makes a > certain amount of sense after considering the contradictory requirements: > >> M <- new("dsyMatrix", uplo="L", x=as.double(1:(10*10)), >> Dim=as.integer(c(10, 10))) >> M > 10 x 10 Matrix of class "dsyMatrix" > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] > [1,] 1 2 3 4 5 6 7 8 9 10 > [2,] 2 12 13 14 15 16 17 18 19 20 > [3,] 3 13 23 24 25 26 27 28 29 30 > [4,] 4 14 24 34 35 36 37 38 39 40 > [5,] 5 15 25 35 45 46 47 48 49 50 > [6,] 6 16 26 36 46 56 57 58 59 60 > [7,] 7 17 27 37 47 57 67 68 69 70 > [8,] 8 18 28 38 48 58 68 78 79 80 > [9,] 9 19 29 39 49 59 69 79 89 90 > [10,] 10 20 30 40 50 60 70 80 90 100 >
But I don't want to specify x=foo where foo is of length n^2, because that uses a lot of memory (I have 20000 by 20000 matrices). I just want to be able to fill in one triangle and diagonal, like you can with regular non-Matrix matrices: M <- matrix(0, m, n) gdata::lowerTriangle(M) <- x diag(M) <- y -- Gad Abraham PhD Student, Dept. CSSE and NICTA The University of Melbourne Parkville 3010, Victoria, Australia email: gabra...@csse.unimelb.edu.au web: http://www.csse.unimelb.edu.au/~gabraham ______________________________________________ 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.