Skip to content

Commit

Permalink
build based on a2b2072
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Feb 21, 2024
1 parent f86fd2b commit a15f080
Show file tree
Hide file tree
Showing 13 changed files with 3,388 additions and 4,015 deletions.
2 changes: 1 addition & 1 deletion dev/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.1","generation_timestamp":"2024-02-21T02:17:12","documenter_version":"1.2.1"}}
{"documenter":{"julia_version":"1.10.1","generation_timestamp":"2024-02-21T02:24:42","documenter_version":"1.2.1"}}
2 changes: 1 addition & 1 deletion dev/details/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
\mathrm{min}\quad & \frac{1}{2} \Vert G - X \Vert^2 \\
\mathrm{s.t.}\quad & X_{ii} = 1, \quad i = 1, \ldots , n, \\
& X \in S_{+}^{n}
\end{aligned}\]</p><ul><li>Qi, H., &amp; Sun, D. (2006). A quadratically convergent Newton method for computing the nearest correlation matrix. SIAM journal on matrix analysis and applications, 28(2), 360-385.</li></ul><h2 id="Normal-to-Anything-(NORTA)"><a class="docs-heading-anchor" href="#Normal-to-Anything-(NORTA)">Normal to Anything (NORTA)</a><a id="Normal-to-Anything-(NORTA)-1"></a><a class="docs-heading-anchor-permalink" href="#Normal-to-Anything-(NORTA)" title="Permalink"></a></h2><p>Given:</p><ul><li>A target correlation matrix, <span>$\rho$</span></li><li>A list of marginal distributions, <span>$F$</span></li></ul><p>Do:</p><ul><li>Generate <span>$Z_{n \times d} = \mathcal{N}(0, 1)$</span> IID standard normal samples</li><li>Transform <span>$Y = ZC$</span> where <span>$C$</span> is the upper Cholesky factor of <span>$\rho$</span></li><li>Transform <span>$U = \Phi(Y)$</span> where <span>$\Phi(\cdot)$</span> is the CDF of the standard normal distribution</li><li>Transform <span>$X_i = F_{i}^{-1}(U_i)$</span></li></ul></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../main_functions/">« API Reference</a><a class="docs-footer-nextpage" href="../function_index/">Index »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Wednesday 21 February 2024 02:17">Wednesday 21 February 2024</span>. Using Julia version 1.10.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
\end{aligned}\]</p><ul><li>Qi, H., &amp; Sun, D. (2006). A quadratically convergent Newton method for computing the nearest correlation matrix. SIAM journal on matrix analysis and applications, 28(2), 360-385.</li></ul><h2 id="Normal-to-Anything-(NORTA)"><a class="docs-heading-anchor" href="#Normal-to-Anything-(NORTA)">Normal to Anything (NORTA)</a><a id="Normal-to-Anything-(NORTA)-1"></a><a class="docs-heading-anchor-permalink" href="#Normal-to-Anything-(NORTA)" title="Permalink"></a></h2><p>Given:</p><ul><li>A target correlation matrix, <span>$\rho$</span></li><li>A list of marginal distributions, <span>$F$</span></li></ul><p>Do:</p><ul><li>Generate <span>$Z_{n \times d} = \mathcal{N}(0, 1)$</span> IID standard normal samples</li><li>Transform <span>$Y = ZC$</span> where <span>$C$</span> is the upper Cholesky factor of <span>$\rho$</span></li><li>Transform <span>$U = \Phi(Y)$</span> where <span>$\Phi(\cdot)$</span> is the CDF of the standard normal distribution</li><li>Transform <span>$X_i = F_{i}^{-1}(U_i)$</span></li></ul></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../main_functions/">« API Reference</a><a class="docs-footer-nextpage" href="../function_index/">Index »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Wednesday 21 February 2024 02:24">Wednesday 21 February 2024</span>. Using Julia version 1.10.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
2 changes: 1 addition & 1 deletion dev/function_index/index.html

Large diffs are not rendered by default.

1,475 changes: 1,475 additions & 0 deletions dev/getting_started/15ad7dd8.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,522 changes: 1,522 additions & 0 deletions dev/getting_started/29851180.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,385 changes: 0 additions & 1,385 deletions dev/getting_started/413288e4.svg

This file was deleted.

2,239 changes: 0 additions & 2,239 deletions dev/getting_started/cc250c52.svg

This file was deleted.

