Skip to content

Commit

Permalink
Deploying to gh-pages from @ ee3aed2 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
freezenik committed Oct 10, 2024
1 parent 9db59a3 commit 87dd786
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
Binary file modified man/HarzTraffic_files/figure-html/unnamed-chunk-1-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/gamlss2.html
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ <h3 class="anchored" data-anchor-id="examples">Examples</h3>
*--------
n = 610 df = 13.12 res.df = 596.88
Deviance = 4770.1554 Null Dev. Red. = 33.39%
AIC = 4796.3966 elapsed = 0.79sec</code></pre>
AIC = 4796.3966 elapsed = 0.78sec</code></pre>
</div>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="do">## plot estimated effects</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(b, <span class="at">which =</span> <span class="st">"effects"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
Expand Down
8 changes: 4 additions & 4 deletions man/prodist.gamlss2.html
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@ <h3 class="anchored" data-anchor-id="examples">Examples</h3>
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="do">## simulate random numbers</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="fu">random</span>(d, <span class="dv">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> r_1 r_2 r_3 r_4 r_5
1 20.05192 12.01664 28.09310 17.86293 32.08695
2 39.93538 54.87385 58.66783 84.24932 77.59599
3 75.54687 126.27259 128.96634 74.50611 173.73709</code></pre>
<pre><code> r_1 r_2 r_3 r_4 r_5
1 21.37530 30.88462 25.30309 11.07565 21.63578
2 36.46126 34.15373 73.37629 75.47346 42.17611
3 102.67860 55.63671 100.03750 99.18436 65.02560</code></pre>
</div>
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="do">## density and distribution</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="fu">pdf</span>(d, <span class="dv">50</span> <span class="sc">*</span> <span class="sc">-</span><span class="dv">2</span><span class="sc">:</span><span class="dv">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
Expand Down
18 changes: 9 additions & 9 deletions search.json

Large diffs are not rendered by default.

Binary file modified vignettes/gamlss2_files/figure-html/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions vignettes/mixture.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ <h1 class="title display-7">Mixture Models</h1>
</header>


