## ----echo=FALSE---------------------------------------------------------- library(knitr) opts_chunk$set(size="small",background="white", highlight=FALSE, cache=TRUE, autdep=TRUE, tidy=TRUE) ## ------------------------------------------------------------------------ bea <-read.csv("http://www.stat.cmu.edu/~cshalizi/mreg/15/lectures/03/bea-2006.csv") ## ------------------------------------------------------------------------ dim(bea) # Should have 7 columns and 366 rows, and we do head(bea) # Look at the beginning of the data ## ------------------------------------------------------------------------ bea$gmp <- bea$pcgmp * bea$pop ## ------------------------------------------------------------------------ plot(gmp ~ pop, data=bea, xlab="Population", ylab="Total GMP") ## ------------------------------------------------------------------------ plot(gmp ~ pop, data=bea, xlab="Population", ylab="Total GMP") abline(a=0,b=4e4) ## ------------------------------------------------------------------------ plot(pcgmp ~ pop, data=bea, xlab="Population", ylab="Per-capita GMP") ## ------------------------------------------------------------------------ plot(pcgmp ~ pop, data=bea, xlab="Population", ylab="Per-capita GMP", log="x") ## ------------------------------------------------------------------------ # alter the plotting symbol from a hollow circle to a filled dot (pch) # shrink the plotting symbols by a factor of 0.5 (cex) plot(pcgmp ~ pop, data=bea, xlab="Population", ylab="Per-capita GMP", pch=19, cex=0.5) ## ------------------------------------------------------------------------ lm(pcgmp ~ pop, data=bea) ## ------------------------------------------------------------------------ plot(pcgmp ~ pop, data=bea, xlab="Population", ylab="Per-capita GMP", pch=19, cex=0.5) abline(lm(pcgmp ~ pop, data=bea), col="blue") ## ----warning=FALSE------------------------------------------------------- plot(pcgmp ~ pop, data=bea, xlab="Population", ylab="Per-capita GMP", pch=19, cex=0.5) abline(lm(pcgmp ~ pop, data=bea), col="blue") abline(a=4e4, b=0, col="grey") abline(a=2e4, b=4e4/2e7, col="green") lines(smooth.spline(x=bea$pop, y=bea$pcgmp, cv=TRUE), col="orange")