```{r global_options, include=FALSE}
library(knitr)
library(tidyverse)
library(ggthemes)
opts_chunk$set(fig.align = "center", fig.height = 4, fig.width = 6)
theme_set(theme_bw(base_size = 12))
```
## Homework 5
*Enter your name and EID here*

**This homework is due on Mar. 5, 2019 at 4:00pm. Please submit as a PDF file on Canvas.**

For this homework, you will work with a dataset collected by John Holcomb from the North Carolina State Center for Health and Environmental Statistics. This data set contains 1409 birth records from North Carolina in 2001.

```{r}
NCbirths <- read_csv("http://wilkelab.org/classes/SDS348/data_sets/NCbirths.csv")
head(NCbirths)
```

The column contents are as follows:

+ **Plural**: 1=single birth, 2=twins, 3=triplets.
+ **Sex**: Sex of the baby 1=male 2=female.
+ **MomAge**: Mother's age (in years).
+ **Weeks**: Completed weeks of gestation.
+ **Gained**: Weight gained during pregnancy (in pounds).
+ **Smoke**: Mother is a smoker: 1=yes, 0=no.
+ **BirthWeightGm**: Birth weight in grams.
+ **Low**: Indicator for low birth weight, 1=2500 grams or less, 0=otherwise.
+ **Premie**: Indicator for premature birth, 1=36 weeks or sooner, 0=otherwise.
+ **Marital**: Marital status: 0=married or 1=not married.

**Problem 1 (3 pts):** We are interested in assessing the relationships between the variables in the dataset `NCbirths` and the mothers' marital status, the mothers' smoking habits, and plural births. Perform a principal components analysis (PCA) on the dataset `NCbirths`. Remove the columns `Marital`, `Smoke`, and `Plural` prior to performing PCA. Create a scatterplot of PC1 vs. PC2. First, color each point bythe  mother's marital status, then color each point by the mother's smoking habit, and then color each point by the indicator of plural births. What do you observe? Visually, and without doing any calculations, do the different types of births cluster together in principal-component space? Do the smokers or married mothers cluster together?

```{r}
# your R code goes here
```

*Your answer goes here. 2-3 sentences only.*

**Problem 2 (4 pts):** Now visualize the rotation matrix of the PCA obtained under Problem 1. 
```{r}
# your R code goes here
```

Given the plots from Problem 1 and the arrow plot you made, how do you interpret PC1 and PC2? What does PC1 tell you about a data point? What does PC2 tell you about a data point?

*Your answer goes here.*

**Problem 3 (3 pts):** Create a bar plot that shows the percent variance explained by each principal component. State how much variance is explained by each of the principal components 1 through 4.

```{r}
# your R code goes here
```

*Your answer goes here. 1-2 sentences only.*