<p>Mixture models are used for modeling data generated from multiple distinct processes, where each process can be described by a separate probability distribution. The challenge is that for each observation, we do not know which process generated it, and therefore we must infer the underlying latent classes (or components).</p>
<p>Mixture models are used for modeling data generated from multiple distinct processes, where each process can be described by a separate probability distribution. The challenge is that for each observation, we do not know which process generated it, and therefore we must infer the underlying latent components.</p>
<p>This vignette demonstrates how to fit a mixture of normal distributions where the mixing probabilities depend on a covariate.</p>
<section id="simulating-data" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="simulating-data"><span class="header-section-number">1</span> Simulating Data</h2>
<p>We begin by simulating data where the response <code>y</code> is generated by one of two normal distributions, depending on a covariate <code>x</code>. The latent class membership is determined by a logistic model, where the mixing probability is a function of <code>x</code>.</p>
<p>We begin by simulating data where the response <code>y</code> is generated by one of two normal distributions, depending on a covariate <code>x</code>. The latent component membership is determined by a logistic model, where the mixing probability is a function of <code>x</code>.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">123</span>)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
Expand All @@ -460,7 +460,7 @@ <h2 data-number="1" class="anchored" data-anchor-id="simulating-data"><span clas
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a><span class="do">## plot the data, color by latent component z</span></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a><span class="fu">par</span>(<span class="at">mar =</span> <span class="fu">c</span>(<span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">1</span>))</span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(d, <span class="at">col =</span> z <span class="sc">+</span> <span class="dv">1</span>, <span class="at">main =</span> <span class="st">"Simulated Data by Latent Class"</span>, </span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(d, <span class="at">col =</span> z <span class="sc">+</span> <span class="dv">1</span>, <span class="at">main =</span> <span class="st">"Simulated Data by Latent Component"</span>, </span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a> <span class="at">xlab =</span> <span class="st">"x"</span>, <span class="at">ylab =</span> <span class="st">"y"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
Expand Down Expand Up @@ -529,14 +529,14 @@ <h2 data-number="3" class="anchored" data-anchor-id="fitting-the-mixture-model">
</section>
<section id="predicting-and-visualizing-results" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="predicting-and-visualizing-results"><span class="header-section-number">4</span> Predicting and Visualizing Results</h2>
<p>We predict the component-specific means (<code>mu1</code>, <code>mu2</code>) and the mixing probability (<code>pi</code>) from the fitted model. Then, we compare the predicted and true class probabilities and plot the fitted means along with the data.</p>
<p>First, compute predicted parameters</p>
<p>We predict the component-specific means (<code>mu1</code>, <code>mu2</code>) and the mixing probability (<code>pi</code>) from the fitted model. Then, we compare the predicted and true component probabilities and plot the fitted means along with the data.</p>
<p>First, compute predicted parameters.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>p <span class="ot">&lt;-</span> <span class="fu">predict</span>(b, <span class="at">type =</span> <span class="st">"parameter"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Plot estimated vs.&nbsp;true component probabilities</p>
<p>Plot estimated vs.&nbsp;true component probabilities.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(p<span class="sc">$</span>pi, mix_prob, <span class="at">main =</span> <span class="st">"Estimated vs. True Class Probabilities"</span>, </span>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(p<span class="sc">$</span>pi, mix_prob, <span class="at">main =</span> <span class="st">"Estimated vs. True Component Probabilities"</span>, </span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="at">xlab =</span> <span class="st">"Estimated Probability"</span>, <span class="at">ylab =</span> <span class="st">"True Probability"</span>)</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="fu">abline</span>(<span class="dv">0</span>, <span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
Expand All @@ -546,21 +546,21 @@ <h2 data-number="4" class="anchored" data-anchor-id="predicting-and-visualizing-
</figure>
</div>
</div>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="do">## compute posterior class probabilities</span></span>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="do">## compute posterior component probabilities</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>d1 <span class="ot">&lt;-</span> <span class="fu">dnorm</span>(d<span class="sc">$</span>y, p<span class="sc">$</span>mu1, p<span class="sc">$</span>sigma1)</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>d2 <span class="ot">&lt;-</span> <span class="fu">dnorm</span>(d<span class="sc">$</span>y, p<span class="sc">$</span>mu2, p<span class="sc">$</span>sigma2)</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>totprob <span class="ot">&lt;-</span> <span class="fu">rowSums</span>(<span class="fu">cbind</span>(p<span class="sc">$</span>pi <span class="sc">*</span> d1, (<span class="dv">1</span> <span class="sc">-</span> p<span class="sc">$</span>pi) <span class="sc">*</span> d2))</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>c1 <span class="ot">&lt;-</span> p<span class="sc">$</span>pi <span class="sc">*</span> d1 <span class="sc">/</span> totprob</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>c2 <span class="ot">&lt;-</span> (<span class="dv">1</span> <span class="sc">-</span> p<span class="sc">$</span>pi) <span class="sc">*</span> d2 <span class="sc">/</span> totprob</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a><span class="do">## get classes</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>classes <span class="ot">&lt;-</span> <span class="fu">apply</span>(<span class="fu">cbind</span>(c2, c1), <span class="dv">1</span>, which.max)</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a><span class="do">## get components</span></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>comp <span class="ot">&lt;-</span> <span class="fu">apply</span>(<span class="fu">cbind</span>(c2, c1), <span class="dv">1</span>, which.max)</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a><span class="do">## plot the data and fitted component means</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a><span class="fu">par</span>(<span class="at">mar =</span> <span class="fu">c</span>(<span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">1</span>))</span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(y <span class="sc">~</span> x, <span class="at">data =</span> d,</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a> <span class="at">main =</span> <span class="st">"Fitted Component Means"</span>,</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a> <span class="at">xlab =</span> <span class="st">"x"</span>, <span class="at">ylab =</span> <span class="st">"y"</span>, <span class="at">col =</span> classes)</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a> <span class="at">xlab =</span> <span class="st">"x"</span>, <span class="at">ylab =</span> <span class="st">"y"</span>, <span class="at">col =</span> comp)</span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a><span class="fu">lines</span>(p<span class="sc">$</span>mu1 <span class="sc">~</span> x, <span class="at">col =</span> <span class="dv">2</span>, <span class="at">lwd =</span> <span class="dv">4</span>)</span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a><span class="fu">lines</span>(p<span class="sc">$</span>mu2 <span class="sc">~</span> x, <span class="at">col =</span> <span class="dv">1</span>, <span class="at">lwd =</span> <span class="dv">4</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
Expand All @@ -574,7 +574,7 @@ <h2 data-number="4" class="anchored" data-anchor-id="predicting-and-visualizing-
</section>
<section id="summary" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="summary"><span class="header-section-number">5</span> Summary</h2>
<p>In this vignette, we have demonstrated how to fit a mixture model where the mixing probabilities depend on a covariate. We simulated data, defined a custom mixture family, and fitted the model to estimate the component means and mixing probabilities. Finally, we compared the predicted class probabilities with the true values and visualized the results.</p>
<p>In this vignette, we have demonstrated how to fit a mixture model where the mixing probabilities depend on a covariate. We simulated data, defined a custom mixture family, and fitted the model to estimate the component means and mixing probabilities. Finally, we compared the predicted component probabilities with the true values and visualized the results.</p>



Expand Down
Binary file modified vignettes/mixture_files/figure-html/unnamed-chunk-1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/mixture_files/figure-html/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vignettes/spatial.html
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ <h2 data-number="5" class="anchored" data-anchor-id="estimating-the-model"><span
*--------
n = 3494 df = 98.97 res.df = 3395.03
Deviance = 16484.181 Null Dev. Red. = 14.46%
AIC = 16682.1271 elapsed = 4.45sec</code></pre>
AIC = 16682.1271 elapsed = 4.40sec</code></pre>
</div>
</div>
<p>Model calibration is checked using histogram, Q-Q plot, wormplot etc.</p>
Expand Down
Binary file modified vignettes/spatial_files/figure-html/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 87dd786

Please sign in to comment.