624 changes: 312 additions & 312 deletions dev/getting_started/79aecc74.svg → dev/getting_started/e08869a4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 26 additions & 26 deletions dev/getting_started/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@
| 114 | 14 | 75 |
| 115 | 18 | 76 |
| 116 | 20 | 68 |
110 rows omitted</code></pre><p>Let’s look at the joint distribution of the Ozone and Temperature</p><img src="79aecc74.svg" alt="Example block output"/><p>We can see that not all margins are normally distributed; the ozone level is highly skewed. Though we don’t know the true distribution of ozone levels, we can go forward assuming that it is log-normally distributed.</p><p>To simulate observations from this joint distribution, we need to estimate the correlation and the marginal parameters.</p><h2 id="Estimating-Correlation"><a class="docs-heading-anchor" href="#Estimating-Correlation">Estimating Correlation</a><a id="Estimating-Correlation-1"></a><a class="docs-heading-anchor-permalink" href="#Estimating-Correlation" title="Permalink"></a></h2><p>To estimate the correlation, we use <code>cor</code> with an argument specifying the type of correlation to estimate. The options are <code>Pearson</code>, <code>Spearman</code>, or <code>Kendall</code>.</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; ρ = cor(Matrix(df), Pearson)</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
110 rows omitted</code></pre><p>Let’s look at the joint distribution of the Ozone and Temperature</p><img src="e08869a4.svg" alt="Example block output"/><p>We can see that not all margins are normally distributed; the ozone level is highly skewed. Though we don’t know the true distribution of ozone levels, we can go forward assuming that it is log-normally distributed.</p><p>To simulate observations from this joint distribution, we need to estimate the correlation and the marginal parameters.</p><h2 id="Estimating-Correlation"><a class="docs-heading-anchor" href="#Estimating-Correlation">Estimating Correlation</a><a id="Estimating-Correlation-1"></a><a class="docs-heading-anchor-permalink" href="#Estimating-Correlation" title="Permalink"></a></h2><p>To estimate the correlation, we use <code>cor</code> with an argument specifying the type of correlation to estimate. The options are <code>Pearson</code>, <code>Spearman</code>, or <code>Kendall</code>.</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; ρ = cor(Matrix(df), Pearson)</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 0.69836
0.69836 1.0</code></pre><h2 id="Defining-Marginal-Distributions"><a class="docs-heading-anchor" href="#Defining-Marginal-Distributions">Defining Marginal Distributions</a><a id="Defining-Marginal-Distributions-1"></a><a class="docs-heading-anchor-permalink" href="#Defining-Marginal-Distributions" title="Permalink"></a></h2><p>Next we can estimate the marginal parameters. Assuming that the <code>Temperature</code> is normally distributed, it has parameters:</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; μ_Temp = mean(df.Temp)</code><code class="nohighlight hljs ansi" style="display:block;">77.87068965517241</code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; σ_Temp = std(df.Temp)</code><code class="nohighlight hljs ansi" style="display:block;">9.48548563759966</code></pre><p>and assuming that <code>Ozone</code> is log-normally distributed, it has parameters:</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; μ_Ozone = mean(log.(df.Ozone))</code><code class="nohighlight hljs ansi" style="display:block;">3.418515100812007</code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; σ_Ozone = sqrt(mean((log.(df.Ozone) .- mean(log.(df.Ozone))).^2))</code><code class="nohighlight hljs ansi" style="display:block;">0.8617359690270703</code></pre><p>Finally we take the parameters and put them into a vector of margins:</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; margins = [Normal(μ_Temp, σ_Temp), LogNormal(μ_Ozone, σ_Ozone)]</code><code class="nohighlight hljs ansi" style="display:block;">2-element Vector{Distribution{Univariate, Continuous}}:
Normal{Float64}(μ=77.87068965517241, σ=9.48548563759966)
LogNormal{Float64}(μ=3.418515100812007, σ=0.8617359690270703)</code></pre><h2 id="Correlation-Bounds"><a class="docs-heading-anchor" href="#Correlation-Bounds">Correlation Bounds</a><a id="Correlation-Bounds-1"></a><a class="docs-heading-anchor-permalink" href="#Correlation-Bounds" title="Permalink"></a></h2><p>Given a vector of margins, the theoretical lower and upper correlation coefficients can be estimated using simulation:</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; lower, upper = cor_bounds(margins, Pearson);</code><code class="nohighlight hljs ansi" style="display:block;"></code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; lower</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 -0.807527
-0.807527 1.0</code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; upper</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 0.808883
0.808883 1.0</code></pre><p>The <code>pearson_bounds</code> function uses more sophisticated methods to determine the theoretical lower and upper Pearson correlation bounds. It also requires more computational time.</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; lower, upper = pearson_bounds(margins);</code><code class="nohighlight hljs ansi" style="display:block;"></code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; lower</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 -0.827695
-0.827695 1.0</code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; upper</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 0.826898
0.826898 1.0</code></pre><p>The <code>pearson_bounds</code> function uses more sophisticated methods to determine the theoretical lower and upper Pearson correlation bounds. It also requires more computational time.</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; lower, upper = pearson_bounds(margins);</code><code class="nohighlight hljs ansi" style="display:block;"></code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; lower</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 -0.821122
-0.821122 1.0</code><br/><code class="language-julia-repl hljs" style="display:block;">julia&gt; upper</code><code class="nohighlight hljs ansi" style="display:block;">2×2 Matrix{Float64}:
1.0 0.821122
0.821122 1.0</code></pre><h2 id="Simulating-Multivariate-Data"><a class="docs-heading-anchor" href="#Simulating-Multivariate-Data">Simulating Multivariate Data</a><a id="Simulating-Multivariate-Data-1"></a><a class="docs-heading-anchor-permalink" href="#Simulating-Multivariate-Data" title="Permalink"></a></h2><p>Let’s now simulate 10,000 observations from the joint distribution using <code>rvec</code>:</p><pre><code class="language-julia-repl hljs" style="display:block;">julia&gt; x = rvec(10_000, ρ, margins)</code><code class="nohighlight hljs ansi" style="display:block;">10000×2 Matrix{Float64}:
73.5149 33.4932
87.8056 28.5674
68.7403 12.457
61.3621 7.22837
74.7645 70.4748
75.4706 20.6238
69.9828 10.0259
56.979 6.31042
82.285 45.5811
75.3011 37.3477
87.4109 22.3591
75.7104 19.7585
61.4875 7.91311
87.2304 93.3604
80.5391 20.9102
74.0107 42.8532
92.2595 76.5276
59.7821 20.2999
73.4545 4.69385
77.3004 18.7691
74.3841 33.5517
76.7599 29.6025
93.9216 136.805
87.9215 91.6839
84.193 56.5316
71.6759 21.7275
58.5467 8.13902
80.2676 41.4696
69.3834 10.5428</code></pre><h2 id="Visualizing-Bivariate-Data"><a class="docs-heading-anchor" href="#Visualizing-Bivariate-Data">Visualizing Bivariate Data</a><a id="Visualizing-Bivariate-Data-1"></a><a class="docs-heading-anchor-permalink" href="#Visualizing-Bivariate-Data" title="Permalink"></a></h2><pre><code class="language-julia hljs">df_sim = DataFrame(x, [:Temp, :Ozone]);
82.8761 34.0147
75.0262 41.8732
67.5626 53.1339
64.4427 7.12912
81.6657 47.3555
63.7596 7.44514
88.6181 44.4193
83.7085 134.4
71.7335 35.387</code></pre><h2 id="Visualizing-Bivariate-Data"><a class="docs-heading-anchor" href="#Visualizing-Bivariate-Data">Visualizing Bivariate Data</a><a id="Visualizing-Bivariate-Data-1"></a><a class="docs-heading-anchor-permalink" href="#Visualizing-Bivariate-Data" title="Permalink"></a></h2><pre><code class="language-julia hljs">df_sim = DataFrame(x, [:Temp, :Ozone]);

