Skip to content

Commit

Permalink
deploy: 529250f
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddalpiaz committed Sep 16, 2024
1 parent 1fbd617 commit 9e86e30
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
Binary file modified applied_statistics.pdf
Binary file not shown.
16 changes: 8 additions & 8 deletions data-and-programming.html
Original file line number Diff line number Diff line change
Expand Up @@ -1400,11 +1400,11 @@ <h3><span class="header-section-number">3.3.2</span> Functions<a href="data-and-
<p>Here the name of the function is <code>standardize</code>, and the function has a single argument <code>x</code> which is used in the body of function. Note that the output of the final line of the body is what is returned by the function. In this case the function returns the vector stored in the variable <code>result</code>.</p>
<p>To test our function, we will take a random sample of size <code>n = 10</code> from a normal distribution with a mean of <code>2</code> and a standard deviation of <code>5</code>.</p>
<div class="sourceCode" id="cb312"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb312-1"><a href="data-and-programming.html#cb312-1" tabindex="-1"></a>(<span class="at">test_sample =</span> <span class="fu">rnorm</span>(<span class="at">n =</span> <span class="dv">10</span>, <span class="at">mean =</span> <span class="dv">2</span>, <span class="at">sd =</span> <span class="dv">5</span>))</span></code></pre></div>
<pre><code>## [1] 3.4663306 -1.8992181 -3.3143635 -3.4093843 5.3309762 0.7177388
## [7] 2.0023602 0.9305203 0.1863598 2.1499918</code></pre>
<pre><code>## [1] 4.3739701 7.8123334 0.8049539 9.0578998 4.6352177 -7.5363113
## [7] -2.3655660 -7.7944228 6.2973004 4.0238428</code></pre>
<div class="sourceCode" id="cb314"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb314-1"><a href="data-and-programming.html#cb314-1" tabindex="-1"></a><span class="fu">standardize</span>(<span class="at">x =</span> test_sample)</span></code></pre></div>
<pre><code>## [1] 1.00144306 -0.88379048 -1.38101447 -1.41440089 1.65660299 0.03570074
## [7] 0.48706398 0.11046344 -0.15100402 0.53893564</code></pre>
<pre><code>## [1] 0.4058923 0.9771480 -0.1870703 1.1840886 0.4492965 -1.5729027
## [7] -0.7138260 -1.6157858 0.7254378 0.3477216</code></pre>
<p>This function could be written much more succinctly, simply performing all the operations on one line and immediately returning the result, without storing any of the intermediate results.</p>
<div class="sourceCode" id="cb316"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb316-1"><a href="data-and-programming.html#cb316-1" tabindex="-1"></a>standardize <span class="ot">=</span> <span class="cf">function</span>(x) {</span>
<span id="cb316-2"><a href="data-and-programming.html#cb316-2" tabindex="-1"></a> (x <span class="sc">-</span> <span class="fu">mean</span>(x)) <span class="sc">/</span> <span class="fu">sd</span>(x)</span>
Expand Down Expand Up @@ -1441,14 +1441,14 @@ <h3><span class="header-section-number">3.3.2</span> Functions<a href="data-and-
<span id="cb329-3"><a href="data-and-programming.html#cb329-3" tabindex="-1"></a> (<span class="dv">1</span> <span class="sc">/</span> n) <span class="sc">*</span> <span class="fu">sum</span>((x <span class="sc">-</span> <span class="fu">mean</span>(x)) <span class="sc">^</span> <span class="dv">2</span>)</span>
<span id="cb329-4"><a href="data-and-programming.html#cb329-4" tabindex="-1"></a>}</span></code></pre></div>
<div class="sourceCode" id="cb330"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb330-1"><a href="data-and-programming.html#cb330-1" tabindex="-1"></a><span class="fu">get_var</span>(test_sample)</span></code></pre></div>
<pre><code>## [1] 8.100242</code></pre>
<pre><code>## [1] 36.22784</code></pre>
<div class="sourceCode" id="cb332"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb332-1"><a href="data-and-programming.html#cb332-1" tabindex="-1"></a><span class="fu">get_var</span>(test_sample, <span class="at">biased =</span> <span class="cn">FALSE</span>)</span></code></pre></div>
<pre><code>## [1] 8.100242</code></pre>
<pre><code>## [1] 36.22784</code></pre>
<div class="sourceCode" id="cb334"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb334-1"><a href="data-and-programming.html#cb334-1" tabindex="-1"></a><span class="fu">var</span>(test_sample)</span></code></pre></div>
<pre><code>## [1] 8.100242</code></pre>
<pre><code>## [1] 36.22784</code></pre>
<p>We see the function is working as expected, and when returning the unbiased estimate it matches <code>R</code>’s built-in function <code>var()</code>. Finally, let’s examine the biased estimate of <span class="math inline">\(\sigma^2\)</span>.</p>
<div class="sourceCode" id="cb336"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb336-1"><a href="data-and-programming.html#cb336-1" tabindex="-1"></a><span class="fu">get_var</span>(test_sample, <span class="at">biased =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<pre><code>## [1] 7.290217</code></pre>
<pre><code>## [1] 32.60505</code></pre>

