R's `chol` differs from MATLAB's `cholcov`. How to do a Cholesky-alike covariance decomposition?
<p>I've been trying to reproduce a cholesky-like covariance decomposition in R - like it is done in Matlab using <code>cholcov()</code>. Example taken from <a href="https://uk.mathworks.com/help/stats/cholcov.html" rel="nofollow noreferrer">https://uk.mathworks.com/help/stats/cholcov.html</a>.</p>

<p>Result of the original <code>cholcov()</code> function as of their example:</p>

<pre><code>T =
   -0.2113    0.7887   -0.5774         0
    0.7887   -0.2113   -0.5774         0
    1.1547    1.1547    1.1547    1.7321
</code></pre>

<p>I am trying to replicate this <code>T</code> in R. I tried:</p>

<pre><code>C1 &lt;- cbind(c(2,1,1,2), c(1,2,1,2), c(1,1,2,2), c(2,2,2,3))
T1 &lt;- chol(C1)
C2 &lt;- t(T1) %*% T1
</code></pre>

<p>My result:</p>

<pre><code>         [,1]      [,2]      [,3]         [,4]
[1,] 1.414214 0.7071068 0.7071068 1.414214e+00
[2,] 0.000000 1.2247449 0.4082483 8.164966e-01
[3,] 0.000000 0.0000000 1.1547005 5.773503e-01
[4,] 0.000000 0.0000000 0.0000000 1.290478e-08
</code></pre>

<p><code>C2</code> recovers <code>C1</code>, but <code>T1</code> is quite different from MATLAB's solution. I then thought maybe it would be a Cholesky composition of the covariance matrix:</p>

<pre><code>T1 &lt;- chol(cov(C1))
</code></pre>

<p>but I get</p>

<pre><code>          [,1]      [,2]      [,3]         [,4]
[1,] 0.5773503 0.0000000 0.0000000 2.886751e-01
[2,] 0.0000000 0.5773503 0.0000000 2.886751e-01
[3,] 0.0000000 0.0000000 0.5773503 2.886751e-01
[4,] 0.0000000 0.0000000 0.0000000 3.725290e-09
</code></pre>

<p>which is not right either.</p>

<p>Could anyone give me a hint how <code>cholcov()</code> in Matlab is calculated so that I could replicate it in R?</p>