quarto-blog/_site/posts/2020-07-25_diabetes-data-collection-and-cleaning/diabetes-in-rural-north-carolina-data-collection-and-cleaning.html
2024-06-08 08:28:40 -04:00

1319 lines
No EOL
53 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="2020-07-25">
<title>Kyle Belanger - Diabetes in Rural North Carolina : Data Collection and Cleaning</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;
}
</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">Diabetes in Rural North Carolina : Data Collection and Cleaning</h1>
<p class="subtitle lead"></p><p>This is the second post in the series exploring Diabetes in rural North Carolina. This post will explore the data used for this project, from collection, cleaning, and analysis ready data.</p><p></p>
</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">July 25, 2020</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="#abstract" id="toc-abstract" class="nav-link active" data-scroll-target="#abstract">Abstract</a></li>
<li><a href="#data" id="toc-data" class="nav-link" data-scroll-target="#data">Data</a>
<ul class="collapse">
<li><a href="#overall" id="toc-overall" class="nav-link" data-scroll-target="#overall">Overall</a></li>
<li><a href="#rural-housing" id="toc-rural-housing" class="nav-link" data-scroll-target="#rural-housing">Rural Housing</a></li>
<li><a href="#county-health-rankings" id="toc-county-health-rankings" class="nav-link" data-scroll-target="#county-health-rankings">County Health Rankings</a></li>
<li><a href="#population-estimates" id="toc-population-estimates" class="nav-link" data-scroll-target="#population-estimates">Population Estimates</a></li>
<li><a href="#diabetes-percentages" id="toc-diabetes-percentages" class="nav-link" data-scroll-target="#diabetes-percentages">Diabetes Percentages</a></li>
</ul></li>
<li><a href="#analyis-data" id="toc-analyis-data" class="nav-link" data-scroll-target="#analyis-data">Analyis Data</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">
<section id="abstract" class="level1">
<h1>Abstract</h1>
<p>This is the second post in the series exploring Diabetes in rural North Carolina. This post will explore the data used for this project, from collection, cleaning, and analysis ready data.</p>
</section>
<section id="data" class="level1">
<h1>Data</h1>
<section id="overall" class="level2">
<h2 class="anchored" data-anchor-id="overall">Overall</h2>
<p>Overall there are four data sources that have been used to create the analysis ready data for this project. There is one additional metadata file that contains the list of all county FIP codes, used for linking the various data sets. All data sets use the county FIPS as the county identifier, the county name is added at the end using the metadata. The image below shows the steps taken to achieve the analysis data set, as well as a table below showing the structure of each data set.</p>
<p><img src="data-cleaning.png" class="img-fluid"></p>
<hr>
<div class="cell">
<div class="cell-output-display">
<div>
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
<caption>Data Sources</caption>
<thead>
<tr class="header">
<th style="text-align: left;" data-quarto-table-cell-role="th">Data</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Structure</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Source</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Notes</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">2010 Census Rural/Urban Housing</td>
<td style="text-align: left;">one row per county</td>
<td style="text-align: left;">US Census</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">County Health Rankings</td>
<td style="text-align: left;">one row per county, year</td>
<td style="text-align: left;">County Health Rankings</td>
<td style="text-align: left;">Raw data is one year per file</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Population Estimates</td>
<td style="text-align: left;">one row per county, year, age group</td>
<td style="text-align: left;">US Census</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Diabetes Data</td>
<td style="text-align: left;">one row per county, year</td>
<td style="text-align: left;">CDC Diabetes Atlas</td>
<td style="text-align: left;">Raw data is one year per file</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="rural-housing" class="level2">
<h2 class="anchored" data-anchor-id="rural-housing">Rural Housing</h2>
<p>The first data set comes from the <a href="https://data.census.gov/cedsci/table?q=rural%20house&amp;hidePreview=true&amp;tid=DECENNIALSF12010.H2&amp;vintage=2010&amp;tp=true&amp;g=0100000US.050000">US Census</a>, and contains the amount of housing units inside both Urban and Rural areas. The raw data was taken and used to calculate the percentage of housing units in rural areas, as well as adding the classifications of Rural, Mostly Rural, and Mostly Urban. More about these classifications can be read <a href="https://www2.census.gov/geo/pdfs/reference/ua/Defining_Rural.pdf">here</a>. This data set is from the 2010 US Census, which is then used to set the rural classification until the next Census (2020).</p>
<p>View greeter script <a href="https://github.com/mmmmtoasty19/nc-diabetes-epidemic-2020/blob/master/manipulation/publish/0-greeter-census-rural-housing.md">here</a></p>
<div class="cell">
<div class="cell-output-display">
<div>
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
<caption>Rural Housing Data Set</caption>
<thead>
<tr class="header">
<th style="text-align: center;" data-quarto-table-cell-role="th">County Fips</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Pct Rural</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Rural</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">05131</td>
<td style="text-align: center;">20.41</td>
<td style="text-align: center;">Mostly Urban</td>
</tr>
<tr class="even">
<td style="text-align: center;">05133</td>
<td style="text-align: center;">69.29</td>
<td style="text-align: center;">Mostly Rural</td>
</tr>
<tr class="odd">
<td style="text-align: center;">05135</td>
<td style="text-align: center;">77.84</td>
<td style="text-align: center;">Mostly Rural</td>
</tr>
<tr class="even">
<td style="text-align: center;">05137</td>
<td style="text-align: center;">100.00</td>
<td style="text-align: center;">Rural</td>
</tr>
<tr class="odd">
<td style="text-align: center;">05139</td>
<td style="text-align: center;">55.07</td>
<td style="text-align: center;">Mostly Rural</td>
</tr>
<tr class="even">
<td style="text-align: center;">05141</td>
<td style="text-align: center;">100.00</td>
<td style="text-align: center;">Rural</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: center; padding: 0;"><span style="font-style: italic;">Note: </span></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center; padding: 0;"><sup></sup> Displaying 6 of 3,143 rows</td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</section>
<section id="county-health-rankings" class="level2">
<h2 class="anchored" data-anchor-id="county-health-rankings">County Health Rankings</h2>
<p>The second data set comes from <a href="https://www.countyhealthrankings.org/">County Health Rankings</a> and contains data for the risk factors associated with diabetes, this data set is complied from many different data sources. The data was downloaded by year, and then combine to form one data set. County Health Rankings uses this data to rate health outcomes across all counties of the United States, for this analysis four categories have been extracted from the overall data set. Note that the food environment index is itself a combine measure, it is a score of both access to healthy food based on distance to grocery stores, as well as access based on cost.</p>
<p>View greeter script <a href="https://github.com/mmmmtoasty19/nc-diabetes-epidemic-2020/blob/master/manipulation/publish/0-greeter-county-rankings-national.md">here</a></p>
<div class="cell">
<div class="cell-output-display">
<div>
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
<caption>County Health Rankings Sources</caption>
<thead>
<tr class="header">
<th style="text-align: left;" data-quarto-table-cell-role="th">Measure</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Data Source</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">First Year Available</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Adult smoking</td>
<td style="text-align: left;">Behavioral Risk Factor Surveillance System</td>
<td style="text-align: right;">2010</td>
</tr>
<tr class="even">
<td style="text-align: left;">Adult obesity</td>
<td style="text-align: left;">CDC Diabetes Interactive Atlas</td>
<td style="text-align: right;">2010</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Physical inactivity</td>
<td style="text-align: left;">CDC Diabetes Interactive Atlas</td>
<td style="text-align: right;">2011</td>
</tr>
<tr class="even">
<td style="text-align: left;">Food environment index</td>
<td style="text-align: left;">USDA Food Environment Atlas, Map the Meal Gap</td>
<td style="text-align: right;">2014</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: left; padding: 0;"><span style="font-style: italic;">Source: </span></td>
<td style="text-align: left;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: left; padding: 0;"><sup></sup> https://www.countyhealthrankings.org/explore-health-rankings/measures-data-sources/2020-measures</td>
<td style="text-align: left;"></td>
<td style="text-align: right;"></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<hr>
<div class="cell">
<div class="cell-output-display">
<div>
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
<caption>County Risk Factors Data Set</caption>
<thead>
<tr class="header">
<th style="text-align: center;" data-quarto-table-cell-role="th">County Fips</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Year</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Adult Smoking Percent</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Adult Obesity Percent</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Physical Inactivity Percent</th>
<th style="text-align: center;" data-quarto-table-cell-role="th">Food Environment Index</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">01001</td>
<td style="text-align: center;">2010</td>
<td style="text-align: center;">28.1</td>
<td style="text-align: center;">30.0</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center;">01003</td>
<td style="text-align: center;">2010</td>
<td style="text-align: center;">23.1</td>
<td style="text-align: center;">24.5</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center;">01005</td>
<td style="text-align: center;">2010</td>
<td style="text-align: center;">22.7</td>
<td style="text-align: center;">36.4</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center;">01007</td>
<td style="text-align: center;">2010</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">31.7</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center;">01009</td>
<td style="text-align: center;">2010</td>
<td style="text-align: center;">23.4</td>
<td style="text-align: center;">31.5</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center;">01011</td>
<td style="text-align: center;">2010</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">37.3</td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;">NA</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: center; padding: 0;"><span style="font-style: italic;">Note: </span></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center; padding: 0;"><sup></sup> Displaying 6 of 34,555 rows</td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</section>
<section id="population-estimates" class="level2">
<h2 class="anchored" data-anchor-id="population-estimates">Population Estimates</h2>
<p>The third data set also comes from the <a href="https://www.census.gov/data/tables/time-series/demo/popest/2010s-counties-detail.html">US Census</a> and contains population estimates for each county in the United States broken down by: year, age-group, sex, race, and ethnicity. For each row in the table the percent of each type of population was calculated using the yearly population total for the county. This breakdown is useful for this project as African-Americans and Hispanics suffer from diabetes at a higher rate then other groups.</p>
<p>View greeter script <a href="https://github.com/mmmmtoasty19/nc-diabetes-epidemic-2020/blob/master/manipulation/publish/0-greeter-us-county-population-estimates.md">here</a></p>
<div class="cell">
<div class="cell-output-display">
<div>
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
<caption>US Population Estimates Data Set</caption>
<thead>
<tr class="header">
<th style="text-align: left;" data-quarto-table-cell-role="th">County Fips</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Year</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Age Group</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Year Total Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Total Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Total Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">White Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">White Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Black Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Black Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">American Indian Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">American Indian Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Asian Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Asian Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Native Hawaiian Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Native Hawaiian Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Not Hispanic Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Not Hispanic Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Hispanic Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Hispanic Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Hsipanic Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Male</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Female</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct White Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct White Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Black Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Black Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct American Indian Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct American Indian Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Asian Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Asian Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Native Hawaiian Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Native Hawaiian Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct not Hispanic Male Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct not Hispanic Female Population</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Pct Hispanic Male Population</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">01001</td>
<td style="text-align: right;">2010</td>
<td style="text-align: left;">0-4</td>
<td style="text-align: right;">54773</td>
<td style="text-align: right;">1863</td>
<td style="text-align: right;">1712</td>
<td style="text-align: right;">1415</td>
<td style="text-align: right;">1314</td>
<td style="text-align: right;">356</td>
<td style="text-align: right;">319</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">1778</td>
<td style="text-align: right;">1653</td>
<td style="text-align: right;">85</td>
<td style="text-align: right;">59</td>
<td style="text-align: right;">0.11</td>
<td style="text-align: right;">3.40</td>
<td style="text-align: right;">3.13</td>
<td style="text-align: right;">2.58</td>
<td style="text-align: right;">2.40</td>
<td style="text-align: right;">0.65</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">3.25</td>
<td style="text-align: right;">3.02</td>
<td style="text-align: right;">0.16</td>
</tr>
<tr class="even">
<td style="text-align: left;">01001</td>
<td style="text-align: right;">2010</td>
<td style="text-align: left;">5-9</td>
<td style="text-align: right;">54773</td>
<td style="text-align: right;">1984</td>
<td style="text-align: right;">1980</td>
<td style="text-align: right;">1506</td>
<td style="text-align: right;">1517</td>
<td style="text-align: right;">398</td>
<td style="text-align: right;">369</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">22</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">1916</td>
<td style="text-align: right;">1908</td>
<td style="text-align: right;">68</td>
<td style="text-align: right;">72</td>
<td style="text-align: right;">0.13</td>
<td style="text-align: right;">3.62</td>
<td style="text-align: right;">3.61</td>
<td style="text-align: right;">2.75</td>
<td style="text-align: right;">2.77</td>
<td style="text-align: right;">0.73</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">3.50</td>
<td style="text-align: right;">3.48</td>
<td style="text-align: right;">0.12</td>
</tr>
<tr class="odd">
<td style="text-align: left;">01001</td>
<td style="text-align: right;">2010</td>
<td style="text-align: left;">10-14</td>
<td style="text-align: right;">54773</td>
<td style="text-align: right;">2163</td>
<td style="text-align: right;">2129</td>
<td style="text-align: right;">1657</td>
<td style="text-align: right;">1621</td>
<td style="text-align: right;">427</td>
<td style="text-align: right;">409</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2098</td>
<td style="text-align: right;">2064</td>
<td style="text-align: right;">65</td>
<td style="text-align: right;">65</td>
<td style="text-align: right;">0.12</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">3.89</td>
<td style="text-align: right;">3.03</td>
<td style="text-align: right;">2.96</td>
<td style="text-align: right;">0.78</td>
<td style="text-align: right;">0.75</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">3.83</td>
<td style="text-align: right;">3.77</td>
<td style="text-align: right;">0.12</td>
</tr>
<tr class="even">
<td style="text-align: left;">01001</td>
<td style="text-align: right;">2010</td>
<td style="text-align: left;">15-19</td>
<td style="text-align: right;">54773</td>
<td style="text-align: right;">2182</td>
<td style="text-align: right;">2047</td>
<td style="text-align: right;">1601</td>
<td style="text-align: right;">1551</td>
<td style="text-align: right;">497</td>
<td style="text-align: right;">426</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">2125</td>
<td style="text-align: right;">1996</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">51</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: right;">3.98</td>
<td style="text-align: right;">3.74</td>
<td style="text-align: right;">2.92</td>
<td style="text-align: right;">2.83</td>
<td style="text-align: right;">0.91</td>
<td style="text-align: right;">0.78</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">3.88</td>
<td style="text-align: right;">3.64</td>
<td style="text-align: right;">0.10</td>
</tr>
<tr class="odd">
<td style="text-align: left;">01001</td>
<td style="text-align: right;">2010</td>
<td style="text-align: left;">20-24</td>
<td style="text-align: right;">54773</td>
<td style="text-align: right;">1573</td>
<td style="text-align: right;">1579</td>
<td style="text-align: right;">1223</td>
<td style="text-align: right;">1219</td>
<td style="text-align: right;">306</td>
<td style="text-align: right;">316</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">7</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">1511</td>
<td style="text-align: right;">1537</td>
<td style="text-align: right;">62</td>
<td style="text-align: right;">42</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">2.87</td>
<td style="text-align: right;">2.88</td>
<td style="text-align: right;">2.23</td>
<td style="text-align: right;">2.23</td>
<td style="text-align: right;">0.56</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">2.76</td>
<td style="text-align: right;">2.81</td>
<td style="text-align: right;">0.11</td>
</tr>
<tr class="even">
<td style="text-align: left;">01001</td>
<td style="text-align: right;">2010</td>
<td style="text-align: left;">25-29</td>
<td style="text-align: right;">54773</td>
<td style="text-align: right;">1574</td>
<td style="text-align: right;">1617</td>
<td style="text-align: right;">1251</td>
<td style="text-align: right;">1235</td>
<td style="text-align: right;">289</td>
<td style="text-align: right;">341</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">1505</td>
<td style="text-align: right;">1570</td>
<td style="text-align: right;">69</td>
<td style="text-align: right;">47</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: right;">2.87</td>
<td style="text-align: right;">2.95</td>
<td style="text-align: right;">2.28</td>
<td style="text-align: right;">2.25</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">2.75</td>
<td style="text-align: right;">2.87</td>
<td style="text-align: right;">0.13</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: left; padding: 0;"><span style="font-style: italic;">Note: </span></td>
<td style="text-align: right;"></td>
<td style="text-align: left;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: left; padding: 0;"><sup></sup> Displaying 6 of 565560 rows</td>
<td style="text-align: right;"></td>
<td style="text-align: left;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</section>
<section id="diabetes-percentages" class="level2">
<h2 class="anchored" data-anchor-id="diabetes-percentages">Diabetes Percentages</h2>
<p>The final data set comes from the <a href="https://www.cdc.gov/diabetes/data/index.html">CDC Diabetes Atlas</a> and contains the estimated prevalence of diabetes in each county of the United States, by year. The data set also includes the upper and lower estimated limits, see the <a href="https://kyleb.rbind.io/post/2020-06-25-diabetes-1/">previous post</a> for an explanation of how these numbers are calculated. The data was downloaded by year, and then merged into one data set for the project.</p>
<p>View greeter script <a href="https://github.com/mmmmtoasty19/nc-diabetes-epidemic-2020/blob/master/manipulation/publish/0-greeter-us-diabetes.md">here</a></p>
<div class="cell">
<div class="cell-output-display">
<div>
<table class="table table-sm table-striped small" data-quarto-postprocess="true">
<caption>US Diabetes Data</caption>
<thead>
<tr class="header">
<th style="text-align: right;" data-quarto-table-cell-role="th">Year</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">County Fips</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Diabetes Percentage</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Diabetes Lower Limit</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Diabetes Upper Limit</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">2010</td>
<td style="text-align: left;">01001</td>
<td style="text-align: right;">11.2</td>
<td style="text-align: right;">8.8</td>
<td style="text-align: right;">13.9</td>
</tr>
<tr class="even">
<td style="text-align: right;">2010</td>
<td style="text-align: left;">01003</td>
<td style="text-align: right;">10.2</td>
<td style="text-align: right;">8.7</td>
<td style="text-align: right;">11.9</td>
</tr>
<tr class="odd">
<td style="text-align: right;">2010</td>
<td style="text-align: left;">01005</td>
<td style="text-align: right;">13.0</td>
<td style="text-align: right;">10.6</td>
<td style="text-align: right;">15.9</td>
</tr>
<tr class="even">
<td style="text-align: right;">2010</td>
<td style="text-align: left;">01007</td>
<td style="text-align: right;">10.6</td>
<td style="text-align: right;">8.2</td>
<td style="text-align: right;">13.3</td>
</tr>
<tr class="odd">
<td style="text-align: right;">2010</td>
<td style="text-align: left;">01009</td>
<td style="text-align: right;">12.6</td>
<td style="text-align: right;">9.8</td>
<td style="text-align: right;">15.7</td>
</tr>
<tr class="even">
<td style="text-align: right;">2010</td>
<td style="text-align: left;">01011</td>
<td style="text-align: right;">16.1</td>
<td style="text-align: right;">12.4</td>
<td style="text-align: right;">20.4</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
</section>
</section>
<section id="analyis-data" class="level1">
<h1>Analyis Data</h1>
<p>After all data has been made ready the data is joined into a final analysis ready data set. Each row of this data set represents, one county, one year, and one age group. The data is also filtered to remove Alaska and Hawaii as these states could affect trends seen in the continental United States.</p>
<p>View the scribe script <a href="https://github.com/mmmmtoasty19/nc-diabetes-epidemic-2020/blob/master/manipulation/publish/1-scribe-diabetes-data-set.md">here</a></p>
<p><img src="data-join.png" class="img-fluid"></p>
</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{belanger2020,
author = {Belanger, Kyle},
title = {Diabetes in {Rural} {North} {Carolina} : {Data} {Collection}
and {Cleaning}},
date = {2020-07-25},
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-belanger2020" class="csl-entry quarto-appendix-citeas" role="listitem">
Belanger, Kyle. 2020. <span>“Diabetes in Rural North Carolina : Data
Collection and Cleaning.”</span> July 25, 2020.
</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>