--- title: "Assignment 7 Notes" output: html_document: toc: yes --- ```{r global_options, include=FALSE} knitr::opts_chunk$set(collapse=TRUE) ``` ## 1. Economic Data One possible single plot view: ```{r} library(ggplot2) library(lattice) sts <- ts(scale(economics[-1], center = FALSE), start = c(1967, 7), frequency = 12) xyplot(sts, superpose= TRUE) ``` An alternative scaling that emphasizes the behavior around 2008: ```{r} sec2008 <- as.numeric(economics[487, -1]) sec <- scale(economics[-1], center = FALSE, scale = sec2008) xyplot(ts(sec, start = c(1967, 7), frequency = 12), superpose = TRUE) ``` An alternative: ```{r, message = FALSE} library(zoo) ets <- ts(economics[-1], start = c(1967, 7), frequency = 12) autoplot(as.zoo(ets)) + facet_grid(Series ~ ., scales = 'free') ``` Some notes: - Population has risen by about 50% over the period. - Personal consumption does not appear to be inflation-adjusted. The series has grown steadily, with a noticable drop at the 2008 recession. - The personal savings rate has a decreasing trend; fluctuations somewhat mirror the unemployment rate. - Unemplyment rate and median unemployment duration follow similar patterns, with duration peaks lagging a little and recovering a little more slowly. ## 2. Florida Death Penalty Data Transform the data to have more useful labels: ```{r, message = FALSE} library(lattice) library(vcd) library(dplyr) data(deathpenalty, package = "catdata") bw <- c("black", "white") dp <- mutate(deathpenalty, DefendantRace = factor(DefendantRace, labels = bw), VictimRace = factor(VictimRace, labels = bw), DeathPenalty = factor(DeathPenalty, labels = c("no", "yes"))) ``` Double decker plots are very effective for visualizing these data. A slightly lower proportion of black defendants than white defendants received the death penalty. ```{r} tabs0 <- xtabs(Freq ~ DefendantRace + DeathPenalty, data = dp) round(prop.table(tabs0, 1), 2) doubledecker(tabs0) ``` Conditioning on the victim's race this is reversed: for both black and white victims, a higher proportion of black defendants than white defendants received the death penalty. For cases where the victim was white and the defendant black almost a quarter of the defendants were sentenced to death. ```{r} tabs <- xtabs(Freq ~ DefendantRace + VictimRace + DeathPenalty, data = dp) round(prop.table(tabs, 1:2), 2) doubledecker(tabs) ```