1<!DOCTYPE html> 2 3<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> 4 5<head> 6 <meta charset="utf-8"/> 7<!-- This site is hosted on Netlify. Anyone can build and deploy a site 8 like this one for free: https://netlify.new/?utm_campaign=loops&utm_source=ai-legible&utm_medium=owned&utm_content=comment&utm_id=ab0ce3c8-c477-4f82-a0ee-037dc555cb61 9 Netlify hosting facts for this site: static/SSR served via Netlify Edge. --> 10 <meta name="viewport" content="width=device-width, initial-scale=1"/> 11 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> 12 <meta name="generator" content="distill" /> 13 14 <style type="text/css"> 15 /* Hide doc at startup (prevent jankiness while JS renders/transforms) */ 16 body { 17 visibility: hidden; 18 } 19 </style> 20 21 <!--radix_placeholder_import_source--> 22 <!--/radix_placeholder_import_source--> 23 24<style type="text/css">code{white-space: pre;}</style> 25<style type="text/css" data-origin="pandoc"> 26pre > code.sourceCode { white-space: pre; position: relative; } 27pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } 28pre > code.sourceCode > span:empty { height: 1.2em; } 29.sourceCode { overflow: visible; } 30code.sourceCode > span { color: inherit; text-decoration: inherit; } 31div.sourceCode { margin: 1em 0; } 32pre.sourceCode { margin: 0; } 33@media screen { 34div.sourceCode { overflow: auto; } 35} 36@media print { 37pre > code.sourceCode { white-space: pre-wrap; } 38pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } 39} 40pre.numberSource code 41 { counter-reset: source-line 0; } 42pre.numberSource code > span 43 { position: relative; left: -4em; counter-increment: source-line; } 44pre.numberSource code > span > a:first-child::before 45 { content: counter(source-line); 46 position: relative; left: -1em; text-align: right; vertical-align: baseline; 47 border: none; display: inline-block; 48 -webkit-touch-callout: none; -webkit-user-select: none; 49 -khtml-user-select: none; -moz-user-select: none; 50 -ms-user-select: none; user-select: none; 51 padding: 0 4px; width: 4em; 52 color: #aaaaaa; 53 } 54pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } 55div.sourceCode 56 { color: #00769e; background-color: #f1f3f5; } 57@media screen { 58pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } 59} 60code span { color: #00769e; } /* Normal */ 61code span.al { color: #ad0000; } /* Alert */ 62code span.an { color: #5e5e5e; } /* Annotation */ 63code span.at { color: #657422; } /* Attribute */ 64code span.bn { color: #ad0000; } /* BaseN */ 65code span.bu { } /* BuiltIn */ 66code span.cf { color: #00769e; } /* ControlFlow */ 67code span.ch { color: #20794d; } /* Char */ 68code span.cn { color: #8f5902; } /* Constant */ 69code span.co { color: #5e5e5e; } /* Comment */ 70code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */ 71code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */ 72code span.dt { color: #ad0000; } /* DataType */ 73code span.dv { color: #ad0000; } /* DecVal */ 74code span.er { color: #ad0000; } /* Error */ 75code span.ex { } /* Extension */ 76code span.fl { color: #ad0000; } /* Float */ 77code span.fu { color: #4758ab; } /* Function */ 78code span.im { } /* Import */ 79code span.in { color: #5e5e5e; } /* Information */ 80code span.kw { color: #00769e; } /* Keyword */ 81code span.op { color: #5e5e5e; } /* Operator */ 82code span.ot { color: #00769e; } /* Other */ 83code span.pp { color: #ad0000; } /* Preprocessor */ 84code span.sc { color: #5e5e5e; } /* SpecialChar */ 85code span.ss { color: #20794d; } /* SpecialString */ 86code span.st { color: #20794d; } /* String */ 87code span.va { color: #111111; } /* Variable */ 88code span.vs { color: #20794d; } /* VerbatimString */ 89code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */ 90</style> 91 92 93 <!--radix_placeholder_meta_tags--> 94 <title>Applied Machine Learning for Educational Data Science: Introduction to Toy Datasets</title> 95 96 97 <link rel="license" href="https://creativecommons.org/licenses/by/4.0/"/> 98 99 <!-- https://schema.org/Article --> 100 <meta property="article:published" itemprop="datePublished" content="2022-06-23"/> 101 <meta property="article:created" itemprop="dateCreated" content="2022-06-23"/> 102 <meta name="article:author" content="Cengiz Zopluoglu"/> 103 104 <!-- https://developers.facebook.com/docs/sharing/webmasters#markup --> 105 <meta property="og:title" content="Applied Machine Learning for Educational Data Science: Introduction to Toy Datasets"/> 106 <meta property="og:type" content="article"/> 107 <meta property="og:locale" content="en_US"/> 108 <meta property="og:site_name" content="Applied Machine Learning for Educational Data Science"/> 109 110 <!-- https://dev.twitter.com/cards/types/summary --> 111 <meta property="twitter:card" content="summary"/> 112 <meta property="twitter:title" content="Applied Machine Learning for Educational Data Science: Introduction to Toy Datasets"/> 113 114 <!--/radix_placeholder_meta_tags--> 115 <!--radix_placeholder_rmarkdown_metadata--> 116 117
117<script type="text/json" id="radix-rmarkdown-metadata"> 118 {"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["title","author","date","output"]}},"value":[{"type":"character","attributes":{},"value":["Introduction to Toy Datasets"]},{"type":"list","attributes":{},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["name","affiliation"]}},"value":[{"type":"character","attributes":{},"value":["Cengiz Zopluoglu"]},{"type":"character","attributes":{},"value":["University of Oregon"]}]}]},{"type":"character","attributes":{},"value":["06/23/2022"]},{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["distill::distill_article"]}},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["self_contained","toc","toc_float","theme"]}},"value":[{"type":"logical","attributes":{},"value":[true]},{"type":"logical","attributes":{},"value":[true]},{"type":"logical","attributes":{},"value":[true]},{"type":"character","attributes":{},"value":["theme.css"]}]}]}]} 119 </script>
119 120 <!--/radix_placeholder_rmarkdown_metadata--> 121 <!--radix_placeholder_navigation_in_header--> 122 <meta name="distill:offset" content=""/> 123 124
124<script type="application/javascript"> 125 126 window.headroom_prevent_pin = false; 127 128 window.document.addEventListener("DOMContentLoaded", function (event) { 129 130 // initialize headroom for banner 131 var header = $('header').get(0); 132 var headerHeight = header.offsetHeight; 133 var headroom = new Headroom(header, { 134 tolerance: 5, 135 onPin : function() { 136 if (window.headroom_prevent_pin) { 137 window.headroom_prevent_pin = false; 138 headroom.unpin(); 139 } 140 } 141 }); 142 headroom.init(); 143 if(window.location.hash) 144 headroom.unpin(); 145 $(header).addClass('headroom--transition'); 146 147 // offset scroll location for banner on hash change 148 // (see: https://github.com/WickyNilliams/headroom.js/issues/38) 149 window.addEventListener("hashchange", function(event) { 150 window.scrollTo(0, window.pageYOffset - (headerHeight + 25)); 151 }); 152 153 // responsive menu 154 $('.distill-site-header').each(function(i, val) { 155 var topnav = $(this); 156 var toggle = topnav.find('.nav-toggle'); 157 toggle.on('click', function() { 158 topnav.toggleClass('responsive'); 159 }); 160 }); 161 162 // nav dropdowns 163 $('.nav-dropbtn').click(function(e) { 164 $(this).next('.nav-dropdown-content').toggleClass('nav-dropdown-active'); 165 $(this).parent().siblings('.nav-dropdown') 166 .children('.nav-dropdown-content').removeClass('nav-dropdown-active'); 167 }); 168 $("body").click(function(e){ 169 $('.nav-dropdown-content').removeClass('nav-dropdown-active'); 170 }); 171 $(".nav-dropdown").click(function(e){ 172 e.stopPropagation(); 173 }); 174 }); 175 </script>
175 176 177 <style type="text/css"> 178 179 /* Theme (user-documented overrideables for nav appearance) */ 180 181 .distill-site-nav { 182 color: rgba(255, 255, 255, 0.8); 183 background-color: #0F2E3D; 184 font-size: 15px; 185 font-weight: 300; 186 } 187 188 .distill-site-nav a { 189 color: inherit; 190 text-decoration: none; 191 } 192 193 .distill-site-nav a:hover { 194 color: white; 195 } 196 197 @media print { 198 .distill-site-nav { 199 display: none; 200 } 201 } 202 203 .distill-site-header { 204 205 } 206 207 .distill-site-footer { 208 209 } 210 211 212 /* Site Header */ 213 214 .distill-site-header { 215 width: 100%; 216 box-sizing: border-box; 217 z-index: 3; 218 } 219 220 .distill-site-header .nav-left { 221 display: inline-block; 222 margin-left: 8px; 223 } 224 225 @media screen and (max-width: 768px) { 226 .distill-site-header .nav-left { 227 margin-left: 0; 228 } 229 } 230 231 232 .distill-site-header .nav-right { 233 float: right; 234 margin-right: 8px; 235 } 236 237 .distill-site-header a, 238 .distill-site-header .title { 239 display: inline-block; 240 text-align: center; 241 padding: 14px 10px 14px 10px; 242 } 243 244 .distill-site-header .title { 245 font-size: 18px; 246 min-width: 150px; 247 } 248 249 .distill-site-header .logo { 250 padding: 0; 251 } 252 253 .distill-site-header .logo img { 254 display: none; 255 max-height: 20px; 256 width: auto; 257 margin-bottom: -4px; 258 } 259 260 .distill-site-header .nav-image img { 261 max-height: 18px; 262 width: auto; 263 display: inline-block; 264 margin-bottom: -3px; 265 } 266 267 268 269 @media screen and (min-width: 1000px) { 270 .distill-site-header .logo img { 271 display: inline-block; 272 } 273 .distill-site-header .nav-left { 274 margin-left: 20px; 275 } 276 .distill-site-header .nav-right { 277 margin-right: 20px; 278 } 279 .distill-site-header .title { 280 padding-left: 12px; 281 } 282 } 283 284 285 .distill-site-header .nav-toggle { 286 display: none; 287 } 288 289 .nav-dropdown { 290 display: inline-block; 291 position: relative; 292 } 293 294 .nav-dropdown .nav-dropbtn { 295 border: none; 296 outline: none; 297 color: rgba(255, 255, 255, 0.8); 298 padding: 16px 10px; 299 background-color: transparent; 300 font-family: inherit; 301 font-size: inherit; 302 font-weight: inherit; 303 margin: 0;
304 margin-top: 1px; 305 z-index: 2; 306 } 307 308 .nav-dropdown-content { 309 display: none; 310 position: absolute; 311 background-color: white; 312 min-width: 200px; 313 border: 1px solid rgba(0,0,0,0.15); 314 border-radius: 4px; 315 box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.1); 316 z-index: 1; 317 margin-top: 2px; 318 white-space: nowrap; 319 padding-top: 4px; 320 padding-bottom: 4px; 321 } 322 323 .nav-dropdown-content hr { 324 margin-top: 4px; 325 margin-bottom: 4px; 326 border: none; 327 border-bottom: 1px solid rgba(0, 0, 0, 0.1); 328 } 329 330 .nav-dropdown-active { 331 display: block; 332 } 333 334 .nav-dropdown-content a, .nav-dropdown-content .nav-dropdown-header { 335 color: black; 336 padding: 6px 24px; 337 text-decoration: none; 338 display: block; 339 text-align: left; 340 } 341 342 .nav-dropdown-content .nav-dropdown-header { 343 display: block; 344 padding: 5px 24px; 345 padding-bottom: 0; 346 text-transform: uppercase; 347 font-size: 14px; 348 color: #999999; 349 white-space: nowrap; 350 } 351 352 .nav-dropdown:hover .nav-dropbtn { 353 color: white; 354 } 355 356 .nav-dropdown-content a:hover { 357 background-color: #ddd; 358 color: black; 359 } 360 361 .nav-right .nav-dropdown-content { 362 margin-left: -45%; 363 right: 0; 364 } 365 366 @media screen and (max-width: 768px) { 367 .distill-site-header a, .distill-site-header .nav-dropdown {display: none;} 368 .distill-site-header a.nav-toggle { 369 float: right; 370 display: block; 371 } 372 .distill-site-header .title { 373 margin-left: 0; 374 } 375 .distill-site-header .nav-right { 376 margin-right: 0; 377 } 378 .distill-site-header { 379 overflow: hidden; 380 } 381 .nav-right .nav-dropdown-content { 382 margin-left: 0; 383 } 384 } 385 386 387 @media screen and (max-width: 768px) { 388 .distill-site-header.responsive {position: relative; min-height: 500px; } 389 .distill-site-header.responsive a.nav-toggle { 390 position: absolute; 391 right: 0; 392 top: 0; 393 } 394 .distill-site-header.responsive a, 395 .distill-site-header.responsive .nav-dropdown { 396 display: block; 397 text-align: left; 398 } 399 .distill-site-header.responsive .nav-left, 400 .distill-site-header.responsive .nav-right { 401 width: 100%; 402 } 403 .distill-site-header.responsive .nav-dropdown {float: none;} 404 .distill-site-header.responsive .nav-dropdown-content {position: relative;} 405 .distill-site-header.responsive .nav-dropdown .nav-dropbtn { 406 display: block; 407 width: 100%; 408 text-align: left; 409 } 410 } 411 412 /* Site Footer */ 413 414 .distill-site-footer { 415 width: 100%; 416 overflow: hidden; 417 box-sizing: border-box; 418 z-index: 3; 419 margin-top: 30px; 420 padding-top: 30px; 421 padding-bottom: 30px; 422 text-align: center; 423 } 424 425 /* Headroom */ 426 427 d-title { 428 padding-top: 6rem; 429 } 430 431 @media print { 432 d-title { 433 padding-top: 4rem; 434 } 435 } 436 437 .headroom { 438 z-index: 1000; 439 position: fixed; 440 top: 0; 441 left: 0; 442 right: 0; 443 } 444 445 .headroom--transition { 446 transition: all .4s ease-in-out; 447 } 448 449 .headroom--unpinned { 450 top: -100px; 451 } 452 453 .headroom--pinned { 454 top: 0; 455 } 456 457 /* adjust viewport for navbar height */ 458 /* helps vertically center bootstrap (non-distill) content */ 459 .min-vh-100 { 460 min-height: calc(100vh - 100px) !important; 461 } 462 463 </style> 464 465
465<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
465 466 <link href="site_libs/font-awesome-5.1.0/css/all.css" rel="stylesheet"/> 467 <link href="site_libs/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet"/> 468
468<script src="site_libs/headroom-0.9.4/headroom.min.js"></script>
468 469
469<script src="site_libs/autocomplete-0.37.1/autocomplete.min.js"></script>
469 470
470<script src="site_libs/fuse-6.4.1/fuse.min.js"></script>
470 471 472
472<script type="application/javascript"> 473 474 function getMeta(metaName) { 475 var metas = document.getElementsByTagName('meta'); 476 for (let i = 0; i < metas.length; i++) { 477 if (metas[i].getAttribute('name') === metaName) { 478 return metas[i].getAttribute('content'); 479 } 480 } 481 return ''; 482 } 483 484 function offsetURL(url) { 485 var offset = getMeta('distill:offset'); 486 return offset ? offset + '/' + url : url; 487 } 488 489 function createFuseIndex() { 490 491 // create fuse index 492 var options = { 493 keys: [ 494 { name: 'title', weight: 20 }, 495 { name: 'categories', weight: 15 }, 496 { name: 'description', weight: 10 }, 497 { name: 'contents', weight: 5 }, 498 ], 499 ignoreLocation: true, 500 threshold: 0 501 }; 502 var fuse = new window.Fuse([], options); 503 504 // fetch the main search.json 505 return fetch(offsetURL('search.json')) 506 .then(function(response) { 507 if (response.status == 200) { 508 return response.json().then(function(json) { 509 // index main articles 510 json.articles.forEach(function(article) { 511 fuse.add(article); 512 }); 513 // download collections and index their articles 514 return Promise.all(json.collections.map(function(collection) { 515 return fetch(offsetURL(collection)).then(function(response) { 516 if (response.status === 200) { 517 return response.json().then(function(articles) { 518 articles.forEach(function(article) { 519 fuse.add(article); 520 }); 521 }) 522 } else { 523 return Promise.reject( 524 new Error('Unexpected status from search index request: ' + 525 response.status) 526 ); 527 } 528 }); 529 })).then(function() { 530 return fuse; 531 }); 532 }); 533 534 } else { 535 return Promise.reject( 536 new Error('Unexpected status from search index request: ' + 537 response.status) 538 ); 539 } 540 }); 541 } 542 543 window.document.addEventListener("DOMContentLoaded", function (event) { 544 545 // get search element (bail if we don't have one) 546 var searchEl = window.document.getElementById('distill-search'); 547 if (!searchEl) 548 return; 549 550 createFuseIndex() 551 .then(function(fuse) { 552 553 // make search box visible 554 searchEl.classList.remove('hidden'); 555 556 // initialize autocomplete 557 var options = { 558 autoselect: true, 559 hint: false, 560 minLength: 2, 561 }; 562 window.autocomplete(searchEl, options, [{ 563 source: function(query, callback) { 564 const searchOptions = { 565 isCaseSensitive: false, 566 shouldSort: true, 567 minMatchCharLength: 2, 568 limit: 10, 569 }; 570 var results = fuse.search(query, searchOptions); 571 callback(results 572 .map(function(result) { return result.item; }) 573 ); 574 }, 575 templates: { 576 suggestion: function(suggestion) { 577 var img = suggestion.preview && Object.keys(suggestion.preview).length > 0 578 ? `<img src="${offsetURL(suggestion.preview)}"</img>` 579 : ''; 580 var html = ` 581 <div class="search-item"> 582 <h3>${suggestion.title}</h3> 583 <div class="search-item-description"> 584 ${suggestion.description || ''} 585 </div> 586 <div class="search-item-preview"> 587 ${img} 588 </div> 589 </div> 590 `; 591 return html; 592 } 593 } 594 }]).on('autocomplete:selected', function(event, suggestion) { 595 window.location.href = offsetURL(suggestion.path); 596 }); 597 // remove inline display style on autocompleter (we want to 598 // manage responsive display via css) 599 $('.algolia-autocomplete').css("display", ""); 600 }) 601 .catch(function(error) { 602 console.log(error); 603 }); 604 605 }); 606 607 </script>
607 608 609 <style type="text/css"> 610 611 .nav-search { 612 font-size: x-small; 613 } 614 615 /* Algolioa Autocomplete */ 616 617 .algolia-autocomplete { 618 display: inline-block; 619 margin-left: 10px; 620 vertical-align: sub; 621 background-color: white; 622 color: black; 623 padding: 6px; 624 padding-top: 8px; 625 padding-bottom: 0; 626 border-radius: 6px; 627 border: 1px #0F2E3D solid; 628 width: 180px; 629 } 630 631 632 @media screen and (max-width: 768px) { 633 .distill-site-nav .algolia-autocomplete { 634 display: none; 635 visibility: hidden; 636 } 637 .distill-site-nav.responsive .algolia-autocomplete { 638 display: inline-block; 639 visibility: visible; 640 } 641 .distill-site-nav.responsive .algolia-autocomplete .aa-dropdown-menu { 642 margin-left: 0; 643 width: 400px; 644 max-height: 400px; 645 } 646 } 647 648 .algolia-autocomplete .aa-input, .algolia-autocomplete .aa-hint { 649 width: 90%; 650 outline: none; 651 border: none; 652 } 653 654 .algolia-autocomplete .aa-hint { 655 color: #999; 656 } 657 .algolia-autocomplete .aa-dropdown-menu { 658 width: 550px; 659 max-height: 70vh; 660 overflow-x: visible; 661 overflow-y: scroll; 662 padding: 5px; 663 margin-top: 3px; 664 margin-left: -150px; 665 background-color: #fff; 666 border-radius: 5px; 667 border: 1px solid #999; 668 border-top: none; 669 } 670 671 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion { 672 cursor: pointer; 673 padding: 5px 4px; 674 border-bottom: 1px solid #eee; 675 } 676 677 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion:last-of-type { 678 border-bottom: none; 679 margin-bottom: 2px; 680 } 681 682 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion .search-item { 683 overflow: hidden; 684 font-size: 0.8em; 685 line-height: 1.4em; 686 } 687 688 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion .search-item h3 { 689 font-size: 1rem; 690 margin-block-start: 0; 691 margin-block-end: 5px; 692 } 693 694 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion .search-item-description { 695 display: inline-block; 696 overflow: hidden; 697 height: 2.8em; 698 width: 80%; 699 margin-right: 4%; 700 } 701 702 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion .search-item-preview { 703 display: inline-block; 704 width: 15%; 705 } 706 707 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion .search-item-preview img { 708 height: 3em; 709 width: auto; 710 display: none; 711 } 712 713 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion .search-item-preview img[src] { 714 display: initial; 715 } 716 717 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor { 718 background-color: #eee; 719 } 720 .algolia-autocomplete .aa-dropdown-menu .aa-suggestion em { 721 font-weight: bold; 722 font-style: normal; 723 } 724 725 </style> 726 727 728 <!--/radix_placeholder_navigation_in_header--> 729 <!--radix_placeholder_distill--> 730 731 <style type="text/css"> 732 733 body { 734 background-color: white; 735 } 736 737 .pandoc-table { 738 width: 100%; 739 } 740 741 .pandoc-table>caption { 742 margin-bottom: 10px; 743 } 744 745 .pandoc-table th:not([align]) { 746 text-align: left; 747 } 748 749 .pagedtable-footer { 750 font-size: 15px; 751 } 752 753 d-byline .byline { 754 grid-template-columns: 2fr 2fr; 755 } 756 757 d-byline .byline h3 { 758 margin-block-start: 1.5em; 759 } 760 761 d-byline .byline .authors-affiliations h3 { 762 margin-block-start: 0.5em; 763 } 764 765 .authors-affiliations .orcid-id { 766 width: 16px; 767 height:16px; 768 margin-left: 4px; 769 margin-right: 4px; 770 vertical-align: middle; 771 padding-bottom: 2px; 772 } 773 774 d-title .dt-tags { 775 margin-top: 1em; 776 grid-column: text; 777 } 778 779 .dt-tags .dt-tag { 780 text-decoration: none; 781 display: inline-block; 782 color: rgba(0,0,0,0.6); 783 padding: 0em 0.4em; 784 margin-right: 0.5em; 785 margin-bottom: 0.4em; 786 font-size: 70%; 787 border: 1px solid rgba(0,0,0,0.2); 788 border-radius: 3px; 789 text-transform: uppercase; 790 font-weight: 500; 791 } 792 793 d-article table.gt_table td, 794 d-article table.gt_table th { 795 border-bottom: none; 796 } 797 798 .html-widget { 799 margin-bottom: 2.0em; 800 } 801 802 .l-screen-inset { 803 padding-right: 16px; 804 } 805 806 .l-screen .caption { 807 margin-left: 10px; 808 } 809 810 .shaded { 811 background: rgb(247, 247, 247); 812 padding-top: 20px; 813 padding-bottom: 20px; 814 border-top: 1px solid rgba(0, 0, 0, 0.1); 815 border-bottom: 1px solid rgba(0, 0, 0, 0.1); 816 } 817 818 .shaded .html-widget { 819 margin-bottom: 0; 820 border: 1px solid rgba(0, 0, 0, 0.1); 821 } 822 823 .shaded .shaded-content { 824 background: white; 825 } 826 827 .text-output { 828 margin-top: 0;
829 line-height: 1.5em; 830 } 831 832 .hidden { 833 display: none !important; 834 } 835 836 d-article { 837 padding-top: 2.5rem; 838 padding-bottom: 30px; 839 } 840 841 d-appendix { 842 padding-top: 30px; 843 } 844 845 d-article>p>img { 846 width: 100%; 847 } 848 849 d-article h2 { 850 margin: 1rem 0 1.5rem 0; 851 } 852 853 d-article h3 { 854 margin-top: 1.5rem; 855 } 856 857 d-article iframe { 858 border: 1px solid rgba(0, 0, 0, 0.1); 859 margin-bottom: 2.0em; 860 width: 100%; 861 } 862 863 /* Tweak code blocks */ 864 865 d-article div.sourceCode code, 866 d-article pre code { 867 font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 868 } 869 870 d-article pre, 871 d-article div.sourceCode, 872 d-article div.sourceCode pre { 873 overflow: auto; 874 } 875 876 d-article div.sourceCode { 877 background-color: white; 878 } 879 880 d-article div.sourceCode pre { 881 padding-left: 10px; 882 font-size: 12px; 883 border-left: 2px solid rgba(0,0,0,0.1); 884 } 885 886 d-article pre { 887 font-size: 12px; 888 color: black; 889 background: none; 890 margin-top: 0; 891 text-align: left; 892 white-space: pre; 893 word-spacing: normal; 894 word-break: normal; 895 word-wrap: normal; 896 line-height: 1.5; 897 898 -moz-tab-size: 4; 899 -o-tab-size: 4; 900 tab-size: 4; 901 902 -webkit-hyphens: none; 903 -moz-hyphens: none; 904 -ms-hyphens: none; 905 hyphens: none; 906 } 907 908 d-article pre a { 909 border-bottom: none; 910 } 911 912 d-article pre a:hover { 913 border-bottom: none; 914 text-decoration: underline; 915 } 916 917 d-article details { 918 grid-column: text; 919 margin-bottom: 0.8em; 920 } 921 922 @media(min-width: 768px) { 923 924 d-article pre, 925 d-article div.sourceCode, 926 d-article div.sourceCode pre { 927 overflow: visible !important; 928 } 929 930 d-article div.sourceCode pre { 931 padding-left: 18px; 932 font-size: 14px; 933 } 934 935 d-article pre { 936 font-size: 14px; 937 } 938 939 } 940 941 figure img.external { 942 background: white; 943 border: 1px solid rgba(0, 0, 0, 0.1); 944 box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); 945 padding: 18px; 946 box-sizing: border-box; 947 } 948 949 /* CSS for d-contents */ 950 951 .d-contents { 952 grid-column: text; 953 color: rgba(0,0,0,0.8); 954 font-size: 0.9em; 955 padding-bottom: 1em; 956 margin-bottom: 1em; 957 padding-bottom: 0.5em; 958 margin-bottom: 1em; 959 padding-left: 0.25em; 960 justify-self: start; 961 } 962 963 @media(min-width: 1000px) { 964 .d-contents.d-contents-float { 965 height: 0; 966 grid-column-start: 1; 967 grid-column-end: 4; 968 justify-self: center; 969 padding-right: 3em; 970 padding-left: 2em; 971 } 972 } 973 974 .d-contents nav h3 { 975 font-size: 18px; 976 margin-top: 0; 977 margin-bottom: 1em; 978 } 979 980 .d-contents li { 981 list-style-type: none 982 } 983 984 .d-contents nav > ul { 985 padding-left: 0; 986 } 987 988 .d-contents ul { 989 padding-left: 1em 990 } 991 992 .d-contents nav ul li { 993 margin-top: 0.6em; 994 margin-bottom: 0.2em; 995 } 996 997 .d-contents nav a { 998 font-size: 13px; 999 border-bottom: none; 1000 text-decoration: none 1001 color: rgba(0, 0, 0, 0.8); 1002 } 1003 1004 .d-contents nav a:hover { 1005 text-decoration: underline solid rgba(0, 0, 0, 0.6) 1006 } 1007 1008 .d-contents nav > ul > li > a { 1009 font-weight: 600; 1010 } 1011 1012 .d-contents nav > ul > li > ul { 1013 font-weight: inherit; 1014 } 1015 1016 .d-contents nav > ul > li > ul > li { 1017 margin-top: 0.2em; 1018 } 1019 1020 1021 .d-contents nav ul { 1022 margin-top: 0; 1023 margin-bottom: 0.25em; 1024 } 1025 1026 .d-article-with-toc h2:nth-child(2) { 1027 margin-top: 0; 1028 } 1029 1030 1031 /* Figure */ 1032 1033 .figure { 1034 position: relative; 1035 margin-bottom: 2.5em; 1036 margin-top: 1.5em; 1037 } 1038 1039 .figure .caption { 1040 color: rgba(0, 0, 0, 0.6); 1041 font-size: 12px; 1042 line-height: 1.5em; 1043 } 1044 1045 .figure img.external { 1046 background: white; 1047 border: 1px solid rgba(0, 0, 0, 0.1); 1048 box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); 1049 padding: 18px; 1050 box-sizing: border-box; 1051 } 1052 1053 .figure .caption a { 1054 color: rgba(0, 0, 0, 0.6); 1055 } 1056 1057 .figure .caption b, 1058 .figure .caption strong, { 1059 font-weight: 600; 1060 color: rgba(0, 0, 0, 1.0); 1061 } 1062 1063 /* Citations */ 1064 1065 d-article .citation { 1066 color: inherit; 1067 cursor: inherit; 1068 } 1069 1070 div.hanging-indent{ 1071 margin-left: 1em; text-indent: -1em; 1072 } 1073 1074 /* Citation hover box */ 1075 1076 .tippy-box[data-theme~=light-border] { 1077 background-color: rgba(250, 250, 250, 0.95); 1078 } 1079 1080 .tippy-content > p { 1081 margin-bottom: 0; 1082 padding: 2px; 1083 } 1084 1085 1086 /* Tweak 1000px media break to show more text */ 1087 1088 @media(min-width: 1000px) { 1089 .base-grid, 1090 distill-header, 1091 d-title, 1092 d-abstract, 1093 d-article, 1094 d-appendix, 1095 distill-appendix, 1096 d-byline, 1097 d-footnote-list, 1098 d-citation-list, 1099 distill-footer { 1100 grid-template-columns: [screen-start] 1fr [page-start kicker-start] 80px [middle-start] 50px [text-start kicker-end] 65px 65px 65px 65px 65px 65px 65px 65px [text-end gutter-start] 65px [middle-end] 65px [page-end gutter-end] 1fr [screen-end]; 1101 grid-column-gap: 16px; 1102 } 1103 1104 .grid { 1105 grid-column-gap: 16px; 1106 } 1107 1108 d-article { 1109 font-size: 1.06rem; 1110 line-height: 1.7em; 1111 } 1112 figure .caption, .figure .caption, figure figcaption { 1113 font-size: 13px; 1114 } 1115 } 1116 1117 @media(min-width: 1180px) { 1118 .base-grid, 1119 distill-header, 1120 d-title, 1121 d-abstract, 1122 d-article, 1123 d-appendix, 1124 distill-appendix, 1125 d-byline, 1126 d-footnote-list, 1127 d-citation-list, 1128 distill-footer { 1129 grid-template-columns: [screen-start] 1fr [page-start kicker-start] 60px [middle-start] 60px [text-start kicker-end] 60px 60px 60px 60px 60px 60px 60px 60px [text-end gutter-start] 60px [middle-end] 60px [page-end gutter-end] 1fr [screen-end]; 1130 grid-column-gap: 32px; 1131 } 1132 1133 .grid { 1134 grid-column-gap: 32px; 1135 } 1136 } 1137 1138 1139 /* Get the citation styles for the appendix (not auto-injected on render since 1140 we do our own rendering of the citation appendix) */ 1141 1142 d-appendix .citation-appendix, 1143 .d-appendix .citation-appendix { 1144 font-size: 11px; 1145 line-height: 15px; 1146 border-left: 1px solid rgba(0, 0, 0, 0.1); 1147 padding-left: 18px; 1148 border: 1px solid rgba(0,0,0,0.1); 1149 background: rgba(0, 0, 0, 0.02); 1150 padding: 10px 18px; 1151 border-radius: 3px; 1152 color: rgba(150, 150, 150, 1); 1153 overflow: hidden; 1154 margin-top: -12px; 1155 white-space: pre-wrap; 1156 word-wrap: break-word; 1157 } 1158 1159 /* Include appendix styles here so they can be overridden */ 1160 1161 d-appendix { 1162 contain: layout style; 1163 font-size: 0.8em; 1164 line-height: 1.7em; 1165 margin-top: 60px; 1166 margin-bottom: 0; 1167 border-top: 1px solid rgba(0, 0, 0, 0.1); 1168 color: rgba(0,0,0,0.5); 1169 padding-top: 60px; 1170 padding-bottom: 48px; 1171 } 1172 1173 d-appendix h3 { 1174 grid-column: page-start / text-start; 1175 font-size: 15px; 1176 font-weight: 500; 1177 margin-top: 1em; 1178 margin-bottom: 0; 1179 color: rgba(0,0,0,0.65); 1180 } 1181 1182 d-appendix h3 + * { 1183 margin-top: 1em; 1184 } 1185 1186 d-appendix ol { 1187 padding: 0 0 0 15px; 1188 } 1189 1190 @media (min-width: 768px) { 1191 d-appendix ol { 1192 padding: 0 0 0 30px; 1193 margin-left: -30px; 1194 } 1195 } 1196 1197 d-appendix li { 1198 margin-bottom: 1em; 1199 } 1200 1201 d-appendix a { 1202 color: rgba(0, 0, 0, 0.6); 1203 } 1204 1205 d-appendix > * { 1206 grid-column: text; 1207 } 1208 1209 d-appendix > d-footnote-list, 1210 d-appendix > d-citation-list, 1211 d-appendix > distill-appendix { 1212 grid-column: screen;
1213 } 1214 1215 /* Include footnote styles here so they can be overridden */ 1216 1217 d-footnote-list { 1218 contain: layout style; 1219 } 1220 1221 d-footnote-list > * { 1222 grid-column: text; 1223 } 1224 1225 d-footnote-list a.footnote-backlink { 1226 color: rgba(0,0,0,0.3); 1227 padding-left: 0.5em; 1228 } 1229 1230 1231 1232 /* Anchor.js */ 1233 1234 .anchorjs-link { 1235 /*transition: all .25s linear; */ 1236 text-decoration: none; 1237 border-bottom: none; 1238 } 1239 *:hover > .anchorjs-link { 1240 margin-left: -1.125em !important; 1241 text-decoration: none; 1242 border-bottom: none; 1243 } 1244 1245 /* Social footer */ 1246 1247 .social_footer { 1248 margin-top: 30px; 1249 margin-bottom: 0; 1250 color: rgba(0,0,0,0.67); 1251 } 1252 1253 .disqus-comments { 1254 margin-right: 30px; 1255 } 1256 1257 .disqus-comment-count { 1258 border-bottom: 1px solid rgba(0, 0, 0, 0.4); 1259 cursor: pointer; 1260 } 1261 1262 #disqus_thread { 1263 margin-top: 30px; 1264 } 1265 1266 .article-sharing a { 1267 border-bottom: none; 1268 margin-right: 8px; 1269 } 1270 1271 .article-sharing a:hover { 1272 border-bottom: none; 1273 } 1274 1275 .sidebar-section.subscribe { 1276 font-size: 12px; 1277 line-height: 1.6em; 1278 } 1279 1280 .subscribe p { 1281 margin-bottom: 0.5em; 1282 } 1283 1284 1285 .article-footer .subscribe { 1286 font-size: 15px; 1287 margin-top: 45px; 1288 } 1289 1290 1291 .sidebar-section.custom { 1292 font-size: 12px; 1293 line-height: 1.6em; 1294 } 1295 1296 .custom p { 1297 margin-bottom: 0.5em; 1298 } 1299 1300 /* Styles for listing layout (hide title) */ 1301 .layout-listing d-title, .layout-listing .d-title { 1302 display: none; 1303 } 1304 1305 /* Styles for posts lists (not auto-injected) */ 1306 1307 1308 .posts-with-sidebar { 1309 padding-left: 45px; 1310 padding-right: 45px; 1311 } 1312 1313 .posts-list .description h2, 1314 .posts-list .description p { 1315 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; 1316 } 1317 1318 .posts-list .description h2 { 1319 font-weight: 700; 1320 border-bottom: none; 1321 padding-bottom: 0; 1322 } 1323 1324 .posts-list h2.post-tag { 1325 border-bottom: 1px solid rgba(0, 0, 0, 0.2); 1326 padding-bottom: 12px; 1327 } 1328 .posts-list { 1329 margin-top: 60px; 1330 margin-bottom: 24px; 1331 } 1332 1333 .posts-list .post-preview { 1334 text-decoration: none; 1335 overflow: hidden; 1336 display: block; 1337 border-bottom: 1px solid rgba(0, 0, 0, 0.1); 1338 padding: 24px 0; 1339 } 1340 1341 .post-preview-last { 1342 border-bottom: none !important; 1343 } 1344 1345 .posts-list .posts-list-caption { 1346 grid-column: screen; 1347 font-weight: 400; 1348 } 1349 1350 .posts-list .post-preview h2 { 1351 margin: 0 0 6px 0; 1352 line-height: 1.2em; 1353 font-style: normal; 1354 font-size: 24px; 1355 } 1356 1357 .posts-list .post-preview p { 1358 margin: 0 0 12px 0; 1359 line-height: 1.4em; 1360 font-size: 16px; 1361 } 1362 1363 .posts-list .post-preview .thumbnail { 1364 box-sizing: border-box; 1365 margin-bottom: 24px; 1366 position: relative; 1367 max-width: 500px; 1368 } 1369 .posts-list .post-preview img { 1370 width: 100%; 1371 display: block; 1372 } 1373 1374 .posts-list .metadata { 1375 font-size: 12px; 1376 line-height: 1.4em; 1377 margin-bottom: 18px; 1378 } 1379 1380 .posts-list .metadata > * { 1381 display: inline-block; 1382 } 1383 1384 .posts-list .metadata .publishedDate { 1385 margin-right: 2em; 1386 } 1387 1388 .posts-list .metadata .dt-authors { 1389 display: block; 1390 margin-top: 0.3em; 1391 margin-right: 2em; 1392 } 1393 1394 .posts-list .dt-tags { 1395 display: block; 1396 line-height: 1em; 1397 } 1398 1399 .posts-list .dt-tags .dt-tag { 1400 display: inline-block; 1401 color: rgba(0,0,0,0.6); 1402 padding: 0.3em 0.4em; 1403 margin-right: 0.2em; 1404 margin-bottom: 0.4em; 1405 font-size: 60%; 1406 border: 1px solid rgba(0,0,0,0.2); 1407 border-radius: 3px; 1408 text-transform: uppercase; 1409 font-weight: 500; 1410 } 1411 1412 .posts-list img { 1413 opacity: 1; 1414 } 1415 1416 .posts-list img[data-src] { 1417 opacity: 0; 1418 } 1419 1420 .posts-more { 1421 clear: both; 1422 } 1423 1424 1425 .posts-sidebar { 1426 font-size: 16px; 1427 } 1428 1429 .posts-sidebar h3 { 1430 font-size: 16px; 1431 margin-top: 0; 1432 margin-bottom: 0.5em; 1433 font-weight: 400; 1434 text-transform: uppercase; 1435 } 1436 1437 .sidebar-section { 1438 margin-bottom: 30px; 1439 } 1440 1441 .categories ul { 1442 list-style-type: none; 1443 margin: 0; 1444 padding: 0; 1445 } 1446 1447 .categories li { 1448 color: rgba(0, 0, 0, 0.8); 1449 margin-bottom: 0; 1450 } 1451 1452 .categories li>a { 1453 border-bottom: none; 1454 } 1455 1456 .categories li>a:hover { 1457 border-bottom: 1px solid rgba(0, 0, 0, 0.4); 1458 } 1459 1460 .categories .active { 1461 font-weight: 600; 1462 } 1463 1464 .categories .category-count { 1465 color: rgba(0, 0, 0, 0.4); 1466 } 1467 1468 1469 @media(min-width: 768px) { 1470 .posts-list .post-preview h2 { 1471 font-size: 26px; 1472 } 1473 .posts-list .post-preview .thumbnail { 1474 float: right; 1475 width: 30%; 1476 margin-bottom: 0; 1477 } 1478 .posts-list .post-preview .description { 1479 float: left; 1480 width: 45%; 1481 } 1482 .posts-list .post-preview .metadata { 1483 float: left; 1484 width: 20%; 1485 margin-top: 8px; 1486 } 1487 .posts-list .post-preview p { 1488 margin: 0 0 12px 0; 1489 line-height: 1.5em; 1490 font-size: 16px; 1491 } 1492 .posts-with-sidebar .posts-list { 1493 float: left; 1494 width: 75%; 1495 } 1496 .posts-with-sidebar .posts-sidebar { 1497 float: right; 1498 width: 20%; 1499 margin-top: 60px; 1500 padding-top: 24px; 1501 padding-bottom: 24px; 1502 } 1503 } 1504 1505 1506 /* Improve display for browsers without grid (IE/Edge <= 15) */ 1507 1508 .downlevel { 1509 line-height: 1.6em; 1510 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; 1511 margin: 0; 1512 } 1513 1514 .downlevel .d-title { 1515 padding-top: 6rem; 1516 padding-bottom: 1.5rem; 1517 } 1518 1519 .downlevel .d-title h1 { 1520 font-size: 50px; 1521 font-weight: 700; 1522 line-height: 1.1em; 1523 margin: 0 0 0.5rem; 1524 } 1525 1526 .downlevel .d-title p { 1527 font-weight: 300; 1528 font-size: 1.2rem; 1529 line-height: 1.55em; 1530 margin-top: 0;
1531 } 1532 1533 .downlevel .d-byline { 1534 padding-top: 0.8em; 1535 padding-bottom: 0.8em; 1536 font-size: 0.8rem; 1537 line-height: 1.8em; 1538 } 1539 1540 .downlevel .section-separator { 1541 border: none; 1542 border-top: 1px solid rgba(0, 0, 0, 0.1); 1543 } 1544 1545 .downlevel .d-article { 1546 font-size: 1.06rem; 1547 line-height: 1.7em; 1548 padding-top: 1rem; 1549 padding-bottom: 2rem; 1550 } 1551 1552 1553 .downlevel .d-appendix { 1554 padding-left: 0; 1555 padding-right: 0; 1556 max-width: none; 1557 font-size: 0.8em; 1558 line-height: 1.7em; 1559 margin-bottom: 0; 1560 color: rgba(0,0,0,0.5); 1561 padding-top: 40px; 1562 padding-bottom: 48px; 1563 } 1564 1565 .downlevel .footnotes ol { 1566 padding-left: 13px; 1567 } 1568 1569 .downlevel .base-grid, 1570 .downlevel .distill-header, 1571 .downlevel .d-title, 1572 .downlevel .d-abstract, 1573 .downlevel .d-article, 1574 .downlevel .d-appendix, 1575 .downlevel .distill-appendix, 1576 .downlevel .d-byline, 1577 .downlevel .d-footnote-list, 1578 .downlevel .d-citation-list, 1579 .downlevel .distill-footer, 1580 .downlevel .appendix-bottom, 1581 .downlevel .posts-container { 1582 padding-left: 40px; 1583 padding-right: 40px; 1584 } 1585 1586 @media(min-width: 768px) { 1587 .downlevel .base-grid, 1588 .downlevel .distill-header, 1589 .downlevel .d-title, 1590 .downlevel .d-abstract, 1591 .downlevel .d-article, 1592 .downlevel .d-appendix, 1593 .downlevel .distill-appendix, 1594 .downlevel .d-byline, 1595 .downlevel .d-footnote-list, 1596 .downlevel .d-citation-list, 1597 .downlevel .distill-footer, 1598 .downlevel .appendix-bottom, 1599 .downlevel .posts-container { 1600 padding-left: 150px; 1601 padding-right: 150px; 1602 max-width: 900px; 1603 } 1604 } 1605 1606 .downlevel pre code { 1607 display: block; 1608 border-left: 2px solid rgba(0, 0, 0, .1); 1609 padding: 0 0 0 20px; 1610 font-size: 14px; 1611 } 1612 1613 .downlevel code, .downlevel pre { 1614 color: black; 1615 background: none; 1616 font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 1617 text-align: left; 1618 white-space: pre; 1619 word-spacing: normal; 1620 word-break: normal; 1621 word-wrap: normal; 1622 line-height: 1.5; 1623 1624 -moz-tab-size: 4; 1625 -o-tab-size: 4; 1626 tab-size: 4; 1627 1628 -webkit-hyphens: none; 1629 -moz-hyphens: none; 1630 -ms-hyphens: none; 1631 hyphens: none; 1632 } 1633 1634 .downlevel .posts-list .post-preview { 1635 color: inherit; 1636 } 1637 1638 1639 1640 </style> 1641 1642
1642<script type="application/javascript"> 1643 1644 function is_downlevel_browser() { 1645 if (bowser.isUnsupportedBrowser({ msie: "12", msedge: "16"}, 1646 window.navigator.userAgent)) { 1647 return true; 1648 } else { 1649 return window.load_distill_framework === undefined; 1650 } 1651 } 1652 1653 // show body when load is complete 1654 function on_load_complete() { 1655 1656 // add anchors 1657 if (window.anchors) { 1658 window.anchors.options.placement = 'left'; 1659 window.anchors.add('d-article > h2, d-article > h3, d-article > h4, d-article > h5'); 1660 } 1661 1662 1663 // set body to visible 1664 document.body.style.visibility = 'visible'; 1665 1666 // force redraw for leaflet widgets 1667 if (window.HTMLWidgets) { 1668 var maps = window.HTMLWidgets.findAll(".leaflet"); 1669 $.each(maps, function(i, el) { 1670 var map = this.getMap(); 1671 map.invalidateSize(); 1672 map.eachLayer(function(layer) { 1673 if (layer instanceof L.TileLayer) 1674 layer.redraw(); 1675 }); 1676 }); 1677 } 1678 1679 // trigger 'shown' so htmlwidgets resize 1680 $('d-article').trigger('shown'); 1681 } 1682 1683 function init_distill() { 1684 1685 init_common(); 1686 1687 // create front matter 1688 var front_matter = $('<d-front-matter></d-front-matter>'); 1689 $('#distill-front-matter').wrap(front_matter); 1690 1691 // create d-title 1692 $('.d-title').changeElementType('d-title'); 1693 1694 // create d-byline 1695 var byline = $('<d-byline></d-byline>'); 1696 $('.d-byline').replaceWith(byline); 1697 1698 // create d-article 1699 var article = $('<d-article></d-article>'); 1700 $('.d-article').wrap(article).children().unwrap(); 1701 1702 // move posts container into article 1703 $('.posts-container').appendTo($('d-article')); 1704 1705 // create d-appendix 1706 $('.d-appendix').changeElementType('d-appendix'); 1707 1708 // flag indicating that we have appendix items 1709 var appendix = $('.appendix-bottom').children('h3').length > 0; 1710 1711 // replace footnotes with <d-footnote> 1712 $('.footnote-ref').each(function(i, val) { 1713 appendix = true; 1714 var href = $(this).attr('href'); 1715 var id = href.replace('#', ''); 1716 var fn = $('#' + id); 1717 var fn_p = $('#' + id + '>p'); 1718 fn_p.find('.footnote-back').remove(); 1719 var text = fn_p.html(); 1720 var dtfn = $('<d-footnote></d-footnote>'); 1721 dtfn.html(text); 1722 $(this).replaceWith(dtfn); 1723 }); 1724 // remove footnotes 1725 $('.footnotes').remove(); 1726 1727 // move refs into #references-listing 1728 $('#references-listing').replaceWith($('#refs')); 1729 1730 $('h1.appendix, h2.appendix').each(function(i, val) { 1731 $(this).changeElementType('h3'); 1732 }); 1733 $('h3.appendix').each(function(i, val) { 1734 var id = $(this).attr('id'); 1735 $('.d-contents a[href="#' + id + '"]').parent().remove(); 1736 appendix = true; 1737 $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('d-appendix')); 1738 }); 1739 1740 // show d-appendix if we have appendix content 1741 $("d-appendix").css('display', appendix ? 'grid' : 'none'); 1742 1743 // localize layout chunks to just output 1744 $('.layout-chunk').each(function(i, val) { 1745 1746 // capture layout 1747 var layout = $(this).attr('data-layout'); 1748 1749 // apply layout to markdown level block elements 1750 var elements = $(this).children().not('details, div.sourceCode, pre, script'); 1751 elements.each(function(i, el) { 1752 var layout_div = $('<div class="' + layout + '"></div>'); 1753 if (layout_div.hasClass('shaded')) { 1754 var shaded_content = $('<div class="shaded-content"></div>'); 1755 $(this).wrap(shaded_content); 1756 $(this).parent().wrap(layout_div); 1757 } else { 1758 $(this).wrap(layout_div); 1759 } 1760 }); 1761 1762 1763 // unwrap the layout-chunk div 1764 $(this).children().unwrap(); 1765 }); 1766 1767 // remove code block used to force highlighting css 1768 $('.distill-force-highlighting-css').parent().remove(); 1769 1770 // remove empty line numbers inserted by pandoc when using a 1771 // custom syntax highlighting theme 1772 $('code.sourceCode a:empty').remove(); 1773 1774 // load distill framework 1775 load_distill_framework(); 1776 1777 // wait for window.distillRunlevel == 4 to do post processing 1778 function distill_post_process() { 1779 1780 if (!window.distillRunlevel || window.distillRunlevel < 4) 1781 return; 1782 1783 // hide author/affiliations entirely if we have no authors 1784 var front_matter = JSON.parse($("#distill-front-matter").html()); 1785 var have_authors = front_matter.authors && front_matter.authors.length > 0;
1786 if (!have_authors) 1787 $('d-byline').addClass('hidden'); 1788 1789 // article with toc class 1790 $('.d-contents').parent().addClass('d-article-with-toc'); 1791 1792 // strip links that point to # 1793 $('.authors-affiliations').find('a[href="#"]').removeAttr('href'); 1794 1795 // add orcid ids 1796 $('.authors-affiliations').find('.author').each(function(i, el) { 1797 var orcid_id = front_matter.authors[i].orcidID; 1798 if (orcid_id) { 1799 var a = $('<a></a>'); 1800 a.attr('href', 'https://orcid.org/' + orcid_id); 1801 var img = $('<img></img>'); 1802 img.addClass('orcid-id'); 1803 img.attr('alt', 'ORCID ID'); 1804 img.attr('src','data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=='); 1805 a.append(img); 1806 $(this).append(a); 1807 } 1808 }); 1809 1810 // hide elements of author/affiliations grid that have no value 1811 function hide_byline_column(caption) { 1812 $('d-byline').find('h3:contains("' + caption + '")').parent().css('visibility', 'hidden'); 1813 } 1814 1815 // affiliations 1816 var have_affiliations = false; 1817 for (var i = 0; i<front_matter.authors.length; ++i) { 1818 var author = front_matter.authors[i]; 1819 if (author.affiliation !== " ") { 1820 have_affiliations = true; 1821 break; 1822 } 1823 } 1824 if (!have_affiliations) 1825 $('d-byline').find('h3:contains("Affiliations")').css('visibility', 'hidden'); 1826 1827 // published date 1828 if (!front_matter.publishedDate) 1829 hide_byline_column("Published"); 1830 1831 // document object identifier 1832 var doi = $('d-byline').find('h3:contains("DOI")'); 1833 var doi_p = doi.next().empty(); 1834 if (!front_matter.doi) { 1835 // if we have a citation and valid citationText then link to that 1836 if ($('#citation').length > 0 && front_matter.citationText) { 1837 doi.html('Citation'); 1838 $('<a href="#citation"></a>') 1839 .text(front_matter.citationText) 1840 .appendTo(doi_p); 1841 } else { 1842 hide_byline_column("DOI"); 1843 } 1844 } else { 1845 $('<a></a>') 1846 .attr('href', "https://doi.org/" + front_matter.doi) 1847 .html(front_matter.doi) 1848 .appendTo(doi_p); 1849 } 1850 1851 // change plural form of authors/affiliations 1852 if (front_matter.authors.length === 1) { 1853 var grid = $('.authors-affiliations'); 1854 grid.children('h3:contains("Authors")').text('Author'); 1855 grid.children('h3:contains("Affiliations")').text('Affiliation'); 1856 } 1857 1858 // remove d-appendix and d-footnote-list local styles 1859 $('d-appendix > style:first-child').remove(); 1860 $('d-footnote-list > style:first-child').remove(); 1861 1862 // move appendix-bottom entries to the bottom 1863 $('.appendix-bottom').appendTo('d-appendix').children().unwrap(); 1864 $('.appendix-bottom').remove(); 1865 1866 // hoverable references 1867 $('span.citation[data-cites]').each(function() { 1868 if ($(this).children()[0].nodeName == "D-FOOTNOTE") { 1869 var fn = $(this).children()[0] 1870 $(this).html(fn.shadowRoot.querySelector("sup")) 1871 $(this).id = fn.id 1872 fn.remove() 1873 } 1874 var refs = $(this).attr('data-cites').split(" "); 1875 var refHtml = refs.map(function(ref) { 1876 return "<p>" + $('#ref-' + ref).html() + "</p>"; 1877 }).join("\n"); 1878 window.tippy(this, { 1879 allowHTML: true, 1880 content: refHtml, 1881 maxWidth: 500, 1882 interactive: true, 1883 interactiveBorder: 10, 1884 theme: 'light-border', 1885 placement: 'bottom-start' 1886 }); 1887 }); 1888 1889 // fix footnotes in tables (#411) 1890 // replacing broken distill.pub feature 1891 $('table d-footnote').each(function() { 1892 // we replace internal showAtNode methode which is triggered when hovering a footnote
1893 this.hoverBox.showAtNode = function(node) { 1894 // ported from https://github.com/distillpub/template/pull/105/files 1895 calcOffset = function(elem) { 1896 let x = elem.offsetLeft; 1897 let y = elem.offsetTop; 1898 // Traverse upwards until an `absolute` element is found or `elem` 1899 // becomes null. 1900 while (elem = elem.offsetParent && elem.style.position != 'absolute') { 1901 x += elem.offsetLeft; 1902 y += elem.offsetTop; 1903 } 1904 1905 return { left: x, top: y }; 1906 } 1907 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetTop 1908 const bbox = node.getBoundingClientRect(); 1909 const offset = calcOffset(node); 1910 this.show([offset.left + bbox.width, offset.top + bbox.height]); 1911 } 1912 }) 1913 1914 // clear polling timer 1915 clearInterval(tid); 1916 1917 // show body now that everything is ready 1918 on_load_complete(); 1919 } 1920 1921 var tid = setInterval(distill_post_process, 50); 1922 distill_post_process(); 1923 1924 } 1925 1926 function init_downlevel() { 1927 1928 init_common(); 1929 1930 // insert hr after d-title 1931 $('.d-title').after($('<hr class="section-separator"/>')); 1932 1933 // check if we have authors 1934 var front_matter = JSON.parse($("#distill-front-matter").html()); 1935 var have_authors = front_matter.authors && front_matter.authors.length > 0; 1936
1937 // manage byline/border 1938 if (!have_authors) 1939 $('.d-byline').remove(); 1940 $('.d-byline').after($('<hr class="section-separator"/>')); 1941 $('.d-byline a').remove(); 1942 1943 // remove toc 1944 $('.d-contents').remove(); 1945 1946 // move appendix elements 1947 $('h1.appendix, h2.appendix').each(function(i, val) { 1948 $(this).changeElementType('h3'); 1949 }); 1950 $('h3.appendix').each(function(i, val) { 1951 $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('.d-appendix')); 1952 }); 1953 1954 1955 // inject headers into references and footnotes 1956 var refs_header = $('<h3></h3>'); 1957 refs_header.text('References'); 1958 $('#refs').prepend(refs_header); 1959 1960 var footnotes_header = $('<h3></h3'); 1961 footnotes_header.text('Footnotes'); 1962 $('.footnotes').children('hr').first().replaceWith(footnotes_header); 1963 1964 // move appendix-bottom entries to the bottom 1965 $('.appendix-bottom').appendTo('.d-appendix').children().unwrap(); 1966 $('.appendix-bottom').remove(); 1967 1968 // remove appendix if it's empty 1969 if ($('.d-appendix').children().length === 0) 1970 $('.d-appendix').remove(); 1971 1972 // prepend separator above appendix 1973 $('.d-appendix').before($('<hr class="section-separator" style="clear: both"/>')); 1974 1975 // trim code 1976 $('pre>code').each(function(i, val) { 1977 $(this).html($.trim($(this).html())); 1978 }); 1979 1980 // move posts-container right before article 1981 $('.posts-container').insertBefore($('.d-article')); 1982 1983 $('body').addClass('downlevel'); 1984 1985 on_load_complete(); 1986 } 1987 1988 1989 function init_common() { 1990 1991 // jquery plugin to change element types 1992 (function($) { 1993 $.fn.changeElementType = function(newType) { 1994 var attrs = {}; 1995 1996 $.each(this[0].attributes, function(idx, attr) { 1997 attrs[attr.nodeName] = attr.nodeValue; 1998 }); 1999 2000 this.replaceWith(function() { 2001 return $("<" + newType + "/>", attrs).append($(this).contents()); 2002 }); 2003 }; 2004 })(jQuery); 2005 2006 // prevent underline for linked images 2007 $('a > img').parent().css({'border-bottom' : 'none'}); 2008 2009 // mark non-body figures created by knitr chunks as 100% width 2010 $('.layout-chunk').each(function(i, val) { 2011 var figures = $(this).find('img, .html-widget'); 2012 // ignore leaflet img layers (#106) 2013 figures = figures.filter(':not(img[class*="leaflet"])') 2014 if ($(this).attr('data-layout') !== "l-body") { 2015 figures.css('width', '100%'); 2016 } else { 2017 figures.css('max-width', '100%'); 2018 figures.filter("[width]").each(function(i, val) { 2019 var fig = $(this); 2020 fig.css('width', fig.attr('width') + 'px'); 2021 }); 2022 2023 } 2024 }); 2025 2026 // auto-append index.html to post-preview links in file: protocol 2027 // and in rstudio ide preview 2028 $('.post-preview').each(function(i, val) { 2029 if (window.location.protocol === "file:") 2030 $(this).attr('href', $(this).attr('href') + "index.html"); 2031 }); 2032 2033 // get rid of index.html references in header 2034 if (window.location.protocol !== "file:") { 2035 $('.distill-site-header a[href]').each(function(i,val) { 2036 $(this).attr('href', $(this).attr('href').replace(/^index[.]html/, "./")); 2037 }); 2038 } 2039 2040 // add class to pandoc style tables 2041 $('tr.header').parent('thead').parent('table').addClass('pandoc-table'); 2042 $('.kable-table').children('table').addClass('pandoc-table'); 2043 2044 // add figcaption style to table captions 2045 $('caption').parent('table').addClass("figcaption"); 2046 2047 // initialize posts list 2048 if (window.init_posts_list) 2049 window.init_posts_list(); 2050 2051 // implmement disqus comment link 2052 $('.disqus-comment-count').click(function() { 2053 window.headroom_prevent_pin = true; 2054 $('#disqus_thread').toggleClass('hidden'); 2055 if (!$('#disqus_thread').hasClass('hidden')) { 2056 var offset = $(this).offset(); 2057 $(window).resize(); 2058 $('html, body').animate({ 2059 scrollTop: offset.top - 35 2060 }); 2061 } 2062 }); 2063 } 2064 2065 document.addEventListener('DOMContentLoaded', function() { 2066 if (is_downlevel_browser()) 2067 init_downlevel(); 2068 else 2069 window.addEventListener('WebComponentsReady', init_distill); 2070 }); 2071 2072 </script>
2072 2073 2074 <style type="text/css"> 2075 /* base variables */ 2076 2077 /* Edit the CSS properties in this file to create a custom 2078 Distill theme. Only edit values in the right column 2079 for each row; values shown are the CSS defaults. 2080 To return any property to the default, 2081 you may set its value to: unset 2082 All rows must end with a semi-colon. */ 2083 2084 /* Optional: embed custom fonts here with `@import` */ 2085 /* This must remain at the top of this file. */ 2086 2087 2088 2089 html { 2090 /*-- Main font sizes --*/ 2091 --title-size: 50px; 2092 --body-size: 1.06rem; 2093 --code-size: 14px; 2094 --aside-size: 12px; 2095 --fig-cap-size: 13px; 2096 /*-- Main font colors --*/ 2097 --title-color: #000000; 2098 --header-color: rgba(0, 0, 0, 0.8); 2099 --body-color: rgba(0, 0, 0, 0.8); 2100 --aside-color: rgba(0, 0, 0, 0.6); 2101 --fig-cap-color: rgba(0, 0, 0, 0.6); 2102 /*-- Specify custom fonts ~~~ must be imported above --*/ 2103 --heading-font: sans-serif; 2104 --mono-font: monospace; 2105 --body-font: sans-serif; 2106 --navbar-font: sans-serif; /* websites + blogs only */ 2107 } 2108 2109 /*-- ARTICLE METADATA --*/ 2110 d-byline { 2111 --heading-size: 0.6rem; 2112 --heading-color: rgba(0, 0, 0, 0.5); 2113 --body-size: 0.8rem; 2114 --body-color: rgba(0, 0, 0, 0.8); 2115 } 2116 2117 /*-- ARTICLE TABLE OF CONTENTS --*/ 2118 .d-contents { 2119 --heading-size: 18px; 2120 --contents-size: 13px; 2121 } 2122 2123 /*-- ARTICLE APPENDIX --*/ 2124 d-appendix { 2125 --heading-size: 15px; 2126 --heading-color: rgba(0, 0, 0, 0.65); 2127 --text-size: 0.8em; 2128 --text-color: rgba(0, 0, 0, 0.5); 2129 } 2130 2131 /*-- WEBSITE HEADER + FOOTER --*/ 2132 /* These properties only apply to Distill sites and blogs */ 2133 2134 .distill-site-header { 2135 --title-size: 18px; 2136 --text-color: rgba(255, 255, 255, 0.8); 2137 --text-size: 15px; 2138 --hover-color: white; 2139 --bkgd-color: #0F2E3D; 2140 } 2141 2142 .distill-site-footer { 2143 --text-color: rgba(255, 255, 255, 0.8); 2144 --text-size: 15px; 2145 --hover-color: white; 2146 --bkgd-color: #0F2E3D; 2147 } 2148 2149 /*-- Additional custom styles --*/ 2150 /* Add any additional CSS rules below */ 2151 </style> 2152 <style type="text/css"> 2153 /* base variables */ 2154 2155 /* Edit the CSS properties in this file to create a custom 2156 Distill theme. Only edit values in the right column 2157 for each row; values shown are the CSS defaults. 2158 To return any property to the default, 2159 you may set its value to: unset 2160 All rows must end with a semi-colon. */ 2161 2162 /* Optional: embed custom fonts here with `@import` */ 2163 /* This must remain at the top of this file. */ 2164 2165 2166 2167 html { 2168 /*-- Main font sizes --*/ 2169 --title-size: 50px; 2170 --body-size: 1.06rem; 2171 --code-size: 14px; 2172 --aside-size: 12px; 2173 --fig-cap-size: 13px;
2174 /*-- Main font colors --*/ 2175 --title-color: #000000; 2176 --header-color: rgba(0, 0, 0, 0.8); 2177 --body-color: rgba(0, 0, 0, 0.8); 2178 --aside-color: rgba(0, 0, 0, 0.6); 2179 --fig-cap-color: rgba(0, 0, 0, 0.6); 2180 /*-- Specify custom fonts ~~~ must be imported above --*/ 2181 --heading-font: sans-serif; 2182 --mono-font: monospace; 2183 --body-font: sans-serif; 2184 --navbar-font: sans-serif; /* websites + blogs only */ 2185 } 2186 2187 /*-- ARTICLE METADATA --*/ 2188 d-byline { 2189 --heading-size: 0.6rem; 2190 --heading-color: rgba(0, 0, 0, 0.5); 2191 --body-size: 0.8rem; 2192 --body-color: rgba(0, 0, 0, 0.8); 2193 } 2194 2195 /*-- ARTICLE TABLE OF CONTENTS --*/ 2196 .d-contents { 2197 --heading-size: 18px; 2198 --contents-size: 13px; 2199 } 2200 2201 /*-- ARTICLE APPENDIX --*/ 2202 d-appendix { 2203 --heading-size: 15px; 2204 --heading-color: rgba(0, 0, 0, 0.65); 2205 --text-size: 0.8em; 2206 --text-color: rgba(0, 0, 0, 0.5); 2207 } 2208 2209 /*-- WEBSITE HEADER + FOOTER --*/ 2210 /* These properties only apply to Distill sites and blogs */ 2211 2212 .distill-site-header { 2213 --title-size: 18px; 2214 --text-color: rgba(255, 255, 255, 0.8); 2215 --text-size: 15px; 2216 --hover-color: white; 2217 --bkgd-color: #0F2E3D; 2218 } 2219 2220 .distill-site-footer { 2221 --text-color: rgba(255, 255, 255, 0.8); 2222 --text-size: 15px; 2223 --hover-color: white; 2224 --bkgd-color: #0F2E3D; 2225 } 2226 2227 /*-- Additional custom styles --*/ 2228 /* Add any additional CSS rules below */ 2229 2230 /* Code chunks */ 2231 2232 d-article pre { /* Chunk output */ 2233 border-radius: 5px; /* Rounded edges */ 2234 font-size: 12px; 2235 color: black; 2236 background-color: #c1daf0; 2237 padding: 5px 5px 5px 18px; 2238 } 2239 2240 d-article div.sourceCode pre { /* Chunk code */ 2241 border-radius: 5px; /* Rounded edges */ 2242 background-color: #fff2cc; 2243 color: black; 2244 padding: 5px 5px 5px 18px; 2245 } 2246 2247 d-article div.sourceCode { 2248 background-color: transparent; 2249 }</style> 2250 <style type="text/css"> 2251 /* base style */ 2252 2253 /* FONT FAMILIES */ 2254 2255 :root { 2256 --heading-default: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; 2257 --mono-default: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 2258 --body-default: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; 2259 } 2260 2261 body, 2262 .posts-list .post-preview p, 2263 .posts-list .description p { 2264 font-family: var(--body-font), var(--body-default); 2265 } 2266 2267 h1, h2, h3, h4, h5, h6, 2268 .posts-list .post-preview h2, 2269 .posts-list .description h2 { 2270 font-family: var(--heading-font), var(--heading-default); 2271 } 2272 2273 d-article div.sourceCode code, 2274 d-article pre code { 2275 font-family: var(--mono-font), var(--mono-default); 2276 } 2277 2278 2279 /*-- TITLE --*/ 2280 d-title h1, 2281 .posts-list > h1 { 2282 color: var(--title-color, black); 2283 } 2284 2285 d-title h1 { 2286 font-size: var(--title-size, 50px); 2287 } 2288 2289 /*-- HEADERS --*/ 2290 d-article h1, 2291 d-article h2, 2292 d-article h3, 2293 d-article h4, 2294 d-article h5, 2295 d-article h6 { 2296 color: var(--header-color, rgba(0, 0, 0, 0.8)); 2297 } 2298 2299 /*-- BODY --*/ 2300 d-article > p, /* only text inside of <p> tags */ 2301 d-article > ul, /* lists */ 2302 d-article > ol { 2303 color: var(--body-color, rgba(0, 0, 0, 0.8)); 2304 font-size: var(--body-size, 1.06rem); 2305 } 2306 2307 2308 /*-- CODE --*/ 2309 d-article div.sourceCode code, 2310 d-article pre code { 2311 font-size: var(--code-size, 14px); 2312 } 2313 2314 /*-- ASIDE --*/ 2315 d-article aside { 2316 font-size: var(--aside-size, 12px); 2317 color: var(--aside-color, rgba(0, 0, 0, 0.6)); 2318 } 2319 2320 /*-- FIGURE CAPTIONS --*/ 2321 figure .caption, 2322 figure figcaption, 2323 .figure .caption { 2324 font-size: var(--fig-cap-size, 13px); 2325 color: var(--fig-cap-color, rgba(0, 0, 0, 0.6)); 2326 } 2327 2328 /*-- METADATA --*/ 2329 d-byline h3 { 2330 font-size: var(--heading-size, 0.6rem); 2331 color: var(--heading-color, rgba(0, 0, 0, 0.5)); 2332 } 2333 2334 d-byline { 2335 font-size: var(--body-size, 0.8rem); 2336 color: var(--body-color, rgba(0, 0, 0, 0.8)); 2337 } 2338 2339 d-byline a, 2340 d-article d-byline a { 2341 color: var(--body-color, rgba(0, 0, 0, 0.8)); 2342 } 2343 2344 /*-- TABLE OF CONTENTS --*/ 2345 .d-contents nav h3 { 2346 font-size: var(--heading-size, 18px); 2347 } 2348 2349 .d-contents nav a { 2350 font-size: var(--contents-size, 13px); 2351 } 2352 2353 /*-- APPENDIX --*/ 2354 d-appendix h3 { 2355 font-size: var(--heading-size, 15px); 2356 color: var(--heading-color, rgba(0, 0, 0, 0.65)); 2357 } 2358 2359 d-appendix { 2360 font-size: var(--text-size, 0.8em); 2361 color: var(--text-color, rgba(0, 0, 0, 0.5)); 2362 } 2363
2364 d-appendix d-footnote-list a.footnote-backlink { 2365 color: var(--text-color, rgba(0, 0, 0, 0.5)); 2366 } 2367 2368 /*-- WEBSITE HEADER + FOOTER --*/ 2369 .distill-site-header .title { 2370 font-size: var(--title-size, 18px); 2371 font-family: var(--navbar-font), var(--heading-default); 2372 } 2373 2374 .distill-site-header a, 2375 .nav-dropdown .nav-dropbtn { 2376 font-family: var(--navbar-font), var(--heading-default); 2377 } 2378 2379 .nav-dropdown .nav-dropbtn { 2380 color: var(--text-color, rgba(255, 255, 255, 0.8)); 2381 font-size: var(--text-size, 15px); 2382 } 2383 2384 .distill-site-header a:hover, 2385 .nav-dropdown:hover .nav-dropbtn { 2386 color: var(--hover-color, white); 2387 } 2388 2389 .distill-site-header { 2390 font-size: var(--text-size, 15px); 2391 color: var(--text-color, rgba(255, 255, 255, 0.8)); 2392 background-color: var(--bkgd-color, #0F2E3D); 2393 } 2394 2395 .distill-site-footer { 2396 font-size: var(--text-size, 15px); 2397 color: var(--text-color, rgba(255, 255, 255, 0.8)); 2398 background-color: var(--bkgd-color, #0F2E3D); 2399 } 2400 2401 .distill-site-footer a:hover { 2402 color: var(--hover-color, white); 2403 }</style> 2404 <!--/radix_placeholder_distill--> 2405
2405<script src="site_libs/header-attrs-2.14/header-attrs.js"></script>
2405 2406
2406<script src="site_libs/clipboard-1.7.1/clipboard.min.js"></script>
2406 2407 <link href="site_libs/primer-tooltips-1.4.0/build.css" rel="stylesheet" /> 2408 <link href="site_libs/klippy-0.0.0.9500/css/klippy.min.css" rel="stylesheet" /> 2409
2409<script src="site_libs/klippy-0.0.0.9500/js/klippy.min.js"></script>
2409 2410
2410<script src="site_libs/popper-2.6.0/popper.min.js"></script>
2410 2411 <link href="site_libs/tippy-6.2.7/tippy.css" rel="stylesheet" /> 2412 <link href="site_libs/tippy-6.2.7/tippy-light-border.css" rel="stylesheet" /> 2413
2413<script src="site_libs/tippy-6.2.7/tippy.umd.min.js"></script>
2413 2414
2414<script src="site_libs/anchor-4.2.2/anchor.min.js"></script>
2414 2415
2415<script src="site_libs/bowser-1.9.3/bowser.min.js"></script>
2415 2416
2416<script src="site_libs/webcomponents-2.0.0/webcomponents.js"></script>
2416 2417
2417<script src="site_libs/distill-2.2.21/template.v2.js"></script>
2417 2418 <!--radix_placeholder_site_in_header-->
vendor: 116 bytes, lines 2418-2419
2418 2419 <script type="text/javascript" cookie-consent="tracking" async src="https://www.googletagmanager.com/gtag/js?id=
2419G-1RQZJC7E05
vendor: 15 bytes, lines 2419-2420
2419"></script> 2420
2420<script type="text/javascript" cookie-consent="tracking"> 2421
vendor: 136 bytes, lines 2421-2424
2421window.dataLayer = window.dataLayer || []; 2422 function gtag(){dataLayer.push(arguments);} 2423 gtag('js', new Date()); 2424 gtag('config', '
2424G-1RQZJC7E05
vendor: 7 bytes, lines 2424-2425
2424'); 2425
2425</script>
2425 2426 <!--/radix_placeholder_site_in_header--> 2427 2428 2429</head> 2430 2431<body> 2432 2433<!--radix_placeholder_front_matter--> 2434
2435<script id="distill-front-matter" type="text/json"> 2436{"title":"Introduction to Toy Datasets","authors":[{"author":"Cengiz Zopluoglu","authorURL":"#","affiliation":"University of Oregon","affiliationURL":"#","orcidID":""}],"publishedDate":"2022-06-23T00:00:00.000-07:00","citationText":"Zopluoglu, 2022"} 2437</script>
2437 2438 2439<!--/radix_placeholder_front_matter--> 2440<!--radix_placeholder_navigation_before_body--> 2441<header class="header header--fixed" role="banner"> 2442<nav class="distill-site-nav distill-site-header"> 2443<div class="nav-left"> 2444<a class='title' href='/'>Applied Machine Learning for Educational Data Science</a> 2445</div> 2446<div class="nav-right"> 2447<a href='/'>Home</a> 2448<a href='/syllabus'>Syllabus</a> 2449<a href='/schedule'>Schedule</a> 2450<div class="nav-dropdown"> 2451<button class="nav-dropbtn"> 2452Lecture Notes 2453 2454<span class="down-arrow">▾</span> 2455</button> 2456<div class="nav-dropdown-content"> 2457<a href='/lecture-1'>Lecture-1</a> 2458<a href='/lecture-2a'>Lecture-2a</a> 2459<a href='/lecture-2b'>Lecture-2b</a> 2460<a href='/lecture-3a'>Lecture-3a</a> 2461<a href='/lecture-3b'>Lecture-3b</a> 2462<a href='/lecture-4'>Lecture-4</a> 2463<a href='/lecture-5'>Lecture-5</a> 2464<a href='/lecture-6a'>Lecture-6a</a> 2465<a href='/lecture-6b'>Lecture-6b</a> 2466<a href='/lecture-7a'>Lecture-7a</a> 2467<a href='/lecture-7b'>Lecture-7b</a> 2468</div> 2469</div> 2470<div class="nav-dropdown"> 2471<button class="nav-dropbtn"> 2472Kaggle Notebooks 2473 2474<span class="down-arrow">▾</span> 2475</button> 2476<div class="nav-dropdown-content"> 2477<a href="https://www.kaggle.com/code/uocoeeds/week-1-introduction/notebook">Notebook-1</a> 2478<a href="https://www.kaggle.com/code/uocoeeds/lecture-2a-data-preprocessing-i">Notebook-2a</a> 2479<a href="https://www.kaggle.com/code/uocoeeds/lecture-2b-data-preprocessing-ii">Notebook-2b</a> 2480<a href="https://www.kaggle.com/code/uocoeeds/the-recipes-package-demo">The {recipes} demo</a> 2481<a href="https://www.kaggle.com/code/uocoeeds/lecture-3a-overview-of-linear-regression">Notebook-3a</a> 2482<a href="https://www.kaggle.com/code/uocoeeds/lecture-3b-review-of-bias-variance-tradeoff">Notebook-3b</a> 2483<a href="https://www.kaggle.com/code/uocoeeds/building-a-prediction-model-with-cross-validation">Building Linear Models with `caret`</a> 2484<a href="https://www.kaggle.com/code/uocoeeds/lecture-4-regularized-penalized-regression">Notebook-4</a> 2485<a href="https://www.kaggle.com/code/uocoeeds/building-a-ridge-regression-model">Building a Ridge Regression Model</a> 2486<a href="https://www.kaggle.com/code/uocoeeds/building-a-lasso-regression-model">Building a Lasso Regression Model</a> 2487<a href="https://www.kaggle.com/code/uocoeeds/building-a-regression-model-with-elastic-net">
2487Building an Elastic Net Model</a> 2488<a href="https://www.kaggle.com/code/uocoeeds/using-the-prediction-models-for-a-new-text">Using the Existing Models to Predict Outcome for New Observations</a> 2489<a href="https://www.kaggle.com/code/uocoeeds/building-a-logistic-regression-model/notebook">Building a Logistic Regression Model</a> 2490<a href="https://www.kaggle.com/code/uocoeeds/building-a-classification-model-with-ridge-penalty/">Building a Classification Model with Ridge Penalty</a> 2491<a href="https://www.kaggle.com/code/uocoeeds/building-a-classification-model-with-lasso-penalty">Building a Classification Model with Lasso Penalty</a> 2492<a href="https://www.kaggle.com/code/uocoeeds/building-a-classification-model-with-elastic-net">Building a Classification Model with Elastic Net</a> 2493<a href="https://www.kaggle.com/code/uocoeeds/building-a-prediction-model-using-knn">Building a Prediction Model with K-nearest neighbors</a> 2494<a href="https://www.kaggle.com/code/uocoeeds/building-a-classification-model-using-knn">Building a Classification Model with K-nearest neighbors</a> 2495<a href="https://www.kaggle.com/uocoeeds/building-a-prediction-model-using-a-decision-tree">Building a Prediction Model with a Decision Tree</a> 2496<a href="https://www.kaggle.com/code/uocoeeds/building-a-classification-tree-algorithm">Building a Classification Model with a Decision Tree</a> 2497</div> 2498</div> 2499<div class="nav-dropdown"> 2500<button class="nav-dropbtn"> 2501Slides 2502 2503<span class="down-arrow">▾</span> 2504</button> 2505<div class="nav-dropdown-content"> 2506<a href='/slides/slide1'>Week 1</a> 2507<a href='/slides/slide2'>Week 2</a> 2508<a href='/slides/slide3'>Week 3 & 4</a> 2509<a href='/slides/slide4'>Week 5</a> 2510<a href='/slides/slide5'>Week 6 & 7</a> 2511<a href='/slides/slide6a'>Week 8_Part 1</a> 2512<a href='/slides/slide6b'>Week 8_Part 2</a> 2513</div> 2514</div> 2515<div class="nav-dropdown"> 2516<button class="nav-dropbtn"> 2517Assignments 2518 2519<span class="down-arrow">▾</span> 2520</button> 2521<div class="nav-dropdown-content"> 2522<a href="https://www.kaggle.com/code/uocoeeds/assignment-1">Assignment1</a> 2523<a href="https://www.kaggle.com/code/uocoeeds/assignment-2">Assignment2</a> 2524<a href="https://www.kaggle.com/code/uocoeeds/assignment-3">Assignment3</a> 2525</div> 2526</div> 2527<a href="https://github.com/uo-datasci-specialization/c4-ml-fall-2022"> 2528<i class="fa fa-github" aria-hidden="true"></i> 2529</a> 2530<a href="javascript:void(0);" class="nav-toggle">☰</a> 2531</div> 2532</nav> 2533</header> 2534<!--/radix_placeholder_navigation_before_body--> 2535<!--radix_placeholder_site_before_body--> 2536<!--/radix_placeholder_site_before_body--> 2537 2538<div class="d-title"> 2539<h1>Introduction to Toy Datasets</h1> 2540<!--radix_placeholder_categories--> 2541<!--/radix_placeholder_categories--> 2542 2543</div> 2544 2545<div class="d-byline"> 2546 Cengiz Zopluoglu (University of Oregon) 2547 2548<br/>06/23/2022 2549</div> 2550 2551<div class="d-article"> 2552<div class="d-contents d-contents-float"> 2553<nav class="l-text toc figcaption" id="TOC"> 2554<h3>Contents</h3> 2555<ul> 2556<li><a href="#readability" id="toc-readability">Readability</a></li> 2557<li><a href="#recidivism" id="toc-recidivism">Recidivism</a></li> 2558<li><a href="#installing-reticulate-miniconda-and-sentence-transformers" 2559id="toc-installing-reticulate-miniconda-and-sentence-transformers">Installing 2560Reticulate, Miniconda, and Sentence Transformers</a></li> 2561</ul> 2562</nav> 2563</div> 2564<div class="layout-chunk" data-layout="l-body">
2565<script> 2566 addClassKlippyTo("pre.r, pre.markdown"); 2567 addKlippy('right', 'top', 'auto', '1', 'Copy code', 'Copied!'); 2568</script>
2568 2569</div> 2570<style> 2571.list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover { 2572 z-index: 2; 2573 color: #fff; 2574 background-color: #FC4445; 2575 border-color: #97CAEF; 2576} 2577 2578</style> 2579<p>[Updated: Sun, Nov 27, 2022 - 14:03:44 ]</p> 2580<p>There are two datasets we will use throughout this course. The first 2581dataset has a continuous outcome and the second dataset has a binary 2582outcome. We will apply several methods and algorithms to these two 2583datasets during the course. We will have an opportunity to compare and 2584contrast the prediction outcomes from several models and methods on the 2585same datasets.</p> 2586<p>This section provides some background information and context for 2587these two datasets.</p> 2588<h1 id="readability">Readability</h1> 2589<p>The readability dataset comes from a recent <a 2590href="https://www.kaggle.com/c/commonlitreadabilityprize/">Kaggle 2591Competition (CommonLit Readability Prize)</a>. You can directly download 2592the training dataset from the competition website, or you can import it 2593from the course website.</p> 2594<div class="layout-chunk" data-layout="l-body"> 2595<div class="sourceCode"> 2596<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>readability</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>'data/readability.csv'</span><span class='op'>)</span>,header<span class='op'>=</span><span class='cn'>TRUE</span><span class='op'>)</span></span> 2597<span></span> 2598<span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>readability</span><span class='op'>)</span></span></code></pre> 2599</div> 2600<pre><code>'data.frame': 2834 obs. of 6 variables: 2601 $ id : chr "c12129c31" "85aa80a4c" "b69ac6792" "dd1000b26" ... 2602 $ url_legal : chr "" "" "" "" ... 2603 $ license : chr "" "" "" "" ... 2604 $ excerpt : chr "When the young people returned to the ballroom, it presented a decidedly changed appearance. Instead of an inte"| __truncated__ "All through dinner time, Mrs. Fayre was somewhat silent, her eyes resting on Dolly with a wistful, uncertain ex"| __truncated__ "As Roger had predicted, the snow departed as quickly as it came, and two days after their sleigh ride there was"| __truncated__ "And outside before the palace a great garden was walled round, filled full of stately fruit-trees, gray olives "| __truncated__ ... 2605 $ target : num -0.34 -0.315 -0.58 -1.054 0.247 ... 2606 $ standard_error: num 0.464 0.481 0.477 0.45 0.511 ...</code></pre> 2607</div> 2608<p>There is a total of 2834 observations. Each observation represents a 2609reading passage. The most significant variables are the 2610<code>excerpt</code> and <code>target</code> columns. The excerpt column 2611includes plain text data, and the target column includes a corresponding 2612measure of readability for each excerpt.</p> 2613<div class="layout-chunk" data-layout="l-body"> 2614<div class="sourceCode"> 2615<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>readability</span><span class='op'>[</span><span class='fl'>1</span>,<span class='op'>]</span><span class='op'>$</span><span class='va'>excerpt</span></span></code></pre> 2616</div> 2617<pre><code>[1] "When the young people returned to the ballroom, it presented a decidedly changed appearance. Instead of an interior scene, it was a winter landscape.\nThe floor was covered with snow-white canvas, not laid on smoothly, but rumpled over bumps and hillocks, like a real snow field. The numerous palms and evergreens that had decorated the room, were powdered with flour and strewn with tufts of cotton, like snow. Also diamond dust had been lightly sprinkled on them, and glittering crystal icicles hung from the branches.\nAt each end of the room, on the wall, hung a beautiful bear-skin rug.\nThese rugs were for prizes, one for the girls and one for the boys. And this was the game.\nThe girls were gathered at one end of the room and the boys at the other, and one end was called the North Pole, and the other the South Pole. Each player was given a small flag which they were to plant on reaching the Pole.\nThis would have been an easy matter, but each traveller was obliged to wear snowshoes."</code></pre> 2618<div class="sourceCode"> 2619<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>readability</span><span class='op'>[</span><span class='fl'>1</span>,<span class='op'>]</span><span class='op'>$</span><span class='va'>target</span></span></code></pre> 2620</div> 2621<pre><code>[1] -0.3402591</code></pre> 2622</div> 2623<p><a 2624href="https://www.kaggle.com/c/commonlitreadabilityprize/discussion/240423">According 2625to the data owner</a>, ‘<em>the target value is the result of a 2626Bradley-Terry analysis of more than 111,000 pairwise comparisons between 2627excerpts. Teachers spanning grades 3-12 served as the raters for these
2628comparisons.</em>’ A lower target value indicates a more challenging 2629text to read. The highest target score is equivalent to the 3rd-grade 2630level, while the lowest target score is equivalent to the 12th-grade 2631level. The purpose is to develop a model that predicts a readability 2632score for a given text to identify an appropriate reading level.</p> 2633<p>In the following weeks, we will talk a little bit about the 2634pre-trained language models (e.g., <a 2635href="https://arxiv.org/abs/1907.11692">RoBerta</a>). Our coverage of 2636this material will be at the surface level. We will primarily cover how 2637we obtain numerical vector representations (sentence embeddings) for 2638given text input from a pre-trained language model using Python through 2639R. Then, we will use the sentence embeddings as features to predict the 2640target score in this dataset using various modeling frameworks.</p> 2641<h1 id="recidivism">Recidivism</h1> 2642<p>The Recidivism dataset comes from The National Institute of Justice’s 2643(NIJ) <a 2644href="https://nij.ojp.gov/funding/recidivism-forecasting-challenge">Recidivism 2645Forecasting Challenge</a>. The challenge aims to increase public safety 2646and improve the fair administration of justice across the United States. 2647This challenge had three stages of prediction, and all three stages 2648require modeling a binary outcome (recidivated vs. not recidivated in 2649Year 1, Year 2, and Year 3). In this class, we will only work on the 2650second stage and develop a model for predicting the probability of an 2651individual’s recidivism in the second year after initial release.</p> 2652<p>You can download the training dataset directly from <a 2653href="https://data.ojp.usdoj.gov/Courts/NIJ-s-Recidivism-Challenge-Full-Dataset/ynf5-u8nk">the 2654competition website</a>, or from the course website. Either way, please 2655read the <a 2656href="https://data.ojp.usdoj.gov/stories/s/NIJ-s-Recidivism-Challenge-Overview-and-Term-of-Us/gyxv-98b2/">Terms 2657of Use at this link</a> before working with this dataset.</p> 2658<div class="layout-chunk" data-layout="l-body"> 2659<div class="sourceCode"> 2660<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>recidivism</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>'data/recidivism_full.csv'</span><span class='op'>)</span>,header<span class='op'>=</span><span class='cn'>TRUE</span><span class='op'>)</span></span> 2661<span></span> 2662<span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>recidivism</span><span class='op'>)</span></span></code></pre> 2663</div> 2664<pre><code>'data.frame': 25835 obs. of 54 variables: 2665 $ ID : int 1 2 3 4 5 6 7 8 9 10 ... 2666 $ Gender : chr "M" "M" "M" "M" ... 2667 $ Race : chr "BLACK" "BLACK" "BLACK" "WHITE" ... 2668 $ Age_at_Release : chr "43-47" "33-37" "48 or older" "38-42" ... 2669 $ Residence_PUMA : int 16 16 24 16 16 17 18 16 5 16 ... 2670 $ Gang_Affiliated : logi FALSE FALSE FALSE FALSE FALSE FALSE ... 2671 $ Supervision_Risk_Score_First : int 3 6 7 7 4 5 2 5 7 5 ... 2672 $ Supervision_Level_First : chr "Standard" "Specialized" "High" "High" ... 2673 $ Education_Level : chr "At least some college" "Less than HS diploma" "At least some college" "Less than HS diploma" ... 2674 $ Dependents : chr "3 or more" "1" "3 or more" "1" ... 2675 $ Prison_Offense : chr "Drug" "Violent/Non-Sex" "Drug" "Property" ... 2676 $ Prison_Years : chr "More than 3 years" "More than 3 years" "1-2 years" "1-2 years" ... 2677 $ Prior_Arrest_Episodes_Felony : chr "6" "7" "6" "8" ... 2678 $ Prior_Arrest_Episodes_Misd : chr "6 or more" "6 or more" "6 or more" "6 or more" ... 2679 $ Prior_Arrest_Episodes_Violent : chr "1" "3 or more" "3 or more" "0" ... 2680 $ Prior_Arrest_Episodes_Property : chr "3" "0" "2" "3" ... 2681 $ Prior_Arrest_Episodes_Drug : chr "3" "3" "2" "3" ... 2682 $ Prior_Arrest_Episodes_PPViolationCharges : chr "4" "5 or more" "5 or more" "3" ... 2683 $ Prior_Arrest_Episodes_DVCharges : logi FALSE TRUE TRUE FALSE TRUE FALSE ... 2684 $ Prior_Arrest_Episodes_GunCharges : logi FALSE FALSE FALSE FALSE FALSE FALSE ... 2685 $ Prior_Conviction_Episodes_Felony : chr "3 or more" "3 or more" "3 or more" "3 or more" ... 2686 $ Prior_Conviction_Episodes_Misd : chr "3" "4 or more" "2" "4 or more" ... 2687 $ Prior_Conviction_Episodes_Viol : logi FALSE TRUE TRUE FALSE TRUE FALSE ... 2688 $ Prior_Conviction_Episodes_Prop : chr "2" "0" "1" "3 or more" ... 2689 $ Prior_Conviction_Episodes_Drug : chr "2 or more" "2 or more" "2 or more" "2 or more" ... 2690 $ Prior_Conviction_Episodes_PPViolationCharges : logi FALSE TRUE FALSE FALSE FALSE FALSE ... 2691 $ Prior_Conviction_Episodes_DomesticViolenceCharges: logi FALSE TRUE TRUE FALSE FALSE FALSE ... 2692 $ Prior_Conviction_Episodes_GunCharges : logi FALSE TRUE FALSE FALSE FALSE FALSE ... 2693 $ Prior_Revocations_Parole : logi FALSE FALSE FALSE FALSE FALSE FALSE ... 2694 $ Prior_Revocations_Probation : logi FALSE FALSE FALSE TRUE FALSE FALSE ... 2695 $ Condition_MH_SA : logi TRUE FALSE TRUE TRUE TRUE FALSE ... 2696 $ Condition_Cog_Ed : logi TRUE FALSE TRUE TRUE TRUE FALSE ... 2697 $ Condition_Other : logi FALSE FALSE FALSE FALSE TRUE TRUE ... 2698 $ Violations_ElectronicMonitoring : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
2699 $ Violations_Instruction : logi FALSE TRUE TRUE FALSE FALSE FALSE ... 2700 $ Violations_FailToReport : logi FALSE FALSE FALSE FALSE FALSE FALSE ... 2701 $ Violations_MoveWithoutPermission : logi FALSE FALSE TRUE FALSE FALSE TRUE ... 2702 $ Delinquency_Reports : chr "0" "4 or more" "4 or more" "0" ... 2703 $ Program_Attendances : chr "6" "0" "6" "6" ... 2704 $ Program_UnexcusedAbsences : chr "0" "0" "0" "0" ... 2705 $ Residence_Changes : chr "2" "2" "0" "3 or more" ... 2706 $ Avg_Days_per_DrugTest : num 612 35.7 93.7 25.4 23.1 ... 2707 $ DrugTests_THC_Positive : num 0 0 0.333 0 0 ... 2708 $ DrugTests_Cocaine_Positive : num 0 0 0 0 0 0 0 0 NA 0 ... 2709 $ DrugTests_Meth_Positive : num 0 0 0.1667 0 0.0588 ... 2710 $ DrugTests_Other_Positive : num 0 0 0 0 0 0 0 0 NA 0 ... 2711 $ Percent_Days_Employed : num 0.489 0.425 0 1 0.204 ... 2712 $ Jobs_Per_Year : num 0.448 2 0 0.719 0.929 ... 2713 $ Employment_Exempt : logi FALSE FALSE FALSE FALSE FALSE FALSE ... 2714 $ Recidivism_Within_3years : logi FALSE TRUE TRUE FALSE TRUE FALSE ... 2715 $ Recidivism_Arrest_Year1 : logi FALSE FALSE FALSE FALSE TRUE FALSE ... 2716 $ Recidivism_Arrest_Year2 : logi FALSE FALSE TRUE FALSE FALSE FALSE ... 2717 $ Recidivism_Arrest_Year3 : logi FALSE TRUE FALSE FALSE FALSE FALSE ... 2718 $ Training_Sample : int 1 1 1 1 1 0 1 0 1 1 ...</code></pre> 2719</div> 2720<p>There are 25,835 observations in the training set and 54 variables, 2721including a unique ID variable, four outcome variables (Recidivism in 2722Year 1, Recidivism in Year 2, and Recidivism in Year 3, Recidivism 2723within three years), and a filter variable to indicate whether an 2724observation was included in the training dataset or test dataset. The 2725remaining 48 variables are potential predictive features. A complete 2726list of these variables can be found at <a 2727href="https://nij.ojp.gov/funding/recidivism-forecasting-challenge#recidivism-forecasting-challenge-database-fields-defined">this 2728link</a>.</p> 2729<p>We will work on developing a model to predict the outcome variable 2730<code>Recidivism_Arrest_Year2</code> using the 48 potential predictive 2731variables. Before moving forward, we must remove the individuals who had 2732already recidivated in Year 1. As you can see below, about 29.9% of the 2733individuals recidivated in Year 1. I am removing these individuals from 2734the dataset.</p> 2735<div class="layout-chunk" data-layout="l-body"> 2736<div class="sourceCode"> 2737<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/table.html'>table</a></span><span class='op'>(</span><span class='va'>recidivism</span><span class='op'>$</span><span class='va'>Recidivism_Arrest_Year1</span><span class='op'>)</span></span></code></pre> 2738</div> 2739<pre><code> 2740FALSE TRUE 274118111 7724 </code></pre> 2742<div class="sourceCode"> 2743<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>recidivism2</span> <span class='op'><-</span> <span class='va'>recidivism</span><span class='op'>[</span><span class='va'>recidivism</span><span class='op'>$</span><span class='va'>Recidivism_Arrest_Year1</span> <span class='op'>==</span> <span class='cn'>FALSE</span>,<span class='op'>]</span></span></code></pre> 2744</div> 2745</div> 2746<p>
2746I will also recode some variables before saving the new dataset for 2747later use in class.</p> 2748<ul> 2749<li>First, some variables in the dataset are coded as TRUE and FALSE. 2750When these variables are imported into R, R automatically recognizes 2751them as logical variables. I will recode all these variables such that 2752FALSE = 0 and TRUE = 1.</li> 2753</ul> 2754<div class="layout-chunk" data-layout="l-body"> 2755<div class="sourceCode"> 2756<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># Find the columns recognized as logical</span></span> 2757<span></span> 2758<span> <span class='va'>cols</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/lapply.html'>sapply</a></span><span class='op'>(</span><span class='va'>recidivism</span>, <span class='va'>is.logical</span><span class='op'>)</span></span> 2759<span></span> 2760<span><span class='co'># Convert them to numeric 0s and 1s</span></span> 2761<span></span> 2762<span> <span class='va'>recidivism2</span><span class='op'>[</span>,<span class='va'>cols</span><span class='op'>]</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/lapply.html'>lapply</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>[</span>,<span class='va'>cols</span><span class='op'>]</span>, <span class='va'>as.numeric</span><span class='op'>)</span></span></code></pre> 2763</div> 2764</div> 2765<ul> 2766<li>Second, the highest value for some variables are coded as <strong>3 2767or more</strong>, <strong>4 or more</strong>, <strong>10 or 2768more</strong>, etc. These variables can be considered as numeric, but R 2769recognizes them as character vectors due to phrase <strong>or 2770more</strong> for the highest value. We will recode these variables so 2771‘X or more’ will be equal to X.</li> 2772</ul> 2773<div class="layout-chunk" data-layout="l-body"> 2774<div class="sourceCode"> 2775<pre class="sourceCode r"><code class="sourceCode r"><span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>require</a></span><span class='op'>(</span><span class='va'><a href='https://dplyr.tidyverse.org'>dplyr</a></span><span class='op'>)</span></span> 2776<span></span> 2777<span><span class='co'># Dependents</span></span> 2778<span></span> 2779<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Dependents</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Dependents</span>,</span> 2780<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2781<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2782<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2783<span> <span class='st'>'3 or more'</span><span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> 2784<span></span> 2785<span><span class='co'># Prior Arrest Episodes Felony</span></span> 2786<span></span> 2787<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Felony</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Felony</span>,</span> 2788<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2789<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2790<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2791<span>
2791 <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2792<span> <span class='st'>'4'</span><span class='op'>=</span><span class='fl'>4</span>,</span> 2793<span> <span class='st'>'5'</span><span class='op'>=</span><span class='fl'>5</span>,</span> 2794<span> <span class='st'>'6'</span><span class='op'>=</span><span class='fl'>6</span>,</span> 2795<span> <span class='st'>'7'</span><span class='op'>=</span><span class='fl'>7</span>,</span> 2796<span> <span class='st'>'8'</span><span class='op'>=</span><span class='fl'>8</span>,</span> 2797<span> <span class='st'>'9'</span><span class='op'>=</span><span class='fl'>9</span>,</span> 2798<span> <span class='st'>'10 or more'</span><span class='op'>=</span><span class='fl'>10</span><span class='op'>)</span></span> 2799<span><span class='co'># Prior Arrest Episods Misd</span></span> 2800<span></span> 2801<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Misd</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Misd</span>,</span> 2802<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2803<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2804<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2805<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2806<span> <span class='st'>'4'</span><span class='op'>=</span><span class='fl'>4</span>,</span> 2807<span> <span class='st'>'5'</span><span class='op'>=</span><span class='fl'>5</span>,</span> 2808<span> <span class='st'>'6 or more'</span><span class='op'>=</span><span class='fl'>6</span><span class='op'>)</span></span> 2809<span> </span> 2810<span><span class='co'># Prior Arrest Episodes Violent</span></span> 2811<span></span> 2812<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Violent</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Violent</span>,</span> 2813<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2814<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2815<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2816<span> <span class='st'>'3 or more'</span><span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> 2817<span></span> 2818<span><span class='co'># Prior Arrest Episods Property</span></span> 2819<span></span> 2820<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Property</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Property</span>,</span> 2821<span>
2821 <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2822<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2823<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2824<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2825<span> <span class='st'>'4'</span><span class='op'>=</span><span class='fl'>4</span>,</span> 2826<span> <span class='st'>'5 or more'</span><span class='op'>=</span><span class='fl'>5</span><span class='op'>)</span></span> 2827<span> </span> 2828<span><span class='co'># Prior Arrest Episods Drug</span></span> 2829<span></span> 2830<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Drug</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_Drug</span>,</span> 2831<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2832<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2833<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2834<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2835<span> <span class='st'>'4'</span><span class='op'>=</span><span class='fl'>4</span>,</span> 2836<span> <span class='st'>'5 or more'</span><span class='op'>=</span><span class='fl'>5</span><span class='op'>)</span> </span> 2837<span><span class='co'># Prior Arrest Episods PPViolationCharges</span></span> 2838<span></span> 2839<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_PPViolationCharges</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Arrest_Episodes_PPViolationCharges</span>,</span> 2840<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2841<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2842<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2843<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2844<span> <span class='st'>'4'</span><span class='op'>=</span><span class='fl'>4</span>,</span> 2845<span> <span class='st'>'5 or more'</span><span class='op'>=</span><span class='fl'>5</span><span class='op'>)</span> </span> 2846<span> </span> 2847<span><span class='co'># Prior Conviction Episodes Felony</span></span> 2848<span></span> 2849<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Felony</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Felony</span>,</span> 2850<span>
2850 <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2851<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2852<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2853<span> <span class='st'>'3 or more'</span><span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> 2854<span></span> 2855<span><span class='co'># Prior Conviction Episodes Misd</span></span> 2856<span></span> 2857<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Misd</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Misd</span>,</span> 2858<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2859<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2860<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2861<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2862<span> <span class='st'>'4 or more'</span><span class='op'>=</span><span class='fl'>4</span><span class='op'>)</span></span> 2863<span> </span> 2864<span><span class='co'># Prior Conviction Episodes Prop</span></span> 2865<span></span> 2866<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Prop</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Prop</span>,</span> 2867<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2868<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2869<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2870<span> <span class='st'>'3 or more'</span><span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> 2871<span></span> 2872<span><span class='co'># Prior Conviction Episodes Drug</span></span> 2873<span></span> 2874<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Drug</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Prior_Conviction_Episodes_Drug</span>,</span> 2875<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2876<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2877<span> <span class='st'>'2 or more'</span><span class='op'>=</span><span class='fl'>2</span><span class='op'>)</span></span> 2878<span></span> 2879<span><span class='co'># Delinquency Reports</span></span> 2880<span></span> 2881<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Delinquency_Reports</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Delinquency_Reports</span>,</span> 2882<span>
2882 <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2883<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2884<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2885<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2886<span> <span class='st'>'4 or more'</span><span class='op'>=</span><span class='fl'>4</span><span class='op'>)</span></span> 2887<span></span> 2888<span><span class='co'># Program Attendances</span></span> 2889<span></span> 2890<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Program_Attendances</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Program_Attendances</span>,</span> 2891<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2892<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2893<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2894<span> <span class='st'>'3'</span><span class='op'>=</span><span class='fl'>3</span>,</span> 2895<span> <span class='st'>'4'</span><span class='op'>=</span><span class='fl'>4</span>,</span> 2896<span> <span class='st'>'5'</span><span class='op'>=</span><span class='fl'>5</span>,</span> 2897<span> <span class='st'>'6'</span><span class='op'>=</span><span class='fl'>6</span>,</span> 2898<span> <span class='st'>'7'</span><span class='op'>=</span><span class='fl'>7</span>,</span> 2899<span> <span class='st'>'8'</span><span class='op'>=</span><span class='fl'>8</span>,</span> 2900<span> <span class='st'>'9'</span><span class='op'>=</span><span class='fl'>9</span>,</span> 2901<span> <span class='st'>'10 or more'</span><span class='op'>=</span><span class='fl'>10</span><span class='op'>)</span></span> 2902<span></span> 2903<span><span class='co'># Program Unexcused Absences</span></span> 2904<span></span> 2905<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Program_UnexcusedAbsences</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Program_UnexcusedAbsences</span>,</span> 2906<span> <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2907<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2908<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2909<span> <span class='st'>'3 or more'</span><span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> 2910<span></span> 2911<span><span class='co'># Residence Changes</span></span> 2912<span></span> 2913<span> <span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Residence_Changes</span> <span class='op'><-</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/recode.html'>recode</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>$</span><span class='va'>Residence_Changes</span>,</span> 2914<span>
2914 <span class='st'>'0'</span><span class='op'>=</span><span class='fl'>0</span>,</span> 2915<span> <span class='st'>'1'</span><span class='op'>=</span><span class='fl'>1</span>,</span> 2916<span> <span class='st'>'2'</span><span class='op'>=</span><span class='fl'>2</span>,</span> 2917<span> <span class='st'>'3 or more'</span><span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span> </span> 2918<span><span class='co'>#############################################################</span></span> 2919<span> </span> 2920<span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>recidivism2</span><span class='op'>)</span> </span></code></pre> 2921</div> 2922<pre><code>'data.frame': 18111 obs. of 54 variables: 2923 $ ID : int 1 2 3 4 6 7 8 11 13 15 ... 2924 $ Gender : chr "M" "M" "M" "M" ... 2925 $ Race : chr "BLACK" "BLACK" "BLACK" "WHITE" ... 2926 $ Age_at_Release : chr "43-47" "33-37" "48 or older" "38-42" ... 2927 $ Residence_PUMA : int 16 16 24 16 17 18 16 5 18 5 ... 2928 $ Gang_Affiliated : num 0 0 0 0 0 0 0 0 0 0 ... 2929 $ Supervision_Risk_Score_First : int 3 6 7 7 5 2 5 3 3 7 ... 2930 $ Supervision_Level_First : chr "Standard" "Specialized" "High" "High" ... 2931 $ Education_Level : chr "At least some college" "Less than HS diploma" "At least some college" "Less than HS diploma" ... 2932 $ Dependents : num 3 1 3 1 0 2 3 1 1 1 ... 2933 $ Prison_Offense : chr "Drug" "Violent/Non-Sex" "Drug" "Property" ... 2934 $ Prison_Years : chr "More than 3 years" "More than 3 years" "1-2 years" "1-2 years" ... 2935 $ Prior_Arrest_Episodes_Felony : num 6 7 6 8 4 10 6 3 8 9 ... 2936 $ Prior_Arrest_Episodes_Misd : num 6 6 6 6 0 6 6 6 4 3 ... 2937 $ Prior_Arrest_Episodes_Violent : num 1 3 3 0 1 1 3 2 0 2 ... 2938 $ Prior_Arrest_Episodes_Property : num 3 0 2 3 3 5 1 1 5 2 ... 2939 $ Prior_Arrest_Episodes_Drug : num 3 3 2 3 0 1 2 1 2 4 ... 2940 $ Prior_Arrest_Episodes_PPViolationCharges : num 4 5 5 3 0 5 5 3 1 4 ... 2941 $ Prior_Arrest_Episodes_DVCharges : num 0 1 1 0 0 0 0 1 0 0 ... 2942 $ Prior_Arrest_Episodes_GunCharges : num 0 0 0 0 0 1 0 0 0 1 ... 2943 $ Prior_Conviction_Episodes_Felony : num 3 3 3 3 1 3 1 0 1 3 ... 2944 $ Prior_Conviction_Episodes_Misd : num 3 4 2 4 0 1 4 3 0 2 ... 2945 $ Prior_Conviction_Episodes_Viol : num 0 1 1 0 0 0 1 0 0 1 ... 2946 $ Prior_Conviction_Episodes_Prop : num 2 0 1 3 2 3 0 0 2 1 ... 2947 $ Prior_Conviction_Episodes_Drug : num 2 2 2 2 0 0 2 0 1 1 ... 2948 $ Prior_Conviction_Episodes_PPViolationCharges : num 0 1 0 0 0 1 1 1 0 1 ... 2949 $ Prior_Conviction_Episodes_DomesticViolenceCharges: num 0 1 1 0 0 0 0 0 0 0 ... 2950 $ Prior_Conviction_Episodes_GunCharges : num 0 1 0 0 0 1 0 0 0 0 ... 2951 $ Prior_Revocations_Parole : num 0 0 0 0 0 0 0 1 0 0 ... 2952 $ Prior_Revocations_Probation : num 0 0 0 1 0 0 0 0 0 0 ... 2953 $ Condition_MH_SA : num 1 0 1 1 0 0 0 1 0 1 ... 2954 $ Condition_Cog_Ed : num 1 0 1 1 0 0 1 1 0 1 ... 2955 $ Condition_Other : num 0 0 0 0 1 0 0 0 0 1 ... 2956 $ Violations_ElectronicMonitoring : num 0 0 0 0 0 0 0 1 0 0 ...
2957 $ Violations_Instruction : num 0 1 1 0 0 0 0 1 0 0 ... 2958 $ Violations_FailToReport : num 0 0 0 0 0 0 0 0 0 0 ... 2959 $ Violations_MoveWithoutPermission : num 0 0 1 0 1 0 0 0 0 0 ... 2960 $ Delinquency_Reports : num 0 4 4 0 0 0 0 0 0 0 ... 2961 $ Program_Attendances : num 6 0 6 6 0 0 0 9 0 6 ... 2962 $ Program_UnexcusedAbsences : num 0 0 0 0 0 0 0 2 0 0 ... 2963 $ Residence_Changes : num 2 2 0 3 3 1 0 2 1 1 ... 2964 $ Avg_Days_per_DrugTest : num 612 35.7 93.7 25.4 474.6 ... 2965 $ DrugTests_THC_Positive : num 0 0 0.333 0 0 ... 2966 $ DrugTests_Cocaine_Positive : num 0 0 0 0 0 0 0 0 0 0 ... 2967 $ DrugTests_Meth_Positive : num 0 0 0.167 0 0 ... 2968 $ DrugTests_Other_Positive : num 0 0 0 0 0 ... 2969 $ Percent_Days_Employed : num 0.489 0.425 0 1 0.674 ... 2970 $ Jobs_Per_Year : num 0.448 2 0 0.719 0.308 ... 2971 $ Employment_Exempt : num 0 0 0 0 0 0 0 1 0 1 ... 2972 $ Recidivism_Within_3years : num 0 1 1 0 0 1 0 1 0 0 ... 2973 $ Recidivism_Arrest_Year1 : num 0 0 0 0 0 0 0 0 0 0 ... 2974 $ Recidivism_Arrest_Year2 : num 0 0 1 0 0 0 0 1 0 0 ... 2975 $ Recidivism_Arrest_Year3 : num 0 1 0 0 0 1 0 0 0 0 ... 2976 $ Training_Sample : int 1 1 1 1 0 1 0 1 1 0 ...</code></pre> 2977</div> 2978<p>Now, we export the final version of the dataset.</p> 2979<div class="layout-chunk" data-layout="l-body"> 2980<div class="sourceCode"> 2981<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/write.table.html'>write.csv</a></span><span class='op'>(</span><span class='va'>recidivism2</span>, </span> 2982<span> <span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>'data/recidivism_y1 removed and recoded.csv'</span><span class='op'>)</span>,</span> 2983<span> row.names <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span></span></code></pre> 2984</div> 2985</div> 2986<p>In future weeks, we will work with this version of the dataset.</p> 2987<h1 2988id="installing-reticulate-miniconda-and-sentence-transformers">Installing 2989Reticulate, Miniconda, and Sentence Transformers</h1> 2990<p>You will need to install the <code>reticulate</code> package and 2991<code>sentence_transformers</code> module for the following weeks. You 2992can run the following code in your computer to get prepared for the 2993following weeks. Note that you only have to run the following code once 2994to install the necessary packages.</p> 2995<p>If you are having troubles about installing these packages in your 2996computer, I highly recommend using a Kaggle R notebook which these 2997packages are already installed (I will give more information about this 2998in class).</p> 2999<div class="layout-chunk" data-layout="l-body"> 3000<div class="sourceCode"> 3001<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># Install the reticulate package</span></span> 3002<span></span> 3003<span><span class='fu'><a href='https://rdrr.io/r/utils/install.packages.html'>install.packages</a></span><span class='op'>(</span>pkgs <span class='op'>=</span> <span class='st'>'reticulate'</span>,</span> 3004<span> dependencies <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> 3005<span></span> 3006<span></span> 3007<span></span> 3008<span><span class='co'># Install Miniconda</span></span> 3009<span></span> 3010<span><span class='fu'>install_miniconda</span><span class='op'>(</span><span class='op'>)</span></span></code></pre> 3011</div> 3012</div> 3013<p>Once you install the reticulate package, run the following code to 3014get python configurations and make sure everything is properly 3015installed.</p> 3016<div class="layout-chunk" data-layout="l-body"> 3017<div class="sourceCode"> 3018<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'>
3018# Load the reticulate package</span></span> 3019<span></span> 3020<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>require</a></span><span class='op'>(</span><span class='va'><a href='https://github.com/rstudio/reticulate'>reticulate</a></span><span class='op'>)</span></span> 3021<span></span> 3022<span><span class='fu'><a href='https://rdrr.io/pkg/reticulate/man/conda-tools.html'>conda_list</a></span><span class='op'>(</span><span class='op'>)</span></span></code></pre> 3023</div> 3024<pre><code> name 30251 Anaconda3 30262 r-reticulate 3027 python 30281 C:\\Users\\cengiz\\Anaconda3\\python.exe 30292 C:\\Users\\cengiz\\AppData\\Local\\r-miniconda\\envs\\r-reticulate\\python.exe</code></pre> 3030</div> 3031<p>You should see <code>r-reticulate</code> under the name column as one 3032of your virtual Python environment. Finally, you will also need to 3033install the sentence transformers module. The following code will 3034install the sentence transformers module to the virtual Python 3035environment <code>r-reticulate</code>.</p> 3036<div class="layout-chunk" data-layout="l-body"> 3037<div class="sourceCode"> 3038<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># Install the sentence transformer module </span></span> 3039<span></span> 3040<span><span class='fu'><a href='https://rdrr.io/pkg/reticulate/man/use_python.html'>use_condaenv</a></span><span class='op'>(</span><span class='st'>'r-reticulate'</span><span class='op'>)</span></span> 3041<span></span> 3042<span><span class='fu'><a href='https://rdrr.io/pkg/reticulate/man/conda-tools.html'>conda_install</a></span><span class='op'>(</span>envname <span class='op'>=</span> <span class='st'>'r-reticulate'</span>,</span> 3043<span> packages <span class='op'>=</span> <span class='st'>'sentence_transformers'</span>,</span> 3044<span> pip <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span></code></pre> 3045</div> 3046<pre><code>[1] "sentence_transformers"</code></pre> 3047<div class="sourceCode"> 3048<pre class="sourceCode r"><code class="sourceCode r"><span> <span class='co'># try pip=FALSE, if it gives an error message</span></span></code></pre> 3049</div> 3050</div> 3051<p>Once you install the Python packages using the code above, you can 3052run the following code. If you are seeing the same output as below, you 3053should be all set to explore some very exciting NLP tools using the 3054Readability dataset.</p> 3055<div class="layout-chunk" data-layout="l-body"> 3056<div class="sourceCode"> 3057<pre class="sourceCode r"><code class="sourceCode r"><span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>require</a></span><span class='op'>(</span><span class='va'><a href='https://github.com/rstudio/reticulate'>reticulate</a></span><span class='op'>)</span></span> 3058<span></span> 3059<span><span class='co'># Import the sentence transformer module</span></span> 3060<span></span> 3061<span><span class='fu'>reticulate</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/pkg/reticulate/man/import.html'>import</a></span><span class='op'>(</span><span class='st'>'sentence_transformers'</span><span class='op'>)</span></span></code></pre> 3062</div> 3063<pre><code>Module(sentence_transformers)</code></pre> 3064</div> 3065<div class="sourceCode" id="cb10"><pre 3066class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div> 3067<!--radix_placeholder_article_footer--> 3068<!--/radix_placeholder_article_footer--> 3069</div> 3070 3071<div class="d-appendix"> 3072</div> 3073 3074 3075<!--radix_placeholder_site_after_body--> 3076<!--/radix_placeholder_site_after_body--> 3077<!--radix_placeholder_appendices--> 3078<div class="appendix-bottom"> 3079<h3 id="reuse">Reuse</h3> 3080<p>Text and figures are licensed under Creative Commons Attribution <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".</p> 3081</div> 3082<!--/radix_placeholder_appendices--> 3083<!--radix_placeholder_navigation_after_body--> 3084<div class="distill-site-nav distill-site-footer"> 3085<center> 3086<p> Cengiz Zopluoglu, [email protected] </p> 3087<p>
3087 Made using <a href="https://rstudio.github.io/distill/website.html"> the Distill for R Markdown</a> in 3088<a href = "https://www.rstudio.com"> RStudio.</a></p> 3089<p>Copyright © 2022 Cengiz Zopluoglu. All rights reserved.</p> 3090</center> 3091</div> 3092<!--/radix_placeholder_navigation_after_body--> 3093 3094 3095</body> 3096 3097</html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.