-
Notifications
You must be signed in to change notification settings - Fork 1
/
textbook.draft
403 lines (310 loc) · 9.19 KB
/
textbook.draft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
---
layout: default
title: Course Notes
---
<style>
.textbook-toc>ul {
font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
font-size: 18px;
font-style: normal;
font-variant: small-caps;
font-weight: 100;
line-height: 26.4px;
}
.textbook-toc>h2 {
font-size: 22px;
color: maroon;
}
.textbook-toc>h4 {
font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
font-weight: 100;
font-size: 42px;
color: maroon;
}
.textbook-toc>h1 {
background-color: #666;
color: white;
font-size: 24px;
padding: 10px;
margin-top: 70px;
}
.uk-navbar-nav>li>a {
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
height: 80px;
padding: 0 15px;
font-size: .875rem;
font-family: system-ui;
text-decoration: none;
}
iframe {
display: block;
margin-left: auto;
margin-right: auto;
}
#markdown-toc ul {
font-size:calc(0.85em + 0.25vw);
line-height:1.2;
font-weight: bold;
}
#markdown-toc ul li {
list-style-type: disc !important;
font-size:calc(0.65em + 0.25vw);
line-height:1.2;
margin-left: 20px;
}
#markdown-toc a {
color: black;
font-size:calc(0.65em + 0.25vw);
line-height:1.2;
font-weight: normal;
}
#markdown-toc a:hover {
color: black;
text-decoration: none;
font-weight: bold;
}
body {
counter-reset : h2;
}
h2 {
counter-reset : h3;
}
h3 {
counter-reset : h4;
}
h4 {
counter-reset : h5;
}
h5 {
counter-reset : h6;
}
article h2:before {
content : counter(h2,decimal) ". ";
counter-increment : h2;
}
article h3:before {
content : counter(h2,decimal) "." counter(h3,decimal) ". ";
counter-increment : h3;
}
article h4:before {
content : counter(h2,decimal) "." counter(h3,decimal) "." counter(h4,decimal) ". ";
counter-increment : h4;
}
article h5:before {
content : counter(h2,decimal) "." counter(h3,decimal) "." counter(h4,decimal) "." counter(h5,decimal) ". ";
counter-increment : h5;
}
article h6:before {
content : counter(h2,decimal) "." counter(h3,decimal) "." counter(h4,decimal) "." counter(h5,decimal) "." counter(h6,decimal) ". ";
counter-increment : h6;
}
h2.nocount:before, h3.nocount:before, h4.nocount:before, h5.nocount:before, h6.nocount:before {
content : "";
counter-increment : none;
}
</style>
<div class="textbook-toc">
<br>
#### Data Programming for Social Scientists
# The Data Science Toolkit
We will need three tools to manage your data science projects: a data programming language (R), a project management interfact (R Studio), and a way to create data-driven documents (R Markdown).
## Core R [ [CH-01](http://ds4ps.org/dp4ss-textbook/ch-010-core-r.html) ]
* What is R? [ [video](https://player.vimeo.com/video/180644880) ]
* Packages
- [CRAN Views](https://cran.r-project.org/web/views/)
- [Awesome R](https://awesome-r.com/)
- [R Bloggers](https://www.r-bloggers.com/)
## R Studio [ [CH-02](http://ds4ps.org/dp4ss-textbook/ch-020-rstudio.html) ]
* Installing R and R Studio
* Tour of R Studio
## Data-Driven Docs [ [CH-03](http://ds4ps.org/dp4ss-textbook/ch-030-data-driven-docs.html) ]
* Automation & Flexibility
* [The Importance of Reproducibility](https://www.nature.com/news/1-500-scientists-lift-the-lid-on-reproducibility-1.19970)
* Formats [link](https://rmarkdown.rstudio.com/formats.html)
* Gallery [link](https://rmarkdown.rstudio.com/gallery.html)
## Markdown [ [CH-04](http://ds4ps.org/dp4ss-textbook/ch-031-markdown.html) ]
* R Markdown Formats [overview](https://rmarkdown.rstudio.com/lesson-1.html)
* Headers and Chunks [link](https://ds4ps.org/docs/#how-do-data-driven-docs-work)
* Knitting [link](https://ds4ps.org/docs/#knitting-r-markdown-files)
* [Customization](https://holtzy.github.io/Pimp-my-rmd/)
# Getting Started
## R as a Calculator [ [CH-05](http://ds4ps.org/dp4ss-textbook/ch-033-calculator.html) ]
* Mathematical Operators
* Assignment
* Objects
## Functions [ [CH-06](http://ds4ps.org/dp4ss-textbook/ch-040-functions.html) ]
* Input-Output Devices
* Arguments
* Values
* Returns
## The Learning Curve [ [CH-07](http://ds4ps.org/dp4ss-textbook/ch-032-learning_r.html) ]
* Vocabular and verbs
* Learning to Learn R
## Getting Help [ [CH-08](http://ds4ps.org/dp4ss-textbook/ch-021-help.html) ]
* Help files
* Error messages
* Discussion boards
## Starting to Code
* Scripts
* Comments
* [Style Guides](https://jef.works/R-style-guide/)
* [RMD File Styles and Knitting Tips](https://ds4ps.org/cpp-526-fall-2019/labs/r-markdown-files.html)
# One-Dimensional Datasets
## Intro to Vectors [ [CH-09](http://ds4ps.org/dp4ss-textbook/ch-050-vectors.html) ]
* Observations vs Variables (rows vs columns)
* Vector Types
- Numeric
- Character
- Factors (ordered vs unordered)
- Logical (true/false)
* Checking Vector Types
## Working with Vectors
* Built-In Vectors: e.g. LETTERS
* Generating Vectors
* Missing Values and Non-Numbers
* Empty vectors: NULL
## Altering Vectors
* Defining factors, relevel()
* Recoding Values
* Find and replace
* Variable Transformations
- Vectorized addition
- Defining new vector as function of others: ifelse(), gsub(), [] <-
* Casting
* Implicit Casting (coercion)
## Identifying Groups within Data [ [CH-10](http://ds4ps.org/dp4ss-textbook/p-050-business-logic.html) ]
* Set theory as categories and membership
* Logical Operators
- equal
- not equal
- greater than or less than
- opposite of
* Compound Statements: AND and OR
* Casting logical vectors
* Algebra with logical vectors
* Defining groups
- from categorical variables
- from numeric variables
- missing values as a group
# Two-Dimensional Datasets
## Dataframes
* Creating data frames from vectors
* the $ operator
* Checking and changing class types
* Filter rows and select columns
* Reorder rows or columns
* CSV vs RDS formats
## Matrices and Lists
* Matrix
* Lists
* Building data objects:
- data.frame() vs cbind() and rbind()
* Transformations of Datasets
# Data IO
## Getting Data into R [ [tutorial](https://www.datacamp.com/community/tutorials/r-data-import-tutorial) ]
* Read options
* Copy and paste from Excel
* Using rdata format
* Read from csv or tsv
* Read text files
* Import from Excel
* Import from common format (foreign package)
* Import from the web (RCurl)
* Import from GitHub
* Import from DropBox
* APIs
- Census
- Socrata
- Twitter
## Saving Data [ [tutorial](https://thomasleeper.com/Rcourse/Tutorials/savingdata.html) ]
* Write options
- CSV
- R Data Sets (RDS)
- CSV vs RDS
- Tables
- RData Format
- SPSS or Stata
* Copy to Clipboard
* Copy to Excel
## Navigation
* Navigating R (directories, paths, object lists)
* Built-In Datasets
# Data Wrangling (dplyr)
Data wrangling is the process of preparing data for analysis, which includes reading data into R from a variety of formats, cleaning data, tidying datasets, creating subsets and filters, transforming variables, grouping data, and joining multiple datasets.
The goal of data wrangling is to create a **rodeo dataset** (clean and well-structured) that is ready for the big show (modeling and visualization)!
## Slicing Datasets – Base R and dplyr
* Subset operator
* By index, including order / match
* By logical
* Recycling
* Subset by row -- dplyr::filter()
* Indices
* Selector Vectors
* Subset by column --- dplyr::select()
## Combining Datasets
* merge and match
* join in dplyr
* inner, outer, right, left
# Explore and Describe
## Summarizing Vectors
* Counting things: sum( logical statement )
* Categorical data: tables
* Missing values
* prop.table() and margin.table()
* Numeric data: min, max, mean, summary / quantile
* Missing values
* All at once: summary + data.frame / matrix
* Creating tables of descriptives: factors vs numeric
## Summarizing Groups of Vectors
* Table ( f1, f2 ), ftable( row.vars=c(“f1”,”f2”), col.vars=”f3” )
* Function over groups: tapply( v1, f1 ) or dplyr:: group_by() + summarise()
* Functions over levels of numeric data: tapply( v1, cut(v2) )
* tapply( v1, INDEX=list(f1,f2) or dplyr:: group_by() + summarise()
* aggregate( dat, FUN, by=f1 )
* https://cran.r-project.org/web/packages/DescTools/vignettes/DescToolsCompanion.pdf
# Visualize
## Principles of Visual Communication
* Ground, figure, narrative (context, subject, action)
* Tufte’s rules
* Visual tragedies
## Core Graphics Engine
* Defining a canvas: xlim, ylim
* Adding data
* Type (point, line, both)
* Symbols
* Color
* Size
* Adding grids
* Adding axes
* Adding titles / axes labels
* Adding data labels: text()
* Margins
## Advanced Graphics
* Colors and color functions
* Custom fonts / math symbols
* Multiple Plots (core graphics)
- Incorrect: https://en.wikipedia.org/wiki/File:Smallmult.png#/media/File:Smallmult.png
* Custom graph layouts
## ggplot2
* Grammar of graphics concept
* ggplot overview
# Make Dynamic
## R shiny [ [tutorial](http://rmarkdown.rstudio.com/authoring_shiny.html) ]
* What makes documents dynamic?
* Widgets
- input objects
* Render functions
* reactive
## flexdashboards [ [overview](http://rmarkdown.rstudio.com/flexdashboard/) ]
* Principles of good dashboard design
* Layouts
* Sidebars
* Value boxes
* CSS basics
<br>
<br>
<br>
</div>