Muutke küpsiste eelistusi

Criminologist's Guide to R: Crime by the Numbers [Kõva köide]

  • Formaat: Hardback, 410 pages, kõrgus x laius: 234x156 mm, kaal: 820 g, 2 Tables, black and white; 4 Line drawings, color; 45 Line drawings, black and white; 29 Halftones, color; 89 Halftones, black and white; 33 Illustrations, color; 134 Illustrations, black and white
  • Sari: Chapman & Hall/CRC The R Series
  • Ilmumisaeg: 15-Dec-2022
  • Kirjastus: Chapman & Hall/CRC
  • ISBN-10: 1032244070
  • ISBN-13: 9781032244075
Teised raamatud teemal:
  • Formaat: Hardback, 410 pages, kõrgus x laius: 234x156 mm, kaal: 820 g, 2 Tables, black and white; 4 Line drawings, color; 45 Line drawings, black and white; 29 Halftones, color; 89 Halftones, black and white; 33 Illustrations, color; 134 Illustrations, black and white
  • Sari: Chapman & Hall/CRC The R Series
  • Ilmumisaeg: 15-Dec-2022
  • Kirjastus: Chapman & Hall/CRC
  • ISBN-10: 1032244070
  • ISBN-13: 9781032244075
Teised raamatud teemal:
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.

Arvustused

"While many introductory R books use heterogeneous examples, here, the author did a great job introducing the R programming language using examples from criminology in a homogenous way. This book also offers a valuable compendium of crime related datasets for those already familiar programming in R. Specially, for graduate students, researchers, and data scientists, that wish to conduct more complex analyses on these types of data."

- Enrique Garcia-Ceja, Tecnologico de Monterrey, Mexico, Technometrics, November 2023.

