---
####################
## Metadata       ##
####################
course: Mathematics of Ring-bearing
title: |
  Problem Set 1
code: MINT001 # Course code for filename.
date: "`r paste(Sys.Date())`" # Inserts today's date
authors: Gandalf the Grey, Frodo Baggins
# This is the YAML (YAML Ain't Markup Language) header that includes 
# metadata used to produce the document. 
# Be careful with spacing in this header!
# Two spaces at the start of the line create indentation,
# which embeds the parameter in a hierarchy.

#####################
## Bibliography    ##
#####################
bibliography: [references.bib, packages.bib]
csl: chicago-author-date.csl
nocite: '@*' # Adds all elements in bib file to bibliography

##########################
## Define Knit function ##
##########################
knit: iheiddown::problemset_pdf

#####################
## Output Options  ##
#####################
output: iheiddown::problemset_pdf
link-citations: true
documentclass: article
---

```{r, echo=FALSE}
# Set initial knitr options
knitr::opts_chunk$set(eval = TRUE, echo = FALSE,
                      fig.align = "center",
                      fig.asp = 0.7,
                      dpi = 300,
                      out.width = "80%",
                      fig.pos = "!H",
                      out.extra = "")
```

# Problem 1: Escaping the Shire

Solving problem sets will be a weekly ritual at IHEID if you are taking
quantitative courses at the Graduate Institute.`{iheiddown}`'s problem set
template lets you focus on solving the problem set rather than wasting time on
formatting [@iheiddown2020]. Furthermore, since your documents will be written
in RMarkdown, you won't need to learn the more complex Latex syntax.
Finally, it allows you to code and interpret the your results at the same time
which will again speed up your workflow!

# Problem 2: Hiding in forests

Your problem sets will contain some text, probably the solution to a
strange mathematical model and maybe even some pretty graphs. The good news is
that you can type that really easily in your RMarkdown file!

## Tables

The following example shows a simple way to estimate several models and
summarize them in a clear way using the
[`{modelsummary}`](https://vincentarelbundock.github.io/modelsummary/index.html)
package.

```{r Table, echo=TRUE, fig.align='center'}
####################
## Tables Example ##
####################

# Loading the required packages
library(modelsummary)
library(kableExtra)
library(gt)

#Extracting example data
url <- "https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv"
dat <- read.csv(url)

# Creating a list of the different models
models <- list(
  "OLS 1"     = lm(Donations ~ Literacy + Clergy, data = dat),
  "Poisson 1" = glm(Donations ~ Literacy + Commerce,
                    family = poisson,
                    data = dat),
  "OLS 2"     = lm(Crime_pers ~ Literacy + Clergy, data = dat),
  "Poisson 2" = glm(Crime_pers ~ Literacy + Commerce,
                    family = poisson,
                    data = dat),
  "OLS 3"     = lm(Crime_prop ~ Literacy + Clergy, data = dat)
)

# Creating a summary of the different models
modelsummary(models)
```

## Graphs

```{r MpgGraph, echo=FALSE, fig.align='center'}
###################
## Graph Example ##
###################

library(ggplot2)
ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by {iheiddown}") + 
  theme_iheid()
```

# Problem 3: Resisting the power of the Ring

Writing equations is straightforward too! They follow the standard Latex
syntax as shown below. Also see
[this great guide](https://www.overleaf.com/learn/latex/Mathematical_expressions)
for a more comprehensive overview of the math syntax in Latex.

$$ E("Escaping"|"Magic") = \frac{a}{b}$$


# Problem 4: Melting things in volcanoes

Inserting images is easy! Place the image in your main folder and use the
following syntax (see the RMarkdown file).

![Ideal place for melting rings](volcano.jpg)

# Appendix:

Note that you can reference previous code chunks at the end of the code for full
transparency. This is a good way to avoid cluttering your main body with
code while still allowing your reader to see the code you executed to get your
results. Let us demonstrate this feature by inserting the un-evaluated code of 
all chunks used in this document.

```{r ref.label=knitr::all_labels(), echo=TRUE, eval=FALSE}
```

```{r pkgbib, echo=FALSE}
################################
## Citing all loaded packages ##
################################
knitr::write_bib(c(.packages(), "bookdown"), "packages.bib")
```

# References:
<!-- The bibliography is automatically generated here. -->