histogram2d(df_sim.:Temp, df_sim.:Ozone, nbins=250, legend=false,
xlims=extrema(df.:Temp) .+ (-10, 10),
ylims=extrema(df.:Ozone) .+ (0, 20))</code></pre><img src="413288e4.svg" alt="Example block output"/><p><strong>Compared to Uncorrelated Samples</strong></p><p>We can compare the bivariate distribution above to one where no correlation is taken into account.</p><pre><code class="language-julia hljs">df_sim2 = DataFrame(
ylims=extrema(df.:Ozone) .+ (0, 20))</code></pre><img src="29851180.svg" alt="Example block output"/><p><strong>Compared to Uncorrelated Samples</strong></p><p>We can compare the bivariate distribution above to one where no correlation is taken into account.</p><pre><code class="language-julia hljs">df_sim2 = DataFrame(
Temp = rand(margins[1], 10000),
Ozone = rand(margins[2], 10000)
);

histogram2d(df_sim2.:Temp, df_sim2.:Ozone, nbins=250, legend=false,
xlims=extrema(df.:Temp) .+ (-10, 10),
ylims=extrema(df.:Ozone) .+ (0, 20))</code></pre><img src="cc250c52.svg" alt="Example block output"/></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Bigsimr.jl</a><a class="docs-footer-nextpage" href="../pearson_matching/">Pearson Matching »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Wednesday 21 February 2024 02:17">Wednesday 21 February 2024</span>. Using Julia version 1.10.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
ylims=extrema(df.:Ozone) .+ (0, 20))</code></pre><img src="15ad7dd8.svg" alt="Example block output"/></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Bigsimr.jl</a><a class="docs-footer-nextpage" href="../pearson_matching/">Pearson Matching »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Wednesday 21 February 2024 02:24">Wednesday 21 February 2024</span>. Using Julia version 1.10.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit a15f080

Please sign in to comment.