├── LICENSE ├── README.md ├── environment.yml └── notebooks ├── Part1_Variables.ipynb ├── Part2_ControlStructures.ipynb ├── Part3_Functions_Classes.ipynb ├── Part4_NumericalOperations.ipynb ├── Part5_Pandas.ipynb ├── Part6_LinearAlgebraStatisticalModeling.ipynb ├── Part7_Visualization.ipynb ├── arrest_impulsivity.csv ├── demographics.csv ├── meaningful_variables_clean.csv └── subject_x_items.csv /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Russ Poldrack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PythonForRUsers 2 | 3 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/poldrack/PythonForRUsers/master?filepath=notebooks) 4 | 5 | Notebooks to introduce R users to Python 6 | 7 | *NOTE*: This is a work in progress! 8 | 9 | The ultimate aim is to generate a set of notebooks to help introduce R users to Python for data analysis. Here is the tentative plan: 10 | 11 | 1. [Variables](notebooks/Part1_Variables.ipynb) 12 | 2. [Control structures](notebooks/Part2_ControlStructures.ipynb) 13 | 3. [Functions](notebooks/Part3_Functions.ipynb) 14 | 4. [Numerical operations with Numpy](notebooks/Part4_NumericalOperations.ipynb) 15 | 5. [Data analysis and wrangling using Pandas](notebooks/Part5_Pandas.ipynb) 16 | 6. [Linear algebra and statistical modeling](notebooks/Part6_LinearAlgebraStatisticalModeling.ipynb) 17 | 7. [Data visualization and plotting](notebooks/Part7_Visualization.ipynb) 18 | 8. Working with text 19 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - numpy<1.18 # seaborn breaks on new numpy, so restrict until new release 3 | - pandas 4 | - statsmodels 5 | - matplotlib 6 | - seaborn 7 | - rpy2 8 | - r-dplyr 9 | - r-knitr 10 | - r-readr 11 | - r-tidyr 12 | -------------------------------------------------------------------------------- /notebooks/Part1_Variables.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python for R Users\n", 8 | "# Part 1: Variables\n", 9 | "\n", 10 | "In this notebook we will explore how variables are treated in Python in comparison to R. We will also discuss how to use functions defined in external libraries.\n", 11 | "\n", 12 | "*NOTE*: We are going to assume throughout this tutorial that you are using Python 3. \n", 13 | "\n", 14 | "Resources:\n", 15 | "- http://www.data-analysis-in-python.org/python_for_r.html\n" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "## Using Jupyter\n", 23 | "\n", 24 | "Jupyter is a system for interactive computing, that is similar in spirit to R Notebooks that you may have used with RStudio.\n", 25 | "\n", 26 | "In a Jupyter notebook, the code and text (written in Markdown, just like an RMarkdown file) are placed in separate *cells*. \n", 27 | "A handy feature of Jupyter is that we can use both R and Python within the same notebook. Since this is a native Python notebook, it will assume that any code is written in Python --- if we want to use R then we need to tell it explictly to use R.\n", 28 | "\n", 29 | "The first thing we need to do is to tell Jupyter to load the functions it needs to run R code alongside Python. Jupyter has a number of special commands, which start with a percent sign." 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "%load_ext rpy2.ipython" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "First, let's print \"Hello, world!\" using Python. To execute the code in the following cell, you can hit Shift-Enter." 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 6, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "Hello, world\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "print('Hello, world')" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "You should see the message printed to the screen. Now let's do the same with R. In order to call an R function, we need to use the magic command %%R:" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 8, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/plain": [ 80 | "Hello, world" 81 | ] 82 | }, 83 | "metadata": {}, 84 | "output_type": "display_data" 85 | } 86 | ], 87 | "source": [ 88 | "%%R\n", 89 | "\n", 90 | "cat('Hello, world')" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "## Variables and variable assignment\n", 98 | "\n", 99 | "R allows two different ways to assign values to variabes: ```<-``` and ```=```" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 11, 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "[1] 1\n", 111 | "[1] 2\n" 112 | ] 113 | }, 114 | "metadata": {}, 115 | "output_type": "display_data" 116 | } 117 | ], 118 | "source": [ 119 | "%%R\n", 120 | "\n", 121 | "a <- 1\n", 122 | "print(a)\n", 123 | "\n", 124 | "b = 2\n", 125 | "print(b)" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "In Python, there is only one way to assign a value to a variable: **=**" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 12, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "name": "stdout", 142 | "output_type": "stream", 143 | "text": [ 144 | "1\n" 145 | ] 146 | } 147 | ], 148 | "source": [ 149 | "a = 1\n", 150 | "print(a)" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "There is also an important difference under the hood in how Python treats variables compared to R. First let's see it in action, and then explain it. " 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 30, 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "data": { 167 | "text/plain": [ 168 | "[1] 1 2 3\n" 169 | ] 170 | }, 171 | "metadata": {}, 172 | "output_type": "display_data" 173 | } 174 | ], 175 | "source": [ 176 | "%%R\n", 177 | "\n", 178 | "a <- c(1, 2, 3) # create a variable\n", 179 | "\n", 180 | "b <- a # assign it to a new variable\n", 181 | "\n", 182 | "b[4] = 4 # add an entry to the new variable\n", 183 | "\n", 184 | "print(a)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 31, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "[1, 2, 3, 4]\n" 197 | ] 198 | } 199 | ], 200 | "source": [ 201 | "a = [1, 2, 3] # create a variable\n", 202 | "b = a # assign it to a new variable\n", 203 | "b.append(4) # add an entry to the new variable\n", 204 | "\n", 205 | "print(a)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "metadata": {}, 211 | "source": [ 212 | "What is happening here is that when you use ```b <- a``` in R, it automatically makes a new copy of the variable, so that any changes in the new variable don't affect the original one. \n", 213 | "\n", 214 | "R's behavior is different from most general-purpose programming languages, in which a variable is treated as a pointer to a place in memory. Thus, when we say ```b = a``` in Python, these two variables become pointers to the same place in memory. Thus, anything that we do to one will affect the other as well. There are certain types of variables in Python where this doesn't happen, which are called *immutable* variables --- these include character strings, single numbers, and a type of variable called a *tuple* that you will learn about later.\n", 215 | "\n", 216 | "If we want Python to create a copy of a variable (so that changes to the new variable will not affect changes to the old one), we need to use the ```copy()``` operator:" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 33, 222 | "metadata": {}, 223 | "outputs": [ 224 | { 225 | "name": "stdout", 226 | "output_type": "stream", 227 | "text": [ 228 | "a: [1, 2, 3]\n", 229 | "b: [1, 2, 3, 4]\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "a = [1, 2, 3]\n", 235 | "b = a.copy()\n", 236 | "b.append(4)\n", 237 | "print('a:', a)\n", 238 | "print('b:', b)" 239 | ] 240 | }, 241 | { 242 | "cell_type": "markdown", 243 | "metadata": {}, 244 | "source": [ 245 | "The operator notation may be a bit confusing - what's with the dot? It turns out that every variable in Python has various functions or other variables associated with it, and those are accessible using the dot. This means that unlike R, the dot is special, and you can't create regular variable names with a dot in them. We can see all of the functions and variables associated with a particular object using the ```dir()``` command." 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 36, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "['__add__',\n", 257 | " '__class__',\n", 258 | " '__contains__',\n", 259 | " '__delattr__',\n", 260 | " '__delitem__',\n", 261 | " '__dir__',\n", 262 | " '__doc__',\n", 263 | " '__eq__',\n", 264 | " '__format__',\n", 265 | " '__ge__',\n", 266 | " '__getattribute__',\n", 267 | " '__getitem__',\n", 268 | " '__gt__',\n", 269 | " '__hash__',\n", 270 | " '__iadd__',\n", 271 | " '__imul__',\n", 272 | " '__init__',\n", 273 | " '__init_subclass__',\n", 274 | " '__iter__',\n", 275 | " '__le__',\n", 276 | " '__len__',\n", 277 | " '__lt__',\n", 278 | " '__mul__',\n", 279 | " '__ne__',\n", 280 | " '__new__',\n", 281 | " '__reduce__',\n", 282 | " '__reduce_ex__',\n", 283 | " '__repr__',\n", 284 | " '__reversed__',\n", 285 | " '__rmul__',\n", 286 | " '__setattr__',\n", 287 | " '__setitem__',\n", 288 | " '__sizeof__',\n", 289 | " '__str__',\n", 290 | " '__subclasshook__',\n", 291 | " 'append',\n", 292 | " 'clear',\n", 293 | " 'copy',\n", 294 | " 'count',\n", 295 | " 'extend',\n", 296 | " 'index',\n", 297 | " 'insert',\n", 298 | " 'pop',\n", 299 | " 'remove',\n", 300 | " 'reverse',\n", 301 | " 'sort']" 302 | ] 303 | }, 304 | "execution_count": 36, 305 | "metadata": {}, 306 | "output_type": "execute_result" 307 | } 308 | ], 309 | "source": [ 310 | "dir(a)" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "metadata": {}, 316 | "source": [ 317 | "You can see that this variable, which is a type of variable called a *list* in Python, has a bunch of different operators associated with it. If you want to know what one of them does, you can place a question mark in front of it to get its help text:" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 38, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "data": { 327 | "text/plain": [ 328 | "\u001b[0;31mDocstring:\u001b[0m L.count(value) -> integer -- return number of occurrences of value\n", 329 | "\u001b[0;31mType:\u001b[0m builtin_function_or_method\n" 330 | ] 331 | }, 332 | "metadata": {}, 333 | "output_type": "display_data" 334 | } 335 | ], 336 | "source": [ 337 | "?a.count" 338 | ] 339 | }, 340 | { 341 | "cell_type": "markdown", 342 | "metadata": {}, 343 | "source": [ 344 | "This tells us that ```a.count()``` should output the number of occurrences of a particular value, which we have to enter as an argument to the function. Let's see if it works - how many times does the number 1 occur in the list:\n" 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": 43, 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "name": "stdout", 354 | "output_type": "stream", 355 | "text": [ 356 | "1\n" 357 | ] 358 | } 359 | ], 360 | "source": [ 361 | "print(a.count(1))" 362 | ] 363 | }, 364 | { 365 | "cell_type": "markdown", 366 | "metadata": {}, 367 | "source": [ 368 | "## Types of variables\n", 369 | "\n", 370 | "From R you will be familiar with a number of different types of variables, such as *integer*, *double*, and *character*, as well as more complex types of variables such as *vectors* or *lists*. Python has its own set of variable types, some of which overlap with R's but others of which are very different." 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": 46, 376 | "metadata": {}, 377 | "outputs": [ 378 | { 379 | "data": { 380 | "text/plain": [ 381 | "float" 382 | ] 383 | }, 384 | "execution_count": 46, 385 | "metadata": {}, 386 | "output_type": "execute_result" 387 | } 388 | ], 389 | "source": [ 390 | "type(1.)" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": null, 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [] 399 | }, 400 | { 401 | "cell_type": "markdown", 402 | "metadata": {}, 403 | "source": [ 404 | "### Lists in Python\n", 405 | "\n", 406 | "The concept of a *list* in Python is different from the concept of a *list* in R. In Python, a list is more like a vector that you would generate using the ```c()``` function in R. Let's see this in action." 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": 48, 412 | "metadata": {}, 413 | "outputs": [ 414 | { 415 | "name": "stdout", 416 | "output_type": "stream", 417 | "text": [ 418 | "[1, 2, 3, 4]\n" 419 | ] 420 | } 421 | ], 422 | "source": [ 423 | "my_list = [1, 2, 3, 4]\n", 424 | "print(my_list)" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": 51, 430 | "metadata": {}, 431 | "outputs": [ 432 | { 433 | "data": { 434 | "text/plain": [ 435 | "[1] 1 2 3 4\n" 436 | ] 437 | }, 438 | "metadata": {}, 439 | "output_type": "display_data" 440 | } 441 | ], 442 | "source": [ 443 | "%%R\n", 444 | "\n", 445 | "my_vector <- c(1, 2, 3, 4)\n", 446 | "print(my_vector)" 447 | ] 448 | }, 449 | { 450 | "cell_type": "markdown", 451 | "metadata": {}, 452 | "source": [ 453 | "Here we run into what is perhaps the most annoying difference between R and Python. In R, we would access the vector members using their position numbers, starting with 1:" 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": 52, 459 | "metadata": {}, 460 | "outputs": [ 461 | { 462 | "data": { 463 | "text/plain": [ 464 | "[1] 1\n" 465 | ] 466 | }, 467 | "metadata": {}, 468 | "output_type": "display_data" 469 | } 470 | ], 471 | "source": [ 472 | "%%R\n", 473 | "\n", 474 | "print(my_vector[1])" 475 | ] 476 | }, 477 | { 478 | "cell_type": "markdown", 479 | "metadata": {}, 480 | "source": [ 481 | "However, in Python we index the entries starting with zero:" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 53, 487 | "metadata": {}, 488 | "outputs": [ 489 | { 490 | "name": "stdout", 491 | "output_type": "stream", 492 | "text": [ 493 | "1\n" 494 | ] 495 | } 496 | ], 497 | "source": [ 498 | "print(my_list[0])" 499 | ] 500 | }, 501 | { 502 | "cell_type": "markdown", 503 | "metadata": {}, 504 | "source": [ 505 | "This might seem weird, but it is actually the way that most general-purpose programming languages perform indexing, and there are good theorietical reasons for it. For example, see discussion here: https://developeronline.blogspot.com/2008/04/why-array-index-should-start-from-0.html\n", 506 | "\n", 507 | "Another difference between Python and R has to do with their treatment of vectors with different types of objects. R doesn't allow this, and if you try to create one it will convert the elements to a single type:" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": 57, 513 | "metadata": {}, 514 | "outputs": [ 515 | { 516 | "data": { 517 | "text/plain": [ 518 | "[1] \"1\" \"b\"\n" 519 | ] 520 | }, 521 | "metadata": {}, 522 | "output_type": "display_data" 523 | } 524 | ], 525 | "source": [ 526 | "%%R\n", 527 | "\n", 528 | "foo <- c(1, 'b')\n", 529 | "print(foo)\n" 530 | ] 531 | }, 532 | { 533 | "cell_type": "markdown", 534 | "metadata": {}, 535 | "source": [ 536 | "In this case, R converts the elements to a type that can accomomodate all of them, which in this case is a character string. Python, on the other hand, has no problem with lists containing different types of objects:" 537 | ] 538 | }, 539 | { 540 | "cell_type": "code", 541 | "execution_count": 58, 542 | "metadata": {}, 543 | "outputs": [ 544 | { 545 | "name": "stdout", 546 | "output_type": "stream", 547 | "text": [ 548 | "[1, 'b']\n" 549 | ] 550 | } 551 | ], 552 | "source": [ 553 | "foo = [1, 'b']\n", 554 | "print(foo)" 555 | ] 556 | }, 557 | { 558 | "cell_type": "markdown", 559 | "metadata": {}, 560 | "source": [ 561 | "We will have more to say about indexing when we come to the discussion of numerical analysis in a later notebook." 562 | ] 563 | }, 564 | { 565 | "cell_type": "markdown", 566 | "metadata": {}, 567 | "source": [ 568 | "### Dictionaries in Python\n", 569 | "\n", 570 | "In R there is a type of object known as a *list*, can serve as a container for different types of variables. In Python, the analogous object is known as a *dictionary*.\n", 571 | "\n", 572 | "Let's look at this in R first. We can use the str() function in R to give us a nice printout of the list." 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": 20, 578 | "metadata": {}, 579 | "outputs": [ 580 | { 581 | "data": { 582 | "text/plain": [ 583 | "List of 3\n", 584 | " $ info: chr \"my list\"\n", 585 | " $ n : num 3\n", 586 | " $ l : chr [1:4] \"1\" \"2\" \"c\" \"d\"\n" 587 | ] 588 | }, 589 | "metadata": {}, 590 | "output_type": "display_data" 591 | } 592 | ], 593 | "source": [ 594 | "%%R\n", 595 | "\n", 596 | "my_list <- list(info = 'my list', n = 3, l = c(1, 2, 'c', 'd'))\n", 597 | "str(my_list)" 598 | ] 599 | }, 600 | { 601 | "cell_type": "markdown", 602 | "metadata": {}, 603 | "source": [ 604 | "To access the individual items, we would use the dollar sign notation:" 605 | ] 606 | }, 607 | { 608 | "cell_type": "code", 609 | "execution_count": 19, 610 | "metadata": {}, 611 | "outputs": [ 612 | { 613 | "data": { 614 | "text/plain": [ 615 | "[1] \"my list\"\n", 616 | "[1] \"c\"\n" 617 | ] 618 | }, 619 | "metadata": {}, 620 | "output_type": "display_data" 621 | } 622 | ], 623 | "source": [ 624 | "%%R\n", 625 | "\n", 626 | "print(my_list$info)\n", 627 | "print(my_list$l[3])\n" 628 | ] 629 | }, 630 | { 631 | "cell_type": "markdown", 632 | "metadata": {}, 633 | "source": [ 634 | "In Python, we can do the analogous job by creating a dictionary, either using the ```dict()``` function, or more often using end brackets. The brackets contain a set of pairs separated by a colon, where the first element is the name of the field and the second element is the value that it takes." 635 | ] 636 | }, 637 | { 638 | "cell_type": "code", 639 | "execution_count": 24, 640 | "metadata": {}, 641 | "outputs": [ 642 | { 643 | "name": "stdout", 644 | "output_type": "stream", 645 | "text": [ 646 | "{'info': 'my list', 'n': 3, 'l': [1, 2, 'c', 'd']}\n" 647 | ] 648 | } 649 | ], 650 | "source": [ 651 | "my_dict = {'info': 'my list',\n", 652 | " 'n': 3,\n", 653 | " 'l': [1, 2, 'c', 'd']}\n", 654 | "print(my_dict)" 655 | ] 656 | }, 657 | { 658 | "cell_type": "markdown", 659 | "metadata": {}, 660 | "source": [ 661 | "To access the elements, we use the names of each field as an index" 662 | ] 663 | }, 664 | { 665 | "cell_type": "code", 666 | "execution_count": 25, 667 | "metadata": {}, 668 | "outputs": [ 669 | { 670 | "name": "stdout", 671 | "output_type": "stream", 672 | "text": [ 673 | "my list\n", 674 | "c\n" 675 | ] 676 | } 677 | ], 678 | "source": [ 679 | "print(my_dict['info'])\n", 680 | "print(my_dict['l'][2])" 681 | ] 682 | }, 683 | { 684 | "cell_type": "markdown", 685 | "metadata": {}, 686 | "source": [ 687 | "## Sets in Python and R\n", 688 | "\n", 689 | "A set is a list of unique items - that is, no items are duplicated. In R, we would generate a set using the ```unique()``` function and then use the standard set operators:" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": 35, 695 | "metadata": {}, 696 | "outputs": [ 697 | { 698 | "data": { 699 | "text/plain": [ 700 | "[1] 1 2 3 4\n", 701 | "[1] FALSE\n", 702 | "[1] 1 2 3 4 5 6 7\n", 703 | "[1] 4\n", 704 | "[1] 1 2 3\n" 705 | ] 706 | }, 707 | "metadata": {}, 708 | "output_type": "display_data" 709 | } 710 | ], 711 | "source": [ 712 | "%%R\n", 713 | "\n", 714 | "a = c(1, 1, 2, 2, 3, 3, 4, 4)\n", 715 | "s = unique(a)\n", 716 | "print(s)\n", 717 | "\n", 718 | "# is the number 5 in the set?\n", 719 | "print(5 %in% s)\n", 720 | "\n", 721 | "# create another set and apply set theoretic operators\n", 722 | "t = c(4, 5, 6, 7)\n", 723 | "\n", 724 | "print(union(s, t)) # set union\n", 725 | "print(intersect(s, t)) # set intersection\n", 726 | "print(setdiff(s, t)) # set difference" 727 | ] 728 | }, 729 | { 730 | "cell_type": "markdown", 731 | "metadata": {}, 732 | "source": [ 733 | "Whereas R doesn't have a special data type for sets, Python does. One nice feature of this is that a set has associated functions that we can use to perform set theoretic operations:" 734 | ] 735 | }, 736 | { 737 | "cell_type": "code", 738 | "execution_count": 40, 739 | "metadata": {}, 740 | "outputs": [ 741 | { 742 | "name": "stdout", 743 | "output_type": "stream", 744 | "text": [ 745 | "{1, 2, 3, 4}\n", 746 | "False\n", 747 | "{1, 2, 3, 4, 5, 6, 7}\n", 748 | "{4}\n", 749 | "{1, 2, 3}\n" 750 | ] 751 | } 752 | ], 753 | "source": [ 754 | "a = [1, 1, 2, 2, 3, 3, 4, 4]\n", 755 | "s = set(a) # convert the list into a set\n", 756 | "print(s) # note the squiggly brackets versus the square brackets for a\n", 757 | "\n", 758 | "# is the number 5 in the set?\n", 759 | "print(5 in s)\n", 760 | "\n", 761 | "# create another set and apply set theoretic operators\n", 762 | "t = [4, 5, 6, 7]\n", 763 | "\n", 764 | "print(s.union(t)) # set union\n", 765 | "print(s.intersection(t)) # set intersection\n", 766 | "print(s.difference(t)) # set difference" 767 | ] 768 | }, 769 | { 770 | "cell_type": "markdown", 771 | "metadata": {}, 772 | "source": [ 773 | "## Importing library functions in Python and R\n", 774 | "\n", 775 | "So far we have gotten by using only functions that are built into the base R and Python environments. However, we often want to use functions that are contained in *libraries*. For example, in R we might want to load the *knitr* library in order to print out our structure as a table. We would do this using the ```library()``` function:" 776 | ] 777 | }, 778 | { 779 | "cell_type": "code", 780 | "execution_count": 23, 781 | "metadata": {}, 782 | "outputs": [ 783 | { 784 | "data": { 785 | "text/plain": [ 786 | "\n", 787 | "\n", 788 | "|x |\n", 789 | "|:-------|\n", 790 | "|my list |\n", 791 | "\n", 792 | "| x|\n", 793 | "|--:|\n", 794 | "| 3|\n", 795 | "\n", 796 | "|x |\n", 797 | "|:--|\n", 798 | "|1 |\n", 799 | "|2 |\n", 800 | "|c |\n", 801 | "|d |\n" 802 | ] 803 | }, 804 | "metadata": {}, 805 | "output_type": "display_data" 806 | } 807 | ], 808 | "source": [ 809 | "%%R\n", 810 | "\n", 811 | "library(knitr)\n", 812 | "kable(my_list)" 813 | ] 814 | }, 815 | { 816 | "cell_type": "markdown", 817 | "metadata": {}, 818 | "source": [ 819 | "This provides us with access to the ```kable()``` function from within the *knitr* library, but there is something concerning here: Unless we knew explicitly that ```kable()``` was defined within that library, it would not be immediately apparent where that function was coming from. This gets even worse when libraries redefine functions, which can sometimes interfere with their expected operation. \n", 820 | "\n", 821 | "Python provides a much cleaner way to import functions from libraries. Let's say that we want to import the ```pprint()``` function from the *pprint* library, which can give us a pretty printout of our dictionary. We do this using the ```import``` statement. There are two ways to go about this. One is to import the library as a whole, and then refer explicitly to the function as part of the library:" 822 | ] 823 | }, 824 | { 825 | "cell_type": "code", 826 | "execution_count": 26, 827 | "metadata": {}, 828 | "outputs": [ 829 | { 830 | "name": "stdout", 831 | "output_type": "stream", 832 | "text": [ 833 | "{'info': 'my list', 'l': [1, 2, 'c', 'd'], 'n': 3}\n" 834 | ] 835 | } 836 | ], 837 | "source": [ 838 | "import pprint\n", 839 | "pprint.pprint(my_dict)" 840 | ] 841 | }, 842 | { 843 | "cell_type": "markdown", 844 | "metadata": {}, 845 | "source": [ 846 | "Another alternative is to import the function from the library, and then refer to it directly:" 847 | ] 848 | }, 849 | { 850 | "cell_type": "code", 851 | "execution_count": 27, 852 | "metadata": {}, 853 | "outputs": [ 854 | { 855 | "name": "stdout", 856 | "output_type": "stream", 857 | "text": [ 858 | "{'info': 'my list', 'l': [1, 2, 'c', 'd'], 'n': 3}\n" 859 | ] 860 | } 861 | ], 862 | "source": [ 863 | "from pprint import pprint\n", 864 | "pprint(my_dict)" 865 | ] 866 | }, 867 | { 868 | "cell_type": "markdown", 869 | "metadata": {}, 870 | "source": [ 871 | "I generally prefer the former since it is clearer where the function is coming from, but sometimes it can get a bit unwieldy if the functions are defined deep within a library (as we will see later).\n", 872 | "\n", 873 | "It is possible to import all functions from a library, using ```from import *```. However, **you should never do this**. It is bad form because then you have no idea where a particular function is coming from.\n", 874 | "\n", 875 | "Unlike R, for Python there is an official set of recommendations regarding programming style. You can find it at https://www.python.org/dev/peps/pep-0008/. Learning good style from the beginning will make your code much more readable - both for others, and for your future self!" 876 | ] 877 | }, 878 | { 879 | "cell_type": "code", 880 | "execution_count": null, 881 | "metadata": {}, 882 | "outputs": [], 883 | "source": [] 884 | }, 885 | { 886 | "cell_type": "code", 887 | "execution_count": null, 888 | "metadata": {}, 889 | "outputs": [], 890 | "source": [] 891 | } 892 | ], 893 | "metadata": { 894 | "kernelspec": { 895 | "display_name": "Python 3", 896 | "language": "python", 897 | "name": "python3" 898 | }, 899 | "language_info": { 900 | "codemirror_mode": { 901 | "name": "ipython", 902 | "version": 3 903 | }, 904 | "file_extension": ".py", 905 | "mimetype": "text/x-python", 906 | "name": "python", 907 | "nbconvert_exporter": "python", 908 | "pygments_lexer": "ipython3", 909 | "version": "3.6.8" 910 | } 911 | }, 912 | "nbformat": 4, 913 | "nbformat_minor": 2 914 | } 915 | -------------------------------------------------------------------------------- /notebooks/Part2_ControlStructures.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python for R users\n", 8 | "# Part 2: Control structures\n", 9 | "\n", 10 | "In this notebook we will explore how R and Python differ in the syntax of control structures like loops or if/then statements. \n", 11 | "\n", 12 | "First we need to tell Jupyter to let us use R within this Python notebook." 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 2, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "%load_ext rpy2.ipython\n", 22 | "\n", 23 | "from pprint import pprint" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "## Loops\n", 31 | "\n", 32 | "We generally want to avoid loops whenever possible (as we will see later when we are talking about numerical analysis), but sometimes we can't. Loops in Python are structurally very similar to those in R, but the syntax differs quite a bit. Let's say that we want to loop over integers from 1 to 3 and print them out. In R we would do it as follows:" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "[1] 1\n", 45 | "[1] 2\n", 46 | "[1] 3\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "%%R\n", 52 | "\n", 53 | "for (j in 1:3){\n", 54 | " print(j)\n", 55 | "}" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "Notice that in R, the contents of the loop are demarcated by brackets.\n", 63 | "\n", 64 | "The equivalent loop in Python would look like this:" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 4, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stdout", 74 | "output_type": "stream", 75 | "text": [ 76 | "1\n", 77 | "2\n", 78 | "3\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "for j in range(1,4):\n", 84 | " print(j)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "There is one thing here that is new for us, and is another fundamental difference between Python and R. The contents of the loop in Python are denoted by their *indentation*! The fact that white space makes a difference in Python syntax is probably one of the most controversial aspects of Python coding. If the spacing doesn't match exactly, then the code will fail. Try running the next cell after removing the comment symbol (#) from the third line:" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 6, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "ename": "IndentationError", 101 | "evalue": "unexpected indent (, line 3)", 102 | "output_type": "error", 103 | "traceback": [ 104 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m print(j+1)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unexpected indent\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "for j in range(1,4):\n", 110 | " print(j)\n", 111 | "# print(j+1)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "You should see an error message telling you that there is an unexpected indentation. Python expects all of lines with a loop to have exactly the same indentation. This can get a bit tricky if you mix code that uses tabs for indentation and code that uses spaces. In general, indentation by 4 spaces is preferred.\n", 119 | "\n" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "There is another new thing that we see here: the ```range()``` function. This function generates a series of numbers within a particular range, similar to the ```seq()``` function in R except that it starts at zero and steps by 1 at a time until it *almost* reaches the specified number. Here is a simple example:" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 7, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "name": "stdout", 136 | "output_type": "stream", 137 | "text": [ 138 | "0\n", 139 | "1\n", 140 | "2\n", 141 | "3\n" 142 | ] 143 | } 144 | ], 145 | "source": [ 146 | "for j in range(4):\n", 147 | " print(j)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "Notice that the series is as long as the specified number (i.e. 4 digits), but it stops before it gets to the limit. Just like ```seq()```, you can also specify a step size for the sequence:" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 9, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "name": "stdout", 164 | "output_type": "stream", 165 | "text": [ 166 | "0\n", 167 | "2\n", 168 | "4\n", 169 | "6\n" 170 | ] 171 | } 172 | ], 173 | "source": [ 174 | "for j in range(0, 8, 2):\n", 175 | " print(j)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "One limitation is that range() only works for integer step sizes. Later we will encounter a function within the numpy package that can give us more flexible step sizes. But if we are simply looping through for a specific number of times, we would generally use ```range()```.\n", 183 | "\n", 184 | "The ```range()``` function also exhibits a behavior that you will not have experienced in R. Let's say you want to create a new variable that contains a sequence of integers from 1 to 5. In R you could do this using the ```seq()``` command:" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 10, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "[1] 1 2 3 4 5\n" 197 | ] 198 | } 199 | ], 200 | "source": [ 201 | "%%R\n", 202 | "\n", 203 | "my_var <- seq(1,5)\n", 204 | "print(my_var)" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "However, if we try to do this using the ```range()``` command, the result is not what we expect:" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 11, 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "range(0, 5)\n" 224 | ] 225 | } 226 | ], 227 | "source": [ 228 | "my_var = range(5)\n", 229 | "print(my_var)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "You probably expected this command to output a set of values, but instead it prints out what looks like a function. That's because the ```range()``` function is a special type of Python function known as a *generator*, which is meant to generate a sequence. You don't need to know how generators work under the hood (though if you do, you can read more [here](https://wiki.python.org/moin/Generators)), but you should be aware that you can't simply use them to define a new variable --- they have to be part of a loop. " 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": {}, 242 | "source": [ 243 | "## List comprehensions\n", 244 | "\n", 245 | "One way to easily obtain a new variable from a generator is to use a special Python construction called a *list comprehension*. Going back to our previous problem of generating a list that ranges from 1 to 5, we could create a for loop to do this:" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 14, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "name": "stdout", 255 | "output_type": "stream", 256 | "text": [ 257 | "[1, 2, 3, 4, 5]\n" 258 | ] 259 | } 260 | ], 261 | "source": [ 262 | "my_var = [] # create an empty list\n", 263 | "for j in range(1, 6):\n", 264 | " my_var.append(j) # append the value to the list\n", 265 | "\n", 266 | "print(my_var)" 267 | ] 268 | }, 269 | { 270 | "cell_type": "markdown", 271 | "metadata": {}, 272 | "source": [ 273 | "However, this is a lot of code to generate such a simple variable. A list comprehension allows us to embed this entire loop within a single command:" 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": 15, 279 | "metadata": {}, 280 | "outputs": [ 281 | { 282 | "name": "stdout", 283 | "output_type": "stream", 284 | "text": [ 285 | "[1, 2, 3, 4, 5]\n" 286 | ] 287 | } 288 | ], 289 | "source": [ 290 | "my_var = [j for j in range(1, 6)]\n", 291 | "\n", 292 | "print(my_var)" 293 | ] 294 | }, 295 | { 296 | "cell_type": "markdown", 297 | "metadata": {}, 298 | "source": [ 299 | "One useful thing that this allows us to do is to transform the numbers being generated by our generator (in this case ```range()```).\n", 300 | "\n", 301 | "Let's say that we wanted to create a series of powers of 2, from 2^0 to 2^5. We could do this easily using a list comprehension, by simply raising the initial value ```i``` to the power of 2:" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 16, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "[1, 2, 4, 8, 16, 32]\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "power_series = [2**j for j in range(0, 6)]\n", 319 | "print(power_series)" 320 | ] 321 | }, 322 | { 323 | "cell_type": "markdown", 324 | "metadata": {}, 325 | "source": [ 326 | "## Nested Loops\n", 327 | "\n", 328 | "We can also easily nest loops within one another, using additional indentation for each level of the loop. For example, let's say we want to loop through for integers from 1 to 9 and create a dictionary that contains a list of that value when raised to powers from zero to five." 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 17, 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "name": "stdout", 338 | "output_type": "stream", 339 | "text": [ 340 | "{1: [1, 1, 1, 1, 1, 1],\n", 341 | " 2: [1, 2, 4, 8, 16, 32],\n", 342 | " 3: [1, 3, 9, 27, 81, 243],\n", 343 | " 4: [1, 4, 16, 64, 256, 1024],\n", 344 | " 5: [1, 5, 25, 125, 625, 3125],\n", 345 | " 6: [1, 6, 36, 216, 1296, 7776],\n", 346 | " 7: [1, 7, 49, 343, 2401, 16807],\n", 347 | " 8: [1, 8, 64, 512, 4096, 32768],\n", 348 | " 9: [1, 9, 81, 729, 6561, 59049]}\n" 349 | ] 350 | } 351 | ], 352 | "source": [ 353 | "power_dict = {} # create empty dictionary to store our results\n", 354 | "\n", 355 | "for j in range(1, 10): ## loop through integers 1-9\n", 356 | " power_dict[j] = [] # create an empty list to store the results for this integer\n", 357 | " for k in range(0, 6):\n", 358 | " power_dict[j].append(j**k)\n", 359 | " \n", 360 | "pprint(power_dict) ## pretty print the dict" 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "metadata": {}, 366 | "source": [ 367 | "## While loops\n", 368 | "\n", 369 | "While loops in Python are very similar to those in R, except for the surface syntax:" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 19, 375 | "metadata": {}, 376 | "outputs": [ 377 | { 378 | "name": "stdout", 379 | "output_type": "stream", 380 | "text": [ 381 | "[1] 1\n", 382 | "[1] 2\n", 383 | "[1] 3\n", 384 | "[1] 4\n", 385 | "[1] 5\n" 386 | ] 387 | } 388 | ], 389 | "source": [ 390 | "%%R\n", 391 | "\n", 392 | "j <- 1\n", 393 | "while (j < 6){\n", 394 | " print(j)\n", 395 | " j <- j + 1\n", 396 | "}" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 20, 402 | "metadata": {}, 403 | "outputs": [ 404 | { 405 | "name": "stdout", 406 | "output_type": "stream", 407 | "text": [ 408 | "1\n", 409 | "2\n", 410 | "3\n", 411 | "4\n", 412 | "5\n" 413 | ] 414 | } 415 | ], 416 | "source": [ 417 | "j = 1\n", 418 | "while j < 6:\n", 419 | " print(j)\n", 420 | " j += 1\n", 421 | " " 422 | ] 423 | }, 424 | { 425 | "cell_type": "markdown", 426 | "metadata": {}, 427 | "source": [ 428 | "Note that we used a special operator, ```+=``` which is shorthand for \"add the value on the right side to the existing variable on the left side\"." 429 | ] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "metadata": {}, 434 | "source": [ 435 | "## If/then statement\n", 436 | "\n", 437 | "If/then statements are also fairly similar between R and Python. Let's say we want to loop through all numbers from 1 to 10 and print whether they are odd or even. Here is how we would do that in R:" 438 | ] 439 | }, 440 | { 441 | "cell_type": "code", 442 | "execution_count": 21, 443 | "metadata": {}, 444 | "outputs": [ 445 | { 446 | "name": "stdout", 447 | "output_type": "stream", 448 | "text": [ 449 | "[1] \"1: odd\"\n", 450 | "[1] \"2: even\"\n", 451 | "[1] \"3: odd\"\n", 452 | "[1] \"4: even\"\n", 453 | "[1] \"5: odd\"\n", 454 | "[1] \"6: even\"\n", 455 | "[1] \"7: odd\"\n", 456 | "[1] \"8: even\"\n", 457 | "[1] \"9: odd\"\n", 458 | "[1] \"10: even\"\n" 459 | ] 460 | } 461 | ], 462 | "source": [ 463 | "%%R\n", 464 | "\n", 465 | "for (j in 1:10){\n", 466 | " # use the modulus operator to see if the remainder from 2 is zero\n", 467 | " if (!(j %% 2)) {\n", 468 | " print(sprintf('%d: even', j))\n", 469 | " } else {\n", 470 | " print(sprintf('%d: odd', j))\n", 471 | " \n", 472 | " }\n", 473 | "}" 474 | ] 475 | }, 476 | { 477 | "cell_type": "markdown", 478 | "metadata": {}, 479 | "source": [ 480 | "The analogous code in Python looks fairly similar:" 481 | ] 482 | }, 483 | { 484 | "cell_type": "code", 485 | "execution_count": 22, 486 | "metadata": {}, 487 | "outputs": [ 488 | { 489 | "name": "stdout", 490 | "output_type": "stream", 491 | "text": [ 492 | "1 odd\n", 493 | "2 even\n", 494 | "3 odd\n", 495 | "4 even\n", 496 | "5 odd\n", 497 | "6 even\n", 498 | "7 odd\n", 499 | "8 even\n", 500 | "9 odd\n", 501 | "10 even\n" 502 | ] 503 | } 504 | ], 505 | "source": [ 506 | "for j in range(1, 11):\n", 507 | " if not j % 2:\n", 508 | " print(j, 'even', )\n", 509 | " else:\n", 510 | " print(j, 'odd')" 511 | ] 512 | }, 513 | { 514 | "cell_type": "markdown", 515 | "metadata": {}, 516 | "source": [ 517 | "Note a few small syntactic differences. Most importantly, again here the structure of the statement in Python relies upon indentation. Second, instead of using the ```!``` operator to signify negation in R, in Python we can simply use ```not```. Also note that the modulus operator is ```%``` in Python versus ```%%``` in R." 518 | ] 519 | } 520 | ], 521 | "metadata": { 522 | "kernelspec": { 523 | "display_name": "Python 3", 524 | "language": "python", 525 | "name": "python3" 526 | }, 527 | "language_info": { 528 | "codemirror_mode": { 529 | "name": "ipython", 530 | "version": 3 531 | }, 532 | "file_extension": ".py", 533 | "mimetype": "text/x-python", 534 | "name": "python", 535 | "nbconvert_exporter": "python", 536 | "pygments_lexer": "ipython3", 537 | "version": "3.6.7" 538 | } 539 | }, 540 | "nbformat": 4, 541 | "nbformat_minor": 4 542 | } 543 | -------------------------------------------------------------------------------- /notebooks/Part3_Functions_Classes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python for R users\n", 8 | "# Part 3: Functions\n", 9 | "\n", 10 | "In this notebook we will explore how R and Python differ in the creation and usage of functions.\n", 11 | "\n", 12 | "First, a general note: Whenever you find yourself doing something more than once, you should put the relevant code inside a function and call that function instead. Then you can reuse that code whenever you need it in the future. This in keeping with the general software engineering philsophy known as \"Don't Repeat Yourself\" (DRY). It's also good practice to keep these organized in a central place so that you can always find them --- we will come back to that later. \n", 13 | "\n", 14 | "First we need to tell Jupyter to let us use R within this Python notebook." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 6, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "The rpy2.ipython extension is already loaded. To reload it, use:\n", 27 | " %reload_ext rpy2.ipython\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "%load_ext rpy2.ipython" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "## Creating a function\n", 40 | "\n", 41 | "Let's say that we want to create our own function that divides two numbers but returns NaN (\"not a number\") if one tries to divide by zero. Here is how we would define this function in R. " 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 7, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "data": { 51 | "text/plain": [ 52 | "[1] NaN\n" 53 | ] 54 | }, 55 | "metadata": {}, 56 | "output_type": "display_data" 57 | } 58 | ], 59 | "source": [ 60 | "%%R\n", 61 | "\n", 62 | "my_divide <- function(i, j){\n", 63 | " if (j == 0){\n", 64 | " return(NaN)\n", 65 | " } else {\n", 66 | " return(i/j)\n", 67 | " }\n", 68 | "}\n", 69 | "\n", 70 | "my_divide(1,0)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "Now let's write the analogous function in Python. First, we need to import the math library where nan is defined, then we can define the function. Note that it's generally good practice to put all of the imports at the top of the file, but we will leave it here for clarity." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "import math" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 13, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "data": { 96 | "text/plain": [ 97 | "nan" 98 | ] 99 | }, 100 | "execution_count": 13, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "def my_divide(i, j):\n", 107 | " if j == 0:\n", 108 | " return(math.nan)\n", 109 | " else:\n", 110 | " return(i / j)\n", 111 | " \n", 112 | "my_divide(1, 0)" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "#### Catching exceptions using try/catch\n", 120 | "\n", 121 | "One of the coding philosophies of Python is that it's easier to ask for forgiveness than permission (summarized as *EAFP*). This means that rather than checking for various conditions, we should assume that everything will work as intended (e.g. files will exist, operations will work) but be prepared to deal with the errors that can occur. In Python, when an error occurs it results in an *exception* being raised. For example, let's see what happens if we try to divide by zero:" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 1, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "ename": "ZeroDivisionError", 131 | "evalue": "division by zero", 132 | "output_type": "error", 133 | "traceback": [ 134 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 135 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 136 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 137 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 138 | ] 139 | } 140 | ], 141 | "source": [ 142 | "1/0" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "This results in a \"ZeroDvisionError\" exception being raised. Note that the exception specifies the kind of error that is occuring. Similarly, if we try to open a file that doesn't exist, we will see a \"FileNotFoundError\" exception:" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 2, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "ename": "FileNotFoundError", 159 | "evalue": "[Errno 2] No such file or directory: 'nonexistent_file'", 160 | "output_type": "error", 161 | "traceback": [ 162 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 163 | "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", 164 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmyFile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'nonexistent_file'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 165 | "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'nonexistent_file'" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "my_file = open('nonexistent_file','r')" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": {}, 176 | "source": [ 177 | "There is a programming construct called *try/catch* that allows us to deal gracefully with errors. Let's rewrite our myDivide function to use this, rather than checking for the problematic condition up front:" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 5, 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "data": { 187 | "text/plain": [ 188 | "nan" 189 | ] 190 | }, 191 | "execution_count": 5, 192 | "metadata": {}, 193 | "output_type": "execute_result" 194 | } 195 | ], 196 | "source": [ 197 | "def my_divide(i, j):\n", 198 | " try:\n", 199 | " return(i / j)\n", 200 | " except ZeroDivisionError:\n", 201 | " return(math.nan)\n", 202 | " finally:\n", 203 | " pass\n", 204 | " \n", 205 | " \n", 206 | "my_divide(1, 0)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "Here we see that it deals appropriately with the division by zero error. The *finally* section tells the function what to do if it catches any other errors, which in this case is to pass the error up the chain. For example, if we use a string instead of a number, it will raise a \"TypeError\" exception that gets passed back to us:" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 7, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "ename": "TypeError", 223 | "evalue": "unsupported operand type(s) for /: 'int' and 'str'", 224 | "output_type": "error", 225 | "traceback": [ 226 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 227 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 228 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmy_divide\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'0'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 229 | "\u001b[0;32m\u001b[0m in \u001b[0;36mmy_divide\u001b[0;34m(i, j)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmy_divide\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mreturn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mZeroDivisionError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mreturn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnan\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 230 | "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'int' and 'str'" 231 | ] 232 | } 233 | ], 234 | "source": [ 235 | "my_divide(1,'0')" 236 | ] 237 | }, 238 | { 239 | "cell_type": "markdown", 240 | "metadata": {}, 241 | "source": [] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 8, 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "data": { 250 | "text/plain": [ 251 | "0.0" 252 | ] 253 | }, 254 | "execution_count": 8, 255 | "metadata": {}, 256 | "output_type": "execute_result" 257 | } 258 | ], 259 | "source": [] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "metadata": {}, 264 | "source": [ 265 | "#### Variable scope\n", 266 | "\n", 267 | "Similar to R, a variable defined outside of a function in the global workspace is visible within the function, and variables defined within a function are not visible outside of the functionl\n", 268 | "\n", 269 | "*NOTE*: It is generally bad practice to use global variables within a function, unless they are meant to serve as constants that will never be modified. Otherwise it can be very hard to debug problems that arise. It is customary to write the names of constants in all caps so that it's clear that they are different." 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 61, 275 | "metadata": {}, 276 | "outputs": [ 277 | { 278 | "name": "stdout", 279 | "output_type": "stream", 280 | "text": [ 281 | "Earth\n" 282 | ] 283 | }, 284 | { 285 | "ename": "NameError", 286 | "evalue": "name 'defined_inside' is not defined", 287 | "output_type": "error", 288 | "traceback": [ 289 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 290 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 291 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;31m# try printing the variable defined inside the function - will raise an error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdefined_inside\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 292 | "\u001b[0;31mNameError\u001b[0m: name 'defined_inside' is not defined" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "# a constant\n", 298 | "MY_PLANET = 'Earth'\n", 299 | "\n", 300 | "def testfunc():\n", 301 | " print(MY_PLANET)\n", 302 | " defined_inside = 'local'\n", 303 | " \n", 304 | "testfunc()\n", 305 | "\n", 306 | "# try printing the variable defined inside the function - will raise an error\n", 307 | "print(defined_inside)" 308 | ] 309 | }, 310 | { 311 | "cell_type": "markdown", 312 | "metadata": {}, 313 | "source": [ 314 | "#### Optional arguments\n", 315 | "\n", 316 | "Often there are arguments that we want to be optional. For example, let's say that we want to create standardized scores for a set of numbers. Let's start by creating a version that creates standardized scores with a mean of zero and a standard deviation of 1 --- i.e. Z-scores.\n", 317 | "\n", 318 | "Here we will also add some documentation to the function, so that users can know what it's for. We do this by placing what is called a *docstring* on the first indented line of the function. We use triple quotation marks, which allows us to continue the string over several lines, though for a docstring we use them even if it's just a single line." 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 9, 324 | "metadata": {}, 325 | "outputs": [], 326 | "source": [ 327 | "import numpy\n", 328 | "\n", 329 | "def my_std_score(v):\n", 330 | " \"\"\"returns a standard score for a list or array\n", 331 | " with mean zero and standard deviation 1\n", 332 | " \n", 333 | " Parameters\n", 334 | " ----------\n", 335 | " v: list or numpy array \n", 336 | " numbers to be scaled\n", 337 | " \n", 338 | " Returns\n", 339 | " -------\n", 340 | " std_score: numpy array\n", 341 | " the standardized values\n", 342 | " \"\"\"\n", 343 | " \n", 344 | " # make sure it's an appropriate kind of variable (list or numpy array)\n", 345 | " assert type(v) in [list, numpy.ndarray]\n", 346 | " \n", 347 | " # convert list to numpy array\n", 348 | " if type(v) == list:\n", 349 | " v = numpy.array(v)\n", 350 | "\n", 351 | " std_score = (v - numpy.mean(v))/numpy.std(v)\n", 352 | " return(std_score)\n" 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": 10, 358 | "metadata": {}, 359 | "outputs": [ 360 | { 361 | "data": { 362 | "text/plain": [ 363 | "array([-1.34164079, -0.4472136 , 0.4472136 , 1.34164079])" 364 | ] 365 | }, 366 | "execution_count": 10, 367 | "metadata": {}, 368 | "output_type": "execute_result" 369 | } 370 | ], 371 | "source": [ 372 | "v = numpy.array([1,2,3,4])\n", 373 | "my_std_score(v)" 374 | ] 375 | }, 376 | { 377 | "cell_type": "markdown", 378 | "metadata": {}, 379 | "source": [ 380 | "Now that we added the docstring, the help() function will give us useful information." 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": 11, 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "name": "stdout", 390 | "output_type": "stream", 391 | "text": [ 392 | "Help on function my_std_score in module __main__:\n", 393 | "\n", 394 | "my_std_score(v)\n", 395 | " returns a standard score for a list or array\n", 396 | " with mean zero and standard deviation 1\n", 397 | " \n", 398 | " Parameters\n", 399 | " ----------\n", 400 | " v: list or numpy array \n", 401 | " numbers to be scaled\n", 402 | " \n", 403 | " Returns\n", 404 | " -------\n", 405 | " std_score: numpy array\n", 406 | " the standardized values\n", 407 | "\n" 408 | ] 409 | } 410 | ], 411 | "source": [ 412 | "help(my_std_score)" 413 | ] 414 | }, 415 | { 416 | "cell_type": "markdown", 417 | "metadata": {}, 418 | "source": [ 419 | "Sometimes we might want to create scores with a different mean or standard deviation. To enable this, we can add optional arguments specifying the mean and standard deviation, setting them to zero and one by default." 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": 12, 425 | "metadata": {}, 426 | "outputs": [], 427 | "source": [ 428 | "def my_std_score2(v, mean=0, sd=1):\n", 429 | " \"\"\"returns a standard score for a list or array\n", 430 | " with arbitrary mean and standard deviation\n", 431 | " \n", 432 | " Parameters\n", 433 | " ----------\n", 434 | " v: list or numpy array \n", 435 | " numbers to be scaled\n", 436 | " mean: float, optional\n", 437 | " mean of the standard scores (default = 0)\n", 438 | " sd: float, optional\n", 439 | " standard deviation of the standard scores (default = 1)\n", 440 | " \n", 441 | " Returns\n", 442 | " -------\n", 443 | " std_score: numpy array\n", 444 | " the standardized values\n", 445 | " \n", 446 | " \"\"\"\n", 447 | " \n", 448 | " # make sure it's an appropriate kind of variable (list or numpy array)\n", 449 | " assert type(v) in [list, numpy.ndarray]\n", 450 | " \n", 451 | " # convert list to numpy array\n", 452 | " if type(v) == list:\n", 453 | " v = numpy.array(v)\n", 454 | "\n", 455 | " # first create Z-score, then convert to units of interest\n", 456 | " z_score = (v - numpy.mean(v))/numpy.std(v)\n", 457 | " std_score = z_score*sd + mean\n", 458 | " return(std_score)\n" 459 | ] 460 | }, 461 | { 462 | "cell_type": "markdown", 463 | "metadata": {}, 464 | "source": [ 465 | "Now if we run it with no arguments, we will still get Z-scores:" 466 | ] 467 | }, 468 | { 469 | "cell_type": "code", 470 | "execution_count": 13, 471 | "metadata": {}, 472 | "outputs": [ 473 | { 474 | "data": { 475 | "text/plain": [ 476 | "array([-1.34164079, -0.4472136 , 0.4472136 , 1.34164079])" 477 | ] 478 | }, 479 | "execution_count": 13, 480 | "metadata": {}, 481 | "output_type": "execute_result" 482 | } 483 | ], 484 | "source": [ 485 | "my_std_score2(v)" 486 | ] 487 | }, 488 | { 489 | "cell_type": "markdown", 490 | "metadata": {}, 491 | "source": [ 492 | "But we can also modify those arguments to obtain differently scaled scores. Note that including the names of the arguments is not required, but is good practice in general to be clear about which optional arguments are being set." 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 14, 498 | "metadata": {}, 499 | "outputs": [ 500 | { 501 | "data": { 502 | "text/plain": [ 503 | "array([ 86.58359214, 95.52786405, 104.47213595, 113.41640786])" 504 | ] 505 | }, 506 | "execution_count": 14, 507 | "metadata": {}, 508 | "output_type": "execute_result" 509 | } 510 | ], 511 | "source": [ 512 | "my_std_score2(v, mean=100, sd=10)" 513 | ] 514 | }, 515 | { 516 | "cell_type": "markdown", 517 | "metadata": {}, 518 | "source": [ 519 | "#### Return values" 520 | ] 521 | }, 522 | { 523 | "cell_type": "markdown", 524 | "metadata": {}, 525 | "source": [ 526 | "So far we have seen functions that return a single variable, but a function can also return multiple variables. The easiest way to do this is to return a *tuple* of items, which is similar to a list but is immutable, meaning that its values can't be modified.\n", 527 | "\n", 528 | "Let's create an example of a function that will take in a vector and return the mean and standard deviation of the values. It will also by default print a report." 529 | ] 530 | }, 531 | { 532 | "cell_type": "code", 533 | "execution_count": 15, 534 | "metadata": {}, 535 | "outputs": [], 536 | "source": [ 537 | "def my_summary_stats(v, print_report=True):\n", 538 | " \"\"\"compute the mean and sd of a numpy array\n", 539 | " \n", 540 | " Parameters\n", 541 | " ----------\n", 542 | " v: numpy array \n", 543 | " values to be processed\n", 544 | " print_report: bool, optional\n", 545 | " a flag for whether to print a report (default = True)\n", 546 | " \n", 547 | " Returns\n", 548 | " -------\n", 549 | " mean: int\n", 550 | " mean of vector\n", 551 | " sd: int\n", 552 | " sd of vector\n", 553 | " \"\"\"\n", 554 | " mean = numpy.mean(v)\n", 555 | " sd = numpy.std(v)\n", 556 | " \n", 557 | " if print_report:\n", 558 | " print(f'Mean = {mean:.2f}')\n", 559 | " print(f'SD = {sd:.2f}')\n", 560 | "\n", 561 | " return((mean, sd))\n" 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": 16, 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "name": "stdout", 571 | "output_type": "stream", 572 | "text": [ 573 | "Mean = 2.50\n", 574 | "SD = 1.12\n", 575 | "(2.5, 1.118033988749895)\n" 576 | ] 577 | }, 578 | { 579 | "ename": "TypeError", 580 | "evalue": "'tuple' object does not support item assignment", 581 | "output_type": "error", 582 | "traceback": [ 583 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 584 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 585 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# if you try to change a value of the output tuple, it will raise an error:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0moutput\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 586 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 587 | ] 588 | } 589 | ], 590 | "source": [ 591 | "vec = numpy.array([1,2,3,4])\n", 592 | "output = my_summary_stats(vec)\n", 593 | "print(output)\n", 594 | "\n", 595 | "# if you try to change a value of the output tuple, it will raise an error:\n", 596 | "\n", 597 | "output[1] = 1" 598 | ] 599 | }, 600 | { 601 | "cell_type": "markdown", 602 | "metadata": {}, 603 | "source": [ 604 | "## Classes\n", 605 | "\n", 606 | "The way that you generally write programs in R is known as *procedural programming*: The program is basically a script that outlines a procedure, and R goes through it sequentially to perform the procedure. Python allows this kind of programming, but there is another way of programming that is used by most modern programming languages, known as *object-oriented programming*. Understanding the basics of object oriented programming is essential for working with R code as well as for building code that you can easily reuse, following the DRY principle that we outlined above.\n", 607 | "\n", 608 | "Tutorials:\n", 609 | "- https://realpython.com/python3-object-oriented-programming/\n", 610 | "\n", 611 | "\n", 612 | "In object-oriented programming, we define the objects that we are interested in, and then characterize them in terms of their properties or attributes and the functions that they perform or that are performed on them. The fundamental concept that defines an object in Python is known as a *class*. \n", 613 | "\n", 614 | "Let's say that we want to build a program to keep track of information about our cats. To do this, we would define a class to describe a cat (generically). First let's think about the different attributes that a cat might have. Keeping it simple, we could say that we want to keep track of their weight and whether they are hungry (which we will assume is true by default - these are cats after all). Let's start by creating a class that stores these.\n", 615 | "\n", 616 | "First we will create the class definition, dissecting it in the comments." 617 | ] 618 | }, 619 | { 620 | "cell_type": "code", 621 | "execution_count": 67, 622 | "metadata": {}, 623 | "outputs": [], 624 | "source": [ 625 | "#The first line says that we want to create a new class called \"Cat\", which is a kind of object. \n", 626 | "#This is an example of *inheritance*, in which an object can inherit the features of another \n", 627 | "#kind of object. In this case, Cat inherits the features of Python's most generic kind of object, \n", 628 | "#called simply *object*.\n", 629 | "\n", 630 | "class Cat:\n", 631 | " # the next section is the docstring, providing info about the object\n", 632 | " # the parameters refer to the values that are passed into the __init__ function\n", 633 | " \"\"\"an object describing a cat\n", 634 | "\n", 635 | " Parameters\n", 636 | " ----------\n", 637 | " weight_lbs: float\n", 638 | " cat's weight, in pounds\n", 639 | " is_hungry: bool, optional\n", 640 | " Is the cat hungry? (default = True)\n", 641 | " \"\"\"\n", 642 | " \n", 643 | " # the next line is a *class attribute* - this is a value that is shared by \n", 644 | " # all instances of the class\n", 645 | " species = \"Felis catus\"\n", 646 | " \n", 647 | " # The next line creates a special function called __init__(), which is used to \n", 648 | " # create a new instance of the class - in this case, a description of a \n", 649 | " # specific cat. The fact that the function's name starts with two underscores \n", 650 | " # means that this is a *private* function that is not meant to be called except \n", 651 | " # by the class itself. The first item in the list, which by convention is called *self*, \n", 652 | " # refers to the object itself; whenever we create a function inside a class, we usually \n", 653 | " # need to put *self* as the first argument. The next two arguments refer to the specific \n", 654 | " # features of the cat that we want to define: weight in pounds, and whether the cat is hungry. \n", 655 | " # We use descriptive variable names to make clear what each one refers to.\n", 656 | " def __init__(self, weight_lbs, is_hungry=True):\n", 657 | " # the next two lines make sure that the values passed for the arguments\n", 658 | " # are of the correct type: weight should be a number (either integer or \n", 659 | " # floating point) and is_hungry should be a Boolean value. \n", 660 | " # It is generally good practice to make sure that values passed to\n", 661 | " # a class or function are of the correct type\n", 662 | " assert isinstance(weight_lbs, int) or isinstance(weight_lbs, float)\n", 663 | " assert isinstance(is_hungry, bool)\n", 664 | " \n", 665 | " # These two lines take the two settings and use them to create variables that are part of \n", 666 | " # the object, which we call *attributes*. These are called *self.is_hungry* and \n", 667 | " # *self.weight_lbs* respectively. The period is used to denote that this is an attribute \n", 668 | " # of the current class (*self*). \n", 669 | " self.weight_lbs = weight_lbs\n", 670 | " self.is_hungry = is_hungry\n" 671 | ] 672 | }, 673 | { 674 | "cell_type": "markdown", 675 | "metadata": {}, 676 | "source": [ 677 | "Now let's create a new instance of the cat object, for my cat Coco." 678 | ] 679 | }, 680 | { 681 | "cell_type": "code", 682 | "execution_count": 68, 683 | "metadata": {}, 684 | "outputs": [], 685 | "source": [ 686 | "Coco = Cat(8,True)" 687 | ] 688 | }, 689 | { 690 | "cell_type": "markdown", 691 | "metadata": {}, 692 | "source": [ 693 | "Because we added a docstring, we can also obtain help if we forget how to use the function:" 694 | ] 695 | }, 696 | { 697 | "cell_type": "code", 698 | "execution_count": 71, 699 | "metadata": {}, 700 | "outputs": [ 701 | { 702 | "name": "stdout", 703 | "output_type": "stream", 704 | "text": [ 705 | "Help on class Cat in module __main__:\n", 706 | "\n", 707 | "class Cat(builtins.object)\n", 708 | " | an object describing a cat\n", 709 | " | \n", 710 | " | Parameters\n", 711 | " | ----------\n", 712 | " | weight_lbs: float\n", 713 | " | cat's weight, in pounds\n", 714 | " | is_hungry: bool, optional\n", 715 | " | Is the cat hungry? (default = True)\n", 716 | " | \n", 717 | " | Methods defined here:\n", 718 | " | \n", 719 | " | __init__(self, weight_lbs, is_hungry=True)\n", 720 | " | Initialize self. See help(type(self)) for accurate signature.\n", 721 | " | \n", 722 | " | ----------------------------------------------------------------------\n", 723 | " | Data descriptors defined here:\n", 724 | " | \n", 725 | " | __dict__\n", 726 | " | dictionary for instance variables (if defined)\n", 727 | " | \n", 728 | " | __weakref__\n", 729 | " | list of weak references to the object (if defined)\n", 730 | " | \n", 731 | " | ----------------------------------------------------------------------\n", 732 | " | Data and other attributes defined here:\n", 733 | " | \n", 734 | " | species = 'Felis catus'\n", 735 | "\n" 736 | ] 737 | } 738 | ], 739 | "source": [ 740 | "help(Cat)" 741 | ] 742 | }, 743 | { 744 | "cell_type": "markdown", 745 | "metadata": {}, 746 | "source": [ 747 | "We can refer to the attributes from outside of the class using the dot operator:" 748 | ] 749 | }, 750 | { 751 | "cell_type": "code", 752 | "execution_count": 69, 753 | "metadata": {}, 754 | "outputs": [ 755 | { 756 | "name": "stdout", 757 | "output_type": "stream", 758 | "text": [ 759 | "8\n", 760 | "True\n", 761 | "Felis catus\n" 762 | ] 763 | } 764 | ], 765 | "source": [ 766 | "print(Coco.weight_lbs)\n", 767 | "print(Coco.is_hungry)\n", 768 | "print(Coco.species)" 769 | ] 770 | }, 771 | { 772 | "cell_type": "markdown", 773 | "metadata": {}, 774 | "source": [ 775 | "We can also assign the value of an attribute directly. Let's say that Coco gains some weight, up to 9 pounds. We can assign this new value to the attribute." 776 | ] 777 | }, 778 | { 779 | "cell_type": "code", 780 | "execution_count": 70, 781 | "metadata": {}, 782 | "outputs": [ 783 | { 784 | "name": "stdout", 785 | "output_type": "stream", 786 | "text": [ 787 | "9\n" 788 | ] 789 | } 790 | ], 791 | "source": [ 792 | "Coco.weight_lbs = 9\n", 793 | "print(Coco.weight_lbs)" 794 | ] 795 | }, 796 | { 797 | "cell_type": "markdown", 798 | "metadata": {}, 799 | "source": [ 800 | "#### Class methods\n", 801 | "\n", 802 | "In addition to having attributes, a class also has the ability to do things, which we refer to as *methods*. For example, let's say that we want to feed the cat. We can create a new function that is part of the method, which we will call *feed*. When this method is invoked, it moves the cat from a hungry state to a not hungry state. " 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "execution_count": 72, 808 | "metadata": {}, 809 | "outputs": [], 810 | "source": [ 811 | "class Cat:\n", 812 | " \"\"\"an object describing a cat\n", 813 | "\n", 814 | " Parameters\n", 815 | " ----------\n", 816 | " weight_lbs: float\n", 817 | " cat's weight, in pounds\n", 818 | " is_hungry: bool, optional\n", 819 | " Is the cat hungry? (default = True)\n", 820 | " \n", 821 | " \"\"\"\n", 822 | "\n", 823 | " def __init__(self, weight_lbs, is_hungry=True):\n", 824 | " assert isinstance(weight_lbs, int) or isinstance(weight_lbs, float)\n", 825 | " assert isinstance(is_hungry, bool)\n", 826 | " \n", 827 | " self.weight_lbs = weight_lbs\n", 828 | " self.is_hungry = is_hungry\n", 829 | " \n", 830 | " def feed(self):\n", 831 | " \"\"\"\n", 832 | " A function that feeds the cat, moving is_hungry from true to false\n", 833 | " \"\"\"\n", 834 | " self.is_hungry = False" 835 | ] 836 | }, 837 | { 838 | "cell_type": "code", 839 | "execution_count": 73, 840 | "metadata": {}, 841 | "outputs": [ 842 | { 843 | "name": "stdout", 844 | "output_type": "stream", 845 | "text": [ 846 | "True\n", 847 | "False\n" 848 | ] 849 | } 850 | ], 851 | "source": [ 852 | "Coco = Cat(8,True)\n", 853 | "print(Coco.is_hungry)\n", 854 | "Coco.feed()\n", 855 | "print(Coco.is_hungry)" 856 | ] 857 | }, 858 | { 859 | "cell_type": "markdown", 860 | "metadata": {}, 861 | "source": [ 862 | "### A more realistic example: designing an analysis method using the scikit-learn pattern\n", 863 | "\n", 864 | "Now we will look at an example of how to build a class that does something interesting. We will build on a design pattern that we will use extensively in Psych 253, which is the pattern used by the scikit-learn package.\n", 865 | "\n", 866 | "In scikit-learn, each analysis method is represented by a class. Each of these classes has a set of methods that are standard, which is nice because we don't have to learn a new interface for each function. The interface includes several commong methods:\n", 867 | "\n", 868 | "* *fit()*: This fits the model.\n", 869 | "* *predict()*: This returns the predicted values from the model\n", 870 | "* *score()*: This returns the goodness of fit (R^2) of the model\n", 871 | "\n", 872 | "Let's build a simple version of this to see how it would work.\n", 873 | "\n" 874 | ] 875 | }, 876 | { 877 | "cell_type": "code", 878 | "execution_count": 17, 879 | "metadata": {}, 880 | "outputs": [], 881 | "source": [ 882 | "import numpy\n", 883 | "\n", 884 | "def check_variable_sizes(X, y=None):\n", 885 | " \"\"\"\n", 886 | " makes sure that vectors are properly shaped for linear modeling\n", 887 | " \n", 888 | " Parameters\n", 889 | " ----------\n", 890 | " X: numpy array (N x k)\n", 891 | " design matrix for a linear model\n", 892 | " y: numpy array (N or N x 1), optional\n", 893 | " vector of dependent variables for model\n", 894 | " \n", 895 | " Returns\n", 896 | " -------\n", 897 | " y: numpy array (N x 1)\n", 898 | " vector of dependent variables, reshaped\n", 899 | " if necessary (or None if y is None)\n", 900 | " \"\"\"\n", 901 | "\n", 902 | " # make sure X is two-dimensional\n", 903 | " assert len(X.shape) == 2\n", 904 | "\n", 905 | " if y is not None:\n", 906 | " # if y is one-dimensional then add a second dimension\n", 907 | " # so that it matches X\n", 908 | " if len(y.shape) == 1:\n", 909 | " y = y[:, numpy.newaxis]\n", 910 | "\n", 911 | " assert y.shape[0] == X.shape[0]\n", 912 | "\n", 913 | " return(y)\n", 914 | " else:\n", 915 | " return(None)\n", 916 | "\n", 917 | "\n", 918 | "class MyLinearRegression:\n", 919 | " \"\"\"Class to perform linear regression using scikit-learn API\n", 920 | " \n", 921 | " Attributes\n", 922 | " ----------\n", 923 | " coef_: numpy array, k X 1\n", 924 | " estimated regression coefficients (None until model is fitted)\n", 925 | " residuals_: numpy array, N X 1\n", 926 | " residuals from model fit (None until model is fitted)\n", 927 | " \n", 928 | " Notes\n", 929 | " -----\n", 930 | " This function assumes that the model has an intercept added already\n", 931 | " \n", 932 | " Example\n", 933 | " -------\n", 934 | " >>> lr = myLinearRegression()\n", 935 | " >>> X = numpy.random.randn(100,3)\n", 936 | " >>> X[:,2] = 1 # intercept column\n", 937 | " >>> y = X.dot(numpy.array([3,-2, 5]))\n", 938 | " >>> lr.fit(X, y)\n", 939 | " >>> lr.coef_\n", 940 | " array([[ 3.],\n", 941 | " [-2.],\n", 942 | " [ 5.]])\n", 943 | " \"\"\"\n", 944 | " \n", 945 | " \n", 946 | " def __init__(self, fit_intercept=True):\n", 947 | " # placeholder for the regression coefficients\n", 948 | " # that we will estimate\n", 949 | " self.coef_ = None\n", 950 | " self.residuals_ = None\n", 951 | " \n", 952 | "\n", 953 | " \n", 954 | " def fit(self, X, y):\n", 955 | " \"\"\"function to fit the model\n", 956 | " \n", 957 | " Parameters\n", 958 | " ----------\n", 959 | " X: numpy array (N x k)\n", 960 | " design matrix for the model\n", 961 | " y: numpy array (N or N x 1)\n", 962 | " vector of dependent variables for model\n", 963 | " \"\"\"\n", 964 | " \n", 965 | " # check variable sizes\n", 966 | " y = check_variable_sizes(X, y)\n", 967 | " \n", 968 | " # compute the regression coefficients using ordinary least squares\n", 969 | " self.coef_ = numpy.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)\n", 970 | " \n", 971 | " self.residuals_ = y[:, 0] - self.predict(X)\n", 972 | " \n", 973 | " \n", 974 | " def predict(self, X):\n", 975 | " \"\"\"Predicted values using fitted coefficients\n", 976 | " \n", 977 | " Parameters\n", 978 | " ----------\n", 979 | " X: numpy array (N x k)\n", 980 | " design matrix for the model\n", 981 | " \n", 982 | " Returns\n", 983 | " -------\n", 984 | " pred: numpy array (N)\n", 985 | " predicted values\n", 986 | " \"\"\"\n", 987 | " \n", 988 | " # make sure the model has been fit\n", 989 | " if self.coef_ is None:\n", 990 | " print('Model must be fitted first!')\n", 991 | " return(None)\n", 992 | " \n", 993 | " # check variable sizes\n", 994 | " check_variable_sizes(X)\n", 995 | " \n", 996 | " # make sure X has same dimension as coefficients\n", 997 | " # raise an exception if it doesn't\n", 998 | " assert self.coef_.shape[0] == X.shape[1]\n", 999 | " \n", 1000 | " return(X.dot(self.coef_)[:, 0])\n", 1001 | "\n", 1002 | " \n", 1003 | " def score(self, X, y):\n", 1004 | " \"\"\"returns coefficient of determination (R**2) for fitted model\n", 1005 | " \n", 1006 | " Parameters\n", 1007 | " ----------\n", 1008 | " X: numpy array (N x k)\n", 1009 | " design matrix for the model\n", 1010 | " y: numpy array (N or N x 1)\n", 1011 | " vector of dependent variables for model\n", 1012 | "\n", 1013 | " Returns\n", 1014 | " -------\n", 1015 | " r2: float\n", 1016 | " coefficient of determination\n", 1017 | " \n", 1018 | " Notes\n", 1019 | " -----\n", 1020 | " Computed as in sklearn: The coefficient R^2 is defined as (1 - u/v), \n", 1021 | " where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() \n", 1022 | " and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). \n", 1023 | " \n", 1024 | " \"\"\"\n", 1025 | " \n", 1026 | " if self.coef_ is None:\n", 1027 | " self.fit(X, y)\n", 1028 | "\n", 1029 | " y = check_variable_sizes(X, y)\n", 1030 | "\n", 1031 | " y_pred = self.predict(X)\n", 1032 | " \n", 1033 | " # return to a 1d vector to match y_pred\n", 1034 | " y_true = y[:, 0]\n", 1035 | " \n", 1036 | " # compute r-squared using sum of squares formulation\n", 1037 | " \n", 1038 | " RSS = (self.residuals_ ** 2).sum()\n", 1039 | " SSE = ((y_true - y_true.mean()) ** 2).sum()\n", 1040 | " r2 = (1 - RSS/SSE)\n", 1041 | " \n", 1042 | " return(r2)\n", 1043 | " \n", 1044 | " " 1045 | ] 1046 | }, 1047 | { 1048 | "cell_type": "code", 1049 | "execution_count": 18, 1050 | "metadata": {}, 1051 | "outputs": [ 1052 | { 1053 | "name": "stdout", 1054 | "output_type": "stream", 1055 | "text": [ 1056 | "Model must be fitted first!\n", 1057 | "[[ 2.2906098 ]\n", 1058 | " [ 4.113673 ]\n", 1059 | " [-2.53111071]]\n" 1060 | ] 1061 | }, 1062 | { 1063 | "data": { 1064 | "text/plain": [ 1065 | "0.9686900814459842" 1066 | ] 1067 | }, 1068 | "execution_count": 18, 1069 | "metadata": {}, 1070 | "output_type": "execute_result" 1071 | } 1072 | ], 1073 | "source": [ 1074 | "reg = MyLinearRegression()\n", 1075 | "\n", 1076 | "num_points = 10\n", 1077 | "X = numpy.random.randn(num_points, 2)\n", 1078 | "# add intercept\n", 1079 | "X = numpy.append(X, numpy.ones(num_points)[:, numpy.newaxis], 1)\n", 1080 | "y = X.dot([3, 4, -2]) + numpy.random.randn(10)\n", 1081 | "\n", 1082 | "# running predict before running model returns a warning\n", 1083 | "reg.predict(X)\n", 1084 | "\n", 1085 | "reg.fit(X, y)\n", 1086 | "print(reg.coef_)\n", 1087 | "\n", 1088 | "predicted = reg.predict(X)\n", 1089 | "\n", 1090 | "reg.score(X, y)" 1091 | ] 1092 | }, 1093 | { 1094 | "cell_type": "code", 1095 | "execution_count": null, 1096 | "metadata": {}, 1097 | "outputs": [], 1098 | "source": [] 1099 | } 1100 | ], 1101 | "metadata": { 1102 | "kernelspec": { 1103 | "display_name": "Python 3", 1104 | "language": "python", 1105 | "name": "python3" 1106 | }, 1107 | "language_info": { 1108 | "codemirror_mode": { 1109 | "name": "ipython", 1110 | "version": 3 1111 | }, 1112 | "file_extension": ".py", 1113 | "mimetype": "text/x-python", 1114 | "name": "python", 1115 | "nbconvert_exporter": "python", 1116 | "pygments_lexer": "ipython3", 1117 | "version": "3.6.7" 1118 | } 1119 | }, 1120 | "nbformat": 4, 1121 | "nbformat_minor": 4 1122 | } 1123 | -------------------------------------------------------------------------------- /notebooks/Part4_NumericalOperations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python for R users\n", 8 | "# Part 4: Numerical operations\n", 9 | "\n", 10 | "In this notebook we will explore how R and Python differ in the use of numerical operations. In particular we will dig into the Numpy package for numerical operations in Python. \n", 11 | "\n", 12 | "NOTE: A useful cheat sheet is available [here](http://mathesaurus.sourceforge.net/r-numpy.html).\n", 13 | "\n", 14 | "\n", 15 | "First we need to tell Jupyter to let us use R within this Python notebook. We also need to import the numpy package. Online you will often see people abbreviate numpy by using ```import numpy as np```. I am not sure why people do this but I like to use the full name of the package unless it's really long." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "import numpy\n", 25 | "\n", 26 | "%load_ext rpy2.ipython\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Basic numerical operations\n", 34 | "\n", 35 | "All of the standard arithmetic operators (+, -, /, \\*) and relational operators (==, >, <, >=, <=) are the same between Python and R, with two exceptions: exponentiation and remainders. Here they are in R:" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 10, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "[1] 9\n", 47 | "[1] 2\n" 48 | ] 49 | }, 50 | "metadata": {}, 51 | "output_type": "display_data" 52 | } 53 | ], 54 | "source": [ 55 | "%%R\n", 56 | "\n", 57 | "print(3^2)\n", 58 | "print(8 %% 3)" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "Here are the equivalents in Python, where you use \\*\\* instead of ^ and % instead of %%:" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 12, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "9\n", 78 | "2\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "print(3**2)\n", 84 | "print(8 % 3)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "The numpy package includes all of the standard mathematical functions that one might want to perform on a number. First let's implement them in R:" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 7, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "data": { 101 | "text/plain": [ 102 | "[1] 0.9635582\n", 103 | "[1] 0.2623643\n", 104 | "[1] 0.1139434\n", 105 | "[1] 1\n" 106 | ] 107 | }, 108 | "metadata": {}, 109 | "output_type": "display_data" 110 | } 111 | ], 112 | "source": [ 113 | "%%R\n", 114 | "\n", 115 | "x <- 1.3\n", 116 | "print(sin(x)) # sine\n", 117 | "print(log(x)) # natural logarithm\n", 118 | "print(log10(x)) # base 10 logarithm\n", 119 | "print(round(x)) # rounding" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 8, 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "0.963558185417193\n", 132 | "0.26236426446749106\n", 133 | "0.11394335230683679\n", 134 | "1.0\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "x = 1.3\n", 140 | "print(numpy.sin(x)) # sine\n", 141 | "print(numpy.log(x)) # natural logarithm\n", 142 | "print(numpy.log10(x)) # base 10 logarithm\n", 143 | "print(numpy.round(x)) # rounding" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "## Logical operations\n", 151 | "\n", 152 | "Logical operators are slightly different (and arguably much simpler) in Python compared to R. Here they are in R:" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 14, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "data": { 162 | "text/plain": [ 163 | "[1] FALSE\n", 164 | "[1] TRUE\n", 165 | "[1] TRUE\n" 166 | ] 167 | }, 168 | "metadata": {}, 169 | "output_type": "display_data" 170 | } 171 | ], 172 | "source": [ 173 | "%%R\n", 174 | "\n", 175 | "a = TRUE\n", 176 | "b = FALSE\n", 177 | "\n", 178 | "print(a && b) # logical AND\n", 179 | "print(a || b) # logical OR\n", 180 | "print(xor(a, b)) # EXCLUSIVE OR\n" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "Here they are in Python:" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 17, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "False\n", 200 | "True\n", 201 | "True\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "a = True\n", 207 | "b = False\n", 208 | "\n", 209 | "print(a and b) # logical AND\n", 210 | "print(a or b) # logical OR\n", 211 | "print(numpy.logical_xor(a,b)) # EXCLUSIVE OR\n" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "metadata": {}, 217 | "source": [ 218 | "## Arrays in Python and R\n", 219 | "\n", 220 | "Let's start by discussing single-dimensional arrays (i.e. vectors). First let's look at how one would do a number of vector operations in R.\n" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 45, 226 | "metadata": {}, 227 | "outputs": [ 228 | { 229 | "data": { 230 | "text/plain": [ 231 | "[1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0\n", 232 | "[1] 9\n", 233 | "[1] 1.0 1.5 2.0\n", 234 | "[1] 4.5 5.0\n", 235 | "[1] 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0\n", 236 | "[1] 110 115 120 125 130 135 140 145 150\n", 237 | " [1] 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.5 15.0 110.0 115.0 120.0\n", 238 | "[13] 125.0 130.0 135.0 140.0 145.0 150.0\n" 239 | ] 240 | }, 241 | "metadata": {}, 242 | "output_type": "display_data" 243 | } 244 | ], 245 | "source": [ 246 | "%%R\n", 247 | "\n", 248 | "# create a vector using seq()\n", 249 | "a = seq(1,5, 0.5)\n", 250 | "print(a)\n", 251 | "\n", 252 | "# get the length of the vector\n", 253 | "print(length(a))\n", 254 | "\n", 255 | "# extract first 3 elements of vector\n", 256 | "print(a[1:3])\n", 257 | "\n", 258 | "# extract last two elements of vector\n", 259 | "print(tail(a, 2))\n", 260 | "\n", 261 | "# add 10 to all elements\n", 262 | "b = a + 10\n", 263 | "print(b)\n", 264 | "\n", 265 | "# multiply all elements by 5\n", 266 | "# we skip using the name \"c\" as a variable here - why?\n", 267 | "d = b * 10\n", 268 | "print(d)\n", 269 | "\n", 270 | "# concatenate two vectors\n", 271 | "e = c(b, d)\n", 272 | "print(e)" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "metadata": {}, 278 | "source": [ 279 | "Here we do the equivalent work in Python:" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 61, 285 | "metadata": {}, 286 | "outputs": [ 287 | { 288 | "name": "stdout", 289 | "output_type": "stream", 290 | "text": [ 291 | "[1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. ]\n" 292 | ] 293 | }, 294 | { 295 | "data": { 296 | "text/plain": [ 297 | "[1] 1\n" 298 | ] 299 | }, 300 | "metadata": {}, 301 | "output_type": "display_data" 302 | }, 303 | { 304 | "name": "stdout", 305 | "output_type": "stream", 306 | "text": [ 307 | "(9,)\n", 308 | "[1. 1.5 2. ]\n", 309 | "[4.5 5. ]\n", 310 | "[11. 11.5 12. 12.5 13. 13.5 14. 14.5 15. ]\n", 311 | "[110. 115. 120. 125. 130. 135. 140. 145. 150.]\n", 312 | "[ 11. 11.5 12. 12.5 13. 13.5 14. 14.5 15. 110. 115. 120.\n", 313 | " 125. 130. 135. 140. 145. 150. ]\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "# create a vector using numpy.arange\n", 319 | "a = numpy.arange(1, 5.5, 0.5)\n", 320 | "print(a)\n", 321 | "\n", 322 | "%R print(1)\n", 323 | "\n", 324 | "# get the length of the vector\n", 325 | "print(a.shape)\n", 326 | "\n", 327 | "# extract first 3 elements of vector\n", 328 | "print(a[:3])\n", 329 | "\n", 330 | "# extract last two elements of vector\n", 331 | "print(a[-2:])\n", 332 | "\n", 333 | "# add 10 to all elements\n", 334 | "b = a + 10\n", 335 | "print(b)\n", 336 | "\n", 337 | "# multiply all elements by 5\n", 338 | "d = b * 10\n", 339 | "print(d)\n", 340 | "\n", 341 | "# concatenate two vectors\n", 342 | "# NOTE: the two vectors being concatenated must be provided to the function as a tuple.\n", 343 | "e = numpy. concatenate((b, d))\n", 344 | "print(e)" 345 | ] 346 | }, 347 | { 348 | "cell_type": "markdown", 349 | "metadata": {}, 350 | "source": [ 351 | "Just as in R, many numpy functions are *vectorized* meaning that if one inputs a vector, they will output a vector with the operation applied independently to each element." 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 47, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "data": { 361 | "text/plain": [ 362 | " [1] 0.000000e+00 3.090170e-01 5.877853e-01 8.090170e-01 9.510565e-01\n", 363 | " [6] 1.000000e+00 9.510565e-01 8.090170e-01 5.877853e-01 3.090170e-01\n", 364 | "[11] 1.224647e-16\n" 365 | ] 366 | }, 367 | "metadata": {}, 368 | "output_type": "display_data" 369 | } 370 | ], 371 | "source": [ 372 | "%%R\n", 373 | "\n", 374 | "x = seq(0,pi, pi/10)\n", 375 | "print(sin(x))" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 52, 381 | "metadata": {}, 382 | "outputs": [ 383 | { 384 | "name": "stdout", 385 | "output_type": "stream", 386 | "text": [ 387 | "[0.00000000e+00 3.09016994e-01 5.87785252e-01 8.09016994e-01\n", 388 | " 9.51056516e-01 1.00000000e+00 9.51056516e-01 8.09016994e-01\n", 389 | " 5.87785252e-01 3.09016994e-01 1.22464680e-16]\n" 390 | ] 391 | } 392 | ], 393 | "source": [ 394 | "x = numpy.arange(0, numpy.pi*1.01, numpy.pi/10)\n", 395 | "print(numpy.sin(x))" 396 | ] 397 | }, 398 | { 399 | "cell_type": "markdown", 400 | "metadata": {}, 401 | "source": [ 402 | "## Generating random numbers\n", 403 | "\n", 404 | "One common thing that we need to do is to generate random numbers. This works similarly in R and Python. For the purpose of reproducibility it's usually good practice to set the random seed to a specific value at the begnning of the code, so that the code will always provide the same results. " 405 | ] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "execution_count": 58, 410 | "metadata": {}, 411 | "outputs": [ 412 | { 413 | "data": { 414 | "text/plain": [ 415 | "[1] 0.7977843 0.7535651 0.3912557 0.3415567 0.3612941\n", 416 | "[1] -0.8475485 -1.3016020 -0.9638145 0.2373156\n" 417 | ] 418 | }, 419 | "metadata": {}, 420 | "output_type": "display_data" 421 | } 422 | ], 423 | "source": [ 424 | "%%R\n", 425 | "\n", 426 | "set.seed(123456) # fix the random seed\n", 427 | "\n", 428 | "# generate 5 uniform random variates\n", 429 | "print(runif(5))\n", 430 | "\n", 431 | "# generate 4 standard normal variates\n", 432 | "print(rnorm(4))" 433 | ] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "execution_count": 60, 438 | "metadata": {}, 439 | "outputs": [ 440 | { 441 | "name": "stdout", 442 | "output_type": "stream", 443 | "text": [ 444 | "[0.12696983 0.96671784 0.26047601 0.89723652 0.37674972]\n", 445 | "[-0.58986305 -1.98683112 -2.17314697 0.73630915]\n" 446 | ] 447 | } 448 | ], 449 | "source": [ 450 | "numpy.random.seed(123456) # fix the random seed\n", 451 | "\n", 452 | "# generate 5 uniform random variates\n", 453 | "print(numpy.random.rand(5))\n", 454 | "\n", 455 | "# generate 4 standard normal variates\n", 456 | "print(numpy.random.randn(4))" 457 | ] 458 | }, 459 | { 460 | "cell_type": "markdown", 461 | "metadata": {}, 462 | "source": [ 463 | "## Working with multidimensional arrays\n", 464 | "\n", 465 | "We very often want to work with multidimensional data; the term *matrix* is often used to refer specifically to a 2-d array, though the array functions in both R and numpy can handle higher-dimension arrays as well. We will focus on 2-d arrays for now, though higher dimensional arrays become important when dealing with volumetric images.\n", 466 | "\n", 467 | "In R, one can use the ```array()``` function to generate a 2-d array. There is also a function called ```matrix()```, which is just another way to generate the same thing." 468 | ] 469 | }, 470 | { 471 | "cell_type": "code", 472 | "execution_count": 91, 473 | "metadata": {}, 474 | "outputs": [ 475 | { 476 | "data": { 477 | "text/plain": [ 478 | " [,1] [,2] [,3]\n", 479 | "[1,] 1 5 9\n", 480 | "[2,] 2 6 10\n", 481 | "[3,] 3 7 11\n", 482 | "[4,] 4 8 12\n", 483 | "[1] 4 3\n" 484 | ] 485 | }, 486 | "metadata": {}, 487 | "output_type": "display_data" 488 | } 489 | ], 490 | "source": [ 491 | "%%R\n", 492 | "\n", 493 | "# create an array from two vectors\n", 494 | "vector1 = c(1, 2, 3, 4)\n", 495 | "vector2 = c(5, 6, 7, 8)\n", 496 | "vector3 = c(9, 10, 11, 12)\n", 497 | "a = array(c(vector1, vector2, vector3), dim = c(4, 3))\n", 498 | "print(a)\n", 499 | "dim(a)" 500 | ] 501 | }, 502 | { 503 | "cell_type": "markdown", 504 | "metadata": {}, 505 | "source": [ 506 | "The situation for Numpy is a bit more confusing. Numpy has separate object types for *arrays* and *matrices*, and they are not equivalent. Because one can usually do anything with the array class that is possible with the matrix class, we will focus on the array class in this document. However, occasionally you might encounter a library that requires Numpy matrices, and it's important to realize that they are a not interchangeable as they are in R.\n", 507 | "\n", 508 | "Let's generate a 2-d array in Python:" 509 | ] 510 | }, 511 | { 512 | "cell_type": "code", 513 | "execution_count": 92, 514 | "metadata": {}, 515 | "outputs": [ 516 | { 517 | "name": "stdout", 518 | "output_type": "stream", 519 | "text": [ 520 | "[[ 1 2 3 4]\n", 521 | " [ 5 6 7 8]\n", 522 | " [ 9 10 11 12]]\n", 523 | "(3, 4)\n" 524 | ] 525 | } 526 | ], 527 | "source": [ 528 | "# create an array from two vectors\n", 529 | "vector1 = [1, 2, 3, 4]\n", 530 | "vector2 = [5, 6, 7, 8]\n", 531 | "vector3 = [9, 10, 11, 12]\n", 532 | "a = numpy.array([vector1, vector2, vector3])\n", 533 | "print(a)\n", 534 | "\n", 535 | "print(a.shape)" 536 | ] 537 | }, 538 | { 539 | "cell_type": "markdown", 540 | "metadata": {}, 541 | "source": [ 542 | "Numpy creates the array with the vectors in rows, whereas R created it with the vectors in columns.\n", 543 | "In order to match what was done in R, we need to transpose the array, using the ```.T``` operator.\n" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": 93, 549 | "metadata": {}, 550 | "outputs": [ 551 | { 552 | "name": "stdout", 553 | "output_type": "stream", 554 | "text": [ 555 | "[[ 1 5 9]\n", 556 | " [ 2 6 10]\n", 557 | " [ 3 7 11]\n", 558 | " [ 4 8 12]]\n", 559 | "(4, 3)\n" 560 | ] 561 | } 562 | ], 563 | "source": [ 564 | "a = a.T\n", 565 | "print(a)\n", 566 | "print(a.shape)" 567 | ] 568 | }, 569 | { 570 | "cell_type": "markdown", 571 | "metadata": {}, 572 | "source": [ 573 | "### Indexing arrays\n", 574 | "\n", 575 | "Indexing works slightly differently between R and Python. We have already encountered one way in which they differ: R indexes starting at 1, whereas Python indexes starting at zero. There are a few other differences, as we will see below." 576 | ] 577 | }, 578 | { 579 | "cell_type": "code", 580 | "execution_count": 99, 581 | "metadata": {}, 582 | "outputs": [ 583 | { 584 | "data": { 585 | "text/plain": [ 586 | " [,1] [,2] [,3]\n", 587 | "[1,] 1 5 9\n", 588 | "[2,] 2 6 10\n", 589 | "[3,] 3 7 11\n", 590 | " [,1] [,2]\n", 591 | "[1,] 1 5\n", 592 | "[2,] 2 6\n", 593 | "[3,] 3 7\n", 594 | "[4,] 4 8\n", 595 | " [,1] [,2] [,3]\n", 596 | "[1,] 3 7 11\n", 597 | "[2,] 4 8 12\n", 598 | " [,1] [,2] [,3] [,4]\n", 599 | "[1,] 1 2 3 4\n", 600 | "[2,] 5 6 7 8\n", 601 | "[3,] 9 10 11 12\n", 602 | " [,1] [,2] [,3]\n", 603 | "[1,] 4 8 12\n", 604 | "[2,] 3 7 11\n", 605 | "[3,] 2 6 10\n", 606 | "[4,] 1 5 9\n" 607 | ] 608 | }, 609 | "metadata": {}, 610 | "output_type": "display_data" 611 | } 612 | ], 613 | "source": [ 614 | "%%R \n", 615 | "\n", 616 | "# extract first 3 rows\n", 617 | "print(a[1:3 ,])\n", 618 | "\n", 619 | "# extract first two columns\n", 620 | "print(a[, 1:2])\n", 621 | "\n", 622 | "# extract last two rows\n", 623 | "print(a[3:4, ])\n", 624 | "\n", 625 | "# transpose the array\n", 626 | "print(t(a))\n", 627 | "\n", 628 | "# flip the array up-down\n", 629 | "print(a[4:1, ])" 630 | ] 631 | }, 632 | { 633 | "cell_type": "markdown", 634 | "metadata": {}, 635 | "source": [ 636 | "Now we will do the same in Python. There are several differences to notice. The first is that we can't leave the index for an axis blank like we can in R --- instead, if we want to use all elements along a particular dimension, we need to use the wild-card symbol, ```:```. A second difference is that we can use negative indices to move backward from the end. Doing this in R would require computing the length of the array along the dimension of interest, and then subtracting off the number of desired steps. \n", 637 | "\n", 638 | "Indexing also works a bit differently in Python versus R (as discussed in detail [here](https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html)). If we put ```1:3``` as a sequence in R, the resulting values are 1, 2, and 3. If we put the same in Python, we only get the numbers 1 and 2, because Python treats the second number as an exclusive limit rather than an inclusive limit. This is useful in the context of Python's zero-based indexing, because if we want the first three elements (which have indices 0, 1, and 2), then we can use ```:3``` and we will get the correct answer.\n", 639 | "\n", 640 | "You can think about the syntax for slicing an array as follows. we specify up to three numbers as ```i:j:k``` which specify the starting index (i), the stopping index (j), and the step size (k). The default value for i is 0, for j is the length of the dimension, and for k is 1. \n" 641 | ] 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": 103, 646 | "metadata": {}, 647 | "outputs": [ 648 | { 649 | "name": "stdout", 650 | "output_type": "stream", 651 | "text": [ 652 | "[[ 1 5 9]\n", 653 | " [ 2 6 10]\n", 654 | " [ 3 7 11]]\n", 655 | "[[1 5]\n", 656 | " [2 6]\n", 657 | " [3 7]\n", 658 | " [4 8]]\n", 659 | "[[ 3 7 11]\n", 660 | " [ 4 8 12]]\n", 661 | "[[ 1 2 3 4]\n", 662 | " [ 5 6 7 8]\n", 663 | " [ 9 10 11 12]]\n", 664 | "[[ 4 8 12]\n", 665 | " [ 3 7 11]\n", 666 | " [ 2 6 10]\n", 667 | " [ 1 5 9]]\n", 668 | "[[ 4 8 12]\n", 669 | " [ 3 7 11]\n", 670 | " [ 2 6 10]\n", 671 | " [ 1 5 9]]\n" 672 | ] 673 | } 674 | ], 675 | "source": [ 676 | "# extract first 3 rows\n", 677 | "print(a[:3, :])\n", 678 | "\n", 679 | "# extract first two columns\n", 680 | "print(a[:, :2])\n", 681 | "\n", 682 | "# extract last two rows\n", 683 | "print(a[-2:, :])\n", 684 | "\n", 685 | "# transpose the array\n", 686 | "print(a.T)\n", 687 | "\n", 688 | "# flip the array up-down\n", 689 | "# setting k to -1 goes backwards from j to i\n", 690 | "print(a[::-1, :])\n", 691 | "\n", 692 | "# there is also a built-in numpy function to flip an array up-down:\n", 693 | "print(numpy.flipud(a))" 694 | ] 695 | }, 696 | { 697 | "cell_type": "markdown", 698 | "metadata": {}, 699 | "source": [ 700 | "One handy feature of Numpy arrays is that they have a bunch of built-in functions that you can apply to them. We can see all of those using the ```dir()``` function:" 701 | ] 702 | }, 703 | { 704 | "cell_type": "code", 705 | "execution_count": 104, 706 | "metadata": {}, 707 | "outputs": [ 708 | { 709 | "data": { 710 | "text/plain": [ 711 | "['T',\n", 712 | " '__abs__',\n", 713 | " '__add__',\n", 714 | " '__and__',\n", 715 | " '__array__',\n", 716 | " '__array_finalize__',\n", 717 | " '__array_function__',\n", 718 | " '__array_interface__',\n", 719 | " '__array_prepare__',\n", 720 | " '__array_priority__',\n", 721 | " '__array_struct__',\n", 722 | " '__array_ufunc__',\n", 723 | " '__array_wrap__',\n", 724 | " '__bool__',\n", 725 | " '__class__',\n", 726 | " '__complex__',\n", 727 | " '__contains__',\n", 728 | " '__copy__',\n", 729 | " '__deepcopy__',\n", 730 | " '__delattr__',\n", 731 | " '__delitem__',\n", 732 | " '__dir__',\n", 733 | " '__divmod__',\n", 734 | " '__doc__',\n", 735 | " '__eq__',\n", 736 | " '__float__',\n", 737 | " '__floordiv__',\n", 738 | " '__format__',\n", 739 | " '__ge__',\n", 740 | " '__getattribute__',\n", 741 | " '__getitem__',\n", 742 | " '__gt__',\n", 743 | " '__hash__',\n", 744 | " '__iadd__',\n", 745 | " '__iand__',\n", 746 | " '__ifloordiv__',\n", 747 | " '__ilshift__',\n", 748 | " '__imatmul__',\n", 749 | " '__imod__',\n", 750 | " '__imul__',\n", 751 | " '__index__',\n", 752 | " '__init__',\n", 753 | " '__init_subclass__',\n", 754 | " '__int__',\n", 755 | " '__invert__',\n", 756 | " '__ior__',\n", 757 | " '__ipow__',\n", 758 | " '__irshift__',\n", 759 | " '__isub__',\n", 760 | " '__iter__',\n", 761 | " '__itruediv__',\n", 762 | " '__ixor__',\n", 763 | " '__le__',\n", 764 | " '__len__',\n", 765 | " '__lshift__',\n", 766 | " '__lt__',\n", 767 | " '__matmul__',\n", 768 | " '__mod__',\n", 769 | " '__mul__',\n", 770 | " '__ne__',\n", 771 | " '__neg__',\n", 772 | " '__new__',\n", 773 | " '__or__',\n", 774 | " '__pos__',\n", 775 | " '__pow__',\n", 776 | " '__radd__',\n", 777 | " '__rand__',\n", 778 | " '__rdivmod__',\n", 779 | " '__reduce__',\n", 780 | " '__reduce_ex__',\n", 781 | " '__repr__',\n", 782 | " '__rfloordiv__',\n", 783 | " '__rlshift__',\n", 784 | " '__rmatmul__',\n", 785 | " '__rmod__',\n", 786 | " '__rmul__',\n", 787 | " '__ror__',\n", 788 | " '__rpow__',\n", 789 | " '__rrshift__',\n", 790 | " '__rshift__',\n", 791 | " '__rsub__',\n", 792 | " '__rtruediv__',\n", 793 | " '__rxor__',\n", 794 | " '__setattr__',\n", 795 | " '__setitem__',\n", 796 | " '__setstate__',\n", 797 | " '__sizeof__',\n", 798 | " '__str__',\n", 799 | " '__sub__',\n", 800 | " '__subclasshook__',\n", 801 | " '__truediv__',\n", 802 | " '__xor__',\n", 803 | " 'all',\n", 804 | " 'any',\n", 805 | " 'argmax',\n", 806 | " 'argmin',\n", 807 | " 'argpartition',\n", 808 | " 'argsort',\n", 809 | " 'astype',\n", 810 | " 'base',\n", 811 | " 'byteswap',\n", 812 | " 'choose',\n", 813 | " 'clip',\n", 814 | " 'compress',\n", 815 | " 'conj',\n", 816 | " 'conjugate',\n", 817 | " 'copy',\n", 818 | " 'ctypes',\n", 819 | " 'cumprod',\n", 820 | " 'cumsum',\n", 821 | " 'data',\n", 822 | " 'diagonal',\n", 823 | " 'dot',\n", 824 | " 'dtype',\n", 825 | " 'dump',\n", 826 | " 'dumps',\n", 827 | " 'fill',\n", 828 | " 'flags',\n", 829 | " 'flat',\n", 830 | " 'flatten',\n", 831 | " 'getfield',\n", 832 | " 'imag',\n", 833 | " 'item',\n", 834 | " 'itemset',\n", 835 | " 'itemsize',\n", 836 | " 'max',\n", 837 | " 'mean',\n", 838 | " 'min',\n", 839 | " 'nbytes',\n", 840 | " 'ndim',\n", 841 | " 'newbyteorder',\n", 842 | " 'nonzero',\n", 843 | " 'partition',\n", 844 | " 'prod',\n", 845 | " 'ptp',\n", 846 | " 'put',\n", 847 | " 'ravel',\n", 848 | " 'real',\n", 849 | " 'repeat',\n", 850 | " 'reshape',\n", 851 | " 'resize',\n", 852 | " 'round',\n", 853 | " 'searchsorted',\n", 854 | " 'setfield',\n", 855 | " 'setflags',\n", 856 | " 'shape',\n", 857 | " 'size',\n", 858 | " 'sort',\n", 859 | " 'squeeze',\n", 860 | " 'std',\n", 861 | " 'strides',\n", 862 | " 'sum',\n", 863 | " 'swapaxes',\n", 864 | " 'take',\n", 865 | " 'tobytes',\n", 866 | " 'tofile',\n", 867 | " 'tolist',\n", 868 | " 'tostring',\n", 869 | " 'trace',\n", 870 | " 'transpose',\n", 871 | " 'var',\n", 872 | " 'view']" 873 | ] 874 | }, 875 | "execution_count": 104, 876 | "metadata": {}, 877 | "output_type": "execute_result" 878 | } 879 | ], 880 | "source": [ 881 | "dir(a)" 882 | ] 883 | }, 884 | { 885 | "cell_type": "markdown", 886 | "metadata": {}, 887 | "source": [ 888 | "Here are just a few examples:" 889 | ] 890 | }, 891 | { 892 | "cell_type": "code", 893 | "execution_count": 108, 894 | "metadata": {}, 895 | "outputs": [ 896 | { 897 | "name": "stdout", 898 | "output_type": "stream", 899 | "text": [ 900 | "6.5\n", 901 | "[ 2.5 6.5 10.5]\n", 902 | "78\n" 903 | ] 904 | } 905 | ], 906 | "source": [ 907 | "# take the mean of the entire array\n", 908 | "print(a.mean())\n", 909 | "\n", 910 | "# take the mean along the first axis\n", 911 | "print(a.mean(axis=0))\n", 912 | "\n", 913 | "# take the sum of the entire array\n", 914 | "print(a.sum())" 915 | ] 916 | }, 917 | { 918 | "cell_type": "code", 919 | "execution_count": null, 920 | "metadata": {}, 921 | "outputs": [], 922 | "source": [] 923 | }, 924 | { 925 | "cell_type": "code", 926 | "execution_count": null, 927 | "metadata": {}, 928 | "outputs": [], 929 | "source": [] 930 | } 931 | ], 932 | "metadata": { 933 | "kernelspec": { 934 | "display_name": "Python 3", 935 | "language": "python", 936 | "name": "python3" 937 | }, 938 | "language_info": { 939 | "codemirror_mode": { 940 | "name": "ipython", 941 | "version": 3 942 | }, 943 | "file_extension": ".py", 944 | "mimetype": "text/x-python", 945 | "name": "python", 946 | "nbconvert_exporter": "python", 947 | "pygments_lexer": "ipython3", 948 | "version": "3.6.8" 949 | } 950 | }, 951 | "nbformat": 4, 952 | "nbformat_minor": 2 953 | } 954 | -------------------------------------------------------------------------------- /notebooks/Part6_LinearAlgebraStatisticalModeling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python for R users\n", 8 | "# Part 6: Linear algebra and statistical modeling\n", 9 | "\n", 10 | "\n", 11 | "Here are some great resources (from which some of the material below was adapted):\n", 12 | "- https://github.com/kuleshov/cs228-material/blob/master/tutorials/python/cs228-python-tutorial.ipynb\n", 13 | "- https://cs231n.github.io/python-numpy-tutorial/#numpy\n", 14 | "\n", 15 | "First we need to tell Jupyter to let us use R within this Python notebook, and load some relevant libraries" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 116, 21 | "metadata": {}, 22 | "outputs": [ 23 | { 24 | "name": "stdout", 25 | "output_type": "stream", 26 | "text": [ 27 | "The rpy2.ipython extension is already loaded. To reload it, use:\n", 28 | " %reload_ext rpy2.ipython\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "import numpy\n", 34 | "import pandas\n", 35 | "import statsmodels.api\n", 36 | "\n", 37 | "%load_ext rpy2.ipython" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Creating matrices in Numpy\n", 45 | "\n", 46 | "First let's refresh a bit on numpy matrices and look at the various functions that are available to work with them. Note that as we discussed in an earlier section, Numpy has two types of objects that can represent a numeric matrix: arrays and matrices. Because Numpy matrices are not used very often, we will focus here on arrays, so when I used the term \"matrix\" I am really referring to \"a 2-dimensional numpy.array object\".\n", 47 | "\n", 48 | "Let's create a matrix ```X```:\n", 49 | "\n", 50 | "$X = \\begin{bmatrix}\n", 51 | "1 & 5\\\\ \n", 52 | "2 & 6\\\\ \n", 53 | "3 & 7\\\\ \n", 54 | "4 & 8\n", 55 | "\\end{bmatrix}$" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 7, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "array([[1, 5],\n", 67 | " [2, 6],\n", 68 | " [3, 7],\n", 69 | " [4, 8]])" 70 | ] 71 | }, 72 | "execution_count": 7, 73 | "metadata": {}, 74 | "output_type": "execute_result" 75 | } 76 | ], 77 | "source": [ 78 | "X = numpy.array([[1, 5], [2, 6], [3, 7], [4, 8]])\n", 79 | "X" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 5, 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "(4, 2)" 91 | ] 92 | }, 93 | "execution_count": 5, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "X.shape" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "Let's say that we want to create a matrix with a single column called ```Y```:\n", 107 | "\n", 108 | "$Y = \\begin{bmatrix}\n", 109 | "8\\\\ \n", 110 | "10\\\\ \n", 111 | "12\\\\ \n", 112 | "14\n", 113 | "\\end{bmatrix}$\n", 114 | "\n" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "If we just create a vector, it will only have a single dimension:" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 10, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "(4,)" 133 | ] 134 | }, 135 | "execution_count": 10, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "Y_vector = numpy.array([8, 10, 12, 14])\n", 142 | "Y_vector.shape" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "You might think that transposing it would turn it into a column vector, but that doesn't work:" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 11, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "array([ 8, 10, 12, 14])" 161 | ] 162 | }, 163 | "execution_count": 11, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "Y_vector.T" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 12, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/plain": [ 180 | "(4,)" 181 | ] 182 | }, 183 | "execution_count": 12, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "Y_vector.T.shape" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "There are a couple of ways around this. First, we could specify it as a set of vectors:" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 17, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "data": { 206 | "text/plain": [ 207 | "array([[ 8],\n", 208 | " [10],\n", 209 | " [12],\n", 210 | " [14]])" 211 | ] 212 | }, 213 | "execution_count": 17, 214 | "metadata": {}, 215 | "output_type": "execute_result" 216 | } 217 | ], 218 | "source": [ 219 | "Y = numpy.array([[8], [10], [12], [14]])\n", 220 | "Y" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "We could also create a vector and then turn it into a matrix by adding a dimension:" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 20, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "name": "stdout", 237 | "output_type": "stream", 238 | "text": [ 239 | "[ 8 10 12 14]\n", 240 | "[[ 8]\n", 241 | " [10]\n", 242 | " [12]\n", 243 | " [14]]\n" 244 | ] 245 | } 246 | ], 247 | "source": [ 248 | "Y = numpy.array([ 8, 10, 12, 14]) # create a vector\n", 249 | "print(Y)\n", 250 | "\n", 251 | "Y = Y[:, numpy.newaxis] # add a new axis using numpy.newaxis\n", 252 | "print(Y)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "metadata": {}, 258 | "source": [ 259 | "There are also a number of ways to create full matrices in Numpy:" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 36, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "array([[0., 0., 0., 0.],\n", 271 | " [0., 0., 0., 0.],\n", 272 | " [0., 0., 0., 0.],\n", 273 | " [0., 0., 0., 0.]])" 274 | ] 275 | }, 276 | "execution_count": 36, 277 | "metadata": {}, 278 | "output_type": "execute_result" 279 | } 280 | ], 281 | "source": [ 282 | "numpy.zeros((4, 4)) # create a matrix full of zeros" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 37, 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "data": { 292 | "text/plain": [ 293 | "array([[1., 1., 1., 1.],\n", 294 | " [1., 1., 1., 1.],\n", 295 | " [1., 1., 1., 1.],\n", 296 | " [1., 1., 1., 1.]])" 297 | ] 298 | }, 299 | "execution_count": 37, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "numpy.ones((4, 4)) # create a matrix full of ones" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 38, 311 | "metadata": {}, 312 | "outputs": [ 313 | { 314 | "data": { 315 | "text/plain": [ 316 | "array([[1., 0., 0., 0.],\n", 317 | " [0., 1., 0., 0.],\n", 318 | " [0., 0., 1., 0.],\n", 319 | " [0., 0., 0., 1.]])" 320 | ] 321 | }, 322 | "execution_count": 38, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "numpy.eye(4) # create a identity matrix" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 41, 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/plain": [ 339 | "array([[ 0.07745061, -0.18132854, 1.14380771, 0.15858806],\n", 340 | " [ 0.80841882, -0.64581488, 1.84212199, 1.20836525],\n", 341 | " [ 1.22670288, 1.4361737 , 0.81077107, 0.55930126],\n", 342 | " [ 0.8419945 , -0.62126735, 0.87026206, 0.9736254 ]])" 343 | ] 344 | }, 345 | "execution_count": 41, 346 | "metadata": {}, 347 | "output_type": "execute_result" 348 | } 349 | ], 350 | "source": [ 351 | "numpy.random.randn(4, 4) # create a matrix of random normal variates" 352 | ] 353 | }, 354 | { 355 | "cell_type": "markdown", 356 | "metadata": {}, 357 | "source": [ 358 | "Finally, we can take a vector and reshape it into a matrix using the ```.reshape()``` operator" 359 | ] 360 | }, 361 | { 362 | "cell_type": "code", 363 | "execution_count": 44, 364 | "metadata": {}, 365 | "outputs": [ 366 | { 367 | "data": { 368 | "text/plain": [ 369 | "array([[ 0.58890519, 1.47946945, -0.30811304, -1.92770671],\n", 370 | " [ 0.61598558, 1.22105069, -0.46318886, 0.91614638],\n", 371 | " [ 0.63697573, 0.21707719, -0.39858465, -0.39221386],\n", 372 | " [-0.73307617, -0.13088766, -0.4658867 , 1.41455679]])" 373 | ] 374 | }, 375 | "execution_count": 44, 376 | "metadata": {}, 377 | "output_type": "execute_result" 378 | } 379 | ], 380 | "source": [ 381 | "numpy.random.randn(16).reshape((4, 4)) # create a 16 item vector and reshape into a 4 x 4 array" 382 | ] 383 | }, 384 | { 385 | "cell_type": "markdown", 386 | "metadata": {}, 387 | "source": [ 388 | "## Basic arithmetic on matrices\n", 389 | "\n", 390 | "All of the standard aritmetic and logical operators work on matrices in Numpy, operating element-wise.\n", 391 | "\n" 392 | ] 393 | }, 394 | { 395 | "cell_type": "code", 396 | "execution_count": 50, 397 | "metadata": {}, 398 | "outputs": [ 399 | { 400 | "name": "stdout", 401 | "output_type": "stream", 402 | "text": [ 403 | "[[2. 2. 2.]\n", 404 | " [2. 2. 2.]\n", 405 | " [2. 2. 2.]]\n" 406 | ] 407 | } 408 | ], 409 | "source": [ 410 | "A = numpy.ones((3,3)) * 2\n", 411 | "print(A)" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 51, 417 | "metadata": {}, 418 | "outputs": [ 419 | { 420 | "name": "stdout", 421 | "output_type": "stream", 422 | "text": [ 423 | "[[1 2 3]\n", 424 | " [4 5 6]\n", 425 | " [7 8 9]]\n" 426 | ] 427 | } 428 | ], 429 | "source": [ 430 | "B = numpy.arange(1,10).reshape(3,3)\n", 431 | "print(B)" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": 52, 437 | "metadata": {}, 438 | "outputs": [ 439 | { 440 | "data": { 441 | "text/plain": [ 442 | "array([[ 3., 4., 5.],\n", 443 | " [ 6., 7., 8.],\n", 444 | " [ 9., 10., 11.]])" 445 | ] 446 | }, 447 | "execution_count": 52, 448 | "metadata": {}, 449 | "output_type": "execute_result" 450 | } 451 | ], 452 | "source": [ 453 | "A + B # elementwise addition" 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": 53, 459 | "metadata": {}, 460 | "outputs": [ 461 | { 462 | "data": { 463 | "text/plain": [ 464 | "array([[ 1., 0., -1.],\n", 465 | " [-2., -3., -4.],\n", 466 | " [-5., -6., -7.]])" 467 | ] 468 | }, 469 | "execution_count": 53, 470 | "metadata": {}, 471 | "output_type": "execute_result" 472 | } 473 | ], 474 | "source": [ 475 | "A - B # elementwise subtraction" 476 | ] 477 | }, 478 | { 479 | "cell_type": "code", 480 | "execution_count": 54, 481 | "metadata": {}, 482 | "outputs": [ 483 | { 484 | "data": { 485 | "text/plain": [ 486 | "array([[ 2., 4., 6.],\n", 487 | " [ 8., 10., 12.],\n", 488 | " [14., 16., 18.]])" 489 | ] 490 | }, 491 | "execution_count": 54, 492 | "metadata": {}, 493 | "output_type": "execute_result" 494 | } 495 | ], 496 | "source": [ 497 | "A * B # elementwise multiplication" 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 56, 503 | "metadata": {}, 504 | "outputs": [ 505 | { 506 | "data": { 507 | "text/plain": [ 508 | "array([[2. , 1. , 0.66666667],\n", 509 | " [0.5 , 0.4 , 0.33333333],\n", 510 | " [0.28571429, 0.25 , 0.22222222]])" 511 | ] 512 | }, 513 | "execution_count": 56, 514 | "metadata": {}, 515 | "output_type": "execute_result" 516 | } 517 | ], 518 | "source": [ 519 | "A / B # elementwise division" 520 | ] 521 | }, 522 | { 523 | "cell_type": "code", 524 | "execution_count": 58, 525 | "metadata": {}, 526 | "outputs": [ 527 | { 528 | "data": { 529 | "text/plain": [ 530 | "array([[False, True, False],\n", 531 | " [False, False, False],\n", 532 | " [False, False, False]])" 533 | ] 534 | }, 535 | "execution_count": 58, 536 | "metadata": {}, 537 | "output_type": "execute_result" 538 | } 539 | ], 540 | "source": [ 541 | "A == B # elementwise equality" 542 | ] 543 | }, 544 | { 545 | "cell_type": "markdown", 546 | "metadata": {}, 547 | "source": [ 548 | "## Matrix multiplication\n", 549 | "\n", 550 | "Matrix multiplication is performed in Numpy using the ```.dot()``` operator. \n", 551 | "\n", 552 | "First let's look at a simple example: the inner product of two matrices (aka the \"dot product\"). " 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": 73, 558 | "metadata": {}, 559 | "outputs": [ 560 | { 561 | "name": "stdout", 562 | "output_type": "stream", 563 | "text": [ 564 | "(1, 4)\n" 565 | ] 566 | }, 567 | { 568 | "data": { 569 | "text/plain": [ 570 | "array([[1, 2, 3, 4]])" 571 | ] 572 | }, 573 | "execution_count": 73, 574 | "metadata": {}, 575 | "output_type": "execute_result" 576 | } 577 | ], 578 | "source": [ 579 | "A = numpy.array([[1, 2, 3, 4]])\n", 580 | "print(A.shape)\n", 581 | "A" 582 | ] 583 | }, 584 | { 585 | "cell_type": "code", 586 | "execution_count": 74, 587 | "metadata": {}, 588 | "outputs": [ 589 | { 590 | "name": "stdout", 591 | "output_type": "stream", 592 | "text": [ 593 | "(4, 1)\n" 594 | ] 595 | }, 596 | { 597 | "data": { 598 | "text/plain": [ 599 | "array([[5],\n", 600 | " [6],\n", 601 | " [7],\n", 602 | " [8]])" 603 | ] 604 | }, 605 | "execution_count": 74, 606 | "metadata": {}, 607 | "output_type": "execute_result" 608 | } 609 | ], 610 | "source": [ 611 | "B = numpy.array([[5, 6, 7, 8]]).T\n", 612 | "print(B.shape)\n", 613 | "B" 614 | ] 615 | }, 616 | { 617 | "cell_type": "code", 618 | "execution_count": 75, 619 | "metadata": {}, 620 | "outputs": [ 621 | { 622 | "data": { 623 | "text/plain": [ 624 | "array([[70]])" 625 | ] 626 | }, 627 | "execution_count": 75, 628 | "metadata": {}, 629 | "output_type": "execute_result" 630 | } 631 | ], 632 | "source": [ 633 | "dp = A.dot(B)\n", 634 | "dp" 635 | ] 636 | }, 637 | { 638 | "cell_type": "markdown", 639 | "metadata": {}, 640 | "source": [ 641 | "Note that the ```.dot()``` operator returns a single value (i.e. a *scalar*) but it returns it in the form of a matrix. Thus, if we wanted to work with that value we would need to reference it in the matrix:" 642 | ] 643 | }, 644 | { 645 | "cell_type": "code", 646 | "execution_count": 76, 647 | "metadata": {}, 648 | "outputs": [ 649 | { 650 | "data": { 651 | "text/plain": [ 652 | "70" 653 | ] 654 | }, 655 | "execution_count": 76, 656 | "metadata": {}, 657 | "output_type": "execute_result" 658 | } 659 | ], 660 | "source": [ 661 | "dp[0, 0]" 662 | ] 663 | }, 664 | { 665 | "cell_type": "markdown", 666 | "metadata": {}, 667 | "source": [ 668 | "The ```.dot()``` operator also performs matrix multiplication" 669 | ] 670 | }, 671 | { 672 | "cell_type": "code", 673 | "execution_count": 77, 674 | "metadata": {}, 675 | "outputs": [ 676 | { 677 | "data": { 678 | "text/plain": [ 679 | "array([[1., 0., 0., 0.],\n", 680 | " [0., 1., 0., 0.],\n", 681 | " [0., 0., 1., 0.],\n", 682 | " [0., 0., 0., 1.]])" 683 | ] 684 | }, 685 | "execution_count": 77, 686 | "metadata": {}, 687 | "output_type": "execute_result" 688 | } 689 | ], 690 | "source": [ 691 | "I = numpy.eye(B.shape[0])\n", 692 | "I" 693 | ] 694 | }, 695 | { 696 | "cell_type": "code", 697 | "execution_count": 78, 698 | "metadata": {}, 699 | "outputs": [ 700 | { 701 | "data": { 702 | "text/plain": [ 703 | "array([[5.],\n", 704 | " [6.],\n", 705 | " [7.],\n", 706 | " [8.]])" 707 | ] 708 | }, 709 | "execution_count": 78, 710 | "metadata": {}, 711 | "output_type": "execute_result" 712 | } 713 | ], 714 | "source": [ 715 | "I.dot(B) # multiply by identity to get original matrix" 716 | ] 717 | }, 718 | { 719 | "cell_type": "markdown", 720 | "metadata": {}, 721 | "source": [ 722 | "## Matrix inversion\n", 723 | "\n", 724 | "Matrix inversion for square matrices (when possible) can be performed using the ```numpy.linalg.inv()``` function." 725 | ] 726 | }, 727 | { 728 | "cell_type": "code", 729 | "execution_count": 87, 730 | "metadata": {}, 731 | "outputs": [ 732 | { 733 | "data": { 734 | "text/plain": [ 735 | "array([[1., 0., 0., 0.],\n", 736 | " [0., 1., 0., 0.],\n", 737 | " [0., 0., 1., 0.],\n", 738 | " [0., 0., 0., 1.]])" 739 | ] 740 | }, 741 | "execution_count": 87, 742 | "metadata": {}, 743 | "output_type": "execute_result" 744 | } 745 | ], 746 | "source": [ 747 | "I = numpy.eye(4)\n", 748 | "numpy.linalg.inv(I) # inverse of an identity is itself" 749 | ] 750 | }, 751 | { 752 | "cell_type": "markdown", 753 | "metadata": {}, 754 | "source": [ 755 | "Often in statistics we need to compute the pseudo-inverse of a matrix that is not square. We can do that using the ```numpy.linalg.pinv()``` function" 756 | ] 757 | }, 758 | { 759 | "cell_type": "code", 760 | "execution_count": 88, 761 | "metadata": {}, 762 | "outputs": [ 763 | { 764 | "data": { 765 | "text/plain": [ 766 | "array([[-0.57344016, 1.07747937, -0.50876169, -1.86218524],\n", 767 | " [ 0.0114388 , -0.02775375, 0.10517914, -0.38024641],\n", 768 | " [ 0.66925415, -1.08451724, 1.05243413, 0.34458032],\n", 769 | " [ 2.0575053 , -0.09195579, -1.54825252, 0.7635312 ],\n", 770 | " [-0.60547741, -0.46430286, 0.51902325, 1.8179072 ],\n", 771 | " [ 0.33913747, 0.80691863, -0.17380382, 2.25232951]])" 772 | ] 773 | }, 774 | "execution_count": 88, 775 | "metadata": {}, 776 | "output_type": "execute_result" 777 | } 778 | ], 779 | "source": [ 780 | "R = numpy.random.randn(6, 4)\n", 781 | "R" 782 | ] 783 | }, 784 | { 785 | "cell_type": "code", 786 | "execution_count": 92, 787 | "metadata": {}, 788 | "outputs": [ 789 | { 790 | "data": { 791 | "text/plain": [ 792 | "array([[ 0.07335528, 0.10388678, 0.5221196 , 0.13659959, -0.48529086,\n", 793 | " 0.34369183],\n", 794 | " [ 0.3710633 , 0.08452705, 0.19836166, -0.214768 , -0.45230208,\n", 795 | " 0.72858055],\n", 796 | " [ 0.11667684, 0.13872055, 0.69457962, -0.40039239, -0.42496194,\n", 797 | " 0.49235108],\n", 798 | " [-0.12434592, -0.04788307, -0.08896299, 0.02832385, 0.20907454,\n", 799 | " 0.16835376]])" 800 | ] 801 | }, 802 | "execution_count": 92, 803 | "metadata": {}, 804 | "output_type": "execute_result" 805 | } 806 | ], 807 | "source": [ 808 | "pinv = numpy.linalg.pinv(R)\n", 809 | "pinv" 810 | ] 811 | }, 812 | { 813 | "cell_type": "code", 814 | "execution_count": 95, 815 | "metadata": {}, 816 | "outputs": [ 817 | { 818 | "data": { 819 | "text/plain": [ 820 | "array([[ 1.00000000e+00, 3.33066907e-16, -6.10622664e-16,\n", 821 | " 0.00000000e+00],\n", 822 | " [-5.55111512e-17, 1.00000000e+00, 1.94289029e-16,\n", 823 | " 2.22044605e-16],\n", 824 | " [-1.11022302e-16, 5.55111512e-16, 1.00000000e+00,\n", 825 | " 5.55111512e-16],\n", 826 | " [-9.71445147e-17, 8.32667268e-17, 4.02455846e-16,\n", 827 | " 1.00000000e+00]])" 828 | ] 829 | }, 830 | "execution_count": 95, 831 | "metadata": {}, 832 | "output_type": "execute_result" 833 | } 834 | ], 835 | "source": [ 836 | "pinv.dot(R) # should give back an identity matrix, probably with small numeric differences in off-diagnoals" 837 | ] 838 | }, 839 | { 840 | "cell_type": "markdown", 841 | "metadata": {}, 842 | "source": [ 843 | "## Statistical modeling\n", 844 | "\n", 845 | "Now let's look at how to use linear algebra in Python to perform statistical modeling. We will fit the general linear model:\n", 846 | "\n", 847 | "$ Y = X * \\beta$\n", 848 | "\n", 849 | "where Y are the data, X is the *design matrix*, and $\\beta$ is a vector of model parameters. We can estimate the parameters using the following equation:\n", 850 | "\n", 851 | "$ \\hat{\\beta} = (X^T X)^{-1}X^T Y$\n", 852 | "\n", 853 | "We would generally want to include a column of ones in the design matrix (i.e. an intercept term) in addition to the independent variables of interest, in order to fit the mean of the data. Let's start by fitting a simple linear regression with five observations, using the following design matrix:\n", 854 | "\n", 855 | "$X = \\begin{bmatrix}\n", 856 | "-2 & 1\\\\ \n", 857 | "-1 & 1\\\\ \n", 858 | "0 & 1\\\\ \n", 859 | "1 & 1\\\\ \n", 860 | "2 & 1\n", 861 | "\\end{bmatrix}$\n", 862 | "\n", 863 | "The first columns reflects the linear term, and the second column reflects the intercept. Note that we have *centered* the linear term by removing its mean.\n" 864 | ] 865 | }, 866 | { 867 | "cell_type": "code", 868 | "execution_count": 107, 869 | "metadata": {}, 870 | "outputs": [ 871 | { 872 | "data": { 873 | "text/plain": [ 874 | "array([[-2., 1.],\n", 875 | " [-1., 1.],\n", 876 | " [ 0., 1.],\n", 877 | " [ 1., 1.],\n", 878 | " [ 2., 1.]])" 879 | ] 880 | }, 881 | "execution_count": 107, 882 | "metadata": {}, 883 | "output_type": "execute_result" 884 | } 885 | ], 886 | "source": [ 887 | "X = numpy.ones((5, 2))\n", 888 | "X[:, 0] = numpy.arange(-2, 3)\n", 889 | "X" 890 | ] 891 | }, 892 | { 893 | "cell_type": "markdown", 894 | "metadata": {}, 895 | "source": [ 896 | "Let's generate some data using this model:" 897 | ] 898 | }, 899 | { 900 | "cell_type": "code", 901 | "execution_count": 113, 902 | "metadata": {}, 903 | "outputs": [ 904 | { 905 | "data": { 906 | "text/plain": [ 907 | "array([-4., -1., 2., 5., 8.])" 908 | ] 909 | }, 910 | "execution_count": 113, 911 | "metadata": {}, 912 | "output_type": "execute_result" 913 | } 914 | ], 915 | "source": [ 916 | "beta = numpy.array([3, 2]) # slope = 3, mean = 2\n", 917 | "Y = X.dot(beta) \n", 918 | "Y" 919 | ] 920 | }, 921 | { 922 | "cell_type": "markdown", 923 | "metadata": {}, 924 | "source": [ 925 | "Now we can estimate the parameters from the data:" 926 | ] 927 | }, 928 | { 929 | "cell_type": "code", 930 | "execution_count": 114, 931 | "metadata": {}, 932 | "outputs": [ 933 | { 934 | "data": { 935 | "text/plain": [ 936 | "array([3., 2.])" 937 | ] 938 | }, 939 | "execution_count": 114, 940 | "metadata": {}, 941 | "output_type": "execute_result" 942 | } 943 | ], 944 | "source": [ 945 | "beta_hat = numpy.linalg.inv(X.T.dot(X)).dot(X.T).dot(Y)\n", 946 | "beta_hat" 947 | ] 948 | }, 949 | { 950 | "cell_type": "markdown", 951 | "metadata": {}, 952 | "source": [ 953 | "We could also use a built-in function from the statsmodels library to perfom linear regression on these data, which also provides statistics for the regression model. Statsmodels uses a design pattern that is common in Python, where the model is first configured and then fit in a separate step." 954 | ] 955 | }, 956 | { 957 | "cell_type": "code", 958 | "execution_count": 118, 959 | "metadata": {}, 960 | "outputs": [ 961 | { 962 | "name": "stdout", 963 | "output_type": "stream", 964 | "text": [ 965 | " OLS Regression Results \n", 966 | "==============================================================================\n", 967 | "Dep. Variable: y R-squared: 1.000\n", 968 | "Model: OLS Adj. R-squared: 1.000\n", 969 | "Method: Least Squares F-statistic: 4.721e+31\n", 970 | "Date: Sun, 18 Aug 2019 Prob (F-statistic): 6.80e-48\n", 971 | "Time: 09:19:41 Log-Likelihood: 165.26\n", 972 | "No. Observations: 5 AIC: -326.5\n", 973 | "Df Residuals: 3 BIC: -327.3\n", 974 | "Df Model: 1 \n", 975 | "Covariance Type: nonrobust \n", 976 | "==============================================================================\n", 977 | " coef std err t P>|t| [0.025 0.975]\n", 978 | "------------------------------------------------------------------------------\n", 979 | "x1 3.0000 4.37e-16 6.87e+15 0.000 3.000 3.000\n", 980 | "const 2.0000 6.17e-16 3.24e+15 0.000 2.000 2.000\n", 981 | "==============================================================================\n", 982 | "Omnibus: nan Durbin-Watson: 0.207\n", 983 | "Prob(Omnibus): nan Jarque-Bera (JB): 0.522\n", 984 | "Skew: 0.035 Prob(JB): 0.770\n", 985 | "Kurtosis: 1.419 Cond. No. 1.41\n", 986 | "==============================================================================\n", 987 | "\n", 988 | "Warnings:\n", 989 | "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n" 990 | ] 991 | }, 992 | { 993 | "name": "stderr", 994 | "output_type": "stream", 995 | "text": [ 996 | "/Users/poldrack/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/stats/stattools.py:72: ValueWarning: omni_normtest is not valid with less than 8 observations; 5 samples were given.\n", 997 | " \"samples were given.\" % int(n), ValueWarning)\n" 998 | ] 999 | } 1000 | ], 1001 | "source": [ 1002 | "model = statsmodels.api.OLS(Y, X) # set up the model\n", 1003 | "results = model.fit() # fit the model\n", 1004 | "print(results.summary())" 1005 | ] 1006 | }, 1007 | { 1008 | "cell_type": "code", 1009 | "execution_count": null, 1010 | "metadata": {}, 1011 | "outputs": [], 1012 | "source": [] 1013 | }, 1014 | { 1015 | "cell_type": "code", 1016 | "execution_count": null, 1017 | "metadata": {}, 1018 | "outputs": [], 1019 | "source": [] 1020 | } 1021 | ], 1022 | "metadata": { 1023 | "kernelspec": { 1024 | "display_name": "Python 3", 1025 | "language": "python", 1026 | "name": "python3" 1027 | }, 1028 | "language_info": { 1029 | "codemirror_mode": { 1030 | "name": "ipython", 1031 | "version": 3 1032 | }, 1033 | "file_extension": ".py", 1034 | "mimetype": "text/x-python", 1035 | "name": "python", 1036 | "nbconvert_exporter": "python", 1037 | "pygments_lexer": "ipython3", 1038 | "version": "3.6.8" 1039 | } 1040 | }, 1041 | "nbformat": 4, 1042 | "nbformat_minor": 2 1043 | } 1044 | -------------------------------------------------------------------------------- /notebooks/arrest_impulsivity.csv: -------------------------------------------------------------------------------- 1 | ,mean_impulsivity,upps_impulsivity_survey.lack_of_perseverance,upps_impulsivity_survey.lack_of_premeditation,upps_impulsivity_survey.negative_urgency,upps_impulsivity_survey.positive_urgency,upps_impulsivity_survey.sensation_seeking,Sex,Age,EverArrested 2 | s004,1.911021117988756,1.5,1.6363636363999998,1.5833333333,1.1428571429,1.9166666666999999,0,35,False 3 | s005,2.0881857843661518,1.7000000000000002,1.3636363636000002,1.75,1.0,2.8333333332999997,0,36,True 4 | s009,2.9619909725619222,2.7,2.7272727273000004,3.0,3.0,2.3333333333,0,26,False 5 | s011,2.0608468072968638,1.7000000000000002,2.0909090909,2.0,2.0714285714,2.1666666667,1,27,False 6 | s012,2.2751280620632723,1.9,1.4545454544999998,2.3333333333,2.0,1.3333333333,1,36,False 7 | s013,1.9596531958591445,1.6,2.0909090909,1.5,1.1428571429,2.1666666667,1,50,False 8 | s015,2.113402070366534,1.1,2.1818181818,1.4166666666999999,1.2142857143,3.1666666667000003,0,27,False 9 | s016,1.5435386204955006,1.2,1.0,1.9166666666999999,1.0,1.0833333333,1,20,False 10 | s017,2.345413687274446,2.1,1.0,1.6666666666999999,1.3571428571000002,3.0,0,31,False 11 | s018,1.9675386744998673,1.9,1.9090909091,2.0,2.0,2.1666666667,0,34,True 12 | s019,1.9053944124854445,1.3,1.3636363636000002,1.5,1.2142857143,2.3333333333,1,32,True 13 | s023,2.196274685478321,1.5,1.3636363636000002,2.0,1.3571428571000002,2.1666666667,0,46,True 14 | s025,2.8076185216104275,2.8,1.8181818182,2.9166666667000003,2.4285714286,2.0,1,39,False 15 | s028,2.5819026450424802,2.0,2.0,2.5833333333,2.0714285714,2.6666666667000003,0,31,False 16 | s030,2.6395744801563303,2.1,2.1818181818,2.1666666667,2.1428571429,2.8333333332999997,0,27,False 17 | s031,2.41112039642685,2.1,2.2727272727,2.1666666667,2.0714285714,2.9166666667000003,0,34,False 18 | s032,1.7293361278178305,1.0,1.2727272726999999,1.25,1.0714285714,1.5,0,38,False 19 | s033,2.107665108018436,1.8,1.6363636363999998,1.6666666666999999,1.6428571428999998,2.3333333333,1,46,True 20 | s035,2.2897493537104276,2.5,1.4545454544999998,2.25,1.3571428571000002,1.5833333333,1,27,False 21 | s036,2.2823785394743337,1.9,2.0909090909,2.1666666667,2.3571428571,2.9166666667000003,0,29,False 22 | s038,1.6912280707415728,1.1,1.0,2.0,1.0714285714,1.1666666667,1,32,False 23 | s039,2.0327171689258114,2.1,1.8181818182,1.8333333333,1.1428571429,1.1666666667,1,40,False 24 | s040,2.945710120159117,2.8,3.0,2.25,2.0714285714,2.4166666667,0,49,True 25 | s041,2.0201329101042185,1.4,1.0,1.75,1.1428571429,2.3333333333,1,34,False 26 | s042,2.188901184368516,2.1,1.5454545455000002,2.0,1.1428571429,2.3333333333,0,28,False 27 | s043,2.58887702945633,2.2,2.1818181818,2.0,1.0714285714,2.6666666667000003,0,41,True 28 | s044,1.8641945632899177,1.1,1.0,2.0,1.0714285714,1.3333333333,1,36,False 29 | s046,2.4527540158980354,2.1,1.8181818182,2.0,2.0,1.9166666666999999,0,25,False 30 | s047,1.9376117139148528,1.2,1.9090909091,1.0833333333,1.2857142857,3.5,0,26,False 31 | s048,1.9510964300245368,3.0,1.0,1.8333333333,1.1428571429,1.5,0,25,False 32 | s049,2.1552840469295096,1.9,1.5454545455000002,2.0,1.5714285713999998,1.75,1,59,False 33 | s051,2.0675445841112183,1.2,1.1818181818,1.3333333333,1.0,2.3333333333,0,30,True 34 | s052,2.256245415531025,2.0,2.0,2.0,1.1428571429,2.0833333333,1,50,False 35 | s053,2.2386186848105964,2.8,1.8181818182,1.9166666666999999,1.7857142857,1.5833333333,0,44,False 36 | s054,2.8845444805755824,2.6,2.0,2.9166666667000003,2.1428571429,2.5833333333,0,23,False 37 | s056,1.6077952477708852,1.1,1.0,1.25,1.0,2.25,0,48,False 38 | s058,1.8695829265220896,1.4,1.4545454544999998,1.5833333333,1.5714285713999998,3.3333333332999997,0,34,False 39 | s059,2.4395326046484804,2.3,2.1818181818,2.3333333333,1.4285714286000002,1.9166666666999999,1,30,False 40 | s060,1.7354995658949082,1.7000000000000002,1.1818181818,1.8333333333,1.0714285714,1.0833333333,1,49,False 41 | s062,1.535182661470408,1.5,1.0909090909,1.75,1.0714285714,1.0833333333,1,26,False 42 | s063,2.614195343407216,2.0,2.0909090909,2.3333333333,2.1428571429,2.0833333333,1,40,False 43 | s064,2.3724806850703994,1.7000000000000002,2.0909090909,2.1666666667,2.3571428571,2.3333333333,0,25,True 44 | s066,1.6480822215251347,1.0,1.0909090909,2.3333333333,1.2142857143,1.4166666666999999,1,27,False 45 | s068,2.6428439633124747,2.2,2.1818181818,2.5833333333,2.4285714286,2.6666666667000003,0,25,False 46 | s071,2.22588809560039,1.7000000000000002,1.9090909091,1.75,1.1428571429,2.5,1,40,False 47 | s074,2.0603333677708786,1.0,1.1818181818,1.8333333333,1.7142857143,2.8333333332999997,1,50,False 48 | s080,2.6378633838978045,1.8,2.7272727273000004,2.5833333333,2.0,2.1666666667,1,43,False 49 | s081,1.7784029796383534,1.9,1.0,1.3333333333,1.1428571429,1.5,1,42,False 50 | s082,1.7483783130680053,1.5,1.1818181818,1.0,1.1428571429,1.3333333333,0,29,False 51 | s085,2.4583219006589214,1.8,1.5454545455000002,1.0833333333,1.0,3.5,1,36,False 52 | s087,2.0631181335791413,1.6,1.2727272726999999,3.0,1.1428571429,1.3333333333,1,49,False 53 | s088,1.7766445018966097,1.7000000000000002,1.2727272726999999,1.25,1.0714285714,2.1666666667,0,27,False 54 | s090,1.490845136145852,1.0,1.0,1.0,1.0,1.5,1,42,False 55 | s091,2.4651434124291334,2.5,1.9090909091,1.6666666666999999,1.1428571429,1.25,1,30,False 56 | s092,2.1837105430088024,2.3,1.0909090909,2.4166666667,1.7142857143,2.0,1,33,False 57 | s094,2.017874216989918,1.6,1.5454545455000002,2.0,2.0,2.6666666667000003,0,40,True 58 | s096,2.5033622377601676,2.9,1.3636363636000002,2.1666666667,1.9285714286,1.4166666666999999,1,39,False 59 | s097,2.1810295801454735,1.6,1.3636363636000002,2.1666666667,1.0714285714,2.5,1,33,False 60 | s099,2.1767629111712785,2.0,1.9090909091,2.4166666667,1.9285714286,2.0,1,26,False 61 | s100,2.2851542854962137,1.3,2.0,2.25,2.2857142857,2.9166666667000003,0,20,False 62 | s101,2.4654580780481776,1.9,2.2727272727,2.6666666667000003,1.5,3.0,1,32,False 63 | s102,2.147962096390045,1.9,1.4545454544999998,2.1666666667,1.5,1.5,1,21,False 64 | s103,3.2921442881866927,2.4,3.0,3.6666666667,3.2142857143,3.6666666667,1,31,False 65 | s105,2.1938249730516612,1.3,1.8181818182,1.9166666666999999,1.6428571428999998,2.75,1,25,False 66 | s106,1.3922871493854447,1.0,1.0,1.0,1.2857142857,1.25,1,35,False 67 | s107,2.5793226805424485,2.1,2.0,2.5833333333,1.9285714286,2.5,0,35,True 68 | s108,2.496981887567441,2.7,1.8181818182,3.0833333332999997,1.1428571429,1.5,1,43,False 69 | s109,2.140073547022089,1.9,1.8181818182,1.8333333333,1.4285714286000002,2.8333333332999997,0,25,False 70 | s112,2.230796147366774,1.8,1.7272727273,1.75,1.8571428571000002,2.75,0,24,False 71 | s113,2.4107903182375447,2.2,1.8181818182,1.4166666666999999,1.0714285714,1.75,1,24,False 72 | s114,2.3682888887569193,2.3,2.1818181818,2.5833333333,1.0,3.0,0,27,False 73 | s117,2.222984864618399,1.3,2.3636363636,2.0833333333,1.6428571428999998,3.75,0,32,False 74 | s122,2.1703253102931073,1.8,1.0,2.0833333333,1.2142857143,3.0833333332999997,1,25,False 75 | s123,2.3557079326621673,1.7000000000000002,1.6363636363999998,2.25,2.1428571429,2.5833333333,0,24,False 76 | s125,1.3986068290171305,1.0,1.1818181818,1.0,1.0,1.25,1,30,False 77 | s126,1.8203054273965558,1.2,1.4545454544999998,1.0,1.0,3.3333333332999997,0,34,False 78 | s127,2.2667942226481212,1.7000000000000002,2.3636363636,2.0,1.5714285713999998,2.4166666667,0,28,False 79 | s128,2.659433494293415,2.8,2.0,2.5,2.0,1.3333333333,1,26,False 80 | s130,2.022536602939353,1.2,1.7272727273,1.8333333333,1.0714285714,1.8333333333,1,33,False 81 | s132,3.028370085016283,2.2,2.9090909091,3.1666666667000003,3.0714285714,3.5833333332999997,0,27,True 82 | s133,1.5904823974332005,1.4,1.0,1.25,1.1428571429,1.5833333333,1,29,False 83 | s134,2.362055410478934,1.9,1.7272727273,2.6666666667000003,2.3571428571,2.3333333333,0,22,False 84 | s136,1.8970098333394827,1.4,1.7272727273,1.5833333333,1.3571428571000002,1.3333333333,0,43,False 85 | s139,2.2028932447522234,1.2,1.0909090909,2.0833333333,1.5714285713999998,2.9166666667000003,1,35,False 86 | s140,2.267293697706019,2.1,2.0,2.0,2.0,1.9166666666999999,0,35,False 87 | s141,1.4888068488186788,1.0,1.0909090909,1.0,1.2142857143,1.9166666666999999,0,24,False 88 | s142,3.2345004098179646,1.5,3.0909090909,3.0,3.0,3.9166666667,0,30,False 89 | s144,2.585726402288996,2.3,1.0,2.5,2.0,3.8333333332999997,0,23,False 90 | s146,2.167821660158922,2.3,1.9090909091,2.4166666667,1.2142857143,1.0833333333,1,45,False 91 | s150,1.5895454466632224,1.0,1.0909090909,1.75,1.1428571429,2.1666666667,1,28,False 92 | s151,2.2851774879466547,1.5,1.7272727273,2.5,3.0,1.9166666666999999,0,34,False 93 | s154,2.4568722194704,2.2,2.0,2.1666666667,2.0,2.4166666667,0,47,True 94 | s156,1.971277421618436,1.1,1.4545454544999998,1.25,1.0714285714,3.5,0,37,True 95 | s158,2.1949981873366995,1.8,1.8181818182,2.25,1.4285714286000002,1.5833333333,1,27,False 96 | s160,1.7910055374635303,1.1,1.2727272726999999,1.4166666666999999,1.1428571429,2.5833333333,0,50,False 97 | s161,2.322595089166774,1.7000000000000002,1.3636363636000002,2.5,2.5,1.75,1,30,False 98 | s162,3.285437343284263,2.5,3.0,3.0,3.0,3.3333333332999997,0,26,False 99 | s165,1.6286098175198314,1.7000000000000002,1.0909090909,1.0,1.1428571429,1.6666666666999999,0,31,False 100 | s167,2.2820405169156373,1.4,1.1818181818,1.75,1.1428571429,1.9166666666999999,1,34,False 101 | s168,2.5293250562732785,2.1,1.9090909091,2.0833333333,1.7857142857,2.5,1,33,False 102 | s172,2.695729544324943,2.8,1.9090909091,2.5833333333,2.2857142857,2.6666666667000003,0,29,False 103 | s173,1.8466867978868926,1.2,1.4545454544999998,1.5833333333,1.0,2.75,0,26,False 104 | s175,2.4774256734533595,1.8,1.9090909091,2.25,2.0,3.0833333332999997,0,30,True 105 | s177,2.5116941965489707,2.4,1.3636363636000002,2.8333333332999997,1.2142857143,1.25,0,37,False 106 | s179,2.370668255971294,1.4,2.0,2.5,1.4285714286000002,3.5833333332999997,1,30,False 107 | s180,2.3913500683177227,2.0,1.5454545455000002,2.1666666667,1.5,3.1666666667000003,0,33,False 108 | s183,1.9237195306665338,1.3,1.6363636363999998,1.0833333333,1.3571428571000002,3.0833333332999997,0,33,False 109 | s184,2.294567734537552,1.5,2.2727272727,2.3333333333,1.7142857143,2.8333333332999997,1,48,False 110 | s185,2.2974450436328184,1.6,2.1818181818,1.25,1.0,2.75,0,35,True 111 | s186,1.875848874328942,1.2,1.1818181818,1.5,1.2142857143,2.4166666667,0,39,False 112 | s188,1.83743601635787,1.1,1.2727272726999999,1.9166666666999999,1.0714285714,2.75,0,31,False 113 | s189,2.80287414345633,2.5,2.2727272727,2.25,2.1428571429,2.25,1,29,False 114 | s190,1.8382129645148524,1.4,1.0,1.75,1.5714285713999998,2.25,0,29,False 115 | s193,1.9348423974481774,1.2,1.6363636363999998,1.4166666666999999,1.0714285714,2.6666666667000003,1,30,False 116 | s195,3.3043854395493275,3.0,2.9090909091,3.0,2.7142857143,3.6666666667,0,44,True 117 | s198,2.4841433369022097,2.1,2.1818181818,2.0,1.9285714286,3.0,1,27,False 118 | s199,3.374387879005296,2.4,2.7272727273000004,3.1666666667000003,2.8571428571,4.0,0,23,True 119 | s201,1.7945097448517693,1.4,1.1818181818,1.25,1.0714285714,2.8333333332999997,1,48,False 120 | s202,2.06858645554105,1.1,2.5454545455,1.25,1.0714285714,3.75,0,26,False 121 | s203,2.0514382298197344,1.9,1.3636363636000002,1.6666666666999999,1.5714285713999998,2.1666666667,1,50,False 122 | s205,2.1592415576678228,2.0,2.0,2.0,2.0,1.9166666666999999,0,33,False 123 | s207,1.583859509118832,1.0,1.0,1.25,1.0,1.0,1,33,False 124 | s210,2.3679314468689814,1.2,2.0,2.8333333332999997,2.6428571429,4.0,0,33,True 125 | s212,2.102998289328372,2.0,1.1818181818,1.5833333333,1.1428571429,2.5833333333,1,32,False 126 | s214,2.3637516207275797,1.6,2.0909090909,1.6666666666999999,1.1428571429,3.0833333332999997,0,45,True 127 | s215,1.9839348303857527,1.5,1.4545454544999998,1.25,1.1428571429,1.4166666666999999,0,46,False 128 | s216,1.9976072930685156,1.2,1.0,2.3333333333,2.0,1.1666666667,1,47,False 129 | s217,2.769293514287734,2.3,2.0909090909,2.9166666667000003,2.1428571429,2.5833333333,0,26,False 130 | s219,2.7522538525962137,2.8,1.8181818182,2.8333333332999997,2.0714285714,2.8333333332999997,0,34,True 131 | s220,2.3378657705921544,1.2,2.2727272727,2.0833333333,2.0714285714,2.75,1,36,False 132 | s221,1.613035014271687,1.0,1.1818181818,1.0833333333,1.0,1.9166666666999999,1,29,False 133 | s222,2.469973204822236,2.4,1.8181818182,2.4166666667,1.8571428571000002,1.6666666666999999,1,32,False 134 | s223,1.7306880771413082,1.2,1.1818181818,1.1666666667,1.0,3.0,0,45,False 135 | s226,2.6666559061277844,1.2,2.2727272727,2.4166666667,1.8571428571000002,3.5833333332999997,1,30,False 136 | s227,1.847408820858468,1.4,1.3636363636000002,1.6666666666999999,1.2142857143,2.5833333333,0,37,False 137 | s228,2.3357044146356483,2.6,1.0,2.6666666667000003,1.9285714286,1.0,0,36,False 138 | s230,1.967070615562275,1.0,1.4545454544999998,2.0,1.1428571429,3.5,0,46,False 139 | s233,2.5273154912882054,2.7,1.4545454544999998,3.3333333332999997,2.9285714286,1.0,1,42,False 140 | s234,2.8866552955319773,1.8,2.3636363636,3.0833333332999997,3.0,2.4166666667,1,29,False 141 | s235,1.9699149649090772,1.9,1.7272727273,2.0833333333,1.8571428571000002,1.3333333333,1,29,False 142 | s236,1.6389100141632769,1.1,1.5454545455000002,1.25,1.0,2.5833333333,1,50,False 143 | s237,2.5172391016490563,2.0,2.1818181818,2.4166666667,2.1428571429,2.4166666667,0,31,True 144 | s240,2.5846504926238807,1.8,2.2727272727,2.25,2.4285714286,2.4166666667,0,25,False 145 | s241,1.8275103027743878,2.3,1.1818181818,1.5,1.1428571429,1.5,0,25,False 146 | s243,1.7050143722573696,2.0,1.4545454544999998,1.25,1.2857142857,2.0833333333,0,24,False 147 | s244,2.314730927864702,2.4,2.0,2.1666666667,1.0714285714,1.6666666666999999,1,37,False 148 | s245,2.599837534715637,2.6,2.0,2.4166666667,2.0,1.9166666666999999,1,41,False 149 | s246,2.9599759943712782,3.5,2.2727272727,2.75,2.0714285714,2.0,1,26,False 150 | s252,1.9948189095013389,1.4,1.2727272726999999,1.8333333333,1.0714285714,1.9166666666999999,0,31,True 151 | s256,2.016399191652165,1.6,1.0909090909,1.8333333333,1.1428571429,2.6666666667000003,1,26,True 152 | s257,1.8501506296415728,1.5,1.3636363636000002,1.5,1.5714285713999998,2.3333333333,0,28,False 153 | s259,1.8136893505351546,1.0,1.3636363636000002,1.0,1.1428571429,3.0,0,26,False 154 | s260,1.9422861492332006,1.6,1.9090909091,1.5833333333,1.0,2.9166666667000003,1,39,False 155 | s266,2.4577101866245368,1.2,2.2727272727,2.3333333333,2.7857142857,3.25,0,41,False 156 | s268,1.6782122232090766,1.1,1.3636363636000002,1.0,1.0,1.3333333333,1,38,False 157 | s270,1.99839369751214,2.1,2.1818181818,1.6666666666999999,1.1428571429,1.8333333333,1,37,True 158 | s271,2.115123252074383,1.9,1.8181818182,2.0,1.7857142857,1.75,0,23,False 159 | s273,1.6663952667517696,1.2,1.5454545455000002,1.3333333333,1.0714285714,1.6666666666999999,0,33,False 160 | s274,2.0268182160227655,2.1,1.2727272726999999,1.6666666666999999,1.5714285713999998,2.0,0,41,False 161 | s276,1.8729720590648529,1.2,1.6363636363999998,1.9166666666999999,1.2857142857,2.9166666667000003,0,39,True 162 | s278,2.5105638454378596,2.1,1.6363636363999998,3.25,1.8571428571000002,1.75,1,37,False 163 | s282,1.720334237579592,1.3,1.3636363636000002,1.1666666667,1.2857142857,2.0833333333,0,50,True 164 | s283,2.798140450891099,2.2,1.9090909091,3.0833333332999997,3.0,2.5833333333,0,28,False 165 | s284,2.0452702222288344,2.1,1.3636363636000002,1.9166666666999999,1.6428571428999998,1.9166666666999999,0,35,False 166 | s288,1.8911392558346722,2.4,1.0,1.75,1.1428571429,1.25,0,28,False 167 | s292,2.1940278967799873,1.7000000000000002,1.8181818182,2.25,1.2857142857,1.8333333333,1,37,False 168 | s293,2.3991746019355435,2.6,1.7272727273,1.9166666666999999,1.5714285713999998,1.5,1,26,False 169 | s294,2.3851974806685154,2.2,1.5454545455000002,3.0833333332999997,2.1428571429,1.4166666666999999,1,23,False 170 | s295,1.803559650019086,1.1,1.6363636363999998,2.5,1.4285714286000002,2.1666666667,0,26,True 171 | s296,2.217093932204036,1.8,2.0,1.6666666666999999,1.2857142857,3.0,1,32,False 172 | s297,2.2987339947644707,1.8,1.2727272726999999,2.6666666667000003,1.7857142857,1.8333333333,1,40,False 173 | s298,2.323498603917131,1.9,2.1818181818,2.0833333333,1.4285714286000002,2.25,1,35,False 174 | s299,2.4060904853072165,2.1,2.0909090909,1.75,2.0714285714,2.4166666667,1,36,False 175 | s301,1.892718543942448,1.1,1.0,2.3333333333,1.2142857143,2.5,0,27,False 176 | s302,1.9719408290298892,1.3,1.4545454544999998,1.8333333333,2.8571428571,1.25,0,31,False 177 | s304,2.467297668520226,3.1,1.6363636363999998,2.9166666667000003,1.2142857143,2.3333333333,1,44,False 178 | s305,2.000788314765983,1.8,1.2727272726999999,2.5,1.1428571429,1.5833333333,0,28,False 179 | s307,2.0998812948757433,1.2,1.4545454544999998,1.6666666666999999,1.3571428571000002,3.5833333332999997,0,28,False 180 | s313,1.6408732863351823,1.1,1.0909090909,1.0,1.0,2.25,1,23,False 181 | s314,2.2830263842535596,1.8,1.9090909091,1.9166666666999999,1.9285714286,2.0,0,27,False 182 | s316,1.9858658277411128,1.8,2.0,1.3333333333,1.0,2.1666666667,1,31,False 183 | s317,2.1117931578311375,1.9,2.7272727273000004,1.4166666666999999,1.0714285714,1.6666666666999999,1,28,False 184 | s323,2.055823145781997,1.4,1.3636363636000002,1.5833333333,1.1428571429,2.3333333333,0,34,True 185 | s324,2.1163661329445516,1.2,1.4545454544999998,1.6666666666999999,1.0,2.6666666667000003,0,28,False 186 | s325,1.9826311110086234,1.5,1.3636363636000002,1.75,1.2142857143,2.3333333333,1,42,False 187 | s328,1.9493327322864689,1.4,1.8181818182,1.3333333333,1.2142857143,3.1666666667000003,0,25,False 188 | s330,2.0388210248870755,1.4,1.5454545455000002,1.6666666666999999,1.3571428571000002,1.8333333333,0,24,False 189 | s334,2.0172469072153296,1.8,1.9090909091,1.5833333333,1.0714285714,2.8333333332999997,1,33,True 190 | s335,3.2672201470337257,2.9,3.1818181818,3.5833333332999997,2.9285714286,3.5833333332999997,0,33,False 191 | s336,2.665531549915723,2.3,2.0,2.25,2.0714285714,2.25,0,26,False 192 | s338,2.868101525548656,2.7,2.1818181818,3.0,2.2857142857,2.5833333333,1,40,False 193 | s340,2.208135115099867,1.2,1.0909090909,2.0,2.0714285714,2.6666666667000003,0,29,False 194 | s342,2.041035547988756,1.1,1.2727272726999999,2.0,1.7857142857,3.1666666667000003,0,27,False 195 | s343,2.2973848958122676,2.7,1.3636363636000002,2.4166666667,1.2857142857,1.6666666666999999,1,20,False 196 | s346,1.828885623897966,1.4,1.4545454544999998,1.25,1.0,2.6666666667000003,0,42,False 197 | s349,2.0045575711334402,1.5,1.6363636363999998,2.0,1.9285714286,2.0833333333,0,33,False 198 | s350,2.185192427052224,2.0,1.3636363636000002,2.6666666667000003,2.5,1.8333333333,1,35,False 199 | s354,1.9981015930979658,1.0,1.3636363636000002,2.0833333333,2.0714285714,2.1666666667,1,35,True 200 | s355,2.4984920903633347,2.6,1.7272727273,2.5833333333,2.0,2.1666666667,0,32,False 201 | s357,1.6740877887791166,1.1,1.3636363636000002,1.1666666667,1.0,2.0833333333,1,49,False 202 | s358,1.6260220272605759,1.1,1.0909090909,1.4166666666999999,1.0714285714,1.5833333333,0,24,False 203 | s360,1.385731377362843,1.1,1.0,1.0833333333,1.0,1.1666666667,1,43,False 204 | s362,1.410456858940053,1.2,1.0,1.0,1.0,1.0,1,28,False 205 | s363,1.6663951580295098,1.0,1.0909090909,1.75,1.0714285714,1.8333333333,1,49,False 206 | s364,2.582744758062409,2.5,1.8181818182,2.5833333333,1.7857142857,2.1666666667,0,26,True 207 | s365,2.7922502573707026,2.3,1.9090909091,3.0,2.0,3.4166666667000003,0,43,True 208 | s368,1.7982134485517693,1.8,1.0,1.5,1.0714285714,1.25,0,50,False 209 | s369,2.37393547516467,1.4,2.0,2.9166666667000003,1.9285714286,3.0,1,33,False 210 | s375,2.57274566894393,2.1,2.0,2.0833333333,2.1428571429,2.8333333332999997,0,48,True 211 | s376,2.285057976696176,2.0,2.0,2.0,2.0,2.4166666667,0,39,False 212 | s377,1.9946440517521111,1.6,2.0909090909,1.4166666666999999,1.2857142857,2.6666666667000003,0,34,True 213 | s383,2.2207328511393527,2.2,1.8181818182,2.25,1.2142857143,1.8333333333,1,50,False 214 | s384,2.5220943813865806,2.6,2.0,1.25,1.2142857143,3.8333333332999997,0,25,False 215 | s386,2.5921895714072165,2.9,3.1818181818,1.9166666666999999,1.7857142857,1.75,1,44,False 216 | s387,2.023821640388997,1.9,1.9090909091,2.0833333333,1.1428571429,1.75,1,48,False 217 | s388,2.357942731402913,1.7000000000000002,1.9090909091,1.9166666666999999,2.0,3.6666666667,1,35,True 218 | s389,1.9060197131076666,1.9,1.2727272726999999,1.5,1.0714285714,1.8333333333,1,50,False 219 | s390,2.6082305032099566,2.3,2.1818181818,2.75,1.7857142857,2.8333333332999997,1,27,False 220 | s394,1.9995551661112185,1.9,1.4545454544999998,1.5,1.0714285714,2.25,1,26,False 221 | s396,2.0588768980783207,1.2,1.2727272726999999,2.0,1.2857142857,2.25,0,35,False 222 | s397,2.40435012959661,2.4,1.8181818182,2.0,1.8571428571000002,2.0833333333,0,40,False 223 | s398,2.5128370590217077,1.7000000000000002,1.9090909091,2.3333333333,2.2142857143,2.8333333332999997,1,27,False 224 | s399,1.732701183040658,1.1,1.2727272726999999,2.0833333333,1.0,1.5,1,43,True 225 | s400,2.3008559297800923,1.7000000000000002,2.0,2.5833333333,1.4285714286000002,2.5,1,32,False 226 | s403,2.9196320615077793,2.8,1.5454545455000002,3.6666666667,2.2857142857,1.1666666667,1,22,False 227 | s405,1.8536345936042187,1.4,1.4545454544999998,1.6666666666999999,1.1428571429,1.8333333333,1,39,False 228 | s406,2.5305538002559453,2.0,2.6363636364,2.0,2.0,3.0833333332999997,0,25,False 229 | s407,2.6629491826448346,2.4,2.3636363636,2.25,2.2142857143,1.75,1,29,False 230 | s409,2.205064219756894,2.0,2.0,2.0833333333,2.0,2.0,1,41,False 231 | s410,2.186822131820188,1.6,1.2727272726999999,3.0833333332999997,1.5714285713999998,1.25,1,26,False 232 | s411,1.7188854758332006,1.7000000000000002,1.4545454544999998,1.4166666666999999,1.0,1.6666666666999999,0,32,False 233 | s414,2.310135930601364,1.6,2.0909090909,2.3333333333,1.7857142857,1.5833333333,1,45,False 234 | s415,1.8793368162966055,1.1,1.7272727273,1.4166666666999999,1.0,3.1666666667000003,1,38,True 235 | s418,2.2583744574788067,2.1,1.0,2.4166666667,1.7857142857,1.75,1,21,True 236 | s419,2.150284387229939,1.5,1.2727272726999999,2.3333333333,1.7142857143,2.9166666667000003,1,25,False 237 | s420,3.052441727751298,2.6,2.0,2.5,2.2857142857,2.75,1,34,True 238 | s421,1.556775257107325,1.2,1.0909090909,1.3333333333,1.0,1.3333333333,1,33,False 239 | s422,2.045058008198035,1.4,1.8181818182,1.5833333333,1.1428571429,2.1666666667,0,36,False 240 | s423,2.384417314839353,1.6,2.5454545455,2.6666666667000003,1.3571428571000002,1.75,1,31,True 241 | s425,2.405465562410978,2.1,1.1818181818,2.75,2.1428571429,1.8333333333,1,34,True 242 | s426,2.51813994158069,1.8,1.6363636363999998,2.8333333332999997,2.2857142857,2.5,0,37,True 243 | s427,2.317420294373279,1.7000000000000002,1.9090909091,2.0833333333,1.9285714286,2.25,0,34,False 244 | s428,2.0845629245264408,1.9,2.0909090909,2.0,2.0,2.0,1,50,False 245 | s429,1.90813883195886,1.0,1.0,1.4166666666999999,1.5,3.8333333332999997,0,24,False 246 | s430,1.9484325353854943,1.3,1.4545454544999998,1.8333333333,1.2142857143,1.6666666666999999,1,32,False 247 | s431,2.192343949804212,1.7000000000000002,1.9090909091,2.0,1.7857142857,2.4166666667,1,34,False 248 | s432,1.5621765540300017,1.1,1.0,1.25,1.1428571429,1.3333333333,1,37,False 249 | s433,2.649555724884631,2.5,1.7272727273,2.8333333332999997,2.2142857143,2.9166666667000003,1,28,True 250 | s434,1.7904885036202576,1.1,1.3636363636000002,1.4166666666999999,1.0714285714,2.0833333333,1,34,False 251 | s435,1.8306940376332004,1.2,1.0909090909,2.0,1.0714285714,2.8333333332999997,1,47,False 252 | s438,2.200357825607721,2.5,1.3636363636000002,1.9166666666999999,1.5,2.0,0,38,False 253 | s439,2.328855257253068,2.6,1.6363636363999998,1.6666666666999999,2.0,2.4166666667,0,32,False 254 | s441,3.139402362234784,2.4,2.0,3.4166666667000003,3.1428571429,2.5833333333,0,40,True 255 | s443,1.926399968040621,1.1,1.4545454544999998,1.9166666666999999,1.7857142857,3.4166666667000003,0,31,True 256 | s444,2.1270280139854942,1.9,1.8181818182,1.5833333333,1.1428571429,1.75,1,31,True 257 | s445,2.375824389810428,2.2,1.5454545455000002,2.1666666667,2.0,2.0833333333,0,28,False 258 | s446,1.8362605865962136,2.2,1.0909090909,1.5833333333,1.0714285714,2.3333333333,0,25,True 259 | s448,2.6038120943896628,2.2,1.6363636363999998,2.75,2.4285714286,3.3333333332999997,0,34,True 260 | s449,2.0500121165889964,1.8,1.2727272726999999,2.25,1.4285714286000002,2.0,1,37,False 261 | s450,2.289600678497609,1.7000000000000002,1.4545454544999998,2.4166666667,1.7857142857,2.9166666667000003,1,35,False 262 | s451,1.6621503112565845,1.3,1.6363636363999998,1.5,1.0,1.0833333333,1,36,False 263 | s454,1.9846000209283718,1.5,1.3636363636000002,1.3333333333,1.0,1.25,1,34,False 264 | s456,2.340302248279436,1.1,1.5454545455000002,1.5,1.7142857143,3.5,0,27,False 265 | s457,2.103527210959767,1.5,2.2727272727,1.3333333333,1.0,2.3333333333,1,47,False 266 | s458,3.139267918368244,3.5,2.6363636364,3.25,1.4285714286000002,2.1666666667,1,27,False 267 | s459,2.958308748326208,2.8,2.2727272727,3.3333333332999997,2.2142857143,1.9166666666999999,1,30,False 268 | s460,1.722829679777645,1.7000000000000002,1.0,1.3333333333,1.2142857143,1.25,1,30,False 269 | s461,2.761238667081454,2.0,2.4545454545,2.5,2.0714285714,3.3333333332999997,1,36,False 270 | s463,2.9368568274341076,3.3,2.2727272727,3.4166666667000003,3.0714285714,2.3333333333,0,26,False 271 | s465,2.1658460410854987,1.4,1.1818181818,1.75,1.5,3.5833333332999997,1,46,False 272 | s466,2.2185838189184364,1.6,1.3636363636000002,2.0,2.0714285714,2.3333333333,0,30,True 273 | s467,2.209732669031025,1.9,2.0,2.0,2.0,1.9166666666999999,1,50,False 274 | s469,2.192840334707779,1.4,2.0909090909,1.9166666666999999,1.2142857143,2.75,1,43,False 275 | s470,2.76402231863863,2.9,2.0909090909,2.6666666667000003,2.0714285714,2.75,0,31,False 276 | s473,2.074983761918828,1.7000000000000002,1.4545454544999998,1.8333333333,1.5714285713999998,2.3333333333,0,23,False 277 | s474,2.297483883692478,2.0,1.9090909091,2.0833333333,2.0,2.0,0,28,False 278 | s476,1.9961958831410496,2.0,1.2727272726999999,1.6666666666999999,1.0714285714,1.1666666667,0,44,True 279 | s477,2.9771184376952555,2.3,1.9090909091,3.5,2.4285714286,2.25,0,32,True 280 | s479,1.5464745702921932,1.0,1.3636363636000002,1.0,1.3571428571000002,2.4166666667,1,49,False 281 | s480,1.9065793712791168,1.5,1.2727272726999999,1.4166666666999999,1.0,1.4166666666999999,1,30,False 282 | s481,2.538346608812475,3.1,1.6363636363999998,2.9166666667000003,1.5714285713999998,2.0833333333,1,29,False 283 | s482,2.175043380892566,1.3,1.2727272726999999,2.3333333333,1.0714285714,3.0,1,41,False 284 | s483,1.7700478300520122,2.1,1.1818181818,1.1666666667,1.0,1.0833333333,1,28,False 285 | s486,2.540999520090466,1.7000000000000002,2.5454545455,1.5,1.0714285714,3.9166666667,0,50,True 286 | s489,2.2547677339849943,1.7000000000000002,1.0909090909,2.1666666667,1.1428571429,2.0,1,34,False 287 | s492,2.063569262678807,1.3,1.5454545455000002,2.0833333333,1.2142857143,2.5833333333,0,30,True 288 | s493,2.056274131518832,1.7000000000000002,1.8181818182,1.8333333333,1.0714285714,2.0,1,35,False 289 | s494,1.511040506031299,1.0,1.1818181818,1.0833333333,1.0,2.0,0,46,False 290 | s495,2.332581695181511,2.1,2.0909090909,2.0,1.8571428571000002,1.9166666666999999,1,40,False 291 | s496,3.156965531425784,1.8,2.7272727273000004,3.1666666667000003,3.5,3.0,1,34,False 292 | s497,2.4422770175299435,2.7,2.0,2.1666666667,2.0,2.8333333332999997,0,41,False 293 | s499,2.2964959383522245,1.8,2.3636363636,2.1666666667,2.0714285714,2.8333333332999997,0,31,True 294 | s501,2.323418636025955,1.5,1.0909090909,2.9166666667000003,2.6428571429,1.9166666666999999,1,34,True 295 | s504,2.1845176137294384,1.4,2.0,2.0833333333,2.0,2.0,0,41,False 296 | s505,2.829162938470907,3.0,1.4545454544999998,3.0,3.0714285714,1.5833333333,0,25,False 297 | s507,2.349607608919914,2.4,1.5454545455000002,2.5,1.4285714286000002,1.9166666666999999,1,33,False 298 | s508,2.394405629704627,1.0,1.4545454544999998,3.1666666667000003,2.9285714286,3.6666666667,1,29,False 299 | s509,2.1477695547220894,1.8,1.6363636363999998,1.8333333333,1.2857142857,1.6666666666999999,1,34,False 300 | s512,2.1601632890912033,1.5,2.0909090909,1.9166666666999999,1.5714285713999998,2.3333333333,1,48,False 301 | s514,1.8869086443597674,1.8,1.1818181818,1.6666666666999999,1.1428571429,2.0833333333,0,45,True 302 | s515,1.8184635688073252,1.7000000000000002,1.2727272726999999,1.75,1.2142857143,2.0,0,20,False 303 | s516,2.467623902015723,1.5,1.3636363636000002,2.6666666667000003,2.2857142857,2.9166666667000003,1,28,True 304 | s520,1.9964005733510564,1.7000000000000002,1.3636363636000002,2.0,1.5,2.8333333332999997,1,28,False 305 | s521,1.7370628174837972,1.1,1.5454545455000002,1.0833333333,1.2142857143,2.9166666667000003,0,45,False 306 | s522,2.0111642602676953,2.1,1.2727272726999999,1.75,1.5714285713999998,2.1666666667,1,26,False 307 | s523,2.0041927811510565,1.2,1.1818181818,1.8333333333,1.1428571429,2.6666666667000003,1,43,True 308 | s526,3.2416138366788068,2.3,2.8181818182,2.6666666667000003,2.8571428571,2.5833333333,0,30,True 309 | s527,2.536425915346759,2.1,2.0,2.4166666667,2.0714285714,2.25,1,39,False 310 | s529,2.099208788411654,1.6,1.7272727273,1.5,1.0714285714,2.3333333333,1,43,True 311 | s533,2.0892587754480334,1.2,1.2727272726999999,1.25,1.0714285714,2.8333333332999997,0,28,False 312 | s535,2.556880037294908,2.3,1.8181818182,2.3333333333,2.0714285714,2.5,0,31,False 313 | s539,2.3288723419980353,2.6,1.0,2.3333333333,1.5714285713999998,1.8333333333,0,29,False 314 | s543,2.6551765843849946,2.1,2.0,2.75,1.8571428571000002,2.0,1,43,False 315 | s545,2.3172129675517694,2.1,2.0909090909,2.75,2.0,1.3333333333,0,35,True 316 | s546,2.2804596435980358,2.0,2.0,1.4166666666999999,1.2857142857,2.6666666667000003,1,34,False 317 | s548,1.9899053383233785,1.0,1.2727272726999999,2.0833333333,1.0714285714,2.5833333333,1,28,False 318 | s549,2.2872847791411126,1.3,1.4545454544999998,2.1666666667,2.2142857143,3.25,0,28,True 319 | s550,2.5601443385308453,2.2,1.6363636363999998,2.75,1.9285714286,2.75,1,34,True 320 | s559,2.387309664273278,2.2,1.6363636363999998,2.25,2.5,2.4166666667,1,39,True 321 | s560,3.51843478089568,2.9,2.8181818182,3.4166666667000003,3.0714285714,3.4166666667000003,0,23,True 322 | -------------------------------------------------------------------------------- /notebooks/demographics.csv: -------------------------------------------------------------------------------- 1 | ,Sex,Age,Race,OtherRace,HispanicLatino,HighestEducation,HeightInches,WeightPounds,RelationshipStatus,DivorceCount,LongestRelationship,RelationshipNumber,ChildrenNumber,HouseholdIncome,RetirementAccount,RetirementPercentStocks,RentOwn,MortgageDebt,CarDebt,EducationDebt,CreditCardDebt,OtherDebtSources,OtherDebtAmount,CoffeeCupsPerDay,TeaCupsPerDay,CaffienatedSodaCansPerDay,CaffieneOtherSourcesDayMG,GamblingProblem,TrafficTicketsLastYearCount,TrafficAccidentsLifeCount,ArrestedChargedLifeCount,MotivationForParticipation,MotivationOther 2 | s001,1,27,White,n/a,1,3,62,110,2,0,84,1,1,40000,1.0,0,1,3.0,1.0,1.0,2.0,monthly expenses ,1.0,1,0,0,0,0,0.0,1.0,0.0,money, 3 | s002,0,35,White,,0,2,72,240,2,0,216,1,3,19500,0.0,,1,1.0,1.0,6.0,5.0,,,3,0,0,0,0,0.0,3.0,0.0,money, 4 | s003,0,25,White,,0,4,73,185,1,0,26,1,0,60000,0.0,,0,,1.0,3.0,1.0,none,1.0,1,0,0,90,0,0.0,1.0,0.0,money, 5 | s004,0,35,White,,0,4,71,190,1,0,36,3,0,81000,0.0,,1,,1.0,3.0,3.0,,,0,0,0,0,0,0.0,0.0,0.0,money,n/a 6 | s005,0,36, Black or African American,,0,3,76,175,1,0,18,5,0,36000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,1,0.0,3.0,5.0,money, 7 | s006,1,33,White,,0,5,60,130,2,0,144,3,3,100000,0.0,,1,1.0,1.0,1.0,1.0,0,1.0,1,0,0,0,0,0.0,0.0,0.0,money, 8 | s007,1,32, Black or African American,,0,3,64,130,1,0,84,3,3,98000,0.0,,1,1.0,1.0,1.0,3.0,,,0,0,0,0,0,0.0,3.0,0.0,money, 9 | s008,1,32,White,,0,4,66,275,2,0,156,2,0,80000,1.0,0,0,1.0,1.0,1.0,1.0,none,1.0,0,0,6,100,0,0.0,2.0,0.0,money, 10 | s009,0,26,White,,0,4,72,244,3,0,17,3,0,8000,0.0,,0,1.0,1.0,4.0,1.0,,1.0,1,2,0,0,0,0.0,0.0,0.0,money, 11 | s010,0,44,White,,0,4,72,165,1,0,12,4,0,39000,0.0,,0,1.0,1.0,4.0,4.0,,1.0,0,0,1,0,0,0.0,0.0,0.0,money, 12 | s011,1,27,White,,0,3,72,320,3,1,65,3,0,25000,0.0,0,0,,,4.0,1.0,Medical bills ,5.0,0,0,2,160,0,0.0,0.0,0.0,money, 13 | s012,1,36,White,,0,3,68,268,2,0,144,4,4,40000,0.0,,0,1.0,1.0,4.0,1.0,,,1,0,0,200,0,0.0,2.0,0.0,money, 14 | s013,1,50,Japanese,,0,3,61,145,2,0,228,5,0,70000,1.0,75,1,5.0,1.0,1.0,4.0,loan,4.0,3,1,3,0,0,0.0,4.0,0.0,money, 15 | s014,0,28,White,,0,1,68,240,2,0,100,2,1,15000,0.0,0,0,,,,,,,0,0,4,120,0,0.0,0.0,0.0,money, 16 | s015,0,27,White,,0,2,75,200,1,0,36,3,0,24000,1.0,0,1,1.0,1.0,1.0,1.0,,,0,1,1,400,0,0.0,0.0,0.0,money, 17 | s016,1,20,White,,0,3,62,107,1,0,0,0,0,125000,0.0,,1,,1.0,3.0,1.0,,,1,0,0,0,0,0.0,0.0,0.0,money, 18 | s017,0,31,White,,0,4,69,180,1,0,36,5,0,45000,1.0,90,0,1.0,4.0,1.0,1.0,,,3,1,0,0,0,0.0,0.0,0.0,money, 19 | s018,0,34,White,,0,6,72,200,2,0,8,3,4,25000,0.0,,1,6.0,1.0,7.0,1.0,,,2,0,1,0,0,0.0,0.0,1.0,money, 20 | s019,1,32,White,,0,2,55,130,3,0,170,2,4,65000,0.0,,0,1.0,7.0,7.0,7.0,medical bills,3.0,0,0,2,0,0,0.0,0.0,1.0,money, 21 | s020,0,25,White,,0,4,75,315,1,0,4,2,0,45000,0.0,,0,5.0,1.0,7.0,2.0,No debt that I can think of besides that.,1.0,2,0,2,200,0,0.0,0.0,0.0,money, 22 | s021,1,40,White,,0,2,65,235,1,0,15,3,0,8000,0.0,,1,1.0,2.0,1.0,3.0,none,,0,5,2,0,0,0.0,1.0,0.0,money, 23 | s023,0,46,White,,0,2,70,200,3,0,81,5,0,17000,0.0,,1,5.0,1.0,1.0,1.0,No debt.,1.0,1,7,0,0,0,0.0,0.0,2.0,money, 24 | s025,1,39,White,,0,4,70,168,3,2,70,5,0,24000,0.0,,0,1.0,1.0,6.0,2.0,N/A,,0,0,0,0,0,0.0,5.0,0.0,money, 25 | s026,0,38,White,,0,4,71,195,1,0,48,5,0,30000,0.0,0,1,1.0,7.0,1.0,1.0,N/A,1.0,0,0,0,0,0,0.0,2.0,0.0,money, 26 | s027,0,30,White,,0,3,73,210,1,0,60,2,0,15000,0.0,,0,1.0,1.0,1.0,1.0,N/A,1.0,2,1,0,0,0,0.0,2.0,0.0,money, 27 | s028,0,31,White,,0,4,66,20,1,0,48,5,4,35000,1.0,,0,1.0,4.0,4.0,3.0,,,2,0,0,0,0,0.0,2.0,0.0,money, 28 | s029,0,22,Chinese,,0,4,65,120,1,0,2,1,0,40000,0.0,,1,,,,,Can't think ,,0,0,0,0,0,0.0,0.0,0.0,money, 29 | s030,0,27,White,,0,4,70,155,1,0,26,5,0,33000,0.0,,0,1.0,1.0,1.0,2.0,,1.0,0,0,0,0,0,0.0,0.0,0.0,money, 30 | s031,0,34,Other,Hispanic,1,4,71,173,2,0,96,5,2,180000,1.0,35,1,,,,,NA,,1,0,0,10,0,0.0,2.0,0.0,money,pass time 31 | s032,0,38,White,,0,3,73,240,2,1,146,6,1,78000,1.0,25,1,7.0,1.0,1.0,1.0,,,2,0,2,0,0,0.0,2.0,0.0,money, 32 | s033,1,46,White,n/a,0,3,70,140,3,1,84,4,0,40000,0.0,,0,1.0,1.0,2.0,1.0,none,1.0,0,1,1,0,0,0.0,1.0,2.0,money, 33 | s034,1,28,White,,0,3,61,199,2,0,88,5,1,35000,1.0,0,0,1.0,1.0,3.0,1.0,0,,1,0,0,0,0,0.0,1.0,0.0,money, 34 | s035,1,27,White,,0,4,65,105,3,0,67,3,0,69000,1.0,80,0,1.0,1.0,1.0,2.0,,,0,1,0,0,0,0.0,3.0,0.0,money, 35 | s036,0,29,White,,0,5,75,200,1,0,58,3,0,50000,1.0,20,0,1.0,3.0,4.0,2.0,,5.0,3,0,0,100,0,0.0,0.0,0.0,money, 36 | s037,1,57,White,,0,2,66,180,1,2,120,5,2,40000,0.0,,0,,1.0,1.0,3.0,,,1,0,1,0,0,0.0,0.0,0.0,money, 37 | s038,1,32,White,,0,3,67,120,2,0,96,3,0,105000,0.0,,1,7.0,1.0,1.0,1.0,N/A,,0,1,1,0,0,0.0,0.0,0.0,money, 38 | s039,1,40,White,,0,4,69,248,2,0,264,2,1,149000,1.0,10,1,,,1.0,1.0,None,1.0,0,0,0,0,0,0.0,1.0,0.0,money,Like to learn about myself 39 | s040,0,49,White,,0,3,70,190,2,0,264,3,2,90000,0.0,,1,8.0,3.0,5.0,4.0,,,0,1,0,20,2,0.0,3.0,2.0,money, 40 | s041,1,34,White,,0,2,65,130,3,1,85,3,1,5800,0.0,,0,1.0,7.0,1.0,1.0,n/a,1.0,0,0,1,0,0,0.0,0.0,0.0,money, 41 | s042,0,28,White,,0,4,65,125,1,0,36,2,0,49000,0.0,,0,1.0,1.0,1.0,1.0,MEDICAL,2.0,0,0,0,0,0,0.0,1.0,0.0,money, 42 | s043,0,41,White,,0,3,71,265,1,0,48,6,0,50000,0.0,,0,1.0,1.0,4.0,1.0,,1.0,1,2,0,0,0,0.0,4.0,2.0,money, 43 | s044,1,36,White,,0,3,62,170,2,0,132,3,2,55000,0.0,,1,5.0,3.0,1.0,1.0,,,1,0,1,0,0,0.0,1.0,0.0,money, 44 | s046,0,25,White,,0,4,73,245,1,0,4,2,0,95000,0.0,,1,7.0,1.0,1.0,1.0,,,0,0,0,600,0,0.0,1.0,0.0,money, 45 | s047,0,26,White,,0,4,70,150,3,0,60,3,0,45000,0.0,,0,1.0,4.0,1.0,2.0,,,0,0,0,0,0,1.0,0.0,0.0,money, 46 | s048,0,25,White,,0,3,70,160,1,0,0,0,0,33000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,1,0,0,0.0,0.0,0.0,money, 47 | s049,1,59,White,,0,2,66,175,2,0,300,1,2,98000,0.0,,0,,4.0,1.0,2.0,,,2,0,1,0,0,0.0,0.0,0.0,money, 48 | s051,0,30, Black or African American,,0,3,70,200,1,0,25,4,0,27888,0.0,,0,1.0,1.0,3.0,3.0,,1.0,0,0,0,0,0,0.0,3.0,1.0,money, 49 | s052,1,50,White,,0,3,65,150,1,1,81,6,1,42500,0.0,,0,2.0,3.0,4.0,2.0,none,,0,0,5,0,0,0.0,4.0,0.0,money,I'm interested to see how I do on cognitive tasks. 50 | s053,0,44,White,,0,3,72,190,2,0,242,5,2,144000,1.0,50,1,8.0,4.0,1.0,6.0,,1.0,0,0,1,200,0,0.0,1.0,0.0,money, 51 | s054,0,23, Filipino,,0,3,66,130,1,0,12,2,0,18000,0.0,,1,1.0,1.0,1.0,2.0,,1.0,0,0,0,0,0,0.0,3.0,0.0,money, 52 | s055,0,52,White,,0,3,76,180,1,1,3,6,0,15000,0.0,0,0,1.0,1.0,1.0,4.0,,1.0,0,2,1,250,0,0.0,0.0,1.0,money, 53 | s056,0,48,White,,0,3,76,200,1,0,120,5,0,48000,1.0,70,0,1.0,1.0,1.0,4.0,No other debt,1.0,0,0,1,0,0,0.0,2.0,0.0,money, 54 | s057,1,28,White,,0,4,65,135,1,0,36,4,0,50000,0.0,,1,1.0,1.0,1.0,1.0,,1.0,2,1,0,0,0,0.0,0.0,0.0,money, 55 | s058,0,34, Filipino,,0,4,59,135,1,0,0,0,0,40000,1.0,85,0,1.0,1.0,1.0,1.0,None,1.0,0,0,0,0,0,0.0,1.0,0.0,money, 56 | s059,1,30,White,,0,3,66,125,3,1,60,5,1,28000,0.0,,0,6.0,2.0,6.0,2.0,collections,1.0,3,0,0,0,0,0.0,1.0,0.0,money,sounded interesting 57 | s060,1,49,Japanese,,0,4,64,145,1,0,24,3,0,25000,0.0,,0,1.0,1.0,1.0,2.0,,,0,4,1,0,0,0.0,2.0,0.0,money, 58 | s062,1,26, Asian Indian,,0,6,66,132,1,0,12,2,0,70000,0.0,,0,1.0,1.0,8.0,2.0,n/a,,2,2,4,0,0,0.0,0.0,0.0,money,"Given my profession. academic background, and research interests, I find participation in a study like this piques my curiosity and a great way to learn about the latest neuro/cognitive research and delve deeper on my own." 59 | s063,1,40,White,,0,3,63,190,3,0,48,3,4,28000,0.0,,0,1.0,1.0,3.0,2.0,,,1,1,1,0,0,0.0,2.0,0.0,money, 60 | s064,0,25,White,,0,3,73,185,1,0,36,2,0,20000,0.0,,0,1.0,1.0,1.0,1.0,na,1.0,0,0,0,0,0,0.0,0.0,1.0,money, 61 | s065,1,28,White,,0,4,50,114,1,0,0,0,0,50000,0.0,,0,1.0,1.0,4.0,1.0,,,1,0,2,0,0,0.0,0.0,0.0,money, 62 | s066,1,27, Black or African American,,0,4,66,167,3,0,65,3,2,66000,1.0,3,0,2.0,6.0,4.0,2.0,,,0,0,0,0,0,0.0,2.0,0.0,money, 63 | s067,1,37,White,,0,2,65,160,2,0,1040,4,2,20000,0.0,,1,5.0,1.0,6.0,1.0,none,1.0,0,0,6,0,0,0.0,0.0,1.0,money,none 64 | s068,0,25,White,,0,3,71,177,1,0,0,0,0,20000,0.0,,1,3.0,3.0,1.0,1.0,,,0,3,1,0,1,0.0,0.0,0.0,money, 65 | s069,1,32, Black or African American,,0,3,62,105,3,0,95,5,2,40000,0.0,,0,2.0,1.0,1.0,1.0,,1.0,0,1,1,0,0,0.0,1.0,0.0,money, 66 | s070,0,29,White,,0,3,70,155,3,0,85,2,0,65000,0.0,,0,1.0,1.0,1.0,,,,0,0,4,0,1,0.0,1.0,1.0,money, 67 | s071,1,40,White,,0,3,64,200,2,1,140,5,1,99000,1.0,30,1,6.0,1.0,1.0,1.0,mortgage,6.0,5,1,0,0,0,1.0,1.0,0.0,money, 68 | s073,0,25,White,,0,2,69,123,1,0,0,0,0,55000,0.0,,1,1.0,1.0,1.0,1.0,,,0,0,0,25,0,0.0,1.0,0.0,money,Helping my friend in need. 69 | s074,1,50,White,,0,3,61,165,2,1,229,5,2,17800,1.0,18,0,3.0,1.0,1.0,3.0,none,,5,0,0,0,0,0.0,2.0,0.0,money, 70 | s075,1,55,White,,1,3,62,175,1,2,136,4,0,25500,0.0,,1,5.0,1.0,1.0,1.0,none,,0,0,4,0,0,1.0,1.0,2.0,money, 71 | s076,1,37,White,,0,3,65,204,2,2,144,4,3,19500,0.0,,1,1.0,1.0,5.0,2.0,Bank loan,2.0,0,0,0,0,0,1.0,2.0,1.0,money, 72 | s077,0,30,Choose not to respond,,0,4,71,170,1,0,36,4,0,48000,0.0,,0,,,,,,,0,0,0,0,0,0.0,0.0,0.0,money, 73 | s078,0,48,White,,0,3,71,165,2,1,264,6,5,25000,0.0,,1,1.0,1.0,1.0,1.0,,2.0,8,0,0,0,0,0.0,0.0,1.0,money, 74 | s079,0,28,Other,hispanic,1,4,71,185,3,0,77,5,1,28000,0.0,,0,2.0,1.0,4.0,4.0,,,4,0,1,0,0,0.0,1.0,1.0,tasks are fun, 75 | s080,1,43,White,,0,3,68,175,1,0,48,3,0,27000,0.0,,0,1.0,5.0,1.0,1.0,,1.0,4,1,0,0,0,0.0,1.0,0.0,money, 76 | s081,1,42, Black or African American,,0,4,69,180,1,0,36,3,0,43800,0.0,,0,1.0,3.0,1.0,2.0,,,0,0,6,0,0,0.0,0.0,0.0,money, 77 | s082,0,29,White,,0,2,70,220,1,0,0,0,0,30000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,0,0,2,0,0,0.0,0.0,0.0,money, 78 | s083,0,50,White,,0,3,68,265,1,0,36,6,0,14000,0.0,,0,1.0,1.0,1.0,1.0,none,,0,0,5,0,2,0.0,5.0,4.0,money, 79 | s084,0,46,White,,0,3,72,280,2,0,216,4,3,79000,1.0,20,0,2.0,1.0,1.0,1.0,,,2,1,3,0,0,0.0,1.0,0.0,money, 80 | s085,1,36,White,,0,4,65,135,1,0,6,3,0,65000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,3.0,0.0,money, 81 | s086,0,24, Vietnamese,,0,4,67,145,1,0,27,2,0,75000,0.0,,1,,1.0,5.0,1.0,,,0,1,0,0,0,0.0,0.0,0.0,money, 82 | s087,1,49,White,,0,4,65,175,1,2,204,3,3,15000,0.0,,0,1.0,1.0,5.0,1.0,,,3,0,3,0,0,0.0,2.0,0.0,money, 83 | s088,0,27,White,,0,4,69,160,3,0,54,1,0,20000,0.0,,1,1.0,2.0,5.0,1.0,N/A,1.0,1,0,2,0,0,0.0,0.0,0.0,money,N/A 84 | s089,1,32,White,,0,3,62,125,2,0,180,1,2,35000,0.0,,1,7.0,1.0,1.0,5.0,,,0,0,0,0,0,0.0,2.0,1.0,money, 85 | s090,1,42,White,n/a,1,3,63,118,2,0,270,2,1,47000,0.0,0,1,6.0,1.0,4.0,1.0,medical,4.0,2,1,0,0,0,0.0,0.0,0.0,money, 86 | s091,1,30,White,,0,4,67,135,2,0,127,2,0,80000,0.0,,0,1.0,3.0,3.0,2.0,,,3,0,0,0,0,0.0,0.0,0.0,money, 87 | s092,1,33,White,,0,3,66,150,2,0,144,3,3,80000,1.0,0,0,1.0,7.0,8.0,3.0,none,,0,0,2,35,0,0.0,1.0,0.0,money,none 88 | s093,0,37, American Indian or Alaska Native,,1,3,71,300,3,0,60,6,1,69999,0.0,,1,3.0,1.0,1.0,2.0,,,0,5,0,0,0,1.0,2.0,0.0,money, 89 | s094,0,40,White,,0,4,71,220,1,0,48,4,0,25000,0.0,,0,,,,,,,0,0,4,0,0,0.0,2.0,3.0,money, 90 | s095,0,46,White,,1,6,72,190,1,0,24,6,0,2500,0.0,,1,2.0,1.0,1.0,1.0,,,1,2,1,0,0,0.0,1.0,0.0,money, 91 | s096,1,39,White,,0,4,63,140,1,0,24,5,0,80000,0.0,,1,,,,,,,0,4,1,0,0,0.0,1.0,0.0,money, 92 | s097,1,33, Black or African American,,0,4,63,155,3,0,62,4,0,62000,0.0,,0,1.0,1.0,6.0,2.0,N/A,,4,1,0,0,0,0.0,0.0,0.0,money, 93 | s098,0,26,White,,0,5,68,140,2,0,122,6,0,27000,0.0,,0,1.0,1.0,3.0,1.0,SSI Repayment,3.0,2,0,1,250,0,0.0,0.0,0.0,money, 94 | s099,1,26,White,,0,4,69,140,2,0,75,5,1,155000,1.0,,1,7.0,1.0,1.0,1.0,,,1,1,0,0,0,0.0,0.0,0.0,money, 95 | s100,0,20,White,,0,2,72,275,1,0,6,1,0,80000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,0,0,0,0,0,0.0,0.0,0.0,money, 96 | s101,1,32,White,,0,4,69,173,2,0,120,4,0,69000,0.0,,0,,3.0,6.0,3.0,,,3,0,3,-12,0,0.0,1.0,0.0,money, 97 | s102,1,21,White,,0,3,66,171,3,0,65,2,0,25000,0.0,,0,1.0,,5.0,1.0,,,2,1,0,0,0,0.0,0.0,0.0,money, 98 | s103,1,31,White,,0,3,66,141,2,0,159,4,2,12500,0.0,,1,1.0,1.0,1.0,1.0,,1.0,4,3,0,200,0,0.0,2.0,0.0,money, 99 | s105,1,25,White,,0,1,64,165,3,0,12,3,0,35000,0.0,,0,1.0,1.0,1.0,2.0,family debt,3.0,0,5,0,0,0,0.0,0.0,0.0,money, 100 | s106,1,35,White,,0,4,69,146,2,0,26,4,1,25000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,1,40,0,0.0,0.0,0.0,money, 101 | s107,0,35,White,,0,3,74,195,1,1,150,1,2,45000,0.0,,0,1.0,3.0,1.0,3.0,,1.0,0,0,0,300,1,1.0,3.0,1.0,money, 102 | s108,1,43,White,,0,3,70,198,3,0,240,5,1,50000,1.0,70,1,,1.0,1.0,4.0,,,2,0,-1,-4,0,0.0,1.0,0.0,money, 103 | s109,0,25,White,,0,4,70,183,2,0,60,1,1,40000,1.0,0,0,1.0,2.0,4.0,2.0,,,2,0,0,0,0,0.0,0.0,0.0,money, 104 | s110,1,27,White,,0,3,64,186,2,0,144,2,1,46000,1.0,0,1,6.0,2.0,5.0,3.0,,1.0,0,5,0,10,0,0.0,0.0,0.0,money, 105 | s111,1,37,White,,0,3,61,150,3,0,144,5,0,46000,0.0,,0,1.0,1.0,4.0,,0,,0,0,5,500,0,0.0,3.0,2.0,money, 106 | s112,0,24,White,,0,4,72,200,1,0,24,3,0,12000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 107 | s113,1,24,White,,0,4,66,110,3,0,58,1,0,60000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,1,0,0,0.0,0.0,0.0,money, 108 | s114,0,27,White,,0,4,72,170,1,0,18,2,0,89000,1.0,0,0,1.0,1.0,1.0,1.0,N/A,1.0,2,0,0,0,0,0.0,2.0,0.0,money, 109 | s115,1,38,White,,0,3,62,188,1,0,2,4,0,70000,0.0,,1,,1.0,1.0,1.0,None,1.0,4,0,0,0,0,0.0,4.0,2.0,money, 110 | s116,0,45,White,,0,4,74,300,1,0,12,4,0,20000,0.0,,1,1.0,1.0,7.0,1.0,None,,0,0,6,0,0,0.0,2.0,1.0,money, 111 | s117,0,32,White,,0,3,72,315,3,0,42,2,0,75500,0.0,,1,1.0,1.0,1.0,1.0,None,1.0,4,2,1,0,0,0.0,0.0,0.0,money, 112 | s118,0,25, Black or African American,,0,3,74,330,1,0,48,3,0,50000,0.0,,0,,,,,,,3,3,0,800,0,0.0,0.0,0.0,money, 113 | s119,0,25,Chinese,,0,3,70,160,1,0,16,1,0,25000,0.0,,1,1.0,1.0,3.0,1.0,,1.0,0,0,0,0,0,0.0,0.0,0.0,money, 114 | s120,0,26,White,,0,4,68,168,3,0,68,3,0,65000,1.0,10,0,1.0,3.0,6.0,3.0,,1.0,0,0,0,0,0,0.0,0.0,0.0,money, 115 | s121,1,36,White,,0,2,69,155,1,0,12,3,0,29000,0.0,,1,1.0,1.0,1.0,1.0,n/a,1.0,4,0,0,0,0,0.0,0.0,0.0,money, 116 | s122,1,25,White,,1,3,66,300,3,0,50,1,0,42000,0.0,,0,1.0,3.0,4.0,2.0,,,2,3,0,0,0,0.0,2.0,0.0,money, 117 | s123,0,24,White,,0,3,69,150,3,0,29,2,0,45000,0.0,,1,1.0,1.0,3.0,1.0,,,0,0,2,2000,0,0.0,0.0,0.0,money, 118 | s124,1,46,White,,0,3,66,225,2,0,250,5,2,70000,0.0,,1,6.0,1.0,1.0,2.0,none,1.0,3,0,1,0,0,0.0,2.0,0.0,money, 119 | s125,1,30, Black or African American,,0,3,66,350,1,0,24,3,0,24000,0.0,,0,1.0,3.0,3.0,2.0,,,1,0,1,0,0,0.0,0.0,0.0,money, 120 | s126,0,34,White,,0,5,74,210,1,0,60,3,0,55000,1.0,30,1,5.0,1.0,1.0,2.0,N/A,,1,0,1,0,0,0.0,0.0,0.0,money,N/A 121 | s127,0,28,White,,0,5,73,225,2,0,120,3,2,85000,0.0,,0,1.0,1.0,6.0,2.0,,,2,0,1,0,0,0.0,0.0,0.0,money, 122 | s128,1,26,White,,0,3,69,225,2,0,97,4,0,65000,0.0,,0,1.0,1.0,1.0,4.0,,1.0,0,0,0,0,0,0.0,2.0,0.0,money, 123 | s129,0,36,White,,1,3,71,240,1,0,24,2,0,12000,0.0,,1,1.0,1.0,1.0,1.0,taxes,3.0,0,0,0,0,0,0.0,0.0,0.0,money, 124 | s130,1,33,White,,0,3,64,135,2,0,201,4,3,140000,0.0,,1,1.0,1.0,3.0,1.0,,1.0,1,3,1,0,0,0.0,1.0,0.0,money, 125 | s131,0,38,White,N/A,0,3,70,180,1,0,52,2,1,20000,0.0,,1,1.0,1.0,1.0,1.0,N/A,1.0,3,0,0,150,0,0.0,2.0,0.0,money, 126 | s132,0,27,White,,0,3,68,135,3,0,18,5,0,35000,1.0,20,0,1.0,1.0,1.0,3.0,None,,0,0,2,0,2,0.0,2.0,3.0,money,Psychological profiling relates to a hobby of mine. 127 | s133,1,29, Vietnamese,,0,3,61,120,3,0,72,5,0,25000,0.0,,1,1.0,1.0,4.0,1.0,Medical bills,1.0,1,3,1,0,0,0.0,0.0,0.0,money, 128 | s134,0,22,White,,0,3,68,160,1,0,6,3,0,70000,0.0,,0,1.0,3.0,2.0,1.0,Medical,4.0,3,0,2,0,0,3.0,0.0,0.0,money, 129 | s135,0,27,White,,0,3,68,150,1,0,60,5,0,29000,1.0,0,0,1.0,1.0,3.0,3.0,,,2,0,0,0,0,0.0,4.0,0.0,money, 130 | s136,0,43,White,,0,4,71,185,2,0,180,5,2,110000,1.0,50,1,8.0,3.0,5.0,2.0,,,3,0,1,100,0,0.0,2.0,0.0,money, 131 | s138,0,27,White,,0,3,70,140,1,0,26,3,0,29000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,1,1,0,100,0,0.0,1.0,0.0,money,Go team science. 132 | s139,1,35,White,,0,3,64,120,2,0,15,5,0,60000,0.0,,0,1.0,1.0,5.0,1.0,,,2,0,1,0,0,0.0,2.0,0.0,tasks are fun, 133 | s140,0,35,White,,0,3,69,195,1,0,24,3,0,30000,0.0,,1,1.0,2.0,1.0,2.0,,1.0,0,0,0,0,0,0.0,1.0,0.0,money, 134 | s141,0,24,White,,0,2,58,154,3,0,34,1,0,35000,0.0,,1,,,1.0,2.0,,,1,1,2,0,0,0.0,3.0,0.0,money, 135 | s142,0,30,White,,0,4,76,180,1,0,48,3,0,46000,1.0,12,1,5.0,1.0,1.0,2.0,,1.0,1,0,1,120,0,1.0,2.0,0.0,money, 136 | s143,0,28,White,,0,2,79,300,3,0,108,2,0,22000,0.0,,0,,,,,None,,0,0,3,50,0,0.0,0.0,0.0,money, 137 | s144,0,23,White,,0,3,72,185,1,0,4,6,0,32000,0.0,0,0,1.0,1.0,1.0,1.0,0,1.0,1,1,0,0,0,0.0,0.0,0.0,money,n/a 138 | s145,0,24,White,,1,2,64,185,1,0,31,3,0,110000,0.0,,1,5.0,1.0,1.0,1.0,N/A,1.0,0,0,1,150,0,0.0,1.0,0.0,money, 139 | s146,1,45,White,,0,3,63,271,2,0,360,1,2,45000,0.0,,0,1.0,2.0,3.0,4.0,none,,0,0,0,0,0,0.0,2.0,0.0,money,n/a 140 | s147,1,29,White,,0,2,64,260,2,0,64,4,0,81000,1.0,25,0,1.0,3.0,3.0,3.0,na,1.0,2,0,0,0,0,1.0,2.0,1.0,money, 141 | s149,0,45,White,,0,6,70,185,1,1,96,5,0,115000,1.0,75,0,1.0,1.0,5.0,1.0,n/a,1.0,1,0,0,0,0,0.0,2.0,0.0,money, 142 | s150,1,28,White,,0,3,63,172,2,0,156,1,2,45230,0.0,,1,6.0,7.0,1.0,4.0,,1.0,0,0,1,0,0,0.0,2.0,0.0,money, 143 | s151,0,34,White,,0,2,70,190,3,0,150,3,0,20000,0.0,,0,1.0,1.0,1.0,1.0,,,0,3,0,0,2,0.0,0.0,0.0,money, 144 | s152,0,43,White,,0,4,67,160,1,0,36,2,0,30000,0.0,,0,1.0,1.0,1.0,2.0,,1.0,0,0,0,0,0,0.0,0.0,1.0,money, 145 | s153,0,31,White,,0,2,70,170,3,0,24,4,0,45000,1.0,70,0,1.0,2.0,1.0,1.0,,1.0,3,0,2,600,0,0.0,2.0,0.0,money, 146 | s154,0,47,White,,0,4,69,165,2,0,311,4,2,132000,1.0,90,1,8.0,1.0,1.0,1.0,N/A,1.0,0,1,1,0,0,0.0,3.0,2.0,money, 147 | s155,1,33,White,,0,2,60,167,2,0,168,5,0,29000,0.0,,0,1.0,1.0,1.0,2.0,,1.0,5,0,0,0,0,0.0,0.0,0.0,money, 148 | s156,0,37,White,,0,3,72,198,1,0,50,6,0,74000,1.0,20,0,1.0,1.0,1.0,1.0,0,1.0,2,0,0,300,0,0.0,3.0,1.0,money, 149 | s157,0,50,White,,0,4,68,180,2,0,240,5,1,106000,1.0,50,1,5.0,1.0,1.0,1.0,none,,2,0,1,0,0,0.0,2.0,0.0,tasks are fun, 150 | s158,1,27,White,,0,3,67,165,2,0,102,2,0,60000,0.0,,0,1.0,3.0,1.0,4.0,,,5,0,0,0,0,0.0,0.0,0.0,money, 151 | s160,0,50,White,,0,3,72,200,1,0,83,5,0,42000,0.0,,0,1.0,1.0,6.0,1.0,none,1.0,0,2,4,20,0,0.0,0.0,0.0,money, 152 | s161,1,30,White,,0,3,65,250,2,0,137,5,0,68000,1.0,50,0,1.0,3.0,3.0,1.0,N/A,1.0,2,1,0,0,0,0.0,1.0,0.0,money,I find it interesting. 153 | s162,0,26,White,,0,2,70,170,1,0,5,3,0,45000,1.0,80,0,1.0,1.0,1.0,1.0,,1.0,1,0,1,0,0,0.0,0.0,0.0,money, 154 | s163,0,44,White,,0,4,76,193,2,0,10,4,4,99000,1.0,99,1,6.0,3.0,1.0,1.0,,1.0,0,0,0,0,0,0.0,2.0,0.0,money, 155 | s165,0,31, Black or African American,,0,4,70,150,1,0,0,0,0,24000,0.0,,0,1.0,3.0,1.0,1.0,,,0,0,0,0,0,0.0,1.0,0.0,money, 156 | s166,0,39,White,,0,2,71,165,2,0,56,3,0,44000,0.0,,0,1.0,1.0,1.0,1.0,n/a,1.0,0,0,0,0,0,0.0,1.0,0.0,money, 157 | s167,1,34,White,,0,4,65,165,3,0,109,4,0,60000,1.0,95,1,7.0,1.0,4.0,2.0,N/A,,0,0,0,0,0,0.0,5.0,0.0,money,It gives me something to do when work is slow. 158 | s168,1,33,Chinese,,0,4,62,135,3,0,147,4,0,75000,1.0,90,0,1.0,1.0,1.0,3.0,,,1,0,0,0,0,0.0,1.0,0.0,money, 159 | s169,1,36,White,,0,4,67,123,2,1,121,2,2,24000,0.0,,0,1.0,1.0,2.0,6.0,student loan,1.0,2,0,0,60,0,0.0,0.0,0.0,money, 160 | s170,0,32, American Indian or Alaska Native,,0,4,69,145,3,0,55,2,0,5000,0.0,,1,,1.0,,1.0,,1.0,3,0,0,0,0,0.0,0.0,0.0,money, 161 | s171,0,27,White,,0,3,70,168,3,0,48,4,0,12000,0.0,,0,1.0,1.0,3.0,1.0,,,4,0,0,0,0,0.0,1.0,0.0,money, 162 | s172,0,29,White,,0,3,72,310,3,1,62,5,0,12000,0.0,,0,1.0,1.0,3.0,1.0,,,3,0,2,0,0,1.0,2.0,0.0,money, 163 | s173,0,26,White,,0,3,67,135,3,0,24,2,0,40000,0.0,,0,1.0,1.0,4.0,1.0,,1.0,1,0,1,0,0,0.0,0.0,0.0,money, 164 | s174,1,29, Black or African American,,0,2,66,140,1,0,48,2,0,15000,0.0,,1,4.0,1.0,1.0,1.0,,1.0,0,0,1,1,0,0.0,0.0,0.0,tasks are fun, 165 | s175,0,30,White,,1,4,67,150,3,0,48,5,0,40000,0.0,,0,1.0,1.0,1.0,1.0,Owe a friend & my mom some money.,3.0,1,0,0,0,1,0.0,2.0,3.0,money, 166 | s176,0,20,White,,1,2,71,275,1,0,3,1,0,29000,0.0,,0,1.0,1.0,1.0,2.0,,1.0,1,0,0,0,0,0.0,0.0,0.0,money, 167 | s177,0,37, Black or African American,,0,3,68,214,1,0,8,1,0,34000,0.0,,1,1.0,1.0,3.0,1.0,loan from family,1.0,0,0,0,0,0,0.0,1.0,0.0,money, 168 | s178,1,32,White,,0,4,66,180,2,0,132,2,0,75000,1.0,50,1,8.0,4.0,1.0,3.0,,,1,0,0,0,0,0.0,1.0,0.0,money, 169 | s179,1,30,White,,0,3,67,190,2,0,126,2,5,35000,0.0,,0,1.0,3.0,5.0,1.0,,1.0,0,0,5,0,0,0.0,1.0,0.0,money, 170 | s180,0,33,White,,0,4,68,180,1,0,60,5,0,19500,0.0,,0,1.0,1.0,4.0,1.0,,,1,0,0,0,0,0.0,0.0,0.0,money, 171 | s181,1,32,White,,0,3,62,160,2,1,8,3,3,13000,0.0,,1,1.0,1.0,4.0,1.0,none,,0,2,3,0,0,0.0,2.0,0.0,money, 172 | s182,0,26, Filipino,,0,4,69,299,1,0,3,1,0,60000,0.0,,1,,,3.0,,,,0,0,0,0,0,0.0,0.0,0.0,money, 173 | s183,0,33,White,,1,2,70,162,1,0,30,3,0,55.000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,1.0,0.0,money, 174 | s184,1,48,White,,0,4,64,160,1,0,60,4,2,63000,1.0,65,1,8.0,1.0,4.0,3.0,none. you nailed all of them,1.0,3,0,1,0,0,0.0,3.0,0.0,money, 175 | s185,0,35,White,,0,5,72,175,2,0,122,6,2,104000,1.0,50,1,7.0,1.0,4.0,1.0,,,3,0,0,0,0,0.0,1.0,2.0,money, 176 | s186,0,39, Black or African American,,0,4,76,210,2,0,144,5,4,74000,1.0,10,1,8.0,3.0,1.0,3.0,,,1,2,1,0,0,0.0,3.0,0.0,money,for the experience 177 | s187,0,28,White,,0,4,69,206,1,0,38,2,0,48500,0.0,,0,1.0,1.0,3.0,2.0,,1.0,3,0,2,75,0,0.0,0.0,0.0,money, 178 | s188,0,31,White,,0,3,72,250,3,0,46,3,0,30000,0.0,0,0,1.0,3.0,1.0,3.0,0,1.0,3,0,0,0,0,0.0,0.0,0.0,money, 179 | s189,1,29,White,,0,3,67,140,1,0,8,4,0,65000,0.0,,0,1.0,1.0,2.0,1.0,,,0,0,2,0,0,0.0,0.0,0.0,money, 180 | s190,0,29,Chinese,,0,4,67,155,1,0,38,4,0,56500,0.0,0,1,4.0,1.0,3.0,1.0,0,1.0,2,0,0,150,0,0.0,0.0,0.0,money, 181 | s191,1,30, Black or African American,,0,3,72,180,2,0,75,3,0,50000,0.0,,0,2.0,1.0,3.0,2.0,Medical ,3.0,0,1,0,20,0,1.0,3.0,0.0,money, 182 | s192,1,31,White,,0,4,65,110,3,0,88,2,0,75000,0.0,,0,1.0,4.0,1.0,2.0,,,1,0,0,0,0,0.0,0.0,0.0,money, 183 | s193,1,30,White,,0,4,67,150,1,1,120,3,0,50000,1.0,0,1,6.0,2.0,2.0,2.0,,,3,1,0,0,0,0.0,0.0,0.0,money, 184 | s194,0,31,White,,0,3,72,280,2,0,96,4,1,95000,1.0,80,0,1.0,5.0,1.0,1.0,,,0,0,1,0,0,0.0,1.0,0.0,money, 185 | s195,0,44,White,,0,4,73,190,1,0,24,5,0,26000,0.0,,0,1.0,1.0,4.0,2.0,tax debt ,5.0,3,0,0,0,0,0.0,1.0,1.0,money, 186 | s196,1,39,White,,0,4,65,175,2,0,192,5,2,35000,0.0,,0,1.0,7.0,1.0,2.0,none,1.0,3,0,0,0,0,0.0,1.0,0.0,money, 187 | s197,0,25,White,,0,4,71,205,3,0,69,5,0,70000,1.0,75,0,1.0,1.0,1.0,3.0,,,0,0,0,0,0,0.0,3.0,1.0,money, 188 | s198,1,27,White,,0,2,68,122,1,0,22,5,0,19500,0.0,0,0,1.0,1.0,1.0,1.0,,,0,0,1,0,0,0.0,0.0,0.0,money, 189 | s199,0,23,White,,0,3,75,145,1,0,108,5,0,19000,0.0,,0,1.0,1.0,4.0,1.0,,7.0,0,0,3,0,0,1.0,1.0,5.0,money, 190 | s200,1,38, Black or African American,,0,5,65,160,2,0,144,5,4,74000,1.0,5,1,8.0,3.0,5.0,1.0,,,0,1,0,0,0,0.0,2.0,0.0,money, 191 | s201,1,48,White,,0,4,65,150,1,1,204,6,2,44900,1.0,27,0,1.0,5.0,3.0,1.0,0,1.0,16,1,0,0,0,0.0,2.0,0.0,money, 192 | s202,0,26,White,,0,5,73,155,1,0,7,5,0,27500,0.0,,1,1.0,1.0,5.0,1.0,Outstanding fines ,,,,,,,,,,, 193 | s203,1,50,White,,0,4,67,150,3,0,108,6,0,70000,1.0,100,0,1.0,1.0,,2.0,,,0,2,0,0,0,0.0,0.0,0.0,money, 194 | s204,1,26,White,,0,3,70,180,3,0,78,1,3,32000,0.0,,0,1.0,1.0,4.0,1.0,,,0,0,2,200,0,0.0,0.0,0.0,money,The challenge of completing the tasks. 195 | s205,0,33,White,,0,2,67,120,3,0,65,2,0,23000,0.0,,0,1.0,1.0,1.0,1.0,,,0,3,1,0,0,0.0,0.0,0.0,money, 196 | s206,1,27,White,,0,2,62,135,3,0,26,4,1,25600,0.0,,0,1.0,1.0,1.0,1.0,none,,0,0,0,0,0,0.0,3.0,4.0,money, 197 | s207,1,33,White,,0,4,64,118,2,0,153,1,2,4400,0.0,,0,1.0,1.0,1.0,1.0,none,,0,0,0,0,0,0.0,1.0,0.0,money, 198 | s208,0,31,White,,0,3,71,250,1,0,48,1,0,50000,0.0,,0,1.0,1.0,6.0,1.0,,1.0,0,0,1,92,0,2.0,1.0,4.0,money, 199 | s209,0,42,White,,0,3,68,210,3,1,48,5,3,23500,0.0,,0,1.0,1.0,1.0,2.0,"Regular bills, loan from family",2.0,0,0,1,0,0,0.0,2.0,1.0,money,"Doing large tasks sometimes becomes my white whale, and I have to slay it." 200 | s210,0,33,White,,0,3,70,150,1,0,66,4,1,35000,0.0,,0,1.0,1.0,1.0,2.0,Past due child support,4.0,0,0,0,0,0,0.0,0.0,2.0,money, 201 | s211,0,43,White,,0,6,70,170,1,0,90,4,0,62000,0.0,0,1,5.0,1.0,,1.0,0,,0,4,0,4,0,0.0,2.0,0.0,money, 202 | s212,1,32,White,,0,4,65,160,1,0,36,3,0,77000,0.0,,0,1.0,2.0,6.0,2.0,,1.0,0,2,0,0,0,0.0,2.0,0.0,money, 203 | s213,1,43,White,,0,3,62,130,2,0,292,4,3,21000,0.0,,0,1.0,1.0,5.0,2.0,,1.0,0,0,5,200,0,0.0,1.0,2.0,money, 204 | s214,0,45,White,,0,5,70,165,3,2,120,5,0,24000,0.0,,0,1.0,1.0,2.0,1.0,Medical bills,4.0,0,3,0,0,0,0.0,3.0,1.0,money, 205 | s215,0,46,White,,0,2,58,240,2,0,286,1,1,19000,0.0,,1,4.0,1.0,1.0,1.0,,1.0,0,0,3,10,0,0.0,0.0,0.0,money, 206 | s216,1,47,White,,0,4,66,180,1,1,168,5,2,31000,0.0,,1,1.0,1.0,3.0,1.0,,,8,2,2,0,0,0.0,1.0,0.0,money, 207 | s217,0,26,White,,0,4,76,225,3,0,47,4,0,50000,0.0,,1,1.0,3.0,1.0,1.0,,,0,5,2,80,0,0.0,0.0,0.0,money, 208 | s218,1,38,White,,0,4,70,175,3,1,60,4,3,64000,1.0,3,1,6.0,2.0,1.0,2.0,none,1.0,3,0,0,0,0,0.0,2.0,0.0,money, 209 | s219,0,34,White,,0,3,75,192,3,0,157,2,0,4000,0.0,,1,4.0,1.0,3.0,3.0,None,,0,0,2,0,0,0.0,2.0,1.0,money, 210 | s220,1,36,White,,0,4,72,200,3,0,14,2,0,15000,0.0,0,0,1.0,1.0,4.0,2.0,0,1.0,5,0,0,0,0,0.0,0.0,0.0,money, 211 | s221,1,29,White,,0,3,63,122,3,1,84,3,0,175000,0.0,,1,6.0,1.0,3.0,1.0,,,3,1,0,0,0,0.0,5.0,0.0,money, 212 | s222,1,32,White,,0,4,69,215,1,0,0,0,0,15000,1.0,0,0,1.0,1.0,1.0,3.0,,,0,0,0,0,0,0.0,2.0,0.0,money, 213 | s223,0,45,White,,0,4,72,178,2,0,96,4,1,42500,1.0,25,0,1.0,1.0,1.0,2.0,,,5,2,0,0,0,0.0,1.0,0.0,want to contribute to research, 214 | s224,0,27,White,,0,4,72,178,1,0,6,2,0,40000,1.0,80,0,1.0,1.0,3.0,1.0,,,0,0,0,195,0,0.0,0.0,5.0,money, 215 | s225,1,40,White,,0,4,68,145,2,0,204,2,2,110000,1.0,50,1,7.0,4.0,1.0,1.0,none,,1,0,1,0,0,0.0,1.0,0.0,money, 216 | s226,1,30,White,,1,4,60,125,3,1,70,4,2,76000,0.0,,1,1.0,1.0,3.0,2.0,,,1,0,0,0,0,1.0,0.0,0.0,money, 217 | s227,0,37,White,,0,5,77,245,2,0,44,4,3,70000,1.0,66,1,7.0,1.0,1.0,1.0,,,2,0,0,0,0,0.0,0.0,0.0,money, 218 | s228,0,36,White,,0,2,65,170,1,0,24,4,0,12000,0.0,,0,1.0,1.0,4.0,4.0,,,0,0,0,0,0,0.0,4.0,0.0,money, 219 | s229,0,28,White,,0,4,68,129,3,0,25,4,0,89000,1.0,36,1,7.0,1.0,,,Prefer Not to say,,1,0,0,400,0,1.0,2.0,0.0,money, 220 | s230,0,46,White,,0,4,74,270,1,0,30,5,0,50000,1.0,60,1,1.0,1.0,4.0,3.0,,,1,2,3,0,0,0.0,2.0,0.0,money, 221 | s231,1,37,White,,0,2,65,137,2,0,168,5,3,49999,0.0,,0,1.0,3.0,1.0,2.0,,,1,0,0,0,0,0.0,1.0,0.0,money, 222 | s232,0,26,Korean,,0,6,68,170,3,0,48,4,0,65000,0.0,,0,1.0,1.0,8.0,4.0,,,1,0,0,50,0,0.0,3.0,0.0,money, 223 | s233,1,42,White,,0,3,65,240,1,0,8,6,0,23000,0.0,,0,1.0,1.0,1.0,2.0,,,0,0,0,65,0,0.0,5.0,0.0,money,Morbidly curious to see how much of a decline my mind has gone down 224 | s234,1,29,White,,0,3,63,240,2,0,155,2,5,80000,1.0,3,1,7.0,5.0,1.0,5.0,5000,3.0,0,2,1,0,0,0.0,5.0,0.0,money, 225 | s235,1,29,White,,0,3,63,180,2,0,96,5,0,49000,0.0,0,0,1.0,4.0,4.0,3.0,,1.0,0,0,1,36,0,0.0,2.0,0.0,money, 226 | s236,1,50,White,,0,4,67,145,3,0,120,4,1,53000,1.0,40,1,5.0,1.0,1.0,1.0,none,1.0,5,0,0,0,0,0.0,1.0,0.0,money,n/a 227 | s237,0,31,White,,0,3,70,210,3,1,60,4,1,18000,0.0,,0,1.0,2.0,3.0,2.0,,,2,0,2,0,0,0.0,1.0,3.0,money, 228 | s238,1,23,White,,0,2,64,164,2,0,4,3,4,45000,1.0,0,1,3.0,3.0,1.0,1.0,0,1.0,4,0,2,300,0,0.0,0.0,0.0,money, 229 | s239,0,29,White,,0,3,71,197,1,0,15,2,0,25000,0.0,,1,,,3.0,2.0,,,4,0,2,4000,0,0.0,1.0,0.0,money, 230 | s240,0,25,White,,0,3,67,150,1,0,6,0,0,20000,0.0,0,1,3.0,3.0,3.0,2.0,,,1,0,1,0,0,0.0,1.0,0.0,money, 231 | s241,0,25,White,,0,3,75,220,1,0,12,6,0,15000,0.0,,0,1.0,1.0,1.0,1.0,none,,1,0,3,0,0,0.0,0.0,0.0,money, 232 | s242,0,27,White,,0,4,72,145,1,0,36,5,0,20000,0.0,,0,1.0,1.0,1.0,1.0,,,2,0,0,190,0,0.0,2.0,1.0,money, 233 | s243,0,24, Black or African American,,1,4,67,145,1,0,5,1,0,15000,0.0,,0,1.0,2.0,5.0,2.0,,,1,0,0,0,0,0.0,0.0,0.0,money, 234 | s244,1,37,White,,0,4,68,150,1,0,120,5,0,2500,0.0,,0,1.0,1.0,4.0,3.0,,,4,2,0,0,0,0.0,5.0,0.0,money, 235 | s245,1,41,White,,0,4,66,200,1,0,60,5,0,22000,1.0,40,1,1.0,1.0,5.0,4.0,,,5,0,0,0,0,0.0,2.0,0.0,money, 236 | s246,1,26,White,,0,2,66,212,2,0,64,3,2,60000,1.0,0,0,2.0,2.0,1.0,2.0,,1.0,1,0,2,0,0,0.0,0.0,0.0,money, 237 | s247,0,46,White,,0,4,75,210,2,1,196,5,1,125000,1.0,85,1,7.0,1.0,1.0,3.0,,,2,0,0,250,0,0.0,1.0,1.0,money, 238 | s248,1,44,White,,0,4,66,150,2,0,288,2,4,98000,1.0,40,1,7.0,1.0,1.0,1.0,n/a,,0,0,6,0,0,0.0,2.0,0.0,money, 239 | s249,0,29,White,,0,4,70,165,1,0,36,2,0,30000,0.0,0,1,1.0,3.0,1.0,3.0,,,1,1,2,200,2,3.0,2.0,2.0,money,to get more bonus 240 | s250,1,31,White,,0,3,66,135,1,0,36,5,0,37500,0.0,,0,1.0,1.0,1.0,1.0,,,0,5,0,0,0,0.0,1.0,0.0,money, 241 | s251,0,26,White,,0,4,70,160,2,0,58,2,0,30000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,0,0,0,0,0,0.0,1.0,2.0,money, 242 | s252,0,31,White,,0,2,68,230,1,0,18,4,0,36000,0.0,,1,6.0,1.0,1.0,1.0,,,8,0,0,0,0,0.0,0.0,2.0,money, 243 | s253,1,24,White,,1,3,62,165,1,0,6,2,0,45000,0.0,,0,1.0,1.0,1.0,1.0,Medical,4.0,2,1,0,15,0,0.0,0.0,0.0,money, 244 | s254,1,50,White,,0,3,65,210,2,2,202,5,2,140000,1.0,0,1,8.0,2.0,3.0,8.0,Personal loan,3.0,0,3,0,40,0,0.0,5.0,0.0,money,n/a 245 | s255,0,37,White,,0,3,72,160,1,0,12,1,0,29000,1.0,100,1,5.0,1.0,1.0,1.0,,1.0,3,1,0,0,0,0.0,0.0,0.0,money, 246 | s256,1,26,White,,1,4,63,125,2,0,77,2,0,65000,0.0,,0,1.0,1.0,1.0,4.0,,1.0,1,0,0,0,0,0.0,2.0,1.0,money, 247 | s257,0,28,White,,0,4,69,165,1,0,15,2,0,10000,0.0,,1,1.0,1.0,4.0,1.0,,,1,0,1,0,0,0.0,1.0,0.0,money, 248 | s258,1,30,White,,1,3,62,197,2,0,60,3,1,20000,0.0,,0,1.0,1.0,1.0,2.0,,,1,1,0,200,0,0.0,0.0,0.0,money, 249 | s259,0,26,White,,0,3,66,120,1,0,9,5,0,23000,0.0,,0,1.0,1.0,1.0,2.0,"Court fines, past balances with utilities",4.0,0,4,2,0,0,0.0,4.0,0.0,money, 250 | s260,1,39,White,,0,4,67,235,2,0,90,2,1,75000,1.0,80,0,1.0,3.0,4.0,2.0,None,,0,4,0,0,0,0.0,3.0,0.0,money, 251 | s261,1,23,Other,Brazilian,1,1,63,171,3,0,48,1,0,30000,0.0,,0,1.0,1.0,1.0,1.0,NA,1.0,1,0,0,0,0,0.0,0.0,0.0,money, 252 | s262,1,36, Other Asian,,0,4,62,112,1,0,40,3,0,60000,1.0,70,1,,1.0,4.0,1.0,,,1,0,0,0,0,0.0,1.0,0.0,money, 253 | s263,0,23,Choose not to respond,,1,3,70,195,1,0,12,2,0,54000,0.0,,0,1.0,4.0,5.0,3.0,,,0,0,0,0,0,0.0,1.0,0.0,money, 254 | s264,1,22, Black or African American,,0,3,65,119,1,0,39,1,0,55000,0.0,,0,1.0,2.0,2.0,1.0,Medical ,2.0,0,0,2,250,0,0.0,0.0,0.0,money, 255 | s265,0,37,White,,0,5,68,190,2,0,160,3,2,92500,1.0,50,1,7.0,4.0,1.0,4.0,personal loans,4.0,3,0,0,0,0,0.0,1.0,1.0,money, 256 | s266,0,41,White,,0,4,72,190,2,0,264,4,2,65000,1.0,90,1,7.0,4.0,1.0,3.0,,,1,1,0,0,0,0.0,2.0,0.0,money, 257 | s267,0,40,White,,0,3,67,195,2,1,240,3,4,60000,1.0,25,0,1.0,1.0,1.0,1.0,none,1.0,3,0,2,0,0,0.0,1.0,2.0,money, 258 | s268,1,38,White,,0,2,61,115,2,0,216,5,2,105000,1.0,20,1,7.0,1.0,1.0,3.0,,1.0,0,0,3,200,0,1.0,3.0,0.0,money, 259 | s269,1,28,White,,0,4,67,140,2,0,60,4,0,60000,1.0,40,0,1.0,3.0,5.0,2.0,,,1,2,3,600,0,0.0,2.0,1.0,money, 260 | s270,1,37,White,,1,4,62,98,2,1,120,5,1,25000,0.0,,0,1.0,1.0,3.0,1.0,None,1.0,3,2,2,0,0,0.0,4.0,2.0,money, 261 | s271,0,23,White,,0,2,77,195,3,0,44,1,0,45000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money,good use of my time off of my other job 262 | s272,0,26,White,,0,4,70,158,1,0,24,2,0,40000,0.0,,0,3.0,3.0,2.0,3.0,,,1,1,2,100,2,2.0,1.0,1.0,money, 263 | s273,0,33,White,,0,4,64,130,1,0,8,5,0,48000,1.0,30,0,1.0,1.0,1.0,2.0,,,2,1,0,0,0,0.0,3.0,0.0,money, 264 | s274,0,41,White,,0,4,79,245,1,0,18,3,0,22000,0.0,,1,1.0,1.0,5.0,5.0,,,2,2,0,0,0,0.0,3.0,0.0,money, 265 | s275,0,34,White,,0,3,71,165,1,0,6,3,0,55000,1.0,5,0,1.0,1.0,1.0,2.0,none,1.0,2,0,3,350,0,0.0,0.0,0.0,money, 266 | s276,0,39,White,,0,4,72,190,2,0,120,5,2,59000,1.0,40,1,6.0,1.0,1.0,1.0,,,3,1,2,0,0,1.0,2.0,2.0,money, 267 | s277,1,27,White,,1,3,63,120,2,0,73,1,0,40000,0.0,0,0,1.0,1.0,1.0,2.0,,5.0,2,0,0,150,0,1.0,0.0,0.0,money,I like doing studies I am always intrigued by the different kinds of tests that there are. The results interest me also. The money is also a plus 268 | s278,1,37,White,,0,3,64,165,3,0,86,5,0,58000,0.0,,0,1.0,1.0,5.0,1.0,N/A,1.0,2,0,0,0,1,0.0,5.0,0.0,money,N/A 269 | s279,1,24,White,none,0,2,60,156,2,0,28,1,1,23000,0.0,,0,1.0,6.0,1.0,1.0,none,1.0,2,1,0,0,0,0.0,0.0,0.0,money,none 270 | s280,1,28, Asian Indian,,0,4,69,136,2,0,35,1,1,90000,0.0,,0,1.0,3.0,1.0,1.0,Loan,3.0,1,2,0,0,0,1.0,0.0,0.0,money, 271 | s282,0,50,White,,0,2,74,212,2,1,90,5,3,50000,0.0,,1,6.0,2.0,1.0,1.0,,,2,0,2,0,0,0.0,4.0,2.0,money, 272 | s283,0,28,White,,0,3,72,264,1,0,0,0,0,75000,0.0,,1,1.0,1.0,1.0,1.0,n/a,1.0,0,0,1,0,0,0.0,0.0,0.0,money, 273 | s284,0,35,Japanese,,0,3,64,160,1,0,12,2,0,60000,0.0,,1,1.0,1.0,1.0,1.0,N/a,1.0,0,0,3,114,0,0.0,1.0,0.0,money, 274 | s285,1,44, Black or African American,,0,4,65,240,1,0,7,4,0,31000,1.0,40,1,5.0,1.0,1.0,1.0,0,,2,0,1,0,0,0.0,0.0,0.0,money, 275 | s286,0,31,White,,0,4,72,140,1,0,18,5,0,30000,1.0,7000,0,1.0,1.0,1.0,1.0,I have no debt.,1.0,4,0,0,500,0,0.0,0.0,0.0,money, 276 | s288,0,28,White,,0,3,75,285,3,0,3,2,0,24000,0.0,,1,,1.0,2.0,1.0,,1.0,0,0,0,0,0,0.0,2.0,0.0,money, 277 | s289,1,33,White,,0,2,65,132,1,0,13,4,0,55000,0.0,,0,1.0,1.0,1.0,2.0,,,3,0,0,200,0,1.0,0.0,0.0,money, 278 | s290,0,21,White,,0,2,66,117,1,0,16,5,0,14000,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 279 | s291,1,30,White,,0,4,61,115,2,0,84,4,0,103000,0.0,,0,3.0,1.0,1.0,3.0,none,1.0,1,0,0,180,0,0.0,2.0,0.0,money, 280 | s292,1,37,White,,0,3,67,220,2,0,266,1,4,110000,1.0,100,1,8.0,4.0,5.0,4.0,none,,0,2,0,200,0,0.0,1.0,0.0,money, 281 | s293,1,26,White,,0,3,64,125,1,0,5,3,0,75000,0.0,,1,1.0,1.0,5.0,1.0,,,1,0,0,0,0,0.0,0.0,0.0,money, 282 | s294,1,23,White,,0,3,69,160,3,0,40,1,0,5000,0.0,,0,1.0,1.0,1.0,1.0,,,1,2,0,0,0,0.0,0.0,0.0,money, 283 | s295,0,26,White,,0,3,63,160,1,0,35,2,0,70000,0.0,,1,5.0,1.0,1.0,1.0,none,5.0,3,0,0,0,0,1.0,0.0,1.0,money, 284 | s296,1,32,White,,0,4,60,155,3,0,38,5,0,50000,0.0,0,0,1.0,1.0,2.0,2.0,None,1.0,1,1,0,0,0,0.0,2.0,0.0,money, 285 | s297,1,40,White,,0,3,67,150,2,1,84,5,3,49000,1.0,0,0,1.0,3.0,4.0,1.0,medical,2.0,5,1,2,0,0,0.0,2.0,0.0,money, 286 | s298,1,35, Black or African American,,0,4,74,250,1,0,36,5,0,60000,0.0,,0,1.0,1.0,5.0,1.0,,,1,1,0,0,0,0.0,0.0,0.0,money, 287 | s299,1,36,Japanese,,0,4,66,155,1,0,26,3,0,55000,1.0,75,1,,1.0,1.0,1.0,none,1.0,2,1,0,0,0,0.0,0.0,0.0,money, 288 | s301,0,27,White,,0,4,68,200,1,0,18,1,0,37000,0.0,,1,,1.0,4.0,1.0,,,0,0,0,0,0,0.0,3.0,0.0,money, 289 | s302,0,31,White,,0,5,68,164,2,0,84,2,2,112000,1.0,100,1,7.0,4.0,5.0,1.0,none,,3,0,1,0,0,0.0,0.0,0.0,money, 290 | s303,0,22,White,,0,4,69,150,3,0,20,2,0,80000,0.0,,0,1.0,1.0,2.0,1.0,,,2,0,0,50,0,0.0,1.0,0.0,money, 291 | s304,1,44,White,Caucasian ,0,3,68,200,2,0,195,5,0,23000,0.0,,0,1.0,1.0,1.0,2.0,,,10,0,0,0,0,0.0,0.0,0.0,money, 292 | s305,0,28,White,,1,3,74,250,2,0,56,5,0,30000,0.0,,0,1.0,4.0,1.0,1.0,,,0,0,0,0,0,0.0,3.0,0.0,money, 293 | s307,0,28,White,,0,4,69,168,3,0,38,5,0,48000,0.0,,1,6.0,1.0,5.0,1.0,,,3,0,0,0,0,0.0,1.0,0.0,money, 294 | s308,0,32,White,,0,4,74,250,2,0,120,5,1,80000,1.0,20,1,7.0,3.0,4.0,2.0,,,0,0,1,0,0,0.0,1.0,0.0,money, 295 | s309,0,41,White,,0,4,70,200,2,0,250,2,2,97500,1.0,20,1,8.0,3.0,1.0,2.0,,1.0,0,1,0,0,0,0.0,1.0,0.0,money, 296 | s311,1,30,White,,0,4,65,180,3,0,20,4,0,20000,0.0,,0,,1.0,1.0,2.0,,,0,1,1,0,0,0.0,0.0,0.0,money, 297 | s312,0,32,Chinese,,0,3,68,170,1,0,3,1,0,50000,0.0,,0,1.0,1.0,1.0,1.0,,,1,1,0,10,0,0.0,0.0,0.0,money, 298 | s313,1,23, American Indian or Alaska Native,,0,3,67,180,1,0,0,0,0,22000,0.0,,1,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 299 | s314,0,27,White,,0,4,78,325,1,0,16,1,0,30000,0.0,,0,1.0,1.0,6.0,1.0,,,0,0,2,8,0,0.0,0.0,0.0,money, 300 | s315,1,28,White,,0,3,62,160,1,0,9,2,1,40000,0.0,,0,3.0,1.0,2.0,2.0,,3.0,5,0,1,0,0,0.0,0.0,0.0,money, 301 | s316,1,31,White,,0,3,71,143,2,0,73,2,0,64000,1.0,0,0,1.0,1.0,1.0,1.0,none,1.0,1,0,0,0,0,0.0,2.0,0.0,money, 302 | s317,1,28,White,,0,2,65,175,2,0,102,4,1,32000,0.0,,0,1.0,3.0,1.0,1.0,,,3,0,0,0,0,0.0,0.0,0.0,money, 303 | s319,1,36, Black or African American,,0,3,69,260,1,0,24,4,1,19000,0.0,,0,1.0,1.0,4.0,2.0,,,3,0,2,0,0,0.0,3.0,0.0,money, 304 | s320,0,27,White,,1,3,72,275,3,0,45,4,0,25000,0.0,,1,3.0,1.0,5.0,1.0,,,1,2,1,0,0,0.0,0.0,0.0,money, 305 | s321,1,23,White,,0,2,64,220,1,0,0,0,0,20900,0.0,,0,1.0,1.0,1.0,3.0,None.,1.0,3,0,1,0,0,0.0,0.0,1.0,money, 306 | s322,1,32,White,,0,4,63,160,3,0,67,5,0,10000,0.0,,0,1.0,1.0,5.0,1.0,"medical, other things in collections",2.0,0,0,4,0,0,0.0,3.0,0.0,money, 307 | s323,0,34,White,,0,2,69,175,1,0,36,5,0,37000,0.0,,0,2.0,1.0,1.0,1.0,None.,,0,0,0,300,0,0.0,5.0,5.0,money, 308 | s324,0,28,White,,0,2,70,170,3,0,64,3,0,95000,0.0,,0,1.0,1.0,1.0,7.0,,,0,0,0,0,0,0.0,1.0,0.0,money, 309 | s325,1,42,White,,0,4,62,130,2,0,120,4,1,60000,0.0,,0,1.0,3.0,1.0,3.0,,,1,1,0,0,0,0.0,0.0,0.0,money, 310 | s326,0,43,White,,0,2,64,135,1,0,132,4,0,33000,0.0,,0,1.0,2.0,2.0,2.0,n/a,1.0,4,0,0,100,0,0.0,0.0,0.0,tasks are fun, 311 | s327,1,26,White,,0,2,64,150,3,0,65,3,0,42000,0.0,,0,6.0,1.0,1.0,2.0,medical bills,4.0,2,0,0,0,0,0.0,4.0,0.0,money, 312 | s328,0,25,White,,1,3,67,130,3,0,64,3,0,37000,0.0,,0,1.0,3.0,1.0,2.0,,,0,2,1,0,0,0.0,1.0,0.0,money, 313 | s329,1,32,White,,0,3,65,240,3,0,91,3,0,41000,0.0,,0,1.0,3.0,1.0,2.0,,,0,2,4,0,0,0.0,2.0,0.0,money,gives me something to do when I'm bored. 314 | s330,0,24,Other,Mexican,1,4,66,169,3,0,17,6,0,24000,0.0,,1,5.0,1.0,5.0,2.0,,,2,0,0,0,0,0.0,1.0,0.0,money, 315 | s331,1,24, Vietnamese,,0,4,59,110,3,0,65,2,0,40000,0.0,,0,1.0,1.0,4.0,3.0,none,1.0,1,0,1,0,0,0.0,0.0,0.0,money, 316 | s332,0,27,White,,0,3,74,160,1,0,36,5,0,25000,0.0,,0,2.0,1.0,1.0,1.0,,1.0,5,1,0,0,0,0.0,0.0,1.0,money, 317 | s333,0,25,White,,0,3,72,200,3,0,84,3,0,15000,0.0,,1,1.0,1.0,4.0,2.0,,,1,1,0,0,0,0.0,1.0,0.0,money, 318 | s334,1,33,White,,0,3,63,150,2,0,84,4,1,69000,1.0,50,1,7.0,3.0,1.0,2.0,none,1.0,2,0,1,600,0,0.0,2.0,1.0,money, 319 | s335,0,33,White,,0,3,68,148,3,0,44,5,1,30000,0.0,,1,1.0,4.0,1.0,2.0,,4.0,0,0,3,0,0,1.0,3.0,0.0,money, 320 | s336,0,26,Chinese,,0,4,70,230,1,0,15,1,0,35000,0.0,,1,1.0,1.0,3.0,1.0,none,1.0,1,3,0,0,1,0.0,0.0,0.0,money, 321 | s337,1,34, Black or African American,,0,5,67,362,3,0,42,3,0,52000,1.0,60,1,6.0,4.0,7.0,4.0,Taxes owed IRS,2.0,0,0,0,0,0,0.0,2.0,0.0,money, 322 | s338,1,40,White,,0,4,67,130,1,0,32,4,0,15000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,3,0,0,0,0,0.0,1.0,0.0,money, 323 | s339,1,28,White,,0,3,65,190,2,0,84,3,2,74000,0.0,,1,7.0,4.0,1.0,3.0,0,,2,5,0,0,0,0.0,1.0,0.0,money, 324 | s340,0,29,White,,0,4,71,190,2,0,42,5,2,62000,0.0,,0,1.0,1.0,4.0,3.0,n/a,,1,0,0,200,0,0.0,2.0,0.0,money,n/a 325 | s341,1,31, Black or African American,,0,3,66,200,3,0,120,3,1,60000,1.0,20,1,1.0,1.0,3.0,1.0,,,0,0,2,0,0,0.0,1.0,0.0,money, 326 | s342,0,27,White,,0,3,67,170,1,0,12,3,0,10000,0.0,,1,1.0,1.0,3.0,2.0,Medical,2.0,2,0,3,500,0,0.0,0.0,0.0,money, 327 | s343,1,20,Chinese,,0,3,61,126,3,0,48,1,0,11000,0.0,,0,1.0,1.0,3.0,1.0,,,1,0,0,0,0,0.0,1.0,0.0,money, 328 | s344,0,30,White,,0,4,67,150,3,0,78,3,0,55000,0.0,,0,1.0,3.0,4.0,1.0,,,2,0,0,0,0,0.0,1.0,0.0,money, 329 | s345,0,21,White,,0,3,74,165,1,0,18,4,0,20000,0.0,,1,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 330 | s346,0,42, Black or African American,,0,4,75,210,2,0,120,3,2,85000,1.0,10,1,6.0,4.0,2.0,1.0,"Mortgage, car loan",6.0,0,0,1,0,0,0.0,0.0,0.0,money, 331 | s347,0,22,White,,0,4,73,210,3,0,42,2,0,67000,1.0,40,0,1.0,1.0,1.0,2.0,Personal loan,2.0,3,0,2,0,0,0.0,0.0,0.0,money, 332 | s348,0,31,White,,0,3,69,190,1,0,24,4,0,30000,1.0,10,1,1.0,1.0,1.0,1.0,none,1.0,2,0,0,1,0,0.0,1.0,0.0,money, 333 | s349,0,33,White,,0,6,78,300,2,0,121,2,0,75000,0.0,,0,1.0,1.0,5.0,3.0,,,0,0,0,0,0,0.0,2.0,0.0,money, 334 | s350,1,35,White,n/a,0,4,69,165,1,0,120,5,1,60000,0.0,0,0,1.0,3.0,1.0,3.0,n/a,1.0,0,0,1,300,0,0.0,0.0,0.0,money, 335 | s351,1,34,White,,0,2,64,132,1,0,18,4,0,35000,0.0,,1,1.0,3.0,1.0,1.0,none,,0,0,1,121,0,1.0,1.0,0.0,money, 336 | s352,1,25,White,,0,4,69,200,2,0,120,1,2,50000,0.0,,0,1.0,4.0,4.0,2.0,,1.0,1,1,5,0,0,0.0,0.0,0.0,money, 337 | s353,1,26, Black or African American,,0,2,53,150,3,0,64,3,3,20000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,3,0,1,10,0,0.0,1.0,0.0,money, 338 | s354,1,35,White,,0,3,66,170,2,0,210,2,5,49999,1.0,50,1,8.0,1.0,7.0,3.0,,1.0,1,0,3,0,0,0.0,2.0,1.0,money, 339 | s355,0,32,White,,0,4,73,220,1,0,12,1,0,70000,0.0,,1,1.0,1.0,1.0,1.0,none,1.0,0,0,0,15,0,0.0,0.0,0.0,money, 340 | s356,0,34,White,,0,2,69,160,1,0,24,5,0,25000,0.0,,0,1.0,1.0,1.0,2.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 341 | s357,1,49, American Indian or Alaska Native,,0,3,64,120,3,2,120,6,2,50000,0.0,,1,7.0,1.0,3.0,2.0,,,4,0,0,0,0,0.0,0.0,0.0,money, 342 | s358,0,24, Black or African American,,0,4,71,238,1,0,0,0,0,90000,0.0,,1,4.0,,1.0,1.0,,,0,0,0,0,0,1.0,1.0,0.0,money, 343 | s359,0,35, Asian Indian,,0,4,66,154,2,0,63,1,2,76000,0.0,,0,1.0,3.0,1.0,2.0,,,0,2,0,0,0,0.0,0.0,0.0,money, 344 | s360,1,43,White,,0,3,61,130,2,0,144,3,1,52000,0.0,0,0,1.0,3.0,3.0,1.0,medical bills from pregnancy,3.0,5,0,0,0,0,0.0,0.0,0.0,money,They stimulate my brain. 345 | s362,1,28,White,,0,4,66,118,2,0,92,2,0,53000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,3,2,0,0,0,0.0,0.0,0.0,money, 346 | s363,1,49,White,,0,3,62,125,2,0,324,5,1,43000,0.0,,0,1.0,1.0,1.0,2.0,,,4,1,0,0,0,0.0,1.0,0.0,money,Buying a home next year and want to pay off a credit card before we buy as do not want any debt going into a new home. 347 | s364,0,26,White,,0,4,70,145,1,0,16,4,0,35000,0.0,,0,1.0,2.0,3.0,1.0,,1.0,1,0,0,0,1,0.0,0.0,2.0,money, 348 | s365,0,43,White,,0,4,69,210,1,0,12,3,0,16000,0.0,,0,1.0,1.0,1.0,3.0,,,10,0,2,0,2,0.0,2.0,4.0,money, 349 | s366,0,27,White,,0,3,70,220,3,0,52,4,0,36000,0.0,,0,1.0,1.0,4.0,2.0,,,0,0,0,0,0,0.0,2.0,2.0,money, 350 | s368,0,50,White,,0,2,76,300,2,0,216,5,0,25000,0.0,,1,1.0,1.0,1.0,1.0,,,0,6,0,0,0,0.0,3.0,0.0,money,To see how well I can do at certain task at my age and see my response time on certain test 351 | s369,1,33, Black or African American,,0,4,70,180,1,0,36,2,0,55000,0.0,,0,1.0,1.0,5.0,2.0,,,1,2,0,0,0,0.0,0.0,0.0,want to contribute to research, 352 | s370,0,28,White,,0,5,70,210,2,0,84,1,0,22000,0.0,,0,5.0,1.0,5.0,1.0,,1.0,3,0,0,0,0,0.0,1.0,0.0,money, 353 | s372,0,37,White,,0,4,72,195,1,0,6,1,0,50000,0.0,,0,1.0,1.0,5.0,1.0,,,2,0,0,0,0,0.0,0.0,0.0,want to contribute to research, 354 | s373,0,26, American Indian or Alaska Native,,1,4,67,140,3,0,7,4,0,30000,0.0,0,0,1.0,1.0,4.0,1.0,,,3,0,4,0,0,0.0,0.0,0.0,money, 355 | s374,0,34,White,,0,4,73,185,1,0,54,5,0,18000,0.0,,0,1.0,1.0,4.0,1.0,,,0,0,0,0,0,0.0,2.0,0.0,money, 356 | s375,0,48,White,,1,4,70,184,1,0,48,5,0,65000,1.0,60,1,7.0,1.0,1.0,1.0,None.,1.0,0,0,0,0,1,0.0,2.0,1.0,money, 357 | s376,0,39,White,,0,4,76,270,2,0,132,2,2,82000,1.0,25,1,6.0,4.0,5.0,4.0,none,,0,2,0,500,0,0.0,2.0,0.0,money, 358 | s377,0,34,White,,0,4,67,120,3,0,59,6,0,20000,0.0,,1,5.0,1.0,6.0,2.0,,,2,1,1,0,0,0.0,2.0,1.0,money, 359 | s378,0,31,White,,0,4,72,165,3,0,30,4,0,60000,1.0,90,0,1.0,1.0,4.0,4.0,,1.0,0,0,0,0,0,0.0,0.0,0.0,money, 360 | s379,1,31,White,,0,2,64,135,2,0,144,5,2,69000,1.0,0,0,1.0,5.0,1.0,3.0,0,1.0,2,0,0,0,0,0.0,2.0,2.0,money, 361 | s380,1,44,White,,0,2,66,175,2,0,274,2,2,63000,0.0,,1,7.0,5.0,1.0,2.0,none,1.0,1,0,0,95,0,0.0,0.0,0.0,money, 362 | s381,0,37,White,,0,2,70,200,1,0,6,3,0,30000,0.0,,0,1.0,1.0,1.0,2.0,,,0,0,2,60,0,0.0,0.0,0.0,money, 363 | s383,1,50,White,,0,3,64,175,2,1,357,4,2,90000,1.0,60,1,7.0,4.0,1.0,3.0,,,2,0,0,0,0,0.0,2.0,0.0,money, 364 | s384,0,25,White,,0,4,75,180,1,0,0,0,0,15000,0.0,,0,1.0,1.0,5.0,1.0,,1.0,4,0,1,0,0,0.0,1.0,0.0,money, 365 | s386,1,44,White,,0,4,62,125,1,0,48,3,0,19000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,0,0,0,50,0,0.0,1.0,0.0,money, 366 | s387,1,48,White,,0,3,64,180,2,0,363,2,1,54000,0.0,,0,1.0,1.0,6.0,1.0,Children's Hospital,2.0,0,3,1,0,1,0.0,2.0,0.0,money, 367 | s388,1,35,White,,0,5,69,245,2,0,193,3,2,125000,1.0,25,1,7.0,4.0,7.0,4.0,,8.0,1,0,1,0,0,0.0,4.0,1.0,money, 368 | s389,1,50,White,,0,4,70,230,3,2,180,5,3,35000,0.0,,0,1.0,1.0,5.0,1.0,,1.0,4,0,3,0,0,0.0,1.0,0.0,money, 369 | s390,1,27,White,,0,2,63,220,1,0,36,4,0,12000,0.0,,0,1.0,1.0,1.0,1.0,healthcare,2.0,0,3,1,0,0,0.0,0.0,0.0,money, 370 | s391,0,33,White,,0,2,71,225,1,0,24,3,0,50000,0.0,,1,1.0,1.0,1.0,1.0,,,0,0,5,0,0,0.0,0.0,0.0,money, 371 | s392,0,42,White,,0,3,73,190,2,0,260,3,2,42000,0.0,,0,1.0,1.0,1.0,4.0,,1.0,0,0,4,0,0,0.0,0.0,0.0,money, 372 | s393,1,30,White,,0,3,65,135,3,0,96,5,3,25000,1.0,20,1,1.0,1.0,4.0,3.0,,,1,3,0,0,1,1.0,2.0,1.0,money, 373 | s394,1,26,White,,0,4,67,240,1,0,8,2,0,35000,0.0,,0,1.0,1.0,6.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 374 | s395,1,43,White,,0,3,65,347,2,0,48,2,1,15000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,2,0,2,0,0,0.0,0.0,1.0,money, 375 | s396,0,35, Middle Eastern or North African,,0,6,70,118,2,0,169,3,0,149000,0.0,,0,1.0,1.0,1.0,1.0,none,,1,0,0,0,0,0.0,0.0,0.0,money, 376 | s397,0,40,White,,0,3,67,125,3,0,243,2,0,45000,0.0,,1,1.0,1.0,1.0,2.0,,1.0,1,1,0,0,0,0.0,1.0,0.0,money, 377 | s398,1,27, Black or African American,,1,3,67,220,2,0,168,1,2,35000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,0,0,2,50,0,0.0,0.0,0.0,money,My birthday is on September 13th and my 6 year old daughter's is on September 14th!! 378 | s399,1,43, American Indian or Alaska Native,,0,4,70,165,2,1,122,3,4,88600,0.0,,1,2.0,1.0,5.0,4.0,none,1.0,1,0,4,0,0,0.0,4.0,1.0,tasks are fun, 379 | s400,1,32,White,,0,2,66,110,2,0,192,1,5,55000,0.0,,1,1.0,1.0,1.0,1.0,,1.0,2,4,2,150,0,0.0,0.0,0.0,money, 380 | s401,1,26,White,,0,3,68,197,1,0,30,4,0,36000,0.0,,1,2.0,3.0,1.0,1.0,,1.0,2,2,0,1000,0,0.0,1.0,0.0,money, 381 | s402,1,21,White,,0,3,64,200,1,0,0,0,0,10000,0.0,,1,1.0,1.0,1.0,1.0,none ,,1,3,1,3,0,0.0,1.0,0.0,money, 382 | s403,1,22,White,,1,3,64,250,1,0,0,0,0,32000,0.0,,0,1.0,1.0,3.0,1.0,,,0,0,4,0,0,0.0,0.0,0.0,money,To see if I could finish it 383 | s404,1,46,White,,0,3,64,150,2,0,300,5,1,78000,0.0,,0,1.0,3.0,1.0,3.0,,,0,4,0,0,0,0.0,2.0,0.0,money, 384 | s405,1,39,White,,0,3,66,185,2,0,216,3,1,65000,1.0,100,1,6.0,4.0,4.0,3.0,,,0,0,0,1,0,0.0,2.0,0.0,money, 385 | s406,0,25,Other,hispanic,1,3,72,255,2,0,74,4,0,80000,0.0,,0,1.0,3.0,3.0,3.0,personal loans,2.0,2,1,0,200,0,0.0,1.0,0.0,money, 386 | s407,1,29,White,,0,3,69,151,2,0,113,5,1,43500,0.0,,1,5.0,1.0,1.0,1.0,n/a,1.0,0,0,5,0,0,0.0,2.0,0.0,money,paying for obamacare and child's schooling 387 | s408,1,48,White,,0,3,65,154,2,0,244,5,1,34000,0.0,,1,4.0,3.0,6.0,3.0,,,0,0,6,0,0,0.0,4.0,0.0,money, 388 | s409,1,41,White,,0,2,64,114,3,1,192,5,0,24000,1.0,0,0,1.0,3.0,1.0,2.0,,,0,3,1,0,0,0.0,3.0,0.0,money, 389 | s410,1,26,White,,0,3,65,145,3,0,52,3,0,30000,0.0,,1,,1.0,1.0,1.0,,,2,0,1,0,0,0.0,3.0,0.0,money, 390 | s411,0,32,White,,0,5,71,180,3,0,40,5,0,60000,0.0,,0,1.0,3.0,1.0,2.0,,,1,0,0,0,0,1.0,0.0,0.0,money, 391 | s412,0,33,Other,Hispanic,1,3,68,182,3,1,96,2,3,12000,0.0,,0,1.0,1.0,4.0,1.0,,,0,6,2,76,0,0.0,3.0,0.0,money, 392 | s413,0,33,White,,0,5,70,171,2,0,96,4,2,137000,1.0,95,1,7.0,1.0,1.0,1.0,N/A,1.0,0,0,0,0,0,0.0,1.0,0.0,money, 393 | s414,1,45,White,,0,2,64,190,2,1,84,6,1,65000,0.0,,0,1.0,4.0,7.0,3.0,,,1,3,1,0,0,0.0,3.0,0.0,money, 394 | s415,1,38,White,,0,3,68,250,2,0,252,6,2,40000,0.0,,0,1.0,7.0,6.0,1.0,hospital,4.0,10,0,1,0,0,0.0,1.0,3.0,money, 395 | s416,0,22,White,,0,4,68,300,1,0,36,1,0,22000,0.0,,0,1.0,1.0,3.0,2.0,,,3,0,0,0,0,1.0,1.0,0.0,money, 396 | s418,1,21,White,,0,3,60,90,3,0,24,4,0,15000,0.0,,0,1.0,1.0,1.0,2.0,,,0,0,2,0,0,0.0,4.0,1.0,money, 397 | s419,1,25,White,,0,4,65,145,1,0,48,4,0,40000,0.0,,0,1.0,7.0,3.0,3.0,,1.0,0,1,0,0,0,1.0,2.0,0.0,money, 398 | s420,1,34,White,,0,4,71,220,2,0,209,2,2,95000,1.0,5,1,8.0,4.0,1.0,3.0,none,,1,0,1,0,0,0.0,1.0,1.0,money,n/a 399 | s421,1,33,White,,0,4,63,127,2,1,74,3,2,36000,1.0,0,0,1.0,1.0,4.0,1.0,none,,1,0,0,0,0,0.0,3.0,0.0,money, 400 | s422,0,36,Chinese,,0,4,70,185,3,0,93,3,0,54850,1.0,25,1,1.0,2.0,1.0,1.0,N/A,,2,1,0,0,0,0.0,2.0,0.0,money,N/A 401 | s423,1,31,White,,0,2,62,105,1,0,24,3,2,40000,0.0,,1,2.0,2.0,,2.0,0,,2,0,2,250,0,0.0,5.0,3.0,money, 402 | s424,1,39,White,,0,5,64,145,1,0,60,5,0,25000,0.0,,0,1.0,6.0,6.0,1.0,,,2,0,0,0,0,0.0,3.0,1.0,money,The requesters have a good reputation for being communicative and fair among members of the MTurk community. 403 | s425,1,34,White,,0,3,62,185,2,0,60,6,1,5000,0.0,,1,1.0,1.0,1.0,1.0,,,0,1,3,0,0,0.0,0.0,1.0,money, 404 | s426,0,37,White,,1,4,58,190,3,0,72,5,2,35000,0.0,,0,1.0,3.0,6.0,1.0,No others to report. ,1.0,2,4,0,0,2,0.0,2.0,5.0,money, 405 | s427,0,34,White,,0,5,73,221,3,0,35,5,0,90000,1.0,95,0,1.0,1.0,5.0,1.0,none,1.0,4,0,0,0,0,0.0,2.0,0.0,money, 406 | s428,1,50,White,,0,5,65,160,3,1,120,5,2,85000,1.0,70,0,,4.0,,1.0,,,2,1,0,0,0,0.0,1.0,0.0,money, 407 | s429,0,24, Black or African American,N/A,0,2,77,210,1,0,3,1,0,20000,0.0,,0,1.0,1.0,1.0,1.0,N/A,1.0,0,0,0,0,0,0.0,0.0,0.0,money,"I feel another form of motivation was just the fact that I can participate in so many experiments at one time to explore how my mind works, develop my brain even more and at the same time earn a very fair amount of pay for my time. For this reason I stopped all other work I was doing in the week to do this experiment solely, definitely a better use of my time than working for slave wage or worse so thank you for the opportunity to participate and I look forward to more in the future." 408 | s430,1,32,White,,0,3,63,180,1,0,144,1,4,40000,0.0,,0,2.0,1.0,3.0,3.0,,,2,0,3,0,0,0.0,2.0,0.0,money, 409 | s431,1,34,White,,0,4,63,180,2,0,122,4,0,90000,1.0,20,1,7.0,1.0,6.0,3.0,N/A,1.0,2,0,0,0,0,0.0,2.0,0.0,money, 410 | s432,1,37,White,,0,3,63,125,2,0,152,2,0,65000,0.0,,1,8.0,1.0,3.0,3.0,,,1,1,1,0,0,0.0,2.0,0.0,money, 411 | s433,1,28,White,,0,3,62,200,3,0,3,5,0,21000,0.0,,0,3.0,1.0,3.0,1.0,,,1,0,4,152,0,0.0,0.0,1.0,money, 412 | s434,1,34,White,,0,4,65,190,2,0,176,3,2,150000,1.0,80,1,8.0,1.0,1.0,1.0,,,2,0,0,0,0,0.0,0.0,0.0,money, 413 | s435,1,47,White,,0,4,67,150,2,0,264,4,0,50000,1.0,,1,,,,,,,1,1,1,100,0,0.0,4.0,0.0,money,I like to learn things from Mturk tasks. 414 | s436,1,32,White,,0,2,61,110,2,0,180,5,4,45000,0.0,,0,1.0,4.0,1.0,1.0,,,2,0,0,0,0,0.0,1.0,0.0,money, 415 | s438,0,38,White,,0,5,71,215,1,0,102,2,0,90000,0.0,,1,1.0,1.0,1.0,1.0,,,1,0,0,0,0,0.0,4.0,0.0,money, 416 | s439,0,32, Native Hawaiian or Other Pacific Islander,,0,3,76,340,1,0,34,5,0,75000,1.0,10,0,1.0,1.0,2.0,2.0,,,0,0,2,0,0,0.0,2.0,0.0,money, 417 | s440,0,50,White,,0,5,68,180,1,0,36,4,0,65000,0.0,,1,1.0,1.0,1.0,1.0,,,1,0,1,150,0,0.0,0.0,0.0,money, 418 | s441,0,40,White,,0,3,63,159,2,0,168,6,1,1000,0.0,,1,1.0,1.0,3.0,1.0,,,6,0,1,0,0,0.0,3.0,6.0,money, 419 | s443,0,31, Black or African American,,0,4,72,180,3,0,32,5,0,68000,1.0,80,0,,,,3.0,,,4,1,0,0,0,0.0,2.0,3.0,money, 420 | s444,1,31,White,,0,3,67,140,3,1,120,4,0,84000,1.0,20,1,6.0,3.0,2.0,2.0,,,2,1,0,0,0,0.0,0.0,1.0,money, 421 | s445,0,28,White,,0,4,71,180,3,0,29,4,0,30000,0.0,,0,1.0,4.0,5.0,1.0,,,0,0,0,0,0,0.0,0.0,0.0,money, 422 | s446,0,25,White,,0,4,72,167,1,0,3,2,0,39000,0.0,,0,1.0,1.0,5.0,1.0,,,0,1,0,0,0,0.0,1.0,1.0,money, 423 | s447,0,22, Vietnamese,,0,3,67,155,1,0,21,2,0,39999,0.0,,1,1.0,1.0,4.0,1.0,,1.0,1,3,0,2,0,0.0,0.0,0.0,money, 424 | s448,0,34,White,,1,2,70,180,1,0,30,5,0,65000,0.0,0,1,1.0,2.0,1.0,2.0,contract loans,2.0,2,2,1,500,1,0.0,0.0,2.0,money, 425 | s449,1,37,White,,0,6,65,150,2,0,171,5,2,240000,1.0,50,1,7.0,1.0,1.0,3.0,none,1.0,0,0,2,209,0,0.0,2.0,0.0,money, 426 | s450,1,35, Filipino,,0,3,63,200,2,0,242,3,2,35000,0.0,,1,,1.0,1.0,1.0,,,1,0,1,0,0,0.0,1.0,0.0,money, 427 | s451,1,36,White,,0,6,63,160,1,1,156,6,0,23000,0.0,,1,6.0,1.0,1.0,3.0,,,0,2,0,0,0,0.0,1.0,0.0,money, 428 | s453,0,41,White,,0,2,78,220,2,0,18,1,5,65000,0.0,,1,1.0,1.0,1.0,1.0,,1.0,3,5,2,700,0,0.0,0.0,1.0,money, 429 | s454,1,34,White,,0,2,60,112,3,0,96,2,0,40000,0.0,,1,,,,,none,,0,0,1,38,0,0.0,0.0,0.0,money,n/a 430 | s455,0,24,White,,0,2,71,130,1,0,13,4,0,18000,0.0,,0,2.0,1.0,1.0,3.0,,1.0,0,0,3,200,0,0.0,0.0,0.0,money, 431 | s456,0,27,White,,0,3,74,160,1,0,36,3,0,20000,0.0,20,1,2.0,3.0,1.0,3.0,furniture,1.0,0,2,0,100,0,2.0,1.0,0.0,money, 432 | s457,1,47,White,,0,4,71,150,2,0,132,5,0,135000,1.0,60,1,5.0,1.0,1.0,2.0,none,1.0,0,1,0,0,0,0.0,0.0,0.0,money, 433 | s458,1,27,White,,0,3,64,295,2,0,142,3,0,68000,0.0,,0,1.0,1.0,4.0,2.0,personal line of credit from in-laws,4.0,0,0,1,80,0,0.0,2.0,0.0,money, 434 | s459,1,30,White,,0,3,68,300,2,0,60,4,0,40000,0.0,,0,1.0,2.0,5.0,,,,1,0,0,0,0,0.0,2.0,0.0,money, 435 | s460,1,30,White,,0,3,64,110,2,0,144,1,2,80000,1.0,0,0,1.0,2.0,4.0,2.0,,,3,0,0,0,0,0.0,0.0,0.0,money, 436 | s461,1,36,White,,0,3,64,150,1,0,60,5,2,25000,0.0,,1,6.0,1.0,1.0,3.0,,,6,0,0,0,0,0.0,0.0,0.0,money, 437 | s462,1,32,White,,0,2,19,230,2,0,96,2,1,60000,0.0,,1,5.0,1.0,1.0,2.0,,1.0,0,0,2,0,0,0.0,0.0,0.0,money, 438 | s463,0,26,White,,0,3,72,240,3,0,45,2,0,40000,0.0,,0,4.0,1.0,4.0,3.0,,,0,0,6,0,0,0.0,2.0,0.0,money, 439 | s464,1,32,White,,0,3,63,105,2,0,128,5,2,49000.00,0.0,,1,8.0,4.0,1.0,3.0,,,0,1,0,0,0,0.0,0.0,1.0,money, 440 | s465,1,46, Filipino,,0,4,62,125,3,1,240,4,1,49000,1.0,2,0,2.0,1.0,1.0,1.0,Debt from a relative,1.0,3,0,1,40,1,0.0,1.0,0.0,money, 441 | s466,0,30, Black or African American,,0,4,68,150,1,0,48,3,0,40000,0.0,,0,1.0,1.0,3.0,3.0,,,1,0,0,100,0,0.0,2.0,2.0,money, 442 | s467,1,50,White,,0,2,65,280,1,1,260,2,4,30000,0.0,,0,1.0,1.0,4.0,1.0,none,,4,0,1,0,0,0.0,0.0,0.0,money, 443 | s468,1,24,White,,0,4,62,115,3,0,95,3,0,70000,0.0,,0,1.0,1.0,1.0,1.0,,,1,0,1,0,0,0.0,0.0,0.0,money, 444 | s469,1,43,White,,0,4,67,180,1,0,80,4,0,20000,0.0,,1,3.0,1.0,1.0,2.0,none,,0,3,0,0,0,0.0,0.0,0.0,money, 445 | s470,0,31,White,,0,4,69,160,1,0,24,6,0,25000,0.0,,0,1.0,1.0,3.0,1.0,,,2,0,0,0,0,0.0,1.0,0.0,money, 446 | s471,0,32,White,,0,4,69,155,1,0,54,5,0,65000,0.0,0,0,1.0,1.0,1.0,1.0,none,1.0,2,0,0,55,0,0.0,2.0,0.0,money, 447 | s472,1,49,White,,0,2,61,185,2,1,276,3,3,19000,0.0,,1,4.0,1.0,1.0,1.0,,,0,5,2,25,0,0.0,0.0,0.0,money, 448 | s473,0,23, Other Asian,,0,4,70,150,1,0,36,1,0,30000,1.0,0,0,,,,,,,1,0,0,200,0,1.0,0.0,0.0,money, 449 | s474,0,28,White,,0,4,65,180,1,0,0,0,0,50000,1.0,100,1,1.0,1.0,1.0,1.0,,1.0,0,1,0,0,0,0.0,0.0,0.0,money, 450 | s475,0,27,White,,0,3,70,190,1,0,24,5,0,24000,0.0,,0,1.0,1.0,2.0,1.0,,,1,0,0,35,0,0.0,2.0,0.0,money, 451 | s476,0,44,White,,0,3,69,145,2,1,202,3,2,55000,0.0,0,0,1.0,4.0,3.0,3.0,none,,0,0,2,0,0,0.0,2.0,1.0,money, 452 | s477,0,32,White,,0,2,66,135,1,0,8,2,0,10000,0.0,,1,4.0,1.0,1.0,1.0,,,0,0,2,0,0,0.0,0.0,1.0,money, 453 | s478,1,40,White,,0,3,59,86,1,0,2,4,0,68000,0.0,,0,1.0,1.0,1.0,1.0,,,3,0,0,0,0,0.0,0.0,0.0,money, 454 | s479,1,49,White,,0,4,64,115,3,2,264,5,2,42000,1.0,40,1,6.0,1.0,1.0,1.0,0,1.0,0,1,0,0,0,0.0,2.0,0.0,money, 455 | s480,1,30, Middle Eastern or North African,,0,2,62,113,1,0,36,5,2,12000,0.0,,1,6.0,1.0,1.0,1.0,none,,2,0,0,0,0,0.0,0.0,0.0,money, 456 | s481,1,29,White,,0,5,66,185,1,0,15,3,0,15000,0.0,,0,1.0,1.0,7.0,2.0,,,1,0,1,0,0,0.0,2.0,0.0,money, 457 | s482,1,41,White,,0,3,65,194,2,0,276,3,4,82000,1.0,75,0,1.0,4.0,5.0,4.0,,,3,0,1,0,0,1.0,3.0,0.0,money, 458 | s483,1,28,White,,0,3,71,185,2,0,240,1,0,25000,0.0,,0,,1.0,,3.0,Medical,5.0,1,1,0,0,0,0.0,0.0,0.0,money, 459 | s484,0,38,White,,1,2,70,180,2,0,120,3,1,27000,0.0,,1,1.0,3.0,1.0,2.0,,1.0,1,2,0,200,0,0.0,0.0,0.0,money, 460 | s485,1,22,White,,0,3,64,180,1,0,12,2,0,15500,1.0,,0,1.0,4.0,1.0,2.0,personal loans,1.0,5,1,0,600,0,0.0,0.0,0.0,money, 461 | s486,0,50,White,,0,6,76,205,1,1,144,6,1,90000,1.0,60,1,7.0,1.0,1.0,4.0,,,1,0,0,0,1,0.0,3.0,2.0,money, 462 | s488,0,28,White,,0,2,70,215,3,0,36,3,0,30000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,1,0,1,0,0,0.0,0.0,6.0,money, 463 | s489,1,34,White,,0,4,62,166,2,0,162,5,2,130000,0.0,0,1,8.0,4.0,1.0,5.0,IRS,2.0,2,0,0,0,0,0.0,1.0,0.0,money, 464 | s490,1,46,White,,0,3,69,160,1,3,50,5,2,15000,0.0,,1,1.0,1.0,1.0,1.0,none,1.0,2,0,1,0,0,0.0,1.0,0.0,money, 465 | s491,1,44, Black or African American,,0,3,60,160,1,1,204,2,1,44000,1.0,100,0,1.0,4.0,1.0,2.0,,2.0,1,0,0,0,0,2.0,0.0,0.0,want to contribute to research, 466 | s492,0,30, Black or African American,,0,3,72,320,1,0,48,5,2,70000,0.0,,0,2.0,2.0,2.0,2.0,Medical Bills,1.0,0,0,0,0,0,2.0,1.0,1.0,money, 467 | s493,1,35,White,,0,4,66,130,3,1,240,6,0,25000,0.0,0,0,1.0,1.0,4.0,1.0,None,1.0,0,0,2,0,0,0.0,1.0,0.0,money, 468 | s494,0,46,White,,0,4,69,145,3,0,130,4,0,52000,1.0,40,1,6.0,1.0,1.0,1.0,0,1.0,1,0,0,0,0,1.0,2.0,0.0,money, 469 | s495,1,40,White,,1,3,63,150,2,0,50,2,1,35000,0.0,,0,1.0,1.0,1.0,3.0,,,1,0,1,0,0,0.0,1.0,0.0,money, 470 | s496,1,34,White,,0,4,63,120,1,0,36,3,0,30000,0.0,,0,6.0,1.0,1.0,4.0,personal loans,4.0,4,2,1,0,0,0.0,0.0,0.0,money, 471 | s497,0,41,White,,0,3,69,150,1,0,12,5,0,2400,0.0,,0,1.0,1.0,1.0,1.0,,,0,0,0,0,0,0.0,1.0,0.0,money, 472 | s498,0,27,White,,0,3,66,160,1,0,24,5,0,45000,0.0,,0,1.0,1.0,5.0,1.0,,,4,0,2,0,0,0.0,2.0,4.0,money, 473 | s499,0,31,White,,0,6,66,180,2,0,46,5,0,16000,0.0,,0,1.0,1.0,8.0,1.0,,8.0,2,1,1,0,0,0.0,2.0,2.0,money, 474 | s500,1,46,White,,0,6,67,190,1,0,60,4,0,107500,1.0,85,1,6.0,1.0,4.0,4.0,none,1.0,4,1,0,0,0,0.0,2.0,0.0,money,turk is kind of a hobby for me . . . a bit of money while relaxing at night 475 | s501,1,34,White,,0,4,63,115,1,0,124,4,2,12000,1.0,100,0,1.0,1.0,1.0,1.0,,,2,0,1,0,0,0.0,1.0,1.0,money, 476 | s502,1,35,Chinese,,0,4,62,100,3,0,12,5,0,33330,1.0,0,0,,,,,,,2,0,0,3,0,0.0,3.0,0.0,money, 477 | s503,1,38,White,,0,3,68,190,3,1,115,5,5,55000,0.0,,1,1.0,4.0,1.0,7.0,na,1.0,0,0,4,100,0,0.0,0.0,2.0,money, 478 | s504,0,41,White,,0,5,57,260,1,0,15,3,0,40000,1.0,100,0,1.0,1.0,4.0,1.0,,,4,1,0,0,1,0.0,2.0,0.0,money, 479 | s505,0,25,White,,0,4,69,165,1,0,36,4,0,20000,0.0,,0,5.0,1.0,5.0,2.0,,1.0,1,0,1,0,1,0.0,1.0,0.0,money, 480 | s506,0,26, American Indian or Alaska Native,,0,2,74,360,3,0,30,2,0,25000,0.0,,0,,,,,,,0,12,0,0,0,0.0,0.0,0.0,money, 481 | s507,1,33,White,,0,4,69,220,2,0,168,2,1,62000,1.0,70,0,,4.0,5.0,3.0,,,0,0,2,0,0,0.0,0.0,0.0,money, 482 | s508,1,29, Other Asian,Asian American,0,4,68,130,1,0,78,1,0,36000,0.0,0,0,1.0,1.0,4.0,4.0,n/a,1.0,0,0,0,0,0,0.0,0.0,0.0,money,n/a 483 | s509,1,34,White,,1,3,62,175,1,1,90,4,1,50000,1.0,10,0,1.0,1.0,1.0,3.0,,1.0,1,0,1,0,0,0.0,2.0,0.0,money,curiosity-everyone was talking about it 484 | s510,1,44,White,,0,4,66,185,2,0,193,5,1,45000,0.0,,0,1.0,1.0,1.0,1.0,,1.0,2,0,0,0,0,1.0,1.0,2.0,want to contribute to research, 485 | s511,0,28,White,,0,3,67,160,2,0,96,5,1,50000,0.0,,1,,,,,,,2,0,2,0,0,0.0,0.0,2.0,money, 486 | s512,1,48,White,,0,4,64,136,2,1,276,5,3,85000,0.0,,1,6.0,5.0,4.0,3.0,none,,2,0,0,0,0,0.0,0.0,0.0,money, 487 | s513,1,30,White,,0,3,5,130,2,0,144,4,3,49000,1.0,100,1,6.0,1.0,1.0,7.0,,1.0,1,0,0,0,0,0.0,2.0,0.0,money, 488 | s514,0,45,White,,0,3,70,179,1,1,82,3,3,37500,0.0,,0,1.0,1.0,1.0,1.0,,,1,2,4,0,0,0.0,3.0,2.0,money,Trying to prove to myself I can do all 63 tasks in a week. It's an act of discipline I suppose. 489 | s515,0,20,Chinese,,0,3,66,120,1,0,3,1,0,19000,0.0,,0,1.0,1.0,1.0,1.0,none,,0,0,0,0,0,0.0,0.0,0.0,money, 490 | s516,1,28,White,,0,3,68,222,2,0,70,4,2,40000,0.0,,0,1.0,1.0,4.0,1.0,Medical,4.0,2,0,1,0,0,0.0,2.0,1.0,money, 491 | s517,0,32, Black or African American,,0,4,6,176,1,0,0,0,0,5000,0.0,,1,,,,,,,0,0,0,0,0,0.0,0.0,0.0,money, 492 | s520,1,28,White,,0,2,58,109,1,0,24,1,0,70000,0.0,,1,,,,,none,,0,0,0,0,0,0.0,0.0,0.0,money, 493 | s521,0,45,White,,0,4,75,180,3,0,168,6,0,50000,0.0,,0,1.0,1.0,1.0,1.0,,,2,4,0,0,0,0.0,0.0,0.0,money, 494 | s522,1,26,White,,0,3,60,165,3,0,16,1,0,6000,0.0,,0,1.0,1.0,3.0,1.0,,1.0,1,2,0,0,0,1.0,1.0,0.0,money, 495 | s523,1,43,White,,0,3,68,136,1,1,36,5,0,24000,0.0,,0,1.0,1.0,5.0,1.0,,1.0,0,1,0,0,0,0.0,1.0,1.0,money, 496 | s524,1,31,White,,0,2,60,136,2,0,113,3,0,60000,0.0,,1,6.0,1.0,1.0,1.0,none,,0,0,2,0,0,0.0,0.0,0.0,money, 497 | s526,0,30,White,,0,2,72,245,3,0,84,4,0,15000,0.0,,0,1.0,1.0,6.0,1.0,,1.0,0,0,0,0,0,0.0,0.0,1.0,money, 498 | s527,1,39,White,,0,3,66,160,1,1,93,3,2,32000,0.0,,0,1.0,8.0,4.0,3.0,,,4,0,0,0,0,0.0,2.0,0.0,money, 499 | s528,1,42,White,,0,3,65,165,2,0,232,4,2,32000,0.0,,1,1.0,1.0,4.0,1.0,,,5,1,3,0,0,0.0,0.0,2.0,money, 500 | s529,1,43,White,,0,4,64,140,1,0,36,3,0,20000,0.0,,1,1.0,1.0,1.0,1.0,,,2,1,0,0,0,0.0,1.0,1.0,money, 501 | s531,1,45,Chinese,,0,3,61,135,2,1,144,5,2,52000,0.0,,1,6.0,1.0,6.0,2.0,,,0,0,1,0,0,0.0,3.0,0.0,money, 502 | s533,0,28,White,,0,3,65,150,1,0,24,5,0,38000,0.0,,0,1.0,1.0,1.0,1.0,,,0,1,0,0,0,0.0,1.0,0.0,money, 503 | s534,1,31,White,,0,3,67,142,3,0,84,4,0,78000,0.0,,0,1.0,1.0,1.0,1.0,medical bills,2.0,3,1,0,300,0,0.0,2.0,0.0,money, 504 | s535,0,31,White,,0,4,72,200,2,0,120,1,3,60000,1.0,50,0,1.0,1.0,1.0,1.0,,1.0,0,0,0,600,0,0.0,1.0,0.0,money, 505 | s538,1,43,White,,0,4,70,130,1,1,60,5,0,45000,1.0,0,1,1.0,1.0,1.0,1.0,I have no debt beyond monthly and annual bills like utilities and taxes,1.0,0,0,0,0,0,0.0,1.0,0.0,money, 506 | s539,0,29,White,,0,3,68,270,3,0,35,3,0,25000,0.0,,0,1.0,1.0,,2.0,,,0,2,4,0,0,0.0,1.0,0.0,money, 507 | s541,1,32,White,,0,4,59,108,3,0,66,5,0,15000,0.0,,1,1.0,1.0,5.0,1.0,,,3,0,1,15,0,0.0,0.0,1.0,money, 508 | s542,0,42,White,,0,3,70,275,2,0,216,2,2,15000,0.0,0,1,,,,,none,,0,5,0,150,0,0.0,2.0,0.0,money,none 509 | s543,1,43,White,,0,3,67,293,1,1,4,5,1,30000,0.0,,0,1.0,4.0,1.0,2.0,,1.0,1,0,1,1,0,1.0,3.0,0.0,money, 510 | s544,1,41, Filipino,,0,3,65,120,2,1,108,3,4,90000,0.0,,1,8.0,4.0,1.0,,,,5,2,1,300,0,1.0,0.0,0.0,money, 511 | s545,0,35,White,,0,2,69,180,2,0,192,5,1,22000,0.0,,1,1.0,1.0,1.0,1.0,n/a,1.0,0,1,1,0,0,0.0,2.0,3.0,money, 512 | s546,1,34,White,,0,3,70,373,3,1,138,5,0,25000,0.0,,0,,3.0,3.0,1.0,,,1,2,0,0,0,0.0,2.0,0.0,money, 513 | s548,1,28,Other,Multiracial,0,4,72,220,1,0,0,0,0,5900,0.0,0,0,1.0,1.0,6.0,1.0,None,1.0,1,1,0,25,0,0.0,0.0,0.0,money,None 514 | s549,0,28,White,,0,4,71,175,1,0,16,2,0,35000,0.0,,0,1.0,4.0,5.0,2.0,,,1,1,0,0,0,1.0,3.0,1.0,money, 515 | s550,1,34,Choose not to respond,,0,4,62,120,3,0,65,5,0,0,0.0,0,1,,1.0,1.0,,,,2,0,1,5,0,0.0,1.0,1.0,money, 516 | s551,0,37,White,,0,3,67,140,2,2,108,6,6,12000,1.0,,1,3.0,1.0,2.0,1.0,Medical bills,2.0,1,2,2,0,0,0.0,2.0,2.0,money, 517 | s552,0,33,White,,0,3,57,167,3,0,75,1,0,52500,1.0,50,1,5.0,1.0,1.0,1.0,family,3.0,0,1,0,0,0,0.0,5.0,2.0,money, 518 | s553,0,44, Black or African American,,0,3,67,173,3,1,102,4,2,76000,1.0,10,1,5.0,4.0,1.0,1.0,N/A,,1,0,1,200,0,0.0,1.0,0.0,money,N/A 519 | s554,1,23,White,,0,3,69,220,1,0,61,1,0,41000,1.0,25,0,1.0,1.0,5.0,1.0,none,,0,0,0,0,0,0.0,0.0,0.0,money, 520 | s556,0,44,White,,0,4,70,220,2,0,8,6,2,90000,0.0,,1,8.0,4.0,1.0,1.0,,,0,0,5,200,0,1.0,1.0,0.0,money, 521 | s557,0,20,White,,0,3,70,140,1,0,0,0,0,80000,0.0,0,0,1.0,2.0,3.0,1.0,,1.0,0,1,0,0,0,0.0,0.0,0.0,money, 522 | s559,1,39,White,,0,4,65,243,3,0,60,5,1,50000,0.0,,0,1.0,1.0,6.0,4.0,,1.0,0,4,6,0,0,0.0,5.0,2.0,money, 523 | s560,0,23, Vietnamese,,0,4,69,145,1,0,22,4,0,25000,0.0,0,0,1.0,1.0,7.0,3.0,,,3,0,2,0,0,0.0,4.0,3.0,money, 524 | --------------------------------------------------------------------------------