Preface xiii
About the author xxi
I Introduction
1(54)
1 A soup to nuts project example
3(10)
1.1 Big picture data example
3(4)
1.2 Little picture data example
7(4)
1.2.1 Loading packages
7(1)
1.2.2 Loading data
7(1)
1.2.3 Cleaning
8(1)
1.2.4 Aggregating
9(1)
1.2.5 Graphing
10(1)
1.3 Reusing and modifying code
11(2)
2 Introduction to R and RStudio
13(22)
2.1 Using RStudio
13(10)
2.1.1 Opening an R Script
15(1)
2.1.2 Setting the working directory
16(1)
2.1.3 Changing RStudio
17(5)
2.1.4 Helpful cheat sheets
22(1)
2.2 Assigning variables
23(2)
2.3 What are functions (and packages)?
25(5)
2.4 Reading data into R
30(1)
2.4.1 Loading data
30(1)
2.5 First steps to exploring data
30(5)
3 Data types and structures
35(12)
3.1 Data types
35(1)
3.2 Numeric, character, and logical (boolean)
36(4)
3.3 Data structures
40(7)
3.3.1 Vectors (collections of "things")
40(1)
3.3.2 Data.frames
41(3)
3.3.3 Other data structures
44(3)
4 Reading and writing data
47(8)
4.1 Reading data into R
47(5)
4.1.1 R
47(1)
4.1.2 Excel
48(2)
4.1.3 Stata
50(1)
4.1.4 SAS
51(1)
4.1.5 SPSS
51(1)
4.1.6 Fixed-width ASCII
51(1)
4.2 Writing data
52(3)
4.2.1 R
53(1)
4.2.2 Excel
53(1)
4.2.3 Stata
53(1)
4.2.4 SAS
54(1)
4.2.5 SPSS
54(1)
II Project Management
55(72)
5 Mise en place
57(14)
5.1 Starting with a pencil and paper
57(3)
5.1.1 Tables and graphs
58(2)
5.2 R Projects
60(6)
5.2.1 Folders
64(2)
5.3 Modular R scripts
66(2)
5.4 Modular code
68(3)
5.4.1 Section labels
68(2)
5.4.2 Helper R scripts
70(1)
6 Collaboration
71(6)
6.1 Code review
71(2)
6.1.1 Style guidelines
72(1)
6.2 Documentation
73(4)
6.2.1 Comments
73(1)
6.2.2 Vignettes
74(3)
7 R Markdown
77(16)
7.1 Code
81(2)
7.1.1 Hiding code in the output
83(1)
7.2 Inline Code
83(1)
7.3 Tables
84(1)
7.4 Footnotes
84(1)
7.5 Citation
85(5)
7.6 Spell check
90(1)
7.7 Making the output file
90(3)
8 Testing your code
93(14)
8.1 Why test your code?
93(3)
8.2 Unit tests
96(9)
8.2.1 Modular test scripts
98(3)
8.2.2 How to write unit tests
101(2)
8.2.3 What to test
103(2)
8.3 Test-driven development (TDD)
105(2)
9 Git
107(20)
9.1 What is Git, and why do I need it?
107(2)
9.2 Git basics
109(1)
9.3 Using Git
110(7)
9.3.1 Setting up Git
111(1)
9.3.2 Setting up GitHub
112(5)
9.4 Setting up Git on an already-made R Project
117(3)
9.5 Using Git through RStudio
120(6)
9.6 When to commit
126(1)
9.7 Other resources
126(1)
III Clean
127(92)
10 Subsetting: Making big things small
129(32)
10.1 Select specific values
129(3)
10.2 Logical values and operations
132(7)
10.2.1 Matching a single value
133(1)
10.2.2 Matching multiple values
134(1)
10.2.3 Does not match
135(1)
10.2.4 Greater than or less than
136(1)
10.2.5 Combining conditional statements - or, and
136(3)
10.3 Subsetting a data.frame
139(22)
10.3.1 Select specific columns
146(1)
10.3.2 Select specific rows
147(7)
10.3.3 Subset Colorado data
154(7)
11 Exploratory data analysis
161(22)
11.1 Summary and Table
163(5)
11.2 Graphing
168(3)
11.3 Aggregating (summaries of groups)
171(7)
11.4 Pipes in dpiyr
178(5)
12 Regular Expressions
183(24)
12.1 Finding patterns in text with grep()
185(4)
12.2 Finding and replacing patterns in text with gsub()
189(3)
12.3 Useful special characters
192(10)
12.3.1 Multiple characters [ ]
193(2)
12.3.2 n-many of previous character {n}
195(1)
12.3.3 n-many to m-many of previous character {n,m}
195(3)
12.3.4 Start of string
198(1)
12.3.5 End of string $
198(1)
12.3.6 Anything
198(1)
12.3.7 One or more of previous
199(1)
12.3.8 Zero or more of previous
199(2)
12.3.9 Multiple patterns
201(1)
12.3.10 Parentheses ()
201(1)
12.3.11 Optional text?
202(1)
12.4 Changing capitalization
202(5)
13 Reshaping data
207(12)
13.1 Reshaping a single column
211(5)
13.2 Reshaping multiple columns
216(3)
IV Visualize
219(114)
14 Graphing with ggpiot2
221(20)
14.1 What does the data look like?
222(1)
14.2 Graphing data
223(1)
14.3 Time-series plots
224(12)
14.4 Scatter plots
236(1)
14.5 Color blindness
237(4)
15 More graphing with ggptot2
241(36)
15.1 Exploring data
242(11)
15.2 Graphing a single numeric variable
253(7)
15.2.1 Histogram
254(4)
15.2.2 Density plot
258(1)
15.2.3 Count graph
259(1)
15.3 Graphing a categorical variable
260(7)
15.3.1 Bar graph
260(7)
15.4 Graphing data over time
267(4)
15.5 Pretty graphs
271(6)
15.5.1 Themes
272(5)
16 Hotspot maps
277(16)
16.1 A simple map
279(7)
16.2 What really are maps?
286(1)
16.3 Making a hotspot map
287(6)
16.3.1 Colors
290(3)
17 Choropleth maps
293(18)
17.1 Spatial joins
298(7)
17.2 Making choropleth maps
305(6)
18 Interactive maps
311(22)
18.1 Why do interactive graphs matter?
312(1)
18.1.1 Understanding your data
312(1)
18.1.2 Police departments use them
312(1)
18.2 Making the interactive map
312(5)
18.3 Adding popup information
317(4)
18.4 Dealing with too many markers
321(2)
18.5 Interactive choropleth maps
323(10)
V Collect
333(76)
19 Webscraping with $$
335(8)
19.1 Scraping one page
337(4)
19.2 Cleaning the webscraped data
341(2)
20 Functions
343(6)
20.1 A simple function
343(2)
20.2 Adding parameters
345(1)
20.3 Making a function to scrape recipes
346(3)
21 For loops
349(6)
21.1 Basic for loops
349(3)
21.2 Scraping multiple recipes
352(3)
22 Scraping tables from PDFs
355(18)
22.1 Scraping the first table
358(8)
22.2 Making a function
366(7)
23 More scraping tables from PDFs
373(24)
23.1 Texas jail data
373(14)
23.2 Pregnant women incarcerated
387(6)
23.3 Making PDF-scraped data available to others
393(4)
24 Geocoding
397(12)
24.1 Geocoding a single address
397(6)
24.2 Geocoding San Francisco marijuana dispensary locations
403(6)
Bibliography 409
Jacob Kaplan is the Chief Data Scientist of the Research on Policing Reform and Accountability (RoPRA), a multi-disciplinary, multi-institutional team of social scientists studying the feasibility and efficacy of policing reform, with a focus on statistically rigorous research and practical applications. His current appointment is at the Princeton School of Public and International Affairs. He holds a PhD and a masters degree in criminology from the University of Pennsylvania and a bachelors degree in criminal justice from California State University, Sacramento. He is the author of several R packages that make it easier to work with data, including fastDummies and asciiSetupReader. He is also the author of books on the two primary criminal justice data sets: the FBIs Uniform Crime Reporting (UCR) Program Data, and the FBIs National Incident Based Reporting System (NIBRS) data.