---
title: "Agresti exercises 9.27 and 9.33"
author: ""
date: ""
output: 
  html_document:
    fig_height: 3
    fig_width: 5
  pdf_document:
    fig_height: 3
    fig_width: 5
  word_document:
    fig_height: 3
    fig_width: 5
---

```{r, setup, include=FALSE}
require(mosaic)   # Load additional packages here 

# Some customization.  You can alter or delete as desired (if you know what you are doing).
trellis.par.set(theme=theme.mosaic()) # change default color scheme for lattice
knitr::opts_chunk$set(
  tidy=FALSE,     # display code as typed
  size="small")   # slightly smaller font for code
```

## Agresti exercise 9.27

Import UN data for exercise 9.27:
```{r}
UN <- read.table("https://asta.math.aau.dk/datasets?file=UN2014.dat", header = TRUE)
```

Answer the exercise by an analysis in RStudio.

Start by making relevant plot(s).
```{r}
## Write plot command(s) here. Hint: gf_point could be relevant...
```

Then fit the linear model in R:
```{r}
## Write a command like: lm( ??? ~ ???, data = ??? )
```

Now answer questions (a) - (d)



## Agresti exercise 9.33

Import OECD data for exercise 9.33 (also available for download at the website):
```{r}
oecd <- read.table("https://asta.math.aau.dk/datasets?file=OECD_Agresti_ed5.dat", header = TRUE)
```

Use `gf_point` to make a scatter plot of the relevant y and x variables.

Use `cor` to calculate the correlation between x and y:
```{r}
# Use a command like cor(oecd$VAR1, oecd$VAR2) with the relevant variable names.
```

For the next part of the exercise the following hint may be helpful:
To remove a row in a `data.frame` you may use a negative index.
For example if you have a `data.frame` called `oecd` and you want to remove row number 10 you do (you have to find the relevant index to remove on your own):
```{r}
oecd2 <- oecd[-10, ]
```

Recall x is like a matrix and the first index corresponds to rows and
the second to columns. Since nothing is written in the second index
the columns are unchanged whereas the 10th row is deleted (due to the
minus sign).
