<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>MeanMean</title>
    <description>An exploratory analysis of agriculture, statistics, and computing.
</description>
    <link>http://meanmean.me/</link>
    <atom:link href="http://meanmean.me/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Wed, 23 Dec 2020 13:22:42 -0500</pubDate>
    <lastBuildDate>Wed, 23 Dec 2020 13:22:42 -0500</lastBuildDate>
    <generator>Jekyll v3.8.6</generator>
    
      <item>
        <title>Cleaning up SPAM with NLP</title>
        <description>    &lt;script type=&quot;text/javascript&quot; async
        src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML&quot;&gt;
    &lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      function showhide(id) {
      var e = document.getElementById(id);
      e.style.display = (e.style.display == 'block') ? 'none' : 'block';
      }
    &lt;/script&gt;
    &lt;style&gt;
img.article {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: &quot;90%&quot;;
}
&lt;/style&gt;
&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
.MathJax_SVG_LineBox {display: table!important}
.MathJax_SVG_LineBox span {display: table-cell!important; width: 10000em!important; min-width: 0; max-width: none; padding: 0; border: 0; margin: 0}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3A3&quot; d=&quot;M666 247Q664 244 652 126T638 4V0H351Q131 0 95 0T57 5V6Q54 12 57 17L73 36Q89 54 121 90T182 159L305 299L56 644L55 658Q55 677 60 681Q63 683 351 683H638V679Q640 674 652 564T666 447V443H626V447Q618 505 604 543T559 605Q529 626 478 631T333 637H294H189L293 494Q314 465 345 422Q400 346 400 340Q400 338 399 337L154 57Q407 57 428 58Q476 60 508 68T551 83T575 103Q595 125 608 162T624 225L626 251H666V247Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6C&quot; d=&quot;M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-68&quot; d=&quot;M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-41&quot; d=&quot;M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6C&quot; d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-53&quot; d=&quot;M55 507Q55 590 112 647T243 704H257Q342 704 405 641L426 672Q431 679 436 687T446 700L449 704Q450 704 453 704T459 705H463Q466 705 472 699V462L466 456H448Q437 456 435 459T430 479Q413 605 329 646Q292 662 254 662Q201 662 168 626T135 542Q135 508 152 480T200 435Q210 431 286 412T370 389Q427 367 463 314T500 191Q500 110 448 45T301 -21Q245 -21 201 -4T140 27L122 41Q118 36 107 21T87 -7T78 -21Q76 -22 68 -22H64Q61 -22 55 -16V101Q55 220 56 222Q58 227 76 227H89Q95 221 95 214Q95 182 105 151T139 90T205 42T305 24Q352 24 386 62T420 155Q420 198 398 233T340 281Q284 295 266 300Q261 301 239 306T206 314T174 325T141 343T112 367T85 402Q55 451 55 507Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-57&quot; d=&quot;M792 683Q810 680 914 680Q991 680 1003 683H1009V637H996Q931 633 915 598Q912 591 863 438T766 135T716 -17Q711 -22 694 -22Q676 -22 673 -15Q671 -13 593 231L514 477L435 234Q416 174 391 92T358 -6T341 -22H331Q314 -21 310 -15Q309 -14 208 302T104 622Q98 632 87 633Q73 637 35 637H18V683H27Q69 681 154 681Q164 681 181 681T216 681T249 682T276 683H287H298V637H285Q213 637 213 620Q213 616 289 381L364 144L427 339Q490 535 492 546Q487 560 482 578T475 602T468 618T461 628T449 633T433 636T408 637H380V683H388Q397 680 508 680Q629 680 650 683H660V637H647Q576 637 576 619L727 146Q869 580 869 600Q869 605 863 612T839 627T794 637H783V683H792Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-50&quot; d=&quot;M130 622Q123 629 119 631T103 634T60 637H27V683H214Q237 683 276 683T331 684Q419 684 471 671T567 616Q624 563 624 489Q624 421 573 372T451 307Q429 302 328 301H234V181Q234 62 237 58Q245 47 304 46H337V0H326Q305 3 182 3Q47 3 38 0H27V46H60Q102 47 111 49T130 61V622ZM507 488Q507 514 506 528T500 564T483 597T450 620T397 635Q385 637 307 637H286Q237 637 234 628Q231 624 231 483V342H302H339Q390 342 423 349T481 382Q507 411 507 488Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5B&quot; d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5D&quot; d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3C3&quot; d=&quot;M184 -11Q116 -11 74 34T31 147Q31 247 104 333T274 430Q275 431 414 431H552Q553 430 555 429T559 427T562 425T565 422T567 420T569 416T570 412T571 407T572 401Q572 357 507 357Q500 357 490 357T476 358H416L421 348Q439 310 439 263Q439 153 359 71T184 -11ZM361 278Q361 358 276 358Q152 358 115 184Q114 180 114 178Q106 141 106 117Q106 67 131 47T188 26Q242 26 287 73Q316 103 334 153T356 233T361 278Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6B&quot; d=&quot;M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-26&quot; d=&quot;M156 540Q156 620 201 668T302 716Q354 716 377 671T401 578Q401 505 287 386L274 373Q309 285 416 148L429 132L437 142Q474 191 543 309L562 341V349Q562 368 541 376T498 385H493V431H502L626 428Q709 428 721 431H727V385H712Q688 384 669 379T639 369T618 354T603 337T591 316T578 295Q537 223 506 176T464 117T454 104Q454 102 471 85T497 62Q543 24 585 24Q618 24 648 48T682 113V121H722V112Q721 94 714 75T692 32T646 -7T574 -22Q491 -19 414 42L402 51L391 42Q312 -22 224 -22Q144 -22 93 25T42 135Q42 153 46 169T55 197T74 225T96 249T125 278T156 308L195 347L190 360Q185 372 182 382T174 411T165 448T159 491T156 540ZM361 576Q361 613 348 646T305 679Q272 679 252 649T232 572Q232 497 255 426L259 411L267 420Q361 519 361 576ZM140 164Q140 103 167 64T240 24Q271 24 304 36T356 61T374 77Q295 156 235 262L220 292L210 310L193 293Q177 277 169 268T151 229T140 164Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2260&quot; d=&quot;M166 -215T159 -215T147 -212T141 -204T139 -197Q139 -190 144 -183L306 133H70Q56 140 56 153Q56 168 72 173H327L406 327H72Q56 332 56 347Q56 360 70 367H426Q597 702 602 707Q605 716 618 716Q625 716 630 712T636 703T638 696Q638 692 471 367H707Q722 359 722 347Q722 336 708 328L451 327L371 173H708Q722 163 722 153Q722 140 707 133H351Q175 -210 170 -212Q166 -215 159 -215Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239B&quot; d=&quot;M837 1154Q843 1148 843 1145Q843 1141 818 1106T753 1002T667 841T574 604T494 299Q417 -84 417 -609Q417 -641 416 -647T411 -654Q409 -655 366 -655Q299 -655 297 -654Q292 -652 292 -643T291 -583Q293 -400 304 -242T347 110T432 470T574 813T785 1136Q787 1139 790 1142T794 1147T796 1150T799 1152T802 1153T807 1154T813 1154H819H837Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239D&quot; d=&quot;M843 -635Q843 -638 837 -644H820Q801 -644 800 -643Q792 -635 785 -626Q684 -503 605 -363T473 -75T385 216T330 518T302 809T291 1093Q291 1144 291 1153T296 1164Q298 1165 366 1165Q409 1165 411 1164Q415 1163 416 1157T417 1119Q417 529 517 109T833 -617Q843 -631 843 -635Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239C&quot; d=&quot;M413 -9Q412 -9 407 -9T388 -10T354 -10Q300 -10 297 -9Q294 -8 293 -5Q291 5 291 127V300Q291 602 292 605L296 609Q298 610 366 610Q382 610 392 610T407 610T412 609Q416 609 416 592T417 473V127Q417 -9 413 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-33&quot; d=&quot;M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-D7&quot; d=&quot;M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-58&quot; d=&quot;M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239E&quot; d=&quot;M31 1143Q31 1154 49 1154H59Q72 1154 75 1152T89 1136Q190 1013 269 873T401 585T489 294T544 -8T572 -299T583 -583Q583 -634 583 -643T577 -654Q575 -655 508 -655Q465 -655 463 -654Q459 -653 458 -647T457 -609Q457 -58 371 340T100 1037Q87 1059 61 1098T31 1143Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A0&quot; d=&quot;M56 -644H50Q31 -644 31 -635Q31 -632 37 -622Q69 -579 100 -527Q286 -228 371 170T457 1119Q457 1161 462 1164Q464 1165 520 1165Q575 1165 577 1164Q582 1162 582 1153T583 1093Q581 910 570 752T527 400T442 40T300 -303T89 -626Q78 -640 75 -642T61 -644H56Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239F&quot; d=&quot;M579 -9Q578 -9 573 -9T554 -10T520 -10Q466 -10 463 -9Q460 -8 459 -5Q457 5 457 127V300Q457 602 458 605L462 609Q464 610 532 610Q548 610 558 610T573 610T578 609Q582 609 582 592T583 473V127Q583 -9 579 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-63&quot; d=&quot;M370 305T349 305T313 320T297 358Q297 381 312 396Q317 401 317 402T307 404Q281 408 258 408Q209 408 178 376Q131 329 131 219Q131 137 162 90Q203 29 272 29Q313 29 338 55T374 117Q376 125 379 127T395 129H409Q415 123 415 120Q415 116 411 104T395 71T366 33T318 2T249 -11Q163 -11 99 53T34 214Q34 318 99 383T250 448T370 421T404 357Q404 334 387 320Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6F&quot; d=&quot;M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-76&quot; d=&quot;M338 431Q344 429 422 429Q479 429 503 431H508V385H497Q439 381 423 345Q421 341 356 172T288 -2Q283 -11 263 -11Q244 -11 239 -2Q99 359 98 364Q93 378 82 381T43 385H19V431H25L33 430Q41 430 53 430T79 430T104 429T122 428Q217 428 232 431H240V385H226Q187 384 184 370Q184 366 235 234L286 102L377 341V349Q377 363 367 372T349 383T335 385H331V431H338Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5E&quot; d=&quot;M112 560L249 694L257 686Q387 562 387 560L361 531Q359 532 303 581L250 627L195 580Q182 569 169 557T148 538L140 532Q138 530 125 546L112 560Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ3-2C6&quot; d=&quot;M1439 564Q1434 564 1080 631T722 698Q719 698 362 631Q7 564 4 564L0 583Q-4 602 -4 603L720 772L1083 688Q1446 603 1447 603Q1447 602 1443 583L1439 564Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-AF&quot; d=&quot;M69 544V590H430V544H69Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6E&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6D&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-73&quot; d=&quot;M295 316Q295 356 268 385T190 414Q154 414 128 401Q98 382 98 349Q97 344 98 336T114 312T157 287Q175 282 201 278T245 269T277 256Q294 248 310 236T342 195T359 133Q359 71 321 31T198 -10H190Q138 -10 94 26L86 19L77 10Q71 4 65 -1L54 -11H46H42Q39 -11 33 -5V74V132Q33 153 35 157T45 162H54Q66 162 70 158T75 146T82 119T101 77Q136 26 198 26Q295 26 295 104Q295 133 277 151Q257 175 194 187T111 210Q75 227 54 256T33 318Q33 357 50 384T93 424T143 442T187 447H198Q238 447 268 432L283 424L292 431Q302 440 314 448H322H326Q329 448 335 442V310L329 304H301Q295 310 295 316Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-74&quot; d=&quot;M27 422Q80 426 109 478T141 600V615H181V431H316V385H181V241Q182 116 182 100T189 68Q203 29 238 29Q282 29 292 100Q293 108 293 146V181H333V146V134Q333 57 291 17Q264 -10 221 -10Q187 -10 162 2T124 33T105 68T98 100Q97 107 97 248V385H18V422H27Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3B2&quot; d=&quot;M29 -194Q23 -188 23 -186Q23 -183 102 134T186 465Q208 533 243 584T309 658Q365 705 429 705H431Q493 705 533 667T573 570Q573 465 469 396L482 383Q533 332 533 252Q533 139 448 65T257 -10Q227 -10 203 -2T165 17T143 40T131 59T126 65L62 -188Q60 -194 42 -194H29ZM353 431Q392 431 427 419L432 422Q436 426 439 429T449 439T461 453T472 471T484 495T493 524T501 560Q503 569 503 593Q503 611 502 616Q487 667 426 667Q384 667 347 643T286 582T247 514T224 455Q219 439 186 308T152 168Q151 163 151 147Q151 99 173 68Q204 26 260 26Q302 26 349 51T425 137Q441 171 449 214T457 279Q457 337 422 372Q380 358 347 358H337Q258 358 258 389Q258 396 261 403Q275 431 353 431Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3F5&quot; d=&quot;M227 -11Q149 -11 95 41T40 174Q40 262 87 322Q121 367 173 396T287 430Q289 431 329 431H367Q382 426 382 411Q382 385 341 385H325H312Q191 385 154 277L150 265H327Q340 256 340 246Q340 228 320 219H138V217Q128 187 128 143Q128 77 160 52T231 26Q258 26 284 36T326 57T343 68Q350 68 354 58T358 39Q358 36 357 35Q354 31 337 21T289 0T227 -11Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-39B&quot; d=&quot;M320 708Q326 716 340 716H348H355Q367 716 372 708Q374 706 423 547T523 226T575 62Q581 52 591 50T634 46H661V0H653Q644 3 532 3Q411 3 390 0H379V46H392Q464 46 464 65Q463 70 390 305T316 539L246 316Q177 95 177 84Q177 72 198 59T248 46H253V0H245Q230 3 130 3Q47 3 38 0H32V46H45Q112 51 127 91Q128 92 224 399T320 708Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-28&quot; d=&quot;M758 -1237T758 -1240T752 -1249H736Q718 -1249 717 -1248Q711 -1245 672 -1199Q237 -706 237 251T672 1700Q697 1730 716 1749Q718 1750 735 1750H752Q758 1744 758 1741Q758 1737 740 1713T689 1644T619 1537T540 1380T463 1176Q348 802 348 251Q348 -242 441 -599T744 -1218Q758 -1237 758 -1240Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-29&quot; d=&quot;M33 1741Q33 1750 51 1750H60H65Q73 1750 81 1743T119 1700Q554 1207 554 251Q554 -707 119 -1199Q76 -1250 66 -1250Q65 -1250 62 -1250T56 -1249Q55 -1249 53 -1249T49 -1250Q33 -1250 33 -1239Q33 -1236 50 -1214T98 -1150T163 -1052T238 -910T311 -727Q443 -335 443 251Q443 402 436 532T405 831T339 1142T224 1438T50 1716Q33 1737 33 1741Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-52&quot; d=&quot;M230 637Q203 637 198 638T193 649Q193 676 204 682Q206 683 378 683Q550 682 564 680Q620 672 658 652T712 606T733 563T739 529Q739 484 710 445T643 385T576 351T538 338L545 333Q612 295 612 223Q612 212 607 162T602 80V71Q602 53 603 43T614 25T640 16Q668 16 686 38T712 85Q717 99 720 102T735 105Q755 105 755 93Q755 75 731 36Q693 -21 641 -21H632Q571 -21 531 4T487 82Q487 109 502 166T517 239Q517 290 474 313Q459 320 449 321T378 323H309L277 193Q244 61 244 59Q244 55 245 54T252 50T269 48T302 46H333Q339 38 339 37T336 19Q332 6 326 0H311Q275 2 180 2Q146 2 117 2T71 2T50 1Q33 1 33 10Q33 12 36 24Q41 43 46 45Q50 46 61 46H67Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628Q287 635 230 637ZM630 554Q630 586 609 608T523 636Q521 636 500 636T462 637H440Q393 637 386 627Q385 624 352 494T319 361Q319 360 388 360Q466 361 492 367Q556 377 592 426Q608 449 619 486T630 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-57&quot; d=&quot;M436 683Q450 683 486 682T553 680Q604 680 638 681T677 682Q695 682 695 674Q695 670 692 659Q687 641 683 639T661 637Q636 636 621 632T600 624T597 615Q597 603 613 377T629 138L631 141Q633 144 637 151T649 170T666 200T690 241T720 295T759 362Q863 546 877 572T892 604Q892 619 873 628T831 637Q817 637 817 647Q817 650 819 660Q823 676 825 679T839 682Q842 682 856 682T895 682T949 681Q1015 681 1034 683Q1048 683 1048 672Q1048 666 1045 655T1038 640T1028 637Q1006 637 988 631T958 617T939 600T927 584L923 578L754 282Q586 -14 585 -15Q579 -22 561 -22Q546 -22 542 -17Q539 -14 523 229T506 480L494 462Q472 425 366 239Q222 -13 220 -15T215 -19Q210 -22 197 -22Q178 -22 176 -15Q176 -12 154 304T131 622Q129 631 121 633T82 637H58Q51 644 51 648Q52 671 64 683H76Q118 680 176 680Q301 680 313 683H323Q329 677 329 674T327 656Q322 641 318 637H297Q236 634 232 620Q262 160 266 136L501 550L499 587Q496 629 489 632Q483 636 447 637Q428 637 422 639T416 648Q416 650 418 660Q419 664 420 669T421 676T424 680T428 682T436 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
Hey, it's the holidays.  Time to take some PTO/Leave, hang out with family, relax, 
 and work on some side projects.
One of the many projects I finally have time for is removal of 'SPAM' messages
from one of the games I play from time-to-time.  This allows me to play with some
NLP and solve some fun problems, like how to score a model quickly while only using a few mb of RAM in the scripting language Lua.
&lt;/p&gt;

&lt;p&gt;
As someone new to Lua, and only vaguely familiar with XGBoost model dumps, there was 
a lot of learning to be done.  However, I was able to achieve an overall accuracy 
rate of 95%.  Not too bad for a first shot.
&lt;/p&gt;




&lt;!-- define problem --&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
Final Fantasy XI (FFXI) is a Massive Multiplayer Online Game, that I've been playing on
and off for about two decades now.  I primarily play the game to get in contact
with old friends, enjoy the storyline, and just blow off some steam at the end
of the day.  However, over the last few years the primary game-wide communication system
has been poluted with SPAM messages.  This is problematic because, this communication system is also 
where people find groups to do content.  
&lt;/p&gt;

&lt;p&gt;
Other solutions do exist to solve this problem, but they are largely just a set of
regular expressions.  So I thought I would take a stab in creating a quick natural
language processing (NLP) solution to see if I can do better.
&lt;/p&gt;

&lt;p&gt;
One way that I can do better is to not exclusively look at two different types of messages,
SPAM and not SPAM.  Instead, I can look at useful classes of messages that people
can decided if they want to see or not.
&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt; Content:  Content Messages.&lt;/li&gt;
&lt;li&gt; RMT:  Real Money Trade, messages for buying/selling items using real money.&lt;/li&gt;
&lt;li&gt; Merc:  People offering to sell content using in-game currency.&lt;/li&gt;
&lt;li&gt; JP Merc:  People offering to 'level' your character for you.&lt;/li&gt;
&lt;li&gt; Chat:  Consersations between players.&lt;/li&gt;
&lt;li&gt; Buying:  Buying items using in-game currency.&lt;/li&gt;
&lt;li&gt; Selling:  Selling items using in-game currency.&lt;/li&gt;
&lt;li&gt; Other:  Unknown messages catch-all.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
Like all problems there are constraints.  Messages need to be scored in real time, on
the computer running the game.  To avoid maintaining a message log, messages must
be considered individually, so we can't infer class by repeated message frequency as
part of the scoring process.
&lt;/p&gt;


&lt;!-- data collection  --&gt;
&lt;h2&gt;Data Collection&lt;/h2&gt;

&lt;p&gt;
I'm not going into the depths of data collection, but
to do any data analysis I do need data.  In particular, I need data that I can 
label.
I utilized a project that allows for 3rd party addons for the game, &lt;a href=&quot;http://windower.net/&quot;&gt;windower&lt;/a&gt;.  This
framework allows a user to interact with various components of the game including 
in-game messaging through the programming language Lua.  This allows me to write
a quick plugin that records messages received from my character to a MariaDB database 
on my home server.
&lt;/p&gt;

&lt;p&gt;
Because the addon only runs
when I log into the game, it certainly is not a census of all messages, but should provide
a reasonable sample of what types of messages are being sent within the game.
&lt;/p&gt;

&lt;p&gt;
After running this for a few months, I was able to aquire, 98,141 messages.  Unfortunately,
the data does not come pre-labeled, so I manualy labeled 3,570 messages.  This accounts for a total
of 1,736 unique messages.  For anyone interested, I've made this &lt;a href=&quot;http://meanmean.me/data/train_data.csv&quot;&gt;training data&lt;/a&gt; 
available.  An sample of the first five and last five rows is provide below to provide context.
&lt;/p&gt;

&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;&lt;tr&gt; &lt;th&gt;  &lt;/th&gt; &lt;th&gt; msg &lt;/th&gt; &lt;th&gt; label &lt;/th&gt; &lt;th&gt; n &lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1 &lt;/td&gt; &lt;td&gt; job points 4m/500p dho gates Ž©“®‚Å‘g‚É“ü‚ê‚é &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       4 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;     124 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 2 &lt;/td&gt; &lt;td&gt; job points š4m/500pšš all time party dho gates autoinvite &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       4 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;     114 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 3 &lt;/td&gt; &lt;td&gt; job points 500p/4m 0-2100 15m dho gates moh gates igeo 4song fast tachi: jinpu 99999 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       4 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;      93 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 4 &lt;/td&gt; &lt;td&gt; job points ššš &quot;500p/4mil dho gates very fast. do you need it? all time party. buy? autoinvite. /tell &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       4 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;      87 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 5 &lt;/td&gt; &lt;td&gt; experience points pl do you need it? 1-99 3m 1-50 2m 50-99 2m escha - zi'tah  &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       4 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;      70 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1732 &lt;/td&gt; &lt;td&gt; i bet you are &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       5 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       1 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1733 &lt;/td&gt; &lt;td&gt; job points 500p do you need it? buy? dho gates fast kill &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       4 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       1 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1734 &lt;/td&gt; &lt;td&gt; kyou enmerkars earring mercenary can i have it? you can have this. 15m &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       3 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       1 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1735 &lt;/td&gt; &lt;td&gt; ea houppe.  1 ea slops  1 ninja nodowa  2 do you need it? buy? cheap bazaar@ guide stone. &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       6 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       1 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1736 &lt;/td&gt; &lt;td&gt; alexandrite 5.6k x6000 do you need it? buy? (f-8) bazaar &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       6 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       1 &lt;/td&gt; &lt;/tr&gt;
   &lt;/tbody&gt;&lt;/table&gt;


&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R1&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R1&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tidyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tidytext)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(xgboost)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tictoc)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(xtable)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;## read in a copy of the data&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# msg - message&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# label - label&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   1 - Content &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   2 - RMT&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   3 - Merc&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   4 - JP Merc&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   5 - Chat&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   6 - Selling (non-Merc) such as AH Items &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   7 - Buying (non-Merc) such as AH Items &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#   8 - Other&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# n - count&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;msgs&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;read.csv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;http://meanmean.me/data/train_data.csv&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;hl kwc&quot;&gt;stringsAsFactors&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;X)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# order by frequency&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;msgs&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;msgs&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n))&lt;/span&gt;



&lt;span class=&quot;hl com&quot;&gt;# get an example of messages&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;msg_example&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(msgs,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(msgs,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;## define labels for plots&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;description&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Content&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;RMT&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;Merc&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;JP Merc&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;Chat&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;hl str&quot;&gt;&quot;Selling (non-Merc)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;Buying (non-Merc)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Unknown&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# convert labels to descriptions&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;label_desc&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= description,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;stringsAsFactors&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# add labels to msgs&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;left_join&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( msgs, label_desc,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;label&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;# summarize message counts&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;message_summary&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(desc)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;summarize&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;Unique&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;Duplicate&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n) )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;tidyr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;gather&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'Messages'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'count'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, Unique , Duplicate)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;message_count.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;480&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(message_summary,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;= desc,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= count,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Messages))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_bar&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;stat&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'identity'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'dodge'&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Message Class&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Count&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggtitle&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Message Count by Category&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;img src=&quot;http://meanmean.me/images/articles/message_count.png&quot; class=&quot;article&quot;&gt;

&lt;p&gt;
From a quick plot of overall counts of each message type, the JP Merc group clarly stands out.  Although the messages in this
group are rarely unique, they do account for most volume.  This matches with my observations
within the game.
Likewise, the next largest group, Merc, also has similar trends in that there are lots of
repeat messages.  These two groups are commonly considered spam by most players.
Content and Chat messages, the one most useful for most players are quite different
from the spammy messages in both uniqueness and quantity.
&lt;/p&gt;

&lt;p&gt;
Unfortunately, these observations don't help much since capturing message frequency would
violate one of our requirements for message scoring.  Instead, we would need to build features
around model content.
&lt;/p&gt;

&lt;h2&gt;Feature Building&lt;/h2&gt;

&lt;p&gt;
Messages in FFXI are brief and organized.
The interquartile range of unique messages within my trained data set is 46 to 78 characters.
This is a bit more similar to tweets rather than a blog post or a novel. 
The messages within each message class are also quite similar.
Content messages usually mention the activity the player is trying to do, what various jobs are needed to do this activity, and if needed the distribution of items from the activity.  Likewise 'selling' messages usually describe the item, price, and a method to find or contact the individual selling the item.
&lt;/p&gt;

&lt;p&gt;
Because of this brevity and organization, classifying distinct messages is fairly straight forward using n-grams and game specific terminology.  The n-grams capture the distinct structure of the message, and the game specific terminology serves as a thesaurus to link together synonyms  such as 'paladin', 'pld', and 'tank'. Implementation of the methods will be through a bag-of-words type approach, where each n-gram or word occurence in a message will generate a feature.
&lt;/p&gt;



&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R2&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R2&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;## Do test-train split early, this avoids any &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# leakage against test &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#Create Holdout &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# holdout 20% of the data&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;#0-4 k-folds (k=5)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;folds&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(desc)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;dplyr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;U&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;runif&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;dplyr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;Rank&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rank&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(U,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ties.method&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'min'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Rank)&lt;/span&gt;  &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# account for repeat messages&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;#dplyr::mutate( Rank=cumsum(n) ) %&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;dplyr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;partition&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;cut&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( Rank&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Rank),&lt;/span&gt;
         &lt;span class=&quot;hl kwc&quot;&gt;breaks&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.36&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.52&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.68&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.84&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ungroup&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;## all variables created past this point are features&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# we will exclude all current variables later on&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;remove_vars&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;## here we use tidy text to generate n-grams&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;##############################################&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# function to build out ngrams, and keep the top 10&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;top_n_gram&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ngram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;top_n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) {&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# get ngrams&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x_token&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;unnest_tokens&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram, msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;token&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;ngrams&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= ngram)&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# subset ngrams by most frequesnt&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x_count&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;x_token&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;is.na&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(desc)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;slice_head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=top_n)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ungroup&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x_count&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# build out groups&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# identify top most frequent 10 ngrams&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_word&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;top_n_gram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ngram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_bigram&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;top_n_gram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ngram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_trigram&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;top_n_gram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ngram&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;




&lt;span class=&quot;hl com&quot;&gt;# grab our distinct words &lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;key_words&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train_word&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( ngram)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;distinct&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;is.na&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;key_bigrams&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train_bigram&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( ngram)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;distinct&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;is.na&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;key_trigrams&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train_trigram&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( ngram)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;distinct&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;is.na&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;# turn key words into features&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;ngram_matrix&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;nrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;NROW&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(key_trigrams,key_bigrams,key_words)))&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ngram_matrix)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(key_trigrams,key_bigrams,key_words)&lt;/span&gt;

&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( key_word&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;key_words ) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;ngram_matrix[,key_word]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(key_word, test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( key_bigram&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;key_bigrams ) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;ngram_matrix[,key_bigram]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(key_bigram, test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( key_trigram&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;key_trigrams ) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;ngram_matrix[,key_trigram]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(key_trigram, test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;cbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( test_train, ngram_matrix&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;())&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;#plot by frequency&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;test_train_word.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;test_train_word&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;order_helper&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;%d::::%s&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;row_number&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(), ngram)) )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;reorder&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(order_helper,n),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= desc))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;show.legend&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;facet_wrap&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;desc,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;scales&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;free_y&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;scale_x_discrete&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'^.*:::'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, x))&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;Most Frequent Words&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggtitle&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;10 Most Frequent Words&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;coord_flip&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;test_train_bigram.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_bigram&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;order_helper&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;%d::::%s&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;row_number&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(), ngram)) )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;reorder&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(order_helper,n),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= desc))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;show.legend&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;facet_wrap&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;desc,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;scales&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;free_y&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;scale_x_discrete&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'^.*:::'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, x))&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;Most Frequent Bigrams&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggtitle&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;10 Most Frequent Bigrams&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;coord_flip&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;test_train_trigram.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_trigram&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;order_helper&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;%d::::%s&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;row_number&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(), ngram)) )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;reorder&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(order_helper,n),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= desc))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;show.legend&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;facet_wrap&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;desc,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;scales&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;free_y&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;scale_x_discrete&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'^.*:::'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, x))&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;Most Frequent Trigrams&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggtitle&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;10 Most Frequent Trigrams&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;coord_flip&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;
Using a little bit of tidy text it is pretty easy to build out the n-gram features to 
see what are the most common words and phrases.
Note that common words like articles are not removed, they actually turn out to be fairly informative since they rarely show up in the spammy messages, but do show up in the 'chat' class.
&lt;/p&gt;

&lt;img src=&quot;http://meanmean.me/images/articles/test_train_word.png&quot; class=&quot;article&quot;&gt;
&lt;img src=&quot;http://meanmean.me/images/articles/test_train_bigram.png&quot; class=&quot;article&quot;&gt;
&lt;img src=&quot;http://meanmean.me/images/articles/test_train_trigram.png&quot; class=&quot;article&quot;&gt;

&lt;p&gt;
Rare words from a TF-IDF approach don't really help out here, since they either exclude important and frequent words used to separate classes, or they just identify words that would appear in the game specific terms.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R3&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R3&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# build out word frequencies&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_word_idf&lt;/span&gt;&lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unnest_tokens&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(word, msg)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(desc,word,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_total_words_idf&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train_word_idf&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(desc)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;summarize&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;total&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_word_idf&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;left_join&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( test_train_word_idf, test_train_total_words_idf)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_word_idf&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train_word_idf&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;bind_tf_idf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(word, desc,n)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(desc)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tf_idf))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;slice_head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ungroup&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;tf_idf.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;800&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_train_word_idf&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;arrange&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tf_idf))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;order_helper&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;%d::::%s&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;row_number&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(), word)) )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;reorder&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(order_helper,tf_idf),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=tf_idf,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= desc))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;show.legend&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;facet_wrap&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;desc,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;scales&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;free_y&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;scale_x_discrete&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'^.*:::'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, x))&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;TF-IDF Words&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggtitle&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;TF-IDF Words&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;coord_flip&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;img src=&quot;http://meanmean.me/images/articles/tf_idf.png&quot; class=&quot;article&quot;&gt;


&lt;p&gt;
I used my own personal experience from reviewing messages and being aware of 
messaging mechanics to build game specific terms.  These link similar game terms 
together which may be difficult to learn with a small data set like the one I have.
To create features using these words I simply use common pattern matching strings
in the form of regular expressions.  These strings are portable between R and Lua,
so it makes if fairly straight forward to implement in both langauges.
&lt;/p&gt;

&lt;p&gt;
Note that matching isn't perfect, subsequences of words are captured along with the word.  
E.g. 'is' would be captured if 'this' was a part of a message.  
It is
possible to fix this, but would require evaluation of matching implementations in
R and lua.  Furthermore, there are some nuances with the FFXI auto-translate 
function that is used frequently by users.  Auto-translated words have the 
unfortunate consequence of having no spaces placed between words.  
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R4&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R4&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;dplyr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__gil`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;[0-9]+(k|M|gil)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__currency`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(alexandrite|plouton|beitsu|riftborn|montiont|jadeshell|byne|bayld|heavy[ ]metal|hmp|hpb|riftcinder)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__jobs`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(war|mnk|whm|rdm|blm|thf|pld|drk|bst|brd|rng|smn|sam|nin|drg|blu|cor|pup|dnc|sch|geo|run|warrior|monk|mage|theif|paladin|knight|beastmaster|bard|ranger|summoner|samurai|ninja|dragoon|corsair|puppet|dancer|scholar|geomancer|rune)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__roles`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(support|healer|tank|dd|melee|job)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__merc`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;merc&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__omen_big_drops`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(regal|dagon|udug|shamash|ashera|nisroch)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__omen_drops`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(utu|ammurapi|niqmaddu|shulmanu|dingir|yamarang|lugalbanda|ilabrat|enmerkar|iskur|sherida)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__mythic_merc`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(tinnin|tyger|sarameya)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__abyssea_merc`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(colorless|chloris|ulhuadshi|dragua|glavoid|itzpapalot|orthus|briareus|sobek|apademak|carabosse|cirein-croin|isgebind|fistule|bukhis|alfard|azdaja)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__htbm_merc`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(daybreak|sacro|malignance|lilith|odin|gere|freke|palug|hjarrandi|zantetsuken|geirrothr)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__bazaar_loc`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;[(][a-z]-[1-9][)]&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__bazaar_item`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(blured|blurred|raetic|voodoo|jinxed|vexed)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__dyna_item`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(voidhead|voidleg|voidhand|voidfeet|voidtorso|voidbody|beastman|kindred)&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__job_points`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(job points|jobpoints|merit points|meritpoint|experiencepoints|experience points|^exp[ ]|[ ]exp[ ])&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__power_level`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(^| )pl[ ]&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__vagary_boss`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(vagary|perfidien|plouton|putraxia)&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__aman_orbs`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(mars|venus)[ ]orb&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__dynamis`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(dynamis|[d]|(d))&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ) ,&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__content`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(omen|kei|kyou|kin|gin|fu|[ ]ou|^ou|ambuscade|[ ]sr|^sr)&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__buy`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(buy[ ]|buy$|sell[?]|wtb|reward|price)&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt; &lt;span class=&quot;hl com&quot;&gt;# I am trying to buy &lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__sell`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(sell[ ]|sell$|buy[?]|wts)&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) ),&lt;/span&gt; &lt;span class=&quot;hl com&quot;&gt;# I am trying to sell&lt;/span&gt;
&lt;span class=&quot;hl kwc&quot;&gt;`__social`&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;grepl&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;(linkshell|schedule|event|social|^ls[ ]|[ ]ls[ ]|concierge)&quot;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;,test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ignore.case&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) )&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;h2&gt;Model Building&lt;/h2&gt;

&lt;p&gt;
Although a Neural Network approach may work better in theory, I don't have a huge
amount of data.  I also have a set of features that are likely to work pretty well
for more traditional models, so I went with XGBoost for an 
initial iteration simply because it is fairly easy to interpret the results and
extremely easy to score for new languages with multi-class models.  This later property is due to the 
raw model dumps that XGBoost provides for multi-class problems.
&lt;/p&gt;

&lt;p&gt;If you are not familiar with XGBoost, it's a popular implementation
of gradient boosted tree models using regularization.  It allows you to fit
a succession of simple models (trees), to create an ensemble of simple trees (boosting).
To avoid over fitting, regularization is used to limit the impact of trees that
provide little input to the model.  A good overview can be found on the &lt;a href=&quot;https://xgboost.readthedocs.io/en/latest/tutorials/model.html&quot;&gt;XGBoost
site&lt;/a&gt;.

&lt;/p&gt;&lt;p&gt;
Implementation of an XGBoost model is fairly straight forward.  
We already split our data early on, so we just need to build a parameter grid; 
train XGBoost on our training set to find our best parameters, and then see what 
features we want to keep.
&lt;/p&gt;

&lt;p&gt; To train I just did a grid search with cross validation to aid in robust
parameter selection.  The parameters we are evaluating our model over are a reduced set from
a prior and more exhaustive run.  With this subset, we will still get pretty
good performance and a reasonable run time, usuallly 1-2min on modern computers.&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R5&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R5&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# find model parameters &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#grid to search&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;nrounds&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;colsample_bytrees&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;.6&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;.8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;min_child_weights&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;max_depths&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;etas&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;subsamples&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;.8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cv.nfold&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;gams&lt;/span&gt;&lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;# create a place to store our results&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;summary_cv&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;expand.grid&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;nrounds,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;max_depths,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;etas,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;subsamples,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;gams,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;colsample_bytrees,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;min_child_weights,&lt;/span&gt;
  &lt;span class=&quot;hl num&quot;&gt;Inf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(summary_cv)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;nround&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;max_depth&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;eta&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'subsample'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;gam&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                          &lt;span class=&quot;hl str&quot;&gt;&quot;colsample_bytree&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;min_child_weight&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;min_log_loss&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                          &lt;span class=&quot;hl str&quot;&gt;&quot;min_log_loss_index&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;summary_cv&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(summary_cv)&lt;/span&gt;



