Displaying 20 results from an estimated 9000 matches similar to: "Flattening and unflattening symmetric matrices"
2007 Jul 28
8
generating symmetric matrices
Greetings,
I have a seemingly simple task which I have not been able to solve today. I want to construct a symmetric matrix of arbtriray size w/o using loops. The following I thought would do it:
p <- 6
Rmat <- diag(p)
dat.cor <- rnorm(p*(p-1)/2)
Rmat[outer(1:p, 1:p, "<")] <- Rmat[outer(1:p, 1:p, ">")] <- dat.cor
However, the problem is that the matrix
2004 Nov 25
4
Avoiding for-loops
Hello R-users,
I have a symmetric matrix of numerical values and I
want to obtain those values in the upper or lower
triangle of the matrix in a vector. I tried to do the
job by using two for-loops but it doens't seem to be a
clever way, and I'd like to know a more efficient code
for a large matrix of thousands of rows and columns.
Below is my code for your reference.
Thanks a lot.
2011 Dec 23
1
Help creating a symmetric matrix?
Hi,
I am trying to work with the output of the MINE analysis routine found at
http://www.exploredata.net
Specifically, I am trying to read the results into a matrix (ideally an
n x n x 6 matrix, but I'll settle right now for getting one column into
a matrix.)
The problem I have is not knowing how to take what amounts to being one
half of a symmetric matrix - excluding the diagonal -
2008 Sep 21
2
Symmetric matrix
I have following matrix :
a = matrix(rnorm(36), 6)
Now I want to replace the lower-triangular elements with it's upper-triangular elements. That is I want to make a symmetric matrix from a. I have tried with lower.tri() and upper.tri() function, but got desired result. Can anyone please tell me how to do that?
2011 Jun 02
4
generating random covariance matrices (with a uniform distribution of correlations)
List members,
Via searches I've seen similar discussion of this topic but have not seen
resolution of the particular issue I am experiencing. If my search on this
topic failed, I apologize for the redundancy. I am attempting to generate
random covariance matrices but would like the corresponding correlations to
be uniformly distributed between -1 and 1.
The approach I have been using is:
2007 Nov 16
1
Efficient way to compute power of a sparse matrix
Dear all,
I would like to compute power of a square non symmetric matrix. This is
a part of a simulation study. Matrices are quite large (e.g., 900 by
900), and contains many 0 (more than 99 %). I have try the function
mtx.exp of the Biodem package:
library(Biodem)
m <- matrix(0, 900, 900)
i <- sample(1:900, 3000, replace = T)
j <- sample(1:900, 3000, replace = T)
for(x in 1:3000)
2009 Jan 07
2
Memory Efficiency of Symmetric Matrix
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm generating a symmetric correlation matrix using a data matrix as input:
mat <- cor(data.mat)
My question is:
Is there a more memory efficient way to store this data? For instance, since:
all(mat == t(mat))
every value is duplicated, and I should be able to almost half the memory usage for large matrices.
Any thoughts/comments?
Cheers,
2011 Jan 20
2
splitting a square symmetric matrix
So many matrices are square symmetrical (i.e. variance-covariance matrices),
is there any way to get R to split the matrix on its diagonal and just
return one diagonal?
So if I have
mat<-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE)
is there anyway to get the lower right diagonal instead of the entire
symmetric matrix?
-------------------------------------------
2010 Apr 23
2
Matrix diagonal help
Hi
Suppose I have a matrix (cohort are rows and years are columns)
[2000] [2001] [2002] [2003]
[C1] 0.01 0.03 0.02 0.09
[C2] 0.06 0.05 0.07 0.11
[C3] 0.1 0.5 0.4 0.98
[C4] 0.7 0.6 0.2 0.77
I want to extracts the diagonals to get a matrix which looks like this (C1
becomes C2 in 2002, C2 becomes C3 in 2003
2005 Aug 31
0
eigen-decomposition of symmetric BCCB matrices
Hi,
Can anyone please point to how to decompose BCCB
(Block-Circulant-Circulant-Block) matrices? I am interested in the derivations:
I do know that this can be numerically done using 2-dimensional FFTs.
Many thanks and best wishes!
2005 May 01
2
eigen() may fail for some symmetric matrices, affects mvrnorm()
Hi all,
Recently our statistics students noticed that their Gibbs samplers were
crashing due to some NaNs in some parameters. The NaNs came from
mvrnorm (Ripley & Venables' MASS package multivariate normal sampling
function) and with some more investigation it turned out that they were
generated by function eigen, the eigenvalue computing function. The
problem did not seem to happen
2013 Jun 18
1
eigen(symmetric=TRUE) for complex matrices
R-3.0.1 rev 62743, binary downloaded from CRAN just now; macosx 10.8.3
Hello,
eigen(symmetric=TRUE) behaves strangely when given complex matrices.
The following two lines define 'A', a 100x100 (real) symmetric matrix
which theoretical considerations [Bochner's theorem] show to be positive
definite:
jj <- matrix(0,100,100)
A <- exp(-0.1*(row(jj)-col(jj))^2)
A's being
2009 Jul 29
1
Drawing lines in margins
Hi all,
Quick question: What function can I use to draw a line in the margin of a plot? segments() and lines() both stop at the margin.
In case the answer depends on exactly what I'm trying to do, see below. I'm using R v. 2.8.1 on Windows XP.
Cheers,
Alan
I'm trying to make a horizontal barplot with a column of numbers on the right side. I'd like to put a line between the
2008 Apr 27
2
Raising a matrix to the (-1/2) power.
Hi, I need to raise a correlation matrix; R; to the negative one half power.
i.e. I need to find R^(-1/2)
eg: if R=[{1,.4},{.4,1}], then R^(-1/2)=[{1.0681,-.2229},
{-.2229,1.0681}]where matrix=[{row1},{row2}]
And are there any built in functions to do this? mtx.exp doesn't work
because it's not raised to a positive integer
Thank you so much.
--
View this message in context:
2005 Feb 23
1
H-F corr.: covariance matrix for interaction effect
Hi,
I'm still not quite there with my H-F (G-G) correction code. I have it
working for the main effects, but I just can't figure out how to do it
for the effect interactions. The thing I really don't know (and can't
find anything about) is how to calculate the covariance matrix for the
interaction between the two (or even n) main factors.
I've looked through some books
2005 Feb 23
1
H-F corr.: covariance matrix for interaction effect
Hi,
I'm still not quite there with my H-F (G-G) correction code. I have it
working for the main effects, but I just can't figure out how to do it
for the effect interactions. The thing I really don't know (and can't
find anything about) is how to calculate the covariance matrix for the
interaction between the two (or even n) main factors.
I've looked through some books
2005 Mar 01
2
almost lower triangular matrices
I have output from a program which produces a distance matrix I want to
read into a clustering program in R.
The output is a .txt file and is 'almost' lower triangular in the sense
that it is just the triangle below the diagonal.
So for example a 4-by-4 distance matrix appears as,
1
2 3
4 5 6
i.e. it looks like a lower triangular of a 3-by3.
I thought I might be able
2003 Jul 03
2
SVD and spectral decompositions of a hermitian matrix
Hi:
I create a hermitian matrix and then perform its singular value
decomposition. But when I put it back, I don't get the original
hermitian matrix. I am having the same problem with spectral value
decomposition as well.
I am using R 1.7.0 on Windows. Here is my code:
X <- matrix(rnorm(16)+1i*rnorm(16),4)
X <- X + t(X)
X[upper.tri(X)] <- Conj(X[upper.tri(X)])
Y <-
2006 Sep 26
2
about the determinant of a symmetric compound matrix
Dear R users,
even if this question is not related to an issue about R, probably some of you will be able to help me.
I have a square matrix of dimension k by k with alpha on the diagonal and beta everywhee else.
This symmetric matrix is called symmetric compound matrix and has the form
a( I + cJ),
where
I is the k by k identity matrix
J is the k by k matrix of all ones
a = alpha - beta
c =
2011 Feb 09
2
Generate multivariate normal data with a random correlation matrix
Hi All.
I'd like to generate a sample of n observations from a k dimensional
multivariate normal distribution with a random correlation matrix.
My solution:
The lower (or upper) triangle of the correlation matrix has
n.tri=(d/2)(d+1)-d entries.
Take a uniform sample of n.tri possible correlations (runi(n.tr,-.99,.99)
Populate a triangle of the matrix with the sampled correlations
Mirror the