Name: Lars Olson
Email: leolson3@wisc.edu
if (!require("knitr")) {
install.packages("knitr") # do this once per lifetime
require("knitr") # do this once per session
}
require("MASS")
## Loading required package: MASS
Boston = Boston
Boston$chas = factor(Boston$chas, levels = c(0, 1), labels = c("off", "on"))
columns = ncol(Boston)
cat(sep = "", "The number of columns are ", columns, "\n")
## The number of columns are 14
rows = nrow(Boston)
cat(sep = "", "The number of rows are ", rows, "\n")
## The number of rows are 506
Each row in this data frame represents a unique suburb in the Boston area, containing statistics related to that suburb.
Each column in this data frame represents a different statistic that is being measured for each suburb. Abstractly, a column is the set of all observations for a particular variable.
rug(Boston$tax). (I neglected to include rug() in the handout.)plot(density(Boston$tax), main = "Tax Rates")
rug(Boston$tax)
It is Bimodal around approximately 300 and 700
hist(Boston$tax, breaks = 100, freq = TRUE, main = "Histogram of Tax Rates",
ylim = c(0, 140), xlim = c(100, 800))
max = length(which(Boston$tax == max(Boston$tax)))
cat(sep = "", "There are ", max, " occurrences of the maximum value, ", max(Boston$tax),
", in this histogram.", "\n")
## There are 5 occurrences of the maximum value, 711, in this histogram.
second = sort(Boston$tax, TRUE)[max + 1]
secondcount = length(which(Boston$tax == second))
cat(sep = "", "There are ", secondcount, " occurrences of the second highest value, ",
second, " ,in this histogram.", "\n")
## There are 132 occurrences of the second highest value, 666 ,in this histogram.
There are multiple occurrences of tax rates at 666 and 711, which is represented as a single dark line with the rug, so it obscures the number of points at these tax rates.
counts = table(Boston$chas)
barplot(counts, names.arg = NULL, main = "Charles River Count (chas)", ylim = c(0,
500))
Rivercount = length(which(Boston$chas == "on"))
cat(sep = "", "There are ", Rivercount, " neighborhoods on the Charles river.",
"\n")
## There are 35 neighborhoods on the Charles river.
#* a scatterplot of “nox” on the y-axis vs. “dis” on the x-axis #* a boxplot of “nox”“ left of the scatterplot's y-axis #* a boxplot of "dis”“ below the scatterplot's x-axis
m = matrix(data = c(1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 0, 2, 2, 2), nrow = 4,
ncol = 4, byrow = TRUE)
layout(m)
boxplot(Boston$nox)
boxplot(Boston$dis, horizontal = TRUE)
plot(Boston$dis, Boston$nox)