---
title: "STAT 331 Week 10 Day 1 Handout"
format: html
embed-resources: true
---

```{r}
#| label: setup

library(knitr)
library(broom)
library(tidyverse)
```


NC births data loaded from `openintro` package:

```{r}
library(openintro)
data(ncbirths)
?ncbirths
```

## Cross Validation

Let's write a general function to implement k-fold cross validation efficiently.

1. Copy the helper function from the slides to calculate $R^2$. It will be nice to use this in your CV function!

```{r}

```

2. Write a function that takes an arbitrary dataframe/tibble, formula for a linear model, and number of folds and implements k-fold CV, returning a vector with k $R^2$ values. 

- Assume that there is not already a variable in the dataset dividing the observations into folds.
- Default to performing 5-fold CV.
- Your function should use a map function to implement the CV efficiently... so you might need another helper function! 

Hint: `augment()` could be useful.

```{r}

```


3. Test your function with the `weight ~ weeks` model and the `ncbirths` data that we worked with in class. 

```{r}

```