&lt;span class=&quot;hl com&quot;&gt;## create training data set&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# data set&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;train&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train[test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;hl opt&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;remove_vars ]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# label (xgboost requires labels that start with 0)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;train_label&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(label)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# folds&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;train_partition&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.character&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;train_folds&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( k&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(train_partition)) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;train_folds[[k]]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;which&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(train_partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;k)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# find best parameters&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( i&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;NROW&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(summary_cv)) {&lt;/span&gt;

   &lt;span class=&quot;hl std&quot;&gt;cur_summary&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;summary_cv[i,]&lt;/span&gt;

   &lt;span class=&quot;hl std&quot;&gt;param&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;objective&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;multi:softprob&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;eval_metric&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;mlogloss&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;num_class&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;max_depth&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;max_depth,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;eta,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;gamma&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;gam,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;subsample&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;subsample,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;colsample_bytree&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;colsample_bytree,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;min_child_weight&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;min_child_weight,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;max_delta_step&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;
   &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

   &lt;span class=&quot;hl std&quot;&gt;mdcv&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xgb.cv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= train,&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= train_label,&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= param,&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;nthread&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;folds&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=train_folds,&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;nrounds&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=cur_summary&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;nround,&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;verbose&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

   &lt;span class=&quot;hl std&quot;&gt;summary_cv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;min_log_loss[i]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
     &lt;span class=&quot;hl kwd&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(mdcv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;evaluation_log[,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'test_mlogloss_mean'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;())&lt;/span&gt;
   &lt;span class=&quot;hl std&quot;&gt;summary_cv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;min_logloss_index[i]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
     &lt;span class=&quot;hl kwd&quot;&gt;which.min&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(mdcv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;evaluation_log[,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'test_mlogloss_mean'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;())&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;best_model_cv&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;summary_cv[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;which.min&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(summary_cv[,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'min_log_loss'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]),]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;p&gt; With our best parameters, we are now going to build a full model using all
our training data.  Based on this output, we are going to pick which features we are going
to keep through a Gain threshold.  Gain just gives us an idea of how important
a variable is by the increase in accuracy after it is used for a split in the
tree.&lt;/p&gt;

&lt;p&gt;
As an implementation note, if we were going to evaluate different gain value thresholds
we would do this as part of the parameter selection step.&lt;/p&gt; 

&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R6&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R6&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# Train Model for Evaluation&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set best parameters&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;param&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;objective&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;multi:softprob&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;eval_metric&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;&quot;mlogloss&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;num_class&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;max_depth&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model_cv[&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'max_depth'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;],&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;eta&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model_cv[&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'eta'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;],&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;gamma&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model_cv[&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'gam'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;],&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;subsample&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model_cv[&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'subsample'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;],&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;colsample_bytree&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model_cv[&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'colsample_bytree'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;],&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;min_child_weight&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model_cv[&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'min_child_weight'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;],&lt;/span&gt;
              &lt;span class=&quot;hl kwc&quot;&gt;max_delta_step&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;best_model&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xgboost&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= train,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= train_label,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= param,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;nthread&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;nrounds&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=best_model_cv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;nround,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;verbose&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# Feature Selection&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;importance&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xgb.importance&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;feature_names&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(train),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;top_features&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;importance&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( Gain&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;0.001&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Feature)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;best_model_reduced&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xgboost&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= train[,top_features],&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= train_label,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= param,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;nthread&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;nrounds&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=best_model_cv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;nround,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;verbose&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;&lt;tr&gt; &lt;th&gt; Model &lt;/th&gt; &lt;th&gt; Log Loss &lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt;  &lt;td&gt; Full &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       0.0663 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt;  &lt;td&gt; Reduced &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       0.0670 &lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;
Using our
gain threshold of 0.001, we end up with 77 out of 174 variables and a minor reduction
in model performance.  This is a pretty good trade off and will also lower the
run time for model scoring.
&lt;/p&gt;

&lt;h2&gt;Model Evaluation&lt;/h2&gt;

&lt;p&gt;
Now that we have our model, we want to check two important model characteristics:  (1) Does the model and it's output  make sense?
(2) How well does the model perform?
&lt;/p&gt;

&lt;p&gt;
To address the first model characteristic, 
models are helpful in expanding our knowledge and challenging our
hypotheses.  However, if they are keying in on variables in a nonsensical way, 
then it is usually an indication that something has gone wrong.   
&lt;/p&gt;



&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R7&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R7&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# Evaluate Model against Holdout &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;## create test data set&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# data set&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train[test_train&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                   &lt;span class=&quot;hl opt&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_train)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;remove_vars ]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# label (xgboost requires labels that start with 0)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;test_label&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(label)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# predict holdout&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;holdout_predict&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(best_model_reduced, test[,top_features])&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;## create data set for evaluation&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# convert holdout prediction to something usable&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(holdout_predict,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;byrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred_label&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pred,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,which.max)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pred)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;description&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pred)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;predicted_label&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;pred_label&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# bring in test label (remember we need to add 1 back)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;actual_label&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;hl std&quot;&gt;test_label&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# add on message for evaluating misclassifications&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
 &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(msg)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# add on repeat messages&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
 &lt;span class=&quot;hl std&quot;&gt;test_train&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( partition&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'holdout'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unlist&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;## take a look at feature importance&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n_features&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;importance&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xgb.importance&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;feature_names&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= best_model)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;importance.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(importance&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;slice_head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n_features),&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;reorder&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Feature,Gain),Gain))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;steelblue&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;coord_flip&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Gain&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggtitle&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Gain from Top 20 Features&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;img src=&quot;http://meanmean.me/images/articles/importance.png&quot; class=&quot;article&quot;&gt;

&lt;p&gt;
The initial way I check if a model makes sense is through feature importance. 
The features here should align with our understanding fo the phenomena we are modeling.
If a feature is suprising, then we should do a further investigation into how that feature
relates with the response.
&lt;/p&gt;

&lt;p&gt; 
Here the most important variables are primarily game term specific features.  
This ranking makes sense since variations of similar terms are captured by these 
features, and are present in almost all of these messages.  They are also specifically
created to relate to different types of content.
&lt;/p&gt;

&lt;p&gt;
Specifically '__job_points' would relate primarily to people selling job points (a sort of RPG leveling system).
Likewise, '__jobs' captures a large number of variations of specific jobs (think D&amp;amp;D classes),
that would be requested in content messages.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R8&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R8&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;## get confusion matrix&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;confusionMatrix&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;table&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;label_desc&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;desc[pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;actual_label],&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;label_desc&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;desc[pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;predicted_label]) )&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;png&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;confusion.png&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;width&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;640&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(confusionMatrix,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Var1,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Var2,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Freq))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;geom_tile&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_text&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Freq))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Actual&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Predicted&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;scale_fill_gradient&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;low&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;white&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;high&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;orange&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;dev.off&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;## get tpr and and fpr&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# calc tpr and fpr&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;tpr&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( actual_label )&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;dplyr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;summarize&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;tpr&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(actual_label&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;predicted_label)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;tnr&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( i&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;NROW&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tpr) ) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;tnr[i]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( (pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;predicted_label&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;i)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;(pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;actual_label&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;i))&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( pred&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;actual_label&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;i )&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;tpr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;tnr&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;tnr&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;tpr&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;actual_label&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;description&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;


&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;&lt;tr&gt; &lt;th&gt; Model &lt;/th&gt; &lt;th&gt; Log Loss &lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt;  &lt;td&gt; Full &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       89% &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt;  &lt;td&gt; Reduced &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;    95% &lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;



&lt;p&gt;
The second model characteristic, model performance, is evaluated through
a confusion matrix, model accuracy, and per class True Positive Rates (TPR).
&lt;/p&gt;

&lt;img src=&quot;http://meanmean.me/images/articles/confusion.png&quot; class=&quot;article&quot;&gt;

&lt;p&gt;
The confusion matrix shows generally good performance, where the diagonal 
clearly dominates the off-diagonal miss-classifications for all classes.
Likewise the model accuracy is 89% for unique messages, and 95% when accounting
for duplicate or repeated messages.&lt;/p&gt;

&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;&lt;tr&gt; &lt;th&gt;  &lt;/th&gt; &lt;th&gt; Message Category &lt;/th&gt; &lt;th&gt; TPR &lt;/th&gt; &lt;th&gt; TNR &lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 1 &lt;/td&gt; &lt;td&gt; Content &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.91 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.97 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 2 &lt;/td&gt; &lt;td&gt; RMT &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 1.00 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 1.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 3 &lt;/td&gt; &lt;td&gt; Merc &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.89 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.96 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 4 &lt;/td&gt; &lt;td&gt; JP Merc &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.99 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.99 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 5 &lt;/td&gt; &lt;td&gt; Chat &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.81 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.98 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 6 &lt;/td&gt; &lt;td&gt; Selling (non-Merc) &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.84 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.98 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 7 &lt;/td&gt; &lt;td&gt; Buying (non-Merc) &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.67 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.99 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; 8 &lt;/td&gt; &lt;td&gt; Unknown &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.67 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 1.00 &lt;/td&gt; &lt;/tr&gt;
   &lt;/tbody&gt;&lt;/table&gt;
   
&lt;p&gt;
The per class TPR and FPR rates also look
fairly good except for the categories 'Unknown' and 'Buying (non-Merc)'.  I'm
not too concerned about the 'Unknown' category since it's both fairly rare and a general 
catch-all of strange messages.&lt;/p&gt;
&lt;p&gt; 'Buying (non-Merc)' is a bit more of an issue.
The primary separaters between 'Merc' and the '(non-Merc)' categories are the
types of content or items that are being bought or sold.  As an example, a 
&lt;i&gt;Malignance Tabard&lt;/i&gt; is only obtained by doing specific content, it cannot
directly be bought or sold buy a player.  Therefore it is a merc item.  But a 
&lt;i&gt;Raetic Rod +1&lt;/i&gt; can directly be bought or sold buy a player, so it would be
a 'Non-Merc' item.  The fix to this would be to create more game specific features to capture this, or to just to label more messages so XGBoost can identify these items on its own.
&lt;/p&gt;




&lt;h2&gt;Model Deployment in Lua&lt;/h2&gt;

&lt;p&gt;
To deploy the model, I need to get it out of R and into Lua.  This is a five step process:
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Dump the XGBoost model to a text format&lt;/li&gt;
  &lt;li&gt;Read in the trees from the XGBoost dump&lt;/li&gt;
  &lt;li&gt;Wait for a new Message&lt;/li&gt;
  &lt;li&gt;Extract features from message&lt;/li&gt;
  &lt;li&gt;Score the message&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
I have already written all the code to do this in a 
&lt;a href=&quot;https://github.com/jlisic/shout_ml/blob/main/xgboost_score.lua&quot;&gt;github repo&lt;/a&gt; function.  This also includes a previous model dump from XGBoost.
&lt;/p&gt;

&lt;p&gt;
The first step is extremely easy, we just grab our model and dump it to a text file.
Note that we retrain the model using all our data at this point to get the best
possible fit out of all of our data.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;javascript:showhide(&amp;#39;R9&amp;#39;)&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R9&quot; style=&quot;display:none;&quot;&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# Retrain on all data&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;best_model_full&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;xgboost&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test[,top_features], train[,top_features]),&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(test_label,train_label),&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= param,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;nthread&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;nrounds&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=best_model_cv&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;nround,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;verbose&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# Dump Model &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;####################################&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# write for windower package&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;xgb.dump&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(best_model_full,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fname&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'ffxi_spam_model.txt'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;dump_format&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# csv to identify key variables&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;write.csv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( test_train[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,top_features] ,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'example.csv'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;row.names&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;
The dump looks something like this (note this is from an earlier version of the same model):
&lt;/p&gt;

&lt;pre&gt;booster[0]
0:[f11&amp;lt;0.5] yes=1,no=2,missing=1
  1:[f194&amp;lt;0.5] yes=3,no=4,missing=3
    3:[f211&amp;lt;0.5] yes=5,no=6,missing=5
      5:[f215&amp;lt;0.5] yes=7,no=8,missing=7
        7:[f64&amp;lt;0.5] yes=11,no=12,missing=11
          11:[f197&amp;lt;0.5] yes=15,no=16,missing=15
            15:[f76&amp;lt;0.5] yes=23,no=24,missing=23
              23:[f210&amp;lt;0.5] yes=27,no=28,missing=27
                27:leaf=-0.0266666692
                28:leaf=-0.00392156886
              24:[f210&amp;lt;0.5] yes=29,no=30,missing=29
                29:leaf=-0.0129032256
                30:leaf=-0.0380228125
            16:leaf=0.11343284
          12:[f129&amp;lt;0.5] yes=17,no=18,missing=17
            17:[f195&amp;lt;0.5] yes=25,no=26,missing=25
              25:[f201&amp;lt;0.5] yes=31,no=32,missing=31
                31:leaf=0.0990595669
                32:leaf=-0.0298507456
              26:leaf=-0.037894737
            18:leaf=0.259561151
        8:leaf=-0.0559531562
      6:[f215&amp;lt;0.5] yes=9,no=10,missing=9
        9:[f210&amp;lt;0.5] yes=13,no=14,missing=13
          13:[f129&amp;lt;0.5] yes=19,no=20,missing=19
            19:leaf=0.164210528
            20:leaf=-0.00784313772
          14:[f129&amp;lt;0.5] yes=21,no=22,missing=21
            21:leaf=0.189473689
            22:leaf=0.323467851
        10:leaf=-0.0519774035
    4:leaf=-0.0562807731
  2:leaf=0.366163135
...
&lt;/pre&gt;

&lt;p&gt;
This is in fact a single tree, given that we ran 200 iterations and there are
eight categories to classify into, that gives is 1,600 trees that we need to 
evaluate in lua.
This may seem a little daunting, but since these are trees it is fairly simple
to write a recursive algorithm that will parse these structures.
To do this, we should note that each line of the XGBoost dump has one of three possible line types that describe the tree structure:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt; &lt;i&gt;booster[m]&lt;/i&gt; denotes the 'm'-th tree.&lt;/li&gt;
  &lt;li&gt; &lt;i&gt;k:[f(xxx) &amp;lt; t] yes=h,no=i,missing=j&lt;/i&gt; is a branch of the tree.
  &lt;ul&gt;
  &lt;li&gt; &lt;i&gt;i&lt;/i&gt; is the index of the node within this tree.&lt;/li&gt;
  &lt;li&gt; &lt;i&gt;[f(xxx) &amp;lt; t]&lt;/i&gt; is an inequality determining if the tree will go to 'yes' &lt;i&gt;f(xxx)&lt;/i&gt; is the feature in order of its input data set starting at 0, and &lt;i&gt;t&lt;/i&gt; is just the value the feature is being compared against.&lt;/li&gt;
   &lt;i&gt;j&lt;/i&gt;, &lt;i&gt;k&lt;/i&gt;, and &lt;i&gt;l&lt;/i&gt; are references to the node to move to given the state of the inequality for a particular row of the data set being evaluated.
  &lt;/ul&gt;
  &lt;/li&gt;&lt;li&gt; 'i:leaf=s' is a leaf node with index &lt;i&gt;i&lt;/i&gt; and log-odd &lt;i&gt;s&lt;/i&gt;&lt;/li&gt;.
&lt;/ol&gt;


&lt;p&gt;
In the example lua the parsing of the tree is accomplished in the &lt;i&gt;read_booster&lt;/i&gt; function
in 
&lt;a href=&quot;https://github.com/jlisic/shout_ml/blob/main/xgboost_score.lua&quot;&gt;xgboost_score.lua&lt;/a&gt;.  
It simply creates an implicit tree structure using lua arrays.
Each element of the array aligns with the node index in the tree.
I do add one to each index of both the features and nodes since Lua starts
indexes at 0 unlike XGBoost (written in C++).
Each element also contains the following components: 

&lt;/p&gt;&lt;ul&gt;
&lt;li&gt; &lt;i&gt;feature&lt;/i&gt; that maps to the &lt;i&gt;(xxx)&lt;/i&gt; part of &lt;i&gt;f(xxx)&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt; &lt;i&gt;lt_value&lt;/i&gt; that aligns with the value &lt;i&gt;t&lt;/i&gt; above.&lt;/li&gt;
&lt;li&gt; &lt;i&gt;yes_node&lt;/i&gt; that aligns with the value &lt;i&gt;j&lt;/i&gt; above.&lt;/li&gt;
&lt;li&gt; &lt;i&gt;no_node&lt;/i&gt; that aligns with the value &lt;i&gt;k&lt;/i&gt; above.&lt;/li&gt;
&lt;li&gt; &lt;i&gt;missing_node&lt;/i&gt; that aligns with the value &lt;i&gt;l&lt;/i&gt; above.&lt;/li&gt;
&lt;li&gt; &lt;i&gt;leaf&lt;/i&gt; the log-odds stored in the terminal node.&lt;/li&gt;
&lt;/ul&gt;
This is duplicated for all 1,600 trees and internally consumes no more than 8MB of data.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
When a new message comes in we need to extract the features from the message to map
to the features created in R.  To do this we just use the regular expressions
library that windower provides for lua.  Here our new message is passed in as
&lt;i&gt;clean_text&lt;/i&gt; after removing non-ascii text and translating all auto-translate
functions to english.  As an example, this is the &lt;i&gt;__gil&lt;/i&gt; feature we created earlier.
It uses the exact same regular expression to achieve a match.
&lt;/p&gt;
&lt;pre&gt;if windower.regex.match(clean_text, &quot;[0-9]+(k|m|gil)&quot;) ~= nil then 
  eval_features[i] = 1 
end
&lt;/pre&gt;

&lt;p&gt;
Our next step is scoring the incomming message based on the features we just generated.
As it turned out, this step was one of the harder bits of this project, not because of
the technical difficulties, but in figuring out how XGBoost actually created the score.
&lt;/p&gt;

&lt;p&gt;
When a new message comes in, it has it's features extracted and then we lookup in
each tree for a particular message category to figure out what score it gets for 
each of these message categories.
&lt;/p&gt;

&lt;p&gt;
The lookup step is done through a recursive function I created called &lt;i&gt;eval_tree&lt;/i&gt;.
It simply iterates over a given tree using the structure we created while reading
the original tree in.  As an initial condition it checks if a given node in the tree is a branch
or a leaf.  If we are at a leaf we are done and return our log-odds value, else we evaluate if 
the feature extracted from the message has a value less than our stored &lt;i&gt;lt_value&lt;/i&gt; from our
XGBoost dump.  If it does, then we go to the &lt;i&gt;yes_node&lt;/i&gt;.  If the value is missing we follow the default value, equivalent to the &lt;i&gt;yes_node&lt;/i&gt;.  Otherwise, we go to the &lt;i&gt;no_node&lt;/i&gt;.  A recursive call is then made to evaluate the selected next node.

&lt;/p&gt;&lt;pre&gt;eval_tree = function( cur_node, booster, eval)

   -- Is this a branch, branches have a conditional
   if booster[cur_node].lt_value ~= nil then
   
     -- this is a branch, let's check what direction to go
     if( eval[ booster[cur_node].feature ] &amp;lt; booster[cur_node].lt_value ) then
       cur_node = booster[cur_node].yes_node
     elseif( eval[ booster[cur_node].feature ] == 0 ) then
       cur_node = booster[cur_node].missing_node
     else
       cur_node = booster[cur_node].no_node
     end
     
   else
     return( booster[cur_node].leaf)
   end

   return( eval_tree(cur_node, booster, eval) )

end
&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;
Remember that each of our 1,600 trees belong to one of eight message categories.
So for every message we get 200 values from the leaf nodes associated with a given
message category.  Each of these values, which are log-odds are then summed up and
added to a default value of 0.5.  This process is implemented through the 
&lt;i&gt; parse tree function&lt;/i&gt; in my Lua code. &lt;p&gt;

&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-lua&quot;&gt;
--parse tree
eval_phrase = function( value, booster,classes )  
  xgboost_class = 0 
  score={}
  for i = 1,classes do
    score[i] = 0.5
  end

  for i = 1,table.getn(booster) do
    xgboost_class = xgboost_class + 1
    
    -- iterate over all classes
    if xgboost_class &amp;gt; classes then 
      xgboost_class = 1
    end
    score[xgboost_class] = score[xgboost_class] + eval_tree( 1, booster[i], value) 

  end

  -- combine score
  sum_all = 0
  for i = 1,classes do
    sum_all = sum_all + math.exp(score[i])
  end
  for i = 1,classes do
    score[i] = math.exp(score[i])/sum_all
  end

  return(score)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt; The 0.5 in the log-odds sum was a bit of mystery to figure out, as I had to search
through all the XGBoost documentation and ended up diving into the source code to
figure out why the sum of of log-odds was not giving me the right value.  However,
it makes sense since it provides a &lt;i&gt;prior&lt;/i&gt; to dampen extreme differences in log-odds
when there are few informative trees.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt; The final step is to use the softmax function to determine the probability that a given message belongs to a particular class.  Here, I've just let the sum of log-odds of message category &lt;span class=&quot;MathJax_Preview&quot; style=&quot;color: inherit; display: none;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot; tabindex=&quot;0&quot; data-mathml=&quot;&amp;lt;math xmlns=&amp;quot;http://www.w3.org/1998/Math/MathML&amp;quot;&amp;gt;&amp;lt;mi&amp;gt;g&amp;lt;/mi&amp;gt;&amp;lt;/math&amp;gt;&quot; role=&quot;presentation&quot; style=&quot;font-size: 100%; display: inline-block; position: relative;&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.116ex&quot; height=&quot;1.796ex&quot; viewBox=&quot;0 -499.7 480.5 773.1&quot; role=&quot;img&quot; focusable=&quot;false&quot; style=&quot;vertical-align: -0.635ex;&quot; aria-hidden=&quot;true&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use href=&quot;#MJMATHI-67&quot; x=&quot;0&quot; y=&quot;0&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;span class=&quot;MJX_Assistive_MathML&quot; role=&quot;presentation&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;mi&gt;g&lt;/mi&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;script type=&quot;math/tex&quot; id=&quot;MathJax-Element-2&quot;&gt;g&lt;/script&gt; be &lt;span class=&quot;MathJax_Preview&quot; style=&quot;color: inherit; display: none;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot; tabindex=&quot;0&quot; data-mathml=&quot;&amp;lt;math xmlns=&amp;quot;http://www.w3.org/1998/Math/MathML&amp;quot;&amp;gt;&amp;lt;msub&amp;gt;&amp;lt;mi&amp;gt;S&amp;lt;/mi&amp;gt;&amp;lt;mi&amp;gt;g&amp;lt;/mi&amp;gt;&amp;lt;/msub&amp;gt;&amp;lt;/math&amp;gt;&quot; role=&quot;presentation&quot; style=&quot;font-size: 100%; display: inline-block; position: relative;&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.446ex&quot; height=&quot;2.636ex&quot; viewBox=&quot;0 -771.1 1053.3 1135.1&quot; role=&quot;img&quot; focusable=&quot;false&quot; style=&quot;vertical-align: -0.845ex;&quot; aria-hidden=&quot;true&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use href=&quot;#MJMATHI-53&quot; x=&quot;0&quot; y=&quot;0&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; href=&quot;#MJMATHI-67&quot; x=&quot;867&quot; y=&quot;-213&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;span class=&quot;MJX_Assistive_MathML&quot; role=&quot;presentation&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;msub&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mi&gt;g&lt;/mi&gt;&lt;/msub&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;script type=&quot;math/tex&quot; id=&quot;MathJax-Element-3&quot;&gt;S_g&lt;/script&gt;.  Finally, to end up with our probability estimate with softmax
we just need to feed our sum of squares plus our prior into the softmax function:
&lt;/p&gt;

&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;24.433ex&quot; height=&quot;7.343ex&quot; style=&quot;vertical-align: -3.505ex;&quot; viewBox=&quot;0 -1652.5 10519.8 3161.4&quot; role=&quot;img&quot; focusable=&quot;false&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; aria-labelledby=&quot;MathJax-SVG-1-Title&quot;&gt;
&lt;title id=&quot;MathJax-SVG-1-Title&quot;&gt;upper P Subscript g Baseline equals StartFraction exp left-parenthesis 0.5 plus upper S Subscript g Baseline right-parenthesis Over sigma-summation Underscript g Overscript upper G Endscripts exp left-parenthesis 0.5 plus upper S Subscript g Baseline right-parenthesis EndFraction&lt;/title&gt;
&lt;defs aria-hidden=&quot;true&quot;&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMATHI-67&quot; d=&quot;M311 43Q296 30 267 15T206 0Q143 0 105 45T66 160Q66 265 143 353T314 442Q361 442 401 394L404 398Q406 401 409 404T418 412T431 419T447 422Q461 422 470 413T480 394Q480 379 423 152T363 -80Q345 -134 286 -169T151 -205Q10 -205 10 -137Q10 -111 28 -91T74 -71Q89 -71 102 -80T116 -111Q116 -121 114 -130T107 -144T99 -154T92 -162L90 -164H91Q101 -167 151 -167Q189 -167 211 -155Q234 -144 254 -122T282 -75Q288 -56 298 -13Q311 35 311 43ZM384 328L380 339Q377 350 375 354T369 368T359 382T346 393T328 402T306 405Q262 405 221 352Q191 313 171 233T151 117Q151 38 213 38Q269 38 323 108L331 118L384 328Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-65&quot; d=&quot;M28 218Q28 273 48 318T98 391T163 433T229 448Q282 448 320 430T378 380T406 316T415 245Q415 238 408 231H126V216Q126 68 226 36Q246 30 270 30Q312 30 342 62Q359 79 369 104L379 128Q382 131 395 131H398Q415 131 415 121Q415 117 412 108Q393 53 349 21T250 -11Q155 -11 92 58T28 218ZM333 275Q322 403 238 411H236Q228 411 220 410T195 402T166 381T143 340T127 274V267H333V275Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-78&quot; d=&quot;M201 0Q189 3 102 3Q26 3 17 0H11V46H25Q48 47 67 52T96 61T121 78T139 96T160 122T180 150L226 210L168 288Q159 301 149 315T133 336T122 351T113 363T107 370T100 376T94 379T88 381T80 383Q74 383 44 385H16V431H23Q59 429 126 429Q219 429 229 431H237V385Q201 381 201 369Q201 367 211 353T239 315T268 274L272 270L297 304Q329 345 329 358Q329 364 327 369T322 376T317 380T310 384L307 385H302V431H309Q324 428 408 428Q487 428 493 431H499V385H492Q443 385 411 368Q394 360 377 341T312 257L296 236L358 151Q424 61 429 57T446 50Q464 46 499 46H516V0H510H502Q494 1 482 1T457 2T432 2T414 3Q403 3 377 3T327 1L304 0H295V46H298Q309 46 320 51T331 63Q331 65 291 120L250 175Q249 174 219 133T185 88Q181 83 181 74Q181 63 188 55T206 46Q208 46 208 23V0H201Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-70&quot; d=&quot;M36 -148H50Q89 -148 97 -134V-126Q97 -119 97 -107T97 -77T98 -38T98 6T98 55T98 106Q98 140 98 177T98 243T98 296T97 335T97 351Q94 370 83 376T38 385H20V408Q20 431 22 431L32 432Q42 433 61 434T98 436Q115 437 135 438T165 441T176 442H179V416L180 390L188 397Q247 441 326 441Q407 441 464 377T522 216Q522 115 457 52T310 -11Q242 -11 190 33L182 40V-45V-101Q182 -128 184 -134T195 -145Q216 -148 244 -148H260V-194H252L228 -193Q205 -192 178 -192T140 -191Q37 -191 28 -194H20V-148H36ZM424 218Q424 292 390 347T305 402Q234 402 182 337V98Q222 26 294 26Q345 26 384 80T424 218Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-35&quot; d=&quot;M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;
&lt;path stroke-width=&quot;1&quot; id=&quot;E1-MJMATHI-47&quot; d=&quot;M50 252Q50 367 117 473T286 641T490 704Q580 704 633 653Q642 643 648 636T656 626L657 623Q660 623 684 649Q691 655 699 663T715 679T725 690L740 705H746Q760 705 760 698Q760 694 728 561Q692 422 692 421Q690 416 687 415T669 413H653Q647 419 647 422Q647 423 648 429T650 449T651 481Q651 552 619 605T510 659Q492 659 471 656T418 643T357 615T294 567T236 496T189 394T158 260Q156 242 156 221Q156 173 170 136T206 79T256 45T308 28T353 24Q407 24 452 47T514 106Q517 114 529 161T541 214Q541 222 528 224T468 227H431Q425 233 425 235T427 254Q431 267 437 273H454Q494 271 594 271Q634 271 659 271T695 272T707 272Q721 272 721 263Q721 261 719 249Q714 230 709 228Q706 227 694 227Q674 227 653 224Q646 221 643 215T629 164Q620 131 614 108Q589 6 586 3Q584 1 581 1Q571 1 553 21T530 52Q530 53 528 52T522 47Q448 -22 322 -22Q201 -22 126 55T50 252Z&quot;&gt;&lt;/path&gt;
&lt;/defs&gt;
&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot; aria-hidden=&quot;true&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMATHI-50&quot; x=&quot;0&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#E1-MJMATHI-67&quot; x=&quot;908&quot; y=&quot;-213&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-3D&quot; x=&quot;1360&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(2138,0)&quot;&gt;
&lt;g transform=&quot;translate(397,0)&quot;&gt;
&lt;rect stroke=&quot;none&quot; width=&quot;7863&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;
&lt;g transform=&quot;translate(999,815)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-65&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-78&quot; x=&quot;444&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-70&quot; x=&quot;973&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(1529,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-28&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(389,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-30&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-2E&quot; x=&quot;500&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-35&quot; x=&quot;779&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-2B&quot; x=&quot;1501&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(2502,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMATHI-53&quot; x=&quot;0&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#E1-MJMATHI-67&quot; x=&quot;867&quot; y=&quot;-213&quot;&gt;&lt;/use&gt;
&lt;/g&gt;
&lt;/g&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-29&quot; x=&quot;3945&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;g transform=&quot;translate(60,-997)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJSZ1-2211&quot; x=&quot;0&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#E1-MJMATHI-47&quot; x=&quot;1494&quot; y=&quot;675&quot;&gt;&lt;/use&gt;
 &lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#E1-MJMATHI-67&quot; x=&quot;1494&quot; y=&quot;-405&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(1879,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-65&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-78&quot; x=&quot;444&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-70&quot; x=&quot;973&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;/g&gt;
&lt;g transform=&quot;translate(3408,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-28&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(389,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-30&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-2E&quot; x=&quot;500&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-35&quot; x=&quot;779&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-2B&quot; x=&quot;1501&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;g transform=&quot;translate(2502,0)&quot;&gt;
 &lt;use xlink:href=&quot;#E1-MJMATHI-53&quot; x=&quot;0&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
 &lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#E1-MJMATHI-67&quot; x=&quot;867&quot; y=&quot;-213&quot;&gt;&lt;/use&gt;
&lt;/g&gt;
&lt;/g&gt;
 &lt;use xlink:href=&quot;#E1-MJMAIN-29&quot; x=&quot;3945&quot; y=&quot;0&quot;&gt;&lt;/use&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;


&lt;p&gt;
Now we have probabilities for each class of our message, and can block the message types
we don't want to see. The result can be seen below where the message screen on the left
is fairly free of spammy messages (Necessary), and the screen on the right has primarily
spammy messages (Sufficient).
&lt;/p&gt;

&lt;div&gt;
&lt;img src=&quot;http://meanmean.me/images/articles/ffxi_spam.png&quot; class=&quot;article&quot; &gt;
&lt;div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;
Through this blog post we have gone through quite a journey.  We started off with a problem of 
message spam, used our ML insights to come up with a quick model, and produced a meaningful solution.  The model attains a 95% accuracy rate for all messages, and fairly good TPR and 
FPR rates on a per category basis.  A few more features could probably be generated to
improve performance, but this serves as an excellent initial solution.
&lt;/p&gt;

&lt;p&gt;
From my github stats, it looks like there have been over 200 users of this plugin,
as of December 1st and hopefully more as I push out new features like automatic model
updating.
&lt;/p&gt;

&lt;p&gt;
Again, happy holidays and let's see your holiday ML projects!
&lt;/p&gt;


&lt;p&gt;
&lt;small&gt;All FFXI content and images © 2002-2020 SQUARE ENIX CO., LTD.
  &lt;br/&gt;FINAL FANTASY is a registered trademark of SQUARE ENIX CO., LTD.
&lt;/small&gt;
&lt;/p&gt;
</description>
        <pubDate>Mon, 21 Dec 2020 00:00:00 -0500</pubDate>
        <link>http://meanmean.me/2020/12/21/Cleaning-Up-SPAM-with-NLP.html</link>
        <guid isPermaLink="true">http://meanmean.me/2020/12/21/Cleaning-Up-SPAM-with-NLP.html</guid>
        
        
      </item>
    
      <item>
        <title>Grand Central Dispatch</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
.MathJax_SVG_LineBox {display: table!important}
.MathJax_SVG_LineBox span {display: table-cell!important; width: 10000em!important; min-width: 0; max-width: none; padding: 0; border: 0; margin: 0}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3A3&quot; d=&quot;M666 247Q664 244 652 126T638 4V0H351Q131 0 95 0T57 5V6Q54 12 57 17L73 36Q89 54 121 90T182 159L305 299L56 644L55 658Q55 677 60 681Q63 683 351 683H638V679Q640 674 652 564T666 447V443H626V447Q618 505 604 543T559 605Q529 626 478 631T333 637H294H189L293 494Q314 465 345 422Q400 346 400 340Q400 338 399 337L154 57Q407 57 428 58Q476 60 508 68T551 83T575 103Q595 125 608 162T624 225L626 251H666V247Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6C&quot; d=&quot;M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-68&quot; d=&quot;M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-41&quot; d=&quot;M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6C&quot; d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-53&quot; d=&quot;M55 507Q55 590 112 647T243 704H257Q342 704 405 641L426 672Q431 679 436 687T446 700L449 704Q450 704 453 704T459 705H463Q466 705 472 699V462L466 456H448Q437 456 435 459T430 479Q413 605 329 646Q292 662 254 662Q201 662 168 626T135 542Q135 508 152 480T200 435Q210 431 286 412T370 389Q427 367 463 314T500 191Q500 110 448 45T301 -21Q245 -21 201 -4T140 27L122 41Q118 36 107 21T87 -7T78 -21Q76 -22 68 -22H64Q61 -22 55 -16V101Q55 220 56 222Q58 227 76 227H89Q95 221 95 214Q95 182 105 151T139 90T205 42T305 24Q352 24 386 62T420 155Q420 198 398 233T340 281Q284 295 266 300Q261 301 239 306T206 314T174 325T141 343T112 367T85 402Q55 451 55 507Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-57&quot; d=&quot;M792 683Q810 680 914 680Q991 680 1003 683H1009V637H996Q931 633 915 598Q912 591 863 438T766 135T716 -17Q711 -22 694 -22Q676 -22 673 -15Q671 -13 593 231L514 477L435 234Q416 174 391 92T358 -6T341 -22H331Q314 -21 310 -15Q309 -14 208 302T104 622Q98 632 87 633Q73 637 35 637H18V683H27Q69 681 154 681Q164 681 181 681T216 681T249 682T276 683H287H298V637H285Q213 637 213 620Q213 616 289 381L364 144L427 339Q490 535 492 546Q487 560 482 578T475 602T468 618T461 628T449 633T433 636T408 637H380V683H388Q397 680 508 680Q629 680 650 683H660V637H647Q576 637 576 619L727 146Q869 580 869 600Q869 605 863 612T839 627T794 637H783V683H792Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-50&quot; d=&quot;M130 622Q123 629 119 631T103 634T60 637H27V683H214Q237 683 276 683T331 684Q419 684 471 671T567 616Q624 563 624 489Q624 421 573 372T451 307Q429 302 328 301H234V181Q234 62 237 58Q245 47 304 46H337V0H326Q305 3 182 3Q47 3 38 0H27V46H60Q102 47 111 49T130 61V622ZM507 488Q507 514 506 528T500 564T483 597T450 620T397 635Q385 637 307 637H286Q237 637 234 628Q231 624 231 483V342H302H339Q390 342 423 349T481 382Q507 411 507 488Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5B&quot; d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5D&quot; d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3C3&quot; d=&quot;M184 -11Q116 -11 74 34T31 147Q31 247 104 333T274 430Q275 431 414 431H552Q553 430 555 429T559 427T562 425T565 422T567 420T569 416T570 412T571 407T572 401Q572 357 507 357Q500 357 490 357T476 358H416L421 348Q439 310 439 263Q439 153 359 71T184 -11ZM361 278Q361 358 276 358Q152 358 115 184Q114 180 114 178Q106 141 106 117Q106 67 131 47T188 26Q242 26 287 73Q316 103 334 153T356 233T361 278Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6B&quot; d=&quot;M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-26&quot; d=&quot;M156 540Q156 620 201 668T302 716Q354 716 377 671T401 578Q401 505 287 386L274 373Q309 285 416 148L429 132L437 142Q474 191 543 309L562 341V349Q562 368 541 376T498 385H493V431H502L626 428Q709 428 721 431H727V385H712Q688 384 669 379T639 369T618 354T603 337T591 316T578 295Q537 223 506 176T464 117T454 104Q454 102 471 85T497 62Q543 24 585 24Q618 24 648 48T682 113V121H722V112Q721 94 714 75T692 32T646 -7T574 -22Q491 -19 414 42L402 51L391 42Q312 -22 224 -22Q144 -22 93 25T42 135Q42 153 46 169T55 197T74 225T96 249T125 278T156 308L195 347L190 360Q185 372 182 382T174 411T165 448T159 491T156 540ZM361 576Q361 613 348 646T305 679Q272 679 252 649T232 572Q232 497 255 426L259 411L267 420Q361 519 361 576ZM140 164Q140 103 167 64T240 24Q271 24 304 36T356 61T374 77Q295 156 235 262L220 292L210 310L193 293Q177 277 169 268T151 229T140 164Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2260&quot; d=&quot;M166 -215T159 -215T147 -212T141 -204T139 -197Q139 -190 144 -183L306 133H70Q56 140 56 153Q56 168 72 173H327L406 327H72Q56 332 56 347Q56 360 70 367H426Q597 702 602 707Q605 716 618 716Q625 716 630 712T636 703T638 696Q638 692 471 367H707Q722 359 722 347Q722 336 708 328L451 327L371 173H708Q722 163 722 153Q722 140 707 133H351Q175 -210 170 -212Q166 -215 159 -215Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239B&quot; d=&quot;M837 1154Q843 1148 843 1145Q843 1141 818 1106T753 1002T667 841T574 604T494 299Q417 -84 417 -609Q417 -641 416 -647T411 -654Q409 -655 366 -655Q299 -655 297 -654Q292 -652 292 -643T291 -583Q293 -400 304 -242T347 110T432 470T574 813T785 1136Q787 1139 790 1142T794 1147T796 1150T799 1152T802 1153T807 1154T813 1154H819H837Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239D&quot; d=&quot;M843 -635Q843 -638 837 -644H820Q801 -644 800 -643Q792 -635 785 -626Q684 -503 605 -363T473 -75T385 216T330 518T302 809T291 1093Q291 1144 291 1153T296 1164Q298 1165 366 1165Q409 1165 411 1164Q415 1163 416 1157T417 1119Q417 529 517 109T833 -617Q843 -631 843 -635Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239C&quot; d=&quot;M413 -9Q412 -9 407 -9T388 -10T354 -10Q300 -10 297 -9Q294 -8 293 -5Q291 5 291 127V300Q291 602 292 605L296 609Q298 610 366 610Q382 610 392 610T407 610T412 609Q416 609 416 592T417 473V127Q417 -9 413 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-33&quot; d=&quot;M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-D7&quot; d=&quot;M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-58&quot; d=&quot;M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239E&quot; d=&quot;M31 1143Q31 1154 49 1154H59Q72 1154 75 1152T89 1136Q190 1013 269 873T401 585T489 294T544 -8T572 -299T583 -583Q583 -634 583 -643T577 -654Q575 -655 508 -655Q465 -655 463 -654Q459 -653 458 -647T457 -609Q457 -58 371 340T100 1037Q87 1059 61 1098T31 1143Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A0&quot; d=&quot;M56 -644H50Q31 -644 31 -635Q31 -632 37 -622Q69 -579 100 -527Q286 -228 371 170T457 1119Q457 1161 462 1164Q464 1165 520 1165Q575 1165 577 1164Q582 1162 582 1153T583 1093Q581 910 570 752T527 400T442 40T300 -303T89 -626Q78 -640 75 -642T61 -644H56Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239F&quot; d=&quot;M579 -9Q578 -9 573 -9T554 -10T520 -10Q466 -10 463 -9Q460 -8 459 -5Q457 5 457 127V300Q457 602 458 605L462 609Q464 610 532 610Q548 610 558 610T573 610T578 609Q582 609 582 592T583 473V127Q583 -9 579 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-63&quot; d=&quot;M370 305T349 305T313 320T297 358Q297 381 312 396Q317 401 317 402T307 404Q281 408 258 408Q209 408 178 376Q131 329 131 219Q131 137 162 90Q203 29 272 29Q313 29 338 55T374 117Q376 125 379 127T395 129H409Q415 123 415 120Q415 116 411 104T395 71T366 33T318 2T249 -11Q163 -11 99 53T34 214Q34 318 99 383T250 448T370 421T404 357Q404 334 387 320Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6F&quot; d=&quot;M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-76&quot; d=&quot;M338 431Q344 429 422 429Q479 429 503 431H508V385H497Q439 381 423 345Q421 341 356 172T288 -2Q283 -11 263 -11Q244 -11 239 -2Q99 359 98 364Q93 378 82 381T43 385H19V431H25L33 430Q41 430 53 430T79 430T104 429T122 428Q217 428 232 431H240V385H226Q187 384 184 370Q184 366 235 234L286 102L377 341V349Q377 363 367 372T349 383T335 385H331V431H338Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5E&quot; d=&quot;M112 560L249 694L257 686Q387 562 387 560L361 531Q359 532 303 581L250 627L195 580Q182 569 169 557T148 538L140 532Q138 530 125 546L112 560Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ3-2C6&quot; d=&quot;M1439 564Q1434 564 1080 631T722 698Q719 698 362 631Q7 564 4 564L0 583Q-4 602 -4 603L720 772L1083 688Q1446 603 1447 603Q1447 602 1443 583L1439 564Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-AF&quot; d=&quot;M69 544V590H430V544H69Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6E&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6D&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-73&quot; d=&quot;M295 316Q295 356 268 385T190 414Q154 414 128 401Q98 382 98 349Q97 344 98 336T114 312T157 287Q175 282 201 278T245 269T277 256Q294 248 310 236T342 195T359 133Q359 71 321 31T198 -10H190Q138 -10 94 26L86 19L77 10Q71 4 65 -1L54 -11H46H42Q39 -11 33 -5V74V132Q33 153 35 157T45 162H54Q66 162 70 158T75 146T82 119T101 77Q136 26 198 26Q295 26 295 104Q295 133 277 151Q257 175 194 187T111 210Q75 227 54 256T33 318Q33 357 50 384T93 424T143 442T187 447H198Q238 447 268 432L283 424L292 431Q302 440 314 448H322H326Q329 448 335 442V310L329 304H301Q295 310 295 316Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-74&quot; d=&quot;M27 422Q80 426 109 478T141 600V615H181V431H316V385H181V241Q182 116 182 100T189 68Q203 29 238 29Q282 29 292 100Q293 108 293 146V181H333V146V134Q333 57 291 17Q264 -10 221 -10Q187 -10 162 2T124 33T105 68T98 100Q97 107 97 248V385H18V422H27Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3B2&quot; d=&quot;M29 -194Q23 -188 23 -186Q23 -183 102 134T186 465Q208 533 243 584T309 658Q365 705 429 705H431Q493 705 533 667T573 570Q573 465 469 396L482 383Q533 332 533 252Q533 139 448 65T257 -10Q227 -10 203 -2T165 17T143 40T131 59T126 65L62 -188Q60 -194 42 -194H29ZM353 431Q392 431 427 419L432 422Q436 426 439 429T449 439T461 453T472 471T484 495T493 524T501 560Q503 569 503 593Q503 611 502 616Q487 667 426 667Q384 667 347 643T286 582T247 514T224 455Q219 439 186 308T152 168Q151 163 151 147Q151 99 173 68Q204 26 260 26Q302 26 349 51T425 137Q441 171 449 214T457 279Q457 337 422 372Q380 358 347 358H337Q258 358 258 389Q258 396 261 403Q275 431 353 431Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3F5&quot; d=&quot;M227 -11Q149 -11 95 41T40 174Q40 262 87 322Q121 367 173 396T287 430Q289 431 329 431H367Q382 426 382 411Q382 385 341 385H325H312Q191 385 154 277L150 265H327Q340 256 340 246Q340 228 320 219H138V217Q128 187 128 143Q128 77 160 52T231 26Q258 26 284 36T326 57T343 68Q350 68 354 58T358 39Q358 36 357 35Q354 31 337 21T289 0T227 -11Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-39B&quot; d=&quot;M320 708Q326 716 340 716H348H355Q367 716 372 708Q374 706 423 547T523 226T575 62Q581 52 591 50T634 46H661V0H653Q644 3 532 3Q411 3 390 0H379V46H392Q464 46 464 65Q463 70 390 305T316 539L246 316Q177 95 177 84Q177 72 198 59T248 46H253V0H245Q230 3 130 3Q47 3 38 0H32V46H45Q112 51 127 91Q128 92 224 399T320 708Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-28&quot; d=&quot;M758 -1237T758 -1240T752 -1249H736Q718 -1249 717 -1248Q711 -1245 672 -1199Q237 -706 237 251T672 1700Q697 1730 716 1749Q718 1750 735 1750H752Q758 1744 758 1741Q758 1737 740 1713T689 1644T619 1537T540 1380T463 1176Q348 802 348 251Q348 -242 441 -599T744 -1218Q758 -1237 758 -1240Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-29&quot; d=&quot;M33 1741Q33 1750 51 1750H60H65Q73 1750 81 1743T119 1700Q554 1207 554 251Q554 -707 119 -1199Q76 -1250 66 -1250Q65 -1250 62 -1250T56 -1249Q55 -1249 53 -1249T49 -1250Q33 -1250 33 -1239Q33 -1236 50 -1214T98 -1150T163 -1052T238 -910T311 -727Q443 -335 443 251Q443 402 436 532T405 831T339 1142T224 1438T50 1716Q33 1737 33 1741Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-52&quot; d=&quot;M230 637Q203 637 198 638T193 649Q193 676 204 682Q206 683 378 683Q550 682 564 680Q620 672 658 652T712 606T733 563T739 529Q739 484 710 445T643 385T576 351T538 338L545 333Q612 295 612 223Q612 212 607 162T602 80V71Q602 53 603 43T614 25T640 16Q668 16 686 38T712 85Q717 99 720 102T735 105Q755 105 755 93Q755 75 731 36Q693 -21 641 -21H632Q571 -21 531 4T487 82Q487 109 502 166T517 239Q517 290 474 313Q459 320 449 321T378 323H309L277 193Q244 61 244 59Q244 55 245 54T252 50T269 48T302 46H333Q339 38 339 37T336 19Q332 6 326 0H311Q275 2 180 2Q146 2 117 2T71 2T50 1Q33 1 33 10Q33 12 36 24Q41 43 46 45Q50 46 61 46H67Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628Q287 635 230 637ZM630 554Q630 586 609 608T523 636Q521 636 500 636T462 637H440Q393 637 386 627Q385 624 352 494T319 361Q319 360 388 360Q466 361 492 367Q556 377 592 426Q608 449 619 486T630 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-57&quot; d=&quot;M436 683Q450 683 486 682T553 680Q604 680 638 681T677 682Q695 682 695 674Q695 670 692 659Q687 641 683 639T661 637Q636 636 621 632T600 624T597 615Q597 603 613 377T629 138L631 141Q633 144 637 151T649 170T666 200T690 241T720 295T759 362Q863 546 877 572T892 604Q892 619 873 628T831 637Q817 637 817 647Q817 650 819 660Q823 676 825 679T839 682Q842 682 856 682T895 682T949 681Q1015 681 1034 683Q1048 683 1048 672Q1048 666 1045 655T1038 640T1028 637Q1006 637 988 631T958 617T939 600T927 584L923 578L754 282Q586 -14 585 -15Q579 -22 561 -22Q546 -22 542 -17Q539 -14 523 229T506 480L494 462Q472 425 366 239Q222 -13 220 -15T215 -19Q210 -22 197 -22Q178 -22 176 -15Q176 -12 154 304T131 622Q129 631 121 633T82 637H58Q51 644 51 648Q52 671 64 683H76Q118 680 176 680Q301 680 313 683H323Q329 677 329 674T327 656Q322 641 318 637H297Q236 634 232 620Q262 160 266 136L501 550L499 587Q496 629 489 632Q483 636 447 637Q428 637 422 639T416 648Q416 650 418 660Q419 664 420 669T421 676T424 680T428 682T436 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
About a decade late, but I decided to give Grand Central Dispatch (GCD) a go in R.  GCD is fairly similar to OpenMP as it provides a simplified interface for pthreads.  Since its release for Mac OS X 10.6 in 2009, GCD has been ported to a number of operating systems through libdispatch.  As of this writing, libdispatch is primarily available on Linux and Apple's operating systems using the Clang compiler.  GCC may work, but I have not had any luck.
&lt;/p&gt;

&lt;p&gt;
The most notable aspect of GCD is that it provides a native multithreading environment in Apple's operating systems.  This includes MacOS and iOS.  Not true for OpenMP since the removal of GCC from Mac OS X Snow Leopard.  So if you are trying to get the most performance for all of your customers, GCD may provide some benefit for a lot of #ifdefs.  
&lt;/p&gt;


&lt;p&gt;
If you have used OpenCL GCD should be familiar.  This is due to OpenCL and GCD both using queues and code blocks.  However, you aren't forced to use code blocks, as GCD provides _f variants of the dispatch commands to allow the use of standard C functions.  

Queues are provided in two main flavors, &lt;i&gt;serial&lt;/i&gt; and &lt;i&gt;concurrent&lt;/i&gt;.  Serial queues are exactly what they sound like, they provide a FIFO (First In First Out) queue.  Therefore, tasks are executed and completed in sequence.  Concurrent queues are non-blocking queues in that they execute in order, but do not wait for completion.   

A simple concurrent queue can be created through &lt;code&gt;dispatch_get_global_queue&lt;/code&gt;, this function has two inputs.  The first is the Quality of Service (QoS) for the queue, the second is reserved for future use and can be set to 0 or NULL.
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
dispatch_queue_global_t dispatch_get_global_queue(intptr_t qos, uintptr_t flags)
&lt;/code&gt;&lt;/pre&gt;
The quality of service will allow flexibility in your R package.  You could have one high priority queue to draw a real-time plot, and have a lower priority queue for pulling data from websites in the background.  
The level of the queue is set by one of three enumerated values:
&lt;ul&gt;
 &lt;li&gt;&lt;code&gt;DISPATCH_QUEUE_PRIORITY_HIGH = 2,&lt;/code&gt;&lt;/li&gt;
 &lt;li&gt;&lt;code&gt;DISPATCH_QUEUE_PRIORITY_DEFAULT = 0,&lt;/code&gt;&lt;/li&gt;
 &lt;li&gt;&lt;code&gt;DISPATCH_QUEUE_PRIORITY_LOW = -2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
Higher QoS will force your queue to run before other tasks in your system.  
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;dispatch_queue_global_t dispatch_get_global_queue&lt;/code&gt; will only create a concurrent queue, but you can use &lt;code&gt;dispatch_queue_create&lt;/code&gt; to create either queue type:
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
dispatch_queue_t dispatch_queue_create(const char *label, dispatch_queue_attr_t qt)
&lt;/code&gt;&lt;/pre&gt;
The first input provides a label for debugging etc, it can be anything including NULL, the second identifies queue type from one of the enumerated values below:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;DISPATCH_QUEUE_SERIAL or NULL&lt;/li&gt;&lt;/code&gt;
&lt;li&gt;&lt;code&gt;DISPATCH_QUEUE_CONCURRENT&lt;/li&gt;&lt;/code&gt;
&lt;/ul&gt;
&lt;/p&gt;

&lt;p&gt;
Once you have a queue, you probably want to stick somethign in it.  The dispatch commands will get you there.
&lt;i&gt;dipatch_apply&lt;/i&gt; and likewise &lt;i&gt;dispatch_apply_f&lt;/i&gt; will solve this problem for you, they will enqueue your request and run it a fixed number of times.  The former function will be used for code blocks while the later will be used for standard functions.
&lt;/p&gt;

&lt;p&gt;
To give you a bit of flavor behind GCD, a parallel for-loop can be created through the following function.
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
// inner kernel using GCD
void R_parallel_inner_kernel_gcd( double * x, double * y, int * n ) {

  // concurrent queue
   dispatch_queue_t my_queue = dispatch_get_global_queue(0, 0);

  // for like loop
  dispatch_apply (*n, my_queue, ^(size_t idx){

      size_t j;
      double tmp = 0;

      for( j = 0; j &lt; *n; j++) {
        tmp += (x[idx] - y[j]) * (x[idx] - y[j]);
      }

      x[idx] = tmp;

  });
}
&lt;/code&gt;&lt;/pre&gt;
Here you can see the code block is being applied to the dispatch and running &lt;i&gt;n&lt;/i&gt; times using the iterator &lt;i&gt;idx&lt;/i&gt;.  The code block is just a rolled up function that allows the creation of private variables such as &lt;i&gt;tmp&lt;/i&gt; and &lt;i&gt;j&lt;/i&gt; and shares the data from &lt;i&gt;y&lt;/i&gt; and &lt;i&gt;x&lt;/i&gt;. 
&lt;/p&gt;

&lt;p&gt;
This should be enough for you to get playing with GCD, further documentation exists at the 
&lt;a href=&quot;https://apple.github.io/swift-corelibs-libdispatch/&quot;&gt;Apple GitHub page&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt; 
For comparison against OpenMP, I re-wrote the code below for some performance testing.  As you can see, the code is fairly similar, but unlike above, failure for having OpenMP available will allow the code to run as designed unlike the GCD case.  
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
// inner kernel using OpenMP
void R_parallel_inner_kernel_omp( double * x, double * y, int * n ) {

  size_t idx,j;
  double tmp;

  #pragma omp parallel 
  {
    #pragma omp for
    for( idx = 0; idx &lt; *n; idx++) {
      tmp = 0;
      for( j = 0; j &lt; *n; j++) {
        tmp += (x[idx] - y[j]) * (x[idx] - y[j]);
      }
      x[idx] = tmp;
    }
  }
  return;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;

&lt;p&gt;
Running the code on an older 12-core, 24-thread (3.3GHz) 2012 MacPro running Mac OS Catalina, I received the following timings for GCC 9 (average 100 runs).
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
With OpenMP: 0.46 sec elapsed
Without GCD or OpenMP: 9.05 sec elapsed
&lt;/code&gt;&lt;/pre&gt;
GCD wasn't tested since I couldn't get it working with GCC in this case.  
Using homebrew's LLVM (Version 10), I received the following timings on the same system (average 100 runs).
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
With GCD: 0.53 sec elapsed
With OpenMP: 0.54 sec elapsed
Without GCD or OpenMP: 9.08 sec elapsed
&lt;/code&gt;&lt;/pre&gt;
Switching to my laptop running the same operationg system, a 2017 13&quot; MacBook Pro with an i5 (2.3GHz, dual-core 4-thread) CPU, I had results that actually went in the other direction using homebrew LLVM (Version 10) (average 100 runs).
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
With GCD: 2.92 sec elapsed
With OpenMP: 3.00 sec elapsed
Without GCD or OpenMP: 11.51 sec elapsed
&lt;/code&gt;&lt;/pre&gt;
Using GCC 9, I also repeated the same compilation again using the same flags (average 100 runs).
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
With OpenMP: 3.21 sec elapsed
Without GCD or OpenMP: 11.61 sec elapsed
&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;
We can see that the performance measures differ quite a bit between OpenMP and GCD, even when running a fairly simple program over different hardware.
Further testing would be required to better understand the conditions that cause OpenMP to be more performant than GCD.
One idea could be the number of cores, or optimzation for specific processors.  
Perhapse another blog post for that!
&lt;/p&gt;

&lt;p&gt;
For those interested in getting their feet wet a bit more, I have created a reference template for GCD with make files to choose the best parallel implementation for your code (&lt;a href=&quot;https://github.com/jlisic/rgcd&quot;&gt;rgcd-template&lt;/a&gt;).  Included are timing tests and the code samples shown.
&lt;/p&gt;

</description>
        <pubDate>Sat, 29 Aug 2020 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/2020/08/29/Grand-Central-Dispatch.html</link>
        <guid isPermaLink="true">http://meanmean.me/2020/08/29/Grand-Central-Dispatch.html</guid>
        
        
      </item>
    
      <item>
        <title>Mysteriously Slow sample</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
.MathJax_SVG_LineBox {display: table!important}
.MathJax_SVG_LineBox span {display: table-cell!important; width: 10000em!important; min-width: 0; max-width: none; padding: 0; border: 0; margin: 0}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3A3&quot; d=&quot;M666 247Q664 244 652 126T638 4V0H351Q131 0 95 0T57 5V6Q54 12 57 17L73 36Q89 54 121 90T182 159L305 299L56 644L55 658Q55 677 60 681Q63 683 351 683H638V679Q640 674 652 564T666 447V443H626V447Q618 505 604 543T559 605Q529 626 478 631T333 637H294H189L293 494Q314 465 345 422Q400 346 400 340Q400 338 399 337L154 57Q407 57 428 58Q476 60 508 68T551 83T575 103Q595 125 608 162T624 225L626 251H666V247Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6C&quot; d=&quot;M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-68&quot; d=&quot;M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-41&quot; d=&quot;M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6C&quot; d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-53&quot; d=&quot;M55 507Q55 590 112 647T243 704H257Q342 704 405 641L426 672Q431 679 436 687T446 700L449 704Q450 704 453 704T459 705H463Q466 705 472 699V462L466 456H448Q437 456 435 459T430 479Q413 605 329 646Q292 662 254 662Q201 662 168 626T135 542Q135 508 152 480T200 435Q210 431 286 412T370 389Q427 367 463 314T500 191Q500 110 448 45T301 -21Q245 -21 201 -4T140 27L122 41Q118 36 107 21T87 -7T78 -21Q76 -22 68 -22H64Q61 -22 55 -16V101Q55 220 56 222Q58 227 76 227H89Q95 221 95 214Q95 182 105 151T139 90T205 42T305 24Q352 24 386 62T420 155Q420 198 398 233T340 281Q284 295 266 300Q261 301 239 306T206 314T174 325T141 343T112 367T85 402Q55 451 55 507Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-57&quot; d=&quot;M792 683Q810 680 914 680Q991 680 1003 683H1009V637H996Q931 633 915 598Q912 591 863 438T766 135T716 -17Q711 -22 694 -22Q676 -22 673 -15Q671 -13 593 231L514 477L435 234Q416 174 391 92T358 -6T341 -22H331Q314 -21 310 -15Q309 -14 208 302T104 622Q98 632 87 633Q73 637 35 637H18V683H27Q69 681 154 681Q164 681 181 681T216 681T249 682T276 683H287H298V637H285Q213 637 213 620Q213 616 289 381L364 144L427 339Q490 535 492 546Q487 560 482 578T475 602T468 618T461 628T449 633T433 636T408 637H380V683H388Q397 680 508 680Q629 680 650 683H660V637H647Q576 637 576 619L727 146Q869 580 869 600Q869 605 863 612T839 627T794 637H783V683H792Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-50&quot; d=&quot;M130 622Q123 629 119 631T103 634T60 637H27V683H214Q237 683 276 683T331 684Q419 684 471 671T567 616Q624 563 624 489Q624 421 573 372T451 307Q429 302 328 301H234V181Q234 62 237 58Q245 47 304 46H337V0H326Q305 3 182 3Q47 3 38 0H27V46H60Q102 47 111 49T130 61V622ZM507 488Q507 514 506 528T500 564T483 597T450 620T397 635Q385 637 307 637H286Q237 637 234 628Q231 624 231 483V342H302H339Q390 342 423 349T481 382Q507 411 507 488Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5B&quot; d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5D&quot; d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3C3&quot; d=&quot;M184 -11Q116 -11 74 34T31 147Q31 247 104 333T274 430Q275 431 414 431H552Q553 430 555 429T559 427T562 425T565 422T567 420T569 416T570 412T571 407T572 401Q572 357 507 357Q500 357 490 357T476 358H416L421 348Q439 310 439 263Q439 153 359 71T184 -11ZM361 278Q361 358 276 358Q152 358 115 184Q114 180 114 178Q106 141 106 117Q106 67 131 47T188 26Q242 26 287 73Q316 103 334 153T356 233T361 278Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6B&quot; d=&quot;M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-26&quot; d=&quot;M156 540Q156 620 201 668T302 716Q354 716 377 671T401 578Q401 505 287 386L274 373Q309 285 416 148L429 132L437 142Q474 191 543 309L562 341V349Q562 368 541 376T498 385H493V431H502L626 428Q709 428 721 431H727V385H712Q688 384 669 379T639 369T618 354T603 337T591 316T578 295Q537 223 506 176T464 117T454 104Q454 102 471 85T497 62Q543 24 585 24Q618 24 648 48T682 113V121H722V112Q721 94 714 75T692 32T646 -7T574 -22Q491 -19 414 42L402 51L391 42Q312 -22 224 -22Q144 -22 93 25T42 135Q42 153 46 169T55 197T74 225T96 249T125 278T156 308L195 347L190 360Q185 372 182 382T174 411T165 448T159 491T156 540ZM361 576Q361 613 348 646T305 679Q272 679 252 649T232 572Q232 497 255 426L259 411L267 420Q361 519 361 576ZM140 164Q140 103 167 64T240 24Q271 24 304 36T356 61T374 77Q295 156 235 262L220 292L210 310L193 293Q177 277 169 268T151 229T140 164Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2260&quot; d=&quot;M166 -215T159 -215T147 -212T141 -204T139 -197Q139 -190 144 -183L306 133H70Q56 140 56 153Q56 168 72 173H327L406 327H72Q56 332 56 347Q56 360 70 367H426Q597 702 602 707Q605 716 618 716Q625 716 630 712T636 703T638 696Q638 692 471 367H707Q722 359 722 347Q722 336 708 328L451 327L371 173H708Q722 163 722 153Q722 140 707 133H351Q175 -210 170 -212Q166 -215 159 -215Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239B&quot; d=&quot;M837 1154Q843 1148 843 1145Q843 1141 818 1106T753 1002T667 841T574 604T494 299Q417 -84 417 -609Q417 -641 416 -647T411 -654Q409 -655 366 -655Q299 -655 297 -654Q292 -652 292 -643T291 -583Q293 -400 304 -242T347 110T432 470T574 813T785 1136Q787 1139 790 1142T794 1147T796 1150T799 1152T802 1153T807 1154T813 1154H819H837Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239D&quot; d=&quot;M843 -635Q843 -638 837 -644H820Q801 -644 800 -643Q792 -635 785 -626Q684 -503 605 -363T473 -75T385 216T330 518T302 809T291 1093Q291 1144 291 1153T296 1164Q298 1165 366 1165Q409 1165 411 1164Q415 1163 416 1157T417 1119Q417 529 517 109T833 -617Q843 -631 843 -635Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239C&quot; d=&quot;M413 -9Q412 -9 407 -9T388 -10T354 -10Q300 -10 297 -9Q294 -8 293 -5Q291 5 291 127V300Q291 602 292 605L296 609Q298 610 366 610Q382 610 392 610T407 610T412 609Q416 609 416 592T417 473V127Q417 -9 413 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-33&quot; d=&quot;M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-D7&quot; d=&quot;M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-58&quot; d=&quot;M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239E&quot; d=&quot;M31 1143Q31 1154 49 1154H59Q72 1154 75 1152T89 1136Q190 1013 269 873T401 585T489 294T544 -8T572 -299T583 -583Q583 -634 583 -643T577 -654Q575 -655 508 -655Q465 -655 463 -654Q459 -653 458 -647T457 -609Q457 -58 371 340T100 1037Q87 1059 61 1098T31 1143Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A0&quot; d=&quot;M56 -644H50Q31 -644 31 -635Q31 -632 37 -622Q69 -579 100 -527Q286 -228 371 170T457 1119Q457 1161 462 1164Q464 1165 520 1165Q575 1165 577 1164Q582 1162 582 1153T583 1093Q581 910 570 752T527 400T442 40T300 -303T89 -626Q78 -640 75 -642T61 -644H56Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239F&quot; d=&quot;M579 -9Q578 -9 573 -9T554 -10T520 -10Q466 -10 463 -9Q460 -8 459 -5Q457 5 457 127V300Q457 602 458 605L462 609Q464 610 532 610Q548 610 558 610T573 610T578 609Q582 609 582 592T583 473V127Q583 -9 579 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-63&quot; d=&quot;M370 305T349 305T313 320T297 358Q297 381 312 396Q317 401 317 402T307 404Q281 408 258 408Q209 408 178 376Q131 329 131 219Q131 137 162 90Q203 29 272 29Q313 29 338 55T374 117Q376 125 379 127T395 129H409Q415 123 415 120Q415 116 411 104T395 71T366 33T318 2T249 -11Q163 -11 99 53T34 214Q34 318 99 383T250 448T370 421T404 357Q404 334 387 320Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6F&quot; d=&quot;M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-76&quot; d=&quot;M338 431Q344 429 422 429Q479 429 503 431H508V385H497Q439 381 423 345Q421 341 356 172T288 -2Q283 -11 263 -11Q244 -11 239 -2Q99 359 98 364Q93 378 82 381T43 385H19V431H25L33 430Q41 430 53 430T79 430T104 429T122 428Q217 428 232 431H240V385H226Q187 384 184 370Q184 366 235 234L286 102L377 341V349Q377 363 367 372T349 383T335 385H331V431H338Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5E&quot; d=&quot;M112 560L249 694L257 686Q387 562 387 560L361 531Q359 532 303 581L250 627L195 580Q182 569 169 557T148 538L140 532Q138 530 125 546L112 560Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ3-2C6&quot; d=&quot;M1439 564Q1434 564 1080 631T722 698Q719 698 362 631Q7 564 4 564L0 583Q-4 602 -4 603L720 772L1083 688Q1446 603 1447 603Q1447 602 1443 583L1439 564Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-AF&quot; d=&quot;M69 544V590H430V544H69Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6E&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6D&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-73&quot; d=&quot;M295 316Q295 356 268 385T190 414Q154 414 128 401Q98 382 98 349Q97 344 98 336T114 312T157 287Q175 282 201 278T245 269T277 256Q294 248 310 236T342 195T359 133Q359 71 321 31T198 -10H190Q138 -10 94 26L86 19L77 10Q71 4 65 -1L54 -11H46H42Q39 -11 33 -5V74V132Q33 153 35 157T45 162H54Q66 162 70 158T75 146T82 119T101 77Q136 26 198 26Q295 26 295 104Q295 133 277 151Q257 175 194 187T111 210Q75 227 54 256T33 318Q33 357 50 384T93 424T143 442T187 447H198Q238 447 268 432L283 424L292 431Q302 440 314 448H322H326Q329 448 335 442V310L329 304H301Q295 310 295 316Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-74&quot; d=&quot;M27 422Q80 426 109 478T141 600V615H181V431H316V385H181V241Q182 116 182 100T189 68Q203 29 238 29Q282 29 292 100Q293 108 293 146V181H333V146V134Q333 57 291 17Q264 -10 221 -10Q187 -10 162 2T124 33T105 68T98 100Q97 107 97 248V385H18V422H27Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3B2&quot; d=&quot;M29 -194Q23 -188 23 -186Q23 -183 102 134T186 465Q208 533 243 584T309 658Q365 705 429 705H431Q493 705 533 667T573 570Q573 465 469 396L482 383Q533 332 533 252Q533 139 448 65T257 -10Q227 -10 203 -2T165 17T143 40T131 59T126 65L62 -188Q60 -194 42 -194H29ZM353 431Q392 431 427 419L432 422Q436 426 439 429T449 439T461 453T472 471T484 495T493 524T501 560Q503 569 503 593Q503 611 502 616Q487 667 426 667Q384 667 347 643T286 582T247 514T224 455Q219 439 186 308T152 168Q151 163 151 147Q151 99 173 68Q204 26 260 26Q302 26 349 51T425 137Q441 171 449 214T457 279Q457 337 422 372Q380 358 347 358H337Q258 358 258 389Q258 396 261 403Q275 431 353 431Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3F5&quot; d=&quot;M227 -11Q149 -11 95 41T40 174Q40 262 87 322Q121 367 173 396T287 430Q289 431 329 431H367Q382 426 382 411Q382 385 341 385H325H312Q191 385 154 277L150 265H327Q340 256 340 246Q340 228 320 219H138V217Q128 187 128 143Q128 77 160 52T231 26Q258 26 284 36T326 57T343 68Q350 68 354 58T358 39Q358 36 357 35Q354 31 337 21T289 0T227 -11Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-39B&quot; d=&quot;M320 708Q326 716 340 716H348H355Q367 716 372 708Q374 706 423 547T523 226T575 62Q581 52 591 50T634 46H661V0H653Q644 3 532 3Q411 3 390 0H379V46H392Q464 46 464 65Q463 70 390 305T316 539L246 316Q177 95 177 84Q177 72 198 59T248 46H253V0H245Q230 3 130 3Q47 3 38 0H32V46H45Q112 51 127 91Q128 92 224 399T320 708Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-28&quot; d=&quot;M758 -1237T758 -1240T752 -1249H736Q718 -1249 717 -1248Q711 -1245 672 -1199Q237 -706 237 251T672 1700Q697 1730 716 1749Q718 1750 735 1750H752Q758 1744 758 1741Q758 1737 740 1713T689 1644T619 1537T540 1380T463 1176Q348 802 348 251Q348 -242 441 -599T744 -1218Q758 -1237 758 -1240Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-29&quot; d=&quot;M33 1741Q33 1750 51 1750H60H65Q73 1750 81 1743T119 1700Q554 1207 554 251Q554 -707 119 -1199Q76 -1250 66 -1250Q65 -1250 62 -1250T56 -1249Q55 -1249 53 -1249T49 -1250Q33 -1250 33 -1239Q33 -1236 50 -1214T98 -1150T163 -1052T238 -910T311 -727Q443 -335 443 251Q443 402 436 532T405 831T339 1142T224 1438T50 1716Q33 1737 33 1741Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-52&quot; d=&quot;M230 637Q203 637 198 638T193 649Q193 676 204 682Q206 683 378 683Q550 682 564 680Q620 672 658 652T712 606T733 563T739 529Q739 484 710 445T643 385T576 351T538 338L545 333Q612 295 612 223Q612 212 607 162T602 80V71Q602 53 603 43T614 25T640 16Q668 16 686 38T712 85Q717 99 720 102T735 105Q755 105 755 93Q755 75 731 36Q693 -21 641 -21H632Q571 -21 531 4T487 82Q487 109 502 166T517 239Q517 290 474 313Q459 320 449 321T378 323H309L277 193Q244 61 244 59Q244 55 245 54T252 50T269 48T302 46H333Q339 38 339 37T336 19Q332 6 326 0H311Q275 2 180 2Q146 2 117 2T71 2T50 1Q33 1 33 10Q33 12 36 24Q41 43 46 45Q50 46 61 46H67Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628Q287 635 230 637ZM630 554Q630 586 609 608T523 636Q521 636 500 636T462 637H440Q393 637 386 627Q385 624 352 494T319 361Q319 360 388 360Q466 361 492 367Q556 377 592 426Q608 449 619 486T630 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-57&quot; d=&quot;M436 683Q450 683 486 682T553 680Q604 680 638 681T677 682Q695 682 695 674Q695 670 692 659Q687 641 683 639T661 637Q636 636 621 632T600 624T597 615Q597 603 613 377T629 138L631 141Q633 144 637 151T649 170T666 200T690 241T720 295T759 362Q863 546 877 572T892 604Q892 619 873 628T831 637Q817 637 817 647Q817 650 819 660Q823 676 825 679T839 682Q842 682 856 682T895 682T949 681Q1015 681 1034 683Q1048 683 1048 672Q1048 666 1045 655T1038 640T1028 637Q1006 637 988 631T958 617T939 600T927 584L923 578L754 282Q586 -14 585 -15Q579 -22 561 -22Q546 -22 542 -17Q539 -14 523 229T506 480L494 462Q472 425 366 239Q222 -13 220 -15T215 -19Q210 -22 197 -22Q178 -22 176 -15Q176 -12 154 304T131 622Q129 631 121 633T82 637H58Q51 644 51 648Q52 671 64 683H76Q118 680 176 680Q301 680 313 683H323Q329 677 329 674T327 656Q322 641 318 637H297Q236 634 232 620Q262 160 266 136L501 550L499 587Q496 629 489 632Q483 636 447 637Q428 637 422 639T416 648Q416 650 418 660Q419 664 420 669T421 676T424 680T428 682T436 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
Hi everyone, I'm at JSM 2018 right now, so feel free to drop by my session or drop by in the halls!  Just give me a &lt;a href=&quot;https://twitter.com/jlisic&quot;&gt;tweet&lt;/a&gt;!
&lt;/p&gt;

&lt;p&gt;
Back to the meat-and-potatoes of this post.  A while ago I was running good old &lt;code&gt;sample&lt;/code&gt; and comparing its performance to my &lt;code&gt;lpm2_kdtree&lt;/code&gt; function in the &lt;i&gt;BalancedSampling&lt;/i&gt; package (Grafström and Lisic, 2016).  
In this comparison I noticed that sample was in some cases slower than my balanced sampling method when using sampling weights.
&lt;/p&gt;


&lt;p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(BalancedSampling)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# sampling proportion&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;0.1&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# population size &lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;N_values&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&quot;hl kwd&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;99&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;runif&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( N&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;N_values) {&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# get sample size &lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;## run lpm2-kdtree&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# to make things even we normalize pi&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pi_tmp&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;pi[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi)&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# we probably don't want to balance by pi_tmp, but &lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# for checking speed this is fine&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;lpm2_kdtree&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi_tmp,pi_tmp)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f, N,&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, end_time ))&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;## run sample &lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# to make things even we normalize pi&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(index,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;prob&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=pi_tmp)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f, N,&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, end_time ))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'SamplingFraction'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'PopulationSize'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'Method'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'RunTime'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;result[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'SamplingFraction'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Method'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;lapply&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'SamplingFraction'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Method'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)], as.factor)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;levels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Method)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;lpm2_kdtree&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;sample&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=PopulationSize,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=RunTime,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Method),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=result)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Method))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Run Time (s)&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Population Size&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/sample/figure/unnamed-chunk-2-1.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 1:&lt;/b&gt;  Lpm2_kdtree vs R sample.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;p&gt; &lt;b&gt;How could this be? &lt;/b&gt;&lt;/p&gt;

&lt;p&gt; Let's condsider a few possible reasons. &lt;/p&gt;

&lt;p&gt; &lt;b&gt;Are you running an old version of R? &lt;/b&gt;&lt;/p&gt; 
&lt;p&gt; No, this was done with R 3.5.0, but results hold on 3.5.1.&lt;/p&gt;  

&lt;p&gt;&lt;b&gt; Is this because you are a &lt;i&gt;freedom hating&lt;/i&gt; Mac user?&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Nope, I get similar results in Linux &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Is this due to the &lt;code&gt;revsort&lt;/code&gt; in &lt;code&gt;ProbSampleNoReplace&lt;/code&gt; found in &lt;i&gt;random.c&lt;/i&gt;?&lt;/b&gt;&lt;/p&gt; 

&lt;p&gt;How amazingly prescient of you!  If you track down the code path, the method used for sampling has a revsort call right at the begining (&lt;a href=&quot;https://github.com/wch/r-source/blob/trunk/src/main/random.c&quot;&gt;Line 323&lt;/a&gt;).  Some basic testing seems to identify this as the likely culprit.  Therefore, it might be possible to speed up sampling by checking if the probabilities are sorted.&lt;/p&gt;

&lt;p&gt;Keep in mind that there are likely good reasons for R to use this method relative to others, including the alternative method below.  One is computational stability, split sampling through the pivotal methods tends to work well when sample sizes aren't extremely small.  However, I don't have any good comparisons of methods, if anyone knows please let me know, doing a literature search on this is pretty far down on my todo list.&lt;/p&gt; 

&lt;p&gt;&lt;b&gt;That's great, but what can I do to improve my weighted or PPS sampling?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Well, I wrote a quick pivotal method implementation (think LPM2 without balancing) that seems to work.  It's available as &lt;code&gt;split_sample&lt;/code&gt; on my github version of BalancedSampling.
There is also &lt;code&gt;UPrandompivotal&lt;/code&gt; in the &lt;i&gt;sampling&lt;/i&gt; package (Tillé and Matei, 2016).  
However, my implementation seems to be considerably faster.  We will take a look at this in another blog post.
&lt;/p&gt;

&lt;p&gt;Finally, keep in mind that split_sample probably isn't as well tested as &lt;code&gt;UPrandompivotal&lt;/code&gt;.  So I'm happy to take any feedback. &lt;/p&gt;

&lt;p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(devtools)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;install_github&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;jlisic/BalancedSampling&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(BalancedSampling)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(sampling)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# sampling proportion&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;0.1&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# population size &lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;N_values&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&quot;hl kwd&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;99&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;runif&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( N&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;N_values) {&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# get sample size &lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;round&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;## run lpm2-kdtree&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# to make things even we normalize pi&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pi_tmp&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;pi[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi)&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# we probably don't want to balance by pi_tmp, but &lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# for checking speed this is fine&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;lpm2_kdtree&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi_tmp,pi_tmp)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f, N,&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, end_time ))&lt;/span&gt;


  &lt;span class=&quot;hl com&quot;&gt;## run pivotal method (BalancedSampling) &lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# to make things even we normalize pi&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pi_tmp&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;pi[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi)&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;split_sample&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi_tmp)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f, N,&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, end_time ))&lt;/span&gt;


  &lt;span class=&quot;hl com&quot;&gt;## run pivotal sampling (sampling) &lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;hl com&quot;&gt;# to make things even we normalize pi&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pi_tmp&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;pi[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;N]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi)&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;UPrandompivotal&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pi_tmp)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;start_time&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(f, N,&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;, end_time ))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'SamplingFraction'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'PopulationSize'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'Method'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'RunTime'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;result[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'SamplingFraction'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Method'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;lapply&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'SamplingFraction'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Method'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)], as.factor)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;levels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Method)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;lpm2_kdtree&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;BalancedSampling::split_sample&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl str&quot;&gt;&amp;quot;sampling::UPrandompivotal&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=PopulationSize,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=RunTime,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Method),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=result)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Method))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Run Time (s)&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Population Size&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/p&gt;

 
&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/sample/figure/unnamed-chunk-3-1.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 2:&lt;/b&gt;  Lpm2_kdtree vs BalancedSampling::split_sample vs sampling::UPrandompivotal.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt; Have a great JSM! &lt;/p&gt; 
  

&lt;h2&gt;References&lt;/h2&gt;

&lt;p&gt;
Grafström, A., Lisic, J.: BalancedSampling: balanced and spatially balanced sampling. R package version 1.5.2. &lt;u&gt;https://CRAN.R-project.org/package=BalancedSampling&lt;/u&gt;. Accessed August 28, 2018. (2016)
&lt;/p&gt;

&lt;p&gt;
Tillé, Y., Matei, M.: sampling: Survey Sampling. R package version 2.8. &lt;u&gt;https://CRAN.R-project.org/package=sampling&lt;/u&gt;. Accessed August 28, 2018. (2016)
&lt;/p&gt;

</description>
        <pubDate>Sat, 28 Jul 2018 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/2018/07/28/Mysteriously-slow-sample.html</link>
        <guid isPermaLink="true">http://meanmean.me/2018/07/28/Mysteriously-slow-sample.html</guid>
        
        
      </item>
    
      <item>
        <title>Making Your .C Less NOTEworthy</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
.MathJax_SVG_LineBox {display: table!important}
.MathJax_SVG_LineBox span {display: table-cell!important; width: 10000em!important; min-width: 0; max-width: none; padding: 0; border: 0; margin: 0}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3A3&quot; d=&quot;M666 247Q664 244 652 126T638 4V0H351Q131 0 95 0T57 5V6Q54 12 57 17L73 36Q89 54 121 90T182 159L305 299L56 644L55 658Q55 677 60 681Q63 683 351 683H638V679Q640 674 652 564T666 447V443H626V447Q618 505 604 543T559 605Q529 626 478 631T333 637H294H189L293 494Q314 465 345 422Q400 346 400 340Q400 338 399 337L154 57Q407 57 428 58Q476 60 508 68T551 83T575 103Q595 125 608 162T624 225L626 251H666V247Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6C&quot; d=&quot;M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-68&quot; d=&quot;M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-41&quot; d=&quot;M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6C&quot; d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-53&quot; d=&quot;M55 507Q55 590 112 647T243 704H257Q342 704 405 641L426 672Q431 679 436 687T446 700L449 704Q450 704 453 704T459 705H463Q466 705 472 699V462L466 456H448Q437 456 435 459T430 479Q413 605 329 646Q292 662 254 662Q201 662 168 626T135 542Q135 508 152 480T200 435Q210 431 286 412T370 389Q427 367 463 314T500 191Q500 110 448 45T301 -21Q245 -21 201 -4T140 27L122 41Q118 36 107 21T87 -7T78 -21Q76 -22 68 -22H64Q61 -22 55 -16V101Q55 220 56 222Q58 227 76 227H89Q95 221 95 214Q95 182 105 151T139 90T205 42T305 24Q352 24 386 62T420 155Q420 198 398 233T340 281Q284 295 266 300Q261 301 239 306T206 314T174 325T141 343T112 367T85 402Q55 451 55 507Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-57&quot; d=&quot;M792 683Q810 680 914 680Q991 680 1003 683H1009V637H996Q931 633 915 598Q912 591 863 438T766 135T716 -17Q711 -22 694 -22Q676 -22 673 -15Q671 -13 593 231L514 477L435 234Q416 174 391 92T358 -6T341 -22H331Q314 -21 310 -15Q309 -14 208 302T104 622Q98 632 87 633Q73 637 35 637H18V683H27Q69 681 154 681Q164 681 181 681T216 681T249 682T276 683H287H298V637H285Q213 637 213 620Q213 616 289 381L364 144L427 339Q490 535 492 546Q487 560 482 578T475 602T468 618T461 628T449 633T433 636T408 637H380V683H388Q397 680 508 680Q629 680 650 683H660V637H647Q576 637 576 619L727 146Q869 580 869 600Q869 605 863 612T839 627T794 637H783V683H792Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-50&quot; d=&quot;M130 622Q123 629 119 631T103 634T60 637H27V683H214Q237 683 276 683T331 684Q419 684 471 671T567 616Q624 563 624 489Q624 421 573 372T451 307Q429 302 328 301H234V181Q234 62 237 58Q245 47 304 46H337V0H326Q305 3 182 3Q47 3 38 0H27V46H60Q102 47 111 49T130 61V622ZM507 488Q507 514 506 528T500 564T483 597T450 620T397 635Q385 637 307 637H286Q237 637 234 628Q231 624 231 483V342H302H339Q390 342 423 349T481 382Q507 411 507 488Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5B&quot; d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5D&quot; d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3C3&quot; d=&quot;M184 -11Q116 -11 74 34T31 147Q31 247 104 333T274 430Q275 431 414 431H552Q553 430 555 429T559 427T562 425T565 422T567 420T569 416T570 412T571 407T572 401Q572 357 507 357Q500 357 490 357T476 358H416L421 348Q439 310 439 263Q439 153 359 71T184 -11ZM361 278Q361 358 276 358Q152 358 115 184Q114 180 114 178Q106 141 106 117Q106 67 131 47T188 26Q242 26 287 73Q316 103 334 153T356 233T361 278Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6B&quot; d=&quot;M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-26&quot; d=&quot;M156 540Q156 620 201 668T302 716Q354 716 377 671T401 578Q401 505 287 386L274 373Q309 285 416 148L429 132L437 142Q474 191 543 309L562 341V349Q562 368 541 376T498 385H493V431H502L626 428Q709 428 721 431H727V385H712Q688 384 669 379T639 369T618 354T603 337T591 316T578 295Q537 223 506 176T464 117T454 104Q454 102 471 85T497 62Q543 24 585 24Q618 24 648 48T682 113V121H722V112Q721 94 714 75T692 32T646 -7T574 -22Q491 -19 414 42L402 51L391 42Q312 -22 224 -22Q144 -22 93 25T42 135Q42 153 46 169T55 197T74 225T96 249T125 278T156 308L195 347L190 360Q185 372 182 382T174 411T165 448T159 491T156 540ZM361 576Q361 613 348 646T305 679Q272 679 252 649T232 572Q232 497 255 426L259 411L267 420Q361 519 361 576ZM140 164Q140 103 167 64T240 24Q271 24 304 36T356 61T374 77Q295 156 235 262L220 292L210 310L193 293Q177 277 169 268T151 229T140 164Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2260&quot; d=&quot;M166 -215T159 -215T147 -212T141 -204T139 -197Q139 -190 144 -183L306 133H70Q56 140 56 153Q56 168 72 173H327L406 327H72Q56 332 56 347Q56 360 70 367H426Q597 702 602 707Q605 716 618 716Q625 716 630 712T636 703T638 696Q638 692 471 367H707Q722 359 722 347Q722 336 708 328L451 327L371 173H708Q722 163 722 153Q722 140 707 133H351Q175 -210 170 -212Q166 -215 159 -215Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239B&quot; d=&quot;M837 1154Q843 1148 843 1145Q843 1141 818 1106T753 1002T667 841T574 604T494 299Q417 -84 417 -609Q417 -641 416 -647T411 -654Q409 -655 366 -655Q299 -655 297 -654Q292 -652 292 -643T291 -583Q293 -400 304 -242T347 110T432 470T574 813T785 1136Q787 1139 790 1142T794 1147T796 1150T799 1152T802 1153T807 1154T813 1154H819H837Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239D&quot; d=&quot;M843 -635Q843 -638 837 -644H820Q801 -644 800 -643Q792 -635 785 -626Q684 -503 605 -363T473 -75T385 216T330 518T302 809T291 1093Q291 1144 291 1153T296 1164Q298 1165 366 1165Q409 1165 411 1164Q415 1163 416 1157T417 1119Q417 529 517 109T833 -617Q843 -631 843 -635Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239C&quot; d=&quot;M413 -9Q412 -9 407 -9T388 -10T354 -10Q300 -10 297 -9Q294 -8 293 -5Q291 5 291 127V300Q291 602 292 605L296 609Q298 610 366 610Q382 610 392 610T407 610T412 609Q416 609 416 592T417 473V127Q417 -9 413 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-33&quot; d=&quot;M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-D7&quot; d=&quot;M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-58&quot; d=&quot;M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239E&quot; d=&quot;M31 1143Q31 1154 49 1154H59Q72 1154 75 1152T89 1136Q190 1013 269 873T401 585T489 294T544 -8T572 -299T583 -583Q583 -634 583 -643T577 -654Q575 -655 508 -655Q465 -655 463 -654Q459 -653 458 -647T457 -609Q457 -58 371 340T100 1037Q87 1059 61 1098T31 1143Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A0&quot; d=&quot;M56 -644H50Q31 -644 31 -635Q31 -632 37 -622Q69 -579 100 -527Q286 -228 371 170T457 1119Q457 1161 462 1164Q464 1165 520 1165Q575 1165 577 1164Q582 1162 582 1153T583 1093Q581 910 570 752T527 400T442 40T300 -303T89 -626Q78 -640 75 -642T61 -644H56Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239F&quot; d=&quot;M579 -9Q578 -9 573 -9T554 -10T520 -10Q466 -10 463 -9Q460 -8 459 -5Q457 5 457 127V300Q457 602 458 605L462 609Q464 610 532 610Q548 610 558 610T573 610T578 609Q582 609 582 592T583 473V127Q583 -9 579 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-63&quot; d=&quot;M370 305T349 305T313 320T297 358Q297 381 312 396Q317 401 317 402T307 404Q281 408 258 408Q209 408 178 376Q131 329 131 219Q131 137 162 90Q203 29 272 29Q313 29 338 55T374 117Q376 125 379 127T395 129H409Q415 123 415 120Q415 116 411 104T395 71T366 33T318 2T249 -11Q163 -11 99 53T34 214Q34 318 99 383T250 448T370 421T404 357Q404 334 387 320Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6F&quot; d=&quot;M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-76&quot; d=&quot;M338 431Q344 429 422 429Q479 429 503 431H508V385H497Q439 381 423 345Q421 341 356 172T288 -2Q283 -11 263 -11Q244 -11 239 -2Q99 359 98 364Q93 378 82 381T43 385H19V431H25L33 430Q41 430 53 430T79 430T104 429T122 428Q217 428 232 431H240V385H226Q187 384 184 370Q184 366 235 234L286 102L377 341V349Q377 363 367 372T349 383T335 385H331V431H338Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5E&quot; d=&quot;M112 560L249 694L257 686Q387 562 387 560L361 531Q359 532 303 581L250 627L195 580Q182 569 169 557T148 538L140 532Q138 530 125 546L112 560Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ3-2C6&quot; d=&quot;M1439 564Q1434 564 1080 631T722 698Q719 698 362 631Q7 564 4 564L0 583Q-4 602 -4 603L720 772L1083 688Q1446 603 1447 603Q1447 602 1443 583L1439 564Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-AF&quot; d=&quot;M69 544V590H430V544H69Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6E&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6D&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-73&quot; d=&quot;M295 316Q295 356 268 385T190 414Q154 414 128 401Q98 382 98 349Q97 344 98 336T114 312T157 287Q175 282 201 278T245 269T277 256Q294 248 310 236T342 195T359 133Q359 71 321 31T198 -10H190Q138 -10 94 26L86 19L77 10Q71 4 65 -1L54 -11H46H42Q39 -11 33 -5V74V132Q33 153 35 157T45 162H54Q66 162 70 158T75 146T82 119T101 77Q136 26 198 26Q295 26 295 104Q295 133 277 151Q257 175 194 187T111 210Q75 227 54 256T33 318Q33 357 50 384T93 424T143 442T187 447H198Q238 447 268 432L283 424L292 431Q302 440 314 448H322H326Q329 448 335 442V310L329 304H301Q295 310 295 316Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-74&quot; d=&quot;M27 422Q80 426 109 478T141 600V615H181V431H316V385H181V241Q182 116 182 100T189 68Q203 29 238 29Q282 29 292 100Q293 108 293 146V181H333V146V134Q333 57 291 17Q264 -10 221 -10Q187 -10 162 2T124 33T105 68T98 100Q97 107 97 248V385H18V422H27Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3B2&quot; d=&quot;M29 -194Q23 -188 23 -186Q23 -183 102 134T186 465Q208 533 243 584T309 658Q365 705 429 705H431Q493 705 533 667T573 570Q573 465 469 396L482 383Q533 332 533 252Q533 139 448 65T257 -10Q227 -10 203 -2T165 17T143 40T131 59T126 65L62 -188Q60 -194 42 -194H29ZM353 431Q392 431 427 419L432 422Q436 426 439 429T449 439T461 453T472 471T484 495T493 524T501 560Q503 569 503 593Q503 611 502 616Q487 667 426 667Q384 667 347 643T286 582T247 514T224 455Q219 439 186 308T152 168Q151 163 151 147Q151 99 173 68Q204 26 260 26Q302 26 349 51T425 137Q441 171 449 214T457 279Q457 337 422 372Q380 358 347 358H337Q258 358 258 389Q258 396 261 403Q275 431 353 431Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3F5&quot; d=&quot;M227 -11Q149 -11 95 41T40 174Q40 262 87 322Q121 367 173 396T287 430Q289 431 329 431H367Q382 426 382 411Q382 385 341 385H325H312Q191 385 154 277L150 265H327Q340 256 340 246Q340 228 320 219H138V217Q128 187 128 143Q128 77 160 52T231 26Q258 26 284 36T326 57T343 68Q350 68 354 58T358 39Q358 36 357 35Q354 31 337 21T289 0T227 -11Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-39B&quot; d=&quot;M320 708Q326 716 340 716H348H355Q367 716 372 708Q374 706 423 547T523 226T575 62Q581 52 591 50T634 46H661V0H653Q644 3 532 3Q411 3 390 0H379V46H392Q464 46 464 65Q463 70 390 305T316 539L246 316Q177 95 177 84Q177 72 198 59T248 46H253V0H245Q230 3 130 3Q47 3 38 0H32V46H45Q112 51 127 91Q128 92 224 399T320 708Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-28&quot; d=&quot;M758 -1237T758 -1240T752 -1249H736Q718 -1249 717 -1248Q711 -1245 672 -1199Q237 -706 237 251T672 1700Q697 1730 716 1749Q718 1750 735 1750H752Q758 1744 758 1741Q758 1737 740 1713T689 1644T619 1537T540 1380T463 1176Q348 802 348 251Q348 -242 441 -599T744 -1218Q758 -1237 758 -1240Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-29&quot; d=&quot;M33 1741Q33 1750 51 1750H60H65Q73 1750 81 1743T119 1700Q554 1207 554 251Q554 -707 119 -1199Q76 -1250 66 -1250Q65 -1250 62 -1250T56 -1249Q55 -1249 53 -1249T49 -1250Q33 -1250 33 -1239Q33 -1236 50 -1214T98 -1150T163 -1052T238 -910T311 -727Q443 -335 443 251Q443 402 436 532T405 831T339 1142T224 1438T50 1716Q33 1737 33 1741Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-52&quot; d=&quot;M230 637Q203 637 198 638T193 649Q193 676 204 682Q206 683 378 683Q550 682 564 680Q620 672 658 652T712 606T733 563T739 529Q739 484 710 445T643 385T576 351T538 338L545 333Q612 295 612 223Q612 212 607 162T602 80V71Q602 53 603 43T614 25T640 16Q668 16 686 38T712 85Q717 99 720 102T735 105Q755 105 755 93Q755 75 731 36Q693 -21 641 -21H632Q571 -21 531 4T487 82Q487 109 502 166T517 239Q517 290 474 313Q459 320 449 321T378 323H309L277 193Q244 61 244 59Q244 55 245 54T252 50T269 48T302 46H333Q339 38 339 37T336 19Q332 6 326 0H311Q275 2 180 2Q146 2 117 2T71 2T50 1Q33 1 33 10Q33 12 36 24Q41 43 46 45Q50 46 61 46H67Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628Q287 635 230 637ZM630 554Q630 586 609 608T523 636Q521 636 500 636T462 637H440Q393 637 386 627Q385 624 352 494T319 361Q319 360 388 360Q466 361 492 367Q556 377 592 426Q608 449 619 486T630 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-57&quot; d=&quot;M436 683Q450 683 486 682T553 680Q604 680 638 681T677 682Q695 682 695 674Q695 670 692 659Q687 641 683 639T661 637Q636 636 621 632T600 624T597 615Q597 603 613 377T629 138L631 141Q633 144 637 151T649 170T666 200T690 241T720 295T759 362Q863 546 877 572T892 604Q892 619 873 628T831 637Q817 637 817 647Q817 650 819 660Q823 676 825 679T839 682Q842 682 856 682T895 682T949 681Q1015 681 1034 683Q1048 683 1048 672Q1048 666 1045 655T1038 640T1028 637Q1006 637 988 631T958 617T939 600T927 584L923 578L754 282Q586 -14 585 -15Q579 -22 561 -22Q546 -22 542 -17Q539 -14 523 229T506 480L494 462Q472 425 366 239Q222 -13 220 -15T215 -19Q210 -22 197 -22Q178 -22 176 -15Q176 -12 154 304T131 622Q129 631 121 633T82 637H58Q51 644 51 648Q52 671 64 683H76Q118 680 176 680Q301 680 313 683H323Q329 677 329 674T327 656Q322 641 318 637H297Q236 634 232 620Q262 160 266 136L501 550L499 587Q496 629 489 632Q483 636 447 637Q428 637 422 639T416 648Q416 650 418 660Q419 664 420 669T421 676T424 680T428 682T436 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
If you are a package maintainer, you may have noticed the following new notes from your code checks:
&lt;code&gt;Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’&lt;/code&gt;  If you are using &lt;code&gt;Rcpp&lt;/code&gt; you can easily fix this by refreshing the auto-generated function registration.  However, if you have a lot of C code that uses the &lt;code&gt;.C()&lt;/code&gt; interface, then you need to make a few changes.  In this blog post, I'll use my updated &lt;a href=&quot;https://github.com/jlisic/meanShiftR&quot;&gt;&lt;i&gt;meanShiftR&lt;/i&gt; package&lt;/a&gt; as an example of how to quickly fix your code.
&lt;/p&gt;

&lt;p&gt;
The first thing you need to do is to examine your C code and determine your parameter types for each of the functions you call from R using &lt;code&gt;.C()&lt;/code&gt;.  In &lt;i&gt;meanShiftR&lt;/i&gt; I have two C functions that I call from R.  The first function &lt;code&gt;R_meanShift&lt;/code&gt;  has a function prototype that looks like this:
&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
/* mean shift function prototype*/
void R_meanShift(
  double * query,                /* data to query for, in row major form */
  double * train,                /* reference data, in row major form */
  int * assignment,              /* assignment */
  int * queryRowPtr,             /* number of rows of query data */
  int * trainRowPtr,             /* number of rows of reference data */
  int * queryColPtr,             /* number of columns of query and reference*/
  int * nNeighborsPtr,           /* number of neighbors */
  int * iterationsPtr,           /* number of iterations */
  double * bandwidth,            /* bandwidth */
  double * alphaPtr,             /* ms to newton ajustment parameter */
  double * epsilonPtr,           /* min l2 dist for convergence  */
  double * epsilonClusterPtr,    /* min l2 dist for clustering */
  int * kernelEnumPtr,           /* kernel type */
  int * algorithmEnumPtr,        /* algorithm type */
  int * intParameters,           /* kernel and alg dependent parameters */
  int * dblParameters            /* kernel and alg dependent parameters */
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
The second function &lt;code&gt;R_knn&lt;/code&gt;has a function prototype that looks like this:
&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
/* R_knn function prototype */
void R_knn( 
  double * queryPoints,  /* point to query for */
  double * x,            /* data to reference for the query 
                            (what we build our tree from) */
  int * xnrowPtr,        /* number of rows of x */
  int * nrowPtr,         /* number of rows from query points */
  int * ncolPtr,         /* number of columns for both queryPoints and x */
  double * kDist,        /* distance vector (we return this) */
  int * indexInt,        /* index of neighbors (we return this) */
  int * kPtr,            /* number of nearest neighbors */
  double * weight,       /* used for weighted distance calculations */
  int * leafSizePtr,     /* number of nodes in the k-d tree leaf nodes */
  double * maxDist       /* maximum distance l2^2 to look for neighbors */
 ); 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
With this information, I can register these function in four pretty painless steps.  (1) Include the &lt;/code&gt;R_ext/Rdynload.h&lt;/code&gt; in a header file.  (2) Create &lt;code&gt;R_NativePrimitiveArgType&lt;/code&gt;s for each C function that you call with &lt;code&gt;.C()&lt;/code&gt;.     
(3) Register our C functions as an R_CMethodDef array. (4) Finally, we create a function that is run when we load our function through R; in this function we register our C functions using &lt;code&gt;R_registerRoutines&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
To detail this process, I have created an example C file identifying each of these steps.  This isn't necessary, but can simplify things if you call C functions from R that have prototypes defined in separate files.  To make things easy to apply to your code, I have included a complete example below, and will then go over each of these steps.
&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
/* init.c */
#include &amp;lt;stdio.h&amp;gt; 
#include &amp;lt;stdlib.h&amp;gt;

#include &quot;R.h&quot;
#include &quot;Rinternals.h&quot;
#include &quot;Rmath.h&quot;

/*************************************/
/* STEP:  1. This header file is new */
/*************************************/
#include &lt;R_ext/Rdynload.h&gt;  

#include &quot;kdtree.h&quot;
#include &quot;meanShift.h&quot;

#if defined _OPENMP
  #include &lt;omp.h&gt;
#endif

/*************************************/
/* Register SO's                     */

/*************************************/
/* STEP:  2. Create R_NativePrimitiveArgTypes 
             for each function */
/*************************************/

static R_NativePrimitiveArgType R_meanShift_t[] = {
      REALSXP, REALSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, 
      REALSXP, REALSXP, REALSXP, REALSXP, INTSXP, INTSXP
};

static R_NativePrimitiveArgType R_knn_t[] = {
      REALSXP, REALSXP, INTSXP, INTSXP, INTSXP, REALSXP, INTSXP, INTSXP, 
      REALSXP, INTSXP, REALSXP
};

/*************************************/
/* STEP:  3. This is where we register 
             our C functions as an R_CMethodDef array */
/*************************************/

static const R_CMethodDef cMethods[] = {
     {&quot;R_meanShift&quot;, (DL_FUNC) &amp;R_meanShift, 14, R_meanShift_t},
     {&quot;R_knn&quot;, (DL_FUNC) &amp;R_knn, 14, R_knn_t},
        {NULL, NULL, 0, NULL}
};

/*************************************/
/* STEP: 4. This is our boilerplate 
           registration of our C code */
/*************************************/
void R_init_myLib(DllInfo *info)
{
     R_registerRoutines(info, cMethods, NULL, NULL, NULL);
     R_useDynamicSymbols(info, TRUE); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt; 
We will start at step two, step one was just including the header file.
Step two involves creating an array of an enumerated types for each C function we call from R, where the enumerated types are from standard R SEXP enumerations:  
&lt;code&gt;INTSXP&lt;/code&gt; for integers,
&lt;code&gt;REALSXP&lt;/code&gt; for doubles, 
&lt;code&gt;CHARSXP&lt;/code&gt; for characters, etc...
Each of these types are detailed in the &lt;a href=&quot;https://cran.r-project.org/doc/manuals/R-ints.html&quot;&gt; R Internals Manual &lt;/a&gt;.
 Each array is created with type &lt;code&gt;R_NativePrimitiveArgType&lt;/code&gt; and we will be using it in the next step.
&lt;/p&gt;

&lt;p&gt;
In step three we register our functions with the function name, our enumerated array from the last step, and the number of parameters.  
We register them through an array of function arrays, where a function array of a function named &lt;code&gt;foo&lt;/code&gt; with enumerated array &lt;code&gt;foo_t&lt;/code&gt; using three parameters would look like:
&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;
{&quot;foo&quot;, (DL_FUNC) &amp;foo, 3, foo_t}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
This array of function arrays is NULL terminated with function array 
&lt;code&gt;{NULL, NULL, 0, NULL}&lt;/code&gt;.
The array type we use is &lt;code&gt;R_CMethodDef&lt;/code&gt; and we need to make sure we register all our C functions in this array. 
&lt;/p&gt;


&lt;p&gt;
Finally in step four we put it all together in a function that registers our C functions when we load the shared object.  
&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;

void R_init_myLib(DllInfo *info)
{
     R_registerRoutines(info, cMethods, NULL, NULL, NULL);
     R_useDynamicSymbols(info, TRUE); 
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;That's it!, now update your packages!&lt;/p&gt;

&lt;img src=&quot;https://openclipart.org/download/284975/GlitchSimplifiedSteampunkCashRegister.svg&quot; /&gt;

</description>
        <pubDate>Fri, 12 Jan 2018 00:00:00 -0500</pubDate>
        <link>http://meanmean.me/2018/01/12/Making-Your-.C-Less-NOTEworthy.html</link>
        <guid isPermaLink="true">http://meanmean.me/2018/01/12/Making-Your-.C-Less-NOTEworthy.html</guid>
        
        
      </item>
    
      <item>
        <title>The Statistician's Apprentice: An Introduction to the SWP Operator</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
.MathJax_SVG_LineBox {display: table!important}
.MathJax_SVG_LineBox span {display: table-cell!important; width: 10000em!important; min-width: 0; max-width: none; padding: 0; border: 0; margin: 0}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3A3&quot; d=&quot;M666 247Q664 244 652 126T638 4V0H351Q131 0 95 0T57 5V6Q54 12 57 17L73 36Q89 54 121 90T182 159L305 299L56 644L55 658Q55 677 60 681Q63 683 351 683H638V679Q640 674 652 564T666 447V443H626V447Q618 505 604 543T559 605Q529 626 478 631T333 637H294H189L293 494Q314 465 345 422Q400 346 400 340Q400 338 399 337L154 57Q407 57 428 58Q476 60 508 68T551 83T575 103Q595 125 608 162T624 225L626 251H666V247Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6C&quot; d=&quot;M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-68&quot; d=&quot;M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-41&quot; d=&quot;M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6C&quot; d=&quot;M117 59Q117 26 142 26Q179 26 205 131Q211 151 215 152Q217 153 225 153H229Q238 153 241 153T246 151T248 144Q247 138 245 128T234 90T214 43T183 6T137 -11Q101 -11 70 11T38 85Q38 97 39 102L104 360Q167 615 167 623Q167 626 166 628T162 632T157 634T149 635T141 636T132 637T122 637Q112 637 109 637T101 638T95 641T94 647Q94 649 96 661Q101 680 107 682T179 688Q194 689 213 690T243 693T254 694Q266 694 266 686Q266 675 193 386T118 83Q118 81 118 75T117 65V59Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-53&quot; d=&quot;M55 507Q55 590 112 647T243 704H257Q342 704 405 641L426 672Q431 679 436 687T446 700L449 704Q450 704 453 704T459 705H463Q466 705 472 699V462L466 456H448Q437 456 435 459T430 479Q413 605 329 646Q292 662 254 662Q201 662 168 626T135 542Q135 508 152 480T200 435Q210 431 286 412T370 389Q427 367 463 314T500 191Q500 110 448 45T301 -21Q245 -21 201 -4T140 27L122 41Q118 36 107 21T87 -7T78 -21Q76 -22 68 -22H64Q61 -22 55 -16V101Q55 220 56 222Q58 227 76 227H89Q95 221 95 214Q95 182 105 151T139 90T205 42T305 24Q352 24 386 62T420 155Q420 198 398 233T340 281Q284 295 266 300Q261 301 239 306T206 314T174 325T141 343T112 367T85 402Q55 451 55 507Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-57&quot; d=&quot;M792 683Q810 680 914 680Q991 680 1003 683H1009V637H996Q931 633 915 598Q912 591 863 438T766 135T716 -17Q711 -22 694 -22Q676 -22 673 -15Q671 -13 593 231L514 477L435 234Q416 174 391 92T358 -6T341 -22H331Q314 -21 310 -15Q309 -14 208 302T104 622Q98 632 87 633Q73 637 35 637H18V683H27Q69 681 154 681Q164 681 181 681T216 681T249 682T276 683H287H298V637H285Q213 637 213 620Q213 616 289 381L364 144L427 339Q490 535 492 546Q487 560 482 578T475 602T468 618T461 628T449 633T433 636T408 637H380V683H388Q397 680 508 680Q629 680 650 683H660V637H647Q576 637 576 619L727 146Q869 580 869 600Q869 605 863 612T839 627T794 637H783V683H792Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-50&quot; d=&quot;M130 622Q123 629 119 631T103 634T60 637H27V683H214Q237 683 276 683T331 684Q419 684 471 671T567 616Q624 563 624 489Q624 421 573 372T451 307Q429 302 328 301H234V181Q234 62 237 58Q245 47 304 46H337V0H326Q305 3 182 3Q47 3 38 0H27V46H60Q102 47 111 49T130 61V622ZM507 488Q507 514 506 528T500 564T483 597T450 620T397 635Q385 637 307 637H286Q237 637 234 628Q231 624 231 483V342H302H339Q390 342 423 349T481 382Q507 411 507 488Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5B&quot; d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5D&quot; d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3C3&quot; d=&quot;M184 -11Q116 -11 74 34T31 147Q31 247 104 333T274 430Q275 431 414 431H552Q553 430 555 429T559 427T562 425T565 422T567 420T569 416T570 412T571 407T572 401Q572 357 507 357Q500 357 490 357T476 358H416L421 348Q439 310 439 263Q439 153 359 71T184 -11ZM361 278Q361 358 276 358Q152 358 115 184Q114 180 114 178Q106 141 106 117Q106 67 131 47T188 26Q242 26 287 73Q316 103 334 153T356 233T361 278Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6B&quot; d=&quot;M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-26&quot; d=&quot;M156 540Q156 620 201 668T302 716Q354 716 377 671T401 578Q401 505 287 386L274 373Q309 285 416 148L429 132L437 142Q474 191 543 309L562 341V349Q562 368 541 376T498 385H493V431H502L626 428Q709 428 721 431H727V385H712Q688 384 669 379T639 369T618 354T603 337T591 316T578 295Q537 223 506 176T464 117T454 104Q454 102 471 85T497 62Q543 24 585 24Q618 24 648 48T682 113V121H722V112Q721 94 714 75T692 32T646 -7T574 -22Q491 -19 414 42L402 51L391 42Q312 -22 224 -22Q144 -22 93 25T42 135Q42 153 46 169T55 197T74 225T96 249T125 278T156 308L195 347L190 360Q185 372 182 382T174 411T165 448T159 491T156 540ZM361 576Q361 613 348 646T305 679Q272 679 252 649T232 572Q232 497 255 426L259 411L267 420Q361 519 361 576ZM140 164Q140 103 167 64T240 24Q271 24 304 36T356 61T374 77Q295 156 235 262L220 292L210 310L193 293Q177 277 169 268T151 229T140 164Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2260&quot; d=&quot;M166 -215T159 -215T147 -212T141 -204T139 -197Q139 -190 144 -183L306 133H70Q56 140 56 153Q56 168 72 173H327L406 327H72Q56 332 56 347Q56 360 70 367H426Q597 702 602 707Q605 716 618 716Q625 716 630 712T636 703T638 696Q638 692 471 367H707Q722 359 722 347Q722 336 708 328L451 327L371 173H708Q722 163 722 153Q722 140 707 133H351Q175 -210 170 -212Q166 -215 159 -215Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239B&quot; d=&quot;M837 1154Q843 1148 843 1145Q843 1141 818 1106T753 1002T667 841T574 604T494 299Q417 -84 417 -609Q417 -641 416 -647T411 -654Q409 -655 366 -655Q299 -655 297 -654Q292 -652 292 -643T291 -583Q293 -400 304 -242T347 110T432 470T574 813T785 1136Q787 1139 790 1142T794 1147T796 1150T799 1152T802 1153T807 1154T813 1154H819H837Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239D&quot; d=&quot;M843 -635Q843 -638 837 -644H820Q801 -644 800 -643Q792 -635 785 -626Q684 -503 605 -363T473 -75T385 216T330 518T302 809T291 1093Q291 1144 291 1153T296 1164Q298 1165 366 1165Q409 1165 411 1164Q415 1163 416 1157T417 1119Q417 529 517 109T833 -617Q843 -631 843 -635Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239C&quot; d=&quot;M413 -9Q412 -9 407 -9T388 -10T354 -10Q300 -10 297 -9Q294 -8 293 -5Q291 5 291 127V300Q291 602 292 605L296 609Q298 610 366 610Q382 610 392 610T407 610T412 609Q416 609 416 592T417 473V127Q417 -9 413 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-33&quot; d=&quot;M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-D7&quot; d=&quot;M630 29Q630 9 609 9Q604 9 587 25T493 118L389 222L284 117Q178 13 175 11Q171 9 168 9Q160 9 154 15T147 29Q147 36 161 51T255 146L359 250L255 354Q174 435 161 449T147 471Q147 480 153 485T168 490Q173 490 175 489Q178 487 284 383L389 278L493 382Q570 459 587 475T609 491Q630 491 630 471Q630 464 620 453T522 355L418 250L522 145Q606 61 618 48T630 29Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-58&quot; d=&quot;M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239E&quot; d=&quot;M31 1143Q31 1154 49 1154H59Q72 1154 75 1152T89 1136Q190 1013 269 873T401 585T489 294T544 -8T572 -299T583 -583Q583 -634 583 -643T577 -654Q575 -655 508 -655Q465 -655 463 -654Q459 -653 458 -647T457 -609Q457 -58 371 340T100 1037Q87 1059 61 1098T31 1143Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A0&quot; d=&quot;M56 -644H50Q31 -644 31 -635Q31 -632 37 -622Q69 -579 100 -527Q286 -228 371 170T457 1119Q457 1161 462 1164Q464 1165 520 1165Q575 1165 577 1164Q582 1162 582 1153T583 1093Q581 910 570 752T527 400T442 40T300 -303T89 -626Q78 -640 75 -642T61 -644H56Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-239F&quot; d=&quot;M579 -9Q578 -9 573 -9T554 -10T520 -10Q466 -10 463 -9Q460 -8 459 -5Q457 5 457 127V300Q457 602 458 605L462 609Q464 610 532 610Q548 610 558 610T573 610T578 609Q582 609 582 592T583 473V127Q583 -9 579 -9Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-63&quot; d=&quot;M370 305T349 305T313 320T297 358Q297 381 312 396Q317 401 317 402T307 404Q281 408 258 408Q209 408 178 376Q131 329 131 219Q131 137 162 90Q203 29 272 29Q313 29 338 55T374 117Q376 125 379 127T395 129H409Q415 123 415 120Q415 116 411 104T395 71T366 33T318 2T249 -11Q163 -11 99 53T34 214Q34 318 99 383T250 448T370 421T404 357Q404 334 387 320Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-6F&quot; d=&quot;M28 214Q28 309 93 378T250 448Q340 448 405 380T471 215Q471 120 407 55T250 -10Q153 -10 91 57T28 214ZM250 30Q372 30 372 193V225V250Q372 272 371 288T364 326T348 362T317 390T268 410Q263 411 252 411Q222 411 195 399Q152 377 139 338T126 246V226Q126 130 145 91Q177 30 250 30Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-76&quot; d=&quot;M338 431Q344 429 422 429Q479 429 503 431H508V385H497Q439 381 423 345Q421 341 356 172T288 -2Q283 -11 263 -11Q244 -11 239 -2Q99 359 98 364Q93 378 82 381T43 385H19V431H25L33 430Q41 430 53 430T79 430T104 429T122 428Q217 428 232 431H240V385H226Q187 384 184 370Q184 366 235 234L286 102L377 341V349Q377 363 367 372T349 383T335 385H331V431H338Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5E&quot; d=&quot;M112 560L249 694L257 686Q387 562 387 560L361 531Q359 532 303 581L250 627L195 580Q182 569 169 557T148 538L140 532Q138 530 125 546L112 560Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ3-2C6&quot; d=&quot;M1439 564Q1434 564 1080 631T722 698Q719 698 362 631Q7 564 4 564L0 583Q-4 602 -4 603L720 772L1083 688Q1446 603 1447 603Q1447 602 1443 583L1439 564Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-AF&quot; d=&quot;M69 544V590H430V544H69Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6E&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6D&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-73&quot; d=&quot;M295 316Q295 356 268 385T190 414Q154 414 128 401Q98 382 98 349Q97 344 98 336T114 312T157 287Q175 282 201 278T245 269T277 256Q294 248 310 236T342 195T359 133Q359 71 321 31T198 -10H190Q138 -10 94 26L86 19L77 10Q71 4 65 -1L54 -11H46H42Q39 -11 33 -5V74V132Q33 153 35 157T45 162H54Q66 162 70 158T75 146T82 119T101 77Q136 26 198 26Q295 26 295 104Q295 133 277 151Q257 175 194 187T111 210Q75 227 54 256T33 318Q33 357 50 384T93 424T143 442T187 447H198Q238 447 268 432L283 424L292 431Q302 440 314 448H322H326Q329 448 335 442V310L329 304H301Q295 310 295 316Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-74&quot; d=&quot;M27 422Q80 426 109 478T141 600V615H181V431H316V385H181V241Q182 116 182 100T189 68Q203 29 238 29Q282 29 292 100Q293 108 293 146V181H333V146V134Q333 57 291 17Q264 -10 221 -10Q187 -10 162 2T124 33T105 68T98 100Q97 107 97 248V385H18V422H27Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3B2&quot; d=&quot;M29 -194Q23 -188 23 -186Q23 -183 102 134T186 465Q208 533 243 584T309 658Q365 705 429 705H431Q493 705 533 667T573 570Q573 465 469 396L482 383Q533 332 533 252Q533 139 448 65T257 -10Q227 -10 203 -2T165 17T143 40T131 59T126 65L62 -188Q60 -194 42 -194H29ZM353 431Q392 431 427 419L432 422Q436 426 439 429T449 439T461 453T472 471T484 495T493 524T501 560Q503 569 503 593Q503 611 502 616Q487 667 426 667Q384 667 347 643T286 582T247 514T224 455Q219 439 186 308T152 168Q151 163 151 147Q151 99 173 68Q204 26 260 26Q302 26 349 51T425 137Q441 171 449 214T457 279Q457 337 422 372Q380 358 347 358H337Q258 358 258 389Q258 396 261 403Q275 431 353 431Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3F5&quot; d=&quot;M227 -11Q149 -11 95 41T40 174Q40 262 87 322Q121 367 173 396T287 430Q289 431 329 431H367Q382 426 382 411Q382 385 341 385H325H312Q191 385 154 277L150 265H327Q340 256 340 246Q340 228 320 219H138V217Q128 187 128 143Q128 77 160 52T231 26Q258 26 284 36T326 57T343 68Q350 68 354 58T358 39Q358 36 357 35Q354 31 337 21T289 0T227 -11Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-39B&quot; d=&quot;M320 708Q326 716 340 716H348H355Q367 716 372 708Q374 706 423 547T523 226T575 62Q581 52 591 50T634 46H661V0H653Q644 3 532 3Q411 3 390 0H379V46H392Q464 46 464 65Q463 70 390 305T316 539L246 316Q177 95 177 84Q177 72 198 59T248 46H253V0H245Q230 3 130 3Q47 3 38 0H32V46H45Q112 51 127 91Q128 92 224 399T320 708Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-28&quot; d=&quot;M758 -1237T758 -1240T752 -1249H736Q718 -1249 717 -1248Q711 -1245 672 -1199Q237 -706 237 251T672 1700Q697 1730 716 1749Q718 1750 735 1750H752Q758 1744 758 1741Q758 1737 740 1713T689 1644T619 1537T540 1380T463 1176Q348 802 348 251Q348 -242 441 -599T744 -1218Q758 -1237 758 -1240Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-29&quot; d=&quot;M33 1741Q33 1750 51 1750H60H65Q73 1750 81 1743T119 1700Q554 1207 554 251Q554 -707 119 -1199Q76 -1250 66 -1250Q65 -1250 62 -1250T56 -1249Q55 -1249 53 -1249T49 -1250Q33 -1250 33 -1239Q33 -1236 50 -1214T98 -1150T163 -1052T238 -910T311 -727Q443 -335 443 251Q443 402 436 532T405 831T339 1142T224 1438T50 1716Q33 1737 33 1741Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-52&quot; d=&quot;M230 637Q203 637 198 638T193 649Q193 676 204 682Q206 683 378 683Q550 682 564 680Q620 672 658 652T712 606T733 563T739 529Q739 484 710 445T643 385T576 351T538 338L545 333Q612 295 612 223Q612 212 607 162T602 80V71Q602 53 603 43T614 25T640 16Q668 16 686 38T712 85Q717 99 720 102T735 105Q755 105 755 93Q755 75 731 36Q693 -21 641 -21H632Q571 -21 531 4T487 82Q487 109 502 166T517 239Q517 290 474 313Q459 320 449 321T378 323H309L277 193Q244 61 244 59Q244 55 245 54T252 50T269 48T302 46H333Q339 38 339 37T336 19Q332 6 326 0H311Q275 2 180 2Q146 2 117 2T71 2T50 1Q33 1 33 10Q33 12 36 24Q41 43 46 45Q50 46 61 46H67Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628Q287 635 230 637ZM630 554Q630 586 609 608T523 636Q521 636 500 636T462 637H440Q393 637 386 627Q385 624 352 494T319 361Q319 360 388 360Q466 361 492 367Q556 377 592 426Q608 449 619 486T630 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-57&quot; d=&quot;M436 683Q450 683 486 682T553 680Q604 680 638 681T677 682Q695 682 695 674Q695 670 692 659Q687 641 683 639T661 637Q636 636 621 632T600 624T597 615Q597 603 613 377T629 138L631 141Q633 144 637 151T649 170T666 200T690 241T720 295T759 362Q863 546 877 572T892 604Q892 619 873 628T831 637Q817 637 817 647Q817 650 819 660Q823 676 825 679T839 682Q842 682 856 682T895 682T949 681Q1015 681 1034 683Q1048 683 1048 672Q1048 666 1045 655T1038 640T1028 637Q1006 637 988 631T958 617T939 600T927 584L923 578L754 282Q586 -14 585 -15Q579 -22 561 -22Q546 -22 542 -17Q539 -14 523 229T506 480L494 462Q472 425 366 239Q222 -13 220 -15T215 -19Q210 -22 197 -22Q178 -22 176 -15Q176 -12 154 304T131 622Q129 631 121 633T82 637H58Q51 644 51 648Q52 671 64 683H76Q118 680 176 680Q301 680 313 683H323Q329 677 329 674T327 656Q322 641 318 637H297Q236 634 232 620Q262 160 266 136L501 550L499 587Q496 629 489 632Q483 636 447 637Q428 637 422 639T416 648Q416 650 418 660Q419 664 420 669T421 676T424 680T428 682T436 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
The sweep operator as defined in (Dempster, 1969), commonly referred to as the SWP operator, is a useful tool for a computational statistician working with covariance matrices.  In particular, the SWP operator allows a statistician to quickly regress all variables against one specified variable, obtaining OLS estimates for regression coefficients and variances in a single application.  Subsequent applications of the SWP operator allows for regressing against more variables. 
&lt;/p&gt;

&lt;p&gt;
In this blog post, I will define the sweep operator, provide an application of the sweep data to simulated data, and provide some references for further study. Examples will be provided in R through the &lt;code&gt;ISR3&lt;/code&gt; package (Lisic, 2016).
&lt;/p&gt;

&lt;p&gt;
The basic SWP operator is parameterized by a matrix and a set of indices associated with rows and columns of the matrix being swept. E.g. to sweep the matrix &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.678ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 722.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; by the &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.42ex&quot; height=&quot;2.676ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -1006.6 1041.8 1152.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-6C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(278,422)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;361&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-68&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; index, such that &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;7.86ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 3384.1 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1028&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2084&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2883&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, the operator has the form &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;11.788ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 5075.5 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2266&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3295&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3574&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3963&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4686&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.  The operator may also be written more descriptively by listing the elements of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.743ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 750.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; as &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;10.738ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 4623.5 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2266&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2843&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3122&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3511&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4234&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;. The application of the SWP operator to the &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.42ex&quot; height=&quot;2.676ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -1006.6 1041.8 1152.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-6C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(278,422)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;361&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-68&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; row and column of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.678ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 722.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; produces a new matrix with elements
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;35.039ex&quot; height=&quot;13.176ex&quot; style=&quot;vertical-align: -5.772ex;&quot; viewBox=&quot;0 -3087.6 15086.1 5673&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1609&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2665,0)&quot;&gt;&lt;g transform=&quot;translate(0,2985)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1156&quot; xlink:href=&quot;#MJSZ4-239B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-3671.5230125529683) scale(1,3.1252422464042033)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-4826&quot; xlink:href=&quot;#MJSZ4-239D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1042,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,2068)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;690&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1746&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3602&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,45)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;690&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1746&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2295&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-26&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3323&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4122&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2260&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5179&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1977)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;690&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2260&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1746&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2295&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-26&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3323&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4122&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2260&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5179&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6467,0)&quot;&gt;&lt;g transform=&quot;translate(1328,2068)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1068&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;505&quot; y=&quot;629&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-137)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1686,45)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1131&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,717)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(91,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-137)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1977)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1554&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2332,0)&quot;&gt;&lt;g transform=&quot;translate(342,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1948&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,718)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(945,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(565,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;


&lt;p&gt;
As an example, consider the application of the SWP operator to the first row and column of the &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-10-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.165ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 2223.9 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use x=&quot;722&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-D7&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1723&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; covariance matrix for the random variables &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-11-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;13.328ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 5738.6 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(500,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1782&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2228,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;3510&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3955,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;5238&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;,
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-12-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;23.851ex&quot; height=&quot;9.176ex&quot; style=&quot;vertical-align: -4.005ex;&quot; viewBox=&quot;0 -2226.5 10269 3950.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1000&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2056,0)&quot;&gt;&lt;g transform=&quot;translate(0,2150)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1156&quot; xlink:href=&quot;#MJSZ4-239B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-2033.6645264847511) scale(1,0.4446227929373997)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-3155&quot; xlink:href=&quot;#MJSZ4-239D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1042,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,1350)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-50)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1450)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2368,0)&quot;&gt;&lt;g transform=&quot;translate(0,1350)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-50)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1450)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(4748,0)&quot;&gt;&lt;g transform=&quot;translate(0,1350)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-50)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1450)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(7336,2150)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1155&quot; xlink:href=&quot;#MJSZ4-239E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-2033.645264847512) scale(1,0.4462279293739968)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239F&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-3155&quot; xlink:href=&quot;#MJSZ4-23A0&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
resulting in 
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-13-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;53.783ex&quot; height=&quot;14.176ex&quot; style=&quot;vertical-align: -6.505ex;&quot; viewBox=&quot;0 -3302.9 23156.3 6103.5&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2266&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3045&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3490,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1112&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;5269&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(6326,0)&quot;&gt;&lt;g transform=&quot;translate(0,3180)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1156&quot; xlink:href=&quot;#MJSZ4-239B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-4055.347833388574) scale(1,3.75343344253449)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-5217&quot; xlink:href=&quot;#MJSZ4-239D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1042,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,2263)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;576&quot; y=&quot;629&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(778,40)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,584)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(778,-2196)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,597)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3177,0)&quot;&gt;&lt;g transform=&quot;translate(3651,2263)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,584)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1049,40)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1601&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2380,0)&quot;&gt;&lt;g transform=&quot;translate(342,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,711)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;705&quot; y=&quot;425&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-267)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-2196)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1601&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2380,0)&quot;&gt;&lt;g transform=&quot;translate(342,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;2218&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,597)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1049,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(584,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(9238,0)&quot;&gt;&lt;g transform=&quot;translate(3651,2263)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,597)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,40)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1601&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2380,0)&quot;&gt;&lt;g transform=&quot;translate(342,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;2218&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,597)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1049,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(584,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1049,-2196)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1601&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2380,0)&quot;&gt;&lt;g transform=&quot;translate(342,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1169&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,724)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;705&quot; y=&quot;425&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-267)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-140)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(15509,3180)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1155&quot; xlink:href=&quot;#MJSZ4-239E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-4055.3285717513345) scale(1,3.7550385789710874)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239F&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-5217&quot; xlink:href=&quot;#MJSZ4-23A0&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;22877&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
How is this useful?  Well, if we substitute the &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-14-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.165ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 2223.9 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use x=&quot;722&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-D7&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1723&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; covariance matrix &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-15-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.678ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 722.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; with the sample covariance matrix, where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-16-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.576ex&quot; height=&quot;3.176ex&quot; style=&quot;vertical-align: -1.005ex;&quot; viewBox=&quot;0 -934.9 1109.1 1367.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;926&quot; y=&quot;488&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;867&quot; y=&quot;-463&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is an estimator of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-17-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.273ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -576.1 1409 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;521&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; and
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-18-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;50.361ex&quot; height=&quot;6.676ex&quot; style=&quot;vertical-align: -2.671ex;&quot; viewBox=&quot;0 -1724.2 21683.2 2874.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-63&quot;&gt;&lt;/use&gt;&lt;use x=&quot;444&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-6F&quot;&gt;&lt;/use&gt;&lt;use x=&quot;945&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-76&quot;&gt;&lt;/use&gt;&lt;use x=&quot;14&quot; y=&quot;-7&quot; xlink:href=&quot;#MJSZ3-2C6&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1473&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1863,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;63&quot; y=&quot;7&quot; xlink:href=&quot;#MJMAIN-AF&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;2904&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3349,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;63&quot; y=&quot;7&quot; xlink:href=&quot;#MJMAIN-AF&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4313&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4980&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(5759,0)&quot;&gt;&lt;g transform=&quot;translate(397,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;14877&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,814)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1494&quot; y=&quot;675&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1124&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2471,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1494&quot; y=&quot;675&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;878&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1657&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;5153&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(5543,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;624&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;7171&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(8171,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;63&quot; y=&quot;7&quot; xlink:href=&quot;#MJMAIN-AF&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;9465&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9854&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(10244,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;878&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1157&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;12326&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(13326,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;63&quot; y=&quot;7&quot; xlink:href=&quot;#MJMAIN-AF&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;14368&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5587,-771)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;600&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;990&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1812&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2813&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3313&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;21404&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
 is an estimator of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-19-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.094ex&quot; height=&quot;2.343ex&quot; style=&quot;vertical-align: -1.005ex;&quot; viewBox=&quot;0 -576.1 1331.9 1008.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, then by sweeping by the &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-20-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.682ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -934.9 1154.9 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(500,393)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;394&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; index, &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-21-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;8.329ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 3586.1 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1028&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2084&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3085&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, we can get the simple linear regression (SLR) estimates for &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-22-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;15.506ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 6676.3 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1575&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2631,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(566,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(4020,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;5269&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6269&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3F5&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; for all &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-23-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;9.736ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 4191.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;799&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1744&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2245&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2745&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3190&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3691&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;:
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-24-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;39.011ex&quot; height=&quot;12.176ex&quot; style=&quot;vertical-align: -5.189ex;&quot; viewBox=&quot;0 -2872.4 16796.5 5242.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2266&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3045&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3490,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1112&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;5269&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(6326,0)&quot;&gt;&lt;g transform=&quot;translate(0,2734)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1156&quot; xlink:href=&quot;#MJSZ4-239B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-3179.4725352720416) scale(1,2.319922316320854)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-4324&quot; xlink:href=&quot;#MJSZ4-239D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1042,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(56,1744)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-39B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;97&quot; y=&quot;294&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;982&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-42)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1828)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2973,0)&quot;&gt;&lt;g transform=&quot;translate(0,1744)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(52,-42)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;36&quot; y=&quot;9&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(52,-1828)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;36&quot; y=&quot;9&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5956,0)&quot;&gt;&lt;g transform=&quot;translate(0,1744)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(52,-42)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;36&quot; y=&quot;9&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(52,-1828)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;36&quot; y=&quot;9&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(9149,2734)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1155&quot; xlink:href=&quot;#MJSZ4-239E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-3179.453273634803) scale(1,2.321527452757451)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239F&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-4324&quot; xlink:href=&quot;#MJSZ4-23A0&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;16518&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt; 
where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-25-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;4.72ex&quot; height=&quot;3.676ex&quot; style=&quot;vertical-align: -1.171ex;&quot; viewBox=&quot;0 -1078.4 2032.3 1582.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;820&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1098&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is the simple linear model estimator of the regression coefficient for the linear model &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-26-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;14.843ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 6390.7 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1575&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2631,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(566,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3877,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4983&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5984&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3F5&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; for &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-27-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;9.736ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 4191.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;799&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1744,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(500,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;945&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1946&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-28-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.078ex&quot; height=&quot;3.176ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -1078.4 1325.2 1367.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-39B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;97&quot; y=&quot;294&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;982&quot; y=&quot;-230&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is the inverse of the covariance matrix of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-29-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;0.693ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 298.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; unscaled by &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-30-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.398ex&quot; height=&quot;2.343ex&quot; style=&quot;vertical-align: -0.505ex;&quot; viewBox=&quot;0 -791.3 2323.9 1008.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;822&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1823&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, and &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-31-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;4.786ex&quot; height=&quot;3.009ex&quot; style=&quot;vertical-align: -1.171ex;&quot; viewBox=&quot;0 -791.3 2060.6 1295.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;36&quot; y=&quot;9&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;934&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1212&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is the sample covariance of the residuals from the regression models on &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-32-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;0.693ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 298.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; unscaled by &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-33-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.398ex&quot; height=&quot;2.343ex&quot; style=&quot;vertical-align: -0.505ex;&quot; viewBox=&quot;0 -791.3 2323.9 1008.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;822&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1823&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.
&lt;p&gt;&lt;/p&gt;



&lt;h2&gt;Example&lt;/h2&gt;


&lt;p&gt;
Lets try this with some real data.  I have used the SWP function included with the &lt;code&gt;ISR3&lt;/code&gt; package.
&lt;/p&gt;&lt;div class=&quot;chunk&quot; id=&quot;main&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ISR3)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# generate a positive definite matrix for covariance&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;Sigma&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rWishart&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,p&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p))[,,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;Sigma_inv&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;chol2inv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;chol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Sigma))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;Sigma_inv_chol&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;chol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Sigma_inv)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# generate 'n' multivate normal deviates&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;Sigma_inv_chol&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%*%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;p),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;nrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=p)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;X_%d&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;p)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;XX&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%*%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;X&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#Sweep by the first row/column of XX&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;SWP_1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;SWP&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(XX,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;SWP_1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##              X_1        X_2         X_3
## X_1 -0.002381092  0.1375626 -0.01674788
## X_2  0.137562633 50.0987932 -4.95181624
## X_3 -0.016747875 -4.9518162 41.73979419
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
We can compare this output with the results from the simple linear models &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-34-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;11.653ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 5017.2 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1560&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2616,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3642,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(566,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; and &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-35-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;11.653ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 5017.2 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1560&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2616,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3642,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(566,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;: 
&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-2&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# linear models&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;fit_21&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;lm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X_2&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;~ -&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;X_1,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;fit_31&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;lm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X_3&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;~ -&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;X_1,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# SLR coefficents for X_1&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(fit_21&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;coefficients)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##       X_1 
## 0.1375626
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(fit_31&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;coefficients)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##         X_1 
## -0.01674788
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# sum of squares&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(fit_21&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;residuals&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;## [1] 50.09879
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(fit_31&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;residuals&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;## [1] 41.73979
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# covariance between X_2 and X_3 given X_1&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(fit_21&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;residuals&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;fit_31&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;residuals))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;## [1] -4.951816
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# negative inverse of the covariance matrix of X_1&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;((n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(X[,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;])) )&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;## [1] -0.002381293
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
Here we see that the coefficients from &lt;code&gt;lm&lt;/code&gt; match up to our swept results.  Likewise, the diagonal terms for the second and third column are equivalent to the sum of squares or the residuals.  The remaining unmatched term is just the negative inverse of the covariance matrix of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-36-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.979ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 1282.4 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; unscaled by &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-37-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.398ex&quot; height=&quot;2.343ex&quot; style=&quot;vertical-align: -0.505ex;&quot; viewBox=&quot;0 -791.3 2323.9 1008.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;822&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1823&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;. 
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
A subsequent sweep on the second rows and columns produces the matrix,
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-38-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;58.708ex&quot; height=&quot;8.843ex&quot; style=&quot;vertical-align: -3.838ex;&quot; viewBox=&quot;0 -2154.8 25277.1 3807.2&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2266&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3045&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3490,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(389,0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2266&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3045&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3490,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1112&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;5381&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;9539&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(10595,0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;556&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;12862&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13140&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13891&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(14336,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1112&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;16115&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(17172,0)&quot;&gt;&lt;g transform=&quot;translate(0,2052)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1156&quot; xlink:href=&quot;#MJSZ4-239B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;0&quot; y=&quot;-2960&quot; xlink:href=&quot;#MJSZ4-239D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1042,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,863)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-39B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;97&quot; y=&quot;294&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(694,716)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;778&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;982&quot; y=&quot;-350&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1024,-1129)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;883&quot; y=&quot;997&quot; xlink:href=&quot;#MJMATHI-54&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-248)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;278&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3466,0)&quot;&gt;&lt;g transform=&quot;translate(655,863)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;278&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1129)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;36&quot; y=&quot;9&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6784,2052)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1155&quot; xlink:href=&quot;#MJSZ4-239E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;0&quot; y=&quot;-2960&quot; xlink:href=&quot;#MJSZ4-23A0&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;24998&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt; 
where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-39-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;10.525ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 4531.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1028&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2084&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2585&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3085&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3530&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4031&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;,  &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-40-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.946ex&quot; height=&quot;3.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -1293.7 1698.9 1654.5&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-39B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;97&quot; y=&quot;294&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(694,716)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;778&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;982&quot; y=&quot;-350&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is now the inverse covariance matrix of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-41-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.979ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 1282.4 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; and &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-42-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.979ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 1282.4 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1171&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; and &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-43-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.374ex&quot; height=&quot;3.676ex&quot; style=&quot;vertical-align: -1.171ex;&quot; viewBox=&quot;0 -1078.4 1452.5 1582.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;278&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is the matrix 
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-44-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;10.484ex&quot; height=&quot;7.843ex&quot; style=&quot;vertical-align: -3.338ex;&quot; viewBox=&quot;0 -1939.5 4514 3376.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(959,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,857)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-929)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B2&quot;&gt;&lt;/use&gt;&lt;use x=&quot;124&quot; y=&quot;283&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(624,-231)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;3276&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ4-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4235&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
Again, we can quickly check the results by comparing the output from &lt;code&gt;lm&lt;/code&gt; to our SWP operator.  
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
A final sweep by the third row and column produces &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-45-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;6.119ex&quot; height=&quot;3.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -1293.7 2634.7 1654.5&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-39B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;97&quot; y=&quot;294&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(694,716)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;778&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(694,-248)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-33&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, the negative inverse of the unscaled covariance matrix of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-46-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.98ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 852.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.  This can be quickly verified through &lt;code&gt;R&lt;/code&gt;:
&lt;/p&gt;&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-3&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;SWP&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(XX,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;chol2inv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;chol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(XX))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##              X_1          X_2          X_3
## X_1 0.000000e+00 0.000000e+00 1.355253e-20
## X_2 0.000000e+00 3.469447e-18 8.673617e-19
## X_3 1.355253e-20 8.673617e-19 0.000000e+00
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;


&lt;h2&gt;Undo!&lt;/h2&gt;

&lt;p&gt;
We can also undo sweeps with the reverse sweep (RSWP) operator through the following element-wise operations
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-47-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;35.039ex&quot; height=&quot;13.176ex&quot; style=&quot;vertical-align: -5.772ex;&quot; viewBox=&quot;0 -3087.6 15086.1 5673&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1609&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2665,0)&quot;&gt;&lt;g transform=&quot;translate(0,2985)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1156&quot; xlink:href=&quot;#MJSZ4-239B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-3671.5230125529683) scale(1,3.1252422464042033)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-239C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-4826&quot; xlink:href=&quot;#MJSZ4-239D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1042,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,2068)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;690&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1746&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2545&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3602&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,45)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;690&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1746&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2295&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-26&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3323&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4122&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2260&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5179&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1977)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;690&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2260&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1746&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2295&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-26&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3323&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4122&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2260&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5179&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6467,0)&quot;&gt;&lt;g transform=&quot;translate(1328,2068)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1068&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;505&quot; y=&quot;629&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(60,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-137)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(1296,45)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;g transform=&quot;translate(120,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1131&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,717)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(91,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-137)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,-1977)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(571,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1554&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2332,0)&quot;&gt;&lt;g transform=&quot;translate(342,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1948&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,718)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(945,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(565,-345)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(404,-156)&quot;&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;298&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
Caution should be used when reverse sweeping, as in application &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-48-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;24.494ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 10546 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-52&quot;&gt;&lt;/use&gt;&lt;use x=&quot;759&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1405&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2453&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3205&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3483&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4234&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4512&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4902&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5547&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-57&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6596&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7347&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7626&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8376&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-5D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8655&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9044&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9767&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10156&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is not necessarily equal to &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-49-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.678ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 722.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; due to floating point error.  In particular when the matrix is ill-conditioned there may be considerable departure between the calculated identity and the original matrix. 
&lt;p&gt;&lt;/p&gt;


&lt;h2&gt;What Next?&lt;/h2&gt;

&lt;p&gt;
A few good references on the subject beyond (Dempster, 1969) can be found in (Goodknight, 1979) and (Little and Rubin, 2014).  There are a few slight differences between these implementations, but all generally do the same thing.
&lt;/p&gt;

&lt;p&gt;One function that doesn't do the same thing is the &lt;code&gt;sweep&lt;/code&gt; function in &lt;code&gt;R&lt;/code&gt;.  This function can be used to write a SWP implementation, but doesn't sweep by itself.
&lt;/p&gt;

&lt;p&gt;
Code examples can be found in the &lt;code&gt;ISR3&lt;/code&gt; package on &lt;code&gt;CRAN&lt;/code&gt; and in lots of other &lt;a href=&quot;https://www.rdocumentation.org/search?q=sweep&quot;&gt;packages&lt;/a&gt;.  
Examples in &lt;code&gt;C&lt;/code&gt; can be found in &lt;code&gt;ISR3&lt;/code&gt; and as an internal function in the &lt;code&gt;MNP&lt;/code&gt; package (Imai and Van Dyk, 2013).
&lt;/p&gt;

&lt;p&gt;
Enjoy your sweeping, next time I'll go over sweeping with the generalized inverse! 
&lt;/p&gt;

&lt;img src=&quot;https://openclipart.org/image/300px/svg_to_png/223800/1438128529.png&amp;amp;disposition=attachment&quot; alt=&quot;broom&quot; title=&quot;broom by  ericlemerdy ( https://openclipart.org/user-detail/ericlemerdy )&quot;&gt;

&lt;h2&gt;References&lt;/h2&gt;

&lt;p&gt;
Dempster, A.P. (1969). &lt;i&gt;Elements of continuous multivariate analysis&lt;/i&gt;. Reading, MA: Addison-Wesley.
&lt;/p&gt;

&lt;p&gt;
Goodnight, J. H. (1979). A tutorial on the SWEEP operator. The American Statistician, 33(3), 149-158.
&lt;/p&gt;

&lt;p&gt;
Imai, K., and Van Dyk, D. A. (2013). MNP: R Package for fitting the Multinomial Probit Model, R package version 2.6-4, &lt;a href=&quot;https://CRAN.R-project.org/package=MNP&quot;&gt;https://CRAN.R-project.org/package=MNP&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
Lisic, J. J. (2016). ISR3: Iterative Sequential Regression, R package version 0.98, &lt;a href=&quot;https://CRAN.R-project.org/package=ISR3&quot;&gt;https://CRAN.R-project.org/package=ISR3&lt;/a&gt;
&lt;/p&gt;


&lt;p&gt;
Little, R. J., and Rubin, D. B. (2014). &lt;i&gt;Statistical analysis with missing data&lt;/i&gt;. John Wiley &amp;amp; Sons.
&lt;/p&gt;

</description>
        <pubDate>Tue, 13 Dec 2016 00:00:00 -0500</pubDate>
        <link>http://meanmean.me/2016/12/13/swp.html</link>
        <guid isPermaLink="true">http://meanmean.me/2016/12/13/swp.html</guid>
        
        
      </item>
    
      <item>
        <title>meanShiftR</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-78&quot; d=&quot;M201 0Q189 3 102 3Q26 3 17 0H11V46H25Q48 47 67 52T96 61T121 78T139 96T160 122T180 150L226 210L168 288Q159 301 149 315T133 336T122 351T113 363T107 370T100 376T94 379T88 381T80 383Q74 383 44 385H16V431H23Q59 429 126 429Q219 429 229 431H237V385Q201 381 201 369Q201 367 211 353T239 315T268 274L272 270L297 304Q329 345 329 358Q329 364 327 369T322 376T317 380T310 384L307 385H302V431H309Q324 428 408 428Q487 428 493 431H499V385H492Q443 385 411 368Q394 360 377 341T312 257L296 236L358 151Q424 61 429 57T446 50Q464 46 499 46H516V0H510H502Q494 1 482 1T457 2T432 2T414 3Q403 3 377 3T327 1L304 0H295V46H298Q309 46 320 51T331 63Q331 65 291 120L250 175Q249 174 219 133T185 88Q181 83 181 74Q181 63 188 55T206 46Q208 46 208 23V0H201Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-A8&quot; d=&quot;M95 612Q95 633 112 651T153 669T193 652T210 612Q210 588 194 571T152 554L127 560Q95 577 95 612ZM289 611Q289 634 304 649T335 668Q336 668 340 668T346 669Q369 669 386 652T404 612T387 572T346 554Q323 554 306 570T289 611Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C7&quot; d=&quot;M114 611L127 630L136 644Q138 644 193 612Q248 581 250 581L306 612Q361 644 363 644L385 611L318 562L249 513L114 611Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-67&quot; d=&quot;M311 43Q296 30 267 15T206 0Q143 0 105 45T66 160Q66 265 143 353T314 442Q361 442 401 394L404 398Q406 401 409 404T418 412T431 419T447 422Q461 422 470 413T480 394Q480 379 423 152T363 -80Q345 -134 286 -169T151 -205Q10 -205 10 -137Q10 -111 28 -91T74 -71Q89 -71 102 -80T116 -111Q116 -121 114 -130T107 -144T99 -154T92 -162L90 -164H91Q101 -167 151 -167Q189 -167 211 -155Q234 -144 254 -122T282 -75Q288 -56 298 -13Q311 35 311 43ZM384 328L380 339Q377 350 375 354T369 368T359 382T346 393T328 402T306 405Q262 405 221 352Q191 313 171 233T151 117Q151 38 213 38Q269 38 323 108L331 118L384 328Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-221D&quot; d=&quot;M56 124T56 216T107 375T238 442Q260 442 280 438T319 425T352 407T382 385T406 361T427 336T442 315T455 297T462 285L469 297Q555 442 679 442Q687 442 722 437V398H718Q710 400 694 400Q657 400 623 383T567 343T527 294T503 253T495 235Q495 231 520 192T554 143Q625 44 696 44Q717 44 719 46H722V-5Q695 -11 678 -11Q552 -11 457 141Q455 145 454 146L447 134Q362 -11 235 -11Q157 -11 107 56ZM93 213Q93 143 126 87T220 31Q258 31 292 48T349 88T389 137T413 178T421 196Q421 200 396 239T362 288Q322 345 288 366T213 387Q163 387 128 337T93 213Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-4B&quot; d=&quot;M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2032&quot; d=&quot;M79 43Q73 43 52 49T30 61Q30 68 85 293T146 528Q161 560 198 560Q218 560 240 545T262 501Q262 496 260 486Q259 479 173 263T84 45T79 43Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-76&quot; d=&quot;M173 380Q173 405 154 405Q130 405 104 376T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Q21 294 29 316T53 368T97 419T160 441Q202 441 225 417T249 361Q249 344 246 335Q246 329 231 291T200 202T182 113Q182 86 187 69Q200 26 250 26Q287 26 319 60T369 139T398 222T409 277Q409 300 401 317T383 343T365 361T357 383Q357 405 376 424T417 443Q436 443 451 425T467 367Q467 340 455 284T418 159T347 40T241 -11Q177 -11 139 22Q102 54 102 117Q102 148 110 181T151 298Q173 362 173 380Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-4E&quot; d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-48&quot; d=&quot;M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 219 683Q260 681 355 681Q389 681 418 681T463 682T483 682Q499 682 499 672Q499 670 497 658Q492 641 487 638H485Q483 638 480 638T473 638T464 637T455 637Q416 636 405 634T387 623Q384 619 355 500Q348 474 340 442T328 395L324 380Q324 378 469 378H614L615 381Q615 384 646 504Q674 619 674 627T617 637Q594 637 587 639T580 648Q580 650 582 660Q586 677 588 679T604 682Q609 682 646 681T740 680Q802 680 835 681T871 682Q888 682 888 672Q888 645 876 638H874Q872 638 869 638T862 638T853 637T844 637Q805 636 794 634T776 623Q773 618 704 340T634 58Q634 51 638 51Q646 48 692 46H723Q729 38 729 37T726 19Q722 6 716 0H701Q664 2 567 2Q533 2 504 2T458 2T437 1Q420 1 420 10Q420 15 423 24Q428 43 433 45Q437 46 448 46H454Q481 46 514 49Q520 50 522 50T528 55T534 64T540 82T547 110T558 153Q565 181 569 198Q602 330 602 331T457 332H312L279 197Q245 63 245 58Q245 51 253 49T303 46H334Q340 38 340 37T337 19Q333 6 327 0H312Q275 2 178 2Q144 2 115 2T69 2T48 1Q31 1 31 10Q31 12 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-28&quot; d=&quot;M152 251Q152 646 388 850H416Q422 844 422 841Q422 837 403 816T357 753T302 649T255 482T236 250Q236 124 255 19T301 -147T356 -251T403 -315T422 -340Q422 -343 416 -349H388Q359 -325 332 -296T271 -213T212 -97T170 56T152 251Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-29&quot; d=&quot;M305 251Q305 -145 69 -349H56Q43 -349 39 -347T35 -338Q37 -333 60 -307T108 -239T160 -136T204 27T221 250T204 473T160 636T108 740T60 807T35 839Q35 850 50 850H56H69Q197 743 256 566Q305 425 305 251Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2F&quot; d=&quot;M423 750Q432 750 438 744T444 730Q444 725 271 248T92 -240Q85 -250 75 -250Q68 -250 62 -245T56 -231Q56 -221 230 257T407 740Q411 750 423 750Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3C&quot; d=&quot;M694 -11T694 -19T688 -33T678 -40Q671 -40 524 29T234 166L90 235Q83 240 83 250Q83 261 91 266Q664 540 678 540Q681 540 687 534T694 519T687 505Q686 504 417 376L151 250L417 124Q686 -4 687 -5Q694 -11 694 -19Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3B4&quot; d=&quot;M195 609Q195 656 227 686T302 717Q319 716 351 709T407 697T433 690Q451 682 451 662Q451 644 438 628T403 612Q382 612 348 641T288 671T249 657T235 628Q235 584 334 463Q401 379 401 292Q401 169 340 80T205 -10H198Q127 -10 83 36T36 153Q36 286 151 382Q191 413 252 434Q252 435 245 449T230 481T214 521T201 566T195 609ZM112 130Q112 83 136 55T204 27Q233 27 256 51T291 111T309 178T316 232Q316 267 309 298T295 344T269 400L259 396Q215 381 183 342T137 256T118 179T112 130Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
In this blog post, I will be introducing the meanShiftR package.  meanShiftR is a rewrite of my original mean shift R package from 2013, based on the &lt;a href=&quot;http://www.cs.ubc.ca/research/flann/&quot;&gt;Fast Library for Approximate Nearest Neighbors (FLANN)&lt;/a&gt;.
The meanShiftR package is focused on providing to R users the most computationally efficient mean shift implementations available in the literature.
This includes approximations to the mean shift algorithm through kernel truncations and approximate nearest-neighbor (ANN) approaches.
&lt;/p&gt;


&lt;!-- algorithm --&gt;
&lt;p&gt;
The mean shift algorithm is a steepest ascent classification algorithm, where classification is performed by fixed point iteration to a local maxima of a kernel density estimate.  This method is originally credited to (Fukunaga and Hostetler, 1975), but didn't see wide-scale adoption until it was popularized by (Cheng, 1995).  
This algorithm has a fairly simple form of a convex combination of the support of the kernel density estimate, where the weight is calculated from the function &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;6.993ex&quot; height=&quot;2.676ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -863.1 3010.9 1152.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;use x=&quot;758&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-221D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1814,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4B&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1274&quot; y=&quot;513&quot; xlink:href=&quot;#MJMAIN-2032&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, the derivative of kernel &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.066ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 889.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.  In the computer science literature this function &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.116ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -576.1 480.5 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is commonly refered to as the &lt;i&gt;profile&lt;/i&gt; and &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.066ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 889.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is refered to as the &lt;i&gt;shadow kernel&lt;/i&gt;.   
&lt;/p&gt;&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
The explicit formulation of the mean shift for &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.461ex&quot; height=&quot;2.676ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -1006.6 1490.2 1152.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;890&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; (the point being classified) is, 
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;49.73ex&quot; height=&quot;8.176ex&quot; style=&quot;vertical-align: -3.505ex;&quot; viewBox=&quot;0 -2011.3 21411.3 3520.2&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,412)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1658&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2436,0)&quot;&gt;&lt;g transform=&quot;translate(397,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;18178&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,950)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1494&quot; y=&quot;675&quot; xlink:href=&quot;#MJMATHI-4E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1191&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2519,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;3483&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4130,0)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ1-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;458&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(848,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1513&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2014&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;3355&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4355,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5320,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;550&quot; y=&quot;513&quot; xlink:href=&quot;#MJMATHI-54&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6307,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-48&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(905,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;778&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;8217&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(8607,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1513&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2014&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;11114&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(12115,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;13079&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13469&quot; y=&quot;-1&quot; xlink:href=&quot;#MJSZ1-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(542,-982)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1494&quot; y=&quot;675&quot; xlink:href=&quot;#MJMATHI-4E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;412&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1191&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;2519&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3166,0)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ1-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;458&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(848,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,288)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1513&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2014&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;3355&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4355,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5320,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;550&quot; y=&quot;408&quot; xlink:href=&quot;#MJMATHI-54&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6307,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-48&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(905,288)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;778&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;8217&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(8607,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,288)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1513&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2014&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;11114&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(12115,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;13079&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13469&quot; y=&quot;-1&quot; xlink:href=&quot;#MJSZ1-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;21132&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
Where, the support is defined by the points in &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;15.691ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 6755.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;809&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1194&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2139&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2640&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3140&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3586&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4031&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4476&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4921&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5366&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6255&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; and kernel bandwidth paramter is identified as &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.064ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 888.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-48&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.  &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-10-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.064ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 888.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-48&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is assumed to be of full rank and symmetric in this formula.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
This algorithm identifies local maxima by updating &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-11-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;3.739ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 1610 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use x=&quot;735&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; at each iteration, starting with a set of initial points.
Iteration continues until a fixed number of iterations is met or &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-12-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;27.146ex&quot; height=&quot;3.176ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -1006.6 11687.7 1367.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;278&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(557,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;2159&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3160,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1513&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2014&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;5445&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5724&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6002&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2F&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6503&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6781&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(7060,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-76&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(485,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;734&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1513&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2014&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;9345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9623&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10179&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11236&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B4&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-13-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.049ex&quot; height=&quot;2.343ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -863.1 451.5 1008.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3B4&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is an acceptable tolerance.
&lt;/p&gt;

&lt;!-- implementations --&gt;
&lt;h2&gt;R Implementations&lt;/h2&gt;

&lt;p&gt;
On CRAN there are two other packages that perform the mean shift algorithm, 
&lt;a href=&quot;https://cran.rstudio.com/web/packages/MeanShift/&quot;&gt;MeanShift&lt;/a&gt; and &lt;a href=&quot;https://cran.rstudio.com/web/packages/LPCM/&quot;&gt;LPCM&lt;/a&gt;.  
The MeanShift package provides multi-core acceleration, a large number of kernels, and support for blured mean shift.
LPCM provides a fast and effective mean shift implementation, as well as plotting and diagnostic tools.
LPCM is restricted to just Gaussian kernels and does not provide any multi-core acceleration.  
&lt;/p&gt;

&lt;p&gt;
The meanShiftR package presented here is considerably faster than the prior two packages, but currently lacks diagnostic tools and support for more kernels.  Instead, the meanShiftR package provides a number of ways to speed mean shift.  This includes a generalized Gaussian variant of the mean shift (Lisic, 2015) providing accelerated convergence at the expense of some numerical stability, and support for support truncation with nearest neighbor and approximate nearest neighbor searches.  Furthermore, this mean shift implementaiton allows for mean shifting on a separate data set than the kernel support, a feature missing in the other two packages.
&lt;/p&gt;

&lt;p&gt;A quick speed comparison was done between the three packages, this was performed on a 13&quot; MacBook Pro with a dual-core hyper-threaded CPU.  In this configuration the default number of cores used by MeanShiftR is four.  A slight change had to be done to the MeanShift package to provide similar results, mainly the terminal condition had to be modified to be equivalent to meanShiftR and LPCM.  This terminal condition is simply the relative L&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-14-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.054ex&quot; height=&quot;1.676ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -432.6 453.9 721.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; distance.&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(LPCM)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(MeanShift)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set a seed to make this reproducible &lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set the number of iterations to test &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# (we will terminate well before this)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;iter&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1000&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set the number of points to simulate&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;500&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set the bandwidth&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create example data&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;x1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( n ),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;x2&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( n ),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( x1, x2 )&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#plot initial points&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(x,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rep&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'red'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'green'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
     &lt;span class=&quot;hl kwc&quot;&gt;cex&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'x'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'y'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;pch&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;########### meanShiftR ###################&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;meanShift&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;KDTREE&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;bandwidth&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=h,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;iterations&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= iter,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;meanShiftR_kd_runtime&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;run.time)[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# assignment&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;meanShiftR_kd_assignment&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;assignment&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# value&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;meanShiftR_kd_value&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;value&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;########### meanShiftR ###################&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;meanShift&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;bandwidth&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=h,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;iterations&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= iter&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;meanShiftR_runtime&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;run.time)[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# assignment&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;meanShiftR_assignment&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;assignment&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# value&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;meanShiftR_value&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;value&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;########### LPCM ###################&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;runtime&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ms&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=h,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;scaled&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=iter,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;plotms&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;LPCM_runtime&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;runtime)[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# assignment&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;LPCM_assignment&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cluster.label&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# value&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;LPCM_value&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cluster.center[LPCM_assignment,]&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;########### MeanShift ###################&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;mc.cores&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(x)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;runtime&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;msClustering&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=z,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=h,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;kernel&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;gaussianKernel&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;tol.stop&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1e-08&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;tol.epsilon&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1e-04&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;hl kwc&quot;&gt;multi.core&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=T)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;MeanShift_runtime&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;runtime)[&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;MeanShift_assignment&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;labels&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;MeanShift_value&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;components[,result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;labels])&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# print &lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(x,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sapply&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR_assignment,&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'red'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'green'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'blue'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)[x]),&lt;/span&gt;
   &lt;span class=&quot;hl kwc&quot;&gt;cex&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'x'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'y'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;pch&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;runtime&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( meanShiftR_runtime,&lt;/span&gt;
                &lt;span class=&quot;hl std&quot;&gt;meanShiftR_kd_runtime,&lt;/span&gt;
                &lt;span class=&quot;hl std&quot;&gt;LPCM_runtime,&lt;/span&gt;
                &lt;span class=&quot;hl std&quot;&gt;MeanShift_runtime),&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;maxDiff&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR_value&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;LPCM_value)),&lt;/span&gt;
               &lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR_kd_value&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;LPCM_value)),&lt;/span&gt;
               &lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
               &lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(MeanShift_value&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;LPCM_value))&lt;/span&gt;
               &lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;assignmentDiff&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR_assignment&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;LPCM_assignment),&lt;/span&gt;
               &lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR_kd_assignment&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;LPCM_assignment),&lt;/span&gt;
               &lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
               &lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(MeanShift_assignment&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;LPCM_assignment)&lt;/span&gt;
               &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Run-Time'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;hl str&quot;&gt;'Maximum Absolute Difference'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;hl str&quot;&gt;'Label Disagreements'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;rownames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'meanShiftR'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;hl str&quot;&gt;'meanShiftR K-D Tree'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;hl str&quot;&gt;'LPCM ms'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;hl str&quot;&gt;'meanShift msClustering'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(xtable)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;xtable&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;digits&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'s'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'f'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'f'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'d'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)),&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'html'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;!-- html table generated in R 3.3.1 by xtable 1.8-2 package --&gt;
&lt;p&gt;
&lt;!-- Mon Sep 19 10:21:51 2016 --&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tbody&gt;&lt;tr&gt; &lt;th&gt;  &lt;/th&gt; &lt;th&gt; Run-Time &lt;/th&gt; &lt;th&gt; Maximum Absolute Difference &lt;/th&gt; &lt;th&gt; Label Disagreements &lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; meanShiftR &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.304000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.000000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       0 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; meanShiftR K-D Tree &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 4.871000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.000000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       0 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; LPCM ms &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 2.425000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.000000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       0 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; meanShift msClustering &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 43.168000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.000000 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt;       0 &lt;/td&gt; &lt;/tr&gt;
   &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/meanShiftR/figure/unnamed-chunk-2-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 1:&lt;/b&gt;  Original image.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/meanShiftR/figure/unnamed-chunk-2-2.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 2:&lt;/b&gt;  Classified image.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;!--
&lt;figure&gt;
  &lt;img src=&quot;figure/unnamed-chunk-2-3.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 2:&lt;/b&gt;  Convergence paths.&lt;/figcaption&gt;
&lt;/figure&gt;
--&gt;

&lt;p&gt;
Here we can see some pretty good performance results for meanShiftR relative to the other R packages.  Unfortunately the k-d tree based implementation wasn't as fast as I would have liked, but its utility is really in tuncated support kernels.  Support for these kernels will be added later.  
&lt;/p&gt;

&lt;p&gt;
It is unclear why the performance of MeanShift was so poor relative to the other approaches.  To verify that it was not a function of the parallel implementation, the algorithm was run with one thread achieving approximately 50% of the performance with &lt;code&gt;mc.cores=4&lt;/code&gt;.  
&lt;/p&gt;

&lt;p&gt;
Diagnostic plots are not yet included, but convergence path plots can be easily generated by looping over single iterations.  An example is provided below, with results in Figure 3.
&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(meanShiftR)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(LPCM)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(MeanShift)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set a seed to make this reproducible &lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set the number of iterations to test &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# (we will terminate well before this)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;iter&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set the number of points to simulate&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;500&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# set the bandwidth&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;h&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create example data&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;x1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( n ),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;x2&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( n ),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( x1, x2 )&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create some test data for diagnostic plots&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;y1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( m ) ,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;y2&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( m ),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( y1, y2 )&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(x,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rep&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'salmon'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'greenyellow'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
   &lt;span class=&quot;hl kwc&quot;&gt;cex&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;xlab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'x'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ylab&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'y'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;pch&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;points&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(y,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rep&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'red'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'green'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=m&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
       &lt;span class=&quot;hl kwc&quot;&gt;cex&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;pch&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;points&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(y,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;cex&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;########### meanShiftR ###################&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#initial run&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;meanShift&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;y,&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;KDTREE&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;bandwidth&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=h,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;iterations&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= iter,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;y0&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(y,result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;value)&lt;/span&gt;

&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( i&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;iter) {&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;meanShift&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;value,&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;x,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;KDTREE&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;bandwidth&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=h,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;iterations&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# concate on the result&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;y0&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(y0,result&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;value)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the paths&lt;/span&gt;

&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( i&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;m ) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pointIndex&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=(m&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(iter&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=m)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;i&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;points&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(y0[pointIndex,] ,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'l'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;lwd&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/meanShiftR/figure/unnamed-chunk-3-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 3:&lt;/b&gt;  Convergence paths.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;!-- plan --&gt;
&lt;h2&gt;Future Plans&lt;/h2&gt;
&lt;p&gt;
Due to issues with stack size limits in &lt;code&gt;.C&lt;/code&gt;, I was unable to directly submit the original FLANN based package to CRAN, therefore a complete rewrite in C has been initiated.  This 0.50 release, is the first release on-the-way to 1.00, where feature parity will be met with the original code.
The release map for this package follows four more planned releases:
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt; 0.50 - Initial release.&lt;/li&gt;
  &lt;li&gt; 0.60 - Distance-based k-d trees, and support for popular kernels.&lt;/li&gt;
  &lt;li&gt; 0.70 - Dual-tree acceleration (Wang et al., 2007). &lt;/li&gt;
  &lt;li&gt; 0.80 - Fast Guassian Transform acceleration (Xia et. al. 2010). &lt;/li&gt;
  &lt;li&gt; 0.90 - Merge-Tree acceleration (Lisic, 2015). &lt;/li&gt;
  &lt;li&gt; 1.00 - Smoothing the support and diagnostic tools. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;References&lt;/h2&gt;

&lt;p&gt;
Cheng, Y. (1995). Mean shift, mode seeking, and clustering. IEEE transactions on pattern analysis and machine intelligence, 17(8), 790-799.
&lt;/p&gt;

&lt;p&gt;
Fukunaga, K., &amp;amp; Hostetler, L. (1975). The estimation of the gradient of a density function, with applications in pattern recognition. IEEE Transactions on information theory, 21(1), 32-40.
&lt;/p&gt;

&lt;p&gt;
Lisic, J. (2015). Parcel Level Agricultural Land Cover Prediction (Doctoral dissertation, George Mason University).
&lt;/p&gt;

&lt;p&gt;
Wang, P., Lee, D., Gray, A. G., &amp;amp; Rehg, J. M. (2007, March). Fast Mean Shift with Accurate and Stable Convergence. In AISTATS (pp. 604-611).
&lt;/p&gt;

&lt;p&gt;
Xiao, C., &amp;amp; Liu, M. (2010, September). Efficient Mean‐shift Clustering Using Gaussian KD‐Tree. In Computer Graphics Forum (Vol. 29, No. 7, pp. 2065-2073). Blackwell Publishing Ltd.
&lt;/p&gt;
</description>
        <pubDate>Sun, 28 Aug 2016 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/meanshift/r/cran/2016/08/28/meanShiftR.html</link>
        <guid isPermaLink="true">http://meanmean.me/meanshift/r/cran/2016/08/28/meanShiftR.html</guid>
        
        
        <category>meanshift</category>
        
        <category>R</category>
        
        <category>CRAN</category>
        
      </item>
    
      <item>
        <title>Elizabeth!</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2B&quot; d=&quot;M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6B&quot; d=&quot;M121 647Q121 657 125 670T137 683Q138 683 209 688T282 694Q294 694 294 686Q294 679 244 477Q194 279 194 272Q213 282 223 291Q247 309 292 354T362 415Q402 442 438 442Q468 442 485 423T503 369Q503 344 496 327T477 302T456 291T438 288Q418 288 406 299T394 328Q394 353 410 369T442 390L458 393Q446 405 434 405H430Q398 402 367 380T294 316T228 255Q230 254 243 252T267 246T293 238T320 224T342 206T359 180T365 147Q365 130 360 106T354 66Q354 26 381 26Q429 26 459 145Q461 153 479 153H483Q499 153 499 144Q499 139 496 130Q455 -11 378 -11Q333 -11 305 15T277 90Q277 108 280 121T283 145Q283 167 269 183T234 206T200 217T182 220H180Q168 178 159 139T145 81T136 44T129 20T122 7T111 -2Q98 -11 83 -11Q66 -11 57 -1T48 16Q48 26 85 176T158 471L195 616Q196 629 188 632T149 637H144Q134 637 131 637T124 640T121 647Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-4D&quot; d=&quot;M132 622Q125 629 121 631T105 634T62 637H29V683H135Q221 683 232 682T249 675Q250 674 354 398L458 124L562 398Q666 674 668 675Q671 681 683 682T781 683H887V637H854Q814 636 803 634T785 622V61Q791 51 802 49T854 46H887V0H876Q855 3 736 3Q605 3 596 0H585V46H618Q660 47 669 49T688 61V347Q688 424 688 461T688 546T688 613L687 632Q454 14 450 7Q446 1 430 1T410 7Q409 9 292 316L176 624V606Q175 588 175 543T175 463T175 356L176 86Q187 50 261 46H278V0H269Q254 3 154 3Q52 3 37 0H29V46H46Q78 48 98 56T122 69T132 86V622Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-53&quot; d=&quot;M55 507Q55 590 112 647T243 704H257Q342 704 405 641L426 672Q431 679 436 687T446 700L449 704Q450 704 453 704T459 705H463Q466 705 472 699V462L466 456H448Q437 456 435 459T430 479Q413 605 329 646Q292 662 254 662Q201 662 168 626T135 542Q135 508 152 480T200 435Q210 431 286 412T370 389Q427 367 463 314T500 191Q500 110 448 45T301 -21Q245 -21 201 -4T140 27L122 41Q118 36 107 21T87 -7T78 -21Q76 -22 68 -22H64Q61 -22 55 -16V101Q55 220 56 222Q58 227 76 227H89Q95 221 95 214Q95 182 105 151T139 90T205 42T305 24Q352 24 386 62T420 155Q420 198 398 233T340 281Q284 295 266 300Q261 301 239 306T206 314T174 325T141 343T112 367T85 402Q55 451 55 507Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-45&quot; d=&quot;M128 619Q121 626 117 628T101 631T58 634H25V680H597V676Q599 670 611 560T625 444V440H585V444Q584 447 582 465Q578 500 570 526T553 571T528 601T498 619T457 629T411 633T353 634Q266 634 251 633T233 622Q233 622 233 621Q232 619 232 497V376H286Q359 378 377 385Q413 401 416 469Q416 471 416 473V493H456V213H416V233Q415 268 408 288T383 317T349 328T297 330Q290 330 286 330H232V196V114Q232 57 237 52Q243 47 289 47H340H391Q428 47 452 50T505 62T552 92T584 146Q594 172 599 200T607 247T612 270V273H652V270Q651 267 632 137T610 3V0H25V46H58Q100 47 109 49T128 61V619Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ2-2211&quot; d=&quot;M60 948Q63 950 665 950H1267L1325 815Q1384 677 1388 669H1348L1341 683Q1320 724 1285 761Q1235 809 1174 838T1033 881T882 898T699 902H574H543H251L259 891Q722 258 724 252Q725 250 724 246Q721 243 460 -56L196 -356Q196 -357 407 -357Q459 -357 548 -357T676 -358Q812 -358 896 -353T1063 -332T1204 -283T1307 -196Q1328 -170 1348 -124H1388Q1388 -125 1381 -145T1356 -210T1325 -294L1267 -449L666 -450Q64 -450 61 -448Q55 -446 55 -439Q55 -437 57 -433L590 177Q590 178 557 222T452 366T322 544L56 909L55 924Q55 945 60 948Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-4E&quot; d=&quot;M234 637Q231 637 226 637Q201 637 196 638T191 649Q191 676 202 682Q204 683 299 683Q376 683 387 683T401 677Q612 181 616 168L670 381Q723 592 723 606Q723 633 659 637Q635 637 635 648Q635 650 637 660Q641 676 643 679T653 683Q656 683 684 682T767 680Q817 680 843 681T873 682Q888 682 888 672Q888 650 880 642Q878 637 858 637Q787 633 769 597L620 7Q618 0 599 0Q585 0 582 2Q579 5 453 305L326 604L261 344Q196 88 196 79Q201 46 268 46H278Q284 41 284 38T282 19Q278 6 272 0H259Q228 2 151 2Q123 2 100 2T63 2T46 1Q31 1 31 10Q31 14 34 26T39 40Q41 46 62 46Q130 49 150 85Q154 91 221 362L289 634Q287 635 234 637Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
 
&lt;p&gt;
Over the last few months I have been spending my nights taking care of my newly born second daughter.  
Keeping me company during the sleepless wee hours of the morning was the &lt;a href=&quot;https://www.relay.fm/rd&quot;&gt;Reconcilable Differences Podcast&lt;/a&gt;.
In episode 17 of this podcast, &lt;a href=&quot;https://www.relay.fm/rd/18&quot;&gt;It's Devastating&lt;/a&gt;, there was an open question placed by &lt;a href=&quot;http://hypercritical.co&quot;&gt;John Siracusa&lt;/a&gt; with regard to how baby names change over time, and if there were any sudden changes.  In this blog post, part of my &lt;a href=&quot;http://meanmean.me/blog/its/its.html&quot;&gt;investigation of podcast theme series&lt;/a&gt;, I will take a look at these two questions.
I will also provide my source code in the spirit of reproducible research.
&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;#jon&quot;&gt;Short a few apostles&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#names1880&quot;&gt;The names of the 1880s&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#distribution&quot;&gt;Name distribution&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#change&quot;&gt;Name change&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#wall&quot;&gt;From the island to the wall&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#fin&quot;&gt;In the end&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2 id=&quot;jon&quot;&gt;Short a Few Apostles&lt;/h2&gt;

&lt;p&gt;
I used the babynames package in R to perform this analysis.
The R package &lt;a href=&quot;https://github.com/hadley/babynames&quot;&gt;babynames&lt;/a&gt; by Hadley Wickham provides a nifty way to get baby names and related information from the Social Security Administration and other government agencies.
Downloading the data and plotting the name John relative to Jon over time can be done with a few simple commands.
&lt;/p&gt;



&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-2&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get the names&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;theJNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Jon'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'John'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=theJNames,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Jon v.s. John'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-2-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 1:&lt;/b&gt;  Proportions of the names Jon and John over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt; 
 With this little bit of work, we can see that the proportion of babies named John is strictly larger than Jon, but is also on a fairly substantial decline.  Out of curiosity, let's check James.  Why James? It seems that just about everyone I know that is male and in their 70s is named James.
&lt;/p&gt;


&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-3&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get the names&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;theJNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'James'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=theJNames,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'James'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;maxYear&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;theJNames&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;year[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;which.max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(theJNames&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop)]&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-3-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 2:&lt;/b&gt;  Proportions of the name James over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
So it looks like we hit peak James in &lt;code&gt;maxYear=&lt;/code&gt;&lt;code class=&quot;knitr inline&quot;&gt;1944&lt;/code&gt;.  So this seems to line up with my observations.  
&lt;/p&gt;

&lt;p&gt;
For the data pedantic, which should be everyone,
this list of baby names is derived from Social Security Card applications.  Since the social security administration didn't exist until 1935 and didn't start issuing cards until 1937, the names from 1880-1937 are likely to be a bit incomplete.
&lt;/p&gt;


&lt;h2 id=&quot;names1880&quot;&gt;The Names of the 1880s&lt;/h2&gt;

&lt;p&gt;
So John and James had downward trends in the coverage of new babies, does this hold for other names? Let's see what the top names in the 1880s are and where they are today, likewise let's see what the top names in 2014 are and how they have historically trended.
&lt;/p&gt;

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-4&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# dream of the 1880s&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# ladies first&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(year&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1880&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'F'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#baby names are presorted&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(oldNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames, name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;oldNames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'F'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(oldNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=oldNamesData,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Top 1880 Female Names'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;maxYear&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;theJNames&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;year[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;which.max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(theJNames&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop)]&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-4-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 3:&lt;/b&gt;  Old time female names over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-5&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# 2014 females&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(year&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2014&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'F'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#baby names are presorted&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(newNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames, name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;newNames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'F'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(newNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=newNamesData,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Top 2014 Female Names'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-5-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 4:&lt;/b&gt;  New female names over time.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;p&gt;
Now for the gents.
&lt;/p&gt;


&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-6&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# dream of the 1880s&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(year&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1880&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#baby names are presorted&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(oldNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames, name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;oldNames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;oldNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(oldNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=oldNamesData,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Top 1880 Male Names'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;maxYear&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;theJNames&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;year[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;which.max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(theJNames&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop)]&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-6-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 5:&lt;/b&gt;  Old time male names over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-7&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# males in 2014&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(year&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2014&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#baby names are presorted&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(newNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNamesData&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames, name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;newNames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;newNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(newNamesData&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;name)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=newNamesData,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Top 2014 Male Names'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-7-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 6:&lt;/b&gt;  New male names over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
The interesting bit about both of these results is that the popularity of names seems to be fairly short lived in modern times.  
This can be seen in the popular names from 2014 poping up from nowhere, with the exception of William and maybe Emily.
&lt;/p&gt;

&lt;h2 id=&quot;distribution&quot;&gt;Name Distribution&lt;/h2&gt;

&lt;p&gt;
That was a lot of fun, but let's get back to the question of how people have labeled their children over time.
What we can hypothesize from the prior results is that there is an abundance of new names over the last century.  
&lt;/p&gt;

&lt;p&gt;
So let's take a look at this new diversity in child naming.
One way to look at this diversity is to just to plot the number of distinct names for each year and see how this changes over time (Figure 7.). 
&lt;/p&gt;

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-8&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# quick aggregation function, there is a dplyr function for this as well&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;uniqueNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aggregate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(prop&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;year&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;sex,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=babynames,&lt;/span&gt;
                         &lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(x))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the number of unique names from new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=uniqueNames,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=sex))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Number of Unique New Names over Time'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-8-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 7:&lt;/b&gt;  Number of unique names over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt; Clearly this is an increase in distinct names.
This increase in new names could be a function of the change in population size, but it is likely more complicated than that.
Immigration from non-European countries may play a large roll in this change, but that would require a bit more work than I'm willing to put into this blog post.
&lt;/p&gt;

&lt;p&gt; 
Another way to look at this data is to plot the sorted proportions.
Plotting the sorted proportions will provide some insights into the distribution of the names.  
If the proportions are uniformly distributed, this implies no real preference towards a particular name.
If the proportions are highly skewed, then the population likely has a large number of uncommon names and a small number of popular names.
To limit the number of plots, I just took a quick look at the plots of proportions for
&lt;a href=&quot;https://www.youtube.com/watch?v=qDiY5-Wtiuc&quot;&gt;1890&lt;/a&gt; (YouTube) and &lt;a href=&quot;https://www.youtube.com/watch?v=HX8BsX3IIa4&quot;&gt;1990&lt;/a&gt; (YouTube).  To make things simple I just pooled male and female names together.
&lt;/p&gt;


&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-9&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get names&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;namesDensity&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(year&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1890&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1990&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(sex,year)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;mutate&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&quot;hl com&quot;&gt;# create an index&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ungroup&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(sex,year)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;namesDensity&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Year&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.factor&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(namesDensity&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;year)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;namesDensity1890&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(namesDensity, Year&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1890&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;namesDensity1890&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;namesDensity1890[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(namesDensity1890&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;index.return&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=T)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;ix,]&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;namesDensity1990&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(namesDensity, Year&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1990&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;namesDensity1990&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;namesDensity1990[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(namesDensity1990&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;index.return&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=T)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;ix,]&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=namesDensity1890,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=index,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Year))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Plot of Decreasing Name Porportions in 1890'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Number of Names&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=namesDensity1990,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=index,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Year))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Plot of Decreasing Name Porportions in 1990'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Number of Names&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-9-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 8:&lt;/b&gt;  Plot of decreasing proportions in 1890.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-9-2.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 9:&lt;/b&gt;  Plot of decreasing proportions in 1990.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;p&gt;
There are a few interesting characteristics about these two plots.
The first characteristic we saw before in Figure 7., the number of the unique names.
Here we can see the number of unique names increased eight times over one hundred years.  So clearly there are more names out there, but how are they distributed?
This can be seen clearly in both plots, there are a small number of common names and a much larger number of uncommon names.
Finally, the magnitudes of these proportions are interesting, in 1890 the most popular names covered about 7% of the total population of new SSN applicants, while this was down to 3% in 1990.
&lt;/p&gt;


&lt;h2 id=&quot;change&quot;&gt;Name Change&lt;/h2&gt;

&lt;p&gt; Were there any large changes in names over time? this is a bit more difficult question to answer, but let's have a go at it.
What we need to do is to look at changes by a given lag, e.g. how do the names at time &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;0.84ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -719.6 361.5 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; compare to names at tie &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;4.891ex&quot; height=&quot;2.343ex&quot; style=&quot;vertical-align: -0.505ex;&quot; viewBox=&quot;0 -791.3 2105.9 1008.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;583&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1584&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.211ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 521.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is a whole number.
&lt;/p&gt;

&lt;p&gt;
Let's take a look at the change with &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.472ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 2356.1 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;799&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1855&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, and use the mean squared difference between names.
The mean squared difference is calculated as
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;28.321ex&quot; height=&quot;7.343ex&quot; style=&quot;vertical-align: -3.005ex;&quot; viewBox=&quot;0 -1867.7 12193.8 3161.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-4D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;917&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-53&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1474&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-45&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;3048&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2788&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3845,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ2-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(147,-1090)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1124&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(299,1185)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4E&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;989&quot; y=&quot;-203&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5289,0)&quot;&gt;&lt;g transform=&quot;translate(286,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;6218&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,807)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(389,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;624&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;1981&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2981,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;624&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;985&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2B&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1764&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;5255&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;7983&quot; y=&quot;675&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2529,-704)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4E&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1136&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;11915&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
where each proportion is identified as &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;17.719ex&quot; height=&quot;3.009ex&quot; style=&quot;vertical-align: -1.005ex;&quot; viewBox=&quot;0 -863.1 7629.2 1295.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;624&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1619&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2242&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3187,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1446&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1891&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2336&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2781,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4E&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1136&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;3940&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, the set of names in year &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;0.84ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -719.6 361.5 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.  
If the name is observed in year &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;0.84ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -719.6 361.5 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; but not in &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;4.842ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 2084.9 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;583&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1584&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; the proportion is set to 0. 
&lt;p&gt;&lt;/p&gt;


&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-10&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get the change in proportion&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(t&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1880&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2014&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;k)) {&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# get the names at t&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;currentName&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( sex&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;year&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;t)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# get the names at t+k&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;currentNamePlusK&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(sex&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;year&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;k)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;#join the two years together by name&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;check&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;left_join&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentName, currentNamePlusK,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;check[&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;is.na&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(check)]&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;0&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;((check&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop.x&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;prop.y)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) )&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;cbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1880&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2014&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;k),result)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(result)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'year'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'change'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=result,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=change))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Changes in Yearly Name Proportion'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Mean of Squared Changes in Proportion&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-10-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 10:&lt;/b&gt;  Name change over time.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
This plot is pretty interesting.  We see some early on changes around 1890 and 1900, followed by a spike around 1910; then in close to 1970 we have another spike.
My best guess would be the 1970 change would be associated with the &lt;a href=&quot;https://en.wikipedia.org/wiki/Black_Power_movement&quot;&gt;black power movement&lt;/a&gt; that peaked in 1970, and the earlier changes are likely due to immigration events.
&lt;/p&gt;

&lt;p&gt;
If we do a little bit of Google sleuthing we can see in this &lt;a href=&quot;http://www.migrationpolicy.org/programs/data-hub/charts/Annual-Number-of-US-Legal-Permanent-Residents?width=1000&amp;amp;height=850&amp;amp;iframe=true&quot;&gt;plot&lt;/a&gt; that there seems to be a bit of correlation between these early events and immigration, but not the massive spike in immigration that occurs in 1990.
Looking at &lt;a href=&quot;https://en.wikipedia.org/wiki/Immigration_to_the_United_States&quot;&gt;Wikipedia&lt;/a&gt; we can see that around the turn of the century there was a large amount of movement from northern, southern, and eastern Europe to the United States.
&lt;/p&gt;

&lt;p&gt;
However, the massive spike in 1990 doesn't seem to be associated with a massive change in source countries, as seen in this &lt;a href=&quot;http://www.migrationpolicy.org/programs/data-hub/charts/regions-immigrant-birth-1960-present?width=1000&amp;amp;height=850&amp;amp;iframe=true&quot;&gt;plot&lt;/a&gt;.  Of course this plot is of regions of birth, which I'll assume is a better indicator of future baby names than country of emigration.
Still, as mentioned earlier, the names pre 1937 are a bit incomplete, so the earlier changes in name might be an anomaly in the data, and I certainly don't want to assume some degree of causal relationship.
&lt;/p&gt;



&lt;h2 id=&quot;wall&quot;&gt;From the island to the wall&lt;/h2&gt;

Just for fun, let's look at some popular TV and Movie names over time for males and females.

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-11&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get the names&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;tvNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt;
           &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Bilbo'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Aragorn'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Gandalf'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Boromir'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Faramir'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Legolas'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Frodo'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Gilligan'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Tyrion'&lt;/span&gt;
             &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=tvNames,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'TV and Movie Names, Male'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-11-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 11:&lt;/b&gt;  TV and Movie names over time, Male.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-12&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get the names&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;tvNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt;
           &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Ginger'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Sansa'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Arya'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Daenerys'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Cersei'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;hl str&quot;&gt;'Arwen'&lt;/span&gt;
             &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'F'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=tvNames,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'TV and Movie Names, Female'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-12-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 12:&lt;/b&gt;  TV and Movie names over time, Female.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;h2 id=&quot;fin&quot;&gt;In the end&lt;/h2&gt;

&lt;p&gt;
This was a lot of fun.  Please let me know via Twitter or email if you would like to see anymore analysis.
If I find some free time I would like to build an interactive website for this data, but in the mean time please feel to play around with the code I have provided. 
&lt;/p&gt;



&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-13&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(babynames)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# big plots, because I'm old and blind&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get the names&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;theJNames&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;babynames&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(name&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Fin'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;sex&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;hl str&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot the proportion of new SSN applications &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# with the names over time&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=theJNames,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=year,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=prop))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=name),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Fin'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Proportion of new SSN applications&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Year&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/babyNames/figure/unnamed-chunk-13-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 13:&lt;/b&gt;  Proportion of males named Fin over time.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;p&gt;
As far as future work goes, I'll probaby take a look at the recent release of data on hard drive reliablility from &lt;a href=&quot;https://www.backblaze.com/blog/hard-drive-reliability-stats-q1-2016/&quot;&gt;Backblaze&lt;/a&gt;.
&lt;/p&gt;

</description>
        <pubDate>Sun, 07 Aug 2016 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/r/babynames/2016/08/07/Eli-za-beth!.html</link>
        <guid isPermaLink="true">http://meanmean.me/r/babynames/2016/08/07/Eli-za-beth!.html</guid>
        
        
        <category>R</category>
        
        <category>babynames</category>
        
      </item>
    
      <item>
        <title>Kernels for everyone!</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-73&quot; d=&quot;M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-44&quot; d=&quot;M287 628Q287 635 230 637Q207 637 200 638T193 647Q193 655 197 667T204 682Q206 683 403 683Q570 682 590 682T630 676Q702 659 752 597T803 431Q803 275 696 151T444 3L430 1L236 0H125H72Q48 0 41 2T33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM703 469Q703 507 692 537T666 584T629 613T590 629T555 636Q553 636 541 636T512 636T479 637H436Q392 637 386 627Q384 623 313 339T242 52Q242 48 253 48T330 47Q335 47 349 47T373 46Q499 46 581 128Q617 164 640 212T683 339T703 469Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-66&quot; d=&quot;M118 -162Q120 -162 124 -164T135 -167T147 -168Q160 -168 171 -155T187 -126Q197 -99 221 27T267 267T289 382V385H242Q195 385 192 387Q188 390 188 397L195 425Q197 430 203 430T250 431Q298 431 298 432Q298 434 307 482T319 540Q356 705 465 705Q502 703 526 683T550 630Q550 594 529 578T487 561Q443 561 443 603Q443 622 454 636T478 657L487 662Q471 668 457 668Q445 668 434 658T419 630Q412 601 403 552T387 469T380 433Q380 431 435 431Q480 431 487 430T498 424Q499 420 496 407T491 391Q489 386 482 386T428 385H372L349 263Q301 15 282 -47Q255 -132 212 -173Q175 -205 139 -205Q107 -205 81 -186T55 -132Q55 -95 76 -78T118 -61Q162 -61 162 -103Q162 -122 151 -136T127 -157L118 -162Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-67&quot; d=&quot;M311 43Q296 30 267 15T206 0Q143 0 105 45T66 160Q66 265 143 353T314 442Q361 442 401 394L404 398Q406 401 409 404T418 412T431 419T447 422Q461 422 470 413T480 394Q480 379 423 152T363 -80Q345 -134 286 -169T151 -205Q10 -205 10 -137Q10 -111 28 -91T74 -71Q89 -71 102 -80T116 -111Q116 -121 114 -130T107 -144T99 -154T92 -162L90 -164H91Q101 -167 151 -167Q189 -167 211 -155Q234 -144 254 -122T282 -75Q288 -56 298 -13Q311 35 311 43ZM384 328L380 339Q377 350 375 354T369 368T359 382T346 393T328 402T306 405Q262 405 221 352Q191 313 171 233T151 117Q151 38 213 38Q269 38 323 108L331 118L384 328Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ2-222B&quot; d=&quot;M114 -798Q132 -824 165 -824H167Q195 -824 223 -764T275 -600T320 -391T362 -164Q365 -143 367 -133Q439 292 523 655T645 1127Q651 1145 655 1157T672 1201T699 1257T733 1306T777 1346T828 1360Q884 1360 912 1325T944 1245Q944 1220 932 1205T909 1186T887 1183Q866 1183 849 1198T832 1239Q832 1287 885 1296L882 1300Q879 1303 874 1307T866 1313Q851 1323 833 1323Q819 1323 807 1311T775 1255T736 1139T689 936T633 628Q574 293 510 -5T410 -437T355 -629Q278 -862 165 -862Q125 -862 92 -831T55 -746Q55 -711 74 -698T112 -685Q133 -685 150 -700T167 -741Q167 -789 114 -798Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-64&quot; d=&quot;M366 683Q367 683 438 688T511 694Q523 694 523 686Q523 679 450 384T375 83T374 68Q374 26 402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487H491Q506 153 506 145Q506 140 503 129Q490 79 473 48T445 8T417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157Q33 205 53 255T101 341Q148 398 195 420T280 442Q336 442 364 400Q369 394 369 396Q370 400 396 505T424 616Q424 629 417 632T378 637H357Q351 643 351 645T353 664Q358 683 366 683ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3D5&quot; d=&quot;M409 688Q413 694 421 694H429H442Q448 688 448 686Q448 679 418 563Q411 535 404 504T392 458L388 442Q388 441 397 441T429 435T477 418Q521 397 550 357T579 260T548 151T471 65T374 11T279 -10H275L251 -105Q245 -128 238 -160Q230 -192 227 -198T215 -205H209Q189 -205 189 -198Q189 -193 211 -103L234 -11Q234 -10 226 -10Q221 -10 206 -8T161 6T107 36T62 89T43 171Q43 231 76 284T157 370T254 422T342 441Q347 441 348 445L378 567Q409 686 409 688ZM122 150Q122 116 134 91T167 53T203 35T237 27H244L337 404Q333 404 326 403T297 395T255 379T211 350T170 304Q152 276 137 237Q122 191 122 150ZM500 282Q500 320 484 347T444 385T405 400T381 404H378L332 217L284 29Q284 27 285 27Q293 27 317 33T357 47Q400 66 431 100T475 170T494 234T500 282Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3BC&quot; d=&quot;M58 -216Q44 -216 34 -208T23 -186Q23 -176 96 116T173 414Q186 442 219 442Q231 441 239 435T249 423T251 413Q251 401 220 279T187 142Q185 131 185 107V99Q185 26 252 26Q261 26 270 27T287 31T302 38T315 45T327 55T338 65T348 77T356 88T365 100L372 110L408 253Q444 395 448 404Q461 431 491 431Q504 431 512 424T523 412T525 402L449 84Q448 79 448 68Q448 43 455 35T476 26Q485 27 496 35Q517 55 537 131Q543 151 547 152Q549 153 557 153H561Q580 153 580 144Q580 138 575 117T555 63T523 13Q510 0 491 -8Q483 -10 467 -10Q446 -10 429 -4T402 11T385 29T376 44T374 51L368 45Q362 39 350 30T324 12T288 -4T246 -11Q199 -11 153 12L129 -85Q108 -167 104 -180T92 -202Q76 -216 58 -216Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-3C3&quot; d=&quot;M184 -11Q116 -11 74 34T31 147Q31 247 104 333T274 430Q275 431 414 431H552Q553 430 555 429T559 427T562 425T565 422T567 420T569 416T570 412T571 407T572 401Q572 357 507 357Q500 357 490 357T476 358H416L421 348Q439 310 439 263Q439 153 359 71T184 -11ZM361 278Q361 358 276 358Q152 358 115 184Q114 180 114 178Q106 141 106 117Q106 67 131 47T188 26Q242 26 287 73Q316 103 334 153T356 233T361 278Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-68&quot; d=&quot;M137 683Q138 683 209 688T282 694Q294 694 294 685Q294 674 258 534Q220 386 220 383Q220 381 227 388Q288 442 357 442Q411 442 444 415T478 336Q478 285 440 178T402 50Q403 36 407 31T422 26Q450 26 474 56T513 138Q516 149 519 151T535 153Q555 153 555 145Q555 144 551 130Q535 71 500 33Q466 -10 419 -10H414Q367 -10 346 17T325 74Q325 90 361 192T398 345Q398 404 354 404H349Q266 404 205 306L198 293L164 158Q132 28 127 16Q114 -11 83 -11Q69 -11 59 -2T48 16Q48 30 121 320L195 616Q195 629 188 632T149 637H128Q122 643 122 645T124 664Q129 683 137 683Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ2-2211&quot; d=&quot;M60 948Q63 950 665 950H1267L1325 815Q1384 677 1388 669H1348L1341 683Q1320 724 1285 761Q1235 809 1174 838T1033 881T882 898T699 902H574H543H251L259 891Q722 258 724 252Q725 250 724 246Q721 243 460 -56L196 -356Q196 -357 407 -357Q459 -357 548 -357T676 -358Q812 -358 896 -353T1063 -332T1204 -283T1307 -196Q1328 -170 1348 -124H1388Q1388 -125 1381 -145T1356 -210T1325 -294L1267 -449L666 -450Q64 -450 61 -448Q55 -446 55 -439Q55 -437 57 -433L590 177Q590 178 557 222T452 366T322 544L56 909L55 924Q55 945 60 948Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-53&quot; d=&quot;M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-77&quot; d=&quot;M580 385Q580 406 599 424T641 443Q659 443 674 425T690 368Q690 339 671 253Q656 197 644 161T609 80T554 12T482 -11Q438 -11 404 5T355 48Q354 47 352 44Q311 -11 252 -11Q226 -11 202 -5T155 14T118 53T104 116Q104 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Q21 293 29 315T52 366T96 418T161 441Q204 441 227 416T250 358Q250 340 217 250T184 111Q184 65 205 46T258 26Q301 26 334 87L339 96V119Q339 122 339 128T340 136T341 143T342 152T345 165T348 182T354 206T362 238T373 281Q402 395 406 404Q419 431 449 431Q468 431 475 421T483 402Q483 389 454 274T422 142Q420 131 420 107V100Q420 85 423 71T442 42T487 26Q558 26 600 148Q609 171 620 213T632 273Q632 306 619 325T593 357T580 385Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-78&quot; d=&quot;M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-71&quot; d=&quot;M33 157Q33 258 109 349T280 441Q340 441 372 389Q373 390 377 395T388 406T404 418Q438 442 450 442Q454 442 457 439T460 434Q460 425 391 149Q320 -135 320 -139Q320 -147 365 -148H390Q396 -156 396 -157T393 -175Q389 -188 383 -194H370Q339 -192 262 -192Q234 -192 211 -192T174 -192T157 -193Q143 -193 143 -185Q143 -182 145 -170Q149 -154 152 -151T172 -148Q220 -148 230 -141Q238 -136 258 -53T279 32Q279 33 272 29Q224 -10 172 -10Q117 -10 75 30T33 157ZM352 326Q329 405 277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q233 26 290 98L298 109L352 326Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-74&quot; d=&quot;M27 422Q80 426 109 478T141 600V615H181V431H316V385H181V241Q182 116 182 100T189 68Q203 29 238 29Q282 29 292 100Q293 108 293 146V181H333V146V134Q333 57 291 17Q264 -10 221 -10Q187 -10 162 2T124 33T105 68T98 100Q97 107 97 248V385H18V422H27Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-68&quot; d=&quot;M41 46H55Q94 46 102 60V68Q102 77 102 91T102 124T102 167T103 217T103 272T103 329Q103 366 103 407T103 482T102 542T102 586T102 603Q99 622 88 628T43 637H25V660Q25 683 27 683L37 684Q47 685 66 686T103 688Q120 689 140 690T170 693T181 694H184V367Q244 442 328 442Q451 442 463 329Q464 322 464 190V104Q464 66 466 59T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-61&quot; d=&quot;M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-72&quot; d=&quot;M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6D&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3A&quot; d=&quot;M78 370Q78 394 95 412T138 430Q162 430 180 414T199 371Q199 346 182 328T139 310T96 327T78 370ZM78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-50&quot; d=&quot;M287 628Q287 635 230 637Q206 637 199 638T192 648Q192 649 194 659Q200 679 203 681T397 683Q587 682 600 680Q664 669 707 631T751 530Q751 453 685 389Q616 321 507 303Q500 302 402 301H307L277 182Q247 66 247 59Q247 55 248 54T255 50T272 48T305 46H336Q342 37 342 35Q342 19 335 5Q330 0 319 0Q316 0 282 1T182 2Q120 2 87 2T51 1Q33 1 33 11Q33 13 36 25Q40 41 44 43T67 46Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628ZM645 554Q645 567 643 575T634 597T609 619T560 635Q553 636 480 637Q463 637 445 637T416 636T404 636Q391 635 386 627Q384 621 367 550T332 412T314 344Q314 342 395 342H407H430Q542 342 590 392Q617 419 631 471T645 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-58&quot; d=&quot;M42 0H40Q26 0 26 11Q26 15 29 27Q33 41 36 43T55 46Q141 49 190 98Q200 108 306 224T411 342Q302 620 297 625Q288 636 234 637H206Q200 643 200 645T202 664Q206 677 212 683H226Q260 681 347 681Q380 681 408 681T453 682T473 682Q490 682 490 671Q490 670 488 658Q484 643 481 640T465 637Q434 634 411 620L488 426L541 485Q646 598 646 610Q646 628 622 635Q617 635 609 637Q594 637 594 648Q594 650 596 664Q600 677 606 683H618Q619 683 643 683T697 681T738 680Q828 680 837 683H845Q852 676 852 672Q850 647 840 637H824Q790 636 763 628T722 611T698 593L687 584Q687 585 592 480L505 384Q505 383 536 304T601 142T638 56Q648 47 699 46Q734 46 734 37Q734 35 732 23Q728 7 725 4T711 1Q708 1 678 1T589 2Q528 2 496 2T461 1Q444 1 444 10Q444 11 446 25Q448 35 450 39T455 44T464 46T480 47T506 54Q523 62 523 64Q522 64 476 181L429 299Q241 95 236 84Q232 76 232 72Q232 53 261 47Q262 47 267 47T273 46Q276 46 277 46T280 45T283 42T284 35Q284 26 282 19Q279 6 276 4T261 1Q258 1 243 1T201 2T142 2Q64 2 42 0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3C&quot; d=&quot;M694 -11T694 -19T688 -33T678 -40Q671 -40 524 29T234 166L90 235Q83 240 83 250Q83 261 91 266Q664 540 678 540Q681 540 687 534T694 519T687 505Q686 504 417 376L151 250L417 124Q686 -4 687 -5Q694 -11 694 -19Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2264&quot; d=&quot;M674 636Q682 636 688 630T694 615T687 601Q686 600 417 472L151 346L399 228Q687 92 691 87Q694 81 694 76Q694 58 676 56H670L382 192Q92 329 90 331Q83 336 83 348Q84 359 96 365Q104 369 382 500T665 634Q669 636 674 636ZM84 -118Q84 -108 99 -98H678Q694 -104 694 -118Q694 -130 679 -138H98Q84 -131 84 -118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ2-7B&quot; d=&quot;M547 -643L541 -649H528Q515 -649 503 -645Q324 -582 293 -466Q289 -449 289 -428T287 -200L286 42L284 53Q274 98 248 135T196 190T146 222L121 235Q119 239 119 250Q119 262 121 266T133 273Q262 336 284 449L286 460L287 701Q287 737 287 794Q288 949 292 963Q293 966 293 967Q325 1080 508 1148Q516 1150 527 1150H541L547 1144V1130Q547 1117 546 1115T536 1109Q480 1086 437 1046T381 950L379 940L378 699Q378 657 378 594Q377 452 374 438Q373 437 373 436Q350 348 243 282Q192 257 186 254L176 251L188 245Q211 236 234 223T287 189T340 135T373 65Q373 64 374 63Q377 49 378 -93Q378 -156 378 -198L379 -438L381 -449Q393 -504 436 -544T536 -608Q544 -611 545 -613T547 -629V-643Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ2-7D&quot; d=&quot;M119 1130Q119 1144 121 1147T135 1150H139Q151 1150 182 1138T252 1105T326 1046T373 964Q378 942 378 702Q378 469 379 462Q386 394 439 339Q482 296 535 272Q544 268 545 266T547 251Q547 241 547 238T542 231T531 227T510 217T477 194Q390 129 379 39Q378 32 378 -201Q378 -441 373 -463Q342 -580 165 -644Q152 -649 139 -649Q125 -649 122 -646T119 -629Q119 -622 119 -619T121 -614T124 -610T132 -607T143 -602Q195 -579 235 -539T285 -447Q286 -435 287 -199T289 51Q294 74 300 91T329 138T390 197Q412 213 436 226T475 244L489 250L472 258Q455 265 430 279T377 313T327 366T293 434Q289 451 289 472T287 699Q286 941 285 948Q279 978 262 1005T227 1048T184 1080T151 1100T129 1109L127 1110Q119 1113 119 1130Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5E&quot; d=&quot;M112 560L249 694L257 686Q387 562 387 560L361 531Q359 532 303 581L250 627L195 580Q182 569 169 557T148 538L140 532Q138 530 125 546L112 560Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ1-2211&quot; d=&quot;M61 748Q64 750 489 750H913L954 640Q965 609 976 579T993 533T999 516H979L959 517Q936 579 886 621T777 682Q724 700 655 705T436 710H319Q183 710 183 709Q186 706 348 484T511 259Q517 250 513 244L490 216Q466 188 420 134T330 27L149 -187Q149 -188 362 -188Q388 -188 436 -188T506 -189Q679 -189 778 -162T936 -43Q946 -27 959 6H999L913 -249L489 -250Q65 -250 62 -248Q56 -246 56 -239Q56 -234 118 -161Q186 -81 245 -11L428 206Q428 207 242 462L57 717L56 728Q56 744 61 748Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-63&quot; d=&quot;M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325T330 359T352 380T366 386H367Q367 388 361 392T340 400T306 404Q276 404 249 390Q228 381 206 359Q162 315 142 235T121 119Q121 73 147 50Q169 26 205 26H209Q321 26 394 111Q403 121 406 121Q410 121 419 112T429 98T420 83T391 55T346 25T282 0T202 -11Q127 -11 81 37T34 159Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-43&quot; d=&quot;M50 252Q50 367 117 473T286 641T490 704Q580 704 633 653Q642 643 648 636T656 626L657 623Q660 623 684 649Q691 655 699 663T715 679T725 690L740 705H746Q760 705 760 698Q760 694 728 561Q692 422 692 421Q690 416 687 415T669 413H653Q647 419 647 422Q647 423 648 429T650 449T651 481Q651 552 619 605T510 659Q484 659 454 652T382 628T299 572T226 479Q194 422 175 346T156 222Q156 108 232 58Q280 24 350 24Q441 24 512 92T606 240Q610 253 612 255T628 257Q648 257 648 248Q648 243 647 239Q618 132 523 55T319 -22Q206 -22 128 53T50 252Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJAMS-49&quot; d=&quot;M20 666Q20 676 31 683H358Q369 676 369 666Q369 648 331 648Q288 645 282 632Q278 626 278 341Q278 57 282 50Q286 42 295 40T331 35Q369 35 369 16Q369 6 358 -1H31Q20 4 20 16Q20 35 58 35Q84 37 93 39T107 50Q113 60 113 341Q113 623 107 632Q101 645 58 648Q20 648 20 666ZM249 35Q246 40 246 41T244 54T242 83T242 139V341Q242 632 244 639L249 648H140Q146 634 147 596T149 341Q149 124 148 86T140 35H249Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-7B&quot; d=&quot;M661 -1243L655 -1249H622L604 -1240Q503 -1190 434 -1107T348 -909Q346 -897 346 -499L345 -98L343 -82Q335 3 287 87T157 223Q146 232 145 236Q144 240 144 250Q144 265 145 268T157 278Q242 333 288 417T343 583L345 600L346 1001Q346 1398 348 1410Q379 1622 600 1739L622 1750H655L661 1744V1727V1721Q661 1712 661 1710T657 1705T648 1700T630 1690T602 1668Q589 1659 574 1643T531 1593T484 1508T459 1398Q458 1389 458 1001Q458 614 457 605Q441 435 301 316Q254 277 202 251L250 222Q260 216 301 185Q443 66 457 -104Q458 -113 458 -501Q458 -888 459 -897Q463 -944 478 -988T509 -1060T548 -1114T580 -1149T602 -1167Q620 -1183 634 -1192T653 -1202T659 -1207T661 -1220V-1226V-1243Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-7D&quot; d=&quot;M144 1727Q144 1743 146 1746T162 1750H167H183L203 1740Q274 1705 325 1658T403 1562T440 1478T456 1410Q458 1398 458 1001Q459 661 459 624T465 558Q470 526 480 496T502 441T529 395T559 356T588 325T615 301T637 284T654 273L660 269V266Q660 263 660 259T661 250V239Q661 236 661 234T660 232T656 229T649 224Q577 179 528 105T465 -57Q460 -86 460 -123T458 -499V-661Q458 -857 457 -893T447 -955Q425 -1048 359 -1120T203 -1239L183 -1249H168Q150 -1249 147 -1246T144 -1226Q144 -1213 145 -1210T153 -1202Q169 -1193 186 -1181T232 -1140T282 -1081T322 -1000T345 -897Q346 -888 346 -501Q346 -113 347 -104Q359 58 503 184Q554 226 603 250Q504 299 430 393T347 605Q346 614 346 1002Q346 1389 345 1398Q338 1493 288 1573T153 1703Q146 1707 145 1710T144 1727Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt;
During my dissertation, I spent a lot of time working on spatial kernel estimates.
Where spatial kernel estimates are defined as a convolution of a spatial suppport &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;9.034ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 3889.6 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(914,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;2115&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3061&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-44&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; ,
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;32.164ex&quot; height=&quot;5.676ex&quot; style=&quot;vertical-align: -2.338ex;&quot; viewBox=&quot;0 -1437.2 13848.4 2443.8&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1162&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2217&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1884&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2365&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2754&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3144,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4067&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4735&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5791&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ2-222B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6902&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7453&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7842&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8312&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8701&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9182&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(9571,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;10717&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11717&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12187&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12576&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-64&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13100&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13569&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
A simple example of this estimate is a Gaussian filter or &lt;i&gt;blur&lt;/i&gt; in more common parlance.
In the Guassian filter, &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.116ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -576.1 480.5 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is the normal density function &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.385ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 596.5 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3D5&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, with the location parameter &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;6.645ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -576.1 2861 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3BC&quot;&gt;&lt;/use&gt;&lt;use x=&quot;881&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1937,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; and scale parameter &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.33ex&quot; height=&quot;1.676ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -576.1 572.5 721.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; equal to the bandwidth &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.339ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 576.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-68&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;kernelDensityEstimates&lt;/code&gt; package provides a means to apply these estimates to &lt;code&gt;raster&lt;/code&gt; S4 objects from the &lt;href a=&quot;https://cran.r-project.org/web/packages/raster/index.html&quot;&gt;raster R package. 
Each function preserves &lt;code&gt;NA&lt;/code&gt; values, and uses &lt;a href=&quot;http://openmp.org/wp/&quot;&gt;OpenMP&lt;/a&gt; for acceleration.
However, all processing is done in memory, so there is no support for extremely large images.
&lt;/href&gt;&lt;/p&gt;

&lt;p&gt;
The rasterKernelEstimates R package is currently not on CRAN, but will be after the documentation is cleaned up.
Furthermore, the implementation of the kernels is currently non-optimal, and a fair bit of work can be done to speed them up a bit more.
For those interested in helping out, the code is on my &lt;a href=&quot;https://github.com/jlisic/rasterKernelEstimates&quot;&gt;github page&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
A short example of each function is provided below with some basic performance metrics.
All timings are done on a Late 2013 MacBook Pro 13&quot; with a dual-core 2.4Ghz i5 running R 3.3.1 compiled under gcc 6.1.0. 
&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;#rasterLocalSums&quot;&gt;rasterLocalSums&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#rasterLocalQuantiles&quot;&gt;rasterLocalQuantiles&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#rasterLocalMoments&quot;&gt;rasterLocalMoments&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#rasterLocalCategoricalModes&quot;&gt;rasterLocalCategoricalModes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2 id=&quot;rasterLocalSums&quot;&gt;rasterLocalSums&lt;/h2&gt;
&lt;p&gt;
The function &lt;code&gt;rasterLocalSums&lt;/code&gt; calculates a weighted sum of pixel values in a spatial neighborhood defined by the matrix &lt;code&gt;W&lt;/code&gt;,
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;21.865ex&quot; height=&quot;6.009ex&quot; style=&quot;vertical-align: -3.505ex;&quot; viewBox=&quot;0 -1078.4 9414 2587.3&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;use x=&quot;550&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(940,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1863&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2530&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3586,0)&quot;&gt;&lt;use x=&quot;75&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ2-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-1117)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(803,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;5349&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-77&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6065&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6455&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6924&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7314&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7886&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8276&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8745&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9135&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
This is similar to the raster library function &lt;code&gt;focal&lt;/code&gt; when fun is not specified.
In fact, the results are identical when padding is used in the &lt;code&gt;focal&lt;/code&gt; call.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-2&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(raster)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rasterKernelEstimates)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;500&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a raster object&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),n,n))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a weight matrix&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;focalWeight&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.04&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Gauss'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# apply the weight with rasterKernelEstimates&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;rLocalKDE1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rasterLocalSums&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,W)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;run.time)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##    user  system elapsed 
##   0.975   0.004   0.325
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# apply the weight with the raster packages focal&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;rLocalKDE2&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;focal&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,W,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;pad&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;run.time)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##    user  system elapsed 
##   0.667   0.008   0.678
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot original image&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot the smoothed image&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# print out the max abs difference&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl str&quot;&gt;&quot;The maximum absolute difference = %f.&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE2)&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;na.rm&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= T))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;## [1] &quot;The maximum absolute difference = 0.000000.&quot;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-2-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 1:&lt;/b&gt;  Original image.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-2-2.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 2:&lt;/b&gt;  Smoothed.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;h2 id=&quot;rasterLocalQuantiles&quot;&gt;rasterLocalQuantiles&lt;/h2&gt;

&lt;p&gt;
The function &lt;code&gt;rasterLocalQuantiles&lt;/code&gt; calculates the &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.865ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -934.9 1233.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-71&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(464,362)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-74&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-68&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; quantile of pixel values in a spatial neighborhood defined by the matrix &lt;code&gt;W&lt;/code&gt;;
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-10-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;53.501ex&quot; height=&quot;4.843ex&quot; style=&quot;vertical-align: -1.838ex;&quot; viewBox=&quot;0 -1293.7 23035 2085&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;use x=&quot;550&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(940,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1863&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2530&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3586,0)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ2-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;667&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-61&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1197&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-72&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1648&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-67&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2129&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3007&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-61&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3537,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;572&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;962&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1431&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1821&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2099&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2569&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2288,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;7289&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8041&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-72&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(8659,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1242&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1631&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2101&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2768&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3824&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4397&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4786&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5256&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5645&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;14972&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2264&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(15750,0)&quot;&gt;&lt;g transform=&quot;translate(397,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;1621&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;use x=&quot;580&quot; y=&quot;714&quot; xlink:href=&quot;#MJMATHI-71&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(60,-687)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;17890&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;18335&quot; y=&quot;-1&quot; xlink:href=&quot;#MJSZ2-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;22756&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-11-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;4.88ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 2101 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-58&quot;&gt;&lt;/use&gt;&lt;use x=&quot;852&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1242&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1711&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is a random variable on the support of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-12-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.479ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 1067.4 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;867&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, a spatial neighborhood about point &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-13-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.145ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -576.1 923.4 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
This result should generally be reproducible using the raster library function &lt;code&gt;focal&lt;/code&gt; when fun is specified as &lt;code&gt;quantile&lt;/code&gt;.
Because quantiles do not necessarily fall exactly on order statistics there is a need to map quantiles between a function of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Order_statistic&quot;&gt;order statistics&lt;/a&gt;.
In the &lt;code&gt;rasterLocalQuantiles&lt;/code&gt; function this mapping is done to the closest odd-valued-index order statistic.
E.g. if the quantile falls between the first and second order statistic.
This approach matches the inverse empirical cdf transform used by the &lt;code&gt;type=1&lt;/code&gt; transform in the &lt;code&gt;stats::quantile&lt;/code&gt; function.
Note that the &lt;code&gt;quantile&lt;/code&gt; function applied to raster objects calculates the quantile from all pixels, not local quantiles.
&lt;/p&gt;

&lt;p&gt;
As far as applications go, this function is particularly useful when working with data with a large number of outliers.
&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-3&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(raster)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rasterKernelEstimates)&lt;/span&gt;


&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a raster object with extreme values&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rcauchy&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),n,n))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a weight matrix&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;nrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# calculate local median&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;rLocalKDE1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rasterLocalQuantiles&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,W,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;run.time)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##    user  system elapsed
##   0.018   0.001   0.010
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# calculate local median&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;rLocalKDE2&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;focal&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;r, W,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;pad&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwa&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;) stats&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;quantile&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(x,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;probs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;na.rm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=T,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;padValue&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;NA&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;run.time)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##    user  system elapsed
##   1.245   0.010   1.268
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot boxplot of original image&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;boxplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot the smoothed image&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# print out the max abs difference&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl str&quot;&gt;&quot;The maximum absolute difference = %f.&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE2)&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;na.rm&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;= T))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;## [1] &quot;The maximum absolute difference = 0.000000.&quot;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-3-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 3:&lt;/b&gt;  Box plot of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Cauchy_distribution&quot;&gt; Cauchy distributed &lt;/a&gt; values in the raster &lt;code&gt;r&lt;/code&gt;.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-3-2.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 4:&lt;/b&gt;  Smoothed.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;h2 id=&quot;rasterLocalMoments&quot;&gt;rasterLocalMoments&lt;/h2&gt;
&lt;p&gt;
The function &lt;code&gt;rasterLocalMoments&lt;/code&gt; calculates up to the second moment over the weighted matricies &lt;code&gt;Wmu&lt;/code&gt; and &lt;code&gt;Wvar&lt;/code&gt;,
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-14-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;26.087ex&quot; height=&quot;7.176ex&quot; style=&quot;vertical-align: -3.005ex;&quot; viewBox=&quot;0 -1796 11231.7 3089.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3BC&quot;&gt;&lt;/use&gt;&lt;use x=&quot;79&quot; y=&quot;20&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;603&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(993,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1916&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2583&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3362,0)&quot;&gt;&lt;g transform=&quot;translate(397,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;7351&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,958)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(803,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2918,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-77&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1013&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-3BC&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4162&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4551&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5021&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5410&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5983&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6372&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6842&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(970,-771)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(803,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2918,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-77&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1013&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-3BC&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4162&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4551&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5021&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
and
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-15-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;38.725ex&quot; height=&quot;7.676ex&quot; style=&quot;vertical-align: -3.005ex;&quot; viewBox=&quot;0 -2011.3 16673.3 3304.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;810&quot; y=&quot;583&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;263&quot; y=&quot;462&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1026&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1416,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;2339&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3006&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3785,0)&quot;&gt;&lt;g transform=&quot;translate(397,0)&quot;&gt;&lt;rect stroke=&quot;none&quot; width=&quot;12091&quot; height=&quot;60&quot; x=&quot;0&quot; y=&quot;220&quot;&gt;&lt;/rect&gt;&lt;g transform=&quot;translate(60,958)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(803,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2918,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-77&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1013&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4140&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4529&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4999&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(5388,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use x=&quot;962&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1351&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1821&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2432&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3433,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-3BC&quot;&gt;&lt;/use&gt;&lt;use x=&quot;79&quot; y=&quot;20&quot; xlink:href=&quot;#MJMAIN-5E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4036&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4426,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;5349&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5739&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;8667&quot; y=&quot;675&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(3351,-771)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ1-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1056,-287)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(803,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2918,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-77&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1013&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMATHI-3C3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;4140&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4529&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4999&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;16394&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
The difference between the mean call here and &lt;code&gt;rasterLocalSums&lt;/code&gt; is the normalization of the weights.  This ensures the weights sum to one.
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-4&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(raster)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rasterKernelEstimates)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;200&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a raster object of two populations&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;cbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),n,n),&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rnorm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),n,n)) )&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;# create a weight matrix&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;focalWeight&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;0.04&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Gauss'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# calculate the weighted local mean and variance&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;rLocalKDE1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rasterLocalMoments&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,W)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;run.time)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##    user  system elapsed 
##   0.343   0.002   0.102
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot original image&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot the weighted mean&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;mu)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot the weighted variance&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;var)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-4-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 5:&lt;/b&gt;  Original image.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-4-2.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 6:&lt;/b&gt;  Local weighted mean of the original image.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-4-3.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 7:&lt;/b&gt;  Local weighted variance of the original image.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;h2 id=&quot;rasterLocalCategoricalModes&quot;&gt;rasterLocalCategorical Modes&lt;/h2&gt;
&lt;p&gt;
The function &lt;code&gt;rasterLocalCategoricalModes&lt;/code&gt; calculates a categorical mode from a raster image over the weighted spatial neighborhood devined by the matrix &lt;code&gt;W&lt;/code&gt;, 
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-16-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;42.577ex&quot; height=&quot;7.843ex&quot; style=&quot;vertical-align: -3.505ex;&quot; viewBox=&quot;0 -1867.7 18331.8 3376.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;use x=&quot;550&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(940,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;663&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1863&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2530&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3586,0)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;806&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1517&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2074&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2952&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-61&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(3482,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(572,-155)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;433&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(778,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-43&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;881&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(5963,0)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-7B&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(806,0)&quot;&gt;&lt;use x=&quot;75&quot; y=&quot;0&quot; xlink:href=&quot;#MJSZ2-2211&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-1117)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;469&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(803,0)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-53&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.574)&quot; x=&quot;755&quot; y=&quot;-243&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;2568&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-77&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3285&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3674&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4144&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4533,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJAMS-49&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(389,-187)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-78&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;572&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;962&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1431&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1821&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;2599&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;7168&quot; y=&quot;-1&quot; xlink:href=&quot;#MJSZ4-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;13938&quot; y=&quot;-1&quot; xlink:href=&quot;#MJSZ4-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-17-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.716ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 1169.4 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-43&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;1011&quot; y=&quot;-213&quot; xlink:href=&quot;#MJMAIN-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is the set of unique categories in &lt;code&gt;r&lt;/code&gt;.
&lt;p&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-5&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(raster)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rasterKernelEstimates)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;set.seed&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;100&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a categorical raster&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;raster&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=n&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=T),n,n)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;hl com&quot;&gt;# create a weight matrix&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# calculate the weighted local mean and variance&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;run.time&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;rLocalKDE1&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rasterLocalCategoricalModes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r,W)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;proc.time&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;run.time)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##    user  system elapsed 
##   0.030   0.000   0.011
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot original image&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(r)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# plot the weighted mean&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(rLocalKDE1)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-5-1.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 8:&lt;/b&gt;  Original image.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/rasterKernel/figure/unnamed-chunk-5-2.png&quot; class=&quot;main&quot;&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 9:&lt;/b&gt;  Local weighted mode of the original image.&lt;/figcaption&gt;
&lt;/figure&gt;


</description>
        <pubDate>Tue, 02 Aug 2016 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/r/kernel/raster/2016/08/02/Kernels-for-everyone-!.html</link>
        <guid isPermaLink="true">http://meanmean.me/r/kernel/raster/2016/08/02/Kernels-for-everyone-!.html</guid>
        
        
        <category>R</category>
        
        <category>kernel</category>
        
        <category>raster</category>
        
      </item>
    
      <item>
        <title>On a finite time scale</title>
        <description>&lt;p&gt;
It was rumored that updates to the MacBook Pro were coming at WWDC.
These rumors did not pan out.
Instead it looks like the new MacBook Pro will be landing sometime later this year, possibly due to delays in availability of high end Skylake 45w mobile parts.
This seems plausible, given that Intel only released its Skylake quad core NUC in mid-May. 
The magnitude of these delays has certainly made its way around the tech press, but are these delays really exceptional?
&lt;/p&gt;

&lt;p&gt; 
This quick exploratory analysis of the significance of these delays was performed using historical delays between iterations.  
The source of this release dates was from the  &lt;a href=&quot;http://www.wikipedia.org&quot;&gt;Wikipedia&lt;/a&gt; pages for each of these products.  A csv file including this data has been made available &lt;a href=&quot;http://meanmean.me/blog/its/macrelease.csv&quot;&gt;here&lt;/a&gt;.
For the retina and non-retina release dates are given for only the retina versions of products once they become available.  
&lt;/p&gt;

&lt;p&gt;
Notably absent from this analysis is the MacBook Air and MacBook.  In the former case the dates were not present on the Wikipedia article, and in the later case there wasn't sufficient data to do anything but interpolate.
&lt;/p&gt;

&lt;h2&gt; Overview &lt;/h2&gt;

&lt;p&gt;
For this exploratory analysis two models were used.
The first model, linear regression with one predictor (see Figure 1.), assumes that there is a constant interval between releases over time.
Deviations from this release cycle are just model error.
The second model is a differenced regression model.
In this linear model, release dates are replaced with differences between release dates.
This allows for a trend in the release dates, such as increasing delays between releases.
&lt;/p&gt;

&lt;p&gt;
This analysis treats future releases and delays as a prediction problem.
Therefore, &lt;a href=&quot;https://en.wikipedia.org/wiki/Prediction_interval&quot;&gt;prediction intervals&lt;/a&gt; are used to determine significance.
The level of significance is set to 5% for the two sided interval, however our interest is really at large delays giving us a one-sided confidence level of to 2.5% for our analysis. 
Inference including point estimates and prediction intervals are based on standard &lt;a href=&quot;https://en.wikipedia.org/wiki/Ordinary_least_squares#Classical_linear_regression_model&quot;&gt;ordinary least squares (OLS) assumptions&lt;/a&gt;.
In both models, time is treated as the dependent variable with product iteration as the independent variable.
Time is represented as days since epoch, where epoch is set at 0 equal to January 1, 1970.
&lt;/p&gt;

&lt;p&gt;
This problem is actually a wait-time problem, so normality is used as an approximation to modeling with &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_distribution&quot;&gt;gamma distributed&lt;/a&gt; errors or other slightly more difficult approaches.
Still, the regression approach seems to be 'good enough' for this blog post.  In the future I'll revisit more complex models.
&lt;/p&gt;

&lt;!--
&lt;p&gt;
&lt;a href=&quot;javascript:showhide('R1')&quot;&gt;Show R Code.&lt;/a&gt;
&lt;/p&gt;
&lt;div id=&quot;R1&quot; style=&quot;display:none;&quot;&gt;
&lt;p&gt;
--&gt;
&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-1&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl std&quot;&gt;macRelease&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;read.csv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'macrelease.csv'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;macRelease&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;releaseDate&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.Date&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;macRelease&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Release.date,&lt;/span&gt;
  &lt;span class=&quot;hl kwc&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;%d %B %Y&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot product release dates by iteration&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(macRelease,&lt;/span&gt;
            &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Iteration,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=releaseDate,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Product))&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;geom_line&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Product),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_point&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Product),&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Apple Product Iteration by Release Date'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Release Date&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;!--
&lt;/p&gt;
&lt;/div&gt;
--&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-1-1.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 1:&lt;/b&gt;  Linear regression models by Product.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
The significance of the results differ considerably by model.
According to the first model used, all but the 27&quot; iMac are past the expected release date.   
Of these delayed products, all but the 21.5&quot; iMac, has a significant delay.
&lt;/p&gt;
&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-2&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl com&quot;&gt;# linear model by product&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#get unique factors as string&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;currentProducts&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;unique&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(macRelease&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Product)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a place to save our predictions&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;releaseInterval&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# get a specific product&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( i&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProducts)) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;currentProduct&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(macRelease,Product&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;currentProducts[i])&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# produce a product scatterplot with a linear model overlay &lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProduct,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Iteration,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=releaseDate))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;geom_point&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;geom_smooth&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;lm&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;se&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=currentProducts[i],&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Iteration&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Release Date&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# converting time to something linear we do our prediction&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;fit&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;lm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(releaseDate)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;Iteration,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=currentProduct)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;fit,&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;Iteration&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;nrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProduct)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;interval&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;prediction&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;releaseInterval&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( releaseInterval, pred)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;rownames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(releaseInterval)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;currentProducts&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# using epoch we get a date range conversion&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;start.date&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.Date&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;1970-01-01&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;releaseInterval&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(releaseInterval)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;releaseInterval&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;fit&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&quot;hl kwd&quot;&gt;as.character&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.Date&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(releaseInterval&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;fit,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=start.date))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;releaseInterval&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;lwr&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&quot;hl kwd&quot;&gt;as.character&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.Date&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(releaseInterval&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;lwr,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=start.date))&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;releaseInterval&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;upr&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&quot;hl kwd&quot;&gt;as.character&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.Date&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(releaseInterval&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;upr,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=start.date))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;table border=1&gt;
&lt;caption&gt; Summary of Expected Release Dates and a 95% Prediction Interval &lt;/caption&gt;
&lt;tr&gt; &lt;th&gt;  Product&lt;/th&gt; &lt;th&gt; Expected Release Date &lt;/th&gt; &lt;th&gt; Lower Bound &lt;/th&gt; &lt;th&gt; Upper Bound &lt;/th&gt;  &lt;/tr&gt;
&lt;tr&gt; &lt;td align=&quot;right&quot;&gt; iMac 27 &lt;/td&gt; &lt;td&gt; 2017-03-28 &lt;/td&gt; &lt;td&gt; 2016-02-02 &lt;/td&gt; &lt;td&gt; 2018-05-22 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; iMac 21.5 &lt;/td&gt; &lt;td&gt; 2016-06-19 &lt;/td&gt; &lt;td&gt; 2015-06-13 &lt;/td&gt; &lt;td&gt; 2017-06-27 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; Mac Mini &lt;/td&gt; &lt;td&gt; 2014-01-26 &lt;/td&gt; &lt;td&gt; 2012-03-02 &lt;/td&gt; &lt;td&gt; 2015-12-22 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; Mac Pro &lt;/td&gt; &lt;td&gt; 2015-04-15 &lt;/td&gt; &lt;td&gt; 2014-06-20 &lt;/td&gt; &lt;td&gt; 2016-02-08 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; MacBook Pro 13 &lt;/td&gt; &lt;td&gt; 2016-01-02 &lt;/td&gt; &lt;td&gt; 2015-07-08 &lt;/td&gt; &lt;td&gt; 2016-06-29 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; MacBook Pro 15 &lt;/td&gt; &lt;td&gt; 2015-07-11 &lt;/td&gt; &lt;td&gt; 2014-10-10 &lt;/td&gt; &lt;td&gt; 2016-04-09 &lt;/td&gt; &lt;/tr&gt;
   &lt;/table&gt;


&lt;p&gt;
The second model is a bit more accepting of delays.  
The MacBook Pros and the Mac Pro have significant delays, marginally so for the Mac Pro.
The significance of the 15&quot; MacBook Pro is in part to it's highly regular release schedule.
The negative values in the lower bound indicate that the normality assumption may be problematic.
&lt;/p&gt;

&lt;table border=1&gt;
&lt;caption&gt;Summary of Expected Delays Between Products and a 95% Prediction Interval&lt;/caption&gt;
&lt;tr&gt; &lt;th&gt; Product &lt;/th&gt; &lt;th&gt; Expected Delay (Days)&lt;/th&gt; &lt;th&gt; Lower Bound	 &lt;/th&gt; &lt;th&gt; Upper Bound &lt;/th&gt; &lt;th&gt; Delay as of 29 July, 2016&lt;/th&gt;  &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; iMac 27 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 213.61 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; -242.05 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 669.27 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 290.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; iMac 21.5 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 317.64 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; -244.61 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 879.90 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 290.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; Mac Mini &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 565.73 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; -101.98 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 1233.44 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 653.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; Mac Pro &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 603.40 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 257.63 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 949.17 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 953.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; MacBook Pro 13 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 220.33 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 0.09 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 440.57 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 508.00 &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt; &lt;td align=&quot;right&quot;&gt; MacBook Pro 15 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 273.71 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 113.57 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 433.85 &lt;/td&gt; &lt;td align=&quot;right&quot;&gt; 437.00 &lt;/td&gt; &lt;/tr&gt;
   &lt;/table&gt;

&lt;p&gt;
In both models the delay before the release of the latest Mac Mini is a fairly significant outlier.
This increase in delay may indicate a change in update frequency.
If this is a change in frequency, then inference using the first model with OLS assumptions is inappropriate due to the error term not being identically distributed.
The presence of a good covariate may fix this issue, but it is unknown what covariate would describe this delay.
The difference model may also be inappropriate under this change due the presence of &lt;a href=&quot;https://en.wikipedia.org/wiki/Heteroscedasticity&quot;&gt;heteroscedasticity&lt;/a&gt;.
&lt;/p&gt;









&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-3&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl std&quot;&gt;diffInterval&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#get a specific product&lt;/span&gt;
&lt;span class=&quot;hl kwa&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( i&lt;/span&gt; &lt;span class=&quot;hl kwa&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProducts)) {&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;currentProduct&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(macRelease,Product&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;currentProducts[i])&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# get differences&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;refreshDiff&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;cbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;diff&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProduct&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;releaseDate),&lt;/span&gt;
    &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;nrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProduct)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# add on some column names and make a data frame&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(refreshDiff)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Days'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Iteration'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;refreshDiff&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(refreshDiff)&lt;/span&gt;

    &lt;span class=&quot;hl com&quot;&gt;# converting time to something linear we do our prediction&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;fit&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;lm&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Days)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;~&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;Iteration,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=refreshDiff)&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl std&quot;&gt;fit,&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;data.frame&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;Iteration&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;nrow&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(refreshDiff)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;interval&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;prediction&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# get the difference between the last date, and today's date&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;todayDiff&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;Sys.Date&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(currentProduct&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;releaseDate) )&lt;/span&gt;

  &lt;span class=&quot;hl std&quot;&gt;diffInterval&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;rbind&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;( diffInterval,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(pred,todayDiff))&lt;/span&gt;

  &lt;span class=&quot;hl com&quot;&gt;# plot the times betweeen iteration&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(refreshDiff,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Iteration,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;as.numeric&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Days)))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;geom_point&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;geom_smooth&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;lm&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=currentProducts[i],&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Iteration&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Days Between Release&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;hl kwd&quot;&gt;geom_hline&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;yintercept&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=todayDiff,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'red'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;rownames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(diffInterval)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;currentProducts&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;h2&gt; Product Release Dates &lt;/h2&gt;

&lt;h3&gt;iMac 27&quot;&lt;/h3&gt;

&lt;p&gt;
Expected Update: &lt;b&gt;2017-03-28&lt;/b&gt; with 95% prediction interval &lt;b&gt;(2016-02-02, 2018-05-22).&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;Looking at the 27&quot; iMac we can see that it is frequently updated.
The substance of the updates may be in question, but it certainly is at least getting some love.
&lt;p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-2-1.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 2:&lt;/b&gt;  Linear regression model of the 27&quot; iMac.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
Furthermore, we can see a decrease in time between updates, and the 27&quot; iMac is the only current product to get the Skylake treatment.  The number of iterations and variability in release dates make this analysis problematic, so the prediction interval takes us way out to mid 2018.
&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-3-1.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 3:&lt;/b&gt;  Differenced linear regression models of the 27&quot; iMac; the red line indicates the current delay as of 29 July, 2016.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h3&gt;iMac 21.5&quot;&lt;/h3&gt;
&lt;p&gt;
Expected Update: &lt;b&gt;2016-06-19&lt;/b&gt; with 95% prediction interval &lt;b&gt;(2015-06-13, 2017-06-27).&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
The 21.5&quot; iMac is a bit of an oddity; it is still using Broadwell, possibly due to its reliance on integrated graphics.
Despite the slightly older CPU architecture, relative to it's big sister, this mac is still being regularly updated.  As some degree of evidence that someone at Apple cares about this product, it did make its way into the Retina-age last update.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-2-2.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 4:&lt;/b&gt;  Linear regression model of the 21.5&quot; iMac.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
As before with the 27&quot; iMac, the data is a bit of a mess.  Looking at the plot of iterations verse days between releases, the slope has a fair bit of play leading to the fairly wide prediction interval.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-3-2.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 5:&lt;/b&gt;  Differenced linear regression models of the 21.5&quot; iMac; the red line indicates the current delay as of 29 July, 2016.&lt;/figcaption&gt;
&lt;/figure&gt;


&lt;h3&gt;Mac Mini&lt;/h3&gt;
&lt;p&gt;
Expected Update: &lt;b&gt;2014-01-26&lt;/b&gt; with 95% prediction interval &lt;b&gt;(2012-03-02, 2015-12-22).&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
The first obvious thing about the expected update date and associated prediction interval is that the lower bound occurs before the release of the prior Mac Mini.
This implies that a model with normal errors is unlikely to be appropriate.
The second thing, possibly more obvious, is that the point estimate (expected update date) is over two years ago, furthermore only about three months after the last release date.
The last release date being an extreme outlier.  Ideally, these estimates should be revisited with an improved model.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-2-3.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 6:&lt;/b&gt;  Linear regression model of the Mac Mini.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt; The second model, for the expected delay, is more forgiving.  
The upper bound of the prediction interval is close to 3.5 years, giving us another 1.5 years or so to call the delay significant.
&lt;/p&gt;

&lt;p&gt;
The Mac Mini did present a problem with an extended delay between the last and current iteration.  
The reason for this delay is unclear, making the identification of a good covariate such as Intel processor road maps problematic.
The problem with the Intel road map covariate, is that there are CPUs available that fit the price and thermal requirements held by prior Mac Minis.
These CPUs, available as of September 2015, include Intel Skylake i5 6260U, 6267U, and 6287U CPUs with the Intel i7 6567U for a high end SKU.
Without a good covariate to help explain this change, the observations may indicate a change in release rate.
If this is a change in release rate, it will be considerably more difficult to model the Mac Mini without moving to non-linear models.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-3-3.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 7:&lt;/b&gt;  Differenced linear regression models of the Mac Mini; the red line indicates the current delay as of 29 July, 2016.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-4&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl std&quot;&gt;geekBench&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;read.csv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'geekbench.csv'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(ggplot2)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;theme_set&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;theme_gray&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;base_size&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# plot product release dates by iteration&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;ggplot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(geekBench,&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;aes&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Product,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=GeekbenchScore,&lt;/span&gt; &lt;span class=&quot;hl kwc&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=Benchmark))&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;geom_bar&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;stat&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;identity&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;dodge&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;coord_flip&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;labs&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'Apple Product Iteration by Geekbench Score'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;hl kwc&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&amp;quot;Geekbench Score&amp;quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(p)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt; 
There is also a chance that the model has been discontinued.
Apple's &lt;a href=&quot;http://www.apple.com/mac-mini/&quot;&gt; Mac Mini advertisement&lt;/a&gt; page certainly doesn't help, where the mac mini is pictured next to a discontinued apple display.
&lt;/p&gt;

&lt;p&gt;
Under the assumption that Apple likes to make a profit, we could use sales figures to get an idea if this product is likely to be discontinued (assuming that Apple isn't selling at a loss).
Unfortunately, we don't have sales figures for the mac mini.
Instead &lt;a href=&quot;https://www.amazon.com/Best-Sellers-Electronics-Desktop-Computers/zgbs/electronics/565098&quot;&gt;Amazon's Best Sellers&lt;/a&gt; could be used as at least a measure of popularity relative to other products.
In this listing (as of 10:18AM EST on July 29, 2016) the mac mini holds place seven and eight with the 21.5&quot; iMac showing up in ninth and the 27&quot; iMac in twelfth.
Although it is unclear what the window the sales are aggregated over (&quot;Updated Hourly&quot; doesn't necessarily imply single hour aggregation), the sales positions do imply someone is buying these.
&lt;/p&gt;

&lt;p&gt;
For those interested, the eighth place product was the base model ($449) with a 1.4Ghz (2.7GHz Turbo Boost) CPU, 4GB of RAM and a 500GB hard drive.
The seventh place Mac Mini ($649) had 8GB of RAM, a 2.6GHz (3.1GHz Turbo Boost) CPU and a 1TB hard drive.
&lt;/p&gt;

&lt;p&gt;
This popularity is a bit surprising, given no real increase in single-core performance since 2011 and a decrease in multi-core performance since dropping the quad core model (Figure 8).
However, the mac mini is only $449 at Amazon, a good $550 cheaper than the 21.5&quot; iMac.
This price and demand for some macOS based desktop computing seems to keep this product around, likely without much change in price or performance.
&lt;/p&gt;


&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-4-1.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 8:&lt;/b&gt;  Rough summary of &lt;a href=&quot;https://browser.primatelabs.com/mac-benchmarks&quot;&gt;Geekbench 3 results&lt;/a&gt; for the Mac Mini.&lt;/figcaption&gt;
&lt;/figure&gt;



&lt;h3&gt;Mac Pro&lt;/h3&gt;

&lt;p&gt;
Expected Update: &lt;b&gt;2015-04-15&lt;/b&gt; with 95% prediction interval &lt;b&gt;(2014-06-20, 2016-02-08).&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
The first model (Figure 9.) shows a fairly regular update cycle for the Mac Pro.
Based on this regularity we would expect an update sometime around last month.
This of course hasn't happened, as seen by my aging 2006 Mac Pro and my full piggy bank.
This change in release date can't be adequately explained by lack of drop in CPU replacements, given that the 2011 pin Haswell and Broadwell chips have been skipped.
Therefore, it is unclear if Apple is waiting for the next Intel chip or the second coming for a future update.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-2-4.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 9:&lt;/b&gt;  Linear regression model of the Mac Pro.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
The second model (Figure 10.) agrees with the first with respect to the delay being significant.
This model further shows an increase in the delay between releases; as mentioned earlier, there doesn't seem to be any obvious reason for this delay.
&lt;/p&gt; 

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-3-4.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 10:&lt;/b&gt;  Differenced linear regression models of the Mac Pro; the red line indicates the current delay as of 29 July, 2016.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
Like the Mac Mini, Apple doesn't provide breakouts for sales for just the Mac Pro so it is hard to determine if it was a flop or not.
Even if it was a flop, there is always the argument for an aspiration product.
But, it is not clear if this product is really aspiring, or if gazes have moved to more mobile devices.
&lt;/p&gt;

&lt;h3&gt;MacBook Pro 13&quot;&lt;/h3&gt;

&lt;p&gt;
Expected Update: &lt;b&gt;2016-01-02&lt;/b&gt; with 95% prediction interval &lt;b&gt;( 2015-07-08, 2016-06-29).&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
There isn't that much to say about the MacBook Pro 13&quot;, it's late.
Furthermore, it's significantly late relative to other delays.
&lt;a href=&quot;http://www.macrumors.com/roundup/macbook-pro/&quot;&gt;Current rumors &lt;/a&gt; point to a release in Q4 2016, so the wait should come to an end soon.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-2-5.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 11:&lt;/b&gt;  Linear regression model of the MacBook Pro 13&quot;.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;
The second model points to a decrease in delays, but the variability is sufficiently high to reverse directions after a few late releases.
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-3-5.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 12:&lt;/b&gt;  Differenced linear regression models of the MacBook Pro 13&quot;; the red line indicates the current delay as of 29 July, 2016.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h3&gt;MacBook Pro 15&quot;&lt;/h3&gt;

&lt;p&gt;
Expected Update: &lt;b&gt;2015-07-11&lt;/b&gt; with 95% prediction interval &lt;b&gt;(2014-10-10, 2016-04-09).&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
Like the 13&quot; model the 15&quot; MacBook Pro is likely to get an update soon.
Unlike the 13&quot;, the 15&quot; model seemed to have slightly less variance, this seems to be at least in part due to the discrete GPU in the more recent models.  If we take a look at the last update in the MacBook Pro line, it met it's release date not by upgrading the CPU but by only upgrading the GPU.  
&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-2-6.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 11:&lt;/b&gt;  Linear regression model of the MacBook Pro 15&quot;.&lt;/figcaption&gt;
&lt;/figure&gt;

As far as the change in release rate goes, it seems to be increasing.  It will be interesting to see if this change extends to align with Intel's latest delays on Kaby Lake, or if Apple is happy to just exchange discrete graphics to keep up the cadence.

&lt;figure&gt;
  &lt;img src=&quot;http://meanmean.me/blog/its/figure/unnamed-chunk-3-6.png&quot;  class=&quot;main&quot;/&gt;
  &lt;figcaption&gt;&lt;b&gt;Figure 14:&lt;/b&gt;  Differenced linear regression models of the MacBook Pro 15&quot;; the red line indicates the current delay as of 29 July, 2016.&lt;/figcaption&gt;
&lt;/figure&gt;

</description>
        <pubDate>Fri, 29 Jul 2016 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/r/apple/2016/07/29/On-a-finite-time-scale.html</link>
        <guid isPermaLink="true">http://meanmean.me/r/apple/2016/07/29/On-a-finite-time-scale.html</guid>
        
        
        <category>R</category>
        
        <category>Apple</category>
        
      </item>
    
      <item>
        <title>Predicting Agriculture, Poorly (Part I)</title>
        <description>&lt;style id=&quot;MathJax_SVG_styles&quot;&gt;.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
&lt;/style&gt;
&lt;svg style=&quot;display: none;&quot;&gt;&lt;defs id=&quot;MathJax_SVG_glyphs&quot;&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAINB-62&quot; d=&quot;M32 686L123 690Q214 694 215 694H221V409Q289 450 378 450Q479 450 539 387T600 221Q600 122 535 58T358 -6H355Q272 -6 203 53L160 1L129 0H98V301Q98 362 98 435T99 525Q99 591 97 604T83 620Q69 624 42 624H29V686H32ZM227 105L232 99Q237 93 242 87T258 73T280 59T306 49T339 45Q380 45 411 66T451 131Q457 160 457 230Q457 264 456 284T448 329T430 367T396 389T343 398Q282 398 235 355L227 348V105Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-73&quot; d=&quot;M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2C&quot; d=&quot;M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-74&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-66&quot; d=&quot;M118 -162Q120 -162 124 -164T135 -167T147 -168Q160 -168 171 -155T187 -126Q197 -99 221 27T267 267T289 382V385H242Q195 385 192 387Q188 390 188 397L195 425Q197 430 203 430T250 431Q298 431 298 432Q298 434 307 482T319 540Q356 705 465 705Q502 703 526 683T550 630Q550 594 529 578T487 561Q443 561 443 603Q443 622 454 636T478 657L487 662Q471 668 457 668Q445 668 434 658T419 630Q412 601 403 552T387 469T380 433Q380 431 435 431Q480 431 487 430T498 424Q499 420 496 407T491 391Q489 386 482 386T428 385H372L349 263Q301 15 282 -47Q255 -132 212 -173Q175 -205 139 -205Q107 -205 81 -186T55 -132Q55 -95 76 -78T118 -61Q162 -61 162 -103Q162 -122 151 -136T127 -157L118 -162Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-62&quot; d=&quot;M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2026&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60ZM525 60Q525 84 542 102T585 120Q609 120 627 104T646 61Q646 36 629 18T586 0T543 17T525 60ZM972 60Q972 84 989 102T1032 120Q1056 120 1074 104T1093 61Q1093 36 1076 18T1033 0T990 17T972 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-72&quot; d=&quot;M21 287Q22 290 23 295T28 317T38 348T53 381T73 411T99 433T132 442Q161 442 183 430T214 408T225 388Q227 382 228 382T236 389Q284 441 347 441H350Q398 441 422 400Q430 381 430 363Q430 333 417 315T391 292T366 288Q346 288 334 299T322 328Q322 376 378 392Q356 405 342 405Q286 405 239 331Q229 315 224 298T190 165Q156 25 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 114 189T154 366Q154 405 128 405Q107 405 92 377T68 316T57 280Q55 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHBI-3F5&quot; d=&quot;M415 89Q423 89 429 74T436 46Q436 43 434 39Q432 36 420 29T380 11T322 -5Q311 -7 281 -7Q216 -7 168 10T94 54T56 110T44 167V181Q44 262 94 329Q104 343 119 357T162 391T234 425T327 443Q328 443 348 443T383 444Q434 444 442 438Q450 430 450 416Q446 392 424 383L376 382Q306 381 278 369Q230 349 208 294Q199 274 199 268Q199 267 291 267Q305 267 325 267T353 268Q383 268 394 263T406 241Q406 214 380 206Q375 205 279 205T183 203Q174 176 174 140Q174 87 208 65T292 43Q295 43 300 43T307 44Q337 49 372 69T415 89Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7B&quot; d=&quot;M434 -231Q434 -244 428 -250H410Q281 -250 230 -184Q225 -177 222 -172T217 -161T213 -148T211 -133T210 -111T209 -84T209 -47T209 0Q209 21 209 53Q208 142 204 153Q203 154 203 155Q189 191 153 211T82 231Q71 231 68 234T65 250T68 266T82 269Q116 269 152 289T203 345Q208 356 208 377T209 529V579Q209 634 215 656T244 698Q270 724 324 740Q361 748 377 749Q379 749 390 749T408 750H428Q434 744 434 732Q434 719 431 716Q429 713 415 713Q362 710 332 689T296 647Q291 634 291 499V417Q291 370 288 353T271 314Q240 271 184 255L170 250L184 245Q202 239 220 230T262 196T290 137Q291 131 291 1Q291 -134 296 -147Q306 -174 339 -192T415 -213Q429 -213 431 -216Q434 -219 434 -231Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2E&quot; d=&quot;M78 60Q78 84 95 102T138 120Q162 120 180 104T199 61Q199 36 182 18T139 0T96 17T78 60Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-63&quot; d=&quot;M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325T330 359T352 380T366 386H367Q367 388 361 392T340 400T306 404Q276 404 249 390Q228 381 206 359Q162 315 142 235T121 119Q121 73 147 50Q169 26 205 26H209Q321 26 394 111Q403 121 406 121Q410 121 419 112T429 98T420 83T391 55T346 25T282 0T202 -11Q127 -11 81 37T34 159Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7D&quot; d=&quot;M65 731Q65 745 68 747T88 750Q171 750 216 725T279 670Q288 649 289 635T291 501Q292 362 293 357Q306 312 345 291T417 269Q428 269 431 266T434 250T431 234T417 231Q380 231 345 210T298 157Q293 143 292 121T291 -28V-79Q291 -134 285 -156T256 -198Q202 -250 89 -250Q71 -250 68 -247T65 -230Q65 -224 65 -223T66 -218T69 -214T77 -213Q91 -213 108 -210T146 -200T183 -177T207 -139Q208 -134 209 3L210 139Q223 196 280 230Q315 247 330 250Q305 257 280 270Q225 304 212 352L210 362L209 498Q208 635 207 640Q195 680 154 696T77 713Q68 713 67 716T65 731Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-54&quot; d=&quot;M40 437Q21 437 21 445Q21 450 37 501T71 602L88 651Q93 669 101 677H569H659Q691 677 697 676T704 667Q704 661 687 553T668 444Q668 437 649 437Q640 437 637 437T631 442L629 445Q629 451 635 490T641 551Q641 586 628 604T573 629Q568 630 515 631Q469 631 457 630T439 622Q438 621 368 343T298 60Q298 48 386 46Q418 46 427 45T436 36Q436 31 433 22Q429 4 424 1L422 0Q419 0 415 0Q410 0 363 1T228 2Q99 2 64 0H49Q43 6 43 9T45 27Q49 40 55 46H83H94Q174 46 189 55Q190 56 191 56Q196 59 201 76T241 233Q258 301 269 344Q339 619 339 625Q339 630 310 630H279Q212 630 191 624Q146 614 121 583T67 467Q60 445 57 441T43 437H40Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-52&quot; d=&quot;M230 637Q203 637 198 638T193 649Q193 676 204 682Q206 683 378 683Q550 682 564 680Q620 672 658 652T712 606T733 563T739 529Q739 484 710 445T643 385T576 351T538 338L545 333Q612 295 612 223Q612 212 607 162T602 80V71Q602 53 603 43T614 25T640 16Q668 16 686 38T712 85Q717 99 720 102T735 105Q755 105 755 93Q755 75 731 36Q693 -21 641 -21H632Q571 -21 531 4T487 82Q487 109 502 166T517 239Q517 290 474 313Q459 320 449 321T378 323H309L277 193Q244 61 244 59Q244 55 245 54T252 50T269 48T302 46H333Q339 38 339 37T336 19Q332 6 326 0H311Q275 2 180 2Q146 2 117 2T71 2T50 1Q33 1 33 10Q33 12 36 24Q41 43 46 45Q50 46 61 46H67Q94 46 127 49Q141 52 146 61Q149 65 218 339T287 628Q287 635 230 637ZM630 554Q630 586 609 608T523 636Q521 636 500 636T462 637H440Q393 637 386 627Q385 624 352 494T319 361Q319 360 388 360Q466 361 492 367Q556 377 592 426Q608 449 619 486T630 554Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-50&quot; d=&quot;M130 622Q123 629 119 631T103 634T60 637H27V683H214Q237 683 276 683T331 684Q419 684 471 671T567 616Q624 563 624 489Q624 421 573 372T451 307Q429 302 328 301H234V181Q234 62 237 58Q245 47 304 46H337V0H326Q305 3 182 3Q47 3 38 0H27V46H60Q102 47 111 49T130 61V622ZM507 488Q507 514 506 528T500 564T483 597T450 620T397 635Q385 637 307 637H286Q237 637 234 628Q231 624 231 483V342H302H339Q390 342 423 349T481 382Q507 411 507 488Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-72&quot; d=&quot;M36 46H50Q89 46 97 60V68Q97 77 97 91T98 122T98 161T98 203Q98 234 98 269T98 328L97 351Q94 370 83 376T38 385H20V408Q20 431 22 431L32 432Q42 433 60 434T96 436Q112 437 131 438T160 441T171 442H174V373Q213 441 271 441H277Q322 441 343 419T364 373Q364 352 351 337T313 322Q288 322 276 338T263 372Q263 381 265 388T270 400T273 405Q271 407 250 401Q234 393 226 386Q179 341 179 207V154Q179 141 179 127T179 101T180 81T180 66V61Q181 59 183 57T188 54T193 51T200 49T207 48T216 47T225 47T235 46T245 46H276V0H267Q249 3 140 3Q37 3 28 0H20V46H36Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-2208&quot; d=&quot;M84 250Q84 372 166 450T360 539Q361 539 377 539T419 540T469 540H568Q583 532 583 520Q583 511 570 501L466 500Q355 499 329 494Q280 482 242 458T183 409T147 354T129 306T124 272V270H568Q583 262 583 250T568 230H124V228Q124 207 134 177T167 112T231 48T328 7Q355 1 466 0H570Q583 -10 583 -20Q583 -32 568 -40H471Q464 -40 446 -40T417 -41Q262 -41 172 45Q84 127 84 250Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-41&quot; d=&quot;M208 74Q208 50 254 46Q272 46 272 35Q272 34 270 22Q267 8 264 4T251 0Q249 0 239 0T205 1T141 2Q70 2 50 0H42Q35 7 35 11Q37 38 48 46H62Q132 49 164 96Q170 102 345 401T523 704Q530 716 547 716H555H572Q578 707 578 706L606 383Q634 60 636 57Q641 46 701 46Q726 46 726 36Q726 34 723 22Q720 7 718 4T704 0Q701 0 690 0T651 1T578 2Q484 2 455 0H443Q437 6 437 9T439 27Q443 40 445 43L449 46H469Q523 49 533 63L521 213H283L249 155Q208 86 208 74ZM516 260Q516 271 504 416T490 562L463 519Q447 492 400 412L310 260L413 259Q516 259 516 260Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-7C&quot; d=&quot;M139 -249H137Q125 -249 119 -235V251L120 737Q130 750 139 750Q152 750 159 735V-235Q151 -249 141 -249H139Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-4B&quot; d=&quot;M285 628Q285 635 228 637Q205 637 198 638T191 647Q191 649 193 661Q199 681 203 682Q205 683 214 683H219Q260 681 355 681Q389 681 418 681T463 682T483 682Q500 682 500 674Q500 669 497 660Q496 658 496 654T495 648T493 644T490 641T486 639T479 638T470 637T456 637Q416 636 405 634T387 623L306 305Q307 305 490 449T678 597Q692 611 692 620Q692 635 667 637Q651 637 651 648Q651 650 654 662T659 677Q662 682 676 682Q680 682 711 681T791 680Q814 680 839 681T869 682Q889 682 889 672Q889 650 881 642Q878 637 862 637Q787 632 726 586Q710 576 656 534T556 455L509 418L518 396Q527 374 546 329T581 244Q656 67 661 61Q663 59 666 57Q680 47 717 46H738Q744 38 744 37T741 19Q737 6 731 0H720Q680 3 625 3Q503 3 488 0H478Q472 6 472 9T474 27Q478 40 480 43T491 46H494Q544 46 544 71Q544 75 517 141T485 216L427 354L359 301L291 248L268 155Q245 63 245 58Q245 51 253 49T303 46H334Q340 37 340 35Q340 19 333 5Q328 0 317 0Q314 0 280 1T180 2Q118 2 85 2T49 1Q31 1 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5B&quot; d=&quot;M118 -250V750H255V710H158V-210H255V-250H118Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-70&quot; d=&quot;M23 287Q24 290 25 295T30 317T40 348T55 381T75 411T101 433T134 442Q209 442 230 378L240 387Q302 442 358 442Q423 442 460 395T497 281Q497 173 421 82T249 -10Q227 -10 210 -4Q199 1 187 11T168 28L161 36Q160 35 139 -51T118 -138Q118 -144 126 -145T163 -148H188Q194 -155 194 -157T191 -175Q188 -187 185 -190T172 -194Q170 -194 161 -194T127 -193T65 -192Q-5 -192 -24 -194H-32Q-39 -187 -39 -183Q-37 -156 -26 -148H-6Q28 -147 33 -136Q36 -130 94 103T155 350Q156 355 156 364Q156 405 131 405Q109 405 94 377T71 316T59 280Q57 278 43 278H29Q23 284 23 287ZM178 102Q200 26 252 26Q282 26 310 49T356 107Q374 141 392 215T411 325V331Q411 405 350 405Q339 405 328 402T306 393T286 380T269 365T254 350T243 336T235 326L232 322Q232 321 229 308T218 264T204 212Q178 106 178 102Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-22EE&quot; d=&quot;M78 30Q78 54 95 72T138 90Q162 90 180 74T199 31Q199 6 182 -12T139 -30T96 -13T78 30ZM78 440Q78 464 95 482T138 500Q162 500 180 484T199 441Q199 416 182 398T139 380T96 397T78 440ZM78 840Q78 864 95 882T138 900Q162 900 180 884T199 841Q199 816 182 798T139 780T96 797T78 840Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMAIN-5D&quot; d=&quot;M22 710V750H159V-250H22V-210H119V710H22Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A1&quot; d=&quot;M319 -645V1154H666V1070H403V-645H319Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A3&quot; d=&quot;M319 -644V1155H403V-560H666V-644H319Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A2&quot; d=&quot;M319 0V602H403V0H319Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A4&quot; d=&quot;M0 1070V1154H347V-645H263V1070H0Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A6&quot; d=&quot;M263 -560V1155H347V-644H0V-560H263Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJSZ4-23A5&quot; d=&quot;M263 0V602H347V0H263Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-69&quot; d=&quot;M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;path stroke-width=&quot;1&quot; id=&quot;MJMATHI-6A&quot; d=&quot;M297 596Q297 627 318 644T361 661Q378 661 389 651T403 623Q403 595 384 576T340 557Q322 557 310 567T297 596ZM288 376Q288 405 262 405Q240 405 220 393T185 362T161 325T144 293L137 279Q135 278 121 278H107Q101 284 101 286T105 299Q126 348 164 391T252 441Q253 441 260 441T272 442Q296 441 316 432Q341 418 354 401T367 348V332L318 133Q267 -67 264 -75Q246 -125 194 -164T75 -204Q25 -204 7 -183T-12 -137Q-12 -110 7 -91T53 -71Q70 -71 82 -81T95 -112Q95 -148 63 -167Q69 -168 77 -168Q111 -168 139 -140T182 -74L193 -32Q204 11 219 72T251 197T278 308T289 365Q289 372 288 376Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;
&lt;p&gt; 
Crop rotation is an agricultural production practice to increase yield, mitigate disease, and control pests. 
This production practice involves growing crops in specific sequences to improve the quality of soil for the following crop.
A common example in the United States is the practice of growing soybeans before corn.  
In this example soybeans fixate nitrogen in the soil leading to an increase in yield and reduction in fertilizer consumption.
&lt;/p&gt;

&lt;p&gt; 
Provided that this production process is prevalent and we have some data regarding where and when particular crops grow, then a stochastic process such as a Markov chain can be used to predict &lt;i&gt;what&lt;/i&gt; will be grown &lt;i&gt;where&lt;/i&gt;. 
Luckily, the United States Department of Agriculture's (USDA) &lt;a href=&quot;https://nassgeodata.gmu.edu/CropScape/&quot;&gt;Cropland Data Layer&lt;/a&gt; (CDL) can be used to obtain crop location anywhere in the continental United States from 2008-2015.

The literature on this subject for major crops including corn, soybeans, winter wheat, cotton and peanuts points towards a high degree of employment of crop rotation across the continental United States.
An analysis of the CDL data by (Sahajpal, 2013) showed that 90% of Iowa's crop production could be represented with three different crop rotations, and 80% of the U.S. crop production could be described with 180 unique rotations.  
Crop rotation analysis by (Boryan, 2014) examined corn and soybean rotations in the corn belt from 2004 to 2008.
This analysis showed that over 45% of the total cultivated acreage in Iowa, 32% of Illinois, and 20% of Nebraska could be explained by corn-to-soy rotations.
Further analysis showed that particular rotation patterns are spatially associated with particular regions.
An example of this can be seen along the Platte river in Nebraska where 65%, 49%, and 50% of the cultivated acreage within Hall, Chase, and Dawson Counties respectfully grew corn for at least four out of the five years studied, while the statewide cultivated acreage covered by continuous or near-continuous corn cropping was much lower.
Similar activity was seen in Iowa and Illinois.
&lt;/p&gt;


&lt;h2&gt; Model Development &lt;/h2&gt;

&lt;p&gt;
In the United States crop rotation can be observed for most major row crops such as corn, soybeans, and wheat. 
A naive model will be introduced using a simple Markov chain to assist in prediction. 
Future models in this blog will build on this model, and use this simple model as a benchmark.
&lt;/p&gt;


&lt;h2&gt;A Naive Approach &lt;/h2&gt;

&lt;p&gt;
A stochastic processes is an ordered sequence of random variables.  
The relationship between these variables can be described by a stochastic model, such models are a typical way to capture changes in states such as crop rotations.  
A general form of a categorical stochastic model for land use is 
&lt;/p&gt;&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-1-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;44.374ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 19105.4 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;639&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1029&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1498&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1943&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2305&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2972&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4028&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4745,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;819&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1208&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1678&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2123&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2706&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3707&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4208&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4597&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5042&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2026&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6381&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6827&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7256&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7646&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8115&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8560&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9144&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10145&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-72&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10596&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10986&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11431&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHBI-3F5&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11914&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12304&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12773&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13219&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13580&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13970&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-2-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;6.259ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 2694.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;639&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1029&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1498&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1943&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2305&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is a categorical random variable for classes &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-3-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;9.664ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 4160.8 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1001&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1446&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1891&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2336&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2781&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3226&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3660&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; indexed by time &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-4-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;0.84ex&quot; height=&quot;2.009ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -719.6 361.5 865.1&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; in a set of temporal indexes &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-5-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.636ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 704.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-54&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;, and &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-6-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.09ex&quot; height=&quot;1.676ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -576.1 469.5 721.6&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; a spatial location in a region &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-7-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;1.764ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 759.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-52&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.
In this model the current land use or state is a function of the prior states and random error &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-8-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;5.896ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 2538.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHBI-3F5&quot;&gt;&lt;/use&gt;&lt;use x=&quot;483&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;873&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1342&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1787&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2149&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.
If we were to make the naive assumption that each land use unit is an independent realization of a stationary in time Markov Chain, where a Markov Chain is a stochastic process satisfying 
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-9-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;72.068ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 31029.2 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;681&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-72&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(1240,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1029&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1418&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1888&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2333&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2694&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3361&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4307&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5057&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5336&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5975&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6365&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6834&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7863&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8864&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9364&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9754&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;11662&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(12718,0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;681&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-72&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(13959,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1029&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1418&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1888&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2333&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2694&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3361&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4307&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-41&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5057&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5336&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5975&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6365&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6834&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7279&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7863&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8864&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9364&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9754&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10199&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10839&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11228&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11698&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12143&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12726&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;13727&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use x=&quot;14228&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;14617&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;15062&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2026&quot;&gt;&lt;/use&gt;&lt;use x=&quot;16235&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;30750&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;  
under these conditions the stochastic model can be written as
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-10-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;30.57ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 13162 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;639&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1029&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1498&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1943&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2305&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2972&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4028&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-66&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(4745,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;389&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;819&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1208&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1678&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2123&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2706&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3707&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4208&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4597&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5042&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHBI-3F5&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5526&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5915&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6385&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;6830&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7191&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7581&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;12883&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;
The term stationary when applied to a stochastic process implies that the distribution is invariant to the index of the process.
Stationarity can be applied to time, space or both.
For the purposes of this simple model we will assume that &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-11-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;6.259ex&quot; height=&quot;2.843ex&quot; style=&quot;vertical-align: -0.838ex;&quot; viewBox=&quot;0 -863.1 2694.7 1223.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;639&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1029&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-73&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1498&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1943&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2305&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; is stationary in time, and each observed transition is independent and identically distributed.  
Future models will relax these restrictions.
Since the transition probabilities are stationary in time, then the process can be also described via a single transition or stochastic matrix,
&lt;div class=&quot;MathJax_SVG_Display&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-12-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;27.734ex&quot; height=&quot;13.843ex&quot; style=&quot;vertical-align: -6.338ex;&quot; viewBox=&quot;0 -3231.2 11941.2 5960&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4B&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1167&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2223,0)&quot;&gt;&lt;g transform=&quot;translate(0,3100)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1155&quot; xlink:href=&quot;#MJSZ4-23A1&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-3946.359271523179) scale(1,3.640728476821192)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-23A2&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-5056&quot; xlink:href=&quot;#MJSZ4-23A3&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(834,0)&quot;&gt;&lt;g transform=&quot;translate(-11,0)&quot;&gt;&lt;g transform=&quot;translate(0,2300)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,900)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;516&quot; y=&quot;-1001&quot; xlink:href=&quot;#MJMAIN-22EE&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(23,-2401)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;433&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(2300,0)&quot;&gt;&lt;g transform=&quot;translate(0,2300)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,900)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(23,-2401)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;433&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(4612,0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;2300&quot; xlink:href=&quot;#MJMAIN-2026&quot;&gt;&lt;/use&gt;&lt;use x=&quot;0&quot; y=&quot;900&quot; xlink:href=&quot;#MJMAIN-2026&quot;&gt;&lt;/use&gt;&lt;use x=&quot;0&quot; y=&quot;-2401&quot; xlink:href=&quot;#MJMAIN-2026&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g transform=&quot;translate(6784,0)&quot;&gt;&lt;g transform=&quot;translate(0,2300)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(0,900)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-32&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;500&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;use x=&quot;492&quot; y=&quot;-1001&quot; xlink:href=&quot;#MJMAIN-22EE&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(23,-2401)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;433&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-63&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(9050,3100)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;-1155&quot; xlink:href=&quot;#MJSZ4-23A4&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(0,-3946.359271523179) scale(1,3.640728476821192)&quot;&gt;&lt;use xlink:href=&quot;#MJSZ4-23A5&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;0&quot; y=&quot;-5056&quot; xlink:href=&quot;#MJSZ4-23A6&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;  
where &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-13-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;30.526ex&quot; height=&quot;3.009ex&quot; style=&quot;vertical-align: -1.005ex;&quot; viewBox=&quot;-38.5 -863.1 13143.1 1295.7&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-70&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(503,-150)&quot;&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use transform=&quot;scale(0.707)&quot; x=&quot;345&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;1417&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;g transform=&quot;translate(2473,0)&quot;&gt;&lt;use xlink:href=&quot;#MJMAIN-50&quot;&gt;&lt;/use&gt;&lt;use x=&quot;681&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-72&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;use x=&quot;3547&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3937&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAINB-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4576&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4966&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5327&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;5994&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7051&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-6A&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7463&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-7C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;7742&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-62&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8171&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-28&quot;&gt;&lt;/use&gt;&lt;use x=&quot;8561&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;9144&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10145&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;10646&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;use x=&quot;11313&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-3D&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12369&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-69&quot;&gt;&lt;/use&gt;&lt;use x=&quot;12715&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; for any &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-14-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;11.193ex&quot; height=&quot;2.509ex&quot; style=&quot;vertical-align: -0.671ex;&quot; viewBox=&quot;0 -791.3 4819.2 1080.4&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;361&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2C&quot;&gt;&lt;/use&gt;&lt;use x=&quot;806&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-74&quot;&gt;&lt;/use&gt;&lt;use x=&quot;1390&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2212&quot;&gt;&lt;/use&gt;&lt;use x=&quot;2391&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-31&quot;&gt;&lt;/use&gt;&lt;use x=&quot;3169&quot; y=&quot;0&quot; xlink:href=&quot;#MJMAIN-2208&quot;&gt;&lt;/use&gt;&lt;use x=&quot;4114&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-54&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt;.  
Under the typical assumption that each row of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-15-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.066ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 889.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; follows a multinomial distribution conditioned on the prior state, then estimates of &lt;span style=&quot;font-size: 100%; display: inline-block;&quot; class=&quot;MathJax_SVG&quot; id=&quot;MathJax-Element-16-Frame&quot;&gt;&lt;svg xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; width=&quot;2.066ex&quot; height=&quot;2.176ex&quot; style=&quot;vertical-align: -0.338ex;&quot; viewBox=&quot;0 -791.3 889.5 936.9&quot; role=&quot;img&quot; focusable=&quot;false&quot;&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;matrix(1 0 0 -1 0 0)&quot;&gt;&lt;use x=&quot;0&quot; y=&quot;0&quot; xlink:href=&quot;#MJMATHI-4B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/span&gt; can be easily be estimated via maximum likelihood.  

&lt;p&gt;&lt;/p&gt;     

&lt;h2&gt; Example &lt;/h2&gt;

&lt;p&gt;The maximum likelihood estimates are simply the observed transitions for each prior state divieded by the total number of observed transitions from the prior state.  To calculate these reatios we need to aggregate the year-to-year transition data from the CDL pixels for Iowa. Note that due to resampling, this may take a considerable amount of time (hours) depending on your system.  To speed things up the &lt;a href=&quot;http://meanmean.me/blog/ag1/Iowa_2008_2015_change.csv&quot;&gt;results&lt;/a&gt; csv is provided through the website.&lt;/p&gt;

&lt;p&gt;Now that you have the data, hopefully from downloading it, we can start working with it:&lt;/p&gt;

&lt;div class=&quot;chunk&quot; id=&quot;unnamed-chunk-1&quot;&gt;&lt;div class=&quot;rcode&quot;&gt;&lt;div class=&quot;source&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(dplyr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(magrittr)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(tidyr)&lt;/span&gt;

&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(devtools)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;install_github&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'jlisic/cdlTools'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(cdlTools)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# read in csv file&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;read.csv&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;&quot;Iowa_2008_2015_change.csv&quot;&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create a major crop type identifier&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# preference is given to corn for corn/soy multiple cropping&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;justSoy&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;setdiff&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(soybeans,corn)&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# Major crop identifier: &lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# 0 non Cultivated&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# 1 other cultivated&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# 2 soybeans (but no dual crop soybeans and corn)&lt;/span&gt;
&lt;span class=&quot;hl com&quot;&gt;# 3 corn&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeFrom&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;In&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cultivated&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeFrom&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;In&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;justSoy&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeFrom&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeFrom&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;In&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;corn&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeFrom&lt;/span&gt;

&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeTo&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Out&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cultivated&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeTo&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Out&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;justSoy&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeTo&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeTo&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;Out&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%in%&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;corn&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;cropTypeTo&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;#create a tidy transition matrix&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;K.tidy&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;cropChange&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;                 &lt;span class=&quot;hl com&quot;&gt;# get data&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(cropTypeTo, cropTypeFrom)&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&quot;hl com&quot;&gt;# group by unique To and From&lt;/span&gt;
  &lt;span class=&quot;hl kwd&quot;&gt;summarize&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl kwc&quot;&gt;totalPixels&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(Pixels))&lt;/span&gt;     &lt;span class=&quot;hl com&quot;&gt;# sum pixels in each group&lt;/span&gt;

&lt;span class=&quot;hl com&quot;&gt;# create the transition matrix K&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;K&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;spread&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(K.tidy,cropTypeTo,totalPixels)&lt;/span&gt; &lt;span class=&quot;hl opt&quot;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;hl num&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl std&quot;&gt;K&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl std&quot;&gt;K&lt;/span&gt;&lt;span class=&quot;hl opt&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;hl kwd&quot;&gt;rowSums&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(K)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;rownames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(K)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;colnames&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(K)&lt;/span&gt; &lt;span class=&quot;hl kwb&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;hl kwd&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'nonCult'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'cult'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'soybeans'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;hl str&quot;&gt;'corn'&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hl kwd&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;hl std&quot;&gt;(K)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;output&quot;&gt;&lt;pre class=&quot;knitr r&quot;&gt;##             nonCult        cult   soybeans       corn
## nonCult  0.81769249 0.019130333 0.06618133 0.09699585
## cult     0.30518990 0.174452328 0.17803400 0.34232377
## soybeans 0.05949642 0.008826269 0.37963993 0.55203739
## corn     0.06057745 0.010194854 0.39156959 0.53765810
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;

Next time, we will compare these results to some federal statistics.

&lt;h2&gt;References&lt;/h2&gt;

&lt;p&gt;

&lt;/p&gt;

&lt;p&gt;Boryan, Claire, et al. &quot;Monitoring US agriculture: the US department of agriculture, national agricultural statistics service, cropland data layer program.&quot; Geocarto International 26.5 (2011): 341-358.&lt;/p&gt;

&lt;p&gt;
Boryan, Claire G., Zhengwei Yang, and Patrick Willis. &quot;US geospatial crop frequency data layers.&quot; Agro-geoinformatics (Agro-geoinformatics 2014), Third International Conference on. IEEE, 2014.
&lt;/p&gt;

&lt;p&gt;
Sahajpal, R., et al. &quot;Generating a Crop Rotation Dataset for the US and its Application in Inferring Land Use Change Induced Wetland Losses in the Prairie Pothole Region.&quot; AGU Fall Meeting Abstracts. Vol. 1. 2013.
&lt;/p&gt;
</description>
        <pubDate>Sun, 24 Jul 2016 00:00:00 -0400</pubDate>
        <link>http://meanmean.me/agriculture/r/2016/07/24/Predicting-Agriculture,-Poorly-(Part-I).html</link>
        <guid isPermaLink="true">http://meanmean.me/agriculture/r/2016/07/24/Predicting-Agriculture,-Poorly-(Part-I).html</guid>
        
        
        <category>Agriculture</category>
        
        <category>R</category>
        
      </item>
    
  </channel>
</rss>
