[R] Symmetric Matrix classes
David Winsemius
dwinsemius at comcast.net
Fri Nov 27 04:22:00 CET 2009
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
> Error in validObject(.Object) :
> invalid class "dsyMatrix" object: length of x slot != prod(Dim)
>
> Is there an easier way of doing this?
>
> Thanks,
> Gad
>
> --
> Gad Abraham
--
Best;
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list