943 lines
No EOL
61 KiB
HTML
943 lines
No EOL
61 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
|
||
|
||
<meta charset="utf-8">
|
||
<meta name="generator" content="quarto-1.4.553">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
|
||
<meta name="author" content="Kyle Belanger">
|
||
<meta name="dcterms.date" content="2024-06-08">
|
||
<meta name="description" content="Inspired by TidyTuesday Week 2 - 2024 dataset about Candian Players, lets look at the same anaylyis for American Born Players">
|
||
|
||
<title>Kyle Belanger - Does a US Born Players Birthdate affect their shot at the NHL</title>
|
||
<style>
|
||
code{white-space: pre-wrap;}
|
||
span.smallcaps{font-variant: small-caps;}
|
||
div.columns{display: flex; gap: min(4vw, 1.5em);}
|
||
div.column{flex: auto; overflow-x: auto;}
|
||
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
||
ul.task-list{list-style: none;}
|
||
ul.task-list li input[type="checkbox"] {
|
||
width: 0.8em;
|
||
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
|
||
vertical-align: middle;
|
||
}
|
||
/* CSS for syntax highlighting */
|
||
pre > code.sourceCode { white-space: pre; position: relative; }
|
||
pre > code.sourceCode > span { line-height: 1.25; }
|
||
pre > code.sourceCode > span:empty { height: 1.2em; }
|
||
.sourceCode { overflow: visible; }
|
||
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
||
div.sourceCode { margin: 1em 0; }
|
||
pre.sourceCode { margin: 0; }
|
||
@media screen {
|
||
div.sourceCode { overflow: auto; }
|
||
}
|
||
@media print {
|
||
pre > code.sourceCode { white-space: pre-wrap; }
|
||
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
||
}
|
||
pre.numberSource code
|
||
{ counter-reset: source-line 0; }
|
||
pre.numberSource code > span
|
||
{ position: relative; left: -4em; counter-increment: source-line; }
|
||
pre.numberSource code > span > a:first-child::before
|
||
{ content: counter(source-line);
|
||
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
||
border: none; display: inline-block;
|
||
-webkit-touch-callout: none; -webkit-user-select: none;
|
||
-khtml-user-select: none; -moz-user-select: none;
|
||
-ms-user-select: none; user-select: none;
|
||
padding: 0 4px; width: 4em;
|
||
}
|
||
pre.numberSource { margin-left: 3em; padding-left: 4px; }
|
||
div.sourceCode
|
||
{ }
|
||
@media screen {
|
||
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
||
}
|
||
</style>
|
||
|
||
|
||
<script src="../../site_libs/quarto-nav/quarto-nav.js"></script>
|
||
<script src="../../site_libs/quarto-nav/headroom.min.js"></script>
|
||
<script src="../../site_libs/clipboard/clipboard.min.js"></script>
|
||
<script src="../../site_libs/quarto-search/autocomplete.umd.js"></script>
|
||
<script src="../../site_libs/quarto-search/fuse.min.js"></script>
|
||
<script src="../../site_libs/quarto-search/quarto-search.js"></script>
|
||
<meta name="quarto:offset" content="../../">
|
||
<script src="../../site_libs/quarto-html/quarto.js"></script>
|
||
<script src="../../site_libs/quarto-html/popper.min.js"></script>
|
||
<script src="../../site_libs/quarto-html/tippy.umd.min.js"></script>
|
||
<script src="../../site_libs/quarto-html/anchor.min.js"></script>
|
||
<link href="../../site_libs/quarto-html/tippy.css" rel="stylesheet">
|
||
<link href="../../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
|
||
<script src="../../site_libs/bootstrap/bootstrap.min.js"></script>
|
||
<link href="../../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
|
||
<link href="../../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
|
||
<script id="quarto-search-options" type="application/json">{
|
||
"location": "navbar",
|
||
"copy-button": false,
|
||
"collapse-after": 3,
|
||
"panel-placement": "end",
|
||
"type": "overlay",
|
||
"limit": 50,
|
||
"keyboard-shortcut": [
|
||
"f",
|
||
"/",
|
||
"s"
|
||
],
|
||
"show-item-context": false,
|
||
"language": {
|
||
"search-no-results-text": "No results",
|
||
"search-matching-documents-text": "matching documents",
|
||
"search-copy-link-title": "Copy link to search",
|
||
"search-hide-matches-text": "Hide additional matches",
|
||
"search-more-match-text": "more match in this document",
|
||
"search-more-matches-text": "more matches in this document",
|
||
"search-clear-button-title": "Clear",
|
||
"search-text-placeholder": "",
|
||
"search-detached-cancel-button-title": "Cancel",
|
||
"search-submit-button-title": "Submit",
|
||
"search-label": "Search"
|
||
}
|
||
}</script>
|
||
<script src="../../site_libs/kePrint-0.0.1/kePrint.js"></script>
|
||
|
||
<link href="../../site_libs/lightable-0.0.1/lightable.css" rel="stylesheet">
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="../../styles.css">
|
||
</head>
|
||
|
||
<body class="floating nav-fixed">
|
||
|
||
<div id="quarto-search-results"></div>
|
||
<header id="quarto-header" class="headroom fixed-top quarto-banner">
|
||
<nav class="navbar navbar-expand-lg " data-bs-theme="dark">
|
||
<div class="navbar-container container-fluid">
|
||
<div class="navbar-brand-container mx-auto">
|
||
<a class="navbar-brand" href="../../index.html">
|
||
<span class="navbar-title">Kyle Belanger</span>
|
||
</a>
|
||
</div>
|
||
<div id="quarto-search" class="" title="Search"></div>
|
||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
|
||
<span class="navbar-toggler-icon"></span>
|
||
</button>
|
||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||
<ul class="navbar-nav navbar-nav-scroll ms-auto">
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../../blog.html">
|
||
<span class="menu-text">Posts</span></a>
|
||
</li>
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../../kyle_resume.pdf">
|
||
<span class="menu-text">Resume</span></a>
|
||
</li>
|
||
<li class="nav-item compact">
|
||
<a class="nav-link" href="https://github.com/mmmmtoasty19"> <i class="bi bi-github" role="img">
|
||
</i>
|
||
<span class="menu-text"></span></a>
|
||
</li>
|
||
</ul>
|
||
</div> <!-- /navcollapse -->
|
||
<div class="quarto-navbar-tools">
|
||
</div>
|
||
</div> <!-- /container-fluid -->
|
||
</nav>
|
||
</header>
|
||
<!-- content -->
|
||
<header id="title-block-header" class="quarto-title-block default toc-left page-columns page-full">
|
||
<div class="quarto-title-banner page-columns page-full">
|
||
<div class="quarto-title column-body">
|
||
<h1 class="title">Does a US Born Players Birthdate affect their shot at the NHL</h1>
|
||
<div>
|
||
<div class="description">
|
||
Inspired by TidyTuesday Week 2 - 2024 dataset about Candian Players, lets look at the same anaylyis for American Born Players
|
||
</div>
|
||
</div>
|
||
<div class="quarto-categories">
|
||
<div class="quarto-category">tidytuesday</div>
|
||
<div class="quarto-category">R</div>
|
||
<div class="quarto-category">dataViz</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="quarto-title-meta">
|
||
|
||
<div>
|
||
<div class="quarto-title-meta-heading">Author</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p><a href="https://kyleb.rbind.io/">Kyle Belanger</a> </p>
|
||
</div>
|
||
</div>
|
||
|
||
<div>
|
||
<div class="quarto-title-meta-heading">Published</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p class="date">June 8, 2024</p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
</header><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
|
||
<!-- sidebar -->
|
||
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto">
|
||
<nav id="TOC" role="doc-toc" class="toc-active">
|
||
<h2 id="toc-title">Table of contents</h2>
|
||
|
||
<ul>
|
||
<li><a href="#distribution-of-births-by-month-in-the-united-states" id="toc-distribution-of-births-by-month-in-the-united-states" class="nav-link active" data-scroll-target="#distribution-of-births-by-month-in-the-united-states">Distribution of Births by Month in the United States</a>
|
||
<ul class="collapse">
|
||
<li><a href="#distribution-of-births-compared-to-expected" id="toc-distribution-of-births-compared-to-expected" class="nav-link" data-scroll-target="#distribution-of-births-compared-to-expected">Distribution of Births Compared to Expected</a></li>
|
||
</ul></li>
|
||
<li><a href="#hockey-data" id="toc-hockey-data" class="nav-link" data-scroll-target="#hockey-data">Hockey Data</a></li>
|
||
<li><a href="#graph-it" id="toc-graph-it" class="nav-link" data-scroll-target="#graph-it">Graph It</a></li>
|
||
<li><a href="#a-little-fun" id="toc-a-little-fun" class="nav-link" data-scroll-target="#a-little-fun">A Little Fun</a></li>
|
||
</ul>
|
||
</nav>
|
||
</nav>
|
||
<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
|
||
<!-- margin-sidebar -->
|
||
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
||
</div>
|
||
<!-- main -->
|
||
<main class="content quarto-banner-title-block" id="quarto-document-content">
|
||
|
||
|
||
|
||
|
||
|
||
<p>This post is inspired by this fantastic <a href="https://jlaw.netlify.app/2023/12/04/are-birth-dates-still-destiny-for-canadian-nhl-players/">blog post</a> on Jlaws Blog. In it they explore how in the first chapter Malcolm Gladwell’s Outliers he discusses how in Canadian Junior Hockey there is a higher likelihood for players to be born in the first quarter of the year. As it appears cutoff dates for USA hockey are different and they are currently using June 1st (if my internet searches are to be believed), I wondered if the same analysis would hold true for American Born Players.</p>
|
||
<section id="distribution-of-births-by-month-in-the-united-states" class="level2">
|
||
<h2 class="anchored" data-anchor-id="distribution-of-births-by-month-in-the-united-states">Distribution of Births by Month in the United States</h2>
|
||
<p>The data for US Birth Rates can be pulled from <a href="https://wonder.cdc.gov/">CDC Wonder</a>. The particular table of interest is the Natality, 2007 - 2022. CDC Wonder has a quite interesting API that requires a request with quite a few XML parameters. Thankfully you can build the request on the website and a nice package already exists to send the query. Check out the <a href="https://socdatar.github.io/wonderapi/index.html">Wonderapi Page</a> for more info.</p>
|
||
<div class="cell">
|
||
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>usa_raw <span class="ot"><-</span> wonderapi<span class="sc">::</span><span class="fu">send_query</span>(<span class="st">"D66"</span>, here<span class="sc">::</span><span class="fu">here</span>(<span class="st">"posts"</span>, <span class="st">"2024-05-15-US-NHL-Birthrate"</span>, <span class="st">"cdc_wonder_request.xml"</span>))</span>
|
||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>usa_births <span class="ot"><-</span> usa_raw <span class="sc">%>%</span></span>
|
||
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">group_by</span>(Month) <span class="sc">%>%</span></span>
|
||
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">summarise</span>(<span class="at">country_births =</span> <span class="fu">sum</span>(Births), <span class="at">.groups =</span> <span class="st">"drop"</span>) <span class="sc">%>%</span></span>
|
||
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">country_pct =</span> country_births <span class="sc">/</span> <span class="fu">sum</span>(country_births))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
</div>
|
||
<section id="distribution-of-births-compared-to-expected" class="level3">
|
||
<h3 class="anchored" data-anchor-id="distribution-of-births-compared-to-expected">Distribution of Births Compared to Expected</h3>
|
||
<p>The data from CDC Wonder pulls in quite nice, the only addition is adding a column for expected Births. This column gives each day of each month an equal chance for a person being born. Based on the data the summer months (June through August), and September have a slightly higher actual birth vs expected. Based on cut off Dates many of these kids would be the oldest in their age groups.</p>
|
||
<div class="cell">
|
||
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>usa_births <span class="sc">%>%</span></span>
|
||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">expected_births =</span> dplyr<span class="sc">::</span><span class="fu">case_when</span>(</span>
|
||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> Month <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"April"</span>, <span class="st">"June"</span>, <span class="st">"September"</span>, <span class="st">"November"</span>) <span class="sc">~</span> <span class="dv">30</span> <span class="sc">/</span> <span class="dv">365</span></span>
|
||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> , Month <span class="sc">==</span> <span class="st">"February"</span> <span class="sc">~</span> <span class="dv">28</span> <span class="sc">/</span> <span class="dv">365</span></span>
|
||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> , <span class="at">.default =</span> <span class="dv">31</span> <span class="sc">/</span> <span class="dv">365</span></span>
|
||
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> , <span class="at">difference =</span> country_pct <span class="sc">-</span> expected_births</span>
|
||
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> , dplyr<span class="sc">::</span><span class="fu">across</span>(Month, <span class="sc">~</span><span class="fu">factor</span>(., <span class="at">levels =</span> month.name))</span>
|
||
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> , dplyr<span class="sc">::</span><span class="fu">across</span>(<span class="fu">c</span>(country_pct, expected_births, difference), <span class="sc">~</span>scales<span class="sc">::</span><span class="fu">percent</span>(., <span class="at">accuracy =</span> .<span class="dv">1</span>))</span>
|
||
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%>%</span></span>
|
||
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">arrange</span>(Month) <span class="sc">%>%</span></span>
|
||
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">rename_with</span>(<span class="sc">~</span>stringr<span class="sc">::</span><span class="fu">str_replace_all</span>(., <span class="st">"_"</span>, <span class="st">" "</span>)) <span class="sc">%>%</span></span>
|
||
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">rename_with</span>(stringr<span class="sc">::</span>str_to_title) <span class="sc">%>%</span></span>
|
||
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> kableExtra<span class="sc">::</span><span class="fu">kbl</span>() <span class="sc">%>%</span></span>
|
||
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> kableExtra<span class="sc">::</span><span class="fu">kable_styling</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output-display">
|
||
<div>
|
||
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
|
||
<thead>
|
||
<tr class="header">
|
||
<th style="text-align: left;" data-quarto-table-cell-role="th">Month</th>
|
||
<th style="text-align: right;" data-quarto-table-cell-role="th">Country Births</th>
|
||
<th style="text-align: left;" data-quarto-table-cell-role="th">Country Pct</th>
|
||
<th style="text-align: left;" data-quarto-table-cell-role="th">Expected Births</th>
|
||
<th style="text-align: left;" data-quarto-table-cell-role="th">Difference</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td style="text-align: left;">January</td>
|
||
<td style="text-align: right;">5118343</td>
|
||
<td style="text-align: left;">8.2%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">-0.3%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td style="text-align: left;">February</td>
|
||
<td style="text-align: right;">4758741</td>
|
||
<td style="text-align: left;">7.6%</td>
|
||
<td style="text-align: left;">7.7%</td>
|
||
<td style="text-align: left;">-0.1%</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td style="text-align: left;">March</td>
|
||
<td style="text-align: right;">5205579</td>
|
||
<td style="text-align: left;">8.3%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">-0.2%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td style="text-align: left;">April</td>
|
||
<td style="text-align: right;">5001651</td>
|
||
<td style="text-align: left;">8.0%</td>
|
||
<td style="text-align: left;">8.2%</td>
|
||
<td style="text-align: left;">-0.3%</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td style="text-align: left;">May</td>
|
||
<td style="text-align: right;">5226642</td>
|
||
<td style="text-align: left;">8.3%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">-0.2%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td style="text-align: left;">June</td>
|
||
<td style="text-align: right;">5226141</td>
|
||
<td style="text-align: left;">8.3%</td>
|
||
<td style="text-align: left;">8.2%</td>
|
||
<td style="text-align: left;">0.1%</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td style="text-align: left;">July</td>
|
||
<td style="text-align: right;">5528731</td>
|
||
<td style="text-align: left;">8.8%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">0.3%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td style="text-align: left;">August</td>
|
||
<td style="text-align: right;">5635283</td>
|
||
<td style="text-align: left;">9.0%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">0.5%</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td style="text-align: left;">September</td>
|
||
<td style="text-align: right;">5448101</td>
|
||
<td style="text-align: left;">8.7%</td>
|
||
<td style="text-align: left;">8.2%</td>
|
||
<td style="text-align: left;">0.5%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td style="text-align: left;">October</td>
|
||
<td style="text-align: right;">5348495</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">0.0%</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td style="text-align: left;">November</td>
|
||
<td style="text-align: right;">5059952</td>
|
||
<td style="text-align: left;">8.1%</td>
|
||
<td style="text-align: left;">8.2%</td>
|
||
<td style="text-align: left;">-0.2%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td style="text-align: left;">December</td>
|
||
<td style="text-align: right;">5227828</td>
|
||
<td style="text-align: left;">8.3%</td>
|
||
<td style="text-align: left;">8.5%</td>
|
||
<td style="text-align: left;">-0.2%</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="hockey-data" class="level2">
|
||
<h2 class="anchored" data-anchor-id="hockey-data">Hockey Data</h2>
|
||
<p>While I wish I could sit and type out how I sat and figured out the complexity of the NHL Stats API and how to bring it into R. In reality I took a great guide, that being Jlaws post, and tweaked what I needed. Instead of Canadian players, I pulled out just the US Born players and their birth dates. I did also pull out positions to see if that will make any sort of difference. What pulls out of the NHL API has a ton of great details and I look forward to diving into what is available to see what kind of graphics can be built.</p>
|
||
<div class="cell">
|
||
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>teams <span class="ot"><-</span> httr<span class="sc">::</span><span class="fu">GET</span>(<span class="st">"https://api.nhle.com/stats/rest/en/team"</span>) <span class="sc">%>%</span></span>
|
||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> httr<span class="sc">::</span><span class="fu">content</span>() <span class="sc">%>%</span></span>
|
||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> .[[<span class="st">"data"</span>]] <span class="sc">%>%</span></span>
|
||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> tibble<span class="sc">::</span><span class="fu">tibble</span>(<span class="at">data =</span> .) <span class="sc">%>%</span></span>
|
||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">unnest_wider</span>(data)</span>
|
||
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>get_roster <span class="ot"><-</span> <span class="cf">function</span>(team){</span>
|
||
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> httr<span class="sc">::</span><span class="fu">GET</span>(glue<span class="sc">::</span><span class="fu">glue</span>(<span class="st">"https://api-web.nhle.com/v1/roster/{team}/20232024"</span>)) <span class="sc">%>%</span></span>
|
||
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> httr<span class="sc">::</span><span class="fu">content</span>() <span class="sc">%>%</span></span>
|
||
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> purrr<span class="sc">::</span><span class="fu">flatten</span>() <span class="sc">%>%</span></span>
|
||
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a> tibble<span class="sc">::</span><span class="fu">tibble</span>(<span class="at">data =</span> .) <span class="sc">%>%</span></span>
|
||
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a> tidyr<span class="sc">::</span><span class="fu">hoist</span>(</span>
|
||
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a> <span class="at">.col =</span> <span class="st">"data"</span></span>
|
||
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a> , <span class="st">"firstName"</span> <span class="ot">=</span> <span class="fu">list</span>(<span class="st">"firstName"</span>, <span class="dv">1</span>L)</span>
|
||
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> , <span class="st">"lastName"</span> <span class="ot">=</span> <span class="fu">list</span>(<span class="st">"lastName"</span>, <span class="dv">1</span>L)</span>
|
||
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a> , <span class="st">"positionCode"</span></span>
|
||
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a> , <span class="st">"birthDate"</span></span>
|
||
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a> , <span class="st">"birthCountry"</span></span>
|
||
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a>}</span>
|
||
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a>usa_roster <span class="ot"><-</span> purrr<span class="sc">::</span><span class="fu">map</span>(teams<span class="sc">$</span>triCode, get_roster) <span class="sc">%>%</span></span>
|
||
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a> purrr<span class="sc">::</span><span class="fu">list_rbind</span>() <span class="sc">%>%</span></span>
|
||
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(firstName)) <span class="sc">%>%</span></span>
|
||
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">filter</span>(birthCountry <span class="sc">==</span> <span class="st">"USA"</span>) <span class="sc">%>%</span></span>
|
||
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">mutate</span>(</span>
|
||
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a> <span class="at">mob =</span> lubridate<span class="sc">::</span><span class="fu">month</span>(lubridate<span class="sc">::</span><span class="fu">ymd</span>(birthDate), <span class="at">label =</span> <span class="cn">TRUE</span>, <span class="at">abbr =</span> <span class="cn">FALSE</span>)</span>
|
||
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a> , <span class="at">mob_id =</span> lubridate<span class="sc">::</span><span class="fu">month</span>(lubridate<span class="sc">::</span><span class="fu">ymd</span>(birthDate))</span>
|
||
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%>%</span></span>
|
||
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">count</span>(mob_id, mob, <span class="at">name =</span> <span class="st">"players"</span>) <span class="sc">%>%</span></span>
|
||
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">player_pct =</span> players <span class="sc">/</span> <span class="fu">sum</span>(players))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="graph-it" class="level2">
|
||
<h2 class="anchored" data-anchor-id="graph-it">Graph It</h2>
|
||
<p>Lets now take a look at the graph. Using the ggimage package we can place nice logos for both the United States and NHL on the graph. This stands out quite nicely versus just using a colored point. Interesting enough the graph seems to show being born early on in the year may mean making the NHL is more likely.</p>
|
||
<div class="cell">
|
||
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>nhl_icon <span class="ot"><-</span> <span class="st">"https://pbs.twimg.com/media/F9sTTAYakAAkRv6.png"</span></span>
|
||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>usa_icon <span class="ot"><-</span> <span class="st">"https://cdn-icons-png.flaticon.com/512/197/197484.png"</span></span>
|
||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>combined <span class="ot"><-</span> usa_roster <span class="sc">%>%</span></span>
|
||
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">left_join</span>(usa_births, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"mob"</span> <span class="ot">=</span> <span class="st">"Month"</span>)) <span class="sc">%>%</span></span>
|
||
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">mutate</span>(</span>
|
||
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="at">random =</span> dplyr<span class="sc">::</span><span class="fu">case_when</span>(</span>
|
||
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> mob_id <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">4</span>, <span class="dv">6</span>, <span class="dv">9</span>, <span class="dv">11</span>) <span class="sc">~</span> <span class="dv">30</span> <span class="sc">/</span> <span class="dv">365</span>,</span>
|
||
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> mob_id <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">3</span>, <span class="dv">5</span>, <span class="dv">7</span>, <span class="dv">8</span>, <span class="dv">10</span>, <span class="dv">12</span>) <span class="sc">~</span> <span class="dv">31</span> <span class="sc">/</span> <span class="dv">365</span>,</span>
|
||
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a> mob_id <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> <span class="dv">28</span> <span class="sc">/</span> <span class="dv">365</span></span>
|
||
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a><span class="co"># labels <- combined %>% glue::glue_data("{mob} <br> n = {players}")</span></span>
|
||
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a>g1 <span class="ot"><-</span> combined <span class="sc">%>%</span></span>
|
||
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> forcats<span class="sc">::</span><span class="fu">fct_reorder</span>(mob, <span class="sc">-</span>mob_id))) <span class="sc">+</span></span>
|
||
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>(<span class="fu">aes</span>(<span class="at">y =</span> random, <span class="at">group =</span> <span class="dv">1</span>), <span class="at">linetype =</span> <span class="dv">2</span>, <span class="at">color =</span> <span class="st">"grey60"</span>) <span class="sc">+</span></span>
|
||
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_linerange</span>(<span class="fu">aes</span>(<span class="at">ymin =</span> country_pct, <span class="at">ymax =</span> player_pct)) <span class="sc">+</span></span>
|
||
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_image</span>(<span class="fu">aes</span>(<span class="at">image =</span> nhl_icon, <span class="at">y =</span> player_pct), <span class="at">size =</span> <span class="fl">0.1</span>) <span class="sc">+</span></span>
|
||
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_image</span>(<span class="fu">aes</span>(<span class="at">image =</span> usa_icon, <span class="at">y =</span> country_pct), <span class="at">size =</span> <span class="fl">0.08</span>) <span class="sc">+</span></span>
|
||
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_text</span>(<span class="fu">aes</span>(<span class="at">label =</span> scales<span class="sc">::</span><span class="fu">percent</span>(player_pct, <span class="at">accuracy =</span> .<span class="dv">1</span>),</span>
|
||
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(player_pct <span class="sc">></span> country_pct, player_pct <span class="sc">+</span> .<span class="dv">006</span>, player_pct <span class="sc">-</span> .<span class="dv">006</span>)), <span class="at">size =</span> <span class="dv">5</span>) <span class="sc">+</span></span>
|
||
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_text</span>(<span class="fu">aes</span>(<span class="at">label =</span> scales<span class="sc">::</span><span class="fu">percent</span>(country_pct, <span class="at">accuracy =</span> .<span class="dv">1</span>),</span>
|
||
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(country_pct <span class="sc">></span> player_pct, country_pct <span class="sc">+</span> .<span class="dv">006</span>, country_pct <span class="sc">-</span> .<span class="dv">006</span>)), <span class="at">size =</span> <span class="dv">5</span>) <span class="sc">+</span></span>
|
||
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">labels =</span> scales<span class="sc">::</span>percent) <span class="sc">+</span></span>
|
||
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a> <span class="co"># scale_x_discrete(labels = labels) +</span></span>
|
||
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a> <span class="fu">coord_flip</span>() <span class="sc">+</span></span>
|
||
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(</span>
|
||
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Month of Birth"</span></span>
|
||
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true" tabindex="-1"></a> , <span class="at">y =</span> <span class="st">"Percentage of Births"</span></span>
|
||
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true" tabindex="-1"></a> , <span class="at">title =</span> <span class="st">"Are United States Born NHL Players More Likely to be Born Early in the Year?"</span></span>
|
||
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true" tabindex="-1"></a> , <span class="at">subtitle =</span> <span class="st">"Comparing the distribution of birth months between US NHL players and US in general"</span></span>
|
||
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true" tabindex="-1"></a> , <span class="at">caption =</span> glue<span class="sc">::</span><span class="fu">glue</span>(</span>
|
||
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true" tabindex="-1"></a> <span class="st">"<img src = {nhl_icon} width = '15' height=' 15' /> - US NHL Players Birth Month Distribution <br /></span></span>
|
||
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true" tabindex="-1"></a><span class="st"> <img src = {usa_icon} width = '15' height=' 15' /> - US Birth Month (2007-2022) Distribution"</span></span>
|
||
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">+</span></span>
|
||
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
|
||
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(</span>
|
||
<span id="cb4-41"><a href="#cb4-41" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.caption =</span> <span class="fu">element_markdown</span>()</span>
|
||
<span id="cb4-42"><a href="#cb4-42" aria-hidden="true" tabindex="-1"></a> , <span class="at">plot.title.position =</span> <span class="st">"plot"</span></span>
|
||
<span id="cb4-43"><a href="#cb4-43" aria-hidden="true" tabindex="-1"></a> , <span class="at">text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">16</span>)</span>
|
||
<span id="cb4-44"><a href="#cb4-44" aria-hidden="true" tabindex="-1"></a> , <span class="at">axis.text =</span> <span class="fu">element_markdown</span>()</span>
|
||
<span id="cb4-45"><a href="#cb4-45" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb4-46"><a href="#cb4-46" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb4-47"><a href="#cb4-47" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb4-48"><a href="#cb4-48" aria-hidden="true" tabindex="-1"></a>g1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output-display">
|
||
<div>
|
||
<figure class="figure">
|
||
<p><img src="index_files/figure-html/Graph_It-1.png" class="img-fluid figure-img" width="960"></p>
|
||
</figure>
|
||
</div>
|
||
</div>
|
||
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Stats ----</span></span>
|
||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>broom<span class="sc">::</span><span class="fu">tidy</span>(<span class="fu">chisq.test</span>(<span class="at">x =</span> combined<span class="sc">$</span>players, <span class="at">p =</span> combined<span class="sc">$</span>country_pct))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-stdout">
|
||
<pre><code># A tibble: 1 × 4
|
||
statistic p.value parameter method
|
||
<dbl> <dbl> <dbl> <chr>
|
||
1 14.8 0.190 11 Chi-squared test for given probabilities</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>If we look at this from a more stats based perspective, running a chi square test on the amount of players in the NHL per month, based on the US expected birth rate, we do see however there is quite a high p value. This is lets us know we can not reject the Null hypothesis that these are the same thing.</p>
|
||
</section>
|
||
<section id="a-little-fun" class="level1">
|
||
<h1>A Little Fun</h1>
|
||
<p>For just a little bit of fun I pulled birth data for the entire world using the UN’s website. I then filtered this out to just countries that currently have players in the NHL. The graph shows more of the same, looks to lean heavily to the beginning of the year, and this time the stat back it up. So being born early in the year may in fact help your chances of making it to the NHL</p>
|
||
<div class="cell">
|
||
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>g2 <span class="ot"><-</span> combined_world <span class="sc">%>%</span></span>
|
||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> forcats<span class="sc">::</span><span class="fu">fct_reorder</span>(mob, <span class="sc">-</span>mob_id))) <span class="sc">+</span></span>
|
||
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>(<span class="fu">aes</span>(<span class="at">y =</span> random, <span class="at">group =</span> <span class="dv">1</span>), <span class="at">linetype =</span> <span class="dv">2</span>, <span class="at">color =</span> <span class="st">"grey60"</span>) <span class="sc">+</span></span>
|
||
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_linerange</span>(<span class="fu">aes</span>(<span class="at">ymin =</span> world_pct, <span class="at">ymax =</span> player_pct)) <span class="sc">+</span></span>
|
||
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_image</span>(<span class="fu">aes</span>(<span class="at">image =</span> world_icon, <span class="at">y =</span> world_pct), <span class="at">size =</span> <span class="fl">0.08</span>) <span class="sc">+</span></span>
|
||
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_image</span>(<span class="fu">aes</span>(<span class="at">image =</span> nhl_icon, <span class="at">y =</span> player_pct), <span class="at">size =</span> <span class="fl">0.1</span>) <span class="sc">+</span></span>
|
||
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_text</span>(<span class="fu">aes</span>(<span class="at">label =</span> scales<span class="sc">::</span><span class="fu">percent</span>(player_pct, <span class="at">accuracy =</span> .<span class="dv">1</span>),</span>
|
||
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(player_pct <span class="sc">></span> world_pct, player_pct <span class="sc">+</span> .<span class="dv">006</span>, player_pct <span class="sc">-</span> .<span class="dv">006</span>)), <span class="at">size =</span> <span class="dv">5</span>) <span class="sc">+</span></span>
|
||
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_text</span>(<span class="fu">aes</span>(<span class="at">label =</span> scales<span class="sc">::</span><span class="fu">percent</span>(world_pct, <span class="at">accuracy =</span> .<span class="dv">1</span>),</span>
|
||
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> dplyr<span class="sc">::</span><span class="fu">if_else</span>(world_pct <span class="sc">></span> player_pct, world_pct <span class="sc">+</span> .<span class="dv">006</span>, world_pct <span class="sc">-</span> .<span class="dv">006</span>)), <span class="at">size =</span> <span class="dv">5</span>) <span class="sc">+</span></span>
|
||
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">labels =</span> scales<span class="sc">::</span>percent) <span class="sc">+</span></span>
|
||
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">coord_flip</span>() <span class="sc">+</span></span>
|
||
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(</span>
|
||
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Month of Birth"</span></span>
|
||
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a> , <span class="at">y =</span> <span class="st">"Percentage of Births"</span></span>
|
||
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a> , <span class="at">title =</span> <span class="st">"What Birthday is most liekly to make the NHL?"</span></span>
|
||
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a> , <span class="at">subtitle =</span> <span class="st">"Comparing the distribution of birth months between All NHL players and the World in general"</span></span>
|
||
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a> , <span class="at">caption =</span> glue<span class="sc">::</span><span class="fu">glue</span>(</span>
|
||
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a> <span class="st">"<img src = {nhl_icon} width = '15' height=' 15' /> - US NHL Players Birth Month Distribution <br /></span></span>
|
||
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a><span class="st"> <img src = {world_icon} width = '15' height=' 15' /> - World Birth Month (2007-2022) Distribution"</span></span>
|
||
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">+</span></span>
|
||
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
|
||
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(</span>
|
||
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.caption =</span> <span class="fu">element_markdown</span>()</span>
|
||
<span id="cb7-26"><a href="#cb7-26" aria-hidden="true" tabindex="-1"></a> , <span class="at">plot.title.position =</span> <span class="st">"plot"</span></span>
|
||
<span id="cb7-27"><a href="#cb7-27" aria-hidden="true" tabindex="-1"></a> , <span class="at">text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">16</span>)</span>
|
||
<span id="cb7-28"><a href="#cb7-28" aria-hidden="true" tabindex="-1"></a> , <span class="at">axis.text =</span> <span class="fu">element_markdown</span>()</span>
|
||
<span id="cb7-29"><a href="#cb7-29" aria-hidden="true" tabindex="-1"></a> )</span>
|
||
<span id="cb7-30"><a href="#cb7-30" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb7-31"><a href="#cb7-31" aria-hidden="true" tabindex="-1"></a>g2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output-display">
|
||
<div>
|
||
<figure class="figure">
|
||
<p><img src="index_files/figure-html/world_graph-1.png" class="img-fluid figure-img" width="960"></p>
|
||
</figure>
|
||
</div>
|
||
</div>
|
||
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>broom<span class="sc">::</span><span class="fu">tidy</span>(<span class="fu">chisq.test</span>(<span class="at">x =</span> combined_world<span class="sc">$</span>players, <span class="at">p =</span> combined_world<span class="sc">$</span>world_pct))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-stdout">
|
||
<pre><code># A tibble: 1 × 4
|
||
statistic p.value parameter method
|
||
<dbl> <dbl> <dbl> <chr>
|
||
1 43.1 0.0000104 11 Chi-squared test for given probabilities</code></pre>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</section>
|
||
|
||
<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{belanger2024,
|
||
author = {Belanger, Kyle},
|
||
title = {Does a {US} {Born} {Players} {Birthdate} Affect Their Shot at
|
||
the {NHL}},
|
||
date = {2024-06-08},
|
||
langid = {en}
|
||
}
|
||
</code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-belanger2024" class="csl-entry quarto-appendix-citeas" role="listitem">
|
||
Belanger, Kyle. 2024. <span>“Does a US Born Players Birthdate Affect
|
||
Their Shot at the NHL.”</span> June 8, 2024.
|
||
</div></div></section></div></main> <!-- /main -->
|
||
<script id="quarto-html-after-body" type="application/javascript">
|
||
window.document.addEventListener("DOMContentLoaded", function (event) {
|
||
const toggleBodyColorMode = (bsSheetEl) => {
|
||
const mode = bsSheetEl.getAttribute("data-mode");
|
||
const bodyEl = window.document.querySelector("body");
|
||
if (mode === "dark") {
|
||
bodyEl.classList.add("quarto-dark");
|
||
bodyEl.classList.remove("quarto-light");
|
||
} else {
|
||
bodyEl.classList.add("quarto-light");
|
||
bodyEl.classList.remove("quarto-dark");
|
||
}
|
||
}
|
||
const toggleBodyColorPrimary = () => {
|
||
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
||
if (bsSheetEl) {
|
||
toggleBodyColorMode(bsSheetEl);
|
||
}
|
||
}
|
||
toggleBodyColorPrimary();
|
||
const icon = "";
|
||
const anchorJS = new window.AnchorJS();
|
||
anchorJS.options = {
|
||
placement: 'right',
|
||
icon: icon
|
||
};
|
||
anchorJS.add('.anchored');
|
||
const isCodeAnnotation = (el) => {
|
||
for (const clz of el.classList) {
|
||
if (clz.startsWith('code-annotation-')) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
||
text: function(trigger) {
|
||
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
||
for (const childEl of codeEl.children) {
|
||
if (isCodeAnnotation(childEl)) {
|
||
childEl.remove();
|
||
}
|
||
}
|
||
return codeEl.innerText;
|
||
}
|
||
});
|
||
clipboard.on('success', function(e) {
|
||
// button target
|
||
const button = e.trigger;
|
||
// don't keep focus
|
||
button.blur();
|
||
// flash "checked"
|
||
button.classList.add('code-copy-button-checked');
|
||
var currentTitle = button.getAttribute("title");
|
||
button.setAttribute("title", "Copied!");
|
||
let tooltip;
|
||
if (window.bootstrap) {
|
||
button.setAttribute("data-bs-toggle", "tooltip");
|
||
button.setAttribute("data-bs-placement", "left");
|
||
button.setAttribute("data-bs-title", "Copied!");
|
||
tooltip = new bootstrap.Tooltip(button,
|
||
{ trigger: "manual",
|
||
customClass: "code-copy-button-tooltip",
|
||
offset: [0, -8]});
|
||
tooltip.show();
|
||
}
|
||
setTimeout(function() {
|
||
if (tooltip) {
|
||
tooltip.hide();
|
||
button.removeAttribute("data-bs-title");
|
||
button.removeAttribute("data-bs-toggle");
|
||
button.removeAttribute("data-bs-placement");
|
||
}
|
||
button.setAttribute("title", currentTitle);
|
||
button.classList.remove('code-copy-button-checked');
|
||
}, 1000);
|
||
// clear code selection
|
||
e.clearSelection();
|
||
});
|
||
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
|
||
var mailtoRegex = new RegExp(/^mailto:/);
|
||
var filterRegex = new RegExp('/' + window.location.host + '/');
|
||
var isInternal = (href) => {
|
||
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
|
||
}
|
||
// Inspect non-navigation links and adorn them if external
|
||
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool)');
|
||
for (var i=0; i<links.length; i++) {
|
||
const link = links[i];
|
||
if (!isInternal(link.href)) {
|
||
// undo the damage that might have been done by quarto-nav.js in the case of
|
||
// links that we want to consider external
|
||
if (link.dataset.originalHref !== undefined) {
|
||
link.href = link.dataset.originalHref;
|
||
}
|
||
}
|
||
}
|
||
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
|
||
const config = {
|
||
allowHTML: true,
|
||
maxWidth: 500,
|
||
delay: 100,
|
||
arrow: false,
|
||
appendTo: function(el) {
|
||
return el.parentElement;
|
||
},
|
||
interactive: true,
|
||
interactiveBorder: 10,
|
||
theme: 'quarto',
|
||
placement: 'bottom-start',
|
||
};
|
||
if (contentFn) {
|
||
config.content = contentFn;
|
||
}
|
||
if (onTriggerFn) {
|
||
config.onTrigger = onTriggerFn;
|
||
}
|
||
if (onUntriggerFn) {
|
||
config.onUntrigger = onUntriggerFn;
|
||
}
|
||
window.tippy(el, config);
|
||
}
|
||
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
||
for (var i=0; i<noterefs.length; i++) {
|
||
const ref = noterefs[i];
|
||
tippyHover(ref, function() {
|
||
// use id or data attribute instead here
|
||
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
||
try { href = new URL(href).hash; } catch {}
|
||
const id = href.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
if (note) {
|
||
return note.innerHTML;
|
||
} else {
|
||
return "";
|
||
}
|
||
});
|
||
}
|
||
const xrefs = window.document.querySelectorAll('a.quarto-xref');
|
||
const processXRef = (id, note) => {
|
||
// Strip column container classes
|
||
const stripColumnClz = (el) => {
|
||
el.classList.remove("page-full", "page-columns");
|
||
if (el.children) {
|
||
for (const child of el.children) {
|
||
stripColumnClz(child);
|
||
}
|
||
}
|
||
}
|
||
stripColumnClz(note)
|
||
if (id === null || id.startsWith('sec-')) {
|
||
// Special case sections, only their first couple elements
|
||
const container = document.createElement("div");
|
||
if (note.children && note.children.length > 2) {
|
||
container.appendChild(note.children[0].cloneNode(true));
|
||
for (let i = 1; i < note.children.length; i++) {
|
||
const child = note.children[i];
|
||
if (child.tagName === "P" && child.innerText === "") {
|
||
continue;
|
||
} else {
|
||
container.appendChild(child.cloneNode(true));
|
||
break;
|
||
}
|
||
}
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(container);
|
||
}
|
||
return container.innerHTML
|
||
} else {
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(note);
|
||
}
|
||
return note.innerHTML;
|
||
}
|
||
} else {
|
||
// Remove any anchor links if they are present
|
||
const anchorLink = note.querySelector('a.anchorjs-link');
|
||
if (anchorLink) {
|
||
anchorLink.remove();
|
||
}
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(note);
|
||
}
|
||
// TODO in 1.5, we should make sure this works without a callout special case
|
||
if (note.classList.contains("callout")) {
|
||
return note.outerHTML;
|
||
} else {
|
||
return note.innerHTML;
|
||
}
|
||
}
|
||
}
|
||
for (var i=0; i<xrefs.length; i++) {
|
||
const xref = xrefs[i];
|
||
tippyHover(xref, undefined, function(instance) {
|
||
instance.disable();
|
||
let url = xref.getAttribute('href');
|
||
let hash = undefined;
|
||
if (url.startsWith('#')) {
|
||
hash = url;
|
||
} else {
|
||
try { hash = new URL(url).hash; } catch {}
|
||
}
|
||
if (hash) {
|
||
const id = hash.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
if (note !== null) {
|
||
try {
|
||
const html = processXRef(id, note.cloneNode(true));
|
||
instance.setContent(html);
|
||
} finally {
|
||
instance.enable();
|
||
instance.show();
|
||
}
|
||
} else {
|
||
// See if we can fetch this
|
||
fetch(url.split('#')[0])
|
||
.then(res => res.text())
|
||
.then(html => {
|
||
const parser = new DOMParser();
|
||
const htmlDoc = parser.parseFromString(html, "text/html");
|
||
const note = htmlDoc.getElementById(id);
|
||
if (note !== null) {
|
||
const html = processXRef(id, note);
|
||
instance.setContent(html);
|
||
}
|
||
}).finally(() => {
|
||
instance.enable();
|
||
instance.show();
|
||
});
|
||
}
|
||
} else {
|
||
// See if we can fetch a full url (with no hash to target)
|
||
// This is a special case and we should probably do some content thinning / targeting
|
||
fetch(url)
|
||
.then(res => res.text())
|
||
.then(html => {
|
||
const parser = new DOMParser();
|
||
const htmlDoc = parser.parseFromString(html, "text/html");
|
||
const note = htmlDoc.querySelector('main.content');
|
||
if (note !== null) {
|
||
// This should only happen for chapter cross references
|
||
// (since there is no id in the URL)
|
||
// remove the first header
|
||
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
|
||
note.children[0].remove();
|
||
}
|
||
const html = processXRef(null, note);
|
||
instance.setContent(html);
|
||
}
|
||
}).finally(() => {
|
||
instance.enable();
|
||
instance.show();
|
||
});
|
||
}
|
||
}, function(instance) {
|
||
});
|
||
}
|
||
let selectedAnnoteEl;
|
||
const selectorForAnnotation = ( cell, annotation) => {
|
||
let cellAttr = 'data-code-cell="' + cell + '"';
|
||
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
||
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
||
return selector;
|
||
}
|
||
const selectCodeLines = (annoteEl) => {
|
||
const doc = window.document;
|
||
const targetCell = annoteEl.getAttribute("data-target-cell");
|
||
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
||
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
||
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
||
const lineIds = lines.map((line) => {
|
||
return targetCell + "-" + line;
|
||
})
|
||
let top = null;
|
||
let height = null;
|
||
let parent = null;
|
||
if (lineIds.length > 0) {
|
||
//compute the position of the single el (top and bottom and make a div)
|
||
const el = window.document.getElementById(lineIds[0]);
|
||
top = el.offsetTop;
|
||
height = el.offsetHeight;
|
||
parent = el.parentElement.parentElement;
|
||
if (lineIds.length > 1) {
|
||
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
||
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
||
height = bottom - top;
|
||
}
|
||
if (top !== null && height !== null && parent !== null) {
|
||
// cook up a div (if necessary) and position it
|
||
let div = window.document.getElementById("code-annotation-line-highlight");
|
||
if (div === null) {
|
||
div = window.document.createElement("div");
|
||
div.setAttribute("id", "code-annotation-line-highlight");
|
||
div.style.position = 'absolute';
|
||
parent.appendChild(div);
|
||
}
|
||
div.style.top = top - 2 + "px";
|
||
div.style.height = height + 4 + "px";
|
||
div.style.left = 0;
|
||
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
||
if (gutterDiv === null) {
|
||
gutterDiv = window.document.createElement("div");
|
||
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
||
gutterDiv.style.position = 'absolute';
|
||
const codeCell = window.document.getElementById(targetCell);
|
||
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
||
gutter.appendChild(gutterDiv);
|
||
}
|
||
gutterDiv.style.top = top - 2 + "px";
|
||
gutterDiv.style.height = height + 4 + "px";
|
||
}
|
||
selectedAnnoteEl = annoteEl;
|
||
}
|
||
};
|
||
const unselectCodeLines = () => {
|
||
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
||
elementsIds.forEach((elId) => {
|
||
const div = window.document.getElementById(elId);
|
||
if (div) {
|
||
div.remove();
|
||
}
|
||
});
|
||
selectedAnnoteEl = undefined;
|
||
};
|
||
// Handle positioning of the toggle
|
||
window.addEventListener(
|
||
"resize",
|
||
throttle(() => {
|
||
elRect = undefined;
|
||
if (selectedAnnoteEl) {
|
||
selectCodeLines(selectedAnnoteEl);
|
||
}
|
||
}, 10)
|
||
);
|
||
function throttle(fn, ms) {
|
||
let throttle = false;
|
||
let timer;
|
||
return (...args) => {
|
||
if(!throttle) { // first call gets through
|
||
fn.apply(this, args);
|
||
throttle = true;
|
||
} else { // all the others get throttled
|
||
if(timer) clearTimeout(timer); // cancel #2
|
||
timer = setTimeout(() => {
|
||
fn.apply(this, args);
|
||
timer = throttle = false;
|
||
}, ms);
|
||
}
|
||
};
|
||
}
|
||
// Attach click handler to the DT
|
||
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
||
for (const annoteDlNode of annoteDls) {
|
||
annoteDlNode.addEventListener('click', (event) => {
|
||
const clickedEl = event.target;
|
||
if (clickedEl !== selectedAnnoteEl) {
|
||
unselectCodeLines();
|
||
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
||
if (activeEl) {
|
||
activeEl.classList.remove('code-annotation-active');
|
||
}
|
||
selectCodeLines(clickedEl);
|
||
clickedEl.classList.add('code-annotation-active');
|
||
} else {
|
||
// Unselect the line
|
||
unselectCodeLines();
|
||
clickedEl.classList.remove('code-annotation-active');
|
||
}
|
||
});
|
||
}
|
||
const findCites = (el) => {
|
||
const parentEl = el.parentElement;
|
||
if (parentEl) {
|
||
const cites = parentEl.dataset.cites;
|
||
if (cites) {
|
||
return {
|
||
el,
|
||
cites: cites.split(' ')
|
||
};
|
||
} else {
|
||
return findCites(el.parentElement)
|
||
}
|
||
} else {
|
||
return undefined;
|
||
}
|
||
};
|
||
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
||
for (var i=0; i<bibliorefs.length; i++) {
|
||
const ref = bibliorefs[i];
|
||
const citeInfo = findCites(ref);
|
||
if (citeInfo) {
|
||
tippyHover(citeInfo.el, function() {
|
||
var popup = window.document.createElement('div');
|
||
citeInfo.cites.forEach(function(cite) {
|
||
var citeDiv = window.document.createElement('div');
|
||
citeDiv.classList.add('hanging-indent');
|
||
citeDiv.classList.add('csl-entry');
|
||
var biblioDiv = window.document.getElementById('ref-' + cite);
|
||
if (biblioDiv) {
|
||
citeDiv.innerHTML = biblioDiv.innerHTML;
|
||
}
|
||
popup.appendChild(citeDiv);
|
||
});
|
||
return popup.innerHTML;
|
||
});
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
</div> <!-- /content -->
|
||
|
||
|
||
|
||
|
||
</body></html> |