```{r setup, include=FALSE}
## Default chunk options 
knitr::opts_chunk$set(
  echo = FALSE,
  results = 'hide',
  message = FALSE
  )
```

## Introduction 

We examined yadda yadda

```{r}
library(mosaic)
CountryData <- read.file("http://colindawson.net/data/CountryData.csv")
```

```{r}
N <- nrow(CountryData)
```

```{r}
## Splitting the data
set.seed(8675309)
CountryData <- CountryData %>% 
  mutate(
    TestSet = rep(c("no","yes"), times = c(80,20)) %>% sample()
  )
TrainingSet <- CountryData %>% filter(TestSet == "no")
TestSet <- CountryData %>% filter(TestSet == "yes")
```

```{r}
## Choose/Fit/Assess on TrainingSet
## ...
healthModel <- lm(LifeExpectancy ~ Health, data = TrainingSet)
internetModel <- lm(LifeExpectancy ~ log(Internet), data = CountryData)
developedModel <- lm(LifeExpectancy ~ factor(Developed), data = CountryData)
```

```{r}
summary(developedModel)
```


```{r}
## Doing cross-validation 
source("~/www/colinreimerdawson/stat213/code/helper_functions.R")
do.k.fold.cv(model = healthModel, data = TrainingSet, num.folds = 10, error.metric = mse) %>%
  sqrt()
```

```{r}
testPredictions = predict(healthModel, newdata = TestSet)
with(TestSet,
  mse(actual = LifeExpectancy, predicted = testPredictions, trained.model = healthModel))
```
```{r}
tally(Developed ~ TestSet + OtherVariable, data = CountryData)
```



