-
Notifications
You must be signed in to change notification settings - Fork 1
/
template_document.Rmd
140 lines (88 loc) · 6.32 KB
/
template_document.Rmd
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
---
title: "Writing a Paper in Rmarkdown"
author:
- name: "Jack Blumenau"
affiliation: "University College London"
date: "02/05/2020"
output:
pdf_document:
citation_package: natbib
latex_engine: pdflatex
template: header.tex
keep_tex: true
abstract: "Everyone agrees that the issue in this paper is really important. But we do not know much about this specific question, although it matters a great deal, for these reasons. We approach the problem from this perspective. Our research design focuses on these cases and relies on these data, which we analyse using this method. Results show what we have learned about the questions. They have these broader implications."
bibliography: bibliography.bib
fontsize: 11pt
---
```{r setup, echo=FALSE, message=FALSE}
# Set global options for chunks
knitr::opts_chunk$set(echo = FALSE) # By default, do not show R code
# Load libraries required for analysis
library(stargazer) # v5.2.2
```
# Introduction
The important thing about academic papers is that you state your argument *very clearly* at the beginning of the introduction. Even if you think your argument is clear, there are certainly ways that you can make it **even clearer**. Often, the way to maximise clarity is to treat your audience as if they are really stupid, and to present your arguments in a list:
* You should be clear
* No, clearer than that
* Are you listening to me? Clarity is everything.
Or, even, as an *ordered* list:
1. One thing
2. Another thing
3. A third thing
If you are writing a paper, another important thing to clarify in your introduction is how you contribute to some important and extensive literature. For instance you might want to write about exciting work in electoral politics [@blumenau2017open], legislative politics [@blumenau2018never]; or even politics and gender [@blumenau2019effects].[^alternatives] Alternatively, you might want to provide a link to a [very interesting online resource](https://www.jackblumenau.com) that is relevant to your work.
[^alternatives]: I can use this footnote to tell you that other authors are available.
<!--- This is how you write a comment in Rmarkdown. For instance, I might leave a comment here asking "will people think I am being serious about citing myself all the time or will they understand that I am making a joke?" --->
# Good papers have good sections
In addition, most good papers use a lot of math.
$$ Y_i = \alpha + \beta X_i + \epsilon_i $$
Sometimes you might not want to include a big equation like this, but instead just add a quick equation in-line with the text like this: $\frac{1}{2} = .5$. Sometimes you might not want to include math at all, but instead a more user-friendly graph. That's easy too. For instance, figure \ref{silly_graph} shows a graph I created to explain what makes for a good paper.
![A very serious graph \label{silly_graph}](silly_graph.jpg)
# Data and analysis
## Data
Of course, while good papers might use math, the best papers use *data*. You can load the data that I provided by writing the following in R:
```{r echo=TRUE}
## Load data
covid_data <- read.csv("data/covid_survey.csv")
```
This data includes responses from from a survey of `r nrow(covid_data)` individuals which was fielded in March 2020. We will focus on information on `r ncol(covid_data)` questions posed to those individuals. Our primary interest is in the responses provided to the following questions:
1. `incomeChangeHH`
- Has your household monthly income changed since the coronavirus outbreak?
2. `approveUKGovt`
- Do you approve or disapprove of the job that the UK government is doing?
## Analysis
Given this data, we might want to conduct some cutting-edge analysis which will produce some awesome findings. For instance, you might want to create plots like this:
\vspace{.5cm}
```{r, fig.width=10, fig.height=5, echo = FALSE}
par(mfrow = c(1,2), oma = c(2,0,0,0))
hist(covid_data$age, xlab = "Age", main = "Age")
barplot(table(covid_data$profile_GOR), las = 2, main = "Region")
```
Note that by including `echo = TRUE` in the chunk options, you can see the code that I used to produce such beautiful graphs
Or you could run a regression and present the results in a table by using the `stargazer` package (let's hide the relevant code in the document this time by setting `echo = FALSE`):
```{r, results='asis', echo = FALSE}
silly_model <- lm(age ~ profile_gender,covid_data)
stargazer(silly_model,
keep.stat = c("rsq", "n"),
header = FALSE)
```
Here, we use `results = 'asis'` in the chunk options to ensure that the table is rendered properly in the PDF.
If we care about reporting some quantity of interest from this model in the text, then that is trivial to do using in-line code chunks. For instance, the coefficient on the gender variable is equal to `r coef(silly_model)[2]`.
# Your work goes here!
In this section you should include some R code that conducts some additional analyses of the `covid_data`. You might, for instance, do the following:
1. Create a histogram of incomeChangeHH
2. Create a histogram of approveUKGovt
3. Recode incomeChangeHH to be a binary variable, where 1 is whether an individual's household has lost income as a result of COVID-19 and else the variable is 0
4. Recode approveUKGovt to be a numeric variable
5. Implement one regression predicting approveUKGovt as a function of the binary income variable you have used
6. Implement one regression predicting approveUKGovt as a function of the binary income variable you have used + demographics
7. Write a one paragraph summary of your results which includes describing a) the sample size used in the regressions; b) the size of the coefficient on approveUKGovt in the two models; and c) the r-squared of the two models.
In your document you should make sure that:
1. We cannot see the code you use to do your recoding and analysis
2. We can see both the graphs and tables you produce
3. Any quantities that you report in the paragraph of text you write should be included as in-line code chunks.
# Helpful resources
1. [Rmarkdown cheat sheet](https://rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf)
2. [Bibdesk](https://bibdesk.sourceforge.io)
3. [Github and Rstudio](https://resources.github.com/whitepapers/github-and-rstudio/)
4. [Writing reproducible research papers with R Markdown](https://resulumit.com/blog/rmd-workshop/)
# References