I want to generate correlation matrix such that it follows the below structure $$\Sigma = B \Lambda B^T $$  where $\Lambda$ is a diagonal matrix containing positive elements, $\Sigma \in R^{n \times n}$ is a correlation matrix and $B \in R^{n \times k}$ where $k$ is less than $n$. Here each column of $B$ is a sparse column with a certain sparsity $\lambda$ and $B$ is not necessarily orthogonal matrix. I am not sure how to generate a correlation matrix given above structure.
123615
I want to simulate a correlation matrix which has some off-diagonal structures and also should have some hierarchical structures. For simulating correlation matrices which contain hierarchical structures, I am using . But, I don't know how to add off-diagonal structures to it. I want to simulate a correlation matrix which somewhat have off-diagonal structures as below image    An example of a hierarchical structure in the correlation matrix is below image   Does anyone have a suggestion on how to simulate such correlation matrices?
62898
I’m trying to generate correlated random sequence with mean = $0$, variance = $1$, correlation coefficient = $0.8$. In the code below, I use s1 &amp; s2 as the standard deviations, and m1 &amp; m2 as the means.   p = 0.8  u = randn(1, n) v = randn(1, n) x = s1 * u + m1 y = s2 * (p * u + sqrt(1 - p^2) * v) + m2   This gives me the correct corrcoef() of 0.8 between x and y. My question is how can I generate a series means if I want z that is also correlated with y (with the same correlation $r=0.8$), but not with x. Is there a particular formula I need to know? I found  but couldn't understand it.
94166
Can someone show me step-by-step how to diagonalize this matrix? I'm trying to teach myself differential equations + linear algebra, but I'm stumped on how to do this. I'd really appreciate if someone would take the time to do this with me!   $\begin{bmatrix} 1 &amp; 2 &amp; 0 \\ 2 &amp; 1 &amp; 0 \\ 0 &amp; 0 &amp; -3 \\ \end{bmatrix}$
43549
We have a multivariate normal vector ${\boldsymbol Y} \sim \mathcal{N}(\boldsymbol\mu, \Sigma)$. Consider partitioning $\boldsymbol\mu$ and ${\boldsymbol Y}$ into  $$\boldsymbol\mu = \begin{bmatrix}  \boldsymbol\mu_1 \\  \boldsymbol\mu_2 \end{bmatrix} $$ $${\boldsymbol Y}=\begin{bmatrix}{\boldsymbol y}_1 \\  {\boldsymbol y}_2 \end{bmatrix}$$  with a similar partition of $\Sigma$ into $$  \begin{bmatrix} \Sigma_{11} &amp; \Sigma_{12}\\ \Sigma_{21} &amp; \Sigma_{22} \end{bmatrix} $$ Then, $({\boldsymbol y}_1|{\boldsymbol y}_2={\boldsymbol a})$, the conditional distribution of the first partition given the second, is  $\mathcal{N}(\overline{\boldsymbol\mu},\overline{\Sigma})$, with mean $$ \overline{\boldsymbol\mu}=\boldsymbol\mu_1+\Sigma_{12}{\Sigma_{22}}^{-1}({\boldsymbol a}-\boldsymbol\mu_2) $$ and covariance matrix $$ \overline{\Sigma}=\Sigma_{11}-\Sigma_{12}{\Sigma_{22}}^{-1}\Sigma_{21}$$  Actually these results are provided in Wikipedia too, but I have no idea how the $\overline{\boldsymbol\mu}$ and $\overline{\Sigma}$ is derived. These results are crucial, since they are important statistical formula for deriving Kalman filters. Would anyone provide me a derivation steps of deriving $\overline{\boldsymbol\mu}$ and $\overline{\Sigma}$ ? Thank you very much!
59258
Can anybody please suggest how I can compute the moment generating function of the inner product of two Gaussian random vectors, each distributed as $\mathcal N(0,\sigma^2)$, independent of each other? Is there some standard result available for this? Any pointer is highly appreciated.
122929
I heard that partial correlations between random variables can be found by inverting the covariance matrix and taking appropriate cells from such resulting precision matrix (this fact is mentioned in , but without a proof).  Why is this the case?
73485
I read in G. Strang's Linear Algebra and its Applications that, if $A$ and $B$ are diagonalisable matrices of the form  such that $AB=BA$, then their eigenvector matrices $S_1$ and $S_2$ (such that $A=S_1\Lambda_1S_1^{-1}$ and $B=S_2\Lambda_2 S_2^{-1}$) can be chosen to be equal: $S_1=S_2$.  How can it be proved?  I have found a proof , but it is not clear to me how to see that $C$ is diagonalisable as $DCD^{-1}=Q$. Matrix $C$ obviously is the matrix with the coordinates of $B\mathbf{x}$ with respect to the basis $\{\mathbf{x}_1,...,\mathbf{x}_k\}$ of the eigenspaceof $V_\lambda (A)$, but I do not see how we can know that it is diagonalisable.  Thank you very much for any explanation of the linked proof or other proof!!!  EDIT: Corrected statement of the lemma I am interested in. See comments below by the users whom I thank for what they have noticed.
71130
According to some articles (e.g. ) correlation is just a centered version of cosine similarity. I use the following code to calculate the cosine similarity matrix of the column vectors of a matrix X (slightly modified from ):  cos.sim &lt;- function(ix)  {   A = X[,ix[1]]   B = X[,ix[2]]   return(t(A)%*%B/sqrt(sum(A^2)*sum(B^2))) }    n &lt;- ncol(X)  cmb &lt;- expand.grid(i=1:n, j=1:n)  C &lt;- matrix(apply(cmb,1,cos.sim),n,n)   My question  Which modifications of the code above are needed to get the correlation matrix cor(X) instead of the cosine similarity matrix. I guess the changes are minimal but I can't see them at the moment.
109668
Let $A\in\mathcal{M}_{n}(K)$, where $K$ is a field. Then, we can obtain the characteristic polynomial of $A$ by simply taking $p(\lambda)=\det(A-\lambda I_n)$, which give us something like $$p(\lambda) = (-1)^n\lambda^n + (-1)^{n-1}(\text{tr } A)\lambda^{n-1} +  \cdots + \det A$$ Now, how can we obtain the matrix $A$ knowing the characteristic polynomial?
12264
I'm working my way through the Oxford notes in Probabilistic Combinatorics and came across this question in one of the question sheets; I'd like to stress that this is not my homework: I'm simply working through the notes for my own pleasure.   For $n, r ∈ \mathbb{N}$, $1 &lt; r &lt; n$, let $z(r, n)$ be the largest possible number of $0$ entries in an $n × n$ matrix which has no $r × r$ submatrix whose entries are all $0$. (Here a submatrix is obtained by selecting any $r$ rows and any $r$ columns; the rows/columns need not be consecutive.)  Consider a random matrix in which each entry is $0$ with probability $p$ and $1$ with probability $1−p$, independently.   Deduce that $z(r, n) &gt; pn^{2}-p^{r^{2}}n^{2r}.$  My solution:  Let $[n]_{2}$ denote the set of all $n \times n$ matrices, with only $0-1$ entries. For each $\sigma \in [n]_{2}$ let the random variable $X(\sigma)$ denote the number of $0$ entries in $\sigma$ and the random variable $Y(\sigma)$ denote the number of $r \times r$ submatrices filled with entirely with $0$'s. It follows that $\mathbb{E}(X)=pn^{{2}}$ and $\mathbb{E}(Y)=\binom{n}{r}^{2}p^{r^{2}}&lt;n^{2r}p^{r^{2}}$.   Further more consider the random variable $X-Y$ for which $\mathbb{E}(X-Y)&gt;pn^{2}-n^{2r}p^{r^{2}}$. It follows that there exists a $\sigma \in [n]_{2}$ such that $X(\sigma)-Y(\sigma)&gt;pn^{2}-n^{2r}p^{r^{2}}$. Given such a $\sigma$ construct $\sigma' \in [n]_{2}$ as follows. For each of the all $0$, $r \times r$ sub matrices of $\sigma$ remove at random a single $0$ from each to ensure $\sigma'$ has no $r \times r$ such sub-matrices. We have removed at most $\binom{n}{r}^{2}&lt;n^{2r}$ such zero's and so we can conclude that $\sigma'$ has at least $pn^{2}-p^{r^{2}}n^{2r}$ zeros thus we can conclude that $z(n,r)&gt;pn^{2}-p^{r^{2}}n^{2r}$.  I'd appreciate any comments on the validity of the proof.
60439
I try to understand and visualize myself covariance matrix. Supposing I have a matrix A = [ 2 3 4; 5 5 6 ], how do I calculate its covariance matrix, and what is its practical meaning? (All I was able to understand by now is that on the diagonal of the covariance matrix, variances for particular variables are placed, and on the upper and lower fields correlations between those variables.)
104766
Find two matrices $\mathbf{A}\in\mathbb{C}^{2\times2}$ and $\mathbf{B}\in\mathbb{C}^{2\times2}$ such that:   they have the same eigenvalues  but they are NOT similar   MY ATTEMPT  The characteristic polynomial of $\mathbf{A}$ is $p_{\mathbf{A}}(\lambda)=\lambda^{2}-\mathrm{tr}(\mathbf{A})+\mathrm{det}(\mathbf{A})$ and the characteristic polynomial of $\mathbf{B}$ is $p_{\mathbf{B}}(\lambda)=\lambda^{2}-\mathrm{tr}(\mathbf{B})+\mathrm{det}(\mathbf{B})$.   "The same eigenvalues" $\Longleftrightarrow P_{\mathbf{A}}(\lambda)=P_{\mathbf{B}}(\lambda)\Longleftrightarrow$ $\Longleftrightarrow\begin{cases} \begin{array}{c} \mathrm{tr}(\mathbf{A})=\mathrm{tr}(\mathbf{B})\\ \mathrm{det}(\mathbf{A})=\mathrm{det}(\mathbf{B}) \end{array} &amp; \Longleftrightarrow\end{cases}\begin{cases} \begin{array}{c} a_{11}+a_{22}=b_{11}+b_{22}\\ a_{11}a_{22}-a_{21}a_{12}=b_{11}b_{22}-b_{21}b_{12} \end{array}\end{cases}$  And now?
108581
I want to know the relationship between the eigensystems of two non-negative-definite (covariance-like) matrices.  Both are derived from X which is a T-by-K real matrix (wlog say K > T).  I avoid subtracting the mean to avoid complicating the main issue which is about the eigensystem structure.  Ct = (1/T) * X' X = Et Lt Et' Ck = (1/K) * X X' = Ek Lk Ek'  .... where Et, Lt are the (column) eigenvectors and diagonal matrix of eigenvalues respectively for Ct, and Ek Lk are the same for Ck.  I remember vaguely from school that there is some kind of duality relationship here (between the two eigensystems) which is particularly interesting because both matrices have rank T &lt; K, and hence only T of the diagonal elements of Lt are nonzero.  Does anyone know this relationship explicitly? Thanks in advance for any light you can shed!
58654
I was wondering if it might be possible to generate correlated random binomial variables following a linear transformation approach?  Below, I tried something simple in R and it produces some correlation. But I was wondering if there is a principled way to do this?  X1 = rbinom(1e4, 6, .5) ; X2 = rbinom(1e4, 6, .5) ;  X3 = rbinom(1e4, 6, .5) ; a = .5  Y1 = X1 + (a*X2) ; Y2 = X2 + (a*X3) ## Y1 and Y2 are supposed to be correlated  cor(Y1, Y2)
115178
Is the set of all $n\times n$ matrices, such that for any fixed matrix B AB=BA, a subspace of the vector space of all $n\times n$ matrices?   Alright, I understand the question and I know what I have to do, basically. I need to show that additive closure and multiplicative closure are satisfied. The problem is, I can't figure out how to do this generally. I tried playing around with $2\times 2$ matrices but that seemed like a dead end. Obviously two such matrices are the 0 matrix and the identity matrix, and those form a subspace, but that doesn't really tell me about all the matrices. Any ideas for how I should be tackling this? I feel like I'm not thinking generally enough.
119440
Let $A = \left[ \begin{array}{*{20}{c}} 0&amp;b&amp;0&amp;0&amp;0&amp;0\\ c&amp;0&amp;b&amp;0&amp;0&amp;0\\ 0&amp;c&amp;0&amp;b&amp;0&amp;0\\ 0&amp;0&amp;c&amp;0&amp;b&amp;0\\ 0&amp;0&amp;0&amp;c&amp;0&amp;b\\ 0&amp;0&amp;0&amp;0&amp;c&amp;0 \end{array} \right]_{n \times n}$.  Why does matrix $A$ have spectrum $\sigma (A) = \left\{ 2\sqrt {bc} \cos \left(\frac{\pi k}{n + 1}\right):k = 1,2,\ldots,n \right\}$?
70859
We have a multivariate normal vector $\mathbf{X} \sim \mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma})$, where $\mathbf{X} =  \left[ \begin{matrix} X_1 \\ X_2 \\ \dot\\\\ \dot\\\\ X_n \end{matrix} \right]$,    $\boldsymbol{\mu} =  \left[ \begin{matrix} \mu_1 \\ \mu_2 \\ \dot\\\\ \dot\\\\ \mu_n \end{matrix} \right]$, and  $\boldsymbol{\Sigma} =  \begin{bmatrix} \sigma_1^2 &amp; \sigma_1\sigma_2 &amp; \dots &amp; \sigma_1\sigma_n   \\ \sigma_2\sigma_1 &amp; \sigma_2^2 &amp; \dots &amp; \sigma_2\sigma_n  \\ \dot\\\\ \dot\\\\ \sigma_n\sigma_1 &amp; \sigma_n\sigma_2  &amp; \dots &amp; \sigma_n^2 \end{bmatrix} $ is the covariance matrix.  Y is a random scalar of the form $Y = \beta_0 + \boldsymbol{\beta^TX} + \epsilon$, where $\epsilon \sim \mathcal{N}(0, \sigma_\epsilon^2)$  How can we go about deriving the joint probability density function(pdf) of the random vector $(Y, \boldsymbol{X^T})$?  The marginal multivariate pdf of $\boldsymbol{X}$ is given by  $ pdf(\boldsymbol{x}) = \frac{1}{\sqrt{(2\pi})^n. \begin{vmatrix} \boldsymbol{\Sigma} \end{vmatrix}}.exp\left[ \frac{-1}{2}\boldsymbol{(x-\mu)}^T \boldsymbol{\Sigma^{-1}}\boldsymbol{(x-\mu)} \right]$  The conditional probability density function of $Y \,\mid \, \boldsymbol{X=x}$ is given by  $pdf(y\mid \boldsymbol{X=x}) = \frac{1}{2\pi\sigma_\epsilon}.exp\left[  \frac{-1}{2\sigma_\epsilon^2}(y - \beta_0 - \boldsymbol{\beta^Tx})^2  \right]   $  To compute the joint probability density function, we can use the fact that   $pdf(y, \boldsymbol{x})=  pdf(y\mid \boldsymbol{X=x}).pdf(\boldsymbol{x})$  I am unable to do the witty manipulation required in the algebra to arrive at the result the joint distribution will have a probability density function of a normal distribution. All questions previously asked seem to address the problem of deriving the conditional density function given the joint probability density function, for example,   Edit:  Multiplying the pdfs, we get $pdf(y, \boldsymbol{x}) = \frac{1}{\sqrt{(2\pi})^n. \begin{vmatrix} \boldsymbol{\Sigma} \end{vmatrix}}. \frac{1}{2\pi\sigma_\epsilon}.exp\left[ \frac{-1}{2}\boldsymbol{(x-\mu)}^T \boldsymbol{\Sigma^{-1}}\boldsymbol{(x-\mu)} + \frac{-1}{2\sigma_\epsilon^2}(y - \beta_0 - \boldsymbol{\beta^Tx})^2 \right]$   Like the comment below mentions, most manipulations dealing with normal pdfs involve completing squares; but since this specific algebraic expression contains $\boldsymbol{x}$ in both terms within the exp term, I'm unsure on how to go about completing the squares.