Crime by the Numbers: A Criminologist’s Guide to R

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

A Criminologist's Guide to R: Crime by the Numbers introduces the programming language R and covers the necessary skills to conduct quantitative research in criminology. By the end of this book, a person without any prior programming experience can take raw crime data, be able to clean it, visualize the data, present it using R Markdown, and change it to a format ready for analysis. A Criminologist's Guide to R focuses on skills specifically for criminology such as spatial joins, mapping, and scraping data from PDFs, however any social scientist looking for an introduction to R for data analysis will find this useful. Key Features Introduction to RStudio including how to change user preference settings. Basic data exploration and cleaning – subsetting, loading data, regular expressions, aggregating data. Graphing with ggplot2. How to make maps (hotspot maps, choropleth maps, interactive maps). Webscraping and PDF scraping. Project management – how to prepare for a project, how to decide which projects to do, best ways to collaborate with people, how to store your code (using git), and how to test your code.

Author(s): Jacob Kaplan
Series: Chapman & Hall/CRC The R Series
Publisher: CRC Press/Chapman & Hall
Year: 2022

Language: English
Pages: 431
City: Boca Raton

Cover
Half Title
Series Page
Title Page
Copyright Page
Dedication
Contents
Preface
About the author
I. Introduction
1. A soup to nuts project example
1.1. Big picture data example
1.2. Little picture data example
1.2.1. Loading packages
1.2.2. Loading data
1.2.3. Cleaning
1.2.4. Aggregating
1.2.5. Graphing
1.3. Reusing and modifying code
2. Introduction to R and RStudio
2.1. Using RStudio
2.1.1. Opening an R Script
2.1.2. Setting the working directory
2.1.3. Changing RStudio
2.1.4. Helpful cheat sheets
2.2. Assigning variables
2.3. What are functions (and packages)?
2.4. Reading data into R
2.4.1. Loading data
2.5. First steps to exploring data
3. Data types and structures
3.1. Data types
3.2. Numeric, character, and logical (boolean)
3.3. Data structures
3.3.1. Vectors (collections of “things”)
3.3.2. Data.frames
3.3.3. Other data structures
4. Reading and writing data
4.1. Reading data into R
4.1.1. R
4.1.2. Excel
4.1.3. Stata
4.1.4. SAS
4.1.5. SPSS
4.1.6. Fixed-width ASCII
4.2. Writing data
4.2.1. R
4.2.2. Excel
4.2.3. Stata
4.2.4. SAS
4.2.5. SPSS
II. Project Management
5. Mise en place
5.1. Starting with a pencil and paper
5.1.1. Tables and graphs
5.2. R Projects
5.2.1. Folders
5.3. Modular R scripts
5.4. Modular code
5.4.1. Section labels
5.4.2. Helper R scripts
6. Collaboration
6.1. Code review
6.1.1. Style guidelines
6.2. Documentation
6.2.1. Comments
6.2.2. Vignettes
7. R Markdown
7.1. Code
7.1.1. Hiding code in the output
7.2. Inline Code
7.3. Tables
7.4. Footnotes
7.5. Citation
7.6. Spell check
7.7. Making the output file
8. Testing your code
8.1. Why test your code?
8.2. Unit tests
8.2.1. Modular test scripts
8.2.2. How to write unit tests
8.2.3. What to test
8.3. Test-driven development (TDD)
9. Git
9.1. What is Git, and why do I need it?
9.2. Git basics
9.3. Using Git
9.3.1. Setting up Git
9.3.2. Setting up GitHub
9.4. Setting up Git on an already-made R Project
9.5. Using Git through RStudio
9.6. When to commit
9.7. Other resources
III. Clean
10. Subsetting: Making big things small
10.1. Select specific values
10.2. Logical values and operations
10.2.1. Matching a single value
10.2.2. Matching multiple values
10.2.3. Does not match
10.2.4. Greater than or less than
10.2.5. Combining conditional statements - or, and
10.3. Subsetting a data.frame
10.3.1. Select specific columns
10.3.2. Select specific rows
10.3.3. Subset Colorado data
11. Exploratory data analysis
11.1. Summary and Table
11.2. Graphing
11.3. Aggregating (summaries of groups)
11.4. Pipes in dplyr
12. Regular Expressions
12.1. Finding patterns in text with grep()
12.2. Finding and replacing patterns in text with gsub()
12.3. Useful special characters
12.3.1. Multiple characters []
12.3.2. n-many of previous character {n}
12.3.3. n-many to m-many of previous character {n,m}
12.3.4. Start of string
12.3.5. End of string $
12.3.6. Anything
12.3.7. One or more of previous +
12.3.8. Zero or more of previous *
12.3.9. Multiple patterns |
12.3.10. Parentheses ()
12.3.11. Optional text ?
12.4. Changing capitalization
13. Reshaping data
13.1. Reshaping a single column
13.2. Reshaping multiple columns
IV. Visualize
14. Graphing with ggplot2
14.1. What does the data look like?
14.2. Graphing data
14.3. Time-series plots
14.4. Scatter plots
14.5. Color blindness
15. More graphing with ggplot2
15.1. Exploring data
15.2. Graphing a single numeric variable
15.2.1. Histogram
15.2.2. Density plot
15.2.3. Count graph
15.3. Graphing a categorical variable
15.3.1. Bar graph
15.4. Graphing data over time
15.5. Pretty graphs
15.5.1. Themes
16. Hotspot maps
16.1. A simple map
16.2. What really are maps?
16.3. Making a hotspot map
16.3.1. Colors
17. Choropleth maps
17.1. Spatial joins
17.2. Making choropleth maps
18. Interactive maps
18.1. Why do interactive graphs matter?
18.1.1. Understanding your data
18.1.2. Police departments use them
18.2. Making the interactive map
18.3. Adding popup information
18.4. Dealing with too many markers
18.5. Interactive choropleth maps
V. Collect
19. Webscraping with rvest
19.1. Scraping one page
19.2. Cleaning the webscraped data
20. Functions
20.1. A simple function
20.2. Adding parameters
20.3. Making a function to scrape recipes
21. For loops
21.1. Basic for loops
21.2. Scraping multiple recipes
22. Scraping tables from PDFs
22.1. Scraping the first table
22.2. Making a function
23. More scraping tables from PDFs
23.1. Texas jail data
23.2. Pregnant women incarcerated
23.3. Making PDF-scraped data available to others
24. Geocoding
24.1. Geocoding a single address
24.2. Geocoding San Francisco marijuana dispensary locations
Bibliography