## R code to accompany Lecture 2 of ## Intermediate Data Analytics & Machine Learning ## Robert B. Gramacy, Virginia Tech pdf("cndprice_scatter.pdf", width=8, height=4) x <- runif(200, 0.5, 3.5) e <- rnorm(200, 0, 50) y <- 120 + 75*x + e plot(x, y, xlab="size", ylab="price") abline(120, 75, lwd=2) v <- c(1, 1.5, 2, 2.5, 3, 3.5) abline(v=v, col="green", lty=2) dev.off() pdf("cndprice_box.pdf", width=8, height=4) bins <- list() bins\$marg <- y[y >= 1] bins[["1-1.5"]] <- y[x >= 1 & x < 1.5] bins[["1.5-2"]] <- y[x >= 1.5 & x < 2] bins[["2-2.5"]] <- y[x >= 2 & x < 2.5] bins[["2.5-3"]] <- y[x >= 2.5 & x < 3] bins[["3-3.5"]] <- y[x >= 3 & x < 3.5] boxplot(bins, col="green", ylab="price") lines(c(2, 6), 120+75*c(1.25,3.25), lwd=2) dev.off() pdf("cndprice_stops_scatter.pdf", width=8, height=4) s <- rnorm(200, 2) xs <- rep(NA, 200) xs[s <= 0.5] <- 0 xs[s > 0.5 & s <= 1.5] <- 1 xs[s > 1.5 & s <= 2.5] <- 2 xs[s > 2.5 & s <= 3.5] <- 3 xs[s > 3.5] <- 4 plot(xs, y, xlab="# stops", ylab="price") dev.off() pdf("cndprice_stops_box.pdf", width=8, height=4) sbins <- list() sbins\$marg <- y sbins[["0"]] <- y[xs == 0] sbins[["1"]] <- y[xs == 1] sbins[["2"]] <- y[xs == 2] sbins[["3"]] <- y[xs == 3] sbins[["4"]] <- y[xs >= 4] boxplot(sbins, col="green", ylab="price") dev.off()