<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>BYU-I Course Project Data</title>
<link>https://byuidatascience.github.io/</link>
<atom:link href="https://byuidatascience.github.io/index.xml" rel="self" type="application/rss+xml"/>
<description>Documentation on the avaialable data that we use in our courses.</description>
<generator>quarto-1.5.56</generator>
<lastBuildDate>Wed, 15 Oct 2025 06:00:00 GMT</lastBuildDate>
<item>
  <title>US Census Record Names</title>
  <dc:creator>DS 250</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_ds/census_names.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>640,295 rows</strong> and <strong>54 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/0d43d66f-d3b7-4c43-8c36-52e3ed69e7f1/_rev1317/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/names_year_csv</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>name:</strong> The birth name</li>
<li><strong>year:</strong> The year of their social security number creation.</li>
<li><strong>State Name Columns:</strong> Each column for the 50 states and DC.</li>
<li><strong>Total:</strong> The total over all the states.</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 16%">
<col style="width: 11%">
<col style="width: 16%">
<col style="width: 9%">
<col style="width: 9%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">year</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1980.63</td>
<td style="text-align: right;">32.00</td>
<td style="text-align: right;">1910</td>
<td style="text-align: right;">1957</td>
<td style="text-align: right;">1989</td>
<td style="text-align: right;">2007</td>
<td style="text-align: right;">2024</td>
<td style="text-align: left;">▃▃▃▆▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">AK</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.72</td>
<td style="text-align: right;">4.95</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">206</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">AL</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9.53</td>
<td style="text-align: right;">56.31</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3050</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">AR</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5.62</td>
<td style="text-align: right;">32.33</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1627</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">AZ</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">6.30</td>
<td style="text-align: right;">29.80</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1047</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">CA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">51.70</td>
<td style="text-align: right;">240.24</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">8315</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CO</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">6.19</td>
<td style="text-align: right;">30.98</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1037</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">CT</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5.69</td>
<td style="text-align: right;">37.79</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1624</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">DC</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2.33</td>
<td style="text-align: right;">17.21</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">883</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">DE</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.06</td>
<td style="text-align: right;">7.60</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">312</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">FL</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">17.59</td>
<td style="text-align: right;">85.48</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">3506</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">GA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">14.48</td>
<td style="text-align: right;">72.85</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">3080</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">HI</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.60</td>
<td style="text-align: right;">8.63</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">326</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">IA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">6.88</td>
<td style="text-align: right;">43.21</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2370</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ID</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2.04</td>
<td style="text-align: right;">10.92</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">530</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">IL</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">25.60</td>
<td style="text-align: right;">145.72</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">6248</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">IN</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">12.29</td>
<td style="text-align: right;">72.68</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3014</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">KS</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5.47</td>
<td style="text-align: right;">30.94</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1387</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">KY</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9.02</td>
<td style="text-align: right;">55.19</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2561</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">LA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9.39</td>
<td style="text-align: right;">46.69</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1681</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">MA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">12.75</td>
<td style="text-align: right;">88.15</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3910</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">MD</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7.81</td>
<td style="text-align: right;">45.69</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1793</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ME</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2.29</td>
<td style="text-align: right;">14.97</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">778</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">MI</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">19.63</td>
<td style="text-align: right;">118.25</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">4941</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">MN</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9.55</td>
<td style="text-align: right;">56.53</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2144</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">MO</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">11.56</td>
<td style="text-align: right;">66.68</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2803</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">MS</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">6.60</td>
<td style="text-align: right;">40.02</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2294</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">MT</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.58</td>
<td style="text-align: right;">10.11</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">473</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">NC</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">14.84</td>
<td style="text-align: right;">79.31</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">3900</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">ND</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.77</td>
<td style="text-align: right;">10.99</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">497</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">NE</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3.81</td>
<td style="text-align: right;">23.05</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1060</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">NH</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.63</td>
<td style="text-align: right;">10.96</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">447</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">NJ</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">14.32</td>
<td style="text-align: right;">87.42</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">3713</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">NM</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2.79</td>
<td style="text-align: right;">14.35</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">589</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">NV</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.71</td>
<td style="text-align: right;">9.82</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">340</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">NY</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">40.09</td>
<td style="text-align: right;">229.81</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">10051</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">OH</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">24.02</td>
<td style="text-align: right;">146.96</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">5899</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">OK</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7.06</td>
<td style="text-align: right;">37.79</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2072</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">OR</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4.70</td>
<td style="text-align: right;">25.58</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1121</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">PA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">27.86</td>
<td style="text-align: right;">184.81</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">8197</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">RI</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.90</td>
<td style="text-align: right;">14.53</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">682</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">SC</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7.53</td>
<td style="text-align: right;">43.33</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2326</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">SD</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.76</td>
<td style="text-align: right;">11.07</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">507</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">TN</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">11.02</td>
<td style="text-align: right;">62.75</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3296</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">TX</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">39.38</td>
<td style="text-align: right;">162.64</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">17</td>
<td style="text-align: right;">5064</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">UT</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4.24</td>
<td style="text-align: right;">20.74</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">707</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">VA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">11.75</td>
<td style="text-align: right;">63.90</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2688</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">VT</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.90</td>
<td style="text-align: right;">6.53</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">325</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">WA</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">8.35</td>
<td style="text-align: right;">42.95</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1750</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">WI</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10.33</td>
<td style="text-align: right;">64.66</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2403</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">WV</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4.85</td>
<td style="text-align: right;">34.06</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1796</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">WY</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.70</td>
<td style="text-align: right;">5.06</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">229</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Total</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">512.54</td>
<td style="text-align: right;">2657.86</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">139</td>
<td style="text-align: right;">99849</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">name</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">33400</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- ```{r}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using R
#| code-line-numbers: true
#| file: ../../../data_scripts/missing/flights_missing_json.R
``` -->
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using Python</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://www.ssa.gov/oact/babynames/limits.html</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Download and unzip to same folder as this script</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># AK,F,1911,Ruth,7</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># %%</span></span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> polars <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pl</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_connect</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv, find_dotenv</span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># from posit import connect</span></span>
<span id="cb1-9"></span>
<span id="cb1-10">load_dotenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"../../../.env"</span>)</span>
<span id="cb1-11">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb1-12">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb1-13"></span>
<span id="cb1-14"></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># %%</span></span>
<span id="cb1-16">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pl.read_csv(</span>
<span id="cb1-17">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'namesbystate/*.TXT'</span>,</span>
<span id="cb1-18">  has_header<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb1-19">  new_columns <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'state'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'gender'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-20">  .group_by(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'state'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-21">  .agg(pl.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>).alias(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-22">  .sort(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'state'</span>)</span>
<span id="cb1-23"></span>
<span id="cb1-24">dat_total <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dat.group_by(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>).agg(pl.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>).alias(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Total'</span>))</span>
<span id="cb1-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># %%</span></span>
<span id="cb1-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Now pivot</span></span>
<span id="cb1-27">out_dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dat.pivot(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'state'</span>, index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>], values<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-28">  .fill_null(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-29">  .join(dat_total, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-30">  .sort(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)</span>
<span id="cb1-31"></span>
<span id="cb1-32"></span>
<span id="cb1-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># %%</span></span>
<span id="cb1-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-35">pin_name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"names_year"</span></span>
<span id="cb1-36">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_connect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb1-37">board.pin_write(out_dat.to_pandas(), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> pin_name, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>)</span>
<span id="cb1-38"></span>
<span id="cb1-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># %%</span></span>
<span id="cb1-40">meta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_meta(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> pin_name)</span>
<span id="cb1-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://docs.posit.co/connect/user/python-pins/</span></span>
<span id="cb1-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://rstudio.github.io/pins-python/</span></span>
<span id="cb1-43">meta.local.get(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content_id"</span>)</span>
<span id="cb1-44"></span>
<span id="cb1-45"></span>
<span id="cb1-46"></span>
<span id="cb1-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#%% Need to set the vanity url</span></span>
<span id="cb1-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Do by hand https://posit.byui.edu/connect/#/apps/c0c197d3-f6bc-4129-9df4-4683c1f25e61/access</span></span>
<span id="cb1-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Soon there will be code.</span></span>
<span id="cb1-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://github.com/posit-dev/posit-sdk-py/issues/175</span></span>
<span id="cb1-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://posit-dev.github.io/posit-sdk-py/quickstart.html</span></span></code></pre></div>
</details>
</div>
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/0d43d66f-d3b7-4c43-8c36-52e3ed69e7f1/names_year_csv.csv">names_year_csv.csv</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/names_year_csv/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"names_year_csv"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/names_year_csv"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/names_year_csv"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="https://www.ssa.gov/oact/babynames/limits.html">https://www.ssa.gov/oact/babynames/limits.html</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>DS250</category>
  <category>names</category>
  <guid>https://byuidatascience.github.io/posts/intro_ds/census_names.html</guid>
  <pubDate>Wed, 15 Oct 2025 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Access to Drinking Water</title>
  <dc:creator>DS 350</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/access_drinking_water_stacked.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>5,622 rows</strong> and <strong>8 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/a15ec282-cf1a-4da9-bd0c-0e25172949a2/_rev422/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/access_drinking_water_stacked</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>entity:</strong> Country name</li>
<li><strong>code:</strong> 3-letter code for each country</li>
<li><strong>year:</strong> Year</li>
<li><strong>Share of the population using safely managed drinking water services:</strong> (Percent)</li>
<li><strong>Share of the population using only basic drinking water services:</strong> (Percent)</li>
<li><strong>Share of the population using limited drinking water services:</strong> (Percent)</li>
<li><strong>Share of the population using unimproved drinking water services:</strong> (Percent)</li>
<li><strong>Share of the population using surface water as a primary source of drinking water:</strong> (Percent)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 49%">
<col style="width: 6%">
<col style="width: 8%">
<col style="width: 4%">
<col style="width: 3%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 3%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">year</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">2010.99</td>
<td style="text-align: right;">6.56</td>
<td style="text-align: right;">2000.00</td>
<td style="text-align: right;">2005.00</td>
<td style="text-align: right;">2011.00</td>
<td style="text-align: right;">2017.00</td>
<td style="text-align: right;">2022.00</td>
<td style="text-align: left;">▇▆▇▆▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">Share of the population using safely managed drinking water services</td>
<td style="text-align: right;">1838</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: right;">68.67</td>
<td style="text-align: right;">30.19</td>
<td style="text-align: right;">1.43</td>
<td style="text-align: right;">45.53</td>
<td style="text-align: right;">77.85</td>
<td style="text-align: right;">96.43</td>
<td style="text-align: right;">100.00</td>
<td style="text-align: left;">▂▂▂▂▇</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Share of the population using only basic drinking water services</td>
<td style="text-align: right;">1838</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: right;">20.10</td>
<td style="text-align: right;">18.75</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">2.95</td>
<td style="text-align: right;">16.90</td>
<td style="text-align: right;">32.77</td>
<td style="text-align: right;">91.14</td>
<td style="text-align: left;">▇▃▃▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Share of the population using limited drinking water services</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">3.53</td>
<td style="text-align: right;">5.77</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.72</td>
<td style="text-align: right;">4.78</td>
<td style="text-align: right;">37.50</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Share of the population using unimproved drinking water services</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">6.61</td>
<td style="text-align: right;">9.12</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.44</td>
<td style="text-align: right;">2.55</td>
<td style="text-align: right;">9.14</td>
<td style="text-align: right;">54.74</td>
<td style="text-align: left;">▇▂▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Share of the population using surface water as a primary source of drinking water</td>
<td style="text-align: right;">94</td>
<td style="text-align: right;">0.98</td>
<td style="text-align: right;">3.32</td>
<td style="text-align: right;">6.15</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.22</td>
<td style="text-align: right;">3.77</td>
<td style="text-align: right;">49.42</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">entity</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">38</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">254</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">code</td>
<td style="text-align: right;">506</td>
<td style="text-align: right;">0.91</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">232</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1">pacman<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p_load</span>(tidyverse, pins, connectapi, owidR)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># owid() function downloads current data directly from Our World in Data.</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use owid_search() to search for other OWID datasets.</span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For more information, see the package documentation here: https://github.com/piersyork/owidR/blob/main/README.md</span></span>
<span id="cb1-6">access_drinking_water_stacked <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">owid</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'access-drinking-water-stacked'</span>)</span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, access_drinking_water_stacked, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"access_drinking_water_stacked"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/a15ec282-cf1a-4da9-bd0c-0e25172949a2/access_drinking_water_stacked.parquet">access_drinking_water_stacked.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/access_drinking_water_stacked/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"access_drinking_water_stacked"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/access_drinking_water_stacked"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/access_drinking_water_stacked"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="https://ourworldindata.org/grapher/access-drinking-water-stacked?country=OWID_WRL~Low+income~Upper-middle+income~High+income~Lower-middle+income~Sub-Saharan+Africa~Central+and+Southern+Asia~North+America+and+Europe~Latin+America+and+the+Caribbean~Western+Asia+and+Northern+Africa">https://ourworldindata.org/grapher/access-drinking-water-stacked?country=OWID_WRL<sub>Low+income</sub>Upper-middle+income<sub>High+income</sub>Lower-middle+income<sub>Sub-Saharan+Africa</sub>Central+and+Southern+Asia<sub>North+America+and+Europe</sub>Latin+America+and+the+Caribbean~Western+Asia+and+Northern+Africa</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>DS350</category>
  <category>world</category>
  <category>resources</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/access_drinking_water_stacked.html</guid>
  <pubDate>Wed, 08 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Climate Change: Antarctica</title>
  <dc:creator>DS 350</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/climate_change_antarctica.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>40 rows</strong> and <strong>5 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/d4a8e7a8-8011-44cc-b7ca-ab0d19b030b9/_rev435/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/climate_change_antarctica</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Entity:</strong> Country name</li>
<li><strong>Code:</strong> 3-letter code for each country</li>
<li><strong>Year:</strong> Year</li>
<li><strong>antarctic_sea_ice_september:</strong> Amount of sea ice in Antarctica in September (millions of square kilometers)</li>
<li><strong>antarctic_sea_ice_february:</strong> Amount of sea ice in Antarctica in February (millions of square kilometers)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 21%">
<col style="width: 7%">
<col style="width: 10%">
<col style="width: 8%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 9%">
<col style="width: 8%">
<col style="width: 9%">
<col style="width: 6%">
<col style="width: 4%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Year</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1998.5</td>
<td style="text-align: right;">11.69</td>
<td style="text-align: right;">1979</td>
<td style="text-align: right;">1988.75</td>
<td style="text-align: right;">1998.5</td>
<td style="text-align: right;">2008.25</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">▇▇▇▇▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">antarctic_sea_ice_september</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">18527513.5</td>
<td style="text-align: right;">436200.40</td>
<td style="text-align: right;">17680013</td>
<td style="text-align: right;">18185013.29</td>
<td style="text-align: right;">18565013.6</td>
<td style="text-align: right;">18805013.74</td>
<td style="text-align: right;">19760014</td>
<td style="text-align: left;">▂▇▇▂▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">antarctic_sea_ice_february</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3072252.2</td>
<td style="text-align: right;">424448.59</td>
<td style="text-align: right;">2290002</td>
<td style="text-align: right;">2840002.08</td>
<td style="text-align: right;">2985002.2</td>
<td style="text-align: right;">3212502.35</td>
<td style="text-align: right;">3890003</td>
<td style="text-align: left;">▂▅▇▁▃</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Entity</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">Code</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1">pacman<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p_load</span>(tidyverse, pins, connectapi, owidR, googledrive)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># owid() doesn't work for this dataset right now because the source site is down 5/8/2024</span></span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># owid() function downloads current data directly from Our World in Data.</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use owid_search() to search for other OWID datasets.</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For more information, see the package documentation here: https://github.com/piersyork/owidR/blob/main/README.md</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># climate_change_antarctica &lt;- owid('climate-change-antarctica')</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Until that issue is resolved, the data can be found in the google drive</span></span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Download the file from google drive</span></span>
<span id="cb1-13">sdrive <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shared_drive_find</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"byuids_data"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This will ask for authentication.</span></span>
<span id="cb1-14">google_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drive_ls</span>(sdrive) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(name, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"climate-change-antarctica"</span>))</span>
<span id="cb1-16">tempf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>()</span>
<span id="cb1-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drive_download</span>(google_file, tempf)</span>
<span id="cb1-18">climate_change_antarctica <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(tempf)</span>
<span id="cb1-19"></span>
<span id="cb1-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-21">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, climate_change_antarctica, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-23"></span>
<span id="cb1-24">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"climate_change_antarctica"</span></span>
<span id="cb1-25">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-26">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-27">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/d4a8e7a8-8011-44cc-b7ca-ab0d19b030b9/climate_change_antarctica.parquet">climate_change_antarctica.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/climate_change_antarctica/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"climate_change_antarctica"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/climate_change_antarctica"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/climate_change_antarctica"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="https://ourworldindata.org/explorers/climate-change?facet=none&amp;country=OWID_WRL~ATA&amp;Metric=Antarctic+sea+ice+extent&amp;Long-run+series%3F=false">https://ourworldindata.org/explorers/climate-change?facet=none&amp;country=OWID_WRL~ATA&amp;Metric=Antarctic+sea+ice+extent&amp;Long-run+series%3F=false</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>DS350</category>
  <category>world</category>
  <category>climate</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/climate_change_antarctica.html</guid>
  <pubDate>Wed, 08 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Climate Change: Ocean</title>
  <dc:creator>DS 350</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/climate_change_ocean.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>66 rows</strong> and <strong>7 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/7ca193f8-5c83-440b-89a2-11714a48facd/_rev436/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/climate_change_ocean</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Entity:</strong> Country name</li>
<li><strong>Code:</strong> 3-letter code for each country</li>
<li><strong>Year:</strong> Year</li>
<li><strong>700m_ocean_heat_content_iap:</strong> Ocean heat content found by the Chinese Academy of Sciences’ institute of Atmospheric Physics (IAP) in 10<sup>22</sup> joules</li>
<li><strong>700m_ocean_heat_content_noaa:</strong> Ocean heat content found by the U.S. National Oceanic and Atmospheric Administration (NOAA) in 10<sup>22</sup> joules</li>
<li><strong>700m_ocean_heat_content_csiro:</strong> Ocean heat content found by the Australia’s Commonwealth Scientific and Industrial Research Organisation (CSIRO) in 10<sup>22</sup> joules</li>
<li><strong>700m_ocean_heat_content_mrijma:</strong> Ocean heat content found by the Japan Meteorological Agency’s Meteorological Research Institute (MRI/JMA) in 10<sup>22</sup> joules</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 26%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 6%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Year</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">1987.50</td>
<td style="text-align: right;">19.20</td>
<td style="text-align: right;">1955.00</td>
<td style="text-align: right;">1971.25</td>
<td style="text-align: right;">1987.50</td>
<td style="text-align: right;">2003.75</td>
<td style="text-align: right;">2020.00</td>
<td style="text-align: left;">▇▇▇▇▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">700m_ocean_heat_content_iap</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">2.86</td>
<td style="text-align: right;">7.71</td>
<td style="text-align: right;">-7.57</td>
<td style="text-align: right;">-2.92</td>
<td style="text-align: right;">-0.28</td>
<td style="text-align: right;">9.67</td>
<td style="text-align: right;">20.01</td>
<td style="text-align: left;">▇▇▂▃▃</td>
</tr>
<tr class="odd">
<td style="text-align: left;">700m_ocean_heat_content_noaa</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">2.65</td>
<td style="text-align: right;">6.64</td>
<td style="text-align: right;">-5.96</td>
<td style="text-align: right;">-2.53</td>
<td style="text-align: right;">0.14</td>
<td style="text-align: right;">8.98</td>
<td style="text-align: right;">17.49</td>
<td style="text-align: left;">▇▆▂▃▂</td>
</tr>
<tr class="even">
<td style="text-align: left;">700m_ocean_heat_content_csiro</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">0.85</td>
<td style="text-align: right;">1.96</td>
<td style="text-align: right;">6.21</td>
<td style="text-align: right;">-7.52</td>
<td style="text-align: right;">-2.78</td>
<td style="text-align: right;">1.42</td>
<td style="text-align: right;">6.24</td>
<td style="text-align: right;">15.88</td>
<td style="text-align: left;">▇▇▇▃▃</td>
</tr>
<tr class="odd">
<td style="text-align: left;">700m_ocean_heat_content_mrijma</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">2.11</td>
<td style="text-align: right;">7.32</td>
<td style="text-align: right;">-9.50</td>
<td style="text-align: right;">-3.61</td>
<td style="text-align: right;">0.63</td>
<td style="text-align: right;">8.69</td>
<td style="text-align: right;">18.08</td>
<td style="text-align: left;">▆▇▃▃▃</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Entity</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">Code</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1">pacman<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p_load</span>(tidyverse, pins, connectapi, googledrive, owidR)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pwid() doesn't work for this dataset right now because the source site is down 5/8/2024</span></span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># # owid() function downloads current data directly from Our World in Data.</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># # Use owid_search() to search for other OWID datasets.</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># # For more information, see the package documentation here: https://github.com/piersyork/owidR/blob/main/README.md</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># climate_change_ocean &lt;- owid('climate-change-ocean')</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Until that issue is resolved, the data can be found in the google drive</span></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Download the file from google drive</span></span>
<span id="cb1-12">sdrive <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shared_drive_find</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"byuids_data"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This will ask for authentication.</span></span>
<span id="cb1-13">google_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drive_ls</span>(sdrive) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(name, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"climate-change-ocean"</span>))</span>
<span id="cb1-15">tempf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tempfile</span>()</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drive_download</span>(google_file, tempf)</span>
<span id="cb1-17">climate_change_ocean <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(tempf)</span>
<span id="cb1-18"></span>
<span id="cb1-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-20">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, climate_change_ocean, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-22"></span>
<span id="cb1-23">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"climate_change_ocean"</span></span>
<span id="cb1-24">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-25">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-26">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/7ca193f8-5c83-440b-89a2-11714a48facd/climate_change_ocean.parquet">climate_change_ocean.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/climate_change_ocean/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"climate_change_ocean"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/climate_change_ocean"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/climate_change_ocean"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="https://ourworldindata.org/explorers/climate-change?facet=none&amp;country=~OWID_WRL&amp;Metric=Ocean+heat+content+%28top+700m%29&amp;Long-run+series%3F=fals">https://ourworldindata.org/explorers/climate-change?facet=none&amp;country=~OWID_WRL&amp;Metric=Ocean+heat+content+%28top+700m%29&amp;Long-run+series%3F=fals</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>DS 350</category>
  <category>world</category>
  <category>climate</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/climate_change_ocean.html</guid>
  <pubDate>Wed, 08 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Biggest Loser</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/biggest_loser.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>277 rows</strong> and <strong>11 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/2f917961-32ce-473c-97e0-bf4ad6071c75/_rev425/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/biggest_loser</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>contestant_gender</strong> Gender of contestant (Female, Male)</li>
<li><strong>contestant_age_group</strong> Age group (&lt; 30, 30 to 39, 40 to 49, 50 to 59, 60 Plus)</li>
<li><strong>contestant_age</strong> Age (years)</li>
<li><strong>initial_weight_at_start_show</strong> Initial weight at start of show (lbs)</li>
<li><strong>weight_after_1_week</strong> Weight after one week (lbs)</li>
<li><strong>height</strong> Height (in)</li>
<li><strong>season</strong> Season of show (1 to 17)</li>
<li><strong>trainer</strong> Trainer first name</li>
<li><strong>prop_initial_weight_lost</strong> Unknown (appears to be a quantity of weight in lbs)</li>
<li><strong>prop_initial_weight_lost_week1</strong> Unknown (Presumes to be weight lost, but numbers are NOT the difference between the initial weight and weight after one week)</li>
<li><strong>winner</strong> Whether contestant won or lost (lost, won)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 28%">
<col style="width: 9%">
<col style="width: 12%">
<col style="width: 6%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">contestant_age</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">34.71</td>
<td style="text-align: right;">10.87</td>
<td style="text-align: right;">18.00</td>
<td style="text-align: right;">27.00</td>
<td style="text-align: right;">31.00</td>
<td style="text-align: right;">41.00</td>
<td style="text-align: right;">66.00</td>
<td style="text-align: left;">▆▇▃▂▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">initial_weight_at_start_show</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">311.29</td>
<td style="text-align: right;">71.04</td>
<td style="text-align: right;">167.00</td>
<td style="text-align: right;">252.00</td>
<td style="text-align: right;">297.00</td>
<td style="text-align: right;">365.00</td>
<td style="text-align: right;">526.00</td>
<td style="text-align: left;">▂▇▅▃▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">weight_after_1_week</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">294.46</td>
<td style="text-align: right;">66.85</td>
<td style="text-align: right;">164.00</td>
<td style="text-align: right;">239.00</td>
<td style="text-align: right;">285.00</td>
<td style="text-align: right;">344.00</td>
<td style="text-align: right;">492.00</td>
<td style="text-align: left;">▃▇▅▃▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">height</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">69.00</td>
<td style="text-align: right;">4.17</td>
<td style="text-align: right;">60.00</td>
<td style="text-align: right;">66.00</td>
<td style="text-align: right;">68.00</td>
<td style="text-align: right;">72.00</td>
<td style="text-align: right;">80.00</td>
<td style="text-align: left;">▂▇▅▃▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">season</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9.14</td>
<td style="text-align: right;">4.72</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">5.00</td>
<td style="text-align: right;">9.00</td>
<td style="text-align: right;">13.00</td>
<td style="text-align: right;">17.00</td>
<td style="text-align: left;">▇▇▆▆▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">prop_initial_weight_lost</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">36.16</td>
<td style="text-align: right;">9.68</td>
<td style="text-align: right;">7.37</td>
<td style="text-align: right;">29.29</td>
<td style="text-align: right;">36.18</td>
<td style="text-align: right;">43.94</td>
<td style="text-align: right;">59.62</td>
<td style="text-align: left;">▁▃▇▆▂</td>
</tr>
<tr class="odd">
<td style="text-align: left;">prop_initial_weight_lost_week1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5.37</td>
<td style="text-align: right;">1.72</td>
<td style="text-align: right;">0.92</td>
<td style="text-align: right;">4.20</td>
<td style="text-align: right;">5.24</td>
<td style="text-align: right;">6.46</td>
<td style="text-align: right;">10.44</td>
<td style="text-align: left;">▂▆▇▃▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 26%">
<col style="width: 12%">
<col style="width: 17%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 7%">
<col style="width: 11%">
<col style="width: 13%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">contestant_gender</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">contestant_age_group</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="odd">
<td style="text-align: left;">trainer</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">winner</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">biggest_loser <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/biggest_loser/biggest_loser.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, biggest_loser, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"biggest_loser"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/2f917961-32ce-473c-97e0-bf4ad6071c75/biggest_loser.parquet">biggest_loser.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/biggest_loser/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"biggest_loser"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/biggest_loser"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/biggest_loser"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Unknown">Unknown</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>entertainment</category>
  <category>questionablebeautystandards</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/biggest_loser.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Cardiac Arrest Health</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/cardiac_arrest_health.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>50 rows</strong> and <strong>1 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/5b0a1cd7-12e3-413b-8135-d09fb13fb247/_rev430/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/cardiac_arrest_health</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Health:</strong> SF-36 score (0-100). Lower scores on the SF-36 indicate a poorer quality of health.</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 18%">
<col style="width: 12%">
<col style="width: 18%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 3%">
<col style="width: 7%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 7%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Health</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">47.82</td>
<td style="text-align: right;">8.82</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">43.25</td>
<td style="text-align: right;">50</td>
<td style="text-align: right;">53</td>
<td style="text-align: right;">59</td>
<td style="text-align: left;">▁▁▂▆▇</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>NULL</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb2-4"></span>
<span id="cb2-5">cardiac_arrest_health <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/CardiacArrestHealth/CardiacArrestHealth.csv'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Health =</span> x) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Rename column to match documentation</span></span>
<span id="cb2-7"></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb2-10">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb2-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, cardiac_arrest_health, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb2-12"></span>
<span id="cb2-13">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cardiac_arrest_health"</span></span>
<span id="cb2-14">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb2-15">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb2-16">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb2-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/5b0a1cd7-12e3-413b-8135-d09fb13fb247/cardiac_arrest_health.parquet">cardiac_arrest_health.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb3-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/cardiac_arrest_health/"</span></span>
<span id="cb3-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb3-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb4-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb4-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb4-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb4-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb4-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb4-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb4-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb4-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb4-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb4-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cardiac_arrest_health"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb5-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb5-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/cardiac_arrest_health"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb6-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb6-4">load_dotenv()</span>
<span id="cb6-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb6-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb6-7"></span>
<span id="cb6-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb6-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/cardiac_arrest_health"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="T. Jared Bunch, Roger D. White, Bernard J. Gersh, Ryan A. Meverden, David O. Hodge, Karla V. Ballman, Stephen C. Hammill, Win-Kuang Shen, and Douglas L. Packer. Long-term outcomes of out-of-hospital cardiac arrest after successful early defibrillation. New England Journal of Medicine, 348:2626-2633, 2003. John E.Ware, Jr. and Cathy Donald Sherbourne. The MOS 36-item Short-Form Health Survey (SF-36): I. conceptual framework and item selection. Medical Care, 30(6):473-483, June 1992. Crispin Jenkinson, Sarah Stewart-Brown, Sophie Petersen, and Colin Paice. Assessment of the SF-36 version 2 in the United Kingdom. The Journal of Epidemiology and Community Health, 53:46-50, 1999.">T. Jared Bunch, Roger D. White, Bernard J. Gersh, Ryan A. Meverden, David O. Hodge, Karla V. Ballman, Stephen C. Hammill, Win-Kuang Shen, and Douglas L. Packer. Long-term outcomes of out-of-hospital cardiac arrest after successful early defibrillation. New England Journal of Medicine, 348:2626-2633, 2003. John E.Ware, Jr.&nbsp;and Cathy Donald Sherbourne. The MOS 36-item Short-Form Health Survey (SF-36): I. conceptual framework and item selection. Medical Care, 30(6):473-483, June 1992. Crispin Jenkinson, Sarah Stewart-Brown, Sophie Petersen, and Colin Paice. Assessment of the SF-36 version 2 in the United Kingdom. The Journal of Epidemiology and Community Health, 53:46-50, 1999.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>health</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/cardiac_arrest_health.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>2015 Census</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/census_2015.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>3,220 rows</strong> and <strong>37 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/b65fb63b-3422-428c-8817-3ac435f6cf32/_rev433/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/census_2015</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>censusid:</strong> Unique ID for each county</li>
<li><strong>state:</strong> State that county is in</li>
<li><strong>county:</strong> County name</li>
<li><strong>totalpop:</strong> Total population of county</li>
<li><strong>men:</strong> Total population of men</li>
<li><strong>women:</strong> Total population of women</li>
<li><strong>hispanic:</strong> Percent of population that is marked as Hispanic</li>
<li><strong>white:</strong> Percent of population that is marked as White</li>
<li><strong>black:</strong> Percent of population that is marked as Black</li>
<li><strong>native:</strong> Percent of population that is marked as Native</li>
<li><strong>asian:</strong> Percent of population that is marked as Asian</li>
<li><strong>pacific:</strong> Percent of population that is marked as Pacific</li>
<li><strong>citizen:</strong> Unknown, could refer to total population of citizens</li>
<li><strong>income:</strong> Unknown, appears to be a summary statistic of some kind involving income</li>
<li><strong>incomeerr:</strong> Unknown</li>
<li><strong>incomepercap:</strong> Unknown, appears to relate to income per capita</li>
<li><strong>incomepercaperr:</strong> Unknown</li>
<li><strong>poverty:</strong> Unknown, possibly a percent of people in poverty</li>
<li><strong>childpoverty:</strong> Unknown, possibly a percent of children in poverty</li>
<li><strong>professional:</strong> Percent of people working in the category “professional”</li>
<li><strong>service:</strong> Percent of people working in the category “service”</li>
<li><strong>office:</strong> Percent of people working in the category “office”</li>
<li><strong>construction:</strong> Percent of people working in the category “construction”</li>
<li><strong>production:</strong> Percent of people working in the category “production”</li>
<li><strong>drive:</strong> Percent of people who fit into the category “drive”</li>
<li><strong>carpool:</strong> Percent of people who fit into the category “carpool”</li>
<li><strong>transit:</strong> Percent of people who fit into the category “transit”</li>
<li><strong>walk:</strong> Percent of people who fit into the category “walk”</li>
<li><strong>othertransp:</strong> Percent of people who fit into the category “other transport”</li>
<li><strong>workathome:</strong> Percent of people who fit into the category “work at home”</li>
<li><strong>meancommute:</strong> Most likely the mean duration of commutes (min)</li>
<li><strong>employed:</strong> Total people employed</li>
<li><strong>privatework:</strong> Percent of people who fit into the category “private work”</li>
<li><strong>publicwork:</strong> Percent of people who fit into the category “public work”</li>
<li><strong>selfemployed:</strong> Percent of people who fit into the category “self employed”</li>
<li><strong>familywork:</strong> Percent of people who fit into the category “family work”</li>
<li><strong>unemployment:</strong> Unemployment percentage (not part of the percentages in the previous 4 columns)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 14%">
<col style="width: 9%">
<col style="width: 12%">
<col style="width: 8%">
<col style="width: 9%">
<col style="width: 7%">
<col style="width: 8%">
<col style="width: 8%">
<col style="width: 8%">
<col style="width: 9%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">censusid</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">31393.61</td>
<td style="text-align: right;">16292.08</td>
<td style="text-align: right;">1001.0</td>
<td style="text-align: right;">19032.50</td>
<td style="text-align: right;">30024.00</td>
<td style="text-align: right;">46105.50</td>
<td style="text-align: right;">72153.0</td>
<td style="text-align: left;">▅▇▆▆▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">totalpop</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">99409.35</td>
<td style="text-align: right;">319305.45</td>
<td style="text-align: right;">85.0</td>
<td style="text-align: right;">11218.00</td>
<td style="text-align: right;">26035.00</td>
<td style="text-align: right;">66430.50</td>
<td style="text-align: right;">10038388.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">men</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">48896.94</td>
<td style="text-align: right;">156681.28</td>
<td style="text-align: right;">42.0</td>
<td style="text-align: right;">5637.25</td>
<td style="text-align: right;">12932.00</td>
<td style="text-align: right;">32992.75</td>
<td style="text-align: right;">4945351.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">women</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">50512.41</td>
<td style="text-align: right;">162661.95</td>
<td style="text-align: right;">43.0</td>
<td style="text-align: right;">5572.00</td>
<td style="text-align: right;">13057.00</td>
<td style="text-align: right;">33487.50</td>
<td style="text-align: right;">5093037.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">hispanic</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">11.01</td>
<td style="text-align: right;">19.24</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">1.90</td>
<td style="text-align: right;">3.90</td>
<td style="text-align: right;">9.83</td>
<td style="text-align: right;">99.9</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">white</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">75.43</td>
<td style="text-align: right;">22.93</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">64.10</td>
<td style="text-align: right;">84.10</td>
<td style="text-align: right;">93.20</td>
<td style="text-align: right;">99.8</td>
<td style="text-align: left;">▁▁▂▃▇</td>
</tr>
<tr class="odd">
<td style="text-align: left;">black</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">8.67</td>
<td style="text-align: right;">14.28</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: right;">1.90</td>
<td style="text-align: right;">9.60</td>
<td style="text-align: right;">85.9</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">native</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.72</td>
<td style="text-align: right;">7.25</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.30</td>
<td style="text-align: right;">0.60</td>
<td style="text-align: right;">92.1</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">asian</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.23</td>
<td style="text-align: right;">2.63</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.20</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: right;">1.20</td>
<td style="text-align: right;">41.6</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">pacific</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">0.73</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">35.3</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">citizen</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">69935.07</td>
<td style="text-align: right;">205118.91</td>
<td style="text-align: right;">80.0</td>
<td style="text-align: right;">8450.50</td>
<td style="text-align: right;">19643.00</td>
<td style="text-align: right;">49920.50</td>
<td style="text-align: right;">6046749.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">income</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">46129.87</td>
<td style="text-align: right;">12911.30</td>
<td style="text-align: right;">10499.0</td>
<td style="text-align: right;">38191.50</td>
<td style="text-align: right;">44749.00</td>
<td style="text-align: right;">52074.00</td>
<td style="text-align: right;">123453.0</td>
<td style="text-align: left;">▁▇▂▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">incomeerr</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2850.40</td>
<td style="text-align: right;">1918.94</td>
<td style="text-align: right;">270.0</td>
<td style="text-align: right;">1635.00</td>
<td style="text-align: right;">2406.00</td>
<td style="text-align: right;">3446.00</td>
<td style="text-align: right;">21355.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">incomepercap</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">23981.77</td>
<td style="text-align: right;">6204.34</td>
<td style="text-align: right;">5878.0</td>
<td style="text-align: right;">20238.50</td>
<td style="text-align: right;">23460.00</td>
<td style="text-align: right;">27053.25</td>
<td style="text-align: right;">65600.0</td>
<td style="text-align: left;">▁▇▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">incomepercaperr</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1362.52</td>
<td style="text-align: right;">1049.88</td>
<td style="text-align: right;">113.0</td>
<td style="text-align: right;">755.00</td>
<td style="text-align: right;">1096.50</td>
<td style="text-align: right;">1631.00</td>
<td style="text-align: right;">15266.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">poverty</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">17.49</td>
<td style="text-align: right;">8.32</td>
<td style="text-align: right;">1.4</td>
<td style="text-align: right;">12.10</td>
<td style="text-align: right;">16.15</td>
<td style="text-align: right;">20.70</td>
<td style="text-align: right;">64.2</td>
<td style="text-align: left;">▆▇▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">childpoverty</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">24.18</td>
<td style="text-align: right;">11.70</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">16.30</td>
<td style="text-align: right;">22.70</td>
<td style="text-align: right;">30.00</td>
<td style="text-align: right;">81.6</td>
<td style="text-align: left;">▃▇▂▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">professional</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">30.99</td>
<td style="text-align: right;">6.37</td>
<td style="text-align: right;">13.5</td>
<td style="text-align: right;">26.70</td>
<td style="text-align: right;">29.90</td>
<td style="text-align: right;">34.40</td>
<td style="text-align: right;">74.0</td>
<td style="text-align: left;">▂▇▂▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">service</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">18.35</td>
<td style="text-align: right;">3.64</td>
<td style="text-align: right;">5.0</td>
<td style="text-align: right;">16.00</td>
<td style="text-align: right;">18.10</td>
<td style="text-align: right;">20.30</td>
<td style="text-align: right;">38.2</td>
<td style="text-align: left;">▁▇▇▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">office</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">22.22</td>
<td style="text-align: right;">3.20</td>
<td style="text-align: right;">4.1</td>
<td style="text-align: right;">20.20</td>
<td style="text-align: right;">22.40</td>
<td style="text-align: right;">24.40</td>
<td style="text-align: right;">35.4</td>
<td style="text-align: left;">▁▁▇▇▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">construction</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">12.71</td>
<td style="text-align: right;">4.22</td>
<td style="text-align: right;">1.7</td>
<td style="text-align: right;">9.80</td>
<td style="text-align: right;">12.10</td>
<td style="text-align: right;">14.90</td>
<td style="text-align: right;">40.3</td>
<td style="text-align: left;">▃▇▂▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">production</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">15.73</td>
<td style="text-align: right;">5.74</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">11.50</td>
<td style="text-align: right;">15.25</td>
<td style="text-align: right;">19.33</td>
<td style="text-align: right;">55.6</td>
<td style="text-align: left;">▃▇▂▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">drive</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">79.18</td>
<td style="text-align: right;">7.66</td>
<td style="text-align: right;">5.2</td>
<td style="text-align: right;">76.60</td>
<td style="text-align: right;">80.70</td>
<td style="text-align: right;">83.70</td>
<td style="text-align: right;">94.6</td>
<td style="text-align: left;">▁▁▁▂▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">carpool</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10.28</td>
<td style="text-align: right;">2.91</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">8.40</td>
<td style="text-align: right;">9.90</td>
<td style="text-align: right;">11.80</td>
<td style="text-align: right;">29.9</td>
<td style="text-align: left;">▁▇▂▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">transit</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.97</td>
<td style="text-align: right;">3.06</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.40</td>
<td style="text-align: right;">0.80</td>
<td style="text-align: right;">61.7</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">walk</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3.32</td>
<td style="text-align: right;">3.76</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">1.40</td>
<td style="text-align: right;">2.40</td>
<td style="text-align: right;">4.00</td>
<td style="text-align: right;">71.2</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">othertransp</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.61</td>
<td style="text-align: right;">1.67</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.90</td>
<td style="text-align: right;">1.30</td>
<td style="text-align: right;">1.90</td>
<td style="text-align: right;">39.1</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">workathome</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4.63</td>
<td style="text-align: right;">3.18</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">2.70</td>
<td style="text-align: right;">3.90</td>
<td style="text-align: right;">5.60</td>
<td style="text-align: right;">37.2</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">meancommute</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">23.28</td>
<td style="text-align: right;">5.60</td>
<td style="text-align: right;">4.9</td>
<td style="text-align: right;">19.50</td>
<td style="text-align: right;">23.00</td>
<td style="text-align: right;">26.80</td>
<td style="text-align: right;">44.0</td>
<td style="text-align: left;">▁▅▇▂▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">employed</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">45593.52</td>
<td style="text-align: right;">149699.50</td>
<td style="text-align: right;">62.0</td>
<td style="text-align: right;">4550.75</td>
<td style="text-align: right;">10508.00</td>
<td style="text-align: right;">28632.75</td>
<td style="text-align: right;">4635465.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">privatework</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">74.22</td>
<td style="text-align: right;">7.86</td>
<td style="text-align: right;">25.0</td>
<td style="text-align: right;">70.50</td>
<td style="text-align: right;">75.70</td>
<td style="text-align: right;">79.70</td>
<td style="text-align: right;">88.3</td>
<td style="text-align: left;">▁▁▁▆▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">publicwork</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">17.56</td>
<td style="text-align: right;">6.51</td>
<td style="text-align: right;">5.8</td>
<td style="text-align: right;">13.10</td>
<td style="text-align: right;">16.20</td>
<td style="text-align: right;">20.50</td>
<td style="text-align: right;">66.2</td>
<td style="text-align: left;">▇▅▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">selfemployed</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7.93</td>
<td style="text-align: right;">3.91</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">5.40</td>
<td style="text-align: right;">6.90</td>
<td style="text-align: right;">9.40</td>
<td style="text-align: right;">36.6</td>
<td style="text-align: left;">▇▆▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">familywork</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: right;">0.46</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.20</td>
<td style="text-align: right;">0.30</td>
<td style="text-align: right;">9.8</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unemployment</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">8.09</td>
<td style="text-align: right;">4.10</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">5.50</td>
<td style="text-align: right;">7.60</td>
<td style="text-align: right;">9.90</td>
<td style="text-align: right;">36.5</td>
<td style="text-align: left;">▇▇▁▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">state</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">52</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">county</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">33</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1928</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">census_2015 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/census2015/census2015.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, census_2015, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"census_2015"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/b65fb63b-3422-428c-8817-3ac435f6cf32/census_2015.parquet">census_2015.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/census_2015/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"census_2015"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/census_2015"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/census_2015"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Unknown">Unknown</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>population</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/census_2015.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>COPD Rehab</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/copd_rehab.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>85 rows</strong> and <strong>2 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/7e8f7a52-a7a7-4fd2-87e2-28203bbd02f9/_rev438/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/copd_rehab</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Community:</strong> Difference in ESWT score over course of study for participants in community-based rehab.</li>
<li><strong>Hospital:</strong> Difference in ESWT score over course of study for participants in hospital-based rehab. Note: Higher scores indicate improvement, and negative scores indicate deterioration.</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 16%">
<col style="width: 11%">
<col style="width: 16%">
<col style="width: 8%">
<col style="width: 8%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 8%">
<col style="width: 5%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Community</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">0.89</td>
<td style="text-align: right;">216.12</td>
<td style="text-align: right;">339.90</td>
<td style="text-align: right;">-402</td>
<td style="text-align: right;">-40.5</td>
<td style="text-align: right;">169.5</td>
<td style="text-align: right;">444.25</td>
<td style="text-align: right;">1000</td>
<td style="text-align: left;">▃▇▅▃▂</td>
</tr>
<tr class="even">
<td style="text-align: left;">Hospital</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">283.38</td>
<td style="text-align: right;">359.94</td>
<td style="text-align: right;">-540</td>
<td style="text-align: right;">-1.0</td>
<td style="text-align: right;">292.0</td>
<td style="text-align: right;">525.00</td>
<td style="text-align: right;">1031</td>
<td style="text-align: left;">▁▇▇▇▃</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>NULL</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb2-4"></span>
<span id="cb2-5">copd_rehab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/COPD-Rehab/COPD-Rehab.csv'</span>)</span>
<span id="cb2-6"></span>
<span id="cb2-7"></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb2-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb2-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, copd_rehab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb2-11"></span>
<span id="cb2-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"copd_rehab"</span></span>
<span id="cb2-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb2-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb2-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb2-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/7e8f7a52-a7a7-4fd2-87e2-28203bbd02f9/copd_rehab.parquet">copd_rehab.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb3-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/copd_rehab/"</span></span>
<span id="cb3-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb3-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb4-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb4-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb4-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb4-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb4-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb4-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb4-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb4-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb4-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb4-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"copd_rehab"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb5-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb5-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/copd_rehab"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb6-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb6-4">load_dotenv()</span>
<span id="cb6-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb6-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb6-7"></span>
<span id="cb6-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb6-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/copd_rehab"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="National Heart Lung and Blood Institute, National Institutes of Health, U.S. Department of Health &amp; Human Services. What is chronic obstructive pulmonary disease (COPD)? Website, March 2009. http://www.nhlbi.nih.gov/health/dci/Diseases/Copd/Copd_WhatIs.html. J. C. Waterhouse, S. J. Walters, Y. Oluboyede, and R. A. Lawson. A randomised 2x2 trial of community versus hospital pulmonary rehabilitation for chronic obstructive pulmonary disease followed by telephone or conventional follow-up. Health Technology Assessment, 14(6), 2010.">National Heart Lung and Blood Institute, National Institutes of Health, U.S. Department of Health &amp; Human Services. What is chronic obstructive pulmonary disease (COPD)? Website, March 2009. http://www.nhlbi.nih.gov/health/dci/Diseases/Copd/Copd_WhatIs.html. J. C. Waterhouse, S. J. Walters, Y. Oluboyede, and R. A. Lawson. A randomised 2x2 trial of community versus hospital pulmonary rehabilitation for chronic obstructive pulmonary disease followed by telephone or conventional follow-up. Health Technology Assessment, 14(6), 2010.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>health</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/copd_rehab.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Movies</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/movies.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>58,788 rows</strong> and <strong>24 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/c5a9669c-9bc3-40cb-a437-1196bdac1093/_rev480/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/movies</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>title</strong> Movie title</li>
<li><strong>year</strong> Release Year</li>
<li><strong>length</strong> Movie length (min)</li>
<li><strong>budget</strong> Budget (dollars)</li>
<li><strong>rating</strong> Rating</li>
<li><strong>votes</strong> Unkown</li>
<li><strong>r1</strong> Unkown</li>
<li><strong>r2</strong> Unkown</li>
<li><strong>r3</strong> Unkown</li>
<li><strong>r4</strong> Unkown</li>
<li><strong>r5</strong> Unkown</li>
<li><strong>r6</strong> Unkown</li>
<li><strong>r7</strong> Unkown</li>
<li><strong>r8</strong> Unkown</li>
<li><strong>r9</strong> Unkown</li>
<li><strong>r10</strong> Unkown</li>
<li><strong>mpaa</strong> Motion Picture Association of America rating (NC-17, PG, PG-13, R)</li>
<li><strong>Action</strong> Whether film pertains to action genre or not (0, 1)</li>
<li><strong>Animation</strong> Whether film pertains to animation genre or not (0, 1)</li>
<li><strong>Comedy</strong> Whether film pertains to comedy genre or not (0, 1)</li>
<li><strong>Drama</strong> Whether film pertains to drama genre or not (0, 1)</li>
<li><strong>Documentary</strong> Whether film pertains to documentary genre or not (0, 1)</li>
<li><strong>Romance</strong> Whether film pertains to romance genre or not (0, 1)</li>
<li><strong>Short</strong> Whether film pertains to short genre or not (0, 1)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 12%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 10%">
<col style="width: 10%">
<col style="width: 4%">
<col style="width: 7%">
<col style="width: 8%">
<col style="width: 8%">
<col style="width: 10%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">year</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">1976.13</td>
<td style="text-align: right;">23.74</td>
<td style="text-align: right;">1893</td>
<td style="text-align: right;">1958.0</td>
<td style="text-align: right;">1983.0</td>
<td style="text-align: right;">1.997e+03</td>
<td style="text-align: right;">2005.0</td>
<td style="text-align: left;">▁▁▃▃▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">length</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">82.34</td>
<td style="text-align: right;">44.35</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">74.0</td>
<td style="text-align: right;">90.0</td>
<td style="text-align: right;">1.000e+02</td>
<td style="text-align: right;">5220.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">budget</td>
<td style="text-align: right;">53573</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: right;">13412513.25</td>
<td style="text-align: right;">23350084.93</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">250000.0</td>
<td style="text-align: right;">3000000.0</td>
<td style="text-align: right;">1.500e+07</td>
<td style="text-align: right;">200000000.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">rating</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">5.93</td>
<td style="text-align: right;">1.55</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5.0</td>
<td style="text-align: right;">6.1</td>
<td style="text-align: right;">7.000e+00</td>
<td style="text-align: right;">10.0</td>
<td style="text-align: left;">▁▃▇▆▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">votes</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">632.13</td>
<td style="text-align: right;">3829.62</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">11.0</td>
<td style="text-align: right;">30.0</td>
<td style="text-align: right;">1.120e+02</td>
<td style="text-align: right;">157608.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">r1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">7.01</td>
<td style="text-align: right;">10.94</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">4.500e+00</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">r2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">4.02</td>
<td style="text-align: right;">5.96</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">4.500e+00</td>
<td style="text-align: right;">84.5</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">r3</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">4.72</td>
<td style="text-align: right;">6.45</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">4.500e+00</td>
<td style="text-align: right;">84.5</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">r4</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">6.37</td>
<td style="text-align: right;">7.59</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">4.500e+00</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">r5</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">9.80</td>
<td style="text-align: right;">9.73</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">1.450e+01</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">r6</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">13.04</td>
<td style="text-align: right;">10.98</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">1.450e+01</td>
<td style="text-align: right;">84.5</td>
<td style="text-align: left;">▇▂▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">r7</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">15.55</td>
<td style="text-align: right;">11.59</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">2.450e+01</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▃▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">r8</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">13.88</td>
<td style="text-align: right;">11.32</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">2.450e+01</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▃▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">r9</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">8.95</td>
<td style="text-align: right;">9.44</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">1.450e+01</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">r10</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">16.85</td>
<td style="text-align: right;">15.65</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4.5</td>
<td style="text-align: right;">14.5</td>
<td style="text-align: right;">2.450e+01</td>
<td style="text-align: right;">100.0</td>
<td style="text-align: left;">▇▃▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Action</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Animation</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: right;">0.24</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Comedy</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: right;">0.46</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">1.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▃</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Drama</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.37</td>
<td style="text-align: right;">0.48</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">1.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▅</td>
</tr>
<tr class="even">
<td style="text-align: left;">Documentary</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: right;">0.24</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Romance</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Short</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: right;">0.37</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">0.000e+00</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: left;">▇▁▁▁▂</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">title</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">121</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">56007</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">mpaa</td>
<td style="text-align: right;">53864</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">movies <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/movies/movies.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, movies, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"movies"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/c5a9669c-9bc3-40cb-a437-1196bdac1093/movies.parquet">movies.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/movies/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"movies"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/movies"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/movies"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="unknown">unknown</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>entertainment</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/movies.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Singer Heights</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/singer_heights.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>39 rows</strong> and <strong>4 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/a420dd88-30ba-4744-af9b-26cba9b37763/_rev491/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/singer_heights</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Soprano</strong> Singer height (inches)</li>
<li><strong>Alto</strong> Singer height (inches)</li>
<li><strong>Tenor</strong> Singer height (inches)</li>
<li><strong>Bass</strong> Singer height (inches)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 18%">
<col style="width: 13%">
<col style="width: 18%">
<col style="width: 8%">
<col style="width: 6%">
<col style="width: 4%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 8%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Soprano</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">64.72</td>
<td style="text-align: right;">2.46</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">65</td>
<td style="text-align: right;">66</td>
<td style="text-align: right;">72</td>
<td style="text-align: left;">▃▂▇▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Alto</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">Tenor</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">14</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Bass</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">singer_heights <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/SingerHeights/SingerHeights.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, singer_heights, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"singer_heights"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/a420dd88-30ba-4744-af9b-26cba9b37763/singer_heights.parquet">singer_heights.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/singer_heights/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"singer_heights"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/singer_heights"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/singer_heights"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Unknown">Unknown</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>music</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/singer_heights.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Soccer Shoes</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/soccer_shoes.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>120 rows</strong> and <strong>2 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/158736e8-af2e-43d7-b619-ba7587e095fe/_rev492/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/soccer_shoes</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Footwear:</strong> A unique ID for each footwear (A, B, C, D, E, Socks)</li>
<li><strong>Accuracy:</strong> Distance from the center of the target (centimeters)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 18%">
<col style="width: 13%">
<col style="width: 18%">
<col style="width: 8%">
<col style="width: 6%">
<col style="width: 4%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 8%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Accuracy</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">32.45</td>
<td style="text-align: right;">6.03</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">27</td>
<td style="text-align: right;">32</td>
<td style="text-align: right;">37</td>
<td style="text-align: right;">48</td>
<td style="text-align: left;">▂▇▆▅▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Footwear</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">soccer_shoes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/SoccerShoes/SoccerShoes.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, soccer_shoes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"soccer_shoes"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/158736e8-af2e-43d7-b619-ba7587e095fe/soccer_shoes.parquet">soccer_shoes.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/soccer_shoes/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"soccer_shoes"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/soccer_shoes"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/soccer_shoes"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Ewald M. Hennig, Katharina Althoff, and Ann-Kathrin Hoemme. Soccer footwear and ball kicking accuracy. Footwear Science, 1(S1):85-87, 2010. Ewald M. Hennig and Thorsten Sterzing. The influence of soccer shoe design on playing performance: a series of biomechanical studies. Footwear Science, 2(1):3-11, 2010.">Ewald M. Hennig, Katharina Althoff, and Ann-Kathrin Hoemme. Soccer footwear and ball kicking accuracy. Footwear Science, 1(S1):85-87, 2010. Ewald M. Hennig and Thorsten Sterzing. The influence of soccer shoe design on playing performance: a series of biomechanical studies. Footwear Science, 2(1):3-11, 2010.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>sports</category>
  <category>products</category>
  <category>advertising</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/soccer_shoes.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Soviet Accidents</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/soviet_accidents.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>8 rows</strong> and <strong>4 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/ed642b77-7bdb-497b-ac00-f01e52129874/_rev493/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/soviet_accidents</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Date:</strong> Date (MM/DD/YYYY)</li>
<li><strong>Location:</strong> Submarine involved in accident, Location of accident</li>
<li><strong>TypeofAccident:</strong> Type of accident</li>
<li><strong>Deaths:</strong> Count of deaths associated with each accident</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 18%">
<col style="width: 13%">
<col style="width: 18%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 4%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 8%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Deaths</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4.12</td>
<td style="text-align: right;">4.26</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">8.25</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">▇▅▁▂▅</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 20%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Date</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">Location</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">55</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="odd">
<td style="text-align: left;">TypeofAccident</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">50</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">soviet_accidents <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/SovietAccidents/SovietAccidents.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, soviet_accidents, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"soviet_accidents"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/ed642b77-7bdb-497b-ac00-f01e52129874/soviet_accidents.parquet">soviet_accidents.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/soviet_accidents/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"soviet_accidents"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/soviet_accidents"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/soviet_accidents"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="W. Robert Johnston. Naval reactor accidents causing radiation casualties. Website, accessed May 2010. http://www.johnstonsarchive.net/nuclear/radevents/radevents3.html">W. Robert Johnston. Naval reactor accidents causing radiation casualties. Website, accessed May 2010. http://www.johnstonsarchive.net/nuclear/radevents/radevents3.html</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>occupationalsafety</category>
  <category>military</category>
  <category>mechanicalengineering</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/soviet_accidents.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Speed of Light by Michelson 1879</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/speed_of_light_by_michelson_1879.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>100 rows</strong> and <strong>5 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/bb1b07ed-d150-45f5-9e1f-e8635c9bd076/_rev494/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/speed_of_light_by_michelson_1879</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>SpeedOfLight:</strong> Speed of light (millions of meters per second)</li>
<li><strong>Temp:</strong> Temperature (F)</li>
<li><strong>Day:</strong> Day of the month</li>
<li><strong>TimeOfDay:</strong> (AM/PM)</li>
<li><strong>Set:</strong> Identification number of dataset (1 to 24)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 15%">
<col style="width: 10%">
<col style="width: 15%">
<col style="width: 7%">
<col style="width: 5%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">SpeedOfLight</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">299.85</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">299.62</td>
<td style="text-align: right;">299.81</td>
<td style="text-align: right;">299.85</td>
<td style="text-align: right;">299.89</td>
<td style="text-align: right;">300.07</td>
<td style="text-align: left;">▁▃▇▃▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Temp</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">76.39</td>
<td style="text-align: right;">8.65</td>
<td style="text-align: right;">58.00</td>
<td style="text-align: right;">72.00</td>
<td style="text-align: right;">77.00</td>
<td style="text-align: right;">83.25</td>
<td style="text-align: right;">90.00</td>
<td style="text-align: left;">▅▁▇▆▆</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Day</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">14.86</td>
<td style="text-align: right;">6.99</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">9.00</td>
<td style="text-align: right;">15.00</td>
<td style="text-align: right;">19.25</td>
<td style="text-align: right;">28.00</td>
<td style="text-align: left;">▃▆▇▃▅</td>
</tr>
<tr class="even">
<td style="text-align: left;">Set</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">12.99</td>
<td style="text-align: right;">6.67</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">7.00</td>
<td style="text-align: right;">13.50</td>
<td style="text-align: right;">18.25</td>
<td style="text-align: right;">24.00</td>
<td style="text-align: left;">▅▇▅▇▆</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">TimeOfDay</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">speed_of_light_by_michelson_1879 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/SpeedOfLightByMichelson1879/SpeedOfLightByMichelson1879.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, speed_of_light_by_michelson_1879, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"speed_of_light_by_michelson_1879"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/bb1b07ed-d150-45f5-9e1f-e8635c9bd076/speed_of_light_by_michelson_1879.parquet">speed_of_light_by_michelson_1879.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/speed_of_light_by_michelson_1879/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"speed_of_light_by_michelson_1879"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/speed_of_light_by_michelson_1879"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/speed_of_light_by_michelson_1879"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Ernest N. Dorsey. The velocity of light. Transactions of the American Philosophical Society, 34(1):1-110, 1944. National Institute of Standards and Technology (NIST). Data gallery: Michelson speed of light. Website. http://www.itl.nist.gov/div898/bayesian/datagall/michelso.htm">Ernest N. Dorsey. The velocity of light. Transactions of the American Philosophical Society, 34(1):1-110, 1944. National Institute of Standards and Technology (NIST). Data gallery: Michelson speed of light. Website. http://www.itl.nist.gov/div898/bayesian/datagall/michelso.htm</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>science</category>
  <category>physics</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/speed_of_light_by_michelson_1879.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Speed of Light by Michelson 1882</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/speed_of_light_by_michelson_1882.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>23 rows</strong> and <strong>1 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/aef77eab-a1fa-41de-b113-4561a1d5cab9/_rev495/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/speed_of_light_by_michelson_1882</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>SpeedOfLight:</strong> Speed of light (millions of meters per second)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 15%">
<col style="width: 11%">
<col style="width: 15%">
<col style="width: 7%">
<col style="width: 5%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 7%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">SpeedOfLight</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">299.76</td>
<td style="text-align: right;">0.11</td>
<td style="text-align: right;">299.57</td>
<td style="text-align: right;">299.7</td>
<td style="text-align: right;">299.77</td>
<td style="text-align: right;">299.8</td>
<td style="text-align: right;">300.05</td>
<td style="text-align: left;">▃▅▇▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>NULL</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb2-4"></span>
<span id="cb2-5">speed_of_light_by_michelson_1882 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/SpeedOfLightByMichelson1882/SpeedOfLightByMichelson1882.csv'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SpeedOfLight =</span> x)</span>
<span id="cb2-7"></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb2-10">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb2-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, speed_of_light_by_michelson_1882, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb2-12"></span>
<span id="cb2-13">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"speed_of_light_by_michelson_1882"</span></span>
<span id="cb2-14">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb2-15">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb2-16">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb2-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/aef77eab-a1fa-41de-b113-4561a1d5cab9/speed_of_light_by_michelson_1882.parquet">speed_of_light_by_michelson_1882.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb3-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/speed_of_light_by_michelson_1882/"</span></span>
<span id="cb3-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb3-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb4-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb4-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb4-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb4-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb4-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb4-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb4-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb4-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb4-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb4-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"speed_of_light_by_michelson_1882"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb5-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb5-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/speed_of_light_by_michelson_1882"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb6-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb6-4">load_dotenv()</span>
<span id="cb6-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb6-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb6-7"></span>
<span id="cb6-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb6-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/speed_of_light_by_michelson_1882"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="S. M. Stigler. Do robust estimators work with real data? The Annals of Statistics, 5(6):1055-1098, November 1977. Cornell University DASL Project. The data and story library: Difference tests. Website. http://lib.stat.cmu.edu/DASL/Datafiles/differencetestdat.html">S. M. Stigler. Do robust estimators work with real data? The Annals of Statistics, 5(6):1055-1098, November 1977. Cornell University DASL Project. The data and story library: Difference tests. Website. http://lib.stat.cmu.edu/DASL/Datafiles/differencetestdat.html</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>MATH221</category>
  <category>science</category>
  <category>physics</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/speed_of_light_by_michelson_1882.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Superbowl Movies</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/super_bowl_movies.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>136 rows</strong> and <strong>4 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/f96a4bf6-2c4f-4dcc-8aa9-5f224cc53bb5/_rev457/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/super_bowl_movies</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Year:</strong> Release Year</li>
<li><strong>AdvertisedinSuperBowl:</strong> Whether movie was advertised in Superbowl or not (No, Yes)</li>
<li><strong>Title:</strong> Movie title</li>
<li><strong>GrossRevenueMillion:</strong> Gross Revenue (millions of dollars)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 20%">
<col style="width: 9%">
<col style="width: 13%">
<col style="width: 7%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Year</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2008.10</td>
<td style="text-align: right;">0.82</td>
<td style="text-align: right;">2007.0</td>
<td style="text-align: right;">2007.0</td>
<td style="text-align: right;">2008.0</td>
<td style="text-align: right;">2009.00</td>
<td style="text-align: right;">2009.0</td>
<td style="text-align: left;">▆▁▆▁▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">GrossRevenueMillion.</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">61.57</td>
<td style="text-align: right;">96.40</td>
<td style="text-align: right;">0.1</td>
<td style="text-align: right;">5.6</td>
<td style="text-align: right;">26.7</td>
<td style="text-align: right;">75.38</td>
<td style="text-align: right;">749.2</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 27%">
<col style="width: 12%">
<col style="width: 17%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 7%">
<col style="width: 11%">
<col style="width: 13%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">AdvertisedinSuperBowl</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">Title</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">54</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">136</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">super_bowl_movies <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/SuperBowlMovies/SuperBowlMovies.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, super_bowl_movies, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"super_bowl_movies"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/f96a4bf6-2c4f-4dcc-8aa9-5f224cc53bb5/super_bowl_movies.parquet">super_bowl_movies.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/super_bowl_movies/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"super_bowl_movies"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/super_bowl_movies"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/super_bowl_movies"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="WorldwideBoxOffice.com. Website. http://www.worldwideboxoffice.com/.">WorldwideBoxOffice.com. Website. http://www.worldwideboxoffice.com/.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>entertainment</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/super_bowl_movies.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Twins Diabetes</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/twins_diabetes.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>16 rows</strong> and <strong>5 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/91603d6b-12d1-4b1a-a391-d4469c48d038/_rev459/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/twins_diabetes</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Twin:</strong> ID for each pair of twins</li>
<li><strong>Age:</strong> Age at time of diagnosis (years)</li>
<li><strong>Gender:</strong> Gender of twins (M, F)</li>
<li><strong>NonDiabeticHeight:</strong> Height of non-diabetic twin (cm)</li>
<li><strong>DiabeticHeight:</strong> Height of diabetic twin (cm)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 10%">
<col style="width: 15%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 5%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 7%">
<col style="width: 6%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Twin</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">8.50</td>
<td style="text-align: right;">4.76</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: right;">4.75</td>
<td style="text-align: right;">8.50</td>
<td style="text-align: right;">12.25</td>
<td style="text-align: right;">16.0</td>
<td style="text-align: left;">▇▆▆▆▆</td>
</tr>
<tr class="even">
<td style="text-align: left;">Age</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">11.39</td>
<td style="text-align: right;">4.68</td>
<td style="text-align: right;">4.1</td>
<td style="text-align: right;">7.77</td>
<td style="text-align: right;">12.35</td>
<td style="text-align: right;">14.65</td>
<td style="text-align: right;">18.5</td>
<td style="text-align: left;">▆▂▆▇▃</td>
</tr>
<tr class="odd">
<td style="text-align: left;">NonDiabeticHeight</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">142.09</td>
<td style="text-align: right;">25.77</td>
<td style="text-align: right;">99.0</td>
<td style="text-align: right;">122.23</td>
<td style="text-align: right;">150.50</td>
<td style="text-align: right;">161.62</td>
<td style="text-align: right;">172.7</td>
<td style="text-align: left;">▅▁▂▃▇</td>
</tr>
<tr class="even">
<td style="text-align: left;">DiabeticHeight</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">140.37</td>
<td style="text-align: right;">25.40</td>
<td style="text-align: right;">99.0</td>
<td style="text-align: right;">119.23</td>
<td style="text-align: right;">148.60</td>
<td style="text-align: right;">160.00</td>
<td style="text-align: right;">171.5</td>
<td style="text-align: left;">▅▁▂▃▇</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Gender</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">twins_diabetes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/TwinsDiabetes/TwinsDiabetes.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, twins_diabetes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"twins_diabetes"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/91603d6b-12d1-4b1a-a391-d4469c48d038/twins_diabetes.parquet">twins_diabetes.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/twins_diabetes/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"twins_diabetes"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/twins_diabetes"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/twins_diabetes"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="P. J. Hoskins, R. D. Leslie, and D. A. Pyke. Height at diagnosis of diabetes in children: a study in identical twins. British Medical Journal, 290(6464):278-280, 1985.">P. J. Hoskins, R. D. Leslie, and D. A. Pyke. Height at diagnosis of diabetes in children: a study in identical twins. British Medical Journal, 290(6464):278-280, 1985.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>health</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/twins_diabetes.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Vertebral Heights</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/vertebral_heights.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>1,000 rows</strong> and <strong>1 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/1bf801d1-8156-4a7a-9e7b-49b00b96739a/_rev461/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/vertebral_heights</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>VertebralHeight:</strong> Height of the T4 vertebra of the subject (centimeters)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 12%">
<col style="width: 17%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 7%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">VertebralHeight</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2.16</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: right;">1.62</td>
<td style="text-align: right;">2.05</td>
<td style="text-align: right;">2.16</td>
<td style="text-align: right;">2.27</td>
<td style="text-align: right;">2.63</td>
<td style="text-align: left;">▁▃▇▅▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>NULL</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb2-4"></span>
<span id="cb2-5">vertebral_heights <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/VertebralHeights/VertebralHeights.csv'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">VertebralHeight =</span> x) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Rename column to match documentation</span></span>
<span id="cb2-7"></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb2-10">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb2-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, vertebral_heights, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb2-12"></span>
<span id="cb2-13">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertebral_heights"</span></span>
<span id="cb2-14">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb2-15">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb2-16">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb2-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/1bf801d1-8156-4a7a-9e7b-49b00b96739a/vertebral_heights.parquet">vertebral_heights.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb3-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/vertebral_heights/"</span></span>
<span id="cb3-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb3-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb4-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb4-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb4-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb4-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb4-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb4-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb4-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb4-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb4-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb4-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertebral_heights"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb5-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb5-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/vertebral_heights"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb6-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb6-4">load_dotenv()</span>
<span id="cb6-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb6-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb6-7"></span>
<span id="cb6-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb6-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/vertebral_heights"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Dennis M. Black, Steven R. Cummings, Katie Stone, Estie Hudes, Lisa Palermo, and Peter Steiger. A new approach to defining normal vertebral dimensions. Journal of Bone and Mineral Research, Volume 6, Number 8, 1991.">Dennis M. Black, Steven R. Cummings, Katie Stone, Estie Hudes, Lisa Palermo, and Peter Steiger. A new approach to defining normal vertebral dimensions. Journal of Bone and Mineral Research, Volume 6, Number 8, 1991.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>health</category>
  <category>anthropology</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/vertebral_heights.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>World Cup Heart Attacks</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/world_cup_heart_attacks.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>273 rows</strong> and <strong>3 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/704f9c12-2671-41ca-bfca-57e6f7014524/_rev462/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/world_cup_heart_attacks</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Date:</strong> Date (Monthname day, YYYY)</li>
<li><strong>HeartAttacks:</strong> Count of heart attacks</li>
<li><strong>TimePeriod:</strong> Time period group (Control, World Cup)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 18%">
<col style="width: 13%">
<col style="width: 18%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 4%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
<col style="width: 8%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">HeartAttacks</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">15.7</td>
<td style="text-align: right;">6.99</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">18</td>
<td style="text-align: right;">63</td>
<td style="text-align: left;">▇▆▁▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: character</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 19%">
<col style="width: 13%">
<col style="width: 19%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 8%">
<col style="width: 12%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">min</th>
<th style="text-align: right;">max</th>
<th style="text-align: right;">empty</th>
<th style="text-align: right;">n_unique</th>
<th style="text-align: right;">whitespace</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Date</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">11</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">273</td>
<td style="text-align: right;">0</td>
</tr>
<tr class="even">
<td style="text-align: left;">TimePeriod</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">0</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb1-4"></span>
<span id="cb1-5">world_cup_heart_attacks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/WorldCupHeartAttacks/WorldCupHeartAttacks.csv'</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb1-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, world_cup_heart_attacks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"world_cup_heart_attacks"</span></span>
<span id="cb1-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb1-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb1-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb1-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/704f9c12-2671-41ca-bfca-57e6f7014524/world_cup_heart_attacks.parquet">world_cup_heart_attacks.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/world_cup_heart_attacks/"</span></span>
<span id="cb2-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb2-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb3-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb3-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb3-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb3-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb3-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb3-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb3-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb3-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb3-15"></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb3-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"world_cup_heart_attacks"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb4-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb4-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/world_cup_heart_attacks"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb5-4">load_dotenv()</span>
<span id="cb5-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb5-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb5-7"></span>
<span id="cb5-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb5-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/world_cup_heart_attacks"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href=""></a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>sports</category>
  <category>health</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/world_cup_heart_attacks.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Wrong Site, Wrong Patient</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/wrong_site_wrong_patient.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>411 rows</strong> and <strong>2 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/02cbe178-e055-4123-8f8c-0acdfc8ad910/_rev463/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/wrong_site_wrong_patient</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Wrong.Site:</strong> Costs incurred by hospital from wrong site errors (dollars)</li>
<li><strong>Wrong.Patient:</strong> Costs incurred by hospital from wrong patient errors (dollars)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 14%">
<col style="width: 10%">
<col style="width: 14%">
<col style="width: 9%">
<col style="width: 10%">
<col style="width: 3%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 9%">
<col style="width: 8%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Wrong.Site</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">80041.24</td>
<td style="text-align: right;">71403.83</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">29496</td>
<td style="text-align: right;">68552</td>
<td style="text-align: right;">124280.0</td>
<td style="text-align: right;">780575</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Wrong.Patient</td>
<td style="text-align: right;">235</td>
<td style="text-align: right;">0.43</td>
<td style="text-align: right;">46172.05</td>
<td style="text-align: right;">105986.68</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">3900</td>
<td style="text-align: right;">18882</td>
<td style="text-align: right;">50145.5</td>
<td style="text-align: right;">1250000</td>
<td style="text-align: left;">▇▁▁▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>NULL</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb2-4"></span>
<span id="cb2-5">wrong_site_wrong_patient <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/WrongSiteWrongPatient/WrongSiteWrongPatient.csv'</span>)</span>
<span id="cb2-6"></span>
<span id="cb2-7"></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb2-9">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb2-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, wrong_site_wrong_patient, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb2-11"></span>
<span id="cb2-12">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wrong_site_wrong_patient"</span></span>
<span id="cb2-13">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb2-14">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb2-15">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb2-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/02cbe178-e055-4123-8f8c-0acdfc8ad910/wrong_site_wrong_patient.parquet">wrong_site_wrong_patient.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb3-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/wrong_site_wrong_patient/"</span></span>
<span id="cb3-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb3-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb4-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb4-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb4-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb4-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb4-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb4-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb4-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb4-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb4-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb4-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wrong_site_wrong_patient"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb5-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb5-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/wrong_site_wrong_patient"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb6-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb6-4">load_dotenv()</span>
<span id="cb6-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb6-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb6-7"></span>
<span id="cb6-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb6-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/wrong_site_wrong_patient"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Philip F. Stahel, Allison L. Sabel, Michael S. Victoroff, Jeffrey Varnell, Alan Lembitz, Dennis J. Boyle, Ted J. Clarke, Wade R. Smith, and Philip S. Mehler. Wrong-site and wrong-patient procedures in the universal protocol era: Analysis of a prospective database of physician self-reported occurrences. Arch Surg, 145(10):978-984, 2010.">Philip F. Stahel, Allison L. Sabel, Michael S. Victoroff, Jeffrey Varnell, Alan Lembitz, Dennis J. Boyle, Ted J. Clarke, Wade R. Smith, and Philip S. Mehler. Wrong-site and wrong-patient procedures in the universal protocol era: Analysis of a prospective database of physician self-reported occurrences. Arch Surg, 145(10):978-984, 2010.</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>health</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/wrong_site_wrong_patient.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
<item>
  <title>Zinc for Colds</title>
  <dc:creator>MATH 221</dc:creator>
  <link>https://byuidatascience.github.io/posts/intro_stats/zinc_for_colds.html</link>
  <description><![CDATA[ 





<section id="section" class="level1">
<h1></h1>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data details</h2>
<p>There are <strong>37 rows</strong> and <strong>2 columns</strong>. The data source<sup>1</sup> is used to create our data that is stored in our <a href="https://posit.byui.edu/content/eb803ffa-dfeb-4338-9411-b5f7f08b0f5f/_rev464/">pins table</a>. You can access this pin from a connection to <a href="https://posit.byui.edu">posit.byui.edu</a> using <code>hathawayj/zinc_for_colds</code>.</p>
<p>This data is available to <strong>all</strong>.</p>
<section id="variable-description" class="level3">
<h3 class="anchored" data-anchor-id="variable-description">Variable description</h3>
<ul>
<li><strong>Duration.of.Symptoms..Zinc.</strong> Days for which subject reported symptoms (zinc lozenge group)</li>
<li><strong>Duration.of.Symptoms..Placebo.</strong> Days for which subject reported symptoms (placebo lozenge group)</li>
</ul>
</section>
<section id="variable-summary" class="level3">
<h3 class="anchored" data-anchor-id="variable-summary">Variable summary</h3>
<div class="cell">
<div class="cell-output-display">
<p><strong>Variable type: numeric</strong></p>
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 32%">
<col style="width: 10%">
<col style="width: 14%">
<col style="width: 6%">
<col style="width: 6%">
<col style="width: 5%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">skim_variable</th>
<th style="text-align: right;">n_missing</th>
<th style="text-align: right;">complete_rate</th>
<th style="text-align: right;">mean</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">p0</th>
<th style="text-align: right;">p25</th>
<th style="text-align: right;">p50</th>
<th style="text-align: right;">p75</th>
<th style="text-align: right;">p100</th>
<th style="text-align: left;">hist</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Duration.of.Symptoms..Zinc.</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">4.26</td>
<td style="text-align: right;">3.47</td>
<td style="text-align: right;">0.25</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">4.0</td>
<td style="text-align: right;">6.0</td>
<td style="text-align: right;">16</td>
<td style="text-align: left;">▇▆▂▁▁</td>
</tr>
<tr class="even">
<td style="text-align: left;">Duration.of.Symptoms..Placebo.</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">0.76</td>
<td style="text-align: right;">12.82</td>
<td style="text-align: right;">10.45</td>
<td style="text-align: right;">2.00</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">9.5</td>
<td style="text-align: right;">17.5</td>
<td style="text-align: right;">40</td>
<td style="text-align: left;">▇▃▂▁▁</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>NULL</code></pre>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Explore generating code using R</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(connectapi)</span>
<span id="cb2-4"></span>
<span id="cb2-5">zinc_for_colds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://github.com/byuistats/data/raw/master/ZincForColds/ZincForColds.csv'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>Souce) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Delete description column</span></span>
<span id="cb2-7"></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Publish the data to the server with Bro. Hathaway as the owner.</span></span>
<span id="cb2-10">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>()</span>
<span id="cb2-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_write</span>(board, zinc_for_colds, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parquet"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">access_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb2-12"></span>
<span id="cb2-13">pin_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zinc_for_colds"</span></span>
<span id="cb2-14">meta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_meta</span>(board, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/"</span>, pin_name))</span>
<span id="cb2-15">client <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">connect</span>()</span>
<span id="cb2-16">my_app <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">content_item</span>(client, meta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>local<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content_id)</span>
<span id="cb2-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_vanity_url</span>(my_app, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/"</span>, pin_name))</span></code></pre></div>
</details>
</div>
<!-- ```{python}
#| echo: true
#| eval: false
#| code-fold: true
#| code-summary: Explore generating code using Python
#| code-line-numbers: true
#| file: ../../../data_scripts/YOURFILEPATH
``` -->
</section>
</section>
<section id="access-data" class="level2">
<h2 class="anchored" data-anchor-id="access-data">Access data</h2>
<p>This data is available to <strong>all</strong>.</p>
<p><strong>Direct Download:</strong> <a href="https://posit.byui.edu/content/eb803ffa-dfeb-4338-9411-b5f7f08b0f5f/zinc_for_colds.parquet">zinc_for_colds.parquet</a></p>
<section id="r-and-python-download" class="level4">
<h4 class="anchored" data-anchor-id="r-and-python-download"><strong>R and Python Download:</strong></h4>
<section id="url-connections" class="level5">
<h5 class="anchored" data-anchor-id="url-connections"><strong>URL Connections:</strong></h5>
<p>For public data, any user can connect and read the data using <code>pins::board_connect_url()</code> in R.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb3-2">url_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/zinc_for_colds/"</span></span>
<span id="cb3-3">board_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect_url</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> url_data))</span>
<span id="cb3-4">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board_url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dat"</span>)</span></code></pre></div>
<p>Use this custom function in Python to have the data in a Pandas DataFrame.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> requests</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> io <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BytesIO</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> read_url_pin(name):</span>
<span id="cb4-6">  url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://posit.byui.edu/data/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".parquet"</span></span>
<span id="cb4-7">  response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> requests.get(url)</span>
<span id="cb4-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> response.status_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>:</span>
<span id="cb4-9">    parquet_content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BytesIO(response.content)</span>
<span id="cb4-10">    pandas_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_parquet(parquet_content)</span>
<span id="cb4-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pandas_dataframe</span>
<span id="cb4-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb4-13">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Failed to retrieve data. Status code: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>response<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>status_code<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb4-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span></span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example usage:</span></span>
<span id="cb4-17">pandas_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> read_url_pin(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zinc_for_colds"</span>)</span></code></pre></div>
</section>
</section>
<section id="authenticated-connection" class="level4">
<h4 class="anchored" data-anchor-id="authenticated-connection"><strong>Authenticated Connection:</strong></h4>
<p>Our connect server is <a href="https://posit.byui.edu/connect/#/content/listing?filter=min_role:viewer&amp;filter=content_type:all&amp;view_type=compact">https://posit.byui.edu</a> which you assign to your <code>CONNECT_SERVER</code> environment variable. You must <a href="https://docs.posit.co/connect/user/api-keys/#api-keys-creating">create an API key</a> and store it in your environment under <code>CONNECT_API_KEY</code>.</p>
<p><em>Read more about <a href="../../environment.html">environment variables and the pins package</a> to understand how these environment variables are stored and accessed in R and Python with pins.</em></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pins)</span>
<span id="cb5-2">board <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">board_connect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>)</span>
<span id="cb5-3">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pin_read</span>(board, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/zinc_for_colds"</span>)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb6-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pins <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> board_rsconnect</span>
<span id="cb6-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> dotenv <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_dotenv</span>
<span id="cb6-4">load_dotenv()</span>
<span id="cb6-5">API_KEY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_API_KEY'</span>)</span>
<span id="cb6-6">SERVER <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> os.getenv(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CONNECT_SERVER'</span>)</span>
<span id="cb6-7"></span>
<span id="cb6-8">board <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board_rsconnect(server_url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SERVER, api_key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>API_KEY)</span>
<span id="cb6-9">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> board.pin_read(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hathawayj/zinc_for_colds"</span>)</span></code></pre></div>


</section>
</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><a href="Figure 1 in http://www.ncbi.nlm.nih.gov/pmc/articles/PMC185426/pdf/aac00190-0044.pdf">Figure 1 in http://www.ncbi.nlm.nih.gov/pmc/articles/PMC185426/pdf/aac00190-0044.pdf</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>health</category>
  <guid>https://byuidatascience.github.io/posts/intro_stats/zinc_for_colds.html</guid>
  <pubDate>Thu, 02 May 2024 06:00:00 GMT</pubDate>
</item>
</channel>
</rss>
