-
Notifications
You must be signed in to change notification settings - Fork 12
/
PaperInR_6.Rnw
226 lines (148 loc) · 9.32 KB
/
PaperInR_6.Rnw
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
% regresion report simple
\documentclass[11pt]{article}
\usepackage{longtable}
\usepackage{adjustbox}
\title{My first replicable Paper}
\author{
MyFirstName MyLastName\\
Evans School of Public Policy and Governance\\
University of Washington\\
Seattle, WA 98115, \underline{United States}\\
\texttt{greatguy@uw.edu}
}
\date{\today}
\begin{document}
\SweaveOpts{concordance=TRUE}
\maketitle
\begin{abstract}
This is an example on how to make a reproducible paper. We are using R from Rstudio, creating an RSweave document. This is a nice start to create a nice paper and get an A+. The next sections will show the steps taken.
\end{abstract}
\section{Introduction}\label{intro}
This is my intro to my great paper, I will explain the cool things I can do with my new `computational thinking' powers combined with some Latex. This is my intro to my great paper, I will explain the cool things I can do with my new `computational thinking' powers combined with some Latex. This is my intro to my great paper, I will explain the cool things I can do with my new `computational thinking' powers combined with some Latex. This is my intro to my great paper, I will explain the cool things I can do with my new `computational thinking' powers combined with some Latex.
This is my nice intro to my great paper,
I will explain the cool things
I can do with my new `computational thinking'
powers
combined with some Latex.
\section{Exploring Data}\label{explo}
Sections may use a label\footnote{In fact, you can have a label wherever you think a future reference to that content might be needed.}. This label is needed for referencing. For example the next section has label \emph{datas}, so you can reference it by writing: As we see in section \ref{catexplo}.
<<libraries, echo=FALSE>>=
library(reporttools)
library(stargazer)
@
<<collecting, echo=FALSE>>=
# collecting
fileLink="https://github.com/eScienceUW-WinterSchool-2020/ReproducibilitySession/raw/master/data/dataidx.RDS"
MyFile=url(fileLink)
dataidx=readRDS(MyFile)
@
\subsection{Exploring Categorical Data}\label{catexplo}
Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.
You can see the statistics of categorical variables in Table \ref{catexplore_table}.
<<results=tex,echo=FALSE>>=
tableNominal(vars = dataidx[, c(2,5)],
cap = "Freq Table",
vertical = FALSE,
lab ="catexplore_table",
caption.placement = "top",
font.size = "normalsize")
@
%%%%%%
You can see this variable plotted in Figure \ref{catexplore_plot}
<<cat_table, echo=FALSE>>=
tableONI=as.data.frame(table(dataidx$ONIpolitical))
names(tableONI)=c("var","count")
##
library(ggplot2)
base=ggplot(data=tableONI,aes(x=var,y=count))
bar1=base + geom_bar(stat = 'identity')
@
\begin{figure}[h]
\centering
\begin{adjustbox}{width=7cm,height=5cm}
<<cat_plot, echo=FALSE, fig=TRUE>>=
bar1
@
\end{adjustbox}
\caption{ONI barplot} %title
\label{catexplore_plot} % for \ref{}
\end{figure}
\subsection{Exploring Numerical Data}\label{numexplo}
Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.
<<summary, results=tex, echo=FALSE>>=
# library(stargazer)
stargazer(dataidx[,c(3,4)],
title = "Stat summary for nummeric vars",
label = "numexplore_table",
font.size = 'footnotesize',
digits = 2,
summary.stat = c("median","mean","min",'max','p25','p75','sd'))
@
In the Table \ref{numexplore_table}, you realize that the mean of FHF is {\bf\Sexpr{mean(dataidx$FHF,na.rm=T)}}.
<<num_table, echo=FALSE>>=
base=ggplot(data=dataidx)
box = base + geom_boxplot(aes(y=FHF,x=1))
box = box + geom_boxplot(aes(y=RWB,x=2))
box=box + scale_x_continuous(breaks = c(1,2),
labels = names(dataidx[,c(3,4)]))
@
\begin{figure}[h]
\centering
\begin{adjustbox}{width=7cm,height=5.5cm,clip,trim=0cm 0.5cm 0cm 0cm}
<<num_plot, echo=FALSE, fig=TRUE>>=
box +labs(x=NULL,y=NULL)
@
\end{adjustbox}
\caption{boxplots}
\label{num_plot}
\end{figure}
Boxplots were introduced by Tuckey (Tukey, John W (1977). Exploratory Data Analysis. Addison-Wesley.)
\section{Looking for Relationships}\label{bivar}
Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.
\subsection{Numerical and Categorical}\label{binumcat}
<<echo=FALSE>>=
base=ggplot(dataidx,aes(y=FHF,x=Region))
box=base + geom_boxplot()
@
\begin{figure}[h]
\centering
\begin{adjustbox}{width=7cm,height=7cm}
<<numcat_plot, echo=FALSE, fig=TRUE>>=
box + theme_minimal() + labs(title = "Is this right?")
@
\end{adjustbox}
\caption{Boxplots: one numerical by a category.}
\label{numcat_plot}
\end{figure}
Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.
\subsection{Numerical and Numerical}\label{binumnum}
Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.Here, I continue doing this nice work, I hope you like it and read it. It has been a very hard work.
<<echo=FALSE>>=
base=ggplot(data=dataidx,aes(x=FHF,y=RWB))
points=base + geom_point()
@
\begin{figure}[h]
\centering
\begin{adjustbox}{width=7cm,height=5.5cm}
<<numnum_plot, echo=FALSE, fig=TRUE>>=
points
@
\end{adjustbox}
\caption{scatter}
\label{numnum_plot}
\end{figure}
The scatter plot is thought to be invented by John Frederick W. Herschel according to this link: https://qz.com/1235712/the-origins-of-the-scatter-plot-data-visualizations-greatest-invention/
\section{My Regression}\label{regre}
This is a Regression in R:
<<>>=
regre1=lm(FHF~RWB,data=dataidx)
@
This is another:
<<>>=
regre2=lm(FHF~RWB+ONIpolitical,data=dataidx)
@
These is the traditional summary for one:
<<>>=
summary(regre1)
@
\end{document}