---
title: "STAT 303 Homework 3"
output: html_document
---

We'll grade your homework by

* opening your "hw3.Rmd" file in RStudio
* clicking "Knit HTML"
* reading the HTML output
* reading your "hw3.Rmd"

You should write R code anywhere you see an empty R code chunk. You
should write English text anywhere you see "..."; please surround it
with doubled asterisks (`**...**`) so that it will show up as boldface
and be easy for us to find.

Include reasonable labels (titles, axis labels, legends, etc.) with
each of your graphs.

Name: ...

Email: ...

Please use an R version no less than 4.0.0 so that students and
teachers will agree on the definition. You can see your version in the
variable `R.version`. The following line of code checks that you're
using major version 4:
```{R}
stopifnot(R.version$major == "4")
```
If this line of code fails, please get the current version from
https://cloud.r-project.org.

We'll use data on housing values in suburbs of Boston. They are in an
R package called "MASS." (An R package is a collection of code,
data, and documentation. "MASS" refers to the book "Modern Applied
Statistics with S." R developed from the earlier language, S.) The
MASS package comes with the default R installation, so it's already on
your computer.  However, it's not loaded into your R session by
default. So we'll load it via the `require()` command (there's nothing
for you to do here):

```{r}
require("MASS")
```

Run `?Boston` (outside this R Markdown document) to read the help page for the `Boston` data frame.

Convert the `chas` variable to a factor with labels "off" and "on" (referring to the Charles river).

```{r}
```

How many rows are in the Boston data frame? How many columns?

```{r}
```

What does a row represent?
...

What does a column represent?
...

Make a density plot (with rug) of tax rates.

```{r}
```

Describe the shape of the distribution of tax rates.
...

Note that the distribution shape doesn't make sense in light of the rug representation of the data. Make a histogram of the tax rates.

```{r}
```

Why is the second peak of the density plot so large? In what way is the rug representation of the data inadequate? Write a line or two of code to figure it out, and then explain it.

```{r}
```
...

Make a barplot of "chas".

```{r}
```

How many neighborhoods are on the Charles river?

```{r}
```

Make a single graph consisting of three sub-graphs as follows:

* a scatterplot of "nox" on the y-axis vs. "dis" on the x-axis 
* a (vertical) boxplot of "nox" left of the scatterplot's y-axis
* a (horizontal) boxplot of "dis" below the scatterplot's x-axis

Hint: use `layout()` with a 4x4 matrix, using the top-right 3x3 corner
for the scatterplot, leaving the bottom-left 1x1 corner blank, and
using the other parts for the boxplots.

(An optional challenge, worth 0 extra credit points: remove the axis
and plot border from each boxplot.)

```{r, fig.width=7, fig.height=7}
```

Look into the highest-crime neighborhood by making a single graph
consisting of three sub-graphs arranged in one column of three rows:

* Find the row number, r, of the neighborhood with the highest "crim".
* Make a density plot of "crim". Include a rug to show the data.
* Add a red circle at (x, y) = (max crime rate, 0) to make this maximum crime rate stand out.
* Make a density plot with rug of "medv", adding a red circle at (x, y) = (medv[r], 0) to see what medv corresponds to the highest crime rate.
* Repeat the last step for "ptratio".

```{r}
```

What do you notice about the ptratio and medv for the highest-crime neighborhood?

...
