-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathElements.Rmd
More file actions
242 lines (146 loc) · 6.29 KB
/
Copy pathElements.Rmd
File metadata and controls
242 lines (146 loc) · 6.29 KB
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
# Samples of Writing in `R bookdown` {#S:SampleSection}
***
In this chapter, you learn how to:
- Reference other sections and equations
- Include in-text citation that links to the bibliography
- Include tables and figures not generated by `R` code
- Include a footnote
***
As we expand our contributor and reviewer base, it will be helpful to know more about the conventions used in the series regarding the details of `R markdown` and `R bookdown` used in the series. This chapter summarizes these conventions.
## Section Labels and Learning Objectives {#S:SectionLabels}
The following shows how to code Section titles and refer to them.
```
## Section Labels {#S:SectionLabels}
```
With that reference, one can readily refer to Section \@ref(S:SectionLabels) in your text, as follows:
```
With that reference, one can readily refer to
Section \@ref(S:SectionLabels) in your text, as follows:
```
The following shows how to code learning objectives:
```
***
In this chapter, you learn how to:
- Reference other sections and equations
- Include in-text citation that links to the bibliography
- Include tables and figures
- Include a footnote
***
```
## Equation References
Here is an example of a latex equation produced in `R markdown`, with reference number.
\begin{equation}
x + y = 1
(\#eq:ExampleEquation)
\end{equation}
You can produce that equation using the following code.
```
\begin{equation}
x + y = 1
(\#eq:ExampleEquation)
\end{equation}
```
With this, equation \@ref(eq:ExampleEquation) can be referred to using the following code:
```
With this, equation \@ref(eq:ExampleEquation) can be
referred to using the following code:
```
## In-text Citations
Here is an example of an in-text citation made possible by `R bookdown` [@xie2015]. This links to the bibliography where the full referece is displayed. As a convention we use the *APA* style citation.
```
Here is an example of an in-text citation made possible by
`R bookdown` [@xie2015]. This links to the bibliography
where the full reference is displayed.
As a convention we use the *APA* style citation.
```
## Including Tables
In order to include table not generated by `R` such as a Latex table, we have to make some adjustments to regular Latex syntax.
<a id=tab:2.1></a>
[Table 2.1]: \#tab:2.1
$$
\begin{matrix}
\begin{array}{c|c} \hline
\text{Policyholder} & \text{Number of claims} \\\hline
\textbf{X} & 1 \\\hline
\textbf{Y} & 2 \\\hline
\end{array}
\end{matrix}
$$
[Table 2.1] : An example of including tables using Latex in an `R markdown` document
`R markdown` does not have a convention for referencing non-R generated tables. For now, we reference them manually as in refer to [Table 2.1]. We do this by manually inserting an html anchor tag.
The following code produces this table.
```
<a id=tab:2.1></a>
[Table 2.1]: \#tab:2.1
$$
\begin{matrix}
\begin{array}{c|c} \hline
\text{Policyholder} & \text{Number of claims} \\\hline
\textbf{X} & 1 \\\hline
\textbf{Y} & 2 \\\hline
\end{array}
\end{matrix}
$$
[Table 2.1] : An example of including tables using Latex in an `R markdown` document
```
For reference, then use
```
`R markdown` does not have a convention for referencing
non-R generated tables. For now, we reference them manually
as in refer to [Table 2.1].
```
## Including Figures
### Figures Generated by `R`
Most figures are generated using `R`. Here is an illustrative figure.
```{r EDFToy, echo = FALSE, fig.cap = 'Empirical Distribution Function of a Toy Example', out.width = '60%', fig.asp = 0.75, fig.align = 'center'}
xExample <- c(10,rep(15,3),20,rep(23,4),30)
PercentilesxExample <- ecdf(xExample)
plot(PercentilesxExample, main = "", xlab = "x")
```
that we refer to as Figure \@ref(fig:EDFToy). Here is the code for producing the figure:
``````
```{r EDFToy, echo = FALSE,
fig.cap = 'Empirical Distribution Function of a Toy Example',
out.width = '60%', fig.asp = 0.75, fig.align = 'center'}
xExample <- c(10,rep(15,3),20,rep(23,4),30)
PercentilesxExample <- ecdf(xExample)
plot(PercentilesxExample, main = "", xlab = "x")
```
``````
Here is is the code for referencing the Figure \@ref(fig:EDFToy):
```
Here is is the code for referencing the Figure \@ref(fig:EDFToy):
```
### Figures Not Generated by `R`
For figures, we store the figures as png or jpeg files in a separate folder called "Figures". Then we use `R` code to call those figures for display so that we can reference them.
Here is such a figure:
```{r, ExampleFigure, fig.cap = 'An example of including figures in an R Markdown document', out.width = '5%', fig.align = 'center', echo = FALSE}
knitr::include_graphics("Figures/RStudio-Ball.png")
```
And here is the code that generates the figure:
```
"three backticks"{r, ExampleFigure, fig.cap = 'An example
of including figures in an R Markdown document',
out.width = '5%', fig.align = 'center', echo = FALSE}
knitr::include_graphics("Figures/RStudio-Ball.png")
"three backticks"
```
Here is is the code for referencing the Figure \@ref(fig:ExampleFigure):
```
Here is is the code for referencing the Figure \@ref(fig:ExampleFigure):
```
## Including Footnotes
Try to minimize the use of footnotes. But, if you need them, here is how you can include a footnote [^1].
[^1]: the footnote displays at the end of the chapter
```
Here is how you can include a footnote [^1].
[^1]: the footnote displays at the end of the chapter
```
## Useful Links {#S:Links}
Naturally, you will want to learn more about coding in `R markdown`, `R bookdown` and so forth. The following provide some useful links for taking the next step.
- For an `R markdown` guide refer [https://rmarkdown.rstudio.com/authoring_pandoc_markdown.html](https://rmarkdown.rstudio.com/authoring_pandoc_markdown.html).
- For a `R bookdown` guide, see [https://bookdown.org/yihui/bookdown/](https://bookdown.org/yihui/bookdown/).
- For best practices in coding `R`, we suggest
[http://r-pkgs.had.co.nz/style.html](http://r-pkgs.had.co.nz/style.html).
- See also our online actuarial text resources at
[https://sites.google.com/a/wisc.edu/loss-data-analytics/online-actuarial-text-resources](https://sites.google.com/a/wisc.edu/loss-data-analytics/online-actuarial-text-resources).