</div>
</div>
Expand Down
16 changes: 8 additions & 8 deletions data-and-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -1949,17 +1949,17 @@ To test our function, we will take a random sample of size `n = 10` from a norma
```

```
## [1] 12.835022 9.646464 3.305105 5.454080 -0.171593 -9.308482 -5.405810
## [8] 4.136374 8.970424 4.704120
## [1] 5.5588628 10.3876969 6.4513614 11.3077184 -4.2592033 -0.7962697
## [7] -0.3575199 -0.3326412 -1.7829676 7.7160442
```

``` r
standardize(x = test_sample)
```

```
## [1] 1.38310669 0.91486460 -0.01636882 0.29920979 -0.52692450 -1.86868350
## [7] -1.29557322 0.10570369 0.81558762 0.18907765
## [1] 0.3923835 1.2657218 0.5538000 1.4321160 -1.3833024 -0.7569996
## [7] -0.6776477 -0.6731482 -0.9354528 0.7825293
```

This function could be written much more succinctly, simply performing all the operations on one line and immediately returning the result, without storing any of the intermediate results.
Expand Down Expand Up @@ -2061,23 +2061,23 @@ get_var(test_sample)
```

```
## [1] 46.37113
## [1] 30.5717
```

``` r
get_var(test_sample, biased = FALSE)
```

```
## [1] 46.37113
## [1] 30.5717
```

``` r
var(test_sample)
```

```
## [1] 46.37113
## [1] 30.5717
```

We see the function is working as expected, and when returning the unbiased estimate it matches `R`'s built-in function `var()`. Finally, let's examine the biased estimate of $\sigma^2$.
Expand All @@ -2088,7 +2088,7 @@ get_var(test_sample, biased = TRUE)
```

```
## [1] 41.73401
## [1] 27.51453
```


1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ <h2><span class="header-section-number">1.3</span> Acknowledgements<a href="inde
<li><a href="https://github.com/djoldman/" target="_blank">David Newman</a></li>
<li><a href="https://github.com/yixingz3" target="_blank">Yixing Zheng</a></li>
<li><a href="https://github.com/OssamaSijbesma" target="_blank">Ossama Sybesma</a></li>
<li><a href="https://github.com/sfindley899" target="_blank">Shaneal Findley</a></li>
</ul>
</div>
<div id="license" class="section level2 hasAnchor" number="1.4">
Expand Down
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Your name could be here! Suggest an edit! Correct a typo! If you submit a correc
- [David Newman](https://github.com/djoldman/){target="_blank"}
- [Yixing Zheng](https://github.com/yixingz3){target="_blank"}
- [Ossama Sybesma](https://github.com/OssamaSijbesma){target="_blank"}
- [Shaneal Findley](https://github.com/sfindley899){target="_blank"}

## License

Expand Down
4 changes: 2 additions & 2 deletions prob-and-stat.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ rnorm(n = 10, mean = 2, sd = 5)
```

```
## [1] -3.4256036 8.7541787 -0.8925227 0.7328776 8.3390382 -0.2870347
## [7] 9.4780333 -3.6029543 7.1857806 7.4014080
## [1] 2.600575 7.344162 9.013289 14.226867 5.463300 1.954447 -1.346849
## [8] 4.065766 3.453854 4.312708
```

These functions exist for many other distributions, including but not limited to:
Expand Down
4 changes: 2 additions & 2 deletions probability-and-statistics-in-r.html
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ <h3><span class="header-section-number">5.1.1</span> Distributions<a href="proba
<pre><code>## [1] 11.79982</code></pre>
<p>Lastly, to generate a random sample of size <code>n = 10</code>, use:</p>
<div class="sourceCode" id="cb360"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb360-1"><a href="probability-and-statistics-in-r.html#cb360-1" tabindex="-1"></a><span class="fu">rnorm</span>(<span class="at">n =</span> <span class="dv">10</span>, <span class="at">mean =</span> <span class="dv">2</span>, <span class="at">sd =</span> <span class="dv">5</span>)</span></code></pre></div>
<pre><code>## [1] 1.3334356 -5.0754528 14.1540511 2.1927133 -3.8482335 -0.2280363
## [7] 7.6598749 -2.7304969 -10.8570448 -6.9123819</code></pre>
<pre><code>## [1] 2.1633378 -1.1196812 0.8459553 6.5446656 1.6821550 4.4308656
## [7] 9.1596978 0.7019646 1.5448990 6.8683464</code></pre>
<p>These functions exist for many other distributions, including but not limited to:</p>
<table>
<thead>
Expand Down
2 changes: 1 addition & 1 deletion search_index.json

Large diffs are not rendered by default.

0 comments on commit 9e86e30

Please sign in to comment.