├── .Rbuildignore
├── .gitignore
├── .remarkrc
├── DESCRIPTION
├── LICENSE
├── Makefile
├── NAMESPACE
├── README.md
├── Untitled.Rmd
├── WORDLIST
├── _bookdown.yml
├── _common.R
├── _lint.R
├── _notes
├── _main.Rmd
├── biblio.md
├── pauperism.Rmd
├── questions.Rmd
├── realstats.Rmd
└── wine.Rmd
├── _output.yml
├── _render.R
├── _serve.R
├── _spelling.R
├── appendix.Rmd
├── bibliography.Rmd
├── bootstrapping.Rmd
├── causal-regression.Rmd
├── cross-validation.Rmd
├── data
└── western1995
│ ├── econ_growth.tsv
│ ├── income_ineq.tsv
│ └── unionization.tsv
├── diagrams
├── _book
│ ├── _main_files
│ │ └── figure-html
│ │ │ ├── unnamed-chunk-11-1.png
│ │ │ ├── unnamed-chunk-12-1.png
│ │ │ └── unnamed-chunk-3-1.png
│ ├── cross-validation.html
│ ├── libs
│ │ ├── gitbook-2.6.7
│ │ │ ├── css
│ │ │ │ ├── fontawesome
│ │ │ │ │ └── fontawesome-webfont.ttf
│ │ │ │ ├── plugin-bookdown.css
│ │ │ │ ├── plugin-fontsettings.css
│ │ │ │ ├── plugin-highlight.css
│ │ │ │ ├── plugin-search.css
│ │ │ │ └── style.css
│ │ │ └── js
│ │ │ │ ├── app.min.js
│ │ │ │ ├── jquery.highlight.js
│ │ │ │ ├── lunr.js
│ │ │ │ ├── plugin-bookdown.js
│ │ │ │ ├── plugin-fontsettings.js
│ │ │ │ ├── plugin-search.js
│ │ │ │ └── plugin-sharing.js
│ │ └── jquery-2.2.3
│ │ │ └── jquery.min.js
│ └── search_index.json
├── iv-dag.gv
├── science.mmd
└── science2.mmd
├── docs
├── .nojekyll
├── appendix.md
├── bootstrapping.html
├── bootstrapping.md
├── causal-regression.md
├── colinearity-and-multicolinearity.html
├── collinearity-and-multicollinearity.html
├── cross-validation.html
├── cross-validation.md
├── cross-validation_files
│ └── figure-html
│ │ ├── unnamed-chunk-12-1.svg
│ │ ├── unnamed-chunk-13-1.svg
│ │ └── unnamed-chunk-4-1.svg
├── eda.md
├── formatting-tables.html
├── img
│ └── islr-fig-6.7.png
├── index.html
├── index.md
├── libs
│ ├── gitbook-2.6.7
│ │ ├── css
│ │ │ ├── fontawesome
│ │ │ │ └── fontawesome-webfont.ttf
│ │ │ ├── plugin-bookdown.css
│ │ │ ├── plugin-fontsettings.css
│ │ │ ├── plugin-highlight.css
│ │ │ ├── plugin-search.css
│ │ │ └── style.css
│ │ └── js
│ │ │ ├── app.min.js
│ │ │ ├── jquery.highlight.js
│ │ │ ├── lunr.js
│ │ │ ├── plugin-bookdown.js
│ │ │ ├── plugin-fontsettings.js
│ │ │ ├── plugin-search.js
│ │ │ └── plugin-sharing.js
│ └── jquery-2.2.3
│ │ └── jquery.min.js
├── linear-regression.md
├── matrix-algebra-review.html
├── matrix.md
├── multicolinearity.md
├── multicollinearity.html
├── multicollinearity.md
├── ols-assumptions.html
├── ols-in-matrix-form.html
├── other-did-approaches.html
├── panel-data-fixed-effects-and-difference-in-difference.html
├── panel.md
├── prediction-policy-problems.html
├── prediction.html
├── prediction.md
├── prediction_files
│ └── figure-html
│ │ ├── unnamed-chunk-10-1.svg
│ │ ├── unnamed-chunk-11-1.svg
│ │ ├── unnamed-chunk-13-1.svg
│ │ ├── unnamed-chunk-16-1.svg
│ │ ├── unnamed-chunk-18-1.svg
│ │ ├── unnamed-chunk-20-1.svg
│ │ ├── unnamed-chunk-21-1.svg
│ │ └── unnamed-chunk-9-1.svg
├── presentation.md
├── programming.md
├── purpose.html
├── rd.md
├── rd_files
│ └── figure-html
│ │ └── unnamed-chunk-2-1.svg
├── references-1.html
├── references-3.html
├── references-4.html
├── references-5.html
├── references.html
├── references.md
├── reganat.md
├── reganat_files
│ └── figure-html
│ │ ├── unnamed-chunk-3-1.svg
│ │ └── unnamed-chunk-7-1.svg
├── regression-anatomy.html
├── regression-discontinuity.html
├── regression.html
├── regularization.html
├── regularization.md
├── regularization_files
│ └── figure-html
│ │ └── unnamed-chunk-5-1.svg
├── reproducible-research.html
├── reproducible-research.md
├── reproducible_research.md
├── search_index.json
├── section.html
├── tables-and-plots.md
├── tables_and_plots.md
├── typesetting-and-word-processing-programs.html
├── word-processing.md
├── writing-resources.html
└── writing.md
├── eda.Rmd
├── img
├── 1000px-Coefficient_of_Determination.svg.png
├── islr-fig-6.7.png
├── laffer.png
└── tobias-funke-blue.jpeg
├── includes
├── after_body.html
├── before_body.html
├── in_header.html
└── preamble.tex
├── index.Rmd
├── intro-methods-notes.Rproj
├── intromethods.bib
├── iv.Rmd
├── linear-regression.Rmd
├── matrix.Rmd
├── model-fit.Rmd
├── multicollinearity.Rmd
├── old-files
├── _main.Rmd
├── multicollinearity.Rmd
├── non-standard-errors.Rmd
├── ols-diagnostics-troubleshooting.Rmd
├── ols-estimator.Rmd
├── ols-inference.Rmd
├── ols-misc.Rmd
├── ovb-measurment-error.Rmd
└── resampling-methods.Rmd
├── outliers.Rmd
├── ovb.Rmd
├── package-lock.json
├── panel.Rmd
├── potential-outcomes.Rmd
├── prediction.Rmd
├── presentation.Rmd
├── probability.Rmd
├── programming.Rmd
├── questions.Rmd
├── rd.Rmd
├── references.Rmd
├── reganat.Rmd
├── regression-inference.Rmd
├── regularization.Rmd
├── reproducible-research.Rmd
├── simple-regression.Rmd
├── simpsons.Rmd
├── tables-and-plots.Rmd
├── word-processing.Rmd
└── writing.Rmd
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^.*\.Rproj$
2 | ^\.Rproj\.user$
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .*.Rnb.cached
5 | *.rds
6 | *.aux
7 | *.fdb_latexmk
8 | *.fls
9 | *.out
10 | *.toc
11 | *.bak
12 | $*$
13 | *.sav
14 | _bookdown_files
15 | *.utf8.md
16 | *.knit.md
17 |
18 | /*.html
19 | /*_cache
20 | /*_files
21 | node_modules
22 | *.log
23 | ^/bookdown*
24 | /bookdown*
25 |
--------------------------------------------------------------------------------
/.remarkrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "remark-preset-lint-recommended",
4 | "remark-preset-lint-consistent",
5 | "remark-preset-lint-markdown-style-guide",
6 | "remark-frontmatter",
7 | ["remark-lint-file-extension", false],
8 | ["remark-lint-maximum-line-length", 300],
9 | ["remark-lint-no-shortcut-reference-link", false],
10 | ["remark-lint-list-item-indent", "tab-size"],
11 | ["remark-lint-no-undefined-references", false],
12 | ["remark-lint-emphasis-marker", false],
13 | ["remark-lint-fenced-code-flag", false],
14 | ["remark-lint-no-duplicate-headings", false]
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: pols503notes
2 | Title: POLS 503 Notes
3 | Version: 0.0.1
4 | Authors@R: c(
5 | person("Jeffrey", "Arnold", , "jeffrey.arnold@gmail.com", c("aut", "cre"))
6 | )
7 | Depends: R (>= 3.1.0)
8 | URL: https://github.com/jrnold/intro-methods-notes
9 | Imports:
10 | bookdown,
11 | broom,
12 | carData,
13 | datums,
14 | htmltools,
15 | htmlTable,
16 | jrnoldmisc,
17 | MASS,
18 | texreg,
19 | tidyverse,
20 | vcd,
21 | xtable
22 | Remotes:
23 | jrnold/jrnoldmisc,
24 | jrnold/datums
25 | RoxygenNote: 6.0.1
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | CC0 1.0 Universal
2 |
3 | Statement of Purpose
4 |
5 | The laws of most jurisdictions throughout the world automatically confer
6 | exclusive Copyright and Related Rights (defined below) upon the creator and
7 | subsequent owner(s) (each and all, an "owner") of an original work of
8 | authorship and/or a database (each, a "Work").
9 |
10 | Certain owners wish to permanently relinquish those rights to a Work for the
11 | purpose of contributing to a commons of creative, cultural and scientific
12 | works ("Commons") that the public can reliably and without fear of later
13 | claims of infringement build upon, modify, incorporate in other works, reuse
14 | and redistribute as freely as possible in any form whatsoever and for any
15 | purposes, including without limitation commercial purposes. These owners may
16 | contribute to the Commons to promote the ideal of a free culture and the
17 | further production of creative, cultural and scientific works, or to gain
18 | reputation or greater distribution for their Work in part through the use and
19 | efforts of others.
20 |
21 | For these and/or other purposes and motivations, and without any expectation
22 | of additional consideration or compensation, the person associating CC0 with a
23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25 | and publicly distribute the Work under its terms, with knowledge of his or her
26 | Copyright and Related Rights in the Work and the meaning and intended legal
27 | effect of CC0 on those rights.
28 |
29 | 1. Copyright and Related Rights. A Work made available under CC0 may be
30 | protected by copyright and related or neighboring rights ("Copyright and
31 | Related Rights"). Copyright and Related Rights include, but are not limited
32 | to, the following:
33 |
34 | i. the right to reproduce, adapt, distribute, perform, display, communicate,
35 | and translate a Work;
36 |
37 | ii. moral rights retained by the original author(s) and/or performer(s);
38 |
39 | iii. publicity and privacy rights pertaining to a person's image or likeness
40 | depicted in a Work;
41 |
42 | iv. rights protecting against unfair competition in regards to a Work,
43 | subject to the limitations in paragraph 4(a), below;
44 |
45 | v. rights protecting the extraction, dissemination, use and reuse of data in
46 | a Work;
47 |
48 | vi. database rights (such as those arising under Directive 96/9/EC of the
49 | European Parliament and of the Council of 11 March 1996 on the legal
50 | protection of databases, and under any national implementation thereof,
51 | including any amended or successor version of such directive); and
52 |
53 | vii. other similar, equivalent or corresponding rights throughout the world
54 | based on applicable law or treaty, and any national implementations thereof.
55 |
56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59 | and Related Rights and associated claims and causes of action, whether now
60 | known or unknown (including existing as well as future claims and causes of
61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum
62 | duration provided by applicable law or treaty (including future time
63 | extensions), (iii) in any current or future medium and for any number of
64 | copies, and (iv) for any purpose whatsoever, including without limitation
65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66 | the Waiver for the benefit of each member of the public at large and to the
67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver
68 | shall not be subject to revocation, rescission, cancellation, termination, or
69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work
70 | by the public as contemplated by Affirmer's express Statement of Purpose.
71 |
72 | 3. Public License Fallback. Should any part of the Waiver for any reason be
73 | judged legally invalid or ineffective under applicable law, then the Waiver
74 | shall be preserved to the maximum extent permitted taking into account
75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76 | is so judged Affirmer hereby grants to each affected person a royalty-free,
77 | non transferable, non sublicensable, non exclusive, irrevocable and
78 | unconditional license to exercise Affirmer's Copyright and Related Rights in
79 | the Work (i) in all territories worldwide, (ii) for the maximum duration
80 | provided by applicable law or treaty (including future time extensions), (iii)
81 | in any current or future medium and for any number of copies, and (iv) for any
82 | purpose whatsoever, including without limitation commercial, advertising or
83 | promotional purposes (the "License"). The License shall be deemed effective as
84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the
85 | License for any reason be judged legally invalid or ineffective under
86 | applicable law, such partial invalidity or ineffectiveness shall not
87 | invalidate the remainder of the License, and in such case Affirmer hereby
88 | affirms that he or she will not (i) exercise any of his or her remaining
89 | Copyright and Related Rights in the Work or (ii) assert any associated claims
90 | and causes of action with respect to the Work, in either case contrary to
91 | Affirmer's express Statement of Purpose.
92 |
93 | 4. Limitations and Disclaimers.
94 |
95 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
96 | surrendered, licensed or otherwise affected by this document.
97 |
98 | b. Affirmer offers the Work as-is and makes no representations or warranties
99 | of any kind concerning the Work, express, implied, statutory or otherwise,
100 | including without limitation warranties of title, merchantability, fitness
101 | for a particular purpose, non infringement, or the absence of latent or
102 | other defects, accuracy, or the present or absence of errors, whether or not
103 | discoverable, all to the greatest extent permissible under applicable law.
104 |
105 | c. Affirmer disclaims responsibility for clearing rights of other persons
106 | that may apply to the Work or any use thereof, including without limitation
107 | any person's Copyright and Related Rights in the Work. Further, Affirmer
108 | disclaims responsibility for obtaining any necessary consents, permissions
109 | or other rights required for any use of the Work.
110 |
111 | d. Affirmer understands and acknowledges that Creative Commons is not a
112 | party to this document and has no duty or obligation with respect to this
113 | CC0 or use of the Work.
114 |
115 | For more information, please see
116 |
117 |
118 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | Rscript --quiet _render.R
3 |
4 | gitbook:
5 | Rscript --quiet _render.R "bookdown::gitbook"
6 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jrnold/intro-methods-notes/4c1342aa322c728ad21bbfaa2eeade554cb79b6c/README.md
--------------------------------------------------------------------------------
/WORDLIST:
--------------------------------------------------------------------------------
1 | AJPS
2 | AME
3 | APSA
4 | ATT
5 | Abadie
6 | AbdulkadirogluAngristPathak
7 | Altonji
8 | AltonjiElderTaber
9 | Angrist
10 | AngristPischke
11 | Arrellano
12 | Ashenfelter
13 | Ashenfelter's
14 | AshenfelterAshemoreLalonde
15 | Ashmore
16 | AtheyImbens
17 | AucTeX
18 | Belloni
19 | BertrandDufloMullainathan
20 | Bizup
21 | Bonferroni
22 | Broockman
23 | BroockmanKallaAronow
24 | CEF
25 | CLT
26 | CPE
27 | CalTech
28 | CarpenterDobkin
29 | CaugheySekhon
30 | Chernozhukov
31 | DAGs
32 | DGP
33 | DOI
34 | Dafoe
35 | DavidsonMacKinnon
36 | DiD
37 | Duflo
38 | EPE
39 | EggersFowlerHainmuellerEtAl
40 | EggersHainmueller
41 | EsareyMenger
42 | Eubank
43 | Evera
44 | FWL
45 | Frisch
46 | Gardeazabel
47 | Gelman
48 | GelmanHill
49 | GelmanKatz
50 | Gentzkow
51 | Glymour
52 | Grilliches
53 | GrimmerHershFeinsteinEtAl
54 | Guber
55 | HahnToddKlaauw
56 | Hausmann
57 | Herndon
58 | HerndonAshPollin
59 | Hesterberg
60 | Hochberg
61 | Holm
62 | Homas
63 | IPE
64 | ISLR
65 | ImbensKalyanaraman
66 | JacobLefgren
67 | JamesWittenHastieEtAl
68 | Jeter
69 | Katz
70 | Keele
71 | KingTomzWittenberg
72 | Kleinberg
73 | KleinbergLudwigMullainathanEtAl
74 | Krugman
75 | LDV
76 | LDVs
77 | LSDV
78 | LaCour
79 | LaTeXTools
80 | Lalonde
81 | LeeLemieux
82 | LeeMorettiButler
83 | LindenAdamsRoberts
84 | LitschigMorrison
85 | Lovell
86 | MPs
87 | MSS
88 | MacKinnon
89 | Makefiles
90 | Mankiw
91 | Mattenberg
92 | McCloskey
93 | McCrary
94 | Mendeley
95 | Methodologist
96 | Mullainathan
97 | NBER
98 | NHST
99 | Nunn
100 | NunnWantchekon
101 | OVB
102 | Oster
103 | PCSE
104 | PSAS
105 | Passell
106 | PeiPischkeSchwandt
107 | Pischke
108 | Pollin
109 | RDD
110 | RStudio
111 | Reinhart
112 | ReporteR
113 | Rmd
114 | Rnw
115 | Rogoff
116 | Ruud
117 | SEs
118 | SSR
119 | ShareLaTeX
120 | Shmueli
121 | StackExchange
122 | Strunk
123 | TSCS
124 | TSS
125 | Taber
126 | TeXStudio
127 | TeXmaker
128 | TeXshop
129 | ThistlethwaiteCampbell
130 | ThistlethwaiteCampbell1960a
131 | VIF
132 | Varian
133 | Vec
134 | WYS
135 | Wantchekon
136 | Weingast
137 | Wikibook
138 | X'X
139 | X'y
140 | Zan
141 | Zapnik
142 | Zheng
143 | Zotero
144 | Zvi
145 | acec
146 | advstats
147 | al
148 | andrewgelman
149 | apalike
150 | apsrtable
151 | arg
152 | arxiv
153 | asymptotics
154 | avesbiodiv
155 | bc
156 | beamer
157 | biblio
158 | binom
159 | bmatrix
160 | bmj
161 | bookdown
162 | cdots
163 | clubSandwich
164 | clusterSE
165 | colinear
166 | collinear
167 | colorlinks
168 | colwiz
169 | confounders
170 | counterfactuals
171 | cov
172 | csic
173 | dX
174 | ddots
175 | df
176 | discretizing
177 | documentclass
178 | docx
179 | doi
180 | downarrow
181 | econometrics
182 | emptyset
183 | estadistica
184 | et
185 | fhat
186 | frac
187 | geq
188 | github
189 | heteroskedastic
190 | heteroskedasticity
191 | homoskedastic
192 | homoskedasticity
193 | htmlTables
194 | http
195 | https
196 | iK
197 | ignorability
198 | igt
199 | ij
200 | ik
201 | infty
202 | intromethods
203 | invertible
204 | itg
205 | jrnold
206 | jrnoldmisc
207 | ki
208 | knitr
209 | lah
210 | leftrightarrow
211 | leq
212 | lim
213 | linearities
214 | literatures
215 | lme
216 | lof
217 | mathbb
218 | mathcal
219 | mathrm
220 | mathsf
221 | mathtt
222 | mattblackwell
223 | mncn
224 | monofont
225 | monofontoptions
226 | multicollinearity
227 | neq
228 | nk
229 | nonsingular
230 | observables
231 | overfit
232 | parametric
233 | perp
234 | plm
235 | policymaker's
236 | politicalsciencereplication
237 | positivity
238 | pre
239 | probabilistically
240 | programmatically
241 | regularization
242 | repo
243 | residualized
244 | roids
245 | rsample
246 | rsquared
247 | se
248 | skedastic
249 | statmethods
250 | tech
251 | teck
252 | texreg
253 | tg
254 | tidyverse
255 | tl
256 | tomhopper
257 | unbiasedness
258 | unconfoundedness
259 | underbrace
260 | underfit
261 | underspecified
262 | unmodeled
263 | untestable
264 | uparrow
265 | varepsilon
266 | vcov
267 | vdots
268 | vec
269 | wc
270 | widehat
271 | wordpress
272 | www
273 | xtable
274 |
--------------------------------------------------------------------------------
/_bookdown.yml:
--------------------------------------------------------------------------------
1 | book_filename: "intro-method-notes"
2 | chapter_name: "Chapter "
3 | delete_merged_file: true
4 | new_session: yes
5 | output_dir: docs
6 | before_chapter_script: "_common.R"
7 | edit:
8 | link: https://github.com/jrnold/intro-methods-notes/edit/gh-pages/%s
9 | text: "Edit"
10 | rmd_subdir: false
11 | rmd_files:
12 | - index.Rmd
13 |
14 | - eda.Rmd
15 |
16 | - programming.Rmd
17 |
18 | - linear-regression.Rmd
19 | - reganat.Rmd
20 | - matrix.Rmd
21 | - multicollinearity.Rmd
22 | - bootstrapping.Rmd
23 |
24 | - prediction.Rmd
25 | - cross-validation.Rmd
26 | - regularization.Rmd
27 |
28 | - causal-regression.Rmd
29 | - panel.Rmd
30 | - rd.Rmd
31 |
32 | - presentation.Rmd
33 | - tables-and-plots.Rmd
34 | - reproducible-research.Rmd
35 | - word-processing.Rmd
36 | - writing.Rmd
37 |
38 | - appendix.Rmd
39 | - references.Rmd
40 |
--------------------------------------------------------------------------------
/_common.R:
--------------------------------------------------------------------------------
1 | suppressPackageStartupMessages(
2 | library("tidyverse")
3 | )
4 |
5 | rpkg_url <- function(pkg) {
6 | paste0("https://cran.r-project.org/package=", pkg)
7 | }
8 |
9 | rpkg <- function(pkg) {
10 | paste0("**[", pkg, "](", rpkg_url(pkg), ")**")
11 | }
12 |
13 | rdoc_url <- function(pkg, fun) {
14 | paste0("https://www.rdocumentation.org/packages/", pkg, "/topics/", fun) # nolint
15 | }
16 |
17 | rdoc <- function(pkg, fun, full_name = FALSE) {
18 | text <- if (full_name) paste0(pkg, "::", fun) else pkg
19 | paste0("[", text, "](", rdoc_url(pkg, fun), ")")
20 | }
21 |
22 | knitr::opts_chunk$set(cache = TRUE, autodep = TRUE)
23 | set.seed(634808943)
24 |
--------------------------------------------------------------------------------
/_lint.R:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env Rscript
2 | suppressPackageStartupMessages({
3 | library("rex")
4 | library("lintr")
5 | })
6 |
7 | lint_dir <- function(path = ".", relative_path = TRUE,
8 | pattern = "\\.([Rr]|Rmd|Rhtml)$", recursive = TRUE, ...) {
9 | lintr:::read_settings(path)
10 | on.exit(lintr:::clear_settings, add = TRUE)
11 | settings <- lintr:::settings
12 | names(settings$exclusions) <-
13 | normalizePath(file.path(path, names(settings$exclusions)))
14 | files <- dir(path = path, pattern = pattern, recursive = TRUE,
15 | full.names = TRUE)
16 | files <- normalizePath(files)
17 | lints <- lintr:::flatten_lints(lapply(files, function(file) {
18 | if (interactive()) {
19 | message(".", appendLF = FALSE)
20 | }
21 | try(lint(file, ..., parse_settings = FALSE))
22 | }))
23 | if (interactive()) {
24 | message()
25 | }
26 | lints <- lintr:::reorder_lints(lints)
27 | if (relative_path == TRUE) {
28 | lints[] <- lapply(lints, function(x) {
29 | x$filename <- re_substitutes(x$filename, rex(normalizePath(path),
30 | one_of("/", "\\")), "")
31 | x
32 | })
33 | attr(lints, "path") <- path
34 | }
35 | class(lints) <- "lints"
36 | lints
37 | }
38 |
39 | lint_dir(here::here())
40 |
--------------------------------------------------------------------------------
/_notes/pauperism.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Yule Replication"
3 | output: html_document
4 | ---
5 |
6 | ```{r include=FALSE}
7 | library("dplyr")
8 | library("readr")
9 | library("tidyr")
10 | library("haven")
11 | library("plm")
12 | library("magrittr")
13 | library("purrr")
14 | library("ggplot2")
15 | library("broom")
16 | ```
17 |
18 | ```{r}
19 | ratiodiff <- function(x) {
20 | z <- x / lag(x)
21 | z[is.infinite(z)] <- NA_real_
22 | z
23 | }
24 | ```
25 |
26 | ```{r}
27 | pauperism <-
28 | left_join(yule, yule_plu, by = "plu")
29 | ```
30 |
31 | Table 2: Metropolitan Group, 1871-1881
32 | ```{r results = 'asis'}
33 | filter(yule_long, Type == "Metropolitan") %>%
34 | filter(year == 1881) %>%
35 | select(ID, Union, pauper_diff, outratio, Prop65_diff,
36 | Popn_diff) %>%
37 | arrange(ID) %>%
38 | select(-ID) %>%
39 | knitr::kable()
40 | ```
41 |
42 | $$
43 | \begin{aligned}[t]
44 | \Delta\mathtt{Paup} &= \beta_0 \\
45 | &+ \beta_1 \Delta\mathtt{Out} \\
46 | &+ \beta_2 \Delta\mathtt{Old} \\
47 | &+ \beta_3 \Delta\mathtt{Pop} + \varepsilon
48 | \end{aligned}
49 | $$
50 |
51 | # Summary Statistics
52 |
53 | ```{r}
54 | filter(yule_long, year > 1871) %>%
55 | group_by(year, Type) %>%
56 | select(pauper_diff, outratiodiff, Prop65_diff, Popn_diff) %>%
57 | gather(variable, value, -Type, -year) %>%
58 | group_by(variable, year, Type) %>%
59 | summarize(mean = mean(value, na.rm = TRUE),
60 | sd = sd(value, na.rm = TRUE)) %>%
61 | knitr::kable()
62 |
63 | ```
64 |
65 |
66 | # Regression
67 |
68 | ```{r}
69 | lm(pauper ~ outratio, data = yule_long)
70 | lm(pauper ~ year + Type + outratio, data = yule_long)
71 | lm(pauper ~ year + Type + outratio + Prop65 + Popn65, data = yule_long)
72 | lm(pauper ~ Type * (year + outratio + Prop65 + Popn65), data = yule_long)
73 | ```
74 |
75 |
76 | ```{r}
77 | yule_diff <- yule_long %>%
78 | filter(year > 1871) %>%
79 | mutate(year = as.factor(year)) %>%
80 | select(ID, Union, Type, year, pauper_diff, outratiodiff, Popn_diff,
81 | Prop65_diff)
82 |
83 | lm(pauper_diff ~ outratiodiff, data = yule_diff)
84 | lm(pauper_diff ~ Type * year + outratiodiff, data = yule_diff)
85 | lm(pauper_diff ~ Type * year + outratiodiff + Popn_diff + Prop65_diff, data = yule_diff)
86 | lm(pauper_diff ~ (Type * year) * (outratiodiff + Prop65_diff + Popn_diff),
87 | data = yule_diff)
88 |
89 |
90 |
91 | ```
92 |
93 | Individual regression for each Type and Region
94 | ```{r}
95 | diff_mod_3 <-
96 | yule_long %>%
97 | filter(year %in% c(1881, 1891)) %>%
98 | group_by(year, Type) %>%
99 | do(tidy(lm(pauper_diff ~ outratiodiff + Popn_diff + Prop65_diff, data = .)))
100 |
101 | diff_mod_3 %>%
102 | select(year, Type, term, estimate) %>%
103 | spread(term, estimate) %>%
104 | knitr::kable()
105 | ```
106 |
107 | ## Summary Statistics
108 |
109 | ### Outratio
110 |
111 | ```{r}
112 | ggplot(select(filter(yule_long, !is.na(outratio)),
113 | outratio, ID, year, Type),
114 | aes(x = outratio, y = ..density..)) +
115 | geom_histogram(binwidth = 2) +
116 | facet_grid(year ~ Type)
117 | ```
118 |
119 | ```{r}
120 | ggplot(select(filter(yule_long, !is.na(outratiodiff)),
121 | outratiodiff, ID, year, Type),
122 | aes(x = outratiodiff, y = ..density..)) +
123 | geom_histogram(binwidth = 20) +
124 | facet_grid(year ~ Type)
125 | ```
126 |
127 | ## Pauperism
128 |
129 | ```{r}
130 | ggplot(select(filter(yule_long, !is.na(pauper)),
131 | pauper, ID, year, Type),
132 | aes(x = pauper, y = ..density..)) +
133 | geom_histogram(binwidth = .01) +
134 | facet_grid(year ~ Type)
135 | ```
136 |
137 | There appear to be some big outliers in the ratio difference
138 | in pauperism,
139 | ```{r}
140 | ggplot(select(filter(yule_long, !is.na(pauper_diff)),
141 | pauper_diff, ID, year, Type),
142 | aes(x = pauper_diff, y = ..density..)) +
143 | geom_histogram(binwidth = 15) +
144 | facet_grid(year ~ Type)
145 | ```
146 |
--------------------------------------------------------------------------------
/_notes/questions.Rmd:
--------------------------------------------------------------------------------
1 | # Questions
2 |
3 | ```{r setup,include=FALSE}
4 | library("DiagrammR")
5 | ```
6 |
7 | # Tukey (1980)
8 |
9 | > Tukey, John W. 1980. "We Need Both Exploratory and Confirmatory" *The American Statistician.* https://dx.doi.org/10.2307/268299
10 |
11 | John Tukey discussed exploratory and confirmatory analysis and the need for both:
12 |
13 | The stylized view of science is the "straight-line paradigm"
14 | ```{r}
15 | mermaid("diagrams/science.mmd")
16 | ```
17 |
18 | But where does the question or idea come from? Tukey notes four issues with this straight-line paradigm:
19 |
20 | - Questions come from theory and insights derived from previous explorations of similar data
21 | - Designs come are also driven by insights from previous studies of similar data
22 | - Data collection is monitored by exploring the data and looking for unexpected patterns
23 | - The analysis proceeds often by exploring the data to avoid bad or pursue good avenues of discovery?
24 |
25 | All science has peeked at the data before answering the question.
26 | In fact, if science as a whole persued the straight-line paradigm only the first question ever posed could be analyzed without some corruption from knowing something about domain of study.
27 |
28 | Instead, a more realistic formulation of the scientific process is
29 | ```{r}
30 | mermaid("diagrams/scienc2.mmd")
31 | ```
32 |
33 | > The formulation of the question itself involves what can in fact be asked, what designs are feasible, as well as how likely a given design is to give a useful answer.
34 | > Both inchoate insight and extensive exploration (of past data) can---and should---play a role in this process of formulating and question.
35 | >
36 | > Science ... DOES NOT BEGIN WITH A TIDY QUESTION. Nor does it end with a tidy answer.
37 | >
38 | > The picture of a scientist struck---as by lightning---with a question is very far from the truth.
39 |
40 | But if you do do confirmatory analysis:
41 |
42 | 1. randomize
43 | 2. pre-plan
44 |
45 | After choosing a question, limit your analysis to one main question---specified by the entire design, collection, monitoring, and analysis.
46 |
47 | # Peng and Leek
48 |
49 | The epicycles of analysis (CH 2).
50 | There are 5 core activities of data analysis:
51 |
52 | 1. Stating the question
53 | 2. Exploratory data analysis
54 | 3. Model building
55 | 4. Interpreting
56 | 5. Communicating
57 |
58 | Each of those activities consists of three epicycles:
59 |
60 | 1. setting expectations
61 | 2. collecting data, comparing data to expectations
62 | 3. if the data don't match expectations, then revise data or expectations and repeat
63 |
64 | Types of questions. There are six types of questions (p. 18--19)
65 | Leek and Peng. What is the question? 2015. *Science* http://science.sciencemag.org/content/347/6228/1314
66 |
67 | 1. Descriptive: Summarizes a characteristic of data.
68 | 2. Exploratory: Find patterns in data. Hypothesis generating analysis.
69 | 3. Inferential: Given a hypothesis, extrapolate from the sample to the population or different sample.
70 | 4. Predictive: Predict new data. In this you don't necessarily care about the predictors, only that the model predicts well.
71 | 5. Causal: Does X cause Y? How does changing one factor change another (on average) in the population?
72 | 6. Mechanistic: How does X cause Y?
73 |
74 | What is a good question (p. 21)?
75 |
76 | 1. interest to the audience
77 | 2. it is not already answered
78 | 3. it stems from a plausible framework
79 | 4. it should be answerable
80 | 5. it is also useful to be specific - because that helps answerability.
81 |
82 | # Exploratory Data Analysis
83 |
84 | Goals of EDA (Art of Data Science, Ch 4.):
85 |
86 | 1. Find problems in the data
87 | 2. Detemine whether the question can be answered with the data at hand (proof of concept)
88 | 3. Develop a "sketch of the answer"
89 |
90 | Their EDA checklist
91 |
92 | 1. Formulate your question
93 | 2. Read in your data
94 | 3. Check the packaging: How many observations and variables? What are the observations and variables in the data?
95 | 4. Look at the top and the bottom of your data: Look at the beginning and end of the data---is it in order, is it properly formatted, in a time series does it have the right times?
96 | 5. Check your "n"s: Always check the number of observations. This is quick way to check that there aren't mistakes in the sample, especially when merging.
97 | 6. Validate with at least one external data source: This doesn't need to be formal. But compare values of variables to other known values to ensure they are in the right ballpark. This catches unit-of-measurement issues, variables not measuring what you thought they were measuring, data entry errors.
98 | 7. Make a plot. Comparing the data to what you expect it to look like is a good way to catch both data errors and also to find new patterns.
99 | 8. Try the easy solution first. This is a proof of concept that your answer will work.
100 | 9. Follow up. Challenge the solution. Why might it be wrong.
101 |
102 | - do you have the right data?
103 | - do you need more data?
104 | - do you have the right question?
105 |
--------------------------------------------------------------------------------
/_notes/realstats.Rmd:
--------------------------------------------------------------------------------
1 | 3.1 Bivariate Regression Model
2 |
3 | - estimation
4 |
5 | 3.2 Random variation in Coefficient estimates
6 |
7 | - distribution of $\hat{\beta}$ estimates
8 | - $\hat{\beta}$ are normally distributed
9 |
10 | 3.3 Exogeneity and Ubiasedness
11 |
12 | - conditions for unbiased estimator
13 | - characterizing biaas
14 |
15 | 3.4 Precision of Estimate
16 | 3.5 Probability limits and consistency
17 |
18 | - probability limit
19 | - consistency
20 |
21 | 3.6 Homoskedasticity
22 |
23 | - heteroskedasticity
24 | - correlated errors - autocorrelation
25 |
--------------------------------------------------------------------------------
/_output.yml:
--------------------------------------------------------------------------------
1 | bookdown::gitbook:
2 | # css: style.css
3 | # math: true
4 | dev: svglite
5 | config:
6 | toc:
7 | collapse: none
8 | before: |
